@slatesvideo/shared 0.7.3 → 0.7.5

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.
Files changed (53) hide show
  1. package/dist/analytics/events.d.ts +155 -0
  2. package/dist/analytics/events.js +430 -0
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +4 -0
  5. package/dist/manual/content.d.ts +1 -1
  6. package/dist/manual/content.js +1 -1
  7. package/dist/operations/index.d.ts +88 -82
  8. package/dist/operations/index.js +235 -45
  9. package/dist/operations/surface.js +1 -0
  10. package/dist/prompts/agent-doctrine.js +26 -7
  11. package/dist/prompts/banned-tokens.d.ts +18 -0
  12. package/dist/prompts/banned-tokens.js +59 -4
  13. package/dist/prompts/generation-policy.d.ts +1 -1
  14. package/dist/prompts/model-capabilities.d.ts +3 -3
  15. package/dist/prompts/model-capabilities.js +3 -3
  16. package/dist/prompts/model-facts.d.ts +1 -1
  17. package/dist/prompts/model-facts.js +2 -2
  18. package/dist/prompts/partials.generated.js +1 -1
  19. package/dist/prompts/prompting-tips.js +8 -8
  20. package/dist/prompts/shot-grammar.d.ts +2 -2
  21. package/dist/prompts/shot-grammar.js +2 -2
  22. package/dist/skills/content.js +18 -18
  23. package/dist/update-check.js +1 -1
  24. package/exports/slates-prompt-builder/generated/reference-character.md +2 -2
  25. package/exports/slates-prompt-builder/generated/reference-content-policy.md +3 -3
  26. package/exports/slates-prompt-builder/generated/reference-gpt-image-2-5.md +4 -4
  27. package/exports/slates-prompt-builder/generated/reference-kling.md +5 -6
  28. package/exports/slates-prompt-builder/generated/reference-omni-flash.md +1 -1
  29. package/exports/slates-prompt-builder/generated/reference-seedance-2-5.md +15 -15
  30. package/exports/slates-prompt-builder/generated/reference-seedance.md +3 -4
  31. package/exports/slates-prompt-builder/generated/slates-prompt-builder-manifest.json +26 -26
  32. package/exports/slates-prompt-builder/generated/slates-prompt-builder.skill +0 -0
  33. package/package.json +5 -2
  34. package/skills/_partials/cinematic-card.md +1 -1
  35. package/skills/_partials/model-routing.md +2 -2
  36. package/skills/slates-character-identity.md +2 -2
  37. package/skills/slates-content-policy.md +3 -3
  38. package/skills/slates-model-selection.md +3 -3
  39. package/skills/slates-prompting-elevenlabs.md +1 -1
  40. package/skills/slates-prompting-flux-2-max.md +1 -2
  41. package/skills/slates-prompting-gpt-image-2-5.md +5 -5
  42. package/skills/slates-prompting-inworld-tts.md +1 -1
  43. package/skills/slates-prompting-kling-v3.md +4 -5
  44. package/skills/slates-prompting-lip-sync.md +5 -8
  45. package/skills/slates-prompting-ltx-2-5.md +2 -2
  46. package/skills/slates-prompting-minimax-h3.md +5 -5
  47. package/skills/slates-prompting-motion-transfer.md +2 -4
  48. package/skills/slates-prompting-omni-flash.md +1 -1
  49. package/skills/slates-prompting-seed-audio.md +1 -1
  50. package/skills/slates-prompting-seedance-2-5.md +19 -19
  51. package/skills/slates-prompting-seedance.md +10 -11
  52. package/skills/slates-prompting-seedream-5-lite.md +2 -3
  53. package/skills/slates-vision-feedback-loop.md +117 -117
