sellwavy-cli 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/README.md +65 -2
- package/bin/sellwavy.mjs +178 -0
- package/lib/api.mjs +67 -0
- package/lib/commands.mjs +661 -0
- package/lib/config.mjs +96 -0
- package/lib/core.mjs +238 -0
- package/lib/guide.d.mts +8 -0
- package/lib/guide.mjs +104 -0
- package/lib/mcp.mjs +383 -0
- package/lib/sections.d.mts +52 -0
- package/lib/sections.mjs +253 -0
- package/lib/site.mjs +129 -0
- package/lib/ui.mjs +72 -0
- package/lib/version.mjs +1 -0
- package/package.json +26 -4
package/lib/config.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where the CLI keeps what it knows.
|
|
7
|
+
*
|
|
8
|
+
* ~/.sellwavy/config.json who is signed in: the host and the key. Readable
|
|
9
|
+
* by this user only.
|
|
10
|
+
* <project>/.sellwavy/ which store a folder works on, and the state of
|
|
11
|
+
* its last pull or push. Safe to commit except
|
|
12
|
+
* that it names the store.
|
|
13
|
+
*
|
|
14
|
+
* SELLWAVY_TOKEN and SELLWAVY_HOST override the file, for CI and agents
|
|
15
|
+
* that are given a key rather than logging in.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_HOST = 'https://sellwavy.com'
|
|
19
|
+
|
|
20
|
+
const CONFIG_DIR = process.env.SELLWAVY_CONFIG_DIR || path.join(os.homedir(), '.sellwavy')
|
|
21
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json')
|
|
22
|
+
|
|
23
|
+
export function readConfig() {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'))
|
|
26
|
+
} catch {
|
|
27
|
+
return {}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function writeConfig(config) {
|
|
32
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 })
|
|
33
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + '\n', { mode: 0o600 })
|
|
34
|
+
// An existing file keeps its old mode on write; make sure it is private.
|
|
35
|
+
try { fs.chmodSync(CONFIG_FILE, 0o600) } catch { /* not supported on every filesystem */ }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function configPath() {
|
|
39
|
+
return CONFIG_FILE
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The Sellwavy server to talk to: --host, then SELLWAVY_HOST, then the one logged in to. */
|
|
43
|
+
export function resolveHost(flags = {}) {
|
|
44
|
+
const raw = flags.host || process.env.SELLWAVY_HOST || readConfig().host || DEFAULT_HOST
|
|
45
|
+
return String(raw).replace(/\/+$/, '')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function resolveToken() {
|
|
49
|
+
return process.env.SELLWAVY_TOKEN || readConfig().token || null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── The project: a folder linked to one store ─────────────────────────────
|
|
53
|
+
|
|
54
|
+
const PROJECT_DIR = '.sellwavy'
|
|
55
|
+
|
|
56
|
+
/** The nearest folder, from here up, that is linked to a store. */
|
|
57
|
+
export function findProjectRoot(start = process.cwd()) {
|
|
58
|
+
let dir = path.resolve(start)
|
|
59
|
+
for (;;) {
|
|
60
|
+
if (fs.existsSync(path.join(dir, PROJECT_DIR, 'project.json'))) return dir
|
|
61
|
+
const up = path.dirname(dir)
|
|
62
|
+
if (up === dir) return null
|
|
63
|
+
dir = up
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function readProject(root = findProjectRoot()) {
|
|
68
|
+
if (!root) return null
|
|
69
|
+
try {
|
|
70
|
+
return { root, ...JSON.parse(fs.readFileSync(path.join(root, PROJECT_DIR, 'project.json'), 'utf8')) }
|
|
71
|
+
} catch {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function writeProject(root, data) {
|
|
77
|
+
const dir = path.join(root, PROJECT_DIR)
|
|
78
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
79
|
+
fs.writeFileSync(path.join(dir, 'project.json'), JSON.stringify(data, null, 2) + '\n')
|
|
80
|
+
// The key never lives here, but the sync state is per machine.
|
|
81
|
+
const ignore = path.join(dir, '.gitignore')
|
|
82
|
+
if (!fs.existsSync(ignore)) fs.writeFileSync(ignore, 'site-state.json\n')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function readState(root, name) {
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(fs.readFileSync(path.join(root, PROJECT_DIR, name), 'utf8'))
|
|
88
|
+
} catch {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function writeState(root, name, data) {
|
|
94
|
+
fs.mkdirSync(path.join(root, PROJECT_DIR), { recursive: true })
|
|
95
|
+
fs.writeFileSync(path.join(root, PROJECT_DIR, name), JSON.stringify(data, null, 2) + '\n')
|
|
96
|
+
}
|
package/lib/core.mjs
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { CliError } from './ui.mjs'
|
|
4
|
+
import { GLOBAL_KEYS, PAGES, labelFor, normalizeKey, normalizeSections, orderSections, pageOf } from './sections.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What the CLI and the MCP server both do to a store. Each takes the API
|
|
8
|
+
* client and a store id and returns plain data; printing is the caller's.
|
|
9
|
+
* The sections themselves (pages, files, merging, checks) are sections.mjs.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './sections.mjs'
|
|
13
|
+
|
|
14
|
+
/** The store's pages as they are live now. */
|
|
15
|
+
export async function getSite(api, storeId) {
|
|
16
|
+
const theme = await api.get(`/api/stores/${storeId}/theme`)
|
|
17
|
+
return { aiDesign: !!theme?.aiHome, sections: orderSections(normalizeSections(theme?.aiSections)) }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Saves the whole list of sections, cleaned by the server exactly as the
|
|
22
|
+
* visual editor's Save does, and returns them as stored. `activate` turns the
|
|
23
|
+
* store's AI design on, so the pages show on the live store.
|
|
24
|
+
*/
|
|
25
|
+
export async function saveSite(api, storeId, sections, { activate = true } = {}) {
|
|
26
|
+
const body = { aiSections: orderSections(sections).map(s => ({ key: s.key, label: s.label, html: s.html, page: pageOf(s) })) }
|
|
27
|
+
if (activate) body.aiHome = true
|
|
28
|
+
const theme = await api.post(`/api/stores/${storeId}/theme`, body)
|
|
29
|
+
return { aiDesign: !!theme?.aiHome, sections: orderSections(normalizeSections(theme?.aiSections)) }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One section added or replaced, the rest left as they are. A new section
|
|
34
|
+
* goes at the end of its page, or before/after the section named.
|
|
35
|
+
*/
|
|
36
|
+
export function upsertSection(sections, { page, key, label, html, before, after }) {
|
|
37
|
+
const k = normalizeKey(key)
|
|
38
|
+
if (!k) throw new CliError('A section needs a key, such as "hero" or "faq".')
|
|
39
|
+
if (typeof html !== 'string' || !html.trim()) throw new CliError('A section needs its HTML.')
|
|
40
|
+
if (page === 'global' && !GLOBAL_KEYS.includes(k)) {
|
|
41
|
+
throw new CliError('Only "header" and "footer" are shared by every page. Put other sections on a page: ' + PAGES.join(', ') + '.')
|
|
42
|
+
}
|
|
43
|
+
const target = GLOBAL_KEYS.includes(k) ? 'global' : page
|
|
44
|
+
if (target !== 'global' && !PAGES.includes(target)) {
|
|
45
|
+
throw new CliError(`Unknown page "${page}". Pages are: ${PAGES.join(', ')} (header and footer are shared).`)
|
|
46
|
+
}
|
|
47
|
+
const list = sections.slice()
|
|
48
|
+
const at = list.findIndex(s => pageOf(s) === target && s.key === k)
|
|
49
|
+
const entry = { key: k, label: (label || (at >= 0 ? list[at].label : '') || labelFor(k)).slice(0, 40), html: html.trim(), page: target }
|
|
50
|
+
const anchorKey = before ? normalizeKey(before) : after ? normalizeKey(after) : null
|
|
51
|
+
|
|
52
|
+
if (at >= 0 && !anchorKey) {
|
|
53
|
+
list[at] = entry
|
|
54
|
+
return list
|
|
55
|
+
}
|
|
56
|
+
if (at >= 0) list.splice(at, 1)
|
|
57
|
+
if (anchorKey) {
|
|
58
|
+
const anchor = list.findIndex(s => pageOf(s) === target && s.key === anchorKey)
|
|
59
|
+
if (anchor < 0) throw new CliError(`There is no section "${anchorKey}" on the ${target} page.`)
|
|
60
|
+
list.splice(before ? anchor : anchor + 1, 0, entry)
|
|
61
|
+
return list
|
|
62
|
+
}
|
|
63
|
+
list.push(entry)
|
|
64
|
+
return orderSections(list)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function removeSection(sections, { page, key }) {
|
|
68
|
+
const k = normalizeKey(key)
|
|
69
|
+
const target = GLOBAL_KEYS.includes(k) ? 'global' : page
|
|
70
|
+
const list = sections.filter(s => !(pageOf(s) === target && s.key === k))
|
|
71
|
+
if (list.length === sections.length) throw new CliError(`There is no section "${k}" on the ${target} page.`)
|
|
72
|
+
return list
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function reorderSections(sections, { page, keys }) {
|
|
76
|
+
if (!PAGES.includes(page)) throw new CliError(`Unknown page "${page}". Pages are: ${PAGES.join(', ')}.`)
|
|
77
|
+
const mine = sections.filter(s => pageOf(s) === page)
|
|
78
|
+
const wanted = keys.map(normalizeKey)
|
|
79
|
+
const missing = wanted.filter(k => !mine.some(s => s.key === k))
|
|
80
|
+
if (missing.length) throw new CliError(`Not on the ${page} page: ${missing.join(', ')}.`)
|
|
81
|
+
const ordered = [...wanted.map(k => mine.find(s => s.key === k)), ...mine.filter(s => !wanted.includes(s.key))]
|
|
82
|
+
return orderSections([...sections.filter(s => pageOf(s) !== page), ...ordered])
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ── Media ─────────────────────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
const MIME = {
|
|
88
|
+
jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp', gif: 'image/gif', avif: 'image/avif', svg: 'image/svg+xml',
|
|
89
|
+
mp4: 'video/mp4', m4v: 'video/mp4', webm: 'video/webm', mov: 'video/quicktime', ogv: 'video/ogg',
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Whether an address is a file already on Sellwavy's image host. */
|
|
93
|
+
export function isLibraryUrl(src) {
|
|
94
|
+
return /^https:\/\/ik\.imagekit\.io\//i.test(String(src))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function mimeOf(name) {
|
|
98
|
+
const ext = path.extname(String(name).split('?')[0]).slice(1).toLowerCase()
|
|
99
|
+
return MIME[ext] ?? null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function slugFileName(name) {
|
|
103
|
+
const ext = path.extname(name).toLowerCase()
|
|
104
|
+
const base = path.basename(name, path.extname(name)).toLowerCase().normalize('NFKD').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60)
|
|
105
|
+
return `${base || 'file'}${ext}`
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Puts a photo or video into the store's media library: the same three steps
|
|
110
|
+
* as the dashboard (a signature from Sellwavy, the upload straight to the
|
|
111
|
+
* image host, a record in the library), so it shows up in the media library
|
|
112
|
+
* and the visual editor like anything uploaded there. `source` is a local
|
|
113
|
+
* file or an https:// address to copy.
|
|
114
|
+
*/
|
|
115
|
+
export async function uploadMedia(api, storeId, source) {
|
|
116
|
+
const isUrl = /^https?:\/\//i.test(source)
|
|
117
|
+
const name = isUrl ? decodeURIComponent(new URL(source).pathname.split('/').pop() || 'file') : path.basename(source)
|
|
118
|
+
const mime = mimeOf(name)
|
|
119
|
+
if (!mime) throw new CliError(`${name}: only photos (jpg, png, webp, gif, avif, svg) and videos (mp4, webm, mov) can be uploaded.`)
|
|
120
|
+
if (!isUrl && !fs.existsSync(source)) throw new CliError(`No such file: ${source}`)
|
|
121
|
+
|
|
122
|
+
const auth = await api.get('/api/imagekit-auth')
|
|
123
|
+
if (!auth?.publicKey) throw new CliError('This Sellwavy server is not set up for uploads.')
|
|
124
|
+
|
|
125
|
+
const form = new FormData()
|
|
126
|
+
if (isUrl) form.append('file', source)
|
|
127
|
+
else form.append('file', new Blob([await fs.promises.readFile(source)], { type: mime }), name)
|
|
128
|
+
form.append('fileName', slugFileName(name))
|
|
129
|
+
form.append('publicKey', auth.publicKey)
|
|
130
|
+
form.append('signature', auth.signature)
|
|
131
|
+
form.append('expire', String(auth.expire))
|
|
132
|
+
form.append('token', auth.token)
|
|
133
|
+
form.append('folder', `/stores/${storeId}`)
|
|
134
|
+
|
|
135
|
+
const res = await fetch('https://upload.imagekit.io/api/v1/files/upload', { method: 'POST', body: form })
|
|
136
|
+
const uploaded = await res.json().catch(() => ({}))
|
|
137
|
+
if (!res.ok) throw new CliError(`${name}: upload failed (${uploaded?.message || `HTTP ${res.status}`}).`)
|
|
138
|
+
|
|
139
|
+
return api.post(`/api/stores/${storeId}/media`, {
|
|
140
|
+
url: uploaded.url,
|
|
141
|
+
fileId: uploaded.fileId,
|
|
142
|
+
filename: uploaded.name,
|
|
143
|
+
type: mime.startsWith('video/') ? 'video' : 'image',
|
|
144
|
+
size: uploaded.size,
|
|
145
|
+
width: uploaded.width,
|
|
146
|
+
height: uploaded.height,
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ── Products ──────────────────────────────────────────────────────────────
|
|
151
|
+
|
|
152
|
+
/** A price typed by a person ("25", "19.99") in the store's smallest unit. */
|
|
153
|
+
export function toCents(value) {
|
|
154
|
+
const n = Number(String(value).replace(/[, ]/g, ''))
|
|
155
|
+
if (!Number.isFinite(n) || n < 0) throw new CliError(`"${value}" is not a price.`)
|
|
156
|
+
return Math.round(n * 100)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A product's fields from loose input (CLI flags, an agent's arguments, a
|
|
161
|
+
* JSON file), in the shape the products API takes. Photos given as local
|
|
162
|
+
* files are uploaded first.
|
|
163
|
+
*/
|
|
164
|
+
export async function productBody(api, storeId, input, { partial = false } = {}) {
|
|
165
|
+
const body = {}
|
|
166
|
+
if (input.title !== undefined) body.title = String(input.title).trim()
|
|
167
|
+
if (input.description !== undefined) body.description = String(input.description)
|
|
168
|
+
if (input.price !== undefined) body.price = toCents(input.price)
|
|
169
|
+
const stock = input.inventory ?? input.stock
|
|
170
|
+
if (stock !== undefined) body.inventory = Math.max(0, Math.round(Number(stock)) || 0)
|
|
171
|
+
if (input.category !== undefined) body.category = String(input.category) || null
|
|
172
|
+
if (input.sku !== undefined) body.sku = String(input.sku) || null
|
|
173
|
+
if (input.status !== undefined) {
|
|
174
|
+
const status = String(input.status).toLowerCase()
|
|
175
|
+
if (!['active', 'draft'].includes(status)) throw new CliError('Status is "active" or "draft".')
|
|
176
|
+
body.status = status
|
|
177
|
+
}
|
|
178
|
+
if (input.tags !== undefined) body.tags = Array.isArray(input.tags) ? input.tags : String(input.tags).split(',').map(t => t.trim()).filter(Boolean)
|
|
179
|
+
if (input.seoTitle !== undefined) body.seoTitle = input.seoTitle
|
|
180
|
+
if (input.seoDescription !== undefined) body.seoDescription = input.seoDescription
|
|
181
|
+
|
|
182
|
+
const images = [].concat(input.images ?? input.image ?? []).filter(Boolean)
|
|
183
|
+
if (images.length) {
|
|
184
|
+
const urls = []
|
|
185
|
+
for (const img of images) {
|
|
186
|
+
const src = typeof img === 'string' ? img : img.url
|
|
187
|
+
// Already in a Sellwavy media library: used as it is. A local file, or
|
|
188
|
+
// a photo elsewhere on the web, is put into this store's library first,
|
|
189
|
+
// so it is hosted with the store and shows up in the editor.
|
|
190
|
+
urls.push(isLibraryUrl(src) ? src : (await uploadMedia(api, storeId, src)).url)
|
|
191
|
+
}
|
|
192
|
+
body.imageUrl = urls[0]
|
|
193
|
+
body.images = urls.map(url => ({ url }))
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!partial) {
|
|
197
|
+
if (!body.title) throw new CliError('A product needs a title.')
|
|
198
|
+
if (!body.price) throw new CliError('A product needs a price above 0.')
|
|
199
|
+
}
|
|
200
|
+
return body
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Finds a product by id, slug or exact title. */
|
|
204
|
+
export async function findProduct(api, storeId, ref) {
|
|
205
|
+
const list = await api.get(`/api/stores/${storeId}/products`)
|
|
206
|
+
const want = String(ref).toLowerCase()
|
|
207
|
+
const hit = list.find(p => p.id === ref) || list.find(p => (p.slug || '').toLowerCase() === want) || list.find(p => p.title.toLowerCase() === want)
|
|
208
|
+
if (!hit) throw new CliError(`No product "${ref}". List them with: sellwavy products list`)
|
|
209
|
+
return hit
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ── Stores ────────────────────────────────────────────────────────────────
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The store a command works on: the one named (id, subdomain or name), the
|
|
216
|
+
* folder's linked store, or the owner's only store.
|
|
217
|
+
*/
|
|
218
|
+
export async function resolveStore(api, { wanted, project } = {}) {
|
|
219
|
+
const me = await api.get('/api/cli/me')
|
|
220
|
+
const stores = me.stores ?? []
|
|
221
|
+
const match = ref => {
|
|
222
|
+
const r = String(ref).toLowerCase()
|
|
223
|
+
return stores.find(s => s.id === ref) || stores.find(s => s.subdomain === r) || stores.find(s => s.name.toLowerCase() === r)
|
|
224
|
+
}
|
|
225
|
+
if (wanted) {
|
|
226
|
+
const hit = match(wanted)
|
|
227
|
+
if (!hit) throw new CliError(`No store "${wanted}". Yours: ${stores.map(s => s.subdomain).join(', ') || 'none'}.`)
|
|
228
|
+
return { me, store: hit }
|
|
229
|
+
}
|
|
230
|
+
if (project?.storeId) {
|
|
231
|
+
const hit = match(project.storeId)
|
|
232
|
+
if (!hit) throw new CliError('This folder is linked to a store that is no longer available. Run: sellwavy link')
|
|
233
|
+
return { me, store: hit }
|
|
234
|
+
}
|
|
235
|
+
if (stores.length === 1) return { me, store: stores[0] }
|
|
236
|
+
if (stores.length === 0) throw new CliError('You have no stores yet. Create one on Sellwavy first.')
|
|
237
|
+
throw new CliError(`You have ${stores.length} stores. Run "sellwavy link" in this folder, or add --store <${stores.map(s => s.subdomain).join('|')}>.`)
|
|
238
|
+
}
|
package/lib/guide.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Types for guide.mjs, which the dashboard imports for the .zip download.
|
|
2
|
+
|
|
3
|
+
export declare const HOOKS: string
|
|
4
|
+
export declare const RULES: string
|
|
5
|
+
export declare const EDITOR: string
|
|
6
|
+
export declare const CLAUDE_MD: string
|
|
7
|
+
export declare const MCP_INSTRUCTIONS: string
|
|
8
|
+
export declare function agentsGuide(store?: { storeName?: string; storeUrl?: string; editorUrl?: string }): string
|
package/lib/guide.mjs
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guide an AI agent reads before working on a Sellwavy store: written to
|
|
3
|
+
* AGENTS.md (and CLAUDE.md, which points at it) by `sellwavy init` and
|
|
4
|
+
* `sellwavy site pull`, and returned by the MCP server's sellwavy_guide tool.
|
|
5
|
+
*
|
|
6
|
+
* The hooks and rules here are the ones Sellwavy AI itself follows
|
|
7
|
+
* (src/lib/ai/site-code.ts), so a page an agent writes behaves, and edits in
|
|
8
|
+
* the visual editor, exactly like one Sellwavy AI wrote.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const HOOKS = `## Hooks: how a page shows the store's live data
|
|
12
|
+
|
|
13
|
+
Sections are plain HTML styled with Tailwind CSS v4 classes (every utility, arbitrary values like bg-[#0b0b0f] too). Sellwavy fills in these hooks when the page is shown:
|
|
14
|
+
|
|
15
|
+
- \`{{store.name}}\`, \`{{store.email}}\` (may be empty), \`{{year}}\`.
|
|
16
|
+
- Logo: \`<a href="/" data-sw-logo class="...">{{store.name}}</a>\` where the brand goes (header, footer). Sellwavy shows the store's logo there when it has one; otherwise what is inside shows. Never draw a made-up logo or monogram.
|
|
17
|
+
- Links: \`/\` home, \`/products\` all products, \`/about\`, \`/contact\`, \`/account\` (the shopper's account and orders). There is no cart page.
|
|
18
|
+
- Products: put \`data-sw-products\` on an element with ONE product card inside; it is repeated per product. Optional \`data-limit="8"\` and \`data-category="Category name"\`. In the card: \`{{product.title}}\`, \`{{product.price}}\` (formatted), \`{{product.image}}\`, \`{{product.url}}\`, \`{{product.category}}\`, \`{{product.id}}\`. Add to cart: \`<button data-sw-add="{{product.id}}">Add to cart</button>\`.
|
|
19
|
+
- Categories: \`data-sw-categories\` with ONE card inside, repeated: \`{{category.name}}\`, \`{{category.url}}\`, \`{{category.image}}\`.
|
|
20
|
+
- Cart: \`data-sw-cart\` on a button opens the cart drawer; \`<span data-sw-cart-count></span>\` shows the item count.
|
|
21
|
+
- Menu: a button with \`data-sw-toggle="menu"\` shows/hides the element with \`id="menu"\` (start it with class \`hidden\`).
|
|
22
|
+
- Open/close (FAQ, read more): \`<details class="group"><summary>Q</summary><p>A</p></details>\`; style with \`group-open:\`.
|
|
23
|
+
- Products page: \`{{page.title}}\` is "All products" or the chosen category; use \`data-sw-categories\` for category links and \`data-sw-products\` for the grid (it filters itself).
|
|
24
|
+
- Product page: \`{{product.title}}\`, \`{{product.price}}\`, \`{{product.description}}\`, \`{{product.category}}\`, \`{{product.image}}\`; a gallery with \`data-sw-gallery\` holding ONE \`<img src="{{image.url}}" alt="{{image.alt}}">\` repeated per photo; and \`<div data-sw-buy></div>\` where Sellwavy puts size/colour, quantity, Add to cart and Buy now. Required: without it nobody can buy.
|
|
25
|
+
- A photo spot for the owner to fill: \`<img data-sw-image alt="what it should show" class="...">\` with no src. Hidden until filled, so the section must look fine without it.
|
|
26
|
+
- Photos and videos: upload them (\`sellwavy media upload <file>\` or the upload_media tool) and use the address you get back: \`<img src="..." alt="...">\` or \`<video src="..." autoplay muted loop playsinline class="..."></video>\`. Never invent image URLs.`
|
|
27
|
+
|
|
28
|
+
export const RULES = `## Rules (the server's cleaner enforces them)
|
|
29
|
+
|
|
30
|
+
- No \`<script>\`, \`<style>\`, \`<iframe>\`, inline event handlers or \`javascript:\` links: they are removed. Interactions only through the hooks above and CSS (hover:, group-hover:, transitions, sticky, scroll-snap carousels).
|
|
31
|
+
- No \`<form>\`, \`<input>\`, \`<textarea>\`, \`<select>\` (newsletter boxes included): removed, there is nowhere to send them.
|
|
32
|
+
- No fonts: no font-sans/serif/mono/[...] classes or font-family. The store's fonts are chosen in the editor. Weights, sizes, tracking and case are fine.
|
|
33
|
+
- Each section is one HTML fragment (no <html>, <head>, <body>), at most 40,000 characters; at most 60 sections in the whole store.
|
|
34
|
+
- Responsive, mobile first (sm: md: lg:). Strong text contrast. A fixed header needs top padding on the first section of every page.
|
|
35
|
+
- Never invent facts in copy: no prices, discounts, delivery times, guarantees, awards, materials or history the owner did not give. Sample testimonials must be clearly generic (first names only). Write in the language of the store's products.
|
|
36
|
+
- Keep one consistent style across every page.`
|
|
37
|
+
|
|
38
|
+
export const EDITOR = `## The visual editor stays in charge
|
|
39
|
+
|
|
40
|
+
Everything you push opens in the owner's visual editor at once. Each piece of text, each photo and each video becomes a field there: the owner clicks it on the page and edits it in the sidebar, as with any Sellwavy AI page. Keep text as real text in the HTML (not baked into images) so it stays editable. The owner may change things in the editor after you push: pull before you edit again.`
|
|
41
|
+
|
|
42
|
+
export function agentsGuide({ storeName = '', storeUrl = '', editorUrl = '' } = {}) {
|
|
43
|
+
return `# Sellwavy store${storeName ? `: ${storeName}` : ''}
|
|
44
|
+
|
|
45
|
+
<!-- Written by the Sellwavy CLI (npx sellwavy-cli). Safe to edit; "npx sellwavy-cli agents --force" rewrites it. -->
|
|
46
|
+
|
|
47
|
+
This folder is linked to a Sellwavy online store${storeUrl ? ` (live at ${storeUrl}` : ''}${editorUrl ? `${storeUrl ? ', ' : ' ('}visual editor: ${editorUrl})` : storeUrl ? ')' : ''}. You can change its pages, products, orders and media with the \`sellwavy\` CLI. Every command takes \`--json\` for machine-readable output.
|
|
48
|
+
|
|
49
|
+
## Workflow for pages
|
|
50
|
+
|
|
51
|
+
1. \`npx sellwavy-cli site pull\` downloads the store's pages into \`site/\`.
|
|
52
|
+
2. Edit or add HTML files in \`site/\` (layout below).
|
|
53
|
+
3. \`npx sellwavy-cli site push --dry-run\` shows what would change and warns about code the cleaner removes.
|
|
54
|
+
4. \`npx sellwavy-cli site push\` saves it live. Changes are on the real store immediately.
|
|
55
|
+
|
|
56
|
+
Push refuses when the store changed since the last pull (the owner saved in the editor). Pull again, re-apply your change, then push. Only use \`--force\` if the owner asks to overwrite their edits.
|
|
57
|
+
|
|
58
|
+
## Files in site/
|
|
59
|
+
|
|
60
|
+
\`\`\`
|
|
61
|
+
site/header.html shared header, on every page
|
|
62
|
+
site/footer.html shared footer, on every page
|
|
63
|
+
site/home/01-hero.html home page sections, in file-name order
|
|
64
|
+
site/products/01-grid.html all products page (also category pages)
|
|
65
|
+
site/product/01-main.html one product's page
|
|
66
|
+
site/about/... about page
|
|
67
|
+
site/contact/... contact page
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
- Each file is one section. Its key is the file name without the number (\`01-hero.html\` is "hero"); keys are unique per page. Order comes from the number.
|
|
71
|
+
- The first line \`<!-- section: Hero -->\` is the name the owner sees in the editor.
|
|
72
|
+
- Add a section: create a file. Remove one: delete the file. Reorder: rename the numbers.
|
|
73
|
+
- Only these five pages exist. Checkout, cart and account pages are Sellwavy's own.
|
|
74
|
+
|
|
75
|
+
${HOOKS}
|
|
76
|
+
|
|
77
|
+
${RULES}
|
|
78
|
+
|
|
79
|
+
${EDITOR}
|
|
80
|
+
|
|
81
|
+
## Other commands
|
|
82
|
+
|
|
83
|
+
\`\`\`
|
|
84
|
+
npx sellwavy-cli products list | get <id> | create --title T --price 25 [--image ./a.jpg] | update <id> --price 30 | delete <id> --yes
|
|
85
|
+
npx sellwavy-cli products import products.json # [{ "title", "price", "description", "category", "inventory", "images": [...] }]
|
|
86
|
+
npx sellwavy-cli orders list [--status PAID] | get <id> | ship <id> [--tracking "DHL 123"] | mark-paid <id>
|
|
87
|
+
npx sellwavy-cli media upload <files...> # photos and videos; prints their addresses
|
|
88
|
+
npx sellwavy-cli media list
|
|
89
|
+
npx sellwavy-cli theme get | set primaryColor=#111111 font=sans logoUrl=https://...
|
|
90
|
+
npx sellwavy-cli ai "make the hero darker" [--page home] # ask Sellwavy AI to do it instead
|
|
91
|
+
npx sellwavy-cli api GET /discounts # any store API route, relative to /api/stores/<store>
|
|
92
|
+
npx sellwavy-cli open [store|editor|admin]
|
|
93
|
+
\`\`\`
|
|
94
|
+
|
|
95
|
+
Prices are typed in the store's currency (\`--price 19.99\`); Sellwavy stores them in cents.
|
|
96
|
+
`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** CLAUDE.md: Claude Code reads it automatically and follows the import. */
|
|
100
|
+
export const CLAUDE_MD = `@AGENTS.md
|
|
101
|
+
`
|
|
102
|
+
|
|
103
|
+
/** Short version for the MCP server's handshake: the full guide is one tool call away. */
|
|
104
|
+
export const MCP_INSTRUCTIONS = `Sellwavy online store tools. Before writing or changing any page section, call sellwavy_guide once: pages are HTML + Tailwind with data-sw-* hooks for live products and cart, and the server removes scripts, forms and fonts. Sections you save go live at once and stay editable in the owner's visual editor. Prices are in the store's currency (19.99), not cents.`
|