Skip to content

Instantly share code, notes, and snippets.

@zirkelc
zirkelc / cloudwatch-insights-freshness-repro.sh
Last active September 30, 2026 07:45
CloudWatch Logs Insights silently hides the newest ~2 minutes of logs from queries that use parse or functions
#!/usr/bin/env bash
#
# CloudWatch Logs Insights freshness repro.
#
# Writes a log event, then asks Logs Insights for it every few seconds with four
# queries that differ only in shape, and shows live which ones find it:
#
# nofilter no filter at all (the event is matched on the client)
# filter filter @message like /<marker>/
# parse parse @message ... | filter @message like /<marker>/ and ispresent(level)
/**
* Azure OpenAI rejects some GPT-5.4 prompts above 272k tokens with
* `context_length_exceeded`, although the model has a 1M context window.
*
* Which prompts fail depends on how many characters they have per token, not on
* their token count: English at 285k tokens passes, Japanese, Chinese or dense
* ASCII at 285k tokens fails, and Japanese at 700k tokens passes again. The same prompts
* sent to OpenAI directly work.
*
* This script sends synthetic prompts of one exact token size but different text
@zirkelc
zirkelc / probe-context-window.mjs
Created September 23, 2026 09:33
Azure OpenAI GPT-5.4 rejects dense prompts (Japanese, Chinese, dense ASCII) above 272k tokens with context_length_exceeded, despite the 1M window. Reproduction script.
#!/usr/bin/env node
/**
* Azure OpenAI rejects some GPT-5.4 prompts above 272k tokens with
* `context_length_exceeded`, although the model has a 1M context window.
*
* Which prompts fail depends on how many characters they have per token, not on
* their token count: English at 285k tokens passes, Japanese, Chinese or dense
* ASCII at 285k tokens fails, and Japanese at 700k tokens passes again. The same prompts
* sent to OpenAI directly work.
*
@zirkelc
zirkelc / probe-context-window.mjs
Created September 23, 2026 09:29
Azure OpenAI GPT-5.4 rejects dense prompts (CJK, dense ASCII) above 272k tokens with context_length_exceeded, despite the 1M window. Reproduction script.
#!/usr/bin/env node
/**
* Azure OpenAI rejects some GPT-5.4 prompts above 272k tokens with
* `context_length_exceeded`, although the model has a 1M context window.
*
* Which prompts fail depends on how many characters they have per token, not on
* their token count: English at 285k tokens passes, Japanese or dense ASCII at
* 285k tokens fails, and Japanese at 700k tokens passes again. The same prompts
* sent to OpenAI directly work.
*
import "dotenv/config";
import { openai } from "@ai-sdk/openai";
import { type InferUITools, stepCountIs, streamText, tool, type UIMessage } from "ai";
import { z } from "zod";
import { pipe, toolCall } from "ai-stream-utils";
const tools = {
weather: tool({
description: `Get the current weather for a location`,
inputSchema: z.object({
import { UIMessage, InferUITools, tool } from 'ai';
type ToolSet = ReturnType<typeof createToolSet>['tools'];
// Create a tool set
// Optionally accept common tool params like a UIStreamWriter
export const createToolSet = () => {
const tools = {
firstTool: tool({
description: 'Greets the user',
@zirkelc
zirkelc / anthropic-overloaded.ts
Created September 24, 2025 14:14
Retryable for Anthropic overloaded error
import type { LanguageModelV2 } from '@ai-sdk/provider';
import { APICallError } from 'ai';
import type { Retryable, RetryModel } from '../create-retryable-model.js';
import { isErrorAttempt, isResultAttempt } from '../create-retryable-model.js';
import { isObject, isString } from '../utils.js';
/**
* Fallback to a different model if Anthropic returns an "overloaded" error.
*
* ```
@zirkelc
zirkelc / default.md
Created July 17, 2025 06:24 — forked from cablej/default.md
Cluely System prompt

<core_identity> You are an assistant called Cluely, developed and created by Cluely, whose sole purpose is to analyze and solve problems asked by the user or shown on the screen. Your responses must be specific, accurate, and actionable. </core_identity>

<general_guidelines>

  • NEVER use meta-phrases (e.g., "let me help you", "I can see that").
  • NEVER summarize unless explicitly requested.
  • NEVER provide unsolicited advice.
  • NEVER refer to "screenshot" or "image" - refer to it as "the screen" if needed.
  • ALWAYS be specific, detailed, and accurate.
@zirkelc
zirkelc / github-release-tools.md
Created October 23, 2024 11:44
GitHub Release Automation Tools
@zirkelc
zirkelc / list-all-files.ts
Created October 11, 2024 07:55
Recursive generator function to list all files in a directory in Node.js
import fs from 'node:fs/promises';
import path from 'node:path';
async function* readAllFiles(dir: string): AsyncGenerator<string> {
// use fs.readdirSync() to avoid async
const files = await fs.readdir(dir, { withFileTypes: true });
for (const file of files) {
if (file.isDirectory()) {
yield* readAllFiles(path.join(dir, file.name));