Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(strategies): send signed-out visitors to sign in instead of opening the builder, and give the view switcher a real focus ring

nirholas8c05bfb80e78
diff --git a/data/changelog.json b/data/changelog.json
index 0005f7853..48dafdac3 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -25440,6 +25440,16 @@
"improvement"
],
"link": "/start"
+ },
+ {
+ "date": "2026-09-01",
+ "title": "Strategy Objects: signed-out visitors are sent to sign in instead of a half-open builder, and the view switcher is keyboard-visible",
+ "summary": "On /strategies, Equip, Fork, and New strategy now take a signed-out visitor straight to sign-in and bring them back to the page afterwards. Before, the page treated everyone as signed in, so the equip picker and the strategy builder opened for visitors who could not use them and Fork failed silently. The My library tab now shows its sign-in prompt without firing a request that could only fail, the Marketplace, Leaderboard, and My library switcher shows a visible focus ring when tabbed to and is announced correctly by screen readers, and the browser tab reads Strategy Objects.",
+ "tags": [
+ "fix",
+ "improvement"
+ ],
+ "link": "/strategies"
}
]
}
diff --git a/pages/strategies.html b/pages/strategies.html
index 598b2ce7b..4cf1ec426 100644
--- a/pages/strategies.html
+++ b/pages/strategies.html
@@ -4,20 +4,20 @@
<script>/* three.ws theme boot — no-flash; runtime in /theme-switcher.js */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title data-i18n="strategies.meta_title">Strategies · three.ws</title>
+ <title data-i18n="strategies.meta_title">Strategy Objects · three.ws</title>
<meta name="description" content="Trading know-how as a collectible. Equip a real, rule-based strategy on your agent and it trades for real, on-chain, strictly within your spend policy. Publish yours, fork the best, ranked by verified live performance." data-i18n-attr="content:strategies.meta_description"/>
<meta property="og:type" content="website" />
<meta property="og:site_name" content="three.ws" />
<meta property="og:url" content="https://three.ws/strategies" />
- <meta property="og:title" content="Strategies · three.ws" data-i18n-attr="content:strategies.meta_og_title"/>
- <meta property="og:description" content="Equip a real, rule-based strategy on your agent — trades on-chain within your spend policy. Publish, fork, and rank by verified live performance." data-i18n-attr="content:strategies.meta_og_description"/>
+ <meta property="og:title" content="Strategy Objects · three.ws" data-i18n-attr="content:strategies.meta_og_title"/>
+ <meta property="og:description" content="Equip a real, rule-based strategy on your agent and it trades on-chain within your spend policy. Publish, fork, and rank by verified live performance." data-i18n-attr="content:strategies.meta_og_description"/>
<meta property="og:image" content="https://three.ws/api/page-og?s=crypto&amp;t=Strategy+Objects&amp;d=A+marketplace+of+how+agents+trade%3A+ownable%2C+forkable%2C+leaderboard-ranked+trade+strategies+your+agent+can+equip+and+run+on-chain+within+your+spend+policy.&amp;p=%2Fstrategies" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@trythreews" />
- <meta name="twitter:title" content="Strategies · three.ws" data-i18n-attr="content:strategies.meta_twitter_title"/>
- <meta name="twitter:description" content="Ownable, forkable, leaderboard-ranked trade strategies — proven on real chain data. Equip one on your agent." data-i18n-attr="content:strategies.meta_twitter_description"/>
+ <meta name="twitter:title" content="Strategy Objects · three.ws" data-i18n-attr="content:strategies.meta_twitter_title"/>
+ <meta name="twitter:description" content="Ownable, forkable, leaderboard-ranked trade strategies, proven on real chain data. Equip one on your agent." data-i18n-attr="content:strategies.meta_twitter_description"/>
<meta name="theme-color" content="#0a0a0a" />
<link rel="icon" href="/favicon.ico" sizes="any" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
@@ -43,14 +43,16 @@
.sp-safety b { color: #ccc; }
.sp-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: var(--space-lg, 24px) 0 var(--space-md, 16px); }
.sp-seg { display: inline-flex; gap: 4px; background: rgba(255,255,255,.03); padding: 4px; border-radius: var(--radius-pill, 999px); border: 1px solid rgba(255,255,255,.1); }
- .sp-seg button { font: inherit; font-size: var(--text-2xs, .68rem); padding: 6px 14px; border-radius: 999px; border: none; background: transparent; color: #888; cursor: pointer; transition: all .15s; }
+ .sp-seg button { font: inherit; font-size: var(--text-2xs, .68rem); padding: 6px 14px; border-radius: 999px; border: none; background: transparent; color: #888; cursor: pointer; transition: background .15s, color .15s; }
.sp-seg button[aria-pressed="true"] { background: #fff; color: #0a0a0a; font-weight: 700; }
+ .sp-seg button:focus-visible { outline: 2px solid rgba(255,255,255,.6); outline-offset: 2px; }
.sp-spacer { flex: 1 1 auto; }
.sp-new { font: inherit; font-size: var(--text-2xs, .72rem); font-weight: 700; padding: 9px 16px; border-radius: var(--radius-pill, 999px); border: none; background: #fff; color: #0a0a0a; cursor: pointer; transition: background .15s; }
.sp-new:hover { background: #d4d4d4; }
.sp-new:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 2px; }
.sp-search { flex: 1 1 180px; min-width: 140px; font: inherit; font-size: var(--text-sm, .82rem); padding: 8px 12px; border-radius: var(--radius-pill, 999px); border: 1px solid rgba(255,255,255,.1); background: rgba(255,255,255,.03); color: #fff; }
.sp-search:focus { outline: none; border-color: rgba(255,255,255,.35); }
+ .sp-search:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 2px; }
.sp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-md, 14px); }
.sp-card { display: flex; flex-direction: column; gap: 8px; border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius-lg, 14px); background: rgba(255,255,255,.025); padding: var(--space-md, 16px); transition: border-color .18s, transform .18s; }
.sp-card:hover { border-color: rgba(255,255,255,.25); transform: translateY(-1px); }
@@ -68,7 +70,7 @@
.sp-meta a { color: #aaa; text-decoration: none; }
.sp-meta a:hover { color: #fff; }
.sp-actions { display: flex; gap: 6px; margin-top: 2px; }
- .sp-btn { flex: 1; font: inherit; font-size: var(--text-2xs, .7rem); padding: 8px 10px; border-radius: var(--radius-sm, 8px); border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.05); color: #e8e8e8; cursor: pointer; transition: all .16s; white-space: nowrap; }
+ .sp-btn { flex: 1; font: inherit; font-size: var(--text-2xs, .7rem); padding: 8px 10px; border-radius: var(--radius-sm, 8px); border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.05); color: #e8e8e8; cursor: pointer; transition: border-color .16s, color .16s, background .16s; white-space: nowrap; }
.sp-btn:hover { border-color: rgba(255,255,255,.35); color: #fff; }
.sp-btn:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 2px; }
.sp-btn-primary { background: #fff; color: #0a0a0a; border-color: transparent; font-weight: 700; }
@@ -95,17 +97,17 @@
<section class="sp-hero">
<p class="sp-kicker" data-i18n-html="strategies.ownable_alpha_proven_on_real_chain_data"><span class="sp-live-dot" aria-hidden="true"></span> Ownable alpha · proven on real chain data</p>
<h1 class="sp-title" data-i18n="strategies.equip_a_strategy_not_a_spreadsheet">Equip a strategy, not a spreadsheet</h1>
- <p class="sp-sub" data-i18n-html="strategies.a_strategy_object_is_a_real_rule">A Strategy Object is a real, rule-based plan — entry conditions, sizing, take-profit, stop-loss — made into a <b>thing you own</b>. Equip it on your agent and it trades for real, on-chain, strictly inside your spend policy. Publish yours, fork the best, and watch the leaderboard rank them by <b>verified live performance</b> — numbers no one can fake.</p>
+ <p class="sp-sub" data-i18n-html="strategies.a_strategy_object_is_a_real_rule">A Strategy Object is a real, rule-based plan (entry conditions, sizing, take-profit, stop-loss) made into a <b>thing you own</b>. Equip it on your agent and it trades for real, on-chain, strictly inside your spend policy. Publish yours, fork the best, and watch the leaderboard rank them by <b>verified live performance</b>: numbers no one can fake.</p>
<div class="sp-safety">
- <span data-i18n-html="strategies.spend_policy_gated_every_trade"><b>Spend-policy gated</b> — every trade</span>
- <span data-i18n-html="strategies.real_on_chain_no_backtested_fiction"><b>Real on-chain</b> — no backtested fiction</span>
- <span data-i18n-html="strategies.forkable_rules_only_never_wallet_access"><b>Forkable</b> — rules only, never wallet access</span>
- <span data-i18n-html="strategies.kill_switch_halt_all_at_once"><b>Kill switch</b> — halt all at once</span>
+ <span data-i18n-html="strategies.spend_policy_gated_every_trade"><b>Spend-policy gated</b>: every trade</span>
+ <span data-i18n-html="strategies.real_on_chain_no_backtested_fiction"><b>Real on-chain</b>: no backtested fiction</span>
+ <span data-i18n-html="strategies.forkable_rules_only_never_wallet_access"><b>Forkable</b>: rules only, never wallet access</span>
+ <span data-i18n-html="strategies.kill_switch_halt_all_at_once"><b>Kill switch</b>: halt all at once</span>
</div>
</section>
<div class="sp-bar">
- <div class="sp-seg" role="tablist" aria-label="Strategy view" id="sp-scope">
+ <div class="sp-seg" role="group" aria-label="Strategy view" id="sp-scope">
<button data-scope="published" aria-pressed="true" data-i18n="strategies.marketplace">Marketplace</button>
<button data-scope="leaderboard" aria-pressed="false" data-i18n="strategies.leaderboard">Leaderboard</button>
<button data-scope="mine" aria-pressed="false" data-i18n="strategies.my_library">My library</button>
diff --git a/prompts/swarm-100/route-strategies.md b/prompts/swarm-100/route-strategies.md
deleted file mode 100644
index 8c95de945..000000000
--- a/prompts/swarm-100/route-strategies.md
+++ /dev/null
@@ -1,119 +0,0 @@
-# Route audit: /strategies (Strategy Objects)
-
-How to run: paste this file's repo path into a fresh Claude Code chat in this
-repository and say "run this work order". This file is fully self-contained:
-it depends on no other prompt file anywhere. If neighboring files in
-prompts/swarm-100/ are gone, that work is done; if present, ignore them.
-Every claim below rots; step 0 re-measures, and what you measure wins.
-
-## Operating clause (binding)
-
-- Read CLAUDE.md first. Its rules override everything, including this file.
-- Finish 100% in this session. Never end the turn with a question, an option
- list, or an unexecuted plan. A judgment call goes in one line of the final
- report; it never becomes a question that halts work.
-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real
- funds or any irreversible on-chain write, git push or a production deploy,
- committing content that references a crypto project other than $THREE, and
- destroying unrecoverable data.
-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no
- commented-out code. Real APIs and real integrations only.
-- The em-dash and en-dash characters are banned in everything you write.
-- Concurrent agents share this worktree: stage explicit paths only (never a
- bare add-everything), and commit finished work promptly.
-- Before committing, run: npm run check:rules -- --paths <files you touched>.
- It must exit 0.
-
-## Step 0: re-derive the current state
-
-1. This route's declared entry (path, description, added date):
-
- node -e "const p=require('./data/pages.json');for(const s of p.sections)for(const g of s.pages)if(g.path==='/strategies')console.log(JSON.stringify(g,null,2))"
-
-2. Find the serving implementation: grep "/strategies" in vercel.json (the live
- route table server/index.mjs boots from), then list matching files in
- pages/ and src/. STRUCTURE.md maps every surface to its directory if the
- grep is ambiguous.
-3. Production right now:
-
- curl -so /dev/null -w '%{http_code}\n' https://three.ws/strategies
-
-4. Start (or reuse) the local dev server: npm run dev (vite, port 3000).
-
-## Task: audit this one route end to end, then fix everything found
-
-Route: /strategies ("Strategy Objects", section "crypto").
-Declared purpose: A marketplace of how agents trade: ownable, forkable, leaderboard-ranked trade strategies your agent can equip and run on-chain within your spend policy.
-
-Drive the page in a real headless browser. Playwright is already a dev
-dependency; keep your probe script in the session scratchpad, never in the
-repo.
-
-1. Load http://localhost:3000/strategies. Record the HTTP status, every console
- error and warning, and every failed network request.
-2. Exercise it like a first-time user: click the primary actions, run the
- primary flow if one exists, follow the page's internal links. Every button
- must do something real; every link must resolve. If the page renders data,
- prove in the network log that it came from a live endpoint, not a baked-in
- fallback array.
-3. States: verify populated, empty, loading, and error states are designed and
- reachable. Block the page's primary fetch in Playwright and confirm an
- actionable error state appears, not a blank void or a raw exception.
-4. Responsive: render at 320, 768, and 1440 px. No horizontal page scroll, no
- overlapping or clipped controls.
-5. Accessibility basics: one h1; interactive elements are real buttons or
- links with visible focus states; images carry alt text; form fields have
- labels.
-6. Head: a specific title tag and meta description that match the declared
- purpose above.
-7. Fix every defect at its root in the page's real source files and re-run the
- probe until clean. Defects in shared modules are in scope when this route
- exercises them.
-
-## Definition of done
-
-- [ ] Local load of /strategies: HTTP 200, zero console errors, zero unhandled
- failed requests (a third-party outage must land in a designed fallback,
- not a broken page).
-- [ ] No dead interactive element on the page: no stub href="#", no button
- without a handler, no link to a missing path.
-- [ ] Empty, loading, error, and populated states verified.
-- [ ] 320 / 768 / 1440 px renders verified clean.
-- [ ] Title and meta description present and specific.
-- [ ] npm test passes; npm run check:rules -- --paths <touched files> exits 0.
-- [ ] Production status from step 0 recorded in the report; if production
- needs a deploy to pick up a fix, the report says so (deploys stay
- owner-gated).
-
-## Never blocked
-
-| Blocker | Resolution (act, do not ask) |
-|---|---|
-| Missing env var or credential | Check .env and .env.local, then the Cloud Run service env, then Secret Manager (the CLAUDE.md self-unblock playbook has the exact commands). If it truly exists nowhere, wire the code fully behind the env var, prove the wiring with a dry run, and name the single missing var in the report. |
-| gcloud not on PATH | Run: export PATH="$HOME/google-cloud-sdk/bin:$PATH" |
-| Dev server port 3000 busy | Another agent may be serving this repo; probe it and reuse if so. Otherwise start your own on a free port: npx vite --port 3101 |
-| Playwright browser missing | npx playwright install chromium |
-| A surface needs a signed-in user | Register a fresh account through the real /register flow against the real API and use it. Never mock the session. |
-| A defect sits in code you did not touch | Fix it if it blocks a Definition of done line (root cause it, never mask it). Otherwise note it in the report and continue. |
-| An unrelated test is red | Same rule. Never pipe npm test through tail; it masks exit codes. |
-
-## Close out (required)
-
-1. Verify every Definition of done line with the actual command output in
- front of you. Never claim a line you did not verify.
-2. Commit with explicit paths and a subject that describes the diff (house
- style: type(scope): what changed and why a reader cares).
-3. Delete this prompt file in that same commit:
-
- git rm prompts/swarm-100/route-strategies.md
-
- The shrinking directory is this campaign's only progress ledger; there is
- no progress log to update.
-4. Final report: what step 0 measured, what changed (file list), evidence per
- Definition of done line, and any one-line judgment calls. No trailing
- questions, no unexecuted plans.
-
-If a line genuinely cannot pass inside this session (an external party must
-respond, or an owner-gated action is the final step), finish everything else,
-leave this file in place, and state exactly which line remains and who owns
-it. Never delete this file on a partial.
diff --git a/src/shared/strategy-forms.js b/src/shared/strategy-forms.js
index 102ce1ad9..39b7b28cf 100644
--- a/src/shared/strategy-forms.js
+++ b/src/shared/strategy-forms.js
@@ -1,4 +1,4 @@
-// Shared Strategy Object UI primitives — the config editor, the equip picker, the
+// Shared Strategy Object UI primitives: the config editor, the equip picker, the
// human-readable rule summary, plus the styles every strategy surface uses. Reused
// by the /strategies library page and the agent-detail equip panel so the editor
// and the design stay in one place.
@@ -14,7 +14,7 @@ export const VIOLET = 'var(--wallet-accent, #c4b5fd)';
export const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
export const shortAddr = (a, h = 4, t = 4) => (a && a.length > h + t + 1 ? `${a.slice(0, h)}…${a.slice(-t)}` : a || '');
export function fmtSol(n) {
- if (n == null || !Number.isFinite(Number(n))) return '—';
+ if (n == null || !Number.isFinite(Number(n))) return '-';
const v = Number(n);
if (v === 0) return '0';
if (Math.abs(v) < 0.001) return v.toExponential(1);
@@ -48,7 +48,7 @@ export function toast(msg, ms = 2800) {
_toastTimer = setTimeout(() => { if (_toastEl) _toastEl.dataset.show = 'false'; }, ms);
}
-// ── rule summary — a one-line, honest plain-language read of a config ──────────
+// ── rule summary: a one-line, honest plain-language read of a config ──────────
export function configSummary(config) {
const c = config || {};
const e = c.entry || {}, s = c.sizing || {}, x = c.exits || {}, k = c.risk || {};
@@ -58,7 +58,7 @@ export function configSummary(config) {
if (e.min_market_cap_usd != null || e.max_market_cap_usd != null) {
const lo = e.min_market_cap_usd != null ? `$${fmtUsdShort(e.min_market_cap_usd)}` : '';
const hi = e.max_market_cap_usd != null ? `$${fmtUsdShort(e.max_market_cap_usd)}` : '';
- parts.push(`MC ${lo}${lo && hi ? '–' : ''}${hi}`);
+ parts.push(`MC ${lo}${lo && hi ? ' to ' : ''}${hi}`);
}
if (e.require_socials) parts.push('has socials');
parts.push(`size ◎${fmtSol(s.amount_sol)}`);
@@ -71,7 +71,7 @@ export function configSummary(config) {
}
function fmtUsdShort(v) {
const n = Number(v);
- if (!Number.isFinite(n)) return '—';
+ if (!Number.isFinite(n)) return '-';
if (n >= 1e9) return `${(n / 1e9).toFixed(1)}B`;
if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
if (n >= 1e3) return `${(n / 1e3).toFixed(0)}K`;
@@ -79,7 +79,7 @@ function fmtUsdShort(v) {
}
function formatMinutes(m) {
const n = Number(m);
- if (!Number.isFinite(n)) return '—';
+ if (!Number.isFinite(n)) return '-';
if (n >= 1440) return `${Math.round(n / 1440)}d`;
if (n >= 60) return `${Math.round(n / 60)}h`;
return `${n}m`;
@@ -158,8 +158,8 @@ const numOrNull = (v) => { const s = String(v ?? '').trim(); if (s === '') retur
// ── shared editor internals ────────────────────────────────────────────────────
// One source of truth for the strategy form, used by both the modal editor
-// (openStrategyEditor — in-context editing on an agent profile) and the full-page
-// builder (mountStrategyComposer — the /strategies "New strategy" flow). The field
+// (openStrategyEditor: in-context editing on an agent profile) and the full-page
+// builder (mountStrategyComposer: the /strategies "New strategy" flow). The field
// markup, parsing, live preview, and save all live here so the two surfaces can
// never drift apart.
function makeState(existing) {
@@ -189,7 +189,7 @@ function strategyFieldsHTML(state, { preview = true } = {}) {
return `<div class="so-field"><label>Name</label><input id="so-name" maxlength="80" placeholder="e.g. Fresh-launch sniper" value="${esc(state.name)}"></div>
<div class="so-field"><label>Description <span style="color:var(--ink-faint,#777)">(optional)</span></label><input id="so-desc" maxlength="2000" placeholder="What edge does this capture?" value="${esc(state.description)}"></div>
- <fieldset class="so-group"><legend>Entry — when to buy</legend>
+ <fieldset class="so-group"><legend>Entry: when to buy</legend>
<div class="so-grid">
<div class="so-field"><label>Max launch age (min)</label><input type="number" min="1" max="10080" id="so-age" value="${numVal(state.entry.max_age_minutes)}"><div class="so-hint">only act on launches newer than this</div></div>
<div class="so-field"><label>Min liquidity (◎ SOL)</label><input type="number" min="0" step="0.1" id="so-liq" value="${numVal(state.entry.min_liquidity_sol)}"></div>
@@ -208,10 +208,10 @@ function strategyFieldsHTML(state, { preview = true } = {}) {
</div>
</fieldset>
- <fieldset class="so-group"><legend>Exits — at least one upside exit + a stop-loss</legend>
+ <fieldset class="so-group"><legend>Exits: at least one upside exit + a stop-loss</legend>
<div class="so-grid">
<div class="so-field"><label>Take-profit (%)</label><input type="number" min="1" id="so-tp" value="${numVal(state.exits.take_profit_pct)}"><div class="so-hint">100 = sell at 2×</div></div>
- <div class="so-field"><label>Stop-loss (%) — required</label><input type="number" min="1" max="99" id="so-sl" value="${numVal(state.exits.stop_loss_pct)}"></div>
+ <div class="so-field"><label>Stop-loss (%), required</label><input type="number" min="1" max="99" id="so-sl" value="${numVal(state.exits.stop_loss_pct)}"></div>
<div class="so-field"><label>Trailing stop (%)</label><input type="number" min="1" max="99" id="so-trail" value="${numVal(state.exits.trailing_stop_pct)}"><div class="so-hint">% drop from peak</div></div>
<div class="so-field"><label>Max hold (min)</label><input type="number" min="1" id="so-hold" value="${numVal(state.exits.max_hold_minutes)}"></div>
</div>
@@ -302,7 +302,7 @@ export function openStrategyEditor({ existing = null } = {}) {
back.className = 'so-modal-back';
back.innerHTML = `<div class="so-modal" role="dialog" aria-modal="true" aria-label="${existing ? 'Edit' : 'New'} strategy">
<h3>${existing ? 'Edit strategy' : 'New strategy'}</h3>
- <p class="so-sub">A strategy is a real, rule-based plan. When equipped, your agent evaluates real launches and executes on-chain — always inside your spend policy.</p>
+ <p class="so-sub">A strategy is a real, rule-based plan. When equipped, your agent evaluates real launches and executes on-chain, always inside your spend policy.</p>
${strategyFieldsHTML(state)}
<div class="so-actions">
<button type="button" class="so-btn" id="so-cancel">Cancel</button>
@@ -337,7 +337,7 @@ export function openStrategyEditor({ existing = null } = {}) {
}
// ── the strategy builder (full page) ───────────────────────────────────────────
-// Renders the whole builder into `host` as a page — a two-column workspace with
+// Renders the whole builder into `host` as a page: a two-column workspace with
// the rules on the left and a sticky live summary + Create button on the right.
// This is the /strategies "New strategy" surface: a complex, multi-section form
// deserves room to breathe, not a cramped modal. onSaved(saved) fires after a
@@ -349,7 +349,7 @@ export function mountStrategyComposer(host, { existing = null, onSaved, onCancel
<div class="so-compose-head">
<button type="button" class="so-compose-back" id="so-back">← Strategies</button>
<h1 class="so-compose-title">${existing ? 'Edit strategy' : 'New strategy'}</h1>
- <p class="so-compose-lead">A strategy is a real, rule-based plan. When equipped, your agent evaluates real launches and executes on-chain — always inside your spend policy.</p>
+ <p class="so-compose-lead">A strategy is a real, rule-based plan. When equipped, your agent evaluates real launches and executes on-chain, always inside your spend policy.</p>
</div>
<div class="so-compose-grid">
<div class="so-compose-main">${strategyFieldsHTML(state, { preview: false })}</div>
@@ -358,9 +358,9 @@ export function mountStrategyComposer(host, { existing = null, onSaved, onCancel
<div class="so-side-h">Your strategy</div>
<div class="so-preview" id="so-preview">${previewText(state)}</div>
<ul class="so-side-points">
- <li><b>Spend-policy gated</b> — every trade is capped by your agent</li>
- <li><b>Real on-chain</b> — no backtested fiction</li>
- <li><b>Kill switch</b> — halt everything at once</li>
+ <li><b>Spend-policy gated</b>: every trade is capped by your agent</li>
+ <li><b>Real on-chain</b>: no backtested fiction</li>
+ <li><b>Kill switch</b>: halt everything at once</li>
</ul>
<div class="so-err" id="so-err" hidden></div>
<button type="button" class="so-btn so-btn-primary so-side-save" id="so-save">${existing ? 'Save changes' : 'Create strategy'}</button>
@@ -395,7 +395,7 @@ function structuredCloneSafe(o) {
try { return structuredClone(o); } catch { return JSON.parse(JSON.stringify(o)); }
}
-// ── equip picker — choose which of MY agents equips this strategy ──────────────
+// ── equip picker: choose which of MY agents equips this strategy ──────────────
// Resolves true if an equip was created.
export async function openEquipPicker({ strategy }) {
ensureStrategyStyles();
@@ -407,7 +407,7 @@ export async function openEquipPicker({ strategy }) {
mine = (j.agents || j.data?.agents || j.data || []).filter((a) => a && a.id);
}
} catch { /* handled below */ }
- if (!mine.length) { toast('You need your own agent first — create or fork one'); return false; }
+ if (!mine.length) { toast('You need your own agent first. Create or fork one'); return false; }
if (mine.length === 1) return equipOn(mine[0], strategy);
@@ -416,7 +416,7 @@ export async function openEquipPicker({ strategy }) {
back.className = 'so-modal-back';
back.innerHTML = `<div class="so-modal" role="dialog" aria-modal="true" aria-label="Pick an agent to equip">
<h3>Equip “${esc(strategy.name)}”</h3>
- <p class="so-sub">Pick the agent that will run these rules. It trades on-chain within <b style="color:var(--ink-bright,#fff)">its own</b> spend policy — no wallet access is shared.</p>
+ <p class="so-sub">Pick the agent that will run these rules. It trades on-chain within <b style="color:var(--ink-bright,#fff)">its own</b> spend policy. No wallet access is shared.</p>
<div>${mine.map((a) => `<button type="button" class="so-pick" data-id="${esc(a.id)}">${a.avatar_url || a.profile_image_url ? `<img loading="lazy" decoding="async" src="${esc(a.avatar_url || a.profile_image_url)}" alt="">` : '<div class="so-av"></div>'}<span class="so-pname">${esc(a.name || shortAddr(a.id))}</span></button>`).join('')}</div>
<div class="so-actions"><button type="button" class="so-btn" id="so-pick-cancel">Cancel</button></div>
</div>`;
@@ -442,7 +442,7 @@ async function equipOn(agent, strategy) {
});
const j = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(j?.error?.message || 'Could not equip');
- toast(`Equipped on ${agent.name || 'your agent'} — running within its limits`);
+ toast(`Equipped on ${agent.name || 'your agent'}, running within its limits`);
return true;
} catch (e) {
if (e?.redirected) return false;
diff --git a/src/strategies.js b/src/strategies.js
index 36a5bd126..c589d6328 100644
--- a/src/strategies.js
+++ b/src/strategies.js
@@ -1,15 +1,15 @@
-// /strategies — the Strategy Object library: a marketplace of HOW agents trade.
+// /strategies: the Strategy Object library, a marketplace of HOW agents trade.
//
// Three real surfaces, one page:
-// • Marketplace — every published strategy, ranked honestly (proven first). Fork
+// • Marketplace: every published strategy, ranked honestly (proven first). Fork
// into your library or equip on your own agent.
-// • Leaderboard — proven strategies ranked by REAL live ROI from on-chain fills.
-// • My library — your strategies: create, edit, publish, equip, delete.
+// • Leaderboard: proven strategies ranked by REAL live ROI from on-chain fills.
+// • My library: your strategies (create, edit, publish, equip, delete).
//
// Every number traces to a real fill (agent_strategy_positions). A strategy with no
-// closed trades is honestly "Unproven" — never a fabricated backtest curve.
+// closed trades is honestly "Unproven", never a fabricated backtest curve.
-import { apiFetch } from './api.js';
+import { apiFetch, noteSession } from './api.js';
import {
esc, shortAddr, fmtSol, timeAgo, toast, configSummary,
mountStrategyComposer, openEquipPicker,
@@ -21,7 +21,7 @@ const searchInput = document.getElementById('sp-search');
// ── full-page builder ──────────────────────────────────────────────────────────
// The "New strategy" / "Edit" flow renders the builder inline as a page (not a
-// modal) — a multi-section form deserves room. State lives in the URL (?editor=new
+// modal): a multi-section form deserves room. State lives in the URL (?editor=new
// or ?editor=<id>) so it survives reload and works with the back button.
const shell = document.querySelector('.sp-shell');
const heroEl = shell?.querySelector('.sp-hero');
@@ -59,7 +59,7 @@ function leaveComposeView() {
showLibraryChrome(true);
}
-// Return to the library, cleaning ?editor from the URL (replaceState — no junk
+// Return to the library, cleaning ?editor from the URL (replaceState, so no junk
// history entry). toScope optionally switches the active tab (e.g. to "mine"
// after a create so the new strategy is visible).
function exitCompose({ toScope } = {}) {
@@ -80,7 +80,7 @@ async function fetchStrategy(id) {
} catch { return null; }
}
-// Reconcile the view with the URL — runs on first load and on every back/forward.
+// Reconcile the view with the URL. Runs on first load and on every back/forward.
async function syncFromUrl() {
const editor = new URL(location.href).searchParams.get('editor');
if (!editor) { if (composing) leaveComposeView(); load(); return; }
@@ -109,7 +109,7 @@ function perfBadge(p) {
: '<span class="sp-badge unproven">Unproven</span>';
}
function statsLine(p) {
- if (!p || !p.proven) return '<span>No closed trades yet — equip it to build a record</span>';
+ if (!p || !p.proven) return '<span>No closed trades yet. Equip it to build a record</span>';
const roi = p.roi_pct != null ? `<span class="${p.roi_pct >= 0 ? 'pos' : 'neg'}">${p.roi_pct >= 0 ? '+' : ''}${p.roi_pct}% ROI</span>` : '';
const pnl = `<span class="${p.pnl_sol >= 0 ? 'pos' : 'neg'}">${p.pnl_sol >= 0 ? '+' : ''}◎${fmtSol(p.pnl_sol)}</span>`;
const win = p.win_rate != null ? `<span>${p.win_rate}% win</span>` : '';
@@ -148,27 +148,41 @@ function card(s, isMine) {
function renderEmpty() {
if (scope === 'mine') {
- grid.innerHTML = `<div class="sp-empty"><strong>No strategies yet</strong>Build your first rule-based plan — entry, sizing, take-profit, stop-loss — then equip it on your agent.<br><br><button class="sp-btn sp-btn-primary" id="sp-empty-new" style="max-width:220px;margin:0 auto">+ Create a strategy</button></div>`;
+ grid.innerHTML = `<div class="sp-empty"><strong>No strategies yet</strong>Build your first rule-based plan (entry, sizing, take-profit, stop-loss), then equip it on your agent.<br><br><button class="sp-btn sp-btn-primary" id="sp-empty-new" style="max-width:220px;margin:0 auto">+ Create a strategy</button></div>`;
document.getElementById('sp-empty-new')?.addEventListener('click', createNew);
} else if (scope === 'leaderboard') {
- grid.innerHTML = `<div class="sp-empty"><strong>No proven strategies yet</strong>The leaderboard ranks strategies by real, on-chain live performance. As equipped strategies close their first trades, they appear here — ranked by verified ROI, not promises.</div>`;
+ grid.innerHTML = `<div class="sp-empty"><strong>No proven strategies yet</strong>The leaderboard ranks strategies by real, on-chain live performance. As equipped strategies close their first trades, they appear here, ranked by verified ROI, not promises.</div>`;
} else {
grid.innerHTML = `<div class="sp-empty"><strong>No published strategies yet</strong>Be the first: build a strategy, prove it on real chain data, and publish it for others to fork and equip.<br><br><button class="sp-btn sp-btn-primary" id="sp-empty-new" style="max-width:220px;margin:0 auto">+ Create a strategy</button></div>`;
document.getElementById('sp-empty-new')?.addEventListener('click', createNew);
}
}
+// The library tab for a signed-out visitor. Rendered without asking the API:
+// /api/strategies?scope=mine can only answer 401 without a session, and every
+// such request prints a red network error in the visitor's console.
+function renderSignIn() {
+ const next = encodeURIComponent('/strategies?scope=mine');
+ grid.innerHTML = `<div class="sp-empty"><strong>Sign in to see your library</strong>Your strategies live in your account. Sign in to create, edit, and equip them.<br><br><a class="sp-btn sp-btn-primary" href="/login?next=${next}" style="max-width:200px;margin:0 auto;text-decoration:none;display:block">Sign in</a></div>`;
+}
+
async function load() {
const seq = ++_seq;
grid.innerHTML = '<div class="sp-sk"></div><div class="sp-sk"></div><div class="sp-sk"></div>';
let strategies = [];
try {
+ if (scope === 'mine' && !(await ensureAuthed())) {
+ if (seq === _seq) renderSignIn();
+ return;
+ }
let path;
if (scope === 'leaderboard') path = '/api/strategies/leaderboard?limit=30';
else path = `/api/strategies?scope=${scope}&limit=40${query ? `&q=${encodeURIComponent(query)}` : ''}`;
const res = await apiFetch(path, { allowAnonymous: true });
if (res.status === 401 && scope === 'mine') {
- grid.innerHTML = `<div class="sp-empty"><strong>Sign in to see your library</strong>Your strategies live in your account — sign in to create, edit, and equip them.<br><br><a class="sp-btn sp-btn-primary" href="/login?next=${encodeURIComponent('/strategies')}" style="max-width:200px;margin:0 auto;text-decoration:none;display:block">Sign in</a></div>`;
+ authed = false;
+ noteSession(false);
+ if (seq === _seq) renderSignIn();
return;
}
if (!res.ok) throw new Error('load failed');
@@ -217,7 +231,7 @@ async function doFork(s, btn) {
const res = await apiFetch(`/api/strategies/${s.id}/fork`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' });
const j = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(j?.error?.message || 'Fork failed');
- toast(`Forked “${s.name}” into your library — yours to tweak and equip`);
+ toast(`Forked “${s.name}” into your library. Yours to tweak and equip`);
} catch (e) { if (!e?.redirected) toast(e.message || 'Fork failed'); }
finally { btn.disabled = false; btn.textContent = '🍴 Fork'; }
}
@@ -234,7 +248,7 @@ async function doPublish(s, btn) {
const res = await apiFetch(`/api/strategies/${s.id}/publish`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ published: !s.published }) });
const j = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(j?.error?.message || 'Could not update');
- toast(j.data?.published ? 'Published — others can fork & equip it' : 'Unpublished');
+ toast(j.data?.published ? 'Published. Others can fork & equip it' : 'Unpublished');
load();
} catch (e) { if (!e?.redirected) toast(e.message || 'Could not update'); btn.disabled = false; }
}
@@ -255,12 +269,18 @@ async function createNew() {
enterCompose(null);
}
+// /api/auth/me answers 200 for everyone and puts the answer in the body:
+// { user: {...} } with a session, { user: null } without one. Reading res.ok
+// here called every anonymous visitor signed in, which opened the equip picker
+// and the builder for them and let Fork fire a request that could only 401.
async function ensureAuthed() {
if (authed != null) return authed;
try {
const res = await apiFetch('/api/auth/me', { allowAnonymous: true });
- authed = res.ok;
+ const body = res.ok ? await res.json().catch(() => null) : null;
+ authed = !!body?.user;
} catch { authed = false; }
+ noteSession(authed);
return authed;
}