@widgetic/cli 0.1.11 → 0.1.13

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
@@ -22,6 +22,21 @@ widgetic mcp create-widget --title "Launch countdown" --brief "A countdown to 14
22
22
 
23
23
  `widgetic` on its own (or `widgetic --help`) is the menu: the commands under three headings, the first steps (make a key in the dashboard under Settings > API Keys, log in, run `doctor`) and a few examples. `widgetic api --help` lists the groups of the REST API with a line each, `widgetic mcp --help` lists the build tools by what they do to your account (read, write, publish, delete), and `widgetic api <group> --help` and `widgetic <command> --help` go one level down. A word that is no command is looked for in both: `widgetic widgets list` answers `try widgetic api widgets list`. The whole reference, one page per group, is generated into [`docs/commands`](docs/commands/index.mdx).
24
24
 
25
+ ## For AI agents
26
+
27
+ The package ships two files for an agent that runs the CLI, so it reads rules and a map that match the version that is installed, not a web page that may have moved on:
28
+
29
+ - [`docs/agent-guide.md`](docs/agent-guide.md): how to sign in without handling the key, what to ask the user first, how to build, publish and embed a widget, what costs credits and what cannot be undone, and what to do after each exit code. It is written by hand, and `test/agent-docs.test.ts` holds it to the program: every command and flag in it exists, every complete example runs with `--dry-run`, and what it says about credits and exit codes is what the tool contract and the CLI say.
30
+ - [`docs/llms.txt`](docs/llms.txt): every group of the REST API and every MCP command of this version, each with the line `--help` gives it, in the [llms.txt](https://llmstxt.org) format. `npm run docs` generates it from the contracts, and a test fails while it is out of date.
31
+
32
+ `widgetic docs` prints the guide and `widgetic docs index` prints the index, so an agent needs no path: both work offline, with no key. The two are also files in the `docs` folder of the installed package: `$(npm root -g)/@widgetic/cli/docs` after `npm install -g @widgetic/cli`, `node_modules/@widgetic/cli/docs` in a project that depends on it. The reference pages of [`docs/commands`](docs/commands/index.mdx) are for the docs site and are not in the package: `widgetic schema` is the exact reference of the version that is installed. To point an agent at them, add this to the project's `AGENTS.md`:
33
+
34
+ ```markdown
35
+ ## Widgetic
36
+
37
+ - Before you run `widgetic`, run `widgetic docs` and read what it prints. `widgetic docs index` lists every command. Both match the installed version.
38
+ ```
39
+
25
40
  ## The commands
26
41
 
27
42
  | Command | What it does |
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@ import { Command, CommanderError } from 'commander';
2
2
  import { registerAuthCommands } from "./commands/auth.js";
3
3
  import { registerApiCall, registerMcpCall } from "./commands/call.js";
4
4
  import { registerCompletionCommands } from "./commands/completion.js";
5
+ import { registerDocsCommand } from "./commands/docs.js";
5
6
  import { registerDoctorCommand } from "./commands/doctor.js";
6
7
  import { registerSchemaCommand } from "./commands/schema.js";
7
8
  import { registerUpdateCommand } from "./commands/update.js";
@@ -55,7 +56,7 @@ export function namespaceOf(argv) {
55
56
  /**
56
57
  * The whole program for `argv`. The namespaces are listed in the help of `widgetic` itself, and their commands are
57
58
  * added only for the one the arguments name; the commands that are not generated (`auth`, `doctor`, `update`,
58
- * `schema`, `completion`) are always there.
59
+ * `schema`, `docs`, `completion`) are always there.
59
60
  */
60
61
  export function buildProgram(environment, argv = []) {
61
62
  const root = createRootCommand(environment);
@@ -90,6 +91,7 @@ export function buildProgram(environment, argv = []) {
90
91
  registerCompletionCommands(root, environment, (words) => buildProgram(environment, words));
91
92
  root.commandsGroup(ROOT_HEADINGS.lookup);
92
93
  registerSchemaCommand(root, environment);
94
+ registerDocsCommand(root, environment);
93
95
  root.helpCommand('help [command]', 'Show the help of a command');
94
96
  root.addHelpText('after', rootHelpFooter());
95
97
  return root;
@@ -0,0 +1,58 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { Argument } from 'commander';
3
+ import { addBasicOptions, readCommon } from "../options.js";
4
+ import { printResult, writeStdout } from "../output.js";
5
+ /**
6
+ * `widgetic docs [guide|index]`: prints the two files the package ships for an AI agent, so the agent needs no path.
7
+ *
8
+ * The files are `docs/agent-guide.md` (rules, written by hand) and `docs/llms.txt` (a map of every command, generated
9
+ * from the contracts). They sit in the `docs` folder of the installed package, which is one folder above `src/` and
10
+ * `dist/` alike, so what is printed always matches the version that runs. Nothing is sent anywhere: the command works
11
+ * offline, with no key.
12
+ */
13
+ /** The pages of `widgetic docs`: the name a person types, and the file of the package that holds the page. */
14
+ export const DOC_PAGES = {
15
+ guide: 'agent-guide.md',
16
+ index: 'llms.txt'
17
+ };
18
+ /** The names `widgetic docs` accepts, the one it prints without a name first. */
19
+ export const DOC_PAGE_NAMES = Object.keys(DOC_PAGES);
20
+ /** The page printed when none is named: the guide an agent reads before it runs anything. */
21
+ export const DEFAULT_DOC_PAGE = 'guide';
22
+ /** The `docs` folder of the package this program runs from (`src/commands/` and `dist/commands/` are the same depth). */
23
+ const PACKAGE_DOCS_FOLDER = new URL('../../docs/', import.meta.url);
24
+ /**
25
+ * The text of one page. `folder` is a parameter so a test can point it at a folder that has no such file: a package
26
+ * that was packed without it must say so, not print nothing.
27
+ */
28
+ export function readDocPage(page, folder = PACKAGE_DOCS_FOLDER) {
29
+ const file = DOC_PAGES[page];
30
+ try {
31
+ return readFileSync(new URL(file, folder), 'utf8');
32
+ }
33
+ catch {
34
+ throw new Error(`docs/${file} is missing: this build of @widgetic/cli is incomplete. Reinstall the package (npm install -g @widgetic/cli).`);
35
+ }
36
+ }
37
+ /** Adds `docs` under the root. */
38
+ export function registerDocsCommand(root, environment) {
39
+ const docs = root
40
+ .command('docs')
41
+ // The line the list of commands of `widgetic --help` shows; the whole text is the help of `docs` itself.
42
+ .summary('Print the guide for AI agents that matches this version of the CLI.')
43
+ .description('Print the guide an AI agent reads before it runs this CLI: how to sign in without handling the API key, what to ask the user first, how to build, preview, publish and embed a widget, what costs credits and what cannot be undone.\n\n`widgetic docs index` prints the index instead: every group of the REST API and every MCP command of this version, each with its one line. Both are files of the installed package, so they match the version that runs, and they need no network and no key.')
44
+ .addArgument(new Argument('[page]', 'guide (what an agent reads first) or index (every command of this version)')
45
+ .choices(DOC_PAGE_NAMES)
46
+ .default(DEFAULT_DOC_PAGE));
47
+ addBasicOptions(docs, { server: false });
48
+ docs.action((page) => {
49
+ const common = readCommon(docs);
50
+ const text = readDocPage(page);
51
+ if (common.json) {
52
+ // The same text, with the name of the page and the file it came from, for a program that parses it.
53
+ printResult(environment, { page, file: `docs/${DOC_PAGES[page]}`, text }, true);
54
+ return;
55
+ }
56
+ writeStdout(environment, text);
57
+ });
58
+ }
@@ -16,7 +16,8 @@ import { waitForBuild } from "./wait.js";
16
16
  * gateway publishes. A command is the tool name in kebab case; an argument that is a string, a number, a choice, a
17
17
  * boolean or a list of strings is a flag, and `--input` takes the whole document (and the arguments that are objects).
18
18
  */
19
- const SCOPE_HEADINGS = {
19
+ /** The headings that sort the commands of `widgetic mcp --help` (`docs/llms.txt` sorts them the same way). */
20
+ export const SCOPE_HEADINGS = {
20
21
  read: 'Read (look at what exists):',
21
22
  write: 'Write (build and edit):',
22
23
  publish: 'Publish (make something public):',
@@ -0,0 +1,53 @@
1
+ # Widgetic CLI: a guide for AI agents
2
+
3
+ `widgetic` is the command line of Widgetic, a service that builds interactive widgets (countdowns, quizzes, galleries and more) from a description, hosts them and gives the code to embed them on a website. You are about to run it for a user, so read this first. It ships inside the CLI package (`widgetic docs` prints it), so it describes the version that is installed. [llms.txt](llms.txt) (`widgetic docs index` prints it) lists every command of that version, and the [README](../README.md) is the full manual.
4
+
5
+ ## Before you run anything
6
+
7
+ 1. Run `widgetic doctor`. It checks the CLI, the API key, the REST API and the MCP server, and it says which workspace the key works in. Add `--json` to read every check.
8
+ 2. No key (exit code 3)? Ask the user to make one under Settings > API Keys in the dashboard (app.widgetic.com) and to run `widgetic auth login` in their own terminal: it asks for the key without showing it. Or they can start you with `WIDGETIC_API_KEY` set. The `widgetic mcp` commands need a key made with full access.
9
+ 3. Never ask for the key in the chat, put it in a command argument, write it to a file of the project or print it. A value the contract marks as a secret takes `@path` or `-` (standard input), never the text itself.
10
+ 4. Say which workspace you are about to change before you create or change anything: a key works in one workspace at a time, the user's own or a team's. A change to a workflow, an A/B test or a translation can be held to the workspace the user means with `--expected-workspace`, or with `WIDGETIC_WORKSPACE` for a whole shell.
11
+
12
+ ## Find a command, then read its schema
13
+
14
+ - `widgetic --help` is the menu. `widgetic api --help` lists the groups of the REST API, `widgetic mcp --help` lists the build tools by what they do to the account (read, write, publish, delete), and `widgetic api GROUP --help` lists one group.
15
+ - `widgetic schema api GROUP COMMAND` and `widgetic schema mcp COMMAND` print everything one command takes, with the JSON Schema of its input. Read it before you run a command you do not know. It works offline and describes the installed version.
16
+ - `widgetic api call OPERATION_ID` and `widgetic mcp call TOOL` run a command by the name its contract gives it.
17
+
18
+ ## Run commands safely
19
+
20
+ - Add `--json` when you read the output. The result is one line of JSON on stdout. An error is one line of JSON on stderr: `{"error":{"code","message","status","requestId"}}`. With `--json` nothing is ever asked.
21
+ - Add `--dry-run` before anything that changes the account. It prints the exact request, with the key left out, and sends nothing. It needs no key.
22
+ - A command that deletes or changes something asks first on a terminal, and needs `--yes` without one. Pass `--yes` only after the user said yes to that change.
23
+ - `--data` (REST commands) and `--input` (MCP commands) take the whole request as JSON, as `@file.json`, or as `-` for standard input. The flags of the command override its keys.
24
+ - The CLI already retries a call up to three times and waits out a `429`. If a build command fails or times out, run `widgetic mcp list-widgets` before you run it again: every `create-widget` call uses a credit.
25
+
26
+ ## Build, preview, publish and embed a widget
27
+
28
+ The `widgetic mcp` commands are the AI build tools. A build stays a draft unless you pass `--publish`.
29
+
30
+ 1. `widgetic mcp create-widget --title "Launch countdown" --brief "A countdown to 14 March 2027" --wait` starts the build and keeps asking until it has finished (up to 15 minutes), then prints the widget. Without `--wait` it answers at once with the `widget_id` and the build goes on in the background. `widgetic mcp replicate-widget` and `widgetic mcp revise-widget` work the same way.
31
+ 2. `widgetic mcp get-widget --widget-id ID` shows the phase of a build (`ready`, `failed` or `cancelled` once it has ended) and the link to the preview. Show the preview to the user and wait for their answer.
32
+ 3. For a change that needs new code, run `widgetic mcp revise-widget --widget-id ID --feedback "Make the numbers bigger"`. To change only the texts, images, colors, fonts or sizes of a published widget, `widgetic mcp update-widget-customization` does it at once, without a rebuild.
33
+ 4. When the user has approved the preview, run `widgetic mcp publish-widget --widget-id ID`. The result has the `composition_id`. If the plan does not include publishing, the result says so: tell the user.
34
+ 5. `widgetic mcp get-embed-code --composition-id ID --format react` prints the code that puts the widget on a website. `--format` is `html`, `iframe`, `react`, `vue`, `svelte` or `angular`. It works only for a published widget.
35
+
36
+ ## What costs credits, and what cannot be undone
37
+
38
+ - **Credits.** Each `widgetic mcp create-widget` and `widgetic mcp revise-widget` call uses 1 credit, charged when the build starts. `widgetic mcp create-widget-batch` builds up to 25 widgets for 1 credit each and needs `--max-credits`: tell the user the total and get a yes first. Everything else is free.
39
+ - **Live embeds.** `widgetic mcp publish-widget`, and a build started with `--publish`, replace the version that existing embeds show, so ask the user first. `widgetic mcp unpublish-widget` takes a widget offline without deleting it.
40
+ - **Deleting is permanent.** `widgetic mcp delete-widget --widget-id ID --confirm-title "Launch countdown"` removes the widget with all its versions and published copies. Embeds already on websites stop working, and credits already used are not refunded. Do it only when the user clearly asked and told you which widget, and pass the exact title they confirmed.
41
+
42
+ ## When a command fails
43
+
44
+ | Code | Meaning | What to do |
45
+ | ---- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
46
+ | 0 | It worked. | |
47
+ | 1 | Anything else: a bug, an unexpected server error, a build that did not finish in time. | Run `widgetic doctor` and tell the user what it says. |
48
+ | 2 | The command line or a JSON document is wrong. Nothing was sent. | Read `widgetic schema` for the command and fix the call. |
49
+ | 3 | No key, or a 401, 402 or 403. | Without a key: `widgetic auth login`, or `WIDGETIC_API_KEY`. Otherwise the key or the plan does not allow the command: tell the user and ask for a key that does. |
50
+ | 4 | Not found. | Check the id with a `list-` command, such as `widgetic mcp list-widgets`. |
51
+ | 5 | The server refused the request (400, 409, 422, another 4xx), a tool answered with an error, or a build failed or was cancelled. | Read the message in the error. Do not repeat the call unchanged. |
52
+ | 6 | Rate limited or unavailable (429, 502, 503, 504), a timeout, or no network. | Wait, then try once more. A `Retry-After` of up to 30 seconds has already been waited out. |
53
+ | 7 | This CLI is too old for the server (426). | `widgetic update`, or `npm install -g @widgetic/cli@latest`. |
package/docs/llms.txt ADDED
@@ -0,0 +1,107 @@
1
+ # Widgetic CLI
2
+
3
+ > `widgetic` is the command line of Widgetic, a service that builds interactive widgets (countdowns, quizzes, galleries and more), hosts them and gives the code to embed them. `widgetic api` runs the public REST API and `widgetic mcp` runs the AI build tools of the Widgetic MCP server. This copy describes the version it was installed with: 159 REST operations in 14 groups and 56 MCP tools (tool contract 1.24.1).
4
+
5
+ Read the agent guide before you run a command: it says how to sign in without handling the API key, what to ask the user first, and how to build, publish and embed a widget. Then find a command below and read its schema with `widgetic schema`.
6
+
7
+ ## Read first
8
+
9
+ - [Agent guide](agent-guide.md): sign-in, dry runs, drafts, publishing, deleting, credits and exit codes
10
+ - [README](../README.md): the full manual: every flag, environment variable and exit code
11
+
12
+ ## Look up one command
13
+
14
+ These work offline and always describe the version that is installed:
15
+
16
+ - `widgetic --help`: the menu of the CLI
17
+ - `widgetic api GROUP --help` and `widgetic mcp COMMAND --help`: what one group or one command takes
18
+ - `widgetic schema api GROUP COMMAND` and `widgetic schema mcp COMMAND`: the whole description of a command and the JSON Schema its input is checked against
19
+ - `widgetic docs` and `widgetic docs index`: print the agent guide and this index, from the installed package
20
+ - `widgetic api call OPERATION_ID` and `widgetic mcp call TOOL`: run a command by the name its contract gives it
21
+
22
+ ## REST API groups: `widgetic api GROUP COMMAND`
23
+
24
+ - `brand-kit` (8 commands): Your Brand Kit: the colors, fonts, icons, corner radius and notes for the AI that every new widget follows.
25
+ - `canvases` (5 commands): The canvases that hold your widgets: create, list, read, update and delete them.
26
+ - `compositions` (39 commands): What is made from a widget: its content, design, preview, versions, data and embed settings.
27
+ - `credits` (2 commands): An account's credit balance and credit ledger.
28
+ - `entitlements` (2 commands): The entitlements of a partner and of its managed users (needs a partner key).
29
+ - `invoices` (1 command): A partner's invoices (needs a partner key).
30
+ - `managed-users` (18 commands): A partner's managed users: their limits, design defaults and editor sessions.
31
+ - `operations` (1 command): The status of work that goes on after the call that started it has answered.
32
+ - `partners` (41 commands): A partner account: analytics, billing, presets, notifications, storage and data (needs a partner key).
33
+ - `tokens` (1 command): Check that the API key in use is valid.
34
+ - `uploads` (5 commands): Upload files, list and delete them, and see the upload limits.
35
+ - `users` (13 commands): Your account: API keys, the websites that may show your widgets, and adapter connections.
36
+ - `widgets` (4 commands): Your library of widgets: list and create them, and start a composition from one.
37
+ - `workflows` (19 commands): Workflows: create, edit, publish, pause and archive them, and restore their versions.
38
+
39
+ ## MCP commands: `widgetic mcp COMMAND`
40
+
41
+ ### Read (look at what exists): 26 commands
42
+
43
+ - `get-ab-test`: Get an A/B test
44
+ - `get-ab-test-options`: Get A/B test options
45
+ - `get-account-usage`: Get account usage
46
+ - `get-brand-kit`: Get the Brand Kit
47
+ - `get-embed-code`: Get embed code
48
+ - `get-embed-settings`: Get embed settings
49
+ - `get-profile`: Get Widgetic account
50
+ - `get-translation`: Get a translation
51
+ - `get-translation-automation`: Get translation automation
52
+ - `get-translation-options`: Get translation options
53
+ - `get-widget`: Get widget status
54
+ - `get-widget-customization-options`: Get customization options
55
+ - `get-widget-data`: Get widget data
56
+ - `get-workflow`: Get a workflow
57
+ - `get-workflow-guide`: Get workflow guide
58
+ - `get-workflow-options`: Get workflow options
59
+ - `list-ab-tests`: List A/B tests
60
+ - `list-media-library`: List media library
61
+ - `list-translations`: List translations
62
+ - `list-widget-data`: List widget data
63
+ - `list-widget-versions`: List widget versions
64
+ - `list-widgets`: List widgets
65
+ - `list-workflows`: List workflows
66
+ - `show-widget`: Show a widget
67
+ - `suggest-widgets`: Suggest widgets to build
68
+ - `test-workflow`: Test a workflow
69
+
70
+ ### Write (build and edit): 25 commands
71
+
72
+ - `add-content-from-files`: Add content from files
73
+ - `add-translation-languages`: Add translation languages
74
+ - `apply-embed-code`: Apply embed code
75
+ - `cancel-widget-batch`: Cancel several widget builds
76
+ - `cancel-widget-creation`: Cancel a widget build
77
+ - `create-translation`: Create a translation
78
+ - `create-widget`: Create a widget
79
+ - `create-widget-batch`: Create several widgets
80
+ - `draft-workflow-from-widgets`: Draft a workflow from widgets
81
+ - `duplicate-composition`: Copy a published widget
82
+ - `manage-media-library`: Rename or move media files
83
+ - `refresh-translation`: Refresh a translation
84
+ - `rename-widget`: Rename a widget
85
+ - `replicate-widget`: Replicate a widget
86
+ - `revise-widget`: Revise a widget
87
+ - `save-ab-test`: Save an A/B test
88
+ - `save-embed-settings`: Save embed settings
89
+ - `save-to-media-library`: Save to media library
90
+ - `save-translation-automation`: Save translation automation
91
+ - `save-workflow`: Save a workflow
92
+ - `set-ab-test-state`: Start, pause or stop a test
93
+ - `set-translation-state`: Activate or pause a translation
94
+ - `set-workflow-state`: Pause or archive a workflow
95
+ - `update-brand-kit`: Change the Brand Kit
96
+ - `update-widget-customization`: Update widget customization
97
+
98
+ ### Publish (make something public): 3 commands
99
+
100
+ - `publish-widget`: Publish a widget
101
+ - `publish-workflow`: Publish a workflow
102
+ - `unpublish-widget`: Unpublish a widget
103
+
104
+ ### Delete: 2 commands
105
+
106
+ - `delete-media-file`: Delete a media file
107
+ - `delete-widget`: Delete a widget
@@ -1 +1 @@
1
- {"package":"@widgetic/api-contracts","version":"1.11.135","publishTag":"latest","source":{"commit":"9b6c664a45d6c51a08412dabcd4917d34fc41bf5","branch":null,"dirty":false,"atOriginMain":true},"openApi":{"file":"openapi-public.json","sha256":"1cdc03eeea38139717d9303a1cc8fc3dd424f9c13a98875da8d7582cc824e5fd","paths":124,"operations":169,"servers":["https://api.widgetic.com/v1"]},"mcp":{"file":"mcp-tools.json","sha256":"bf343b62ce591b2979d7a37f654280b62748be1475c47bec28651681b8d6fd71","contractVersion":"1.24.0","serverName":"widgetic","tools":56}}
1
+ {"package":"@widgetic/api-contracts","version":"1.11.142","publishTag":"latest","source":{"commit":"f78c9a1405bfecd4591c3a32323a3632df205d12","branch":null,"dirty":false,"atOriginMain":true},"openApi":{"file":"openapi-public.json","sha256":"9269c58a86e82c1ac672a987349b0d5ddda7fc01f4c52f8c36d51a0f156e14eb","paths":124,"operations":169,"servers":["https://api.widgetic.com/v1"]},"mcp":{"file":"mcp-tools.json","sha256":"6cdb18c91fecc40626d5ea23486adbea34063653b1142b6619122ace7e94a309","contractVersion":"1.24.1","serverName":"widgetic","tools":56}}