@f-o-h/cli 0.1.1 → 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/README.md +8 -4
  2. package/dist/foh.js +215 -48
  3. package/package.json +39 -39
package/README.md CHANGED
@@ -4,7 +4,7 @@ AI-operator provisioning CLI for Front Of House.
4
4
 
5
5
  Public mirror: https://github.com/iiko38/front-of-house-cli
6
6
 
7
- Current published baseline: `@f-o-h/cli@0.1.1`
7
+ Current published baseline: `@f-o-h/cli@0.1.3`
8
8
 
9
9
  This mirror is a generated release artifact. The private product monorepo is not
10
10
  published here, and no open-source license is granted unless stated separately.
@@ -31,6 +31,7 @@ npx @f-o-h/cli --version
31
31
  ## First Run
32
32
 
33
33
  ```bash
34
+ foh auth signup --web
34
35
  foh auth login --web
35
36
  foh auth login
36
37
  foh org list
@@ -41,6 +42,7 @@ foh setup
41
42
  For AI agents and text-only terminals:
42
43
 
43
44
  ```bash
45
+ foh auth signup --web --json
44
46
  foh auth login --web --json
45
47
  foh auth login --email "$FOH_EMAIL" --password "$FOH_PASSWORD" --json
46
48
  foh org list --json
@@ -48,8 +50,10 @@ foh org use --org <org-id> --json
48
50
  foh setup --org <org-id> --agent-template <template-id> --agent-name "Demo Agent" --json
49
51
  ```
50
52
 
51
- `auth login --web` opens the console sign-in page when possible and always
52
- prints the fallback URL. The CLI still requires explicit credential auth until
53
- device-code browser-token exchange is available.
53
+ `auth signup --web` opens the console signup page when possible and always
54
+ prints the fallback URL. `auth login --web` starts browser device
55
+ authorization, opens `/cli-auth`, waits for console approval, and stores the
56
+ returned short-lived token. Credential auth remains available as fallback.
54
57
 
55
58
  The CLI defaults to the production API at `https://api.frontofhouse.okii.uk`.
59
+
package/dist/foh.js CHANGED
@@ -10146,7 +10146,10 @@ function resolveConsoleBaseUrl(cliOverride) {
10146
10146
  return normalizeBaseUrl(cliOverride ?? process.env.FOH_CONSOLE_URL);
10147
10147
  }
10148
10148
  function buildConsoleSignInUrl(consoleUrl) {
10149
- return `${normalizeBaseUrl(consoleUrl)}/sign-in?source=cli`;
10149
+ return `${normalizeBaseUrl(consoleUrl)}/sign-in?redirect=%2Fdashboard`;
10150
+ }
10151
+ function buildConsoleSignUpUrl(consoleUrl) {
10152
+ return `${normalizeBaseUrl(consoleUrl)}/sign-up?redirect=%2Fdashboard`;
10150
10153
  }
