|
1 | | -# AI Agent Guidelines |
| 1 | +# Filecoin Pin |
2 | 2 |
|
3 | | -When using AI agents (such as Claude Code, Cursor, or similar tools) to contribute to this project, please ensure the agent follows all guidelines outlined in [CONTRIBUTING.md](./CONTRIBUTING.md). |
| 3 | +IPFS persistence layer for Filecoin with verifiable storage proofs. TypeScript library + CLI + GitHub Action. |
4 | 4 |
|
5 | | -This includes: |
6 | | -- Using conventional commits |
7 | | -- Referencing GitHub issues in PRs |
8 | | -- Including visual evidence for user-facing changes |
9 | | -- Keeping PRs in draft until ready for review |
10 | | -- Writing concise, self-documenting code |
| 5 | +## What This Is |
| 6 | + |
| 7 | +Bridges IPFS content to Filecoin storage providers with cryptographic guarantees. Production tool + reference implementation for building on synapse-sdk. |
| 8 | + |
| 9 | +**Affordances**: CLI (`add`, `payments`, `data-set`), GitHub Action, core library (published npm modules), IPFS Pinning Server (`server` daemon). |
| 10 | + |
| 11 | +**Stack**: filecoin-pin → synapse-sdk → FOC contracts (FWSS, FilecoinPay, PDPVerifier, SPRegistry) + Curio. |
| 12 | + |
| 13 | +**Status**: Calibration testnet only. Not production-ready. |
| 14 | + |
| 15 | +## Design Philosophy |
| 16 | + |
| 17 | +**Reference Implementation**: Demonstrates opinionated, documented patterns for building on synapse-sdk. Code clarity and educational value over abstraction. |
| 18 | + |
| 19 | +**Developer Learning**: Primary use case is teaching developers how to build on FOC stack. Favor explicit, traceable code over clever shortcuts. |
| 20 | + |
| 21 | +**Simple API Surface**: Keep public interfaces minimal and focused. Complexity lives in internal implementation, not exposed APIs. |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +``` |
| 26 | +src/ |
| 27 | +├── cli.ts, server.ts # Commander.js CLI + Fastify server |
| 28 | +├── add/, data-set/ # Command implementations |
| 29 | +├── core/ # Published library (see package.json exports) |
| 30 | +│ ├── car/ # CAR file handling (CARv1 streaming) |
| 31 | +│ ├── payments/ # Payment setup/status |
| 32 | +│ ├── synapse/ # SDK initialization patterns |
| 33 | +│ ├── upload/ # Upload workflows |
| 34 | +│ ├── unixfs/ # Helia integration, browser/node variants |
| 35 | +│ └── utils/ # Formatting, constants |
| 36 | +└── common/ # Internal shared code |
| 37 | +``` |
| 38 | + |
| 39 | +**Data flow**: Files → Helia/UnixFS → CAR → Synapse SDK → FOC contracts + Curio → PieceCID + proofs. |
| 40 | + |
| 41 | +## Development |
| 42 | + |
| 43 | +**Setup**: `npm install && npm run build && npm test` |
| 44 | + |
| 45 | +**Scripts**: `npm run build` (tsc), `npm run dev` (tsx watch), `npm test` (lint + typecheck + unit + integration), `npm run lint:fix` |
| 46 | + |
| 47 | +**Requirements**: Node.js 24+, TypeScript ES modules, Biome linting |
| 48 | + |
| 49 | +**Tests**: Vitest (unit + integration), mock SDK at `src/test/mocks/synapse-sdk.js` |
| 50 | + |
| 51 | +## Key Patterns |
| 52 | + |
| 53 | +**Synapse SDK**: Initialize with callbacks (onProviderSelected, onDataSetResolved, onPieceAdded), upload returns {pieceCid, pieceId, provider}. See `src/core/synapse/index.ts`, `src/core/upload/synapse.ts`. |
| 54 | + |
| 55 | +**CAR files**: CARv1 streaming, handle 3 root cases (single/multiple/none), use zero CID for no roots. See `src/core/car/car-blockstore.ts`. |
| 56 | + |
| 57 | +**UnixFS**: Helia for directory imports, chunking, CID calculation. See `src/core/unixfs/`. |
| 58 | + |
| 59 | +**Payments**: `checkPaymentStatus()`, `setupPayments()` in `src/core/payments/index.ts`. |
| 60 | + |
| 61 | +## Biome Linting (Critical) |
| 62 | + |
| 63 | +- **NO** `!` operator → use `?.` or explicit checks |
| 64 | +- **MUST** use `.js` extensions in imports (`import {x} from './y.js'` even for .ts) |
| 65 | +- **NO** semicolons at line end (`semicolons: "asNeeded"`) |
| 66 | +- **MUST** use kebab-case filenames |
| 67 | + |
| 68 | +## Common Pitfalls |
| 69 | + |
| 70 | +1. Import extensions required (`.js` even for .ts files) |
| 71 | +2. Handle 3 CAR root cases (none/single/multiple) |
| 72 | +3. Provider info may be undefined |
| 73 | +4. Clean up CAR files and Helia instances on failure |
| 74 | +5. Browser vs Node variants (check package.json exports) |
| 75 | + |
| 76 | +## CLI & Environment |
| 77 | + |
| 78 | +**Commands**: `payments setup --auto`, `add <file>`, `payments status`, `data-set <id>`, `server` |
| 79 | + |
| 80 | +**Required env**: `PRIVATE_KEY=0x...` (with USDFC tokens) |
| 81 | + |
| 82 | +**Optional**: `RPC_URL` (default: Calibration), `PORT`, `HOST`, `DATABASE_PATH`, `CAR_STORAGE_PATH`, `LOG_LEVEL` |
| 83 | + |
| 84 | +**Default data dirs for pinning server**: Linux `~/.local/share/filecoin-pin/`, macOS `~/Library/Application Support/filecoin-pin/`, Windows `%APPDATA%/filecoin-pin/` |
| 85 | + |
| 86 | +## Git Policy |
| 87 | + |
| 88 | +Conventional commits. Never `git commit` or `git push` without explicit user permission. Ask first, draft message, wait for approval. |
| 89 | + |
| 90 | +## License |
| 91 | + |
| 92 | +Apache-2.0 OR MIT |
0 commit comments