@@ -0,0 +1,155 @@
1
+ /**
2
+ * The Slates analytics taxonomy: every event name slates-api, slates-web and
3
+ * slate send to PostHog, who sends it, and what a purchase event must carry.
4
+ *
5
+ * ONE HOME. This file is the source; slates-web's `npm run build:llm-docs`
6
+ * copies it verbatim into each consumer (`slates-web/src/app/lib/generated/analytics-events.ts`,
7
+ * `slates-api/src/lib/generated/analytics-events.ts`, `slate/src/shared/analyticsEvents.ts`)
8
+ * and its `--check` fails on drift. The consumers do not import the npm package for
9
+ * this: a new shared export would make every API deploy wait on a shared
10
+ * publish, which the release runbook ties to a desktop version bump.
11
+ *
12
+ * Each repo's `check:analytics` scans its source with `findEventCalls` below and
13
+ * fails on a name outside this list, a name only the code can compute, a call
14
+ * form it does not know, or a name listed for the repo that its code never sends. Plan: second-brain
15
+ * `plans/2026-10-07-slates-launch-tracking-proof.md` § The event taxonomy.
16
+ *
17
+ * Self-contained on purpose: no imports, no Node APIs, so the copy is safe in
18
+ * the renderer and the site bundle.
19
+ */
20
+ export type AnalyticsSender = 'slates-api' | 'slates-web' | 'slate';
21
+ export type AnalyticsKind =
22
+ /** A paid charge, sent by slates-api after the grant. Forwarded to Meta and Google. */
23
+ 'purchase'
24
+ /** A step on the way to a charge: page views, checkout, upsell decisions. */
25
+ | 'funnel'
26
+ /** The buyer using the product: sign-in, generation, agent runs. */
27
+ | 'product'
28
+ /** Account and billing life after the purchase: top-ups, refunds, email changes. */
29
+ | 'account'
30
+ /** Offers, leads and codes from the offer machine. */
31
+ | 'offer'
32
+ /** A server-side failure worth counting. */
33
+ | 'ops';
34
+ export interface AnalyticsEvent {
35
+ readonly name: string;
36
+ readonly senders: readonly AnalyticsSender[];
37
+ readonly kind: AnalyticsKind;
38
+ readonly what: string;
39
+ /** Sent by the PostHog library itself, so no call in the sender's code names it. */
40
+ readonly library?: true;
41
+ }
42
+ /** Properties every purchase event carries; a send without one is a bug. */
43
+ export declare const PURCHASE_REQUIRED: readonly ["value", "currency", "payment_intent_id", "event_id"];
44
+ /**
45
+ * Properties a purchase event carries whenever the payment knows them: the
46
+ * last-touch tags (`utm_*`), the first-touch tags (`ft_utm_*`), the landing
47
+ * arm, the offer, the base payment on an upsell, the click ids and the buyer's
48
+ * own IP and browser (Meta matches on them; the server's would be wrong).
49
+ */
50
+ export declare const PURCHASE_CARRIED: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term", "ft_utm_source", "ft_utm_medium", "ft_utm_campaign", "ft_utm_content", "ft_utm_term", "lp_theme", "lp_variant", "offer_key", "initial_pi", "_fbc", "_fbp", "_ttp", "gclid", "endorsely_referral", "$ip", "$raw_user_agent"];
51
+ export declare const ANALYTICS_EVENTS: readonly AnalyticsEvent[];
52
+ export declare function analyticsEvent(name: string): AnalyticsEvent | undefined;
53
+ /**
54
+ * The one PostHog id for a person on every surface: the email, trimmed and
55
+ * lowercased. A buyer who types a capital letter would otherwise be two people,
56
+ * and PostHog will not merge two people who are both already identified.
57
+ */
58
+ export declare function analyticsPersonId(email: string): string;
59
+ /**
60
+ * A purchase event's id: the event and its PaymentIntent. A replayed webhook
61
+ * sends the same id, and Meta dedupes on it within 48 hours.
62
+ */
63
+ export declare function purchaseEventId(event: string, paymentIntentId: string): string;
64
+ /** The required purchase properties a payload lacks (empty string and null count as missing). */
65
+ export declare function missingPurchaseProperties(properties: Record<string, unknown>): string[];
66
+ /** A call form that sends an event: `callee(…)` with the name at argument `arg`. */
67
+ export interface EventCaller {
68
+ readonly callee: string;
69
+ readonly arg: number;
70
+ }
71
+ export interface EventCall {
72
+ readonly callee: string;
73
+ readonly line: number;
74
+ /** The names the argument can take; empty when only the code can compute it. */
75
+ readonly names: readonly string[];
76
+ /** The argument's source text, whitespace collapsed. */
77
+ readonly source: string;
78
+ }
79
+ interface RawCall {
80
+ readonly callee: string;
81
+ readonly line: number;
82
+ /** Index just past the call's opening parenthesis. */
83
+ readonly index: number;
84
+ }
85
+ /**
86
+ * Calls that look like an analytics send: a `.capture(` or `.track(` method,
87
+ * or a function named `trackEvent`, `trackDualEvent` or `track…Event`. The
88
+ * check fails on any of these that is not a known send form, so a new wrapper
89
+ * cannot slip names past it.
90
+ */
91
+ export declare function findSendLikeCalls(text: string): RawCall[];
92
+ /**
93
+ * The calls in `text` made through `callers`, each with the event names its
94
+ * name argument can take. A name argument that is a literal, or a ternary whose
95
+ * branches are literals, resolves; anything else resolves to no names.
96
+ */
97
+ export declare function findEventCalls(text: string, callers: readonly EventCaller[]): EventCall[];
98
+ export interface AnalyticsFinding {
99
+ readonly file: string;
100
+ readonly line: number;
101
+ readonly problem: string;
102
+ }
103
+ /**
104
+ * A send form allowed to pass a computed name. Either its names are checked
105
+ * where the wrapper is called (no `namesFrom`), or the file declares them in
106
+ * one const (`namesFrom`), whose string literals are checked instead.
107
+ */
108
+ export interface DynamicSend {
109
+ readonly file: string;
110
+ readonly callee: string;
111
+ readonly namesFrom?: string;
112
+ }
113
+ export interface CheckOptions {
114
+ readonly callers: readonly EventCaller[];
115
+ readonly dynamic?: readonly DynamicSend[];
116
+ /** Send-like calls that are not PostHog (a pixel, say): `file` + `callee`. */
117
+ readonly ignore?: readonly {
118
+ file: string;
119
+ callee: string;
120
+ }[];
121
+ /** The only callee a purchase event may go through, which builds its required properties. */
122
+ readonly purchaseVia?: string;
123
+ }
124
+ /** The string literals inside `const <name> = …`, up to the end of its bracketed value. */
125
+ export declare function constLiterals(text: string, name: string): string[];
126
+ /** Every event name the files send through `opts`, literal or declared for a computed send. */
127
+ export declare function sentNames(files: readonly {
128
+ path: string;
129
+ text: string;
130
+ }[], opts: CheckOptions): Set<string>;
131
+ /** Check one source file of `sender` against the taxonomy. */
132
+ export declare function checkSource(file: string, text: string, sender: AnalyticsSender, opts: CheckOptions): AnalyticsFinding[];
133
+ /**
134
+ * Mutation cases a repo's check runs on itself. Each must produce a finding, or
135
+ * the check has gone blind; returns the cases that produced none.
136
+ */
137
+ export declare function selfTest(sender: AnalyticsSender, opts: CheckOptions): string[];
138
+ /**
139
+ * The whole check for one repo: its files scanned, the self-test, and its copy
140
+ * of this module compared with the source when the slates-mcp checkout is
141
+ * beside it (`copy` and `source` are the two texts; leave `source` undefined
142
+ * when there is no sibling). Returns the lines to print and whether it passed.
143
+ */
144
+ export declare function analyticsReport(files: readonly {
145
+ path: string;
146
+ text: string;
147
+ }[], sender: AnalyticsSender, opts: CheckOptions, taxonomy: {
148
+ copy: string;
149
+ source?: string;
150
+ }): {
151
+ ok: boolean;
152
+ lines: string[];
153
+ };
154
+ export {};
155
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,430 @@
1
+ /**
2
+ * The Slates analytics taxonomy: every event name slates-api, slates-web and
3
+ * slate send to PostHog, who sends it, and what a purchase event must carry.
4
+ *
5
+ * ONE HOME. This file is the source; slates-web's `npm run build:llm-docs`
6
+ * copies it verbatim into each consumer (`slates-web/src/app/lib/generated/analytics-events.ts`,
7
+ * `slates-api/src/lib/generated/analytics-events.ts`, `slate/src/shared/analyticsEvents.ts`)
8
+ * and its `--check` fails on drift. The consumers do not import the npm package for
9
+ * this: a new shared export would make every API deploy wait on a shared
10
+ * publish, which the release runbook ties to a desktop version bump.
11
+ *
12
+ * Each repo's `check:analytics` scans its source with `findEventCalls` below and
13
+ * fails on a name outside this list, a name only the code can compute, a call
14
+ * form it does not know, or a name listed for the repo that its code never sends. Plan: second-brain
15
+ * `plans/2026-10-07-slates-launch-tracking-proof.md` § The event taxonomy.
16
+ *
17
+ * Self-contained on purpose: no imports, no Node APIs, so the copy is safe in
18
+ * the renderer and the site bundle.
19
+ */
20
+ /** Properties every purchase event carries; a send without one is a bug. */
21
+ export const PURCHASE_REQUIRED = ['value', 'currency', 'payment_intent_id', 'event_id'];
22
+ /**
23
+ * Properties a purchase event carries whenever the payment knows them: the
24
+ * last-touch tags (`utm_*`), the first-touch tags (`ft_utm_*`), the landing
25
+ * arm, the offer, the base payment on an upsell, the click ids and the buyer's
26
+ * own IP and browser (Meta matches on them; the server's would be wrong).
27
+ */
28
+ export const PURCHASE_CARRIED = [
29
+ 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term',
30
+ 'ft_utm_source', 'ft_utm_medium', 'ft_utm_campaign', 'ft_utm_content', 'ft_utm_term',
31
+ 'lp_theme', 'lp_variant', 'offer_key', 'initial_pi',
32
+ '_fbc', '_fbp', '_ttp', 'gclid', 'endorsely_referral',
33
+ '$ip', '$raw_user_agent',
34
+ ];
35
+ const API = ['slates-api'];
36
+ const WEB = ['slates-web'];
37
+ const APP = ['slate'];
38
+ export const ANALYTICS_EVENTS = [
39
+ // ── Purchases (slates-api, from the Stripe webhook after the grant) ──
40
+ { name: 'license_purchased', senders: API, kind: 'purchase', what: 'The base license, with the bump inside its value' },
41
+ { name: 'bump_skills_purchased', senders: API, kind: 'purchase', what: 'The Skills Pack bump, its own cents only' },
42
+ { name: 'pro_license_purchased', senders: API, kind: 'purchase', what: 'Pro bought outright (the $297 checkout)' },
43
+ { name: 'pro_upgraded', senders: API, kind: 'purchase', what: 'Base to Pro: the /letsgo/pro upsell or the /upgrade page' },
44
+ { name: 'mega_credits_purchased', senders: API, kind: 'purchase', what: 'The mega credit pack upsell' },
45
+ { name: 'credit_boost_purchased', senders: API, kind: 'purchase', what: 'The credit boost upsell' },
46
+ { name: 'credits_purchased', senders: API, kind: 'purchase', what: 'A credit pack bought on its own' },
47
+ { name: 'vault_purchased', senders: API, kind: 'purchase', what: 'The legacy vault SKU (unrouted since 2026-07-09)' },
48
+ { name: 'thumbs_purchased', senders: API, kind: 'purchase', what: 'A Thumbs purchase' },
49
+ { name: 'thumbs_oto2_purchased', senders: API, kind: 'purchase', what: 'Thumbs as the /letsgo OTO2 (unrouted since 2026-07-09)' },
50
+ // ── Funnel ──
51
+ { name: '$pageview', senders: WEB, kind: 'funnel', what: 'A page view, sent by hand on each route change' },
52
+ { name: '$pageleave', senders: APP, kind: 'funnel', what: "posthog-js's own leave event in the app (capture_pageleave)", library: true },
53
+ { name: 'view_content', senders: WEB, kind: 'funnel', what: 'A sales page seen; browser pixel and PostHog with one id' },
54
+ { name: 'initiate_checkout', senders: WEB, kind: 'funnel', what: 'The checkout opened; browser pixel and PostHog with one id' },
55
+ { name: 'checkout_started', senders: API, kind: 'funnel', what: "The API first learns the buyer's email for a PaymentIntent" },
56
+ { name: 'thumbs_checkout_started', senders: API, kind: 'funnel', what: 'A Thumbs checkout created' },
57
+ { name: 'checkout_payment_intent_failed', senders: WEB, kind: 'funnel', what: 'The checkout could not create its PaymentIntent' },
58
+ { name: 'headline_variant_shown', senders: WEB, kind: 'funnel', what: 'The /letsgo headline arm shown' },
59
+ { name: 'theme_variant_shown', senders: WEB, kind: 'funnel', what: 'The /letsgo theme arm shown' },
60
+ { name: 'funnel_step', senders: WEB, kind: 'funnel', what: 'An upsell or success page reached' },
61
+ { name: 'oto_decision', senders: WEB, kind: 'funnel', what: 'An upsell accepted or declined' },
62
+ { name: 'bump_skills_toggled', senders: WEB, kind: 'funnel', what: 'The Skills Pack bump ticked or unticked' },
63
+ { name: 'aov_running_total', senders: WEB, kind: 'funnel', what: "The buyer's running order value on each upsell page" },
64
+ { name: 'tier_at_purchase', senders: WEB, kind: 'funnel', what: 'The tier the success page shows' },
65
+ { name: 'currency_displayed', senders: WEB, kind: 'funnel', what: 'The currency /letsgo priced in' },
66
+ { name: 'checkout_theme_toggled', senders: WEB, kind: 'funnel', what: 'The checkout switched light or dark' },
67
+ { name: 'checkout_exit_intent_shown', senders: WEB, kind: 'funnel', what: 'The checkout exit prompt shown' },
68
+ { name: 'checkout_exit_intent_kept', senders: WEB, kind: 'funnel', what: 'The buyer stayed at the exit prompt' },
69
+ { name: 'checkout_exit_intent_dismissed', senders: WEB, kind: 'funnel', what: 'The buyer left at the exit prompt' },
70
+ { name: 'decoy_coupon_removed', senders: WEB, kind: 'funnel', what: 'The decoy coupon removed' },
71
+ { name: 'decoy_coupon_reapplied', senders: WEB, kind: 'funnel', what: 'The decoy coupon put back' },
72
+ { name: 'pro_upgrade_accepted', senders: WEB, kind: 'funnel', what: 'The success-page Pro offer accepted' },
73
+ { name: 'pro_upgrade_declined', senders: WEB, kind: 'funnel', what: 'The success-page Pro offer declined' },
74
+ { name: 'upgrade_page_viewed', senders: WEB, kind: 'funnel', what: 'The /upgrade page seen' },
75
+ { name: 'skills_pack_download_clicked', senders: WEB, kind: 'funnel', what: 'The Skills Pack download pressed on the success page' },
76
+ { name: 'video_play', senders: WEB, kind: 'funnel', what: 'A sales-page video started' },
77
+ { name: 'video_unmute', senders: WEB, kind: 'funnel', what: 'A sales-page video unmuted' },
78
+ { name: 'video_watch_25', senders: WEB, kind: 'funnel', what: 'A quarter of a sales-page video watched (forwarded to Meta)' },
79
+ { name: 'video_watch_50', senders: WEB, kind: 'funnel', what: 'Half a sales-page video watched' },
80
+ { name: 'video_watch_75', senders: WEB, kind: 'funnel', what: 'Three quarters of a sales-page video watched' },
81
+ { name: 'video_watch_100', senders: WEB, kind: 'funnel', what: 'A sales-page video watched to the end' },
82
+ { name: 'web_login_link_sent', senders: WEB, kind: 'account', what: 'A web sign-in link sent' },
83
+ { name: 'web_login_google_started', senders: WEB, kind: 'account', what: 'A web Google sign-in started' },
84
+ { name: 'web_login_completed', senders: WEB, kind: 'account', what: 'A web sign-in finished' },
85
+ { name: 'charge_upsell_initial_pi_rejected', senders: API, kind: 'ops', what: 'An upsell refused: its base payment did not qualify' },
86
+ { name: 'charge_upsell_no_initial_pi', senders: API, kind: 'ops', what: 'An upsell refused: no base payment named' },
87
+ // ── Offers and leads ──
88
+ { name: 'lead_captured', senders: [...API, ...WEB], kind: 'offer', what: 'An email typed at checkout and kept before payment' },
89
+ { name: 'offer_code_issued', senders: API, kind: 'offer', what: 'A personal offer code minted' },
90
+ { name: 'offer_code_redeemed', senders: API, kind: 'offer', what: 'A personal offer code spent by a payment' },
91
+ { name: 'deal_viewed', senders: WEB, kind: 'offer', what: 'A page showing a live deal seen' },
92
+ { name: 'deal_expired', senders: WEB, kind: 'offer', what: "A deal's clock ran out on screen" },
93
+ { name: 'personal_deal_viewed', senders: WEB, kind: 'offer', what: 'A personal code page seen' },
94
+ { name: 'letsgo_unlock_shown', senders: WEB, kind: 'offer', what: 'The /letsgo unlock offer shown' },
95
+ { name: 'letsgo_unlock_applied', senders: WEB, kind: 'offer', what: 'The /letsgo unlock offer taken' },
96
+ { name: 'letsgo_unlock_dismissed', senders: WEB, kind: 'offer', what: 'The /letsgo unlock offer closed' },
97
+ { name: 'checkout_unlock_shown', senders: WEB, kind: 'offer', what: 'The checkout unlock offer shown' },
98
+ { name: 'checkout_unlock_applied', senders: WEB, kind: 'offer', what: 'The checkout unlock offer taken' },
99
+ { name: 'checkout_unlock_dismissed', senders: WEB, kind: 'offer', what: 'The checkout unlock offer closed' },
100
+ { name: 'exit_capture_shown', senders: WEB, kind: 'offer', what: 'The exit email popup shown' },
101
+ { name: 'exit_capture_submitted', senders: WEB, kind: 'offer', what: 'The exit email popup filled in' },
102
+ { name: 'exit_capture_dismissed', senders: WEB, kind: 'offer', what: 'The exit email popup closed' },
103
+ { name: 'offer_shown', senders: APP, kind: 'offer', what: 'An in-app offer shown' },
104
+ { name: 'offer_dismissed', senders: APP, kind: 'offer', what: 'An in-app offer dismissed' },
105
+ { name: 'offer_clicked', senders: APP, kind: 'offer', what: 'An in-app offer clicked' },
106
+ // ── Product ──
107
+ { name: 'user_logged_in', senders: APP, kind: 'product', what: 'A desktop sign-in, from the app' },
108
+ { name: 'user_logged_out', senders: APP, kind: 'product', what: 'A desktop sign-out, from the app' },
109
+ { name: 'generation_started', senders: APP, kind: 'product', what: 'Generate pressed in the app' },
110
+ { name: 'desktop_signed_in', senders: API, kind: 'product', what: 'A desktop sign-in, from the server (first=true on the first)' },
111
+ { name: 'generation_charged', senders: API, kind: 'product', what: "A generation's credits debited, from the server" },
112
+ { name: 'agent_brain_turn', senders: API, kind: 'product', what: 'One Studio Agent turn on the server brain' },
113
+ // The app's agent loop sends these through POST /agent/event; the API relays them.
114
+ { name: 'agent_run_started', senders: [...APP, ...API], kind: 'product', what: 'A Studio Agent run started' },
115
+ { name: 'agent_run_completed', senders: [...APP, ...API], kind: 'product', what: 'A Studio Agent run finished' },
116
+ { name: 'agent_run_cancelled', senders: [...APP, ...API], kind: 'product', what: 'A Studio Agent run stopped by the user' },
117
+ { name: 'agent_run_failed', senders: [...APP, ...API], kind: 'product', what: 'A Studio Agent run failed' },
118
+ { name: 'agent_plan_approved', senders: [...APP, ...API], kind: 'product', what: "The agent's plan approved" },
119
+ { name: 'agent_plan_rejected', senders: [...APP, ...API], kind: 'product', what: "The agent's plan rejected or edited" },
120
+ // ── Account ──
121
+ { name: 'auto_topup_enabled', senders: API, kind: 'account', what: 'Auto top-up switched on' },
122
+ { name: 'auto_topup_disabled', senders: API, kind: 'account', what: 'Auto top-up switched off' },
123
+ { name: 'auto_topup_charged', senders: API, kind: 'account', what: 'An auto top-up charged' },
124
+ { name: 'auto_topup_failed', senders: API, kind: 'account', what: 'An auto top-up failed' },
125
+ { name: 'one_click_topup_charged', senders: API, kind: 'account', what: 'A one-click top-up charged' },
126
+ { name: 'one_click_topup_failed', senders: API, kind: 'account', what: 'A one-click top-up failed' },
127
+ { name: 'account_email_changed', senders: API, kind: 'account', what: "An account's email changed (the person splits; see the plan)" },
128
+ { name: 'account_email_reverted', senders: API, kind: 'account', what: 'An email change undone' },
129
+ { name: 'refund_processed', senders: API, kind: 'account', what: 'A refund taken back what its payment granted' },
130
+ { name: 'dispute_opened', senders: API, kind: 'account', what: 'A chargeback opened' },
131
+ ];
132
+ const BY_NAME = new Map(ANALYTICS_EVENTS.map((e) => [e.name, e]));
133
+ if (BY_NAME.size !== ANALYTICS_EVENTS.length) {
134
+ throw new Error('analytics taxonomy: a name is listed twice');
135
+ }
136
+ export function analyticsEvent(name) {
137
+ return BY_NAME.get(name);
138
+ }
139
+ /**
140
+ * The one PostHog id for a person on every surface: the email, trimmed and
141
+ * lowercased. A buyer who types a capital letter would otherwise be two people,
142
+ * and PostHog will not merge two people who are both already identified.
143
+ */
144
+ export function analyticsPersonId(email) {
145
+ return email.trim().toLowerCase();
146
+ }
147
+ /**
148
+ * A purchase event's id: the event and its PaymentIntent. A replayed webhook
149
+ * sends the same id, and Meta dedupes on it within 48 hours.
150
+ */
151
+ export function purchaseEventId(event, paymentIntentId) {
152
+ return `${event}:${paymentIntentId}`;
153
+ }
154
+ /** The required purchase properties a payload lacks (empty string and null count as missing). */
155
+ export function missingPurchaseProperties(properties) {
156
+ return PURCHASE_REQUIRED.filter((key) => properties[key] === undefined || properties[key] === null || properties[key] === '');
157
+ }
158
+ const CALL = /([A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)*)(\?\.)?\s*(?:<[^<>()]*>\s*)?\(/g;
159
+ /** Every call in `text`, its callee written as the source writes it (`?.capture` when it hangs off an expression). */
160
+ function allCalls(text) {
161
+ const out = [];
162
+ for (const m of text.matchAll(CALL)) {
163
+ const at = m.index;
164
+ if (/(function|async)\s+$/.test(text.slice(Math.max(0, at - 16), at)))
165
+ continue;
166
+ const hangs = text[at - 1] === '.' ? (text[at - 2] === '?' ? '?.' : '.') : '';
167
+ out.push({ callee: hangs + m[1] + (m[2] ?? ''), line: text.slice(0, at).split('\n').length, index: at + m[0].length });
168
+ }
169
+ return out;
170
+ }
171
+ /**
172
+ * Calls that look like an analytics send: a `.capture(` or `.track(` method,
173
+ * or a function named `trackEvent`, `trackDualEvent` or `track…Event`. The
174
+ * check fails on any of these that is not a known send form, so a new wrapper
175
+ * cannot slip names past it.
176
+ */
177
+ export function findSendLikeCalls(text) {
178
+ return allCalls(text).filter(({ callee }) => {
179
+ const method = /\.(capture|track)(\?\.)?$/.test(callee);
180
+ const fn = /^track(Dual)?\w*Event$/.test(callee);
181
+ return method || fn;
182
+ });
183
+ }
184
+ /**
185
+ * The calls in `text` made through `callers`, each with the event names its
186
+ * name argument can take. A name argument that is a literal, or a ternary whose
187
+ * branches are literals, resolves; anything else resolves to no names.
188
+ */
189
+ export function findEventCalls(text, callers) {
190
+ const byCallee = new Map(callers.map((c) => [c.callee, c.arg]));
191
+ const out = [];
192
+ for (const call of allCalls(text)) {
193
+ const arg = byCallee.get(call.callee);
194
+ if (arg === undefined)
195
+ continue;
196
+ const args = splitArguments(text, call.index);
197
+ const source = (args[arg] ?? '').replace(/\s+/g, ' ').trim();
198
+ out.push({ callee: call.callee, line: call.line, names: literalNames(source), source });
199
+ }
200
+ return out;
201
+ }
202
+ /** Top-level comma-separated arguments of the call whose `(` ends just before `start`. */
203
+ function splitArguments(text, start) {
204
+ const args = [];
205
+ let depth = 0;
206
+ let current = '';
207
+ for (let i = start; i < text.length; i++) {
208
+ const ch = text[i];
209
+ if (ch === '"' || ch === "'" || ch === '`') {
210
+ const end = skipString(text, i);
211
+ current += text.slice(i, end);
212
+ i = end - 1;
213
+ continue;
214
+ }
215
+ if (ch === '/' && text[i + 1] === '/') {
216
+ const end = text.indexOf('\n', i);
217
+ i = (end === -1 ? text.length : end) - 1;
218
+ continue;
219
+ }
220
+ if (ch === '/' && text[i + 1] === '*') {
221
+ const end = text.indexOf('*/', i + 2);
222
+ i = (end === -1 ? text.length : end + 2) - 1;
223
+ continue;
224
+ }
225
+ if (ch === '(' || ch === '[' || ch === '{')
226
+ depth++;
227
+ if (ch === ')' || ch === ']' || ch === '}') {
228
+ if (depth === 0) {
229
+ args.push(current);
230
+ return args;
231
+ }
232
+ depth--;
233
+ }
234
+ if (ch === ',' && depth === 0) {
235
+ args.push(current);
236
+ current = '';
237
+ continue;
238
+ }
239
+ current += ch;
240
+ }
241
+ args.push(current);
242
+ return args;
243
+ }
244
+ function skipString(text, start) {
245
+ const quote = text[start];
246
+ for (let i = start + 1; i < text.length; i++) {
247
+ if (text[i] === '\\') {
248
+ i++;
249
+ continue;
250
+ }
251
+ if (quote === '`' && text[i] === '$' && text[i + 1] === '{')
252
+ return text.length; // never treated as a literal
253
+ if (text[i] === quote)
254
+ return i + 1;
255
+ }
256
+ return text.length;
257
+ }
258
+ /** The names a literal or a ternary of literals can produce; [] when anything else. */
259
+ function literalNames(source) {
260
+ const s = stripParens(source.trim());
261
+ const literal = /^(['"])([^'"\\]*)\1$/.exec(s) ?? /^(`)([^`\\$]*)`$/.exec(s);
262
+ if (literal)
263
+ return [literal[2]];
264
+ const q = topLevelIndex(s, '?');
265
+ if (q === -1)
266
+ return [];
267
+ const rest = s.slice(q + 1);
268
+ const c = topLevelIndex(rest, ':');
269
+ if (c === -1)
270
+ return [];
271
+ const a = literalNames(rest.slice(0, c));
272
+ const b = literalNames(rest.slice(c + 1));
273
+ return a.length && b.length ? [...a, ...b] : [];
274
+ }
275
+ function stripParens(s) {
276
+ while (s.startsWith('(') && s.endsWith(')'))
277
+ s = s.slice(1, -1).trim();
278
+ return s;
279
+ }
280
+ /** Index of `ch` outside strings and brackets, skipping `?.` and `??`. */
281
+ function topLevelIndex(s, ch) {
282
+ let depth = 0;
283
+ for (let i = 0; i < s.length; i++) {
284
+ const c = s[i];
285
+ if (c === '"' || c === "'" || c === '`') {
286
+ i = skipString(s, i) - 1;
287
+ continue;
288
+ }
289
+ if (c === '(' || c === '[' || c === '{')
290
+ depth++;
291
+ else if (c === ')' || c === ']' || c === '}')
292
+ depth--;
293
+ else if (depth === 0 && c === ch) {
294
+ if (ch === '?' && (s[i + 1] === '.' || s[i + 1] === '?' || s[i - 1] === '?'))
295
+ continue;
296
+ return i;
297
+ }
298
+ }
299
+ return -1;
300
+ }
301
+ /** Ways to reach `capture`/`track` that hide the call from the scan: each is refused. */
302
+ const INDIRECT_SENDS = [
303
+ [/\[\s*['"`](capture|track)['"`]\s*\]/g, 'bracket access to'],
304
+ [/\.(capture|track)\s*\.\s*(bind|call|apply)\b/g, 'a bound or applied'],
305
+ [/\{[^{}]*\b(capture|track)\b[^{}]*\}\s*=\s*(usePostHog\s*\(|posthog\b)/g, 'a destructured'],
306
+ ];
307
+ /** The string literals inside `const <name> = …`, up to the end of its bracketed value. */
308
+ export function constLiterals(text, name) {
309
+ const at = new RegExp(`const\\s+${name}\\b[^=]*=`).exec(text);
310
+ if (!at)
311
+ return [];
312
+ const open = text.slice(at.index + at[0].length).search(/[[{(]/);
313
+ if (open === -1)
314
+ return [];
315
+ const start = at.index + at[0].length + open + 1;
316
+ const body = splitArguments(text, start).join(',');
317
+ return [...body.matchAll(/(['"])([^'"\\]+)\1/g)].map((m) => m[2]);
318
+ }
319
+ /** Every event name the files send through `opts`, literal or declared for a computed send. */
320
+ export function sentNames(files, opts) {
321
+ const names = new Set();
322
+ for (const f of files) {
323
+ for (const call of findEventCalls(f.text, opts.callers))
324
+ for (const n of call.names)
325
+ names.add(n);
326
+ for (const d of opts.dynamic ?? []) {
327
+ if (d.namesFrom && f.path.replace(/\\/g, '/').endsWith(d.file))
328
+ for (const n of constLiterals(f.text, d.namesFrom))
329
+ names.add(n);
330
+ }
331
+ }
332
+ return names;
333
+ }
334
+ /** Check one source file of `sender` against the taxonomy. */
335
+ export function checkSource(file, text, sender, opts) {
336
+ const findings = [];
337
+ const flag = (line, problem) => findings.push({ file, line, problem });
338
+ const matches = (d, callee) => d.callee === callee && file.replace(/\\/g, '/').endsWith(d.file);
339
+ const known = new Set(opts.callers.map((c) => c.callee));
340
+ for (const call of findSendLikeCalls(text)) {
341
+ if (known.has(call.callee) || opts.ignore?.some((d) => matches(d, call.callee)))
342
+ continue;
343
+ flag(call.line, `unknown send form \`${call.callee}(\`: add it to this repo's callers in check:analytics, or send through a known one`);
344
+ }
345
+ for (const [pattern, what] of INDIRECT_SENDS) {
346
+ for (const m of text.matchAll(pattern)) {
347
+ flag(text.slice(0, m.index).split('\n').length, `${what} \`${m[1]}\` hides the event name from this check: call it directly`);
348
+ }
349
+ }
350
+ const checkName = (line, name, callee) => {
351
+ const event = analyticsEvent(name);
352
+ if (!event)
353
+ flag(line, `\`${name}\` is not in the analytics taxonomy (slates-mcp packages/shared/src/analytics/events.ts)`);
354
+ else if (!event.senders.includes(sender))
355
+ flag(line, `\`${name}\` is not listed as sent by ${sender}`);
356
+ else if (event.kind === 'purchase' && opts.purchaseVia && callee !== opts.purchaseVia) {
357
+ flag(line, `purchase event \`${name}\` must go through ${opts.purchaseVia}, which adds ${PURCHASE_REQUIRED.join(', ')}`);
358
+ }
359
+ };
360
+ for (const call of findEventCalls(text, opts.callers)) {
361
+ if (call.names.length > 0) {
362
+ for (const name of call.names)
363
+ checkName(call.line, name, call.callee);
364
+ continue;
365
+ }
366
+ const allowed = opts.dynamic?.find((d) => matches(d, call.callee));
367
+ if (!allowed) {
368
+ flag(call.line, `event name \`${call.source}\` is computed; use a literal from the taxonomy`);
369
+ }
370
+ else if (allowed.namesFrom) {
371
+ const names = constLiterals(text, allowed.namesFrom);
372
+ if (names.length === 0)
373
+ flag(call.line, `\`${allowed.namesFrom}\` declares no event names in this file`);
374
+ for (const name of names)
375
+ checkName(call.line, name, call.callee);
376
+ }
377
+ }
378
+ return findings;
379
+ }
380
+ /**
381
+ * Mutation cases a repo's check runs on itself. Each must produce a finding, or
382
+ * the check has gone blind; returns the cases that produced none.
383
+ */
384
+ export function selfTest(sender, opts) {
385
+ const caller = opts.callers.find((c) => c.callee !== opts.purchaseVia && !opts.dynamic?.some((d) => d.callee === c.callee)) ?? opts.callers[0];
386
+ const call = (name) => `${caller.callee}(${[...Array(caller.arg).fill('who'), name].join(', ')}, {});`;
387
+ const cases = [
388
+ ['a hand-typed name outside the taxonomy', call("'purchase_completed'")],
389
+ ['a computed name', call('eventName')],
390
+ ['an unknown send form', "analytics.capture('license_purchased');"],
391
+ ['an unknown send form with type arguments', "analytics.capture <Props>('license_purchased');"],
392
+ ['bracket access', "posthog['capture']('license_purchased');"],
393
+ ['a destructured capture', 'const { capture } = usePostHog();'],
394
+ ];
395
+ if (opts.purchaseVia)
396
+ cases.push([`a purchase event sent around ${opts.purchaseVia}`, call("'license_purchased'")]);
397
+ return cases.filter(([, text]) => checkSource('self-test.ts', text, sender, opts).length === 0).map(([what]) => what);
398
+ }
399
+ /**
400
+ * The whole check for one repo: its files scanned, the self-test, and its copy
401
+ * of this module compared with the source when the slates-mcp checkout is
402
+ * beside it (`copy` and `source` are the two texts; leave `source` undefined
403
+ * when there is no sibling). Returns the lines to print and whether it passed.
404
+ */
405
+ export function analyticsReport(files, sender, opts, taxonomy) {
406
+ const lines = [];
407
+ const findings = files.flatMap((f) => checkSource(f.path, f.text, sender, opts));
408
+ const sent = sentNames(files, opts);
409
+ for (const e of ANALYTICS_EVENTS) {
410
+ if (e.senders.includes(sender) && !e.library && !sent.has(e.name)) {
411
+ findings.push({ file: 'taxonomy', line: 0, problem: `\`${e.name}\` is listed as sent by ${sender}, but no code here sends it: remove ${sender} from its senders, or send it` });
412
+ }
413
+ }
414
+ for (const f of findings)
415
+ lines.push(` ${f.file}:${f.line} ${f.problem}`);
416
+ const blind = selfTest(sender, opts);
417
+ for (const what of blind)
418
+ lines.push(` self-test: ${what} passed the check; the scanner has gone blind`);
419
+ const body = taxonomy.copy.replace(/\r\n/g, '\n').split('\n').filter((l) => !l.startsWith('// GENERATED by') && !l.startsWith('// Never hand-edit')).join('\n');
420
+ const drift = taxonomy.source !== undefined && body !== taxonomy.source.replace(/\r\n/g, '\n');
421
+ if (drift)
422
+ lines.push(' the taxonomy copy differs from slates-mcp packages/shared/src/analytics/events.ts: run `npm run build:llm-docs` in slates-web');
423
+ const ok = findings.length === 0 && blind.length === 0 && !drift;
424
+ const sends = files.reduce((n, f) => n + findEventCalls(f.text, opts.callers).length, 0);
425
+ lines.unshift(ok
426
+ ? `✓ analytics: ${sends} sends in ${files.length} files match the taxonomy (${ANALYTICS_EVENTS.length} events)${taxonomy.source === undefined ? '; no slates-mcp checkout beside this repo, so the copy was not compared' : ''}`
427
+ : `✖ analytics: ${findings.length + blind.length + (drift ? 1 : 0)} problem(s)`);
428
+ return { ok, lines };
429
+ }
430
+ //# sourceMappingURL=events.js.map
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export { toolDefinitions, toolDefinition, groupFor, tierFor, OPERATION_GROUPS, G
10
10
  export { MODEL_FACTS, getModelFact, multimodalRefSummary, multimodalRefModels, describeRouting, SEEDANCE_TASK_INTENT_WORDS, seedanceTaskIntentWords, type ModelFact, } from './prompts/model-facts.js';
11
11
  export { MODEL_CAPABILITIES, ALL_ASPECT_RATIOS, AGENT_ROUTE_PROVIDER, getModelCapability, aspectRatiosFor, videoResolutionsFor, defaultVideoResolutionFor, durationsFor, durationValuesFor, aspectRatioUnion, videoResolutionUnion, durationBounds, checkAspectRatio, checkVideoResolution, checkDuration, describeAspectRatios, describeVideoResolutions, describeDurations, describeReferenceImageCaps, type AspectRatio, type VideoResolution, type ModelCapability, type DurationCapability, type VideoResolutionCapability, } from './prompts/model-capabilities.js';
12
12
  export { buildAgentDoctrine, type AgentSurface } from './prompts/agent-doctrine.js';
13
- export { BANNED_PROMPT_TOKENS, describeBannedTokens, findBannedTokens, bannedTokenWarning, bannedTokensForSkill, describeBannedTokensForSkill, type BannedToken, type BannedTokenScope, } from './prompts/banned-tokens.js';
13
+ export { BANNED_PROMPT_TOKENS, describeBannedTokens, findBannedTokens, bannedTokenWarning, refusableBannedTokens, bannedTokensForSkill, describeBannedTokensForSkill, type BannedToken, type BannedTokenScope, type BannedTokenCondition, } from './prompts/banned-tokens.js';
14
14
  export { CRAFT_CARDS, CRAFT_CARD_CEILING, craftCard, describeCraftCard } from './prompts/craft-cards.js';
15
15
  export { PROMPTING_TIPS, getPromptingTips, type PromptingTipsEntry, type PromptingTipCard, type PromptingTipsKey } from './prompts/prompting-tips.js';
16
16
  export { SLATES_API_URL } from './api-url.js';
package/dist/index.js CHANGED
@@ -53,6 +53,10 @@ export {
53
53
  // ops. findBannedTokens: the eval harness scorer. bannedTokenWarning: the ops.
54
54
  // `bannedTokensFor` is internal to the module and stays there.
55
55
  BANNED_PROMPT_TOKENS, describeBannedTokens, findBannedTokens, bannedTokenWarning,
56
+ // refusableBannedTokens: the desktop Studio Agent loop's pre-spend refusal
57
+ // (slate studio-agent/guards.ts) — the checkable subset, honouring each
58
+ // block's call-shape limit.
59
+ refusableBannedTokens,
56
60
  // Per-model lists — the 13 skills the two cross-model lists never covered.
57
61
  bannedTokensForSkill, describeBannedTokensForSkill, } from './prompts/banned-tokens.js';
58
62
  // 🚨 CRAFT CARDS — the POSITIVE half of the guide, extracted from the skills'