10151
10154
  function buildCliAuthFallbackCommands() {
10152
10155
  return [
@@ -10160,16 +10163,32 @@ function buildCliAuthFallbackInstructions(signInUrl) {
10160
10163
  human: [
10161
10164
  `Open ${signInUrl}`,
10162
10165
  "Sign in to Front Of House.",
10163
- "Return to the terminal and authenticate the CLI with email/password until browser-token exchange is available."
10166
+ "Return to the terminal. If device approval is unavailable, authenticate the CLI with email/password."
10164
10167
  ],
10165
10168
  ai_agent: [
10166
10169
  "Show the sign_in_url to the user if browser opening is unavailable.",
10167
- "Ask the user for FOH email/password or an approved service-token path.",
10170
+ "Prefer browser device approval. Ask for email/password only if device approval is unavailable.",
10168
10171
  "Run the explicit CLI auth commands in next_commands.",
10169
10172
  "Never scrape browser cookies or local storage."
10170
10173
  ]
10171
10174
  };
10172
10175
  }
10176
+ function buildCliSignupFallbackInstructions(signUpUrl) {
10177
+ return {
10178
+ human: [
10179
+ `Open ${signUpUrl}`,
10180
+ "Create a Front Of House account.",
10181
+ "Confirm your email if prompted.",
10182
+ "Return to the terminal and run `foh auth login --web --json`."
10183
+ ],
10184
+ ai_agent: [
10185
+ "Show the sign_up_url to the user if browser opening is unavailable.",
10186
+ "Ask the user to complete signup and email confirmation in the browser.",
10187
+ "After the user confirms signup, run `foh auth login --web --json`.",
10188
+ "Never ask the user to paste browser cookies or local storage."
10189
+ ]
10190
+ };
10191
+ }
10173
10192
 
10174
10193
  // src/lib/open-url.ts
10175
10194
  var import_child_process = require("child_process");
@@ -10208,11 +10227,41 @@ function emitBrowserAuthLink(opts) {
10208
10227
  opener_command: openResult.command,
10209
10228
  opener_error: openResult.error ?? null,
10210
10229
  cli_auth_required: true,
10211
- note: "Browser sign-in opens the console. Until device-code auth is implemented, authenticate this CLI with the explicit credential command after sign-in.",
10230
+ note: "Browser device auth is unavailable from this API. Authenticate this CLI with the explicit credential command after sign-in.",
10212
10231
  next_commands: nextCommands,
10213
10232
  text_fallback: buildCliAuthFallbackInstructions(signInUrl)
10214
10233
  }, { json: opts.json ?? false });
10215
10234
  }
