@cleanslop/cli 0.1.0-beta.26 → 0.1.0-beta.27

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 CHANGED
@@ -36,7 +36,7 @@ The app TypeScript / ESLint / coverage gates exclude `cli/` (`tsconfig.json`, `t
36
36
  | `report [id] [--format md\|json] [--preview]` | Fetch `cleanslop.report.v1` |
37
37
  | `setup` | Idempotent skill/rules. Never logs in, never writes a token |
38
38
  | `redeem <code>` | Redeem a promo (invite) code the human gave you for free scans (`POST /api/agent/v1/credits/redeem`). One code per account; `promo_invalid` / `promo_already_redeemed` exit 12 with an `ask_human` block. |
39
- | `billing` | Link account: print where the human subscribes, buys credits or cancels a plan on the web (`/signin/email?from=agent`) and the masked email to enter there, from `webBilling` on `GET /api/agent/v1/me`. Exits 10 with an `ask_human` block; `--json` prints `{webBilling}`. The CLI never sends the sign-in mail. Prints "Not available for this account" (exit 0) when `/me` has no `webBilling`. |
39
+ | `billing` | Link account: `POST /api/agent/v1/billing/sign-in-link` has the server email a sign-in link to the account's Link address, where the human subscribes, buys credits or cancels a plan. Prints the masked address it went to, plus `/signin/email?from=agent` and the masked email to type if it does not arrive. When the server cannot send (email login off, rate limited) or is older (404, read `webBilling` from `GET /me`), it prints only the typed-address page. The CLI never sees the link. Exits 10 with an `ask_human` block; `--json` prints `{sent, expiresAt \| reason, webBilling}`. Prints "Not available for this account" (exit 0) without `webBilling`. |
40
40
 
41
41
  ### Wait
42
42
 
@@ -38,7 +38,7 @@ Run purchase commands in the foreground with `--no-wait`, the same way as Link s
38
38
  4. On success it prints “Added … scan credits. Balance: N”. Rerun the scan.
39
39
  5. If the CLI says Link packs are not available or to contact us for credits, tell the human and stop. For a GitHub account, the `top-up` block is a checkout link instead: relay it and wait.
40
40
  6. Promo codes: if the human gives you a CleanSlop promo code, run `cleanslop redeem <code>` (MCP: `promo_redeem`). Use only a code the human typed in this session; never guess, search for, or reuse one. Each account can use one code; if the CLI says the code is not valid or already used, tell the human and stop. While the account has not used a code, the out-of-scans and `credits buy` questions also offer "Use a promo code"; if the human picks buying instead, run the command that answer gives.
41
- 7. Monthly plans (Link accounts): when an out-of-scans block or `whoami` names `cleanslop billing`, the human picks Monthly plan, or the human asks to subscribe, buy credits on the web or cancel a plan, run `cleanslop billing`. It prints a web address and a masked email and exits 10: relay both exactly. The human opens the page, types their own email and signs in from the mail. Never open the page, never type the address, never ask for the sign-in link.
41
+ 7. Monthly plans (Link accounts): run `cleanslop billing` when the human picks Monthly plan or asks to subscribe, buy credits on the web or cancel a plan. Out-of-scans blocks and `whoami` name it, but do not run it unasked: it emails the human a sign-in link. It prints where the mail went (a masked email), plus a web address to use if the mail does not arrive, and exits 10: relay it exactly. The human signs in from the mail. Never open the page, never type the address, never ask for the sign-in link.
42
42
 
43
43
  ## Relay human actions
44
44
 
@@ -1,7 +1,9 @@
1
1
  import type { CliDeps } from "../deps.js";
2
2
  import type { ParsedArgs } from "../types.js";
3
3
  /**
4
- * Where a Link account manages its plan: `/signin/email` with the masked
5
- * address to type. The human signs in there; the CLI never sends the mail.
4
+ * Where a Link account manages its plan. The server emails the sign-in link
5
+ * to the account's Link address (the CLI never sees it); when it cannot, or
6
+ * an older server has no such route, the human types the masked address at
7
+ * `/signin/email`.
6
8
  */
7
9
  export declare function runBilling(deps: CliDeps, args: ParsedArgs): Promise<number>;
@@ -2,33 +2,64 @@ import { requireToken, resolveOrigin } from "../credentials.js";
2
2
  import { actionError, EXIT_OK } from "../exit.js";
3
3
  import { httpRequest, requireOk } from "../http.js";
4
4
  import { writeJson } from "../output.js";
5
+ function webBillingFrom(raw) {
6
+ return raw?.url && raw.emailMasked ? { url: raw.url, emailMasked: raw.emailMasked } : null;
7
+ }
8
+ function typedAddressPrompt({ url, emailMasked }) {
9
+ return `To subscribe, buy credits or cancel your plan, go to ${url} and enter ${emailMasked}. You'll get a sign-in link by email.`;
10
+ }
5
11
  /**
6
- * Where a Link account manages its plan: `/signin/email` with the masked
7
- * address to type. The human signs in there; the CLI never sends the mail.
12
+ * Where a Link account manages its plan. The server emails the sign-in link
13
+ * to the account's Link address (the CLI never sees it); when it cannot, or
14
+ * an older server has no such route, the human types the masked address at
15
+ * `/signin/email`.
8
16
  */
