···1+# CLAUDE.md
2+3+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+5+## Project Overview
6+7+Sequoia is a CLI tool for publishing Markdown documents with frontmatter to the AT Protocol (Bluesky's decentralized social network). It converts blog posts into ATProto records (`site.standard.document`, `space.litenote.note`) and publishes them to a user's PDS.
8+9+Website: <https://sequoia.pub>
10+11+## Monorepo Structure
12+13+- **`packages/cli/`** โ Main CLI package (the core product)
14+- **`docs/`** โ Documentation website (Vocs-based, deployed to Cloudflare Pages)
15+16+Bun workspaces manage the monorepo.
17+18+## Commands
19+20+```bash
21+# Build CLI
22+bun run build:cli
23+24+# Run CLI in dev (build + link)
25+cd packages/cli && bun run dev
26+27+# Run tests
28+bun run test:cli
29+30+# Run a single test file
31+cd packages/cli && bun test src/lib/markdown.test.ts
32+33+# Lint (auto-fix)
34+cd packages/cli && bun run lint
35+36+# Format (auto-fix)
37+cd packages/cli && bun run format
38+39+# Docs dev server
40+bun run dev:docs
41+```
42+43+## Architecture
44+45+**Entry point:** `packages/cli/src/index.ts` โ Uses `cmd-ts` for type-safe subcommand routing.
46+47+**Commands** (`src/commands/`):
48+49+- `publish` โ Core workflow: scans markdown files, publishes to ATProto
50+- `sync` โ Fetches published records state from ATProto
51+- `update` โ Updates existing records
52+- `auth` โ Multi-identity management (app-password + OAuth)
53+- `init` โ Interactive config setup
54+- `inject` โ Injects verification links into static HTML output
55+- `login` โ Legacy auth (deprecated)
56+57+**Libraries** (`src/lib/`):
58+59+- `atproto.ts` โ ATProto API wrapper (two client types: AtpAgent for app-password, OAuth client)
60+- `config.ts` โ Loads `sequoia.json` config and `.sequoia-state.json` state files
61+- `credentials.ts` โ Multi-identity credential storage at `~/.config/sequoia/credentials.json` (0o600 permissions)
62+- `markdown.ts` โ Frontmatter parsing (YAML/TOML), content hashing, atUri injection
63+64+**Extensions** (`src/extensions/`):
65+66+- `litenote.ts` โ Creates `space.litenote.note` records with embedded images
67+68+## Key Patterns
69+70+- **Config resolution:** `sequoia.json` is found by searching up the directory tree
71+- **Frontmatter formats:** YAML (`---`), TOML (`+++`), and alternative (`***`) delimiters
72+- **Credential types:** App-password (PDS URL + identifier + password) and OAuth (DID + handle)
73+- **Build:** `bun build src/index.ts --target node --outdir dist`
74+75+## Tooling
76+77+- **Runtime/bundler:** Bun
78+- **Linter/formatter:** Biome (tabs, double quotes)
79+- **Test runner:** Bun's native test runner
80+- **CLI framework:** `cmd-ts`
81+- **Interactive UI:** `@clack/prompts`
82+83+## Git Conventions
84+85+Never add 'Co-authored-by' lines to git commits unless explicitly asked.
···11 "build:docs": "cd docs && bun run build",
12 "build:cli": "cd packages/cli && bun run build",
13 "deploy:docs": "cd docs && bun run deploy",
14- "deploy:cli": "cd packages/cli && bun run deploy"
015 },
16 "devDependencies": {
17 "@types/bun": "latest",
···11 "build:docs": "cd docs && bun run build",
12 "build:cli": "cd packages/cli && bun run build",
13 "deploy:docs": "cd docs && bun run deploy",
14+ "deploy:cli": "cd packages/cli && bun run deploy",
15+ "test:cli": "cd packages/cli && bun test"
16 },
17 "devDependencies": {
18 "@types/bun": "latest",
+74-5
packages/cli/src/commands/publish.ts
···25} from "../lib/markdown";
26import type { BlogPost, BlobObject, StrongRef } from "../lib/types";
27import { exitOnCancel } from "../lib/prompts";
02829export const publishCommand = command({
30 name: "publish",
···157 const postsToPublish: Array<{
158 post: BlogPost;
159 action: "create" | "update";
160- reason: string;
161 }> = [];
162 const draftPosts: BlogPost[] = [];
163···179 reason: "forced",
180 });
181 } else if (!postState) {
182- // New post
183 postsToPublish.push({
184 post,
185- action: "create",
186- reason: "new post",
187 });
188 } else if (postState.contentHash !== contentHash) {
189 // Changed post
···233 }
234 }
235236- log.message(` ${icon} ${post.frontmatter.title} (${reason})${bskyNote}`);
237 }
238239 if (dryRun) {
···264 let errorCount = 0;
265 let bskyPostCount = 0;
2660000000000000267 for (const { post, action } of postsToPublish) {
268 s.start(`Publishing: ${post.frontmatter.title}`);
000000269270 try {
271 // Handle cover image upload
···299300 if (action === "create") {
301 atUri = await createDocument(agent, post, config, coverImage);
0302 s.stop(`Created: ${atUri}`);
303304 // Update frontmatter with atUri
···372 slug: post.slug,
373 bskyPostRef,
374 };
00375 } catch (error) {
376 const errorMessage =
377 error instanceof Error ? error.message : String(error);
378 s.stop(`Error publishing "${path.basename(post.filePath)}"`);
379 log.error(` ${errorMessage}`);
380 errorCount++;
00000000000000000000000000000000000000000000000381 }
382 }
383
···13import {
14 scanContentDirectory,
15 getContentHash,
16+ getTextContent,
17 updateFrontmatterWithAtUri,
18} from "../lib/markdown";
19import { exitOnCancel } from "../lib/prompts";
···178 log.message(` URI: ${doc.uri}`);
179 log.message(` File: ${path.basename(localPost.filePath)}`);
180181+ // Compare local text content with PDS text content to detect changes.
182+ // We must avoid storing the local rawContent hash blindly, because
183+ // that would make publish think nothing changed even when content
184+ // was modified since the last publish.
185+ const localTextContent = getTextContent(
186+ localPost,
187+ config.textContentField,
188+ );
189+ const contentMatchesPDS =
190+ localTextContent.slice(0, 10000) === doc.value.textContent;
191+192+ // If local content matches PDS, store the local hash (up to date).
193+ // If it differs, store empty hash so publish detects the change.
194+ const contentHash = contentMatchesPDS
195+ ? await getContentHash(localPost.rawContent)
196+ : "";
197 const relativeFilePath = path.relative(configDir, localPost.filePath);
198 state.posts[relativeFilePath] = {
199 contentHash,