notusci 0.1.9 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notusci",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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
@@ -63,12 +63,16 @@ async function api(s, path, { method = "GET", query = {}, body, bearer = s.token
63
63
  if (body !== undefined) headers["content-type"] = "application/json";
64
64
  let response;
65
65
  let text = "";
66
+ let waited = false;
66
67
  for (let attempt = 0; ; attempt++) {
67
68
  const timeoutMs = Math.max(1000, Math.min(timeoutSeconds * 1000, deadline - Date.now()));
68
69
  try {
69
70
  response = await fetch(url, { method, headers, body: typeof body === "string" || body === undefined ? body : JSON.stringify(body),
70
71
  signal: AbortSignal.timeout(timeoutMs) });
71
72
  text = await response.text();
73
+ // Rate limited: wait once as told, then report (spec 071).
74
+ const wait = Math.min(60, Number(response.headers.get("retry-after")) || 60) * 1000;
75
+ if (response.status === 429 && !waited && Date.now() + wait < deadline) { waited = true; await sleep(wait); continue; }
72
76
  if (response.status < 500 || attempt === 2) break;
73
77
  } catch {
74
78
  if (attempt === 2 || Date.now() >= deadline) throw new CliError({ code: "network", error: `Cannot reach NotusCI at ${s.url}`, next: "Retry the same command." });
@@ -221,7 +225,7 @@ async function init(s, input) {
221
225
  print({ status: "ready", user: me.user, repo: listed(me, repo).repo, scopes: me.scopes, workflow, mcp, next: `${NPX} verify` });
222
226
  }
223
227
 
224
- /** @param {Session} s @param {{repo?: string, timeoutSeconds: number}} input */
228
+ /** @param {Session} s @param {{repo?: string, timeoutSeconds: number, interval?: "month" | "year"}} input */
225
229
  async function billing(s, input) {
226
230
  const repo = repoOrOrigin(input.repo);
227
231
  const deadline = Date.now() + input.timeoutSeconds * 1000;
@@ -232,7 +236,7 @@ async function billing(s, input) {
232
236
  }
233
237
  let action = s.state.billing;
234
238
  if (!action || action.repo.toLowerCase() !== repo.toLowerCase() || new Date(action.expiresAt).getTime() <= Date.now()) {
235
- action = { ...await api(s, "/api/billing/checkouts", { method: "POST", body: { repo }, deadline }), repo };
239
+ action = { ...await api(s, "/api/billing/checkouts", { method: "POST", body: { repo, ...(input.interval ? { interval: input.interval } : {}) }, deadline }), repo };
236
240
  save(s, { token: s.state.token, pending: s.state.pending, billing: action });
237
241
  }
238
242
  while (Date.now() + 2_000 <= deadline) {
@@ -347,6 +351,11 @@ async function main(s, input) {
347
351
  case "doctor": return doctor(s);
348
352
  case "login": return login(s, input);
349
353
  case "billing": return billing(s, input);
354
+ case "usage": {
355
+ const repo = repoOrOrigin(input.repo);
356
+ return print(input.capUsd === undefined ? await api(s, "/api/usage", { query: { repo } })
357
+ : await api(s, "/api/usage/cap", { method: "POST", body: { repo, capUsd: input.capUsd } }));
358
+ }
350
359
  case "logout": return logout(s);
351
360
  case "whoami": {
352
361
  const { user, scopes, repos, installUrl } = await api(s, "/api/whoami");
package/src/core.mjs CHANGED
@@ -43,13 +43,14 @@ const OPTIONS = {
43
43
  approve: { repo: { type: "string" } },
44
44
  repo: { repo: { type: "string" }, settings: { type: "string" }, "push-workflow": { type: "string" }, off: { type: "boolean" }, "image-from-workspace": { type: "string" }, "image-from-dockerfile": { type: "boolean" } },
45
45
  migrations: { repo: { type: "string" }, push: { type: "string" }, reason: { type: "string" }, "force-destructive": { type: "boolean" } },
46
- billing: { repo: { type: "string" }, timeout: { type: "string" } },
46
+ billing: { repo: { type: "string" }, timeout: { type: "string" }, yearly: { type: "boolean" } },
47
+ usage: { repo: { type: "string" }, cap: { type: "string" } },
47
48
  api: { data: { type: "string" } },
48
49
  };
49
50
 
50
51
  export const HELP = {
51
52
  commands: [
52
- "init [--scope SCOPES] [--no-mcp] [--billing]", "billing [--repo OWNER/REPO] [--timeout SECONDS]", "doctor",
53
+ "init [--scope SCOPES] [--no-mcp] [--billing]", "billing [--repo OWNER/REPO] [--yearly] [--timeout SECONDS]", "usage [--repo OWNER/REPO] [--cap USD]", "doctor",
53
54
  "login [--scope SCOPES]", "logout", "whoami", "repos", "token list", "token revoke ID",
54
55
  "target set [--repo OWNER/REPO] [--file TARGET.json] [--auto-promote on|off] [--auto-release on|off]",
55
56
  "secret set NAME [--repo OWNER/REPO] (value on stdin)", "secret list [--repo OWNER/REPO]", "secret rm NAME [--repo OWNER/REPO]",
@@ -178,7 +179,12 @@ export function parseCommand(args) {
178
179
  if (values.workflow === "") throw usage("--workflow must not be empty");
179
180
  return { command, workflow: values.workflow, timeoutSeconds: timeoutSeconds ?? 540, ...(values["no-reuse"] ? { reuse: false } : {}) };
180
181
  }
181
- if (command === "billing") { expect(); return { command, repo: values.repo, timeoutSeconds: timeoutSeconds ?? 90 }; }
182
+ if (command === "billing") { expect(); return { command, repo: values.repo, timeoutSeconds: timeoutSeconds ?? 90, ...(values.yearly ? { interval: "year" } : {}) }; }
183
+ if (command === "usage") {
184
+ expect(); const capUsd = values.cap === undefined ? undefined : Number(values.cap);
185
+ if (capUsd !== undefined && !(capUsd >= 0)) throw usage("--cap must be a number of dollars, 0 or more");
186
+ return { command, repo: values.repo, ...(capUsd !== undefined ? { capUsd } : {}) };
187
+ }
182
188
  if (command === "search-logs") {
183
189
  expect("*"); const runId = /^[1-9]\d*$/.test(positionals[0]) ? Number(positionals[0]) : positionals[0].toLowerCase();
184
190
  if ((typeof runId === "number" ? !Number.isSafeInteger(runId) : !isPushRunId(runId)) || !values.query) throw usage("search-logs requires a valid ID and --query");
@@ -236,9 +242,18 @@ export function renderError({ error = "", code, next, ...extra }, now = Date.now
236
242
  next: `Tell the human the monthly limit is reached and resets on ${resetsOn}. Do not retry.`, ...extra, resetsOn };
237
243
  }
238
244
  if (code === "payment_required") {
239
- return { error: "The 300-minute NotusCI trial is used up. Set up billing to continue.", code,
245
+ return { error: "This account's NotusCI minutes are used up (Free: 1,000 a month; the Pro trial: 3,000). Upgrade to Pro to continue.", code,
246
+ next: `${NPX} billing`, ...extra };
247
+ }
248
+ if (code === "card_required") {
249
+ return { error: "This is the GitHub user's third or later free NotusCI account, so it has no free minutes until a card is on file.", code,
240
250
  next: `${NPX} billing`, ...extra };
241
251
  }
252
+ if (code === "account_suspended") {
253
+ return { error: error || "This NotusCI account is suspended for review.", code,
254
+ next: "Stop. Tell the human the account is suspended and to write to binh@notusworks.com.", ...extra };
255
+ }
256
+ if (code === "rate_limited") return { error, code, next: "Wait a minute before the next call; tell the human if it repeats.", ...extra };
242
257
  if (code === "missing_scope") return { error, code, next: `${NPX} login --scope ${String(extra.scopes)}`, ...extra };
243
258
  /** @type {Record<string, string>} */
244
259
  const defaults = {