stevensDemo.cursorrules15 matches
8### 1. Script Vals
910- Basic JavaScript/TypeScript functions
11- Can be imported by other vals
12- Example structure:
1314```typescript
15export function myFunction() {
16// Your code here
17}
2526```typescript
27export default async function (req: Request) {
28return new Response("Hello World");
29}
3738```typescript
39export default async function () {
40// Scheduled task code
41}
4950```typescript
51export default async function (email: Email) {
52// Process email
53}
5758- Ask clarifying questions when requirements are ambiguous
59- Provide complete, functional solutions rather than skeleton implementations
60- Test your logic against edge cases before presenting the final solution
61- Ensure all code follows Val Town's specific platform requirements
70- **Never bake in secrets into the code** - always use environment variables
71- Include comments explaining complex logic (avoid commenting obvious operations)
72- Follow modern ES6+ conventions and functional programming practices if possible
7374## Val Town Standard Libraries
7576Val Town provides several hosted services and utility functions.
7778### Blob Storage
124```
125126## Val Town Utility Functions
127128Val Town provides several utility functions to help with common project tasks.
129130### Importing Utilities
176{
177name: "should add numbers correctly",
178function: () => {
179expect(1 + 1).toBe(2);
180},
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
213โ โ โโโ README.md
214โ โโโ index.ts # Main entry point
226โโโ shared/
227โโโ README.md
228โโโ utils.ts # Shared types and functions
229```
230232- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
233- Main entry point should be `backend/index.ts`
234- **Static asset serving:** Use the utility functions to read and serve project files:
235```ts
236// Use the serveFile utility to handle content types automatically
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
275- Export clear query functions with proper TypeScript typing
276- Follow the queries and migrations pattern from the example
277
stevensDemocronDailyBrief.ts1 match
1import { sendDailyBriefing } from "./sendDailyBrief.ts";
23export async function cronDailyBrief() {
4try {
5const chatId = Deno.env.get("TELEGRAM_CHAT_ID");
stevensDemoApp.tsx2 matches
62};
6364export function App() {
65const [memories, setMemories] = useState<Memory[]>([]);
66const [loading, setLoading] = useState(true);
139const data = await response.json();
140141// Change the sorting function to show memories in chronological order
142const sortedMemories = [...data].sort((a, b) => {
143const dateA = a.createdDate || 0;
45`;
4647function getYesterdayDateRange(): { startDate: string; endDate: string } {
48const now = new Date();
49const yesterday = new Date(now.setDate(now.getDate() - 1));
56}
5758export async function exec(interval: Interval) {
59const apiKey = Deno.env.get("LINEAR_API_KEY");
60if (!apiKey) {
132});
133134function determineMatchedContext(
135history: any[],
136startDate: string,
staticWordlemain.tsx8 matches
46};
4748function encodeGame(game: Game): string {
49return btoa(JSON.stringify(game));
50}
51function decodeGame(encoded: string): Game {
52try {
53return JSON.parse(atob(encoded));
56}
57}
58function nextStateEncoded(url, game: Game, action: string): string | undefined {
59const next = nextState(game, action);
60return next ? `https://${url}/${encodeGame(next)}` : undefined;
61}
62function nextState(game: Game, action: string): Game | undefined {
63// TODO - check if action is valid and return null if not, ie no link
64const { answer, guesses, currentGuess } = game;
88}
8990function rightPad(str: string, length: number): string {
91return str + " ".repeat(length - str.length);
92}
9394function letterColor({ answer, guesses }: Game, letter: string): string {
95if (guesses.some((guess) => [...guess].some((x, i) => x === letter && answer[i] === letter))) {
96return GREEN;
107}
108109async function handler(req: Request): Promise<Response> {
110const url = new URL(req.url);
111if (url.pathname === "/") {
246}
247248function generateWordleBoardSVG({ guesses, answer, currentGuess }) {
249const GREEN = "#6aaa64";
250const YELLOW = "#c9b458";
2import { google } from "npm:googleapis";
34export async function getAccessToken(accountId: string, bearer = Deno.env.get("pipedream")) {
5const response = await fetchJSON(
6`https://api.pipedream.com/v1/accounts/${accountId}?include_credentials=1`,
10}
1112export function googleService(service: string, accessToken: string) {
13return google[service]({
14version: "v3",
19}
2021export async function pipeDreamGoogle(service: string, accountId: string, bearer = Deno.env.get("pipedream")) {
22const accessToken = await getAccessToken(accountId, bearer);
23return googleService(service, accessToken);
3Pipedream offers an Accounts API to handle OAuth for you, automatically, and for free. [How to do it is covered in this guide](https://docs.val.town/integrations/google-sheets/#use-pipedreams-accounts-api).
45The helper functions below can make it easier to work with various Google API. For example, I used them like so to get all my free/busy times for this week from all my google calendars:
67```ts
11const calendar = await pipeDreamGoogle("calendar", accountId);
1213// Function to get free/busy information
14async function getFreeBusyTimes(calendarId: string) {
15const now = new Date();
16const startOfWeek = new Date(now);
stevensDemotestDailyBrief.ts1 match
4import { DateTime } from "https://esm.sh/luxon@3.4.4";
56export async function testDailyBrief() {
7try {
8const testChatId = Deno.env.get("TEST_TELEGRAM_CHAT_ID");
2// Run this script manually to create the database table
34export default async function setupTelegramChatDb() {
5try {
6// Import SQLite module
stevensDemosendDailyBrief.ts6 matches
13} from "../memoryUtils.ts";
1415async function generateBriefingContent(anthropic, memories, today, isSunday) {
16try {
17const weekdaysHelp = generateWeekDays(today);
96}
9798export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99// Get API keys from environment
100const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139216}
217218function generateWeekDays(today) {
219let output = [];
220239// console.log(weekDays);
240241// Export a function that calls sendDailyBriefing with no parameters
242// This maintains backward compatibility with existing cron jobs
243export default async function (overrideToday?: DateTime) {
244return await sendDailyBriefing(undefined, overrideToday);
245}