9
17
  export async function runBilling(deps, args) {
10
18
  const origin = resolveOrigin(deps);
11
19
  const creds = requireToken(deps, origin);
12
- const result = await httpRequest(deps, origin, "GET", "/api/agent/v1/me", {
13
- token: creds.token,
14
- });
20
+ const result = await httpRequest(deps, origin, "POST", "/api/agent/v1/billing/sign-in-link", { token: creds.token });
21
+ if (result.status === 404)
22
+ return typedAddress(deps, args, origin, creds.token);
15
23
  requireOk(result);
16
- const me = (result.json ?? {});
17
- const url = me.webBilling?.url;
18
- const emailMasked = me.webBilling?.emailMasked;
19
- if (!url || !emailMasked) {
20
- if (args.json)
21
- writeJson(deps, { webBilling: null });
22
- else
23
- deps.io.stdout("Not available for this account.\n");
24
- return EXIT_OK;
24
+ const body = (result.json ?? {});
25
+ const webBilling = webBillingFrom(body.webBilling);
26
+ if (!webBilling)
27
+ return notAvailable(deps, args);
28
+ const sent = body.sent === true;
29
+ if (args.json) {
30
+ writeJson(deps, {
31
+ sent,
32
+ ...(sent ? { expiresAt: body.expiresAt ?? null } : { reason: body.reason ?? null }),
33
+ webBilling,
34
+ });
25
35
  }
36
+ const { url, emailMasked } = webBilling;
37
+ const humanPrompt = sent
38
+ ? `We emailed a sign-in link to ${emailMasked}. Open it to subscribe, buy credits or cancel your plan. It works once and expires in 15 minutes. No email? Go to ${url} and enter ${emailMasked}.`
39
+ : body.reason === "rate_limited"
40
+ ? `Sign-in links already went to ${emailMasked} in the last 15 minutes. Open the newest one to subscribe, buy credits or cancel your plan.`
41
+ : typedAddressPrompt(webBilling);
42
+ throw actionError("", { kind: "ask_human", humanPrompt, url });
43
+ }
44
+ async function typedAddress(deps, args, origin, token) {
45
+ const result = await httpRequest(deps, origin, "GET", "/api/agent/v1/me", { token });
46
+ requireOk(result);
47
+ const webBilling = webBillingFrom(result.json?.webBilling);
48
+ if (!webBilling)
49
+ return notAvailable(deps, args);
26
50
  if (args.json)
27
- writeJson(deps, { webBilling: { url, emailMasked } });
51
+ writeJson(deps, { sent: false, reason: null, webBilling });
28
52
  throw actionError("", {
29
53
  kind: "ask_human",
30
- humanPrompt: `To subscribe, buy credits or cancel your plan, go to ${url} and enter ${emailMasked}. You'll get a sign-in link by email.`,
31
- url,
54
+ humanPrompt: typedAddressPrompt(webBilling),
55
+ url: webBilling.url,
32
56
  });
33
57
  }
58
+ function notAvailable(deps, args) {
59
+ if (args.json)
60
+ writeJson(deps, { webBilling: null });
61
+ else
62
+ deps.io.stdout("Not available for this account.\n");
63
+ return EXIT_OK;
64
+ }
34
65
  //# sourceMappingURL=billing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/commands/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,IAAa,EACb,IAAgB;IAEhB,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE;QACxE,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAC;IACH,SAAS,CAAC,MAAM,CAAC,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,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MAAM,CAAC,mCAAmC,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/dist/config.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export declare const PACKAGE_NAME = "@cleanslop/cli";
2
- export declare const PACKAGE_VERSION = "0.1.0-beta.26";
2
+ export declare const PACKAGE_VERSION = "0.1.0-beta.27";
3
3
  export declare const CLIENT_ID = "cleanslop-cli";
4
4
  export declare const DEFAULT_ORIGIN = "https://cleanslop.com";
5
5
  export declare const DEFAULT_WAIT_MS: number;
6
6
  export declare const MIN_POLL_MS = 3000;
7
7
  export declare const LONGPOLL_MAX_SEC = 45;
8
8
  export declare const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
9
- export declare const USER_AGENT = "cleanslop-cli/0.1.0-beta.26";
9
+ export declare const USER_AGENT = "cleanslop-cli/0.1.0-beta.27";
10
10
  export declare const CREDENTIALS_FILE = "credentials.json";
11
11
  export declare const PENDING_LOGIN_FILE = "pending-login.json";
12
12
  export declare const PENDING_SPEND_FILE = "pending-spend-request.json";
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = "@cleanslop/cli";
2
- export const PACKAGE_VERSION = "0.1.0-beta.26";
2
+ export const PACKAGE_VERSION = "0.1.0-beta.27";
3
3
  export const CLIENT_ID = "cleanslop-cli";
4
4
  export const DEFAULT_ORIGIN = "https://cleanslop.com";
5
5
  export const DEFAULT_WAIT_MS = 8 * 60 * 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanslop/cli",
3
- "version": "0.1.0-beta.26",
3
+ "version": "0.1.0-beta.27",
4
4
  "description": "CleanSlop CLI — readiness scans from your coding agent",
5
5
  "type": "module",
6
6
  "bin": {