Skip to content

Commit f7e962d

Browse files
feat(cli): add openclaw promos to discover and claim ClawHub promotional model offers (#100236)
* feat: add openclaw promos CLI for ClawHub promotional model offers * fix: harden promos claim auth validation and sanitize remote promo text * fix: enforce promo window client-side and validate slug contract * fix: shell-safe model ref contract and explicit --api-key override * fix: hold promotion aliases to the models alias contract * docs: document argv-credential contract and env alternative for promos claim * fix: enforce provider plugin enablement on the credential-reuse claim path * fix: require plugin install before credential-reuse shortcut in promos claim * fix: run runtime plugin repair on promo defaults and harden identifier parsing * fix: distinct message for contract-invalid promo aliases * fix(cli): validate promotion plugin contracts * fix(cli): recheck promotion window before claim * feat(cli): surface ClawHub promotions in models list via the hosted feed Passive discovery for promotional model offers. A cadence-gated (24h), fail-silent conditional GET of ClawHub's immutable promotions feed snapshot (If-None-Match -> 304, short 2.5s timeout, unauthenticated so CDN caches stay unfragmented) is cached in two new shared-state-DB tables, fully separate from update_check_state. models list renders an 'Available via promotion' group for live offers whose models are not in the user's configured set (including the zero-row fresh-install path), tags claimed models promo / promo ended from provenance recorded at claim time, and prints a one-time notice per newly seen offer; promos list and claim mark offers as seen. Machine outputs stay clean, snapshot sequence is monotonic against stale edges, and claims still revalidate against the live API so the kill switch always wins. * style: satisfy lint on promotions feed additions no-useless-fallback-in-spread on the optional request headers and no-map-spread in claim-provenance row mapping. * fix(cli): harden promotions feed cache * fix(cli): honor live promotion validity
1 parent d8ffb1f commit f7e962d

21 files changed

Lines changed: 2733 additions & 5 deletions

‎docs/cli/index.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Setup commands by intent:
2626
| Messaging and agents | [`message`](/cli/message) · [`agent`](/cli/agent) · [`agents`](/cli/agents) · [`attach`](/cli/attach) · [`acp`](/cli/acp) · [`mcp`](/cli/mcp) |
2727
| Health and sessions | [`status`](/cli/status) · [`health`](/cli/health) · [`sessions`](/cli/sessions) · [`audit`](/cli/audit) |
2828
| Gateway and logs | [`gateway`](/cli/gateway) · [`logs`](/cli/logs) · [`system`](/cli/system) |
29-
| Models and inference | [`models`](/cli/models) · [`infer`](/cli/infer) · `capability` (alias for [`infer`](/cli/infer)) · [`memory`](/cli/memory) · [`commitments`](/cli/commitments) · [`wiki`](/cli/wiki) |
29+
| Models and inference | [`models`](/cli/models) · [`promos`](/cli/promos) · [`infer`](/cli/infer) · `capability` (alias for [`infer`](/cli/infer)) · [`memory`](/cli/memory) · [`commitments`](/cli/commitments) · [`wiki`](/cli/wiki) |
3030
| Network and nodes | [`directory`](/cli/directory) · [`nodes`](/cli/nodes) · [`devices`](/cli/devices) · [`node`](/cli/node) |
3131
| Runtime and sandbox | [`approvals`](/cli/approvals) · `exec-policy` (see [`approvals`](/cli/approvals)) · [`sandbox`](/cli/sandbox) · [`tui`](/cli/tui) · `chat`/`terminal` (aliases for [`tui --local`](/cli/tui)) · [`browser`](/cli/browser) |
3232
| Automation | [`cron`](/cli/cron) · [`tasks`](/cli/tasks) · [`hooks`](/cli/hooks) · [`webhooks`](/cli/webhooks) · [`transcripts`](/cli/transcripts) |
@@ -285,6 +285,9 @@ openclaw [--dev] [--profile <name>] <command>
285285
scan
286286
auth list|add|login|setup-token|paste-token|paste-api-key|login-github-copilot
287287
auth order get|set|clear
288+
promos
289+
list
290+
claim <slug>
288291
infer (alias: capability)
289292
list
290293
inspect

‎docs/cli/promos.md‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
summary: "CLI reference for `openclaw promos` (list and claim promotional model offers)"
3+
read_when:
4+
- You want to try a free promotional model offer from ClawHub
5+
- You are configuring a provider through a promotion instead of onboarding
6+
title: "Promos"
7+
---
8+
9+
# `openclaw promos`
10+
11+
Discover and claim promotional model offers published on ClawHub. Claiming a
12+
promotion configures the provider (auth and plugin, when needed) and registers
13+
the promotion's models — without re-running onboarding and without changing
14+
your default model unless you say so.
15+
16+
Related:
17+
18+
- Default model and fallbacks: [Models](/cli/models)
19+
- Provider auth setup: [Getting started](/start/getting-started)
20+
21+
## Commands
22+
23+
```bash
24+
openclaw promos list
25+
openclaw promos claim <slug>
26+
openclaw promos claim <slug> --api-key <key> --set-default
27+
```
28+
29+
## `openclaw promos list`
30+
31+
Lists promotions that are currently live, with their models, the suggested
32+
default, time remaining, and the exact claim command. `--json` prints the raw
33+
payload.
34+
35+
## `openclaw promos claim <slug>`
36+
37+
Claims a live promotion:
38+
39+
1. Fetches the promotion from ClawHub and verifies it is inside its window.
40+
2. Validates the promotion's provider, auth choice, and declared plugin packages
41+
against your installed OpenClaw version. Unknown ids or package mismatches are
42+
refused — a promotion can never make the CLI run anything it does not already
43+
know how to do.
44+
3. Reuses your existing provider credentials when you have them. Otherwise it
45+
walks the provider's normal auth flow (printing the promotion's signup URL
46+
for a free key first). `--api-key <key>` completes API-key auth without
47+
prompts, matching the `openclaw onboard` non-interactive flags; to keep the
48+
key off the command line, export the provider's environment variable
49+
instead (for example `OPENROUTER_API_KEY`) — existing env credentials are
50+
detected automatically and no flag is needed.
51+
4. Registers the promotion's models with their aliases. Existing aliases are
52+
never overwritten.
53+
5. Offers to set the promotion's suggested model as your default —
54+
`--set-default` skips the question; otherwise nothing about your defaults
55+
changes.
56+
57+
When the promotion's window ends, the provider stops serving the free models;
58+
your configuration and credentials are untouched. Switch back anytime with
59+
`openclaw models set <model>`.
60+
61+
## Passive discovery in `models list`
62+
63+
`openclaw models list` also surfaces promotions without you asking ClawHub
64+
directly:
65+
66+
- Live offers whose models you have not configured appear in an
67+
"Available via promotion" group below the table, each with its claim
68+
command.
69+
- Models you registered through `promos claim` carry a `promo` tag, which
70+
flips to `promo ended` once the offer's window passes.
71+
- The first time a new offer is seen, a one-time notice points at
72+
`openclaw promos list`. Offers you have already listed or claimed are never
73+
announced again.
74+
75+
This reads a locally cached copy of ClawHub's hosted promotions feed
76+
(normally refreshed once a day with a conditional request, or earlier when the
77+
cached snapshot expires; refresh failures are silently skipped). A stale
78+
refresh waits at most 2.5 seconds and never breaks the listing. `--json` and
79+
`--plain` output stay machine-clean: no promotion sections or notices.
80+
Claiming always revalidates against the live ClawHub API, so an offer withdrawn
81+
early is refused even while a cached copy still shows it.

