diff --git a/.cursor/rules/storebound.mdc b/.cursor/rules/storebound.mdc index 2d5df596..a13e44b3 100644 --- a/.cursor/rules/storebound.mdc +++ b/.cursor/rules/storebound.mdc @@ -45,6 +45,7 @@ These rules apply to every AI tool that uses storebound (skills, MCP server or t - `skills/privacy-policy/SKILL.md`: Write and host one studio-wide privacy policy page for all of a developer's mobile games - `skills/release-management/SKILL.md`: Ship updates safely after the first release - `skills/review-rejections/SKILL.md`: Triage and answer an App Store or Google Play rejection, policy warning or strike for a mobile game +- `skills/review-replies/SKILL.md`: Reply to App Store and Google Play reviews of a mobile game the safe way - `skills/store-declarations/SKILL.md`: Answer the store compliance forms for a mobile game - `skills/store-health/SKILL.md`: Watch a released mobile game's crash and ANR health on both stores - `skills/store-iap-setup/SKILL.md`: Create and price in-app purchases (consumables, non-consumables like "remove ads", coin/gem packs, starter packs) on Google Play and App Store Connect from one product list diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index e8d34f13..b4684b99 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -47,6 +47,7 @@ These rules apply to every AI tool that uses storebound (skills, MCP server or t | `privacy-policy` | Write and host one studio-wide privacy policy page for all of a developer's mobile games | | `release-management` | Ship updates safely after the first release | | `review-rejections` | Triage and answer an App Store or Google Play rejection, policy warning or strike for a mobile game | +| `review-replies` | Reply to App Store and Google Play reviews of a mobile game the safe way | | `store-declarations` | Answer the store compliance forms for a mobile game | | `store-health` | Watch a released mobile game's crash and ANR health on both stores | | `store-iap-setup` | Create and price in-app purchases (consumables, non-consumables like "remove ads", coin/gem packs, starter packs) on Google Play and App Store Connect from one product list | diff --git a/AGENTS.md b/AGENTS.md index d0e5df4a..61e1aa54 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -45,6 +45,7 @@ These rules apply to every AI tool that uses storebound (skills, MCP server or t - `skills/privacy-policy/SKILL.md`: Write and host one studio-wide privacy policy page for all of a developer's mobile games - `skills/release-management/SKILL.md`: Ship updates safely after the first release - `skills/review-rejections/SKILL.md`: Triage and answer an App Store or Google Play rejection, policy warning or strike for a mobile game +- `skills/review-replies/SKILL.md`: Reply to App Store and Google Play reviews of a mobile game the safe way - `skills/store-declarations/SKILL.md`: Answer the store compliance forms for a mobile game - `skills/store-health/SKILL.md`: Watch a released mobile game's crash and ANR health on both stores - `skills/store-iap-setup/SKILL.md`: Create and price in-app purchases (consumables, non-consumables like "remove ads", coin/gem packs, starter packs) on Google Play and App Store Connect from one product list diff --git a/GEMINI.md b/GEMINI.md index 20603275..eca9ab61 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -46,6 +46,7 @@ These rules apply to every AI tool that uses storebound (skills, MCP server or t | `privacy-policy` | Write and host one studio-wide privacy policy page for all of a developer's mobile games | | `release-management` | Ship updates safely after the first release | | `review-rejections` | Triage and answer an App Store or Google Play rejection, policy warning or strike for a mobile game | +| `review-replies` | Reply to App Store and Google Play reviews of a mobile game the safe way | | `store-declarations` | Answer the store compliance forms for a mobile game | | `store-health` | Watch a released mobile game's crash and ANR health on both stores | | `store-iap-setup` | Create and price in-app purchases (consumables, non-consumables like "remove ads", coin/gem packs, starter packs) on Google Play and App Store Connect from one product list | diff --git a/cli/index.ts b/cli/index.ts index 4f5f2d2f..50ff97ca 100755 --- a/cli/index.ts +++ b/cli/index.ts @@ -18,6 +18,7 @@ const COMMANDS: Record Promise, string]> = { 'check': [() => import('./check'), 'validate config, copy files, data safety answers and products (offline); --aso keyword audit'], 'validate': [() => import('./validate'), 'read-only store readiness report with ordered blockers (--apple / --play), plus local renders checks (--no-local skips); exit 1 on blockers'], 'health': [() => import('./health'), 'crash / ANR vitals (Play) and diagnostics (App Store), read-only; --weekly writes a markdown report; exit 1 over a threshold'], + 'reviews': [() => import('./reviews'), 'list | draft (local reply drafts in .storebound/replies) | send (approved drafts only, asks first)'], 'whats-new': [() => import('./whats-new'), 'draft player-facing release notes from git log into the listing files (--since )'], 'play products': [() => import('./play/products'), 'one-time products: create / update, regional prices, activate'], 'play listing': [() => import('./play/listing'), 'app details + title / short / full description per language'], diff --git a/cli/lib/frontmatter.ts b/cli/lib/frontmatter.ts new file mode 100644 index 00000000..f9e0f220 --- /dev/null +++ b/cli/lib/frontmatter.ts @@ -0,0 +1,34 @@ +// Minimal front matter for the local Markdown drafts storebound writes (review replies): "---", one `key: value` per +// line (strings, numbers, true / false, null; strings JSON-quoted when needed), "---", then the body. Pure. + +export type FmValue = string | number | boolean | null; + +export function parseFrontMatter(text: string): { data: Record; body: string } { + const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text); + if (!m) return { data: {}, body: text }; + const data: Record = {}; + for (const line of m[1]!.split(/\r?\n/)) { + const kv = /^([A-Za-z_][\w-]*):\s*(.*)$/.exec(line); + if (!kv) continue; + data[kv[1]!] = scalar(kv[2]!.trim()); + } + return { data, body: text.slice(m[0].length) }; +} + +function scalar(v: string): FmValue { + if (v === 'true') return true; + if (v === 'false') return false; + if (v === 'null' || v === '~' || v === '') return null; + if (/^-?\d+(\.\d+)?$/.test(v)) return Number(v); + if (v.startsWith('"')) { try { return JSON.parse(v) as string; } catch { return v; } } + if (v.startsWith("'") && v.endsWith("'")) return v.slice(1, -1).replace(/''/g, "'"); + return v; +} + +const plain = (s: string) => /^[\w./@+-][\w ./@:+-]*$/.test(s) && !/^(true|false|null|~|-?\d+(\.\d+)?)$/.test(s) && !/ $/.test(s); + +export function stringifyFrontMatter(data: Record, body: string): string { + const lines = Object.entries(data).filter(([, v]) => v !== undefined) + .map(([k, v]) => `${k}: ${v === null ? 'null' : typeof v === 'string' ? (plain(v) ? v : JSON.stringify(v)) : String(v)}`); + return `---\n${lines.join('\n')}\n---\n${body.startsWith('\n') ? body : '\n' + body}`; +} diff --git a/cli/lib/reviews.ts b/cli/lib/reviews.ts new file mode 100644 index 00000000..4fa74114 --- /dev/null +++ b/cli/lib/reviews.ts @@ -0,0 +1,155 @@ +// Store review replies as pure parts: normalising both stores' reviews, the local draft files the owner / agent edit +// (.storebound/replies/-.md, front matter + the review + "## Reply"), and the checks a reply must pass +// before `storebound reviews send` sends it (only drafts with `approved: true`, after a confirmation). +// Sources (checked October 2026): +// App Store: GET /v1/apps/{id}/customerReviews, POST /v1/customerReviewResponses (one response per review; a new POST +// replaces it; it shows after up to 24 hours) https://developer.apple.com/documentation/appstoreconnectapi/customer-review-responses +// Guidance: https://developer.apple.com/app-store/responding-to-reviews/ (no personal info, marketing or spam) +// Length: Apple documents no maximum; 5970 characters is the limit App Store Connect is commonly reported to +// enforce (NOT VERIFIED), so storebound warns above it instead of blocking. +// Google Play: reviews.list returns reviews created or edited in the last week only; reviews.reply {replyText}, +// at most 350 characters (HTML tags stripped, not counted) https://developers.google.com/android-publisher/reply-to-reviews +import { len } from './copy'; +import { type FmValue, parseFrontMatter, stringifyFrontMatter } from './frontmatter'; + +export type ReviewStore = 'apple' | 'play'; +export const REPLY_LIMITS: Record = { play: 350, apple: 5970 }; + +export interface Review { + store: ReviewStore; + id: string; + rating: number; + title?: string; + body: string; + author?: string; + /** Apple: territory (alpha-3); Play: reviewer language. */ + where?: string; + date: string; + appVersion?: string; + reply?: { text: string; date?: string; state?: string }; +} + +interface AppleReviewsResp { + data?: { id: string; attributes: { rating?: number; title?: string; body?: string; reviewerNickname?: string; createdDate?: string; territory?: string }; relationships?: { response?: { data?: { id: string } | null } } }[]; + included?: { type: string; id: string; attributes?: { responseBody?: string; lastModifiedDate?: string; state?: string } }[]; +} + +export function parseAppleReviews(resp: AppleReviewsResp): Review[] { + const responses = new Map((resp.included ?? []).filter(x => x.type === 'customerReviewResponses').map(x => [x.id, x.attributes ?? {}] as const)); + return (resp.data ?? []).map(r => { + const resp1 = responses.get(r.relationships?.response?.data?.id ?? ''); + return { store: 'apple' as const, id: r.id, rating: r.attributes.rating ?? 0, title: r.attributes.title || undefined, body: r.attributes.body ?? '', + author: r.attributes.reviewerNickname, where: r.attributes.territory, date: r.attributes.createdDate ? new Date(r.attributes.createdDate).toISOString() : '', + ...(resp1?.responseBody ? { reply: { text: resp1.responseBody, date: resp1.lastModifiedDate, state: resp1.state } } : {}) }; + }); +} + +interface PlayReviewsResp { + reviews?: { reviewId: string; authorName?: string; comments?: { userComment?: { text?: string; lastModified?: { seconds?: string }; starRating?: number; reviewerLanguage?: string; appVersionName?: string }; + developerComment?: { text?: string; lastModified?: { seconds?: string } } }[] }[]; +} + +const isoFromSeconds = (s?: string) => (s ? new Date(Number(s) * 1000).toISOString() : ''); + +export function parsePlayReviews(resp: PlayReviewsResp): Review[] { + return (resp.reviews ?? []).map(r => { + const u = r.comments?.find(c => c.userComment)?.userComment ?? {}; + const d = r.comments?.find(c => c.developerComment)?.developerComment; + // A review with a separate title comes as "title\tbody". + const [title, body] = (u.text ?? '').includes('\t') ? (u.text ?? '').split('\t', 2) as [string, string] : [undefined, u.text ?? '']; + return { store: 'play' as const, id: r.reviewId, rating: u.starRating ?? 0, title: title?.trim() || undefined, body: body.trim(), author: r.authorName, + where: u.reviewerLanguage, date: isoFromSeconds(u.lastModified?.seconds), appVersion: u.appVersionName, + ...(d?.text ? { reply: { text: d.text, date: isoFromSeconds(d.lastModified?.seconds) } } : {}) }; + }); +} + +/** Reviews newer than `sinceIso`, optional filters, newest first. */ +export function filterReviews(rs: Review[], o: { since?: string; unanswered?: boolean; ratings?: number[] } = {}): Review[] { + return rs.filter(r => (!o.since || r.date >= o.since) && (!o.unanswered || !r.reply) && (!o.ratings?.length || o.ratings.includes(r.rating))) + .sort((a, b) => b.date.localeCompare(a.date)); +} + +/** File name of a draft: -.md with unsafe characters replaced. */ +export const draftName = (r: Pick): string => `${r.store}-${r.id.replace(/[^A-Za-z0-9._-]/g, '_').slice(0, 120)}.md`; + +export const REPLY_PLACEHOLDER = ''; + +/** A new draft: front matter (approved: false), the review as a quote, an empty "## Reply" section. */ +export function draftMarkdown(r: Review): string { + const quote = (t: string) => t.split('\n').map(l => `> ${l}`).join('\n'); + const body = [ + `# ${'★'.repeat(Math.max(0, Math.min(5, r.rating)))}${'☆'.repeat(Math.max(0, 5 - r.rating))} ${r.title ?? ''}`.trimEnd(), '', + quote(r.body || '(no text)'), '', + `${r.where ? `${r.where} · ` : ''}${r.date.slice(0, 10)}${r.appVersion ? ` · version ${r.appVersion}` : ''}`, '', + ...(r.reply ? ['## Current reply', '', quote(r.reply.text), ''] : []), + '## Reply', '', REPLY_PLACEHOLDER, '', '', + ].join('\n'); + const meta: Record = { store: r.store, review_id: r.id, rating: r.rating, where: r.where ?? null, date: r.date, limit: REPLY_LIMITS[r.store], approved: false, sent: null }; + return stringifyFrontMatter(meta, body); +} + +export interface Draft { file: string; store: ReviewStore; reviewId: string; approved: boolean; sent: string | null; reply: string; meta: Record } + +/** A draft file -> its reply text (after "## Reply", HTML comments removed) and state. */ +export function parseDraft(file: string, text: string): Draft { + const { data, body } = parseFrontMatter(text); + const store = data.store; + if (store !== 'apple' && store !== 'play') throw new Error(`${file}: front matter "store" must be apple or play`); + if (!data.review_id) throw new Error(`${file}: front matter "review_id" missing`); + const at = body.search(/^## Reply\s*$/m); + const reply = at < 0 ? '' : body.slice(at).replace(/^## Reply\s*$/m, '').replace(//g, '').trim(); + return { file, store, reviewId: String(data.review_id), approved: data.approved === true, sent: typeof data.sent === 'string' ? data.sent : null, reply, meta: data }; +} + +/** Front matter `sent: ` (and approved kept) after a successful send. */ +export function markSent(text: string, iso: string): string { + const { data, body } = parseFrontMatter(text); + return stringifyFrontMatter({ ...data, sent: iso }, body); +} + +const INCENTIVE = [ + /\b(free|bonus|extra|gift|reward|compensat\w*)\b[^.!?\n]{0,40}\b(coins?|gems?|diamonds?|credits?|lives|items?|currency|refund)\b/i, + /\b(change|update|raise|edit|improve|revise)\s+(your\s+)?(rating|review|stars?|score)\b/i, + /\b(5|five)[ -]?stars?\b/i, + /\b(rate|review)\s+us\b/i, +]; + +export interface ReplyIssue { level: 'error' | 'warn'; msg: string } + +/** Problems with a reply before sending. Errors block `reviews send`; warnings are shown. */ +export function checkReply(reply: string, store: ReviewStore): ReplyIssue[] { + const e: ReplyIssue[] = []; + const text = store === 'play' ? reply.replace(/<[^>]*>/g, '') : reply; + if (!text.trim()) e.push({ level: 'error', msg: 'empty reply' }); + const n = len(text); + if (store === 'play' && n > REPLY_LIMITS.play) e.push({ level: 'error', msg: `${n} > ${REPLY_LIMITS.play} characters (Google Play limit)` }); + if (store === 'apple' && n > REPLY_LIMITS.apple) e.push({ level: 'warn', msg: `${n} characters: App Store Connect is reported to stop at ${REPLY_LIMITS.apple}` }); + if (INCENTIVE.some(re => re.test(text))) e.push({ level: 'error', msg: 'offers something for a rating or asks to change / give stars: not allowed (no incentives, no rating manipulation)' }); + if (/[^@\s]+@[^@\s]+\.[a-z]{2,}/i.test(text)) e.push({ level: 'warn', msg: 'contains an email address: only your public support address, never a player\'s' }); + if (/(\+?\d[\d\s().-]{7,}\d)/.test(text)) e.push({ level: 'warn', msg: 'contains a phone-like number: no personal data in public replies' }); + if (/https?:\/\//i.test(text)) e.push({ level: 'warn', msg: 'contains a link: support pages only, no marketing' }); + if (/[A-Z]{6,}/.test(text) || /!{3,}/.test(text)) e.push({ level: 'warn', msg: 'shouting (caps / !!!): keep it calm' }); + return e; +} + +/** Which drafts `send` would send, and why the others are skipped. */ +export function sendPlan(drafts: Draft[]): { send: Draft[]; skip: { file: string; why: string }[] } { + const send: Draft[] = []; + const skip: { file: string; why: string }[] = []; + for (const d of drafts) { + if (d.sent) { skip.push({ file: d.file, why: `already sent ${d.sent.slice(0, 10)}` }); continue; } + if (!d.approved) { skip.push({ file: d.file, why: 'not approved (set approved: true after reading it)' }); continue; } + const errors = checkReply(d.reply, d.store).filter(i => i.level === 'error'); + if (errors.length) { skip.push({ file: d.file, why: errors.map(i => i.msg).join('; ') }); continue; } + send.push(d); + } + return { send, skip }; +} + +/** The request that sends one reply. Apple: a POST replaces an earlier response; Play: :reply creates or updates. */ +export function replyRequest(d: Draft, packageName?: string): { method: 'POST'; url: string; body: unknown } { + if (d.store === 'apple') return { method: 'POST', url: '/v1/customerReviewResponses', body: { data: { type: 'customerReviewResponses', attributes: { responseBody: d.reply }, + relationships: { review: { data: { type: 'customerReviews', id: d.reviewId } } } } } }; + if (!packageName) throw new Error('play.packageName is not set'); + return { method: 'POST', url: `https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${packageName}/reviews/${encodeURIComponent(d.reviewId)}:reply`, body: { replyText: d.reply } }; +} diff --git a/cli/mcp-tools.ts b/cli/mcp-tools.ts index 54699cce..6b362fa1 100644 --- a/cli/mcp-tools.ts +++ b/cli/mcp-tools.ts @@ -50,6 +50,16 @@ export const TOOLS: ToolDef[] = [ description: 'Weekly health summary as Markdown in .storebound/health/.md (plus .json for the next week-over-week comparison). Local files only; dry_run prints the report.', props: { store: { type: 'string', enum: ['both', 'apple', 'play'], default: 'both' } }, args: i => (i.store === 'apple' ? ['--apple'] : i.store === 'play' ? ['--play'] : []) }, + { name: 'reviews_list', title: 'Store reviews', command: ['reviews', 'list'], write: false, network: true, + description: 'Read-only list of recent App Store and Google Play reviews (date, stars, territory / language, replied or not, text). Google Play only returns reviews from the last 7 days.', + props: { store: { type: 'string', enum: ['apple', 'play'], description: 'Default: both' }, days: { type: 'integer', minimum: 1, maximum: 365, default: 14 }, + unanswered: { type: 'boolean', default: false }, rating: { type: 'string', pattern: '^[1-5](,[1-5])*$', description: 'e.g. 1,2' } }, + args: i => [...opt('store', i.store), ...opt('days', i.days), ...flag('unanswered', i.unanswered), ...opt('rating', i.rating)] }, + { name: 'reviews_draft', title: 'Draft review replies', command: ['reviews', 'draft'], write: true, network: true, idempotent: true, + description: 'Write one local Markdown draft per unanswered review into .storebound/replies/-.md (approved: false; existing drafts are kept). Then write the reply under "## Reply" following the review-replies skill; the owner approves and sends from the terminal. Nothing is sent to a store.', + props: { store: { type: 'string', enum: ['apple', 'play'], description: 'Default: both' }, days: { type: 'integer', minimum: 1, maximum: 365, default: 14 }, + rating: { type: 'string', pattern: '^[1-5](,[1-5])*$', description: 'Only these star ratings, e.g. 1,2,3' } }, + args: i => [...opt('store', i.store), ...opt('days', i.days), ...opt('rating', i.rating)] }, { name: 'apple_status', title: 'App Store status', command: ['apple', 'status'], write: false, network: true, description: 'Read-only App Store Connect overview: versions and their states, recent builds, in-app purchases, review submissions.' }, { name: 'apple_next_build', title: 'Next iOS build number', command: ['apple', 'next-build'], write: false, network: true, @@ -159,7 +169,7 @@ export const TOOLS: ToolDef[] = [ /** CLI flags / commands that must never be reachable through MCP. Tests assert none of the tools can produce them. */ export const FORBIDDEN_ARGS = ['--yes', '--manual-release', '--cancel-submission', '--production', 'rollout', 'resume', 'complete', - '--submit-review', '--remove', '--invite', 'testers']; + '--submit-review', '--remove', '--invite', 'testers', 'send']; export function inputSchema(t: ToolDef): Record { const props: Record = { ...(t.props ?? {}) }; diff --git a/cli/reviews.ts b/cli/reviews.ts new file mode 100644 index 00000000..7a17a18e --- /dev/null +++ b/cli/reviews.ts @@ -0,0 +1,143 @@ +// Store reviews and replies. +// storebound reviews list [--store apple|play] [--days 14] [--unanswered] [--rating 1,2] [--json] +// storebound reviews draft [--store apple|play] [--days 14] [--rating 1,2,3] [--all] [--dir .storebound/replies] [--dry] +// storebound reviews send [--dir .storebound/replies] [--dry] [--yes] +// `draft` writes one Markdown file per unanswered review into .storebound/replies/ (gitignored): front matter +// (store, review_id, rating, approved: false), the review, and an empty "## Reply" section. Existing files are never +// overwritten (your edits stay). The owner or an agent with the review-replies skill writes the reply; the owner sets +// `approved: true`. `send` sends only approved, unsent drafts that pass the checks (length, no incentives), after a +// confirmation, then writes `sent: