@discourse/create-site 0.0.0-stage → 0.1.0
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/AGENTS.md +66 -0
- package/LICENSE +21 -0
- package/README.md +102 -2
- package/dist/api.d.ts +100 -0
- package/dist/api.js +449 -0
- package/dist/api.js.map +1 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +53 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +368 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/common.d.ts +17 -0
- package/dist/commands/common.js +126 -0
- package/dist/commands/common.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +605 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/info.d.ts +2 -0
- package/dist/commands/info.js +61 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +119 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config.d.ts +49 -0
- package/dist/config.js +151 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +27 -0
- package/dist/mcp.js +129 -0
- package/dist/mcp.js.map +1 -0
- package/dist/output.d.ts +15 -0
- package/dist/output.js +27 -0
- package/dist/output.js.map +1 -0
- package/dist/prompts.d.ts +24 -0
- package/dist/prompts.js +63 -0
- package/dist/prompts.js.map +1 -0
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +233 -0
- package/dist/runner.js.map +1 -0
- package/dist/store.d.ts +44 -0
- package/dist/store.js +121 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Agent Playbook: `@discourse/create-site`
|
|
2
|
+
|
|
3
|
+
Follow this playbook when provisioning a Discourse hosted site on behalf of a user. Your goal is to minimize user round-trips and never leak credentials or bypass legal terms acceptance.
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
1. **Always pass `--json`** so the CLI never blocks waiting for interactive stdin and returns structured exit codes (`0` = done, `1` = error, `2` = user action required).
|
|
8
|
+
2. **Two-step create flow:** Ask ONLY for community name and plan first, then show the plan-specific terms URLs in a separate confirmation message before creating the site.
|
|
9
|
+
3. **Never invent or auto-accept legal terms.** Only pass `--accept-terms` and `--accept-account-terms` after the user explicitly confirms the URLs returned in Step 2 (`terms_urls`).
|
|
10
|
+
4. **Skip subdomain and region by default:** Subdomain is automatically generated from the community name (with automatic collision retry), and region defaults to `global`. Only pass `--subdomain` or `--region` if the user explicitly asks to customize them.
|
|
11
|
+
5. **Never inspect or echo `state.json`.** Raw `access_token` and `device_code` values are intentionally omitted from CLI output.
|
|
12
|
+
|
|
13
|
+
## Minimal Agent Flow
|
|
14
|
+
|
|
15
|
+
### 1. Authenticate (if needed) & check Step 1 options
|
|
16
|
+
Run:
|
|
17
|
+
```bash
|
|
18
|
+
discourse-create-site create --json
|
|
19
|
+
```
|
|
20
|
+
- If exit code is `2` with `code: "auth_required"`:
|
|
21
|
+
- Present `verification_uri_complete` and `user_code` to the user and ask them to approve in their browser (or re-run `auth start --signup --json` if they need a new Discourse ID account).
|
|
22
|
+
- Once they approve, run `discourse-create-site auth poll --json`, then re-run `discourse-create-site create --json`.
|
|
23
|
+
- If exit code is `2` with `code: "missing_input"` (`step: 1`):
|
|
24
|
+
- From `available_plans`, ask the user **ONLY** for:
|
|
25
|
+
- Community name (`--name`)
|
|
26
|
+
- Desired plan (`--plan`: `free`, `pro`, `business`; mention trial duration for paid plans)
|
|
27
|
+
- Do **not** ask for subdomain or server region unless the user brings them up.
|
|
28
|
+
|
|
29
|
+
### 2. Fetch Step 2 terms for the chosen plan
|
|
30
|
+
Run:
|
|
31
|
+
```bash
|
|
32
|
+
discourse-create-site create \
|
|
33
|
+
--name "<Community Name>" \
|
|
34
|
+
--plan <plan> \
|
|
35
|
+
[--subdomain "<custom-slug>"] \
|
|
36
|
+
[--region <global|eu>] \
|
|
37
|
+
--json
|
|
38
|
+
```
|
|
39
|
+
- This exits `2` with `code: "terms_required"` (`step: 2`), returning the exact `terms_urls` for the chosen plan (`terms_urls.hosting`, plus `terms_urls.user` when `user_terms_needed` is `true`).
|
|
40
|
+
- Show the user those exact URL(s) in a separate confirmation step and ask them to agree.
|
|
41
|
+
|
|
42
|
+
### 3. Provision the site
|
|
43
|
+
Once confirmed, run:
|
|
44
|
+
```bash
|
|
45
|
+
discourse-create-site create \
|
|
46
|
+
--name "<Community Name>" \
|
|
47
|
+
--plan <plan> \
|
|
48
|
+
--accept-terms \
|
|
49
|
+
[--accept-account-terms] \
|
|
50
|
+
[--subdomain "<custom-slug>"] \
|
|
51
|
+
[--region <global|eu>] \
|
|
52
|
+
--json
|
|
53
|
+
```
|
|
54
|
+
- Only pass `--accept-account-terms` when `user_terms_needed` was `true`.
|
|
55
|
+
- If an explicit `--subdomain` fails with exit `2` (`code: "subdomain_taken"`), ask the user for another `--subdomain` and re-run `create`.
|
|
56
|
+
- Otherwise exit `0` returns:
|
|
57
|
+
- `redirect_url`: One-time admin sign-in invite link (share ONLY this URL with the user)
|
|
58
|
+
- `user_handoff`: Reminder to share only `redirect_url`
|
|
59
|
+
- `mcp_setup`: Machine-readable MCP setup guidance (`admin_mcp_url`, `site_setting`, `transport`, `mcp_endpoint`, `oauth_metadata_url`, `user_prompt_suggestion`, `agent_instructions`, `detected_client`, `steps`, `client_instructions`)
|
|
60
|
+
|
|
61
|
+
### 4. Post-provisioning handoff
|
|
62
|
+
Share cleanly with the user in this order:
|
|
63
|
+
1. **Share ONLY `redirect_url`** as a clickable link to open the new site (do not also share the bare `https://<subdomain>.discourse.group` URL, because the user must open `redirect_url` directly to claim and sign in to their admin account).
|
|
64
|
+
2. Next, tell the user that once admin sign-in is complete, they should enable MCP (`mcp_server_enabled`) at a clickable link to `mcp_setup.admin_mcp_url` (`<site_origin>/admin/config/mcp/settings`).
|
|
65
|
+
3. **Do NOT tell the user to run a separate CLI command outside the session.** Instead, tell them to reply `"now add mcp support"` once MCP is enabled.
|
|
66
|
+
4. When the user replies `"now add mcp support"`, follow `mcp_setup.agent_instructions` (using `mcp_setup.client_instructions` as reference if applicable) to add MCP for `mcp_setup.mcp_endpoint` directly.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Civilized Discourse Construction Kit, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @discourse/create-site
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Agent-friendly CLI wizard to provision hosted Discourse communities via Discourse ID OAuth 2.0 Device Authorization Grant (RFC 8628).
|
|
4
|
+
|
|
5
|
+
Designed primarily for LLM coding agents (`--json` mode with structured exit code `2` handoffs and zero secret leakage) while also supporting a minimal interactive TTY wizard for humans.
|
|
6
|
+
|
|
7
|
+
## Quick Start (Interactive)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx -y @discourse/create-site
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Agent Workflow (`--json`)
|
|
14
|
+
|
|
15
|
+
In `--json` or non-TTY mode, the CLI **never blocks waiting for stdin** and **never prints `access_token` or `device_code` to stdout**. Credentials are stored per host with `0600` permissions in `~/.config/discourse-create-site/state.json`.
|
|
16
|
+
|
|
17
|
+
### Exit Codes
|
|
18
|
+
- `0`: Success
|
|
19
|
+
- `1`: Fatal or configuration error (`invalid_arguments`, `invalid_input`, `provisioning_disabled`, `expired_token`, `access_denied`, network/API error)
|
|
20
|
+
- `2`: Action required from the end user (`auth_required`, `authorization_pending`, `missing_input`, `terms_required`, `subdomain_taken`)
|
|
21
|
+
|
|
22
|
+
### Step-by-Step Agent Flow
|
|
23
|
+
|
|
24
|
+
1. **Check session & plans (or start device login if unauthenticated):**
|
|
25
|
+
```bash
|
|
26
|
+
discourse-create-site create --json
|
|
27
|
+
```
|
|
28
|
+
If unauthenticated, exits `2` with:
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"ok": false,
|
|
32
|
+
"status": "action_required",
|
|
33
|
+
"code": "auth_required",
|
|
34
|
+
"user_code": "ABCD-EFGH",
|
|
35
|
+
"verification_uri": "https://id.discourse.com/oauth/device",
|
|
36
|
+
"verification_uri_complete": "https://id.discourse.com/oauth/device?user_code=ABCD-EFGH",
|
|
37
|
+
"expires_in": 600,
|
|
38
|
+
"interval": 5
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
Ask the user to open `verification_uri_complete` and confirm `user_code`. Pass `--signup` if the user needs to create a new Discourse ID account first.
|
|
42
|
+
|
|
43
|
+
2. **Complete device authorization:**
|
|
44
|
+
```bash
|
|
45
|
+
discourse-create-site auth poll --json
|
|
46
|
+
```
|
|
47
|
+
(Or use `--no-wait` for a single non-blocking poll returning exit `2` `authorization_pending` while waiting.)
|
|
48
|
+
|
|
49
|
+
3. **Step 1 — Collect community name & plan:**
|
|
50
|
+
Running `create --json` with missing inputs exits `2` (`step: 1`, `code: "missing_input"`) returning `available_plans`. Ask the user ONLY for their community name and desired plan (subdomain is auto-generated from the name unless they explicitly request `--subdomain`; region defaults to `global` unless overridden with `--region`).
|
|
51
|
+
|
|
52
|
+
4. **Step 2 — Show plan-specific terms & provision:**
|
|
53
|
+
Run with `--name` and `--plan` (without `--accept-terms` yet):
|
|
54
|
+
```bash
|
|
55
|
+
discourse-create-site create --name "My Community" --plan free --json
|
|
56
|
+
```
|
|
57
|
+
This exits `2` (`step: 2`, `code: "terms_required"`) with the exact `terms_urls` for that plan (`free-terms` or `trial-terms`, plus `user` 18+ terms if needed). After the user confirms, re-run with acceptance flags:
|
|
58
|
+
```bash
|
|
59
|
+
discourse-create-site create \
|
|
60
|
+
--name "My Community" \
|
|
61
|
+
--plan free \
|
|
62
|
+
--accept-terms \
|
|
63
|
+
--accept-account-terms \
|
|
64
|
+
--json
|
|
65
|
+
```
|
|
66
|
+
Pass `--subdomain <slug>` and `--region <global|eu>` only if requested (or `--customize` in interactive TTY mode to be prompted for them). On completion, exits `0` with `redirect_url` (one-time admin sign-in invite link), `user_handoff` guidance (share ONLY `redirect_url` directly with the user, not the bare site URL), and `mcp_setup` tailored to the detected agent client or generic Streamable HTTP MCP configuration.
|
|
67
|
+
|
|
68
|
+
## Commands
|
|
69
|
+
|
|
70
|
+
- `discourse-create-site [create] [options]` — Provision a new community (default command)
|
|
71
|
+
- `discourse-create-site auth [options]` — Interactive device auth + poll
|
|
72
|
+
- `discourse-create-site auth start [--signup] [--open] [--json]` — Start device auth without blocking
|
|
73
|
+
- `discourse-create-site auth poll [--no-wait] [--timeout <s>] [--json]` — Poll for token completion
|
|
74
|
+
- `discourse-create-site auth status [--json]` — Check active token status
|
|
75
|
+
- `discourse-create-site auth logout [--all] [--json]` — Remove stored credentials
|
|
76
|
+
- `discourse-create-site info [--json]` — Show account details, terms status, and available plans
|
|
77
|
+
- `discourse-create-site status <token> [--wait] [--json]` — Check or wait for site readiness
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
| Flag | Environment Variable | Description | Default |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
| `--id-url` | `DISCOURSE_ID_URL` | Discourse ID base URL | `https://id.discourse.com` |
|
|
84
|
+
| `--client-id` | `DISCOURSE_ID_CLIENT_ID` | Non-confidential OAuth `client_id` | Built-in default for https://id.discourse.com |
|
|
85
|
+
| `--config-dir` | `DISCOURSE_CREATE_SITE_CONFIG_DIR` | Credential storage dir | `$XDG_CONFIG_HOME/discourse-create-site` or `~/.config/discourse-create-site` |
|
|
86
|
+
| `--token` | `DISCOURSE_ID_TOKEN` | Explicit Bearer access token | Stored host token |
|
|
87
|
+
|
|
88
|
+
## Post-Provisioning MCP Setup
|
|
89
|
+
|
|
90
|
+
Newly provisioned sites do not enable Discourse's built-in MCP server by default yet. Once the user opens `redirect_url` directly and finishes admin sign-in:
|
|
91
|
+
|
|
92
|
+
1. Visit `<site_origin>/admin/config/mcp/settings` and enable MCP (`mcp_server_enabled`).
|
|
93
|
+
2. Reply `"now add mcp support"` inside your AI agent session so the agent configures `<site_origin>/mcp` (Streamable HTTP, OAuth discovery at `<site_origin>/.well-known/oauth-protected-resource/mcp`) for you without needing to run an external CLI command.
|
|
94
|
+
|
|
95
|
+
`mcp_setup` in `--json` output includes `admin_mcp_url`, `user_prompt_suggestion` (`"now add mcp support"`), `agent_instructions`, and `client_instructions` as a reference for the detected agent client (or generic Streamable HTTP configuration).
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm install
|
|
101
|
+
npm run typecheck
|
|
102
|
+
npm test
|
|
103
|
+
```
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Plan, type PricingData, type Region } from "./config.js";
|
|
2
|
+
import type { PendingDeviceAuth, StoredToken } from "./store.js";
|
|
3
|
+
import type { FetchLike, NowLike, SleepLike } from "./types.js";
|
|
4
|
+
export declare class ApiError extends Error {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly errors: string[];
|
|
8
|
+
readonly retryAfterSeconds?: number | undefined;
|
|
9
|
+
constructor(status: number, code: string, errors: string[], retryAfterSeconds?: number | undefined);
|
|
10
|
+
}
|
|
11
|
+
export interface DeviceAuthResponse {
|
|
12
|
+
device_code: string;
|
|
13
|
+
user_code: string;
|
|
14
|
+
verification_uri: string;
|
|
15
|
+
verification_uri_complete: string;
|
|
16
|
+
expires_in: number;
|
|
17
|
+
interval: number;
|
|
18
|
+
}
|
|
19
|
+
export type DevicePollResult = {
|
|
20
|
+
status: "approved";
|
|
21
|
+
token: StoredToken;
|
|
22
|
+
} | {
|
|
23
|
+
status: "authorization_pending";
|
|
24
|
+
} | {
|
|
25
|
+
status: "slow_down";
|
|
26
|
+
} | {
|
|
27
|
+
status: "expired_token";
|
|
28
|
+
} | {
|
|
29
|
+
status: "access_denied";
|
|
30
|
+
} | {
|
|
31
|
+
status: "invalid_grant";
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
export interface CliInfoUser {
|
|
35
|
+
email: string;
|
|
36
|
+
username: string;
|
|
37
|
+
preferred_username?: string | null;
|
|
38
|
+
age_terms_agreed: boolean;
|
|
39
|
+
user_terms_agreed: boolean;
|
|
40
|
+
identity_setup_complete: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface CliInfoResponse {
|
|
43
|
+
provisioning_enabled: boolean;
|
|
44
|
+
user: CliInfoUser;
|
|
45
|
+
pricing: PricingData | null;
|
|
46
|
+
}
|
|
47
|
+
export interface CreateSiteInput {
|
|
48
|
+
community_name: string;
|
|
49
|
+
subdomain: string;
|
|
50
|
+
plan: Plan;
|
|
51
|
+
region?: Region;
|
|
52
|
+
legal_agreed: boolean;
|
|
53
|
+
age_terms_agreed?: boolean;
|
|
54
|
+
user_terms_agreed?: boolean;
|
|
55
|
+
email_opt_in?: boolean;
|
|
56
|
+
coupon_code?: string;
|
|
57
|
+
referral_code?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface SiteSummary {
|
|
60
|
+
token: string;
|
|
61
|
+
name: string;
|
|
62
|
+
subdomain: string;
|
|
63
|
+
status: string;
|
|
64
|
+
site_url: string;
|
|
65
|
+
}
|
|
66
|
+
export interface SiteStatusResponse extends SiteSummary {
|
|
67
|
+
redirect_url: string | null;
|
|
68
|
+
}
|
|
69
|
+
export declare function startDeviceAuth(idUrl: string, clientId: string, options?: {
|
|
70
|
+
signup?: boolean;
|
|
71
|
+
fetchImpl?: FetchLike;
|
|
72
|
+
}): Promise<DeviceAuthResponse>;
|
|
73
|
+
export declare function pollDeviceTokenOnce(idUrl: string, clientId: string, deviceCode: string, options?: {
|
|
74
|
+
fetchImpl?: FetchLike;
|
|
75
|
+
now?: NowLike;
|
|
76
|
+
}): Promise<DevicePollResult>;
|
|
77
|
+
export declare function pollDeviceTokenUntilApproved(idUrl: string, clientId: string, pending: PendingDeviceAuth, options?: {
|
|
78
|
+
timeoutSeconds?: number;
|
|
79
|
+
fetchImpl?: FetchLike;
|
|
80
|
+
sleep?: SleepLike;
|
|
81
|
+
now?: NowLike;
|
|
82
|
+
onPoll?: () => void;
|
|
83
|
+
}): Promise<StoredToken>;
|
|
84
|
+
export declare function getCliInfo(idUrl: string, accessToken: string, options?: {
|
|
85
|
+
fetchImpl?: FetchLike;
|
|
86
|
+
}): Promise<CliInfoResponse>;
|
|
87
|
+
export declare function createSite(idUrl: string, accessToken: string, input: CreateSiteInput, options?: {
|
|
88
|
+
fetchImpl?: FetchLike;
|
|
89
|
+
}): Promise<SiteSummary>;
|
|
90
|
+
export declare function getSiteStatus(idUrl: string, accessToken: string, siteToken: string, options?: {
|
|
91
|
+
fetchImpl?: FetchLike;
|
|
92
|
+
}): Promise<SiteStatusResponse>;
|
|
93
|
+
export declare function waitForSiteReady(idUrl: string, accessToken: string, siteToken: string, options?: {
|
|
94
|
+
timeoutSeconds?: number;
|
|
95
|
+
pollIntervalMs?: number;
|
|
96
|
+
fetchImpl?: FetchLike;
|
|
97
|
+
sleep?: SleepLike;
|
|
98
|
+
now?: NowLike;
|
|
99
|
+
onStatus?: (status: SiteStatusResponse) => void;
|
|
100
|
+
}): Promise<SiteStatusResponse>;
|