10235
+ function writeDeviceProgress(event, jsonMode) {
10236
+ const line = jsonMode ? JSON.stringify({ event: "device_auth_started", ...event }, null, 2) : [
10237
+ "Browser auth started.",
10238
+ `Open: ${event["verification_uri_complete"]}`,
10239
+ `Code: ${event["user_code"]}`,
10240
+ "Waiting for browser approval..."
10241
+ ].join("\n");
10242
+ const stream = jsonMode ? process.stderr : process.stdout;
10243
+ stream.write(`${line}
10244
+ `);
10245
+ }
10246
+ function emitBrowserSignupLink(opts) {
10247
+ const consoleUrl = resolveConsoleBaseUrl(opts.consoleUrl);
10248
+ const signUpUrl = buildConsoleSignUpUrl(consoleUrl);
10249
+ const openResult = openUrl(signUpUrl);
10250
+ format({
10251
+ status: openResult.attempted ? "browser_signup_link_opened" : "browser_signup_link",
10252
+ sign_up_url: signUpUrl,
10253
+ opened: openResult.attempted,
10254
+ opener_command: openResult.command,
10255
+ opener_error: openResult.error ?? null,
10256
+ cli_auth_required_after_signup: true,
10257
+ note: "Signup is completed in the FOH console. After account creation and email confirmation, return to the CLI and authenticate.",
10258
+ next_commands: [
10259
+ "foh auth login --web --json",
10260
+ ...buildCliAuthFallbackCommands()
10261
+ ],
10262
+ text_fallback: buildCliSignupFallbackInstructions(signUpUrl)
10263
+ }, { json: opts.json ?? false });
10264
+ }
10216
10265
  async function resolveLoginInputs(opts) {
10217
10266
  let email3 = String(opts.email ?? "").trim();
10218
10267
  let password = String(opts.password ?? "").trim();
@@ -10269,13 +10318,154 @@ async function maybeSelectDefaultOrg(orgs, jsonMode) {
10269
10318
  `);
10270
10319
  }
10271
10320
  }
10321
+ async function fetchOrgMemberships(apiUrl, token) {
10322
+ try {
10323
+ const orgsRes = await fetch(`${apiUrl}/v1/console/auth/my-orgs`, {
10324
+ headers: { Authorization: `Bearer ${token}` }
10325
+ });
10326
+ if (orgsRes.ok) {
10327
+ const orgsData = await orgsRes.json();
10328
+ return {
10329
+ orgs: Array.isArray(orgsData.orgs) ? orgsData.orgs : [],
10330
+ available: true
10331
+ };
10332
+ }
10333
+ } catch {
10334
+ }
10335
+ return { orgs: [], available: false };
10336
+ }
10337
+ async function storeAuthenticatedSession(params) {
10338
+ const { orgs, available } = await fetchOrgMemberships(params.apiUrl, params.token);
10339
+ let autoOrgId;
10340
+ const usableOrgs = orgs.filter((org) => isUsableOrgId(org.org_id));
10341
+ if (usableOrgs.length === 1) {
10342
+ autoOrgId = usableOrgs[0].org_id;
10343
+ } else if (usableOrgs.length > 1) {
10344
+ autoOrgId = await maybeSelectDefaultOrg(orgs, params.jsonMode);
10345
+ }
10346
+ saveCredentials({
10347
+ apiUrl: params.apiUrl,
10348
+ token: params.token,
10349
+ expiresAt: params.expiresAt,
10350
+ orgId: autoOrgId
10351
+ });
10352
+ const output = {
10353
+ status: "authenticated",
10354
+ apiUrl: params.apiUrl,
10355
+ expires_at: params.expiresAt
10356
+ };
10357
+ if (autoOrgId) {
10358
+ output["default_org_id"] = autoOrgId;
10359
+ output["note"] = "Default org stored; --org flag is now optional.";
10360
+ } else if (orgs.length > 1) {
10361
+ output["note"] = `${orgs.length} orgs found. Run: foh org use --org <id> to set a default.`;
10362
+ } else if (orgs.length === 0 && available) {
10363
+ output["note"] = "No orgs found. Run: foh org create --name <name> to create one.";
10364
+ } else {
10365
+ output["note"] = "Authenticated, but org discovery is unavailable. Run: foh org list when API connectivity is healthy.";
10366
+ }
10367
+ return output;
10368
+ }
10369
+ function sleep(ms) {
10370
+ return new Promise((resolve5) => setTimeout(resolve5, ms));
10371
+ }
10372
+ async function runDeviceLogin(opts) {
10373
+ const jsonMode = Boolean(opts.json);
10374
+ let startRes;
10375
+ try {
10376
+ startRes = await fetch(`${opts.apiUrl}/v1/console/auth/device/start`, {
10377
+ method: "POST",
10378
+ headers: { "Content-Type": "application/json" },
10379
+ body: JSON.stringify({ client: "foh-cli" })
10380
+ });
10381
+ } catch {
10382
+ emitBrowserAuthLink({
10383
+ consoleUrl: opts.consoleUrl,
10384
+ json: opts.json
10385
+ });
10386
+ return;
10387
+ }
10388
+ if (!startRes.ok) {
10389
+ emitBrowserAuthLink({
10390
+ consoleUrl: opts.consoleUrl,
10391
+ json: opts.json
10392
+ });
10393
+ return;
10394
+ }
10395
+ const start = await startRes.json();
10396
+ const openResult = openUrl(start.verification_uri_complete);
10397
+ const startedPacket = {
10398
+ status: "browser_device_auth_started",
10399
+ sign_in_url: start.verification_uri_complete,
10400
+ verification_uri: start.verification_uri,
10401
+ verification_uri_complete: start.verification_uri_complete,
10402
+ user_code: start.user_code,
10403
+ opened: openResult.attempted,
10404
+ opener_command: openResult.command,
10405
+ opener_error: openResult.error ?? null,
10406
+ expires_in: start.expires_in,
10407
+ poll_interval_seconds: start.interval
10408
+ };
10409
+ if (opts.wait === false) {
10410
+ format({
10411
+ ...startedPacket,
10412
+ next_commands: [
10413
+ "Complete approval in the opened browser window.",
10414
+ "Then rerun: foh auth login --web --json"
10415
+ ]
10416
+ }, { json: jsonMode });
10417
+ return;
10418
+ }
10419
+ writeDeviceProgress(startedPacket, jsonMode);
10420
+ const timeoutSeconds = Math.max(1, Number(opts.timeoutSeconds ?? start.expires_in) || start.expires_in);
10421
+ const deadline = Date.now() + Math.min(timeoutSeconds, start.expires_in) * 1e3;
10422
+ const intervalMs = Math.max(0.05, Number(start.interval) || 2) * 1e3;
10423
+ while (Date.now() < deadline) {
10424
+ await sleep(intervalMs);
10425
+ const pollRes = await fetch(`${opts.apiUrl}/v1/console/auth/device/poll`, {
10426
+ method: "POST",
10427
+ headers: { "Content-Type": "application/json" },
10428
+ body: JSON.stringify({ device_code: start.device_code })
10429
+ });
10430
+ const poll = await pollRes.json().catch(() => ({}));
10431
+ if (pollRes.status === 202 || poll.status === "authorization_pending") {
10432
+ continue;
10433
+ }
10434
+ if (pollRes.ok && poll.token && poll.expires_at) {
10435
+ const output = await storeAuthenticatedSession({
10436
+ apiUrl: opts.apiUrl,
10437
+ token: poll.token,
10438
+ expiresAt: poll.expires_at,
10439
+ jsonMode
10440
+ });
10441
+ format({
10442
+ ...output,
10443
+ auth_method: "browser_device"
10444
+ }, { json: jsonMode });
10445
+ return;
10446
+ }
10447
+ throw new FohError({
10448
+ step: "auth.login.web",
10449
+ error: poll.error || poll.code || `HTTP ${pollRes.status}`,
10450
+ remediation: "Restart browser auth with: foh auth login --web"
10451
+ });
10452
+ }
10453
+ throw new FohError({
10454
+ step: "auth.login.web",
10455
+ error: "Timed out waiting for browser approval",
10456
+ remediation: "Complete browser approval faster, or rerun: foh auth login --web"
10457
+ });
10458
+ }
10272
10459
  function registerAuth(program3) {
10273
10460
  const auth = program3.command("auth").description("Manage CLI authentication");
10274
- auth.command("login").description("Authenticate with the FOH API and store a token locally").option("--email <email>", "FOH account email").option("--password <password>", "FOH account password").option("--web", "Open browser sign-in and print text fallback commands").option("--browser", "Alias for --web").option("--wizard", "Run guided login wizard prompts").option("--console-url <url>", "Console sign-in URL override").option("--api-url <url>", "Internal API base URL override (operators only)").option("--json", "Output as JSON").action(async (opts) => withCommandErrorHandling(async () => {
10461
+ auth.command("login").description("Authenticate with the FOH API and store a token locally").option("--email <email>", "FOH account email").option("--password <password>", "FOH account password").option("--web", "Open browser sign-in and print text fallback commands").option("--browser", "Alias for --web").option("--wizard", "Run guided login wizard prompts").option("--console-url <url>", "Console sign-in URL override").option("--api-url <url>", "Internal API base URL override (operators only)").option("--timeout-seconds <seconds>", "Maximum seconds to wait for browser approval").option("--no-wait", "Only print/open the browser approval link; do not poll").option("--json", "Output as JSON").action(async (opts) => withCommandErrorHandling(async () => {
10275
10462
  if ((opts.web || opts.browser) && !opts.email && !opts.password) {
10276
- emitBrowserAuthLink({
10463
+ await runDeviceLogin({
10464
+ apiUrl: resolveApiBaseUrl(opts.apiUrl),
10277
10465
  consoleUrl: opts.consoleUrl,
10278
- json: opts.json
10466
+ json: opts.json,
10467
+ wait: opts.wait,
10468
+ timeoutSeconds: opts.timeoutSeconds
10279
10469
  });
10280
10470
  return;
10281
10471
  }
@@ -10309,44 +10499,20 @@ function registerAuth(program3) {
10309
10499
  });
10310
10500
  }
10311
10501
  const data = await res.json();
10312
- let orgs = [];
10313
- let orgDiscoveryAvailable = false;
10314
- try {
10315
- const orgsRes = await fetch(`${apiUrl}/v1/console/auth/my-orgs`, {
10316
- headers: { Authorization: `Bearer ${data.token}` }
10317
- });
10318
- if (orgsRes.ok) {
10319
- const orgsData = await orgsRes.json();
10320
- orgs = Array.isArray(orgsData.orgs) ? orgsData.orgs : [];
10321
- orgDiscoveryAvailable = true;
10322
- }
10323
- } catch {
10324
- }
10325
- let autoOrgId;
10326
- const usableOrgs = orgs.filter((org) => isUsableOrgId(org.org_id));
10327
- if (usableOrgs.length === 1) {
10328
- autoOrgId = usableOrgs[0].org_id;
10329
- } else if (usableOrgs.length > 1) {
10330
- autoOrgId = await maybeSelectDefaultOrg(orgs, Boolean(opts.json));
10331
- }
10332
- saveCredentials({ apiUrl, token: data.token, expiresAt: data.expires_at, orgId: autoOrgId });
10333
- const output = {
10334
- status: "authenticated",
10502
+ const output = await storeAuthenticatedSession({
10335
10503
  apiUrl,
10336
- expires_at: data.expires_at
10337
- };
10338
- if (autoOrgId) {
10339
- output["default_org_id"] = autoOrgId;
10340
- output["note"] = "Default org stored; --org flag is now optional.";
10341
- } else if (orgs.length > 1) {
10342
- output["note"] = `${orgs.length} orgs found. Run: foh org use --org <id> to set a default.`;
10343
- } else if (orgs.length === 0 && orgDiscoveryAvailable) {
10344
- output["note"] = "No orgs found. Run: foh org create --name <name> to create one.";
10345
- } else {
10346
- output["note"] = "Authenticated, but org discovery is unavailable. Run: foh org list when API connectivity is healthy.";
10347
- }
10504
+ token: data.token,
10505
+ expiresAt: data.expires_at,
10506
+ jsonMode: Boolean(opts.json)
10507
+ });
10348
10508
  format(output, { json: opts.json ?? false });
10349
10509
  }));
10510
+ auth.command("signup").description("Open account signup and print text fallback commands").option("--web", "Open browser signup and print text fallback commands", true).option("--browser", "Alias for --web").option("--console-url <url>", "Console signup URL override").option("--json", "Output as JSON").action((opts) => {
10511
+ emitBrowserSignupLink({
10512
+ consoleUrl: opts.consoleUrl,
10513
+ json: opts.json
10514
+ });
10515
+ });
10350
10516
  auth.command("logout").description("Remove stored credentials").option("--json", "Output as JSON").action((opts) => {
10351
10517
  clearCredentials();
10352
10518
  format({ status: "logged_out" }, { json: opts.json ?? false });
@@ -10735,10 +10901,10 @@ async function pollUntil(check2, opts) {
10735
10901
  const label = opts.label ?? step;
10736
10902
  process.stderr.write(import_picocolors2.default.dim(` ${label}: waiting... (${Math.round(elapsed / 1e3)}s)
10737
10903
  `));
10738
- await sleep(opts.intervalMs);
10904
+ await sleep2(opts.intervalMs);
10739
10905
  }
10740
10906
  }
10741
- function sleep(ms) {
10907
+ function sleep2(ms) {
10742
10908
  return new Promise((resolve5) => setTimeout(resolve5, ms));
10743
10909
  }
10744
10910
 
@@ -32184,7 +32350,7 @@ var StdioServerTransport = class {
32184
32350
  };
32185
32351
 
32186
32352
  // src/lib/cli-version.ts
32187
- var CLI_VERSION = "0.1.1";
32353
+ var CLI_VERSION = "0.1.3";
32188
32354
 
32189
32355
  // src/commands/mcp-serve.ts
32190
32356
  var DEFAULT_TIMEOUT_MS = 12e4;
@@ -33702,6 +33868,7 @@ function buildMissingOptionsPlan(missing, opts) {
33702
33868
  reason: "setup requires an authenticated org, an agent template, and an agent name before it can mutate customer resources",
33703
33869
  sign_in_url: signInUrl,
33704
33870
  next_commands: [
33871
+ "foh auth signup --web --json",
33705
33872
  "foh auth login --web --json",
33706
33873
  ...buildCliAuthFallbackCommands(),
33707
33874
  "foh templates list --json",
@@ -35803,7 +35970,7 @@ async function runGuidedStart(apiUrlOverride, executeCommand) {
35803
35970
  }
35804
35971
  if (!state.orgId) {
35805
35972
  process.stdout.write("Step 2/3: Set default org\n");
35806
- const orgs = await fetchOrgMemberships(apiUrlOverride);
35973
+ const orgs = await fetchOrgMemberships2(apiUrlOverride);
35807
35974
  if (orgs.length === 1) {
35808
35975
  const code = await executeCommand(["org", "use", "--org", orgs[0].org_id], apiUrlOverride);
35809
35976
  if (code !== 0) process.stdout.write(`org use exited with code ${code}.
@@ -35829,7 +35996,7 @@ async function runGuidedStart(apiUrlOverride, executeCommand) {
35829
35996
  process.stdout.write(`org create exited with code ${createCode}.
35830
35997
  `);
35831
35998
  } else {
35832
- const refreshedOrgs = await fetchOrgMemberships(apiUrlOverride);
35999
+ const refreshedOrgs = await fetchOrgMemberships2(apiUrlOverride);
35833
36000
  if (refreshedOrgs.length === 1) {
35834
36001
  const useCode = await executeCommand(["org", "use", "--org", refreshedOrgs[0].org_id], apiUrlOverride);
35835
36002
  if (useCode !== 0) process.stdout.write(`org use exited with code ${useCode}.
@@ -35859,7 +36026,7 @@ async function maybeRunTenantStatus(apiUrlOverride, executeCommand) {
35859
36026
  `);
35860
36027
  }
35861
36028
  }
35862
- async function fetchOrgMemberships(apiUrlOverride) {
36029
+ async function fetchOrgMemberships2(apiUrlOverride) {
35863
36030
  try {
35864
36031
  const creds = loadCredentials(apiUrlOverride);
35865
36032
  const res = await fetch(`${creds.apiUrl}/v1/console/auth/my-orgs`, {
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@f-o-h/cli",
3
- "version": "0.1.1",
4
- "description": "FOH CLI - AI-operator provisioning tool for Front Of House",
5
- "license": "UNLICENSED",
6
- "bin": {
7
- "foh": "dist/foh.js"
8
- },
9
- "main": "dist/foh.js",
10
- "files": [
11
- "dist/",
12
- "README.md",
13
- "package.json"
14
- ],
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "engines": {
19
- "node": ">=18"
20
- },
21
- "scripts": {
22
- "build": "node build.mjs",
23
- "test": "vitest run",
24
- "typecheck": "tsc --noEmit"
25
- },
26
- "dependencies": {
27
- "@modelcontextprotocol/sdk": "^1.29.0",
28
- "commander": "^12.1.0",
29
- "js-yaml": "^4.1.1",
30
- "picocolors": "^1.1.1",
31
- "zod": "^4.3.6"
32
- },
33
- "devDependencies": {
34
- "@types/js-yaml": "^4.0.9",
35
- "@types/node": "^22.0.0",
36
- "esbuild": "^0.24.0",
37
- "vitest": "^2.0.0"
38
- }
39
- }
1
+ {
2
+ "name": "@f-o-h/cli",
3
+ "version": "0.1.3",
4
+ "description": "FOH CLI - AI-operator provisioning tool for Front Of House",
5
+ "license": "UNLICENSED",
6
+ "bin": {
7
+ "foh": "dist/foh.js"
8
+ },
9
+ "main": "dist/foh.js",
10
+ "files": [
11
+ "dist/",
12
+ "README.md",
13
+ "package.json"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "scripts": {
22
+ "build": "node build.mjs",
23
+ "test": "vitest run",
24
+ "typecheck": "tsc --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^1.29.0",
28
+ "commander": "^12.1.0",
29
+ "js-yaml": "^4.1.1",
30
+ "picocolors": "^1.1.1",
31
+ "zod": "^4.3.6"
32
+ },
33
+ "devDependencies": {
34
+ "@types/js-yaml": "^4.0.9",
35
+ "@types/node": "^22.0.0",
36
+ "esbuild": "^0.24.0",
37
+ "vitest": "^2.0.0"
38
+ }
39
+ }