‎docs/docs.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,7 @@
17541754
"cli/commitments",
17551755
"cli/message",
17561756
"cli/models",
1757+
"cli/promos",
17571758
"cli/sessions",
17581759
"cli/system",
17591760
"cli/tasks"

‎docs/docs_map.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,16 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
18281828
- H2: Exit codes
18291829
- H2: Related
18301830

1831+
## cli/promos.md
1832+
1833+
- Route: /cli/promos
1834+
- Headings:
1835+
- H1: openclaw promos
1836+
- H2: Commands
1837+
- H2: openclaw promos list
1838+
- H2: openclaw promos claim &lt;slug&gt;
1839+
- H2: Passive discovery in models list
1840+
18311841
## cli/proxy.md
18321842

18331843
- Route: /cli/proxy

‎src/cli/program/register.subclis-core.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ const entrySpecs: readonly CommandGroupDescriptorSpec<SubCliRegistrar>[] = [
121121
loadModule: () => import("../models-cli.js"),
122122
exportName: "registerModelsCli",
123123
},
124+
{
125+
commandNames: ["promos"],
126+
loadModule: () => import("../promos-cli.js"),
127+
exportName: "registerPromosCli",
128+
},
124129
{
125130
commandNames: ["infer", "capability"],
126131
loadModule: () => import("../capability-cli.js"),

‎src/cli/program/subcli-descriptors.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const subCliCommandCatalog = defineCommandDescriptorCatalog([
2929
description: "Model discovery, scanning, and configuration",
3030
hasSubcommands: true,
3131
},
32+
{
33+
name: "promos",
34+
description: "Discover and claim promotional model offers from ClawHub",
35+
hasSubcommands: true,
36+
},
3237
{
3338
name: "infer",
3439
description: "Run provider-backed inference commands through a stable CLI surface",

‎src/cli/promos-cli.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/** CLI registration for ClawHub promotional model offers. */
2+
import type { Command } from "commander";
3+
import { formatDocsLink } from "../../packages/terminal-core/src/links.js";
4+
import { theme } from "../../packages/terminal-core/src/theme.js";
5+
import { defaultRuntime } from "../runtime.js";
6+
import { runCommandWithRuntime } from "./cli-utils.js";
7+
8+
export function registerPromosCli(program: Command) {
9+
const promos = program
10+
.command("promos")
11+
.description("Discover and claim promotional model offers from ClawHub")
12+
.addHelpText(
13+
"after",
14+
() =>
15+
`\n${theme.muted("Docs:")} ${formatDocsLink("/cli/promos", "docs.openclaw.ai/cli/promos")}\n`,
16+
);
17+
18+
promos
19+
.command("list")
20+
.description("List active promotions")
21+
.option("--json", "Output JSON", false)
22+
.action(async (opts: { json?: boolean }) => {
23+
await runCommandWithRuntime(defaultRuntime, async () => {
24+
const { promosListCommand } = await import("../commands/promos/list.js");
25+
await promosListCommand(opts, defaultRuntime);
26+
});
27+
});
28+
29+
promos
30+
.command("claim")
31+
.description("Claim a promotion: set up provider auth and register its models")
32+
.argument("<slug>", "Promotion slug from `openclaw promos list`")
33+
// Credential-on-argv matches the shipped `onboard --<provider>-api-key` /
34+
// `onboard --token` non-interactive contract (AGENTS.md: public API). The
35+
// no-argv alternative is the provider's env var, detected as existing auth.
36+
.option("--api-key <key>", "Provider API key for non-interactive setup")
37+
.option("--set-default", "Set the promotion's suggested model as default without asking", false)
38+
.action(async (slug: string, opts: { apiKey?: string; setDefault?: boolean }) => {
39+
await runCommandWithRuntime(defaultRuntime, async () => {
40+
const { promosClaimCommand } = await import("../commands/promos/claim.js");
41+
await promosClaimCommand(slug, opts, defaultRuntime);
42+
});
43+
});
44+
}

‎src/commands/models/list.list-command.ts‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ import { DEFAULT_PROVIDER, ensureFlagCompatibility } from "./shared.js";
1818

1919
const DISPLAY_MODEL_PARSE_OPTIONS = { allowPluginNormalization: false } as const;
2020

21+
type PromotionsModule = typeof import("./list.promotions.js");
2122
type RegistryLoadModule = typeof import("./list.registry-load.js");
2223
type RowSourcesModule = typeof import("./list.row-sources.js");
2324
type SourcePlanModule = typeof import("./list.source-plan.js");
2425

26+
const promotionsModuleLoader = createLazyImportLoader<PromotionsModule>(
27+
() => import("./list.promotions.js"),
28+
);
2529
const registryLoadModuleLoader = createLazyImportLoader<RegistryLoadModule>(
2630
() => import("./list.registry-load.js"),
2731
);
@@ -243,12 +247,33 @@ export async function modelsListCommand(
243247
);
244248
}
245249

250+
// Promotion decorations are best-effort: claim tags come from local
251+
// provenance, and the discovery section reads a cadence-gated feed cache.
252+
// Neither may break the core listing; stale refreshes have a short timeout.
253+
const promotionsModule = await promotionsModuleLoader.load();
254+
try {
255+
promotionsModule.applyPromotionClaimTags(rows);
256+
} catch {
257+
// Tags are annotation-only.
258+
}
246259
if (rows.length === 0) {
247260
runtime.log("No models found.");
248-
requestExitAfterOneShotOutput(runtime);
249-
return;
261+
} else {
262+
printModelTable(rows, runtime, opts);
263+
}
264+
if (!opts.json && !opts.plain) {
265+
// Runs on the empty listing too: a fresh install with zero configured
266+
// models is exactly the user passive discovery is for. Compares against
267+
// the configured entries, not the rendered rows — filtered and --all
268+
// listings show a different set.
269+
try {
270+
await promotionsModule.printAvailablePromotionsSection({
271+
configuredKeys: new Set(entries.map((entry) => entry.key)),
272+
runtime,
273+
});
274+
} catch {
275+
// Passive discovery must never fail the listing.
276+
}
250277
}
251-
252-
printModelTable(rows, runtime, opts);
253278
requestExitAfterOneShotOutput(runtime);
254279
}

0 commit comments

Comments
 (0)