# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Build and Development Commands

- **Build the project**: `npm run build`
- **Run all tests**: `npm test`
- **Run tests with coverage**: `npm run test:coverage`
- **Run a specific test file**: `npm test -- tests/TransitiveTrustGraph.test.ts` or `npm test -- tests/PriorityQueue.test.ts`
- **Run tests matching a pattern**: `npm test -- --testNamePattern="pattern"`
- **Prepare for publishing**: `npm run prepublishOnly` (runs build automatically)

## Project Architecture

This is a TypeScript SDK implementing a transitive trust scoring system using directed graphs. The architecture consists of:

### Core Components

1. **TransitiveTrustGraph** (src/TransitiveTrustGraph.ts)
   - Main class that manages the trust graph using the graphology library
   - Implements a modified Dijkstra algorithm with a max-heap priority queue for computing trust scores
   - Handles both positive and negative trust weights on edges
   - Key method: `computeTrustScores()` which propagates trust through the graph
   - Public property: `graph` - exposes the underlying graphology Graph instance

2. **PriorityQueue** (src/PriorityQueue.ts)
   - Custom max-heap implementation used by the trust score computation algorithm
   - Supports priority updates needed for the trust propagation algorithm
   - Key methods: `insert()`, `extractMax()`, `updatePriority()`, `isEmpty()`

### Trust Score Algorithm

The trust propagation algorithm in `computeScores()` works as follows:
1. Initialize all nodes with positive score 0 and negative score 0, except source node (positive score 1)
2. Use a priority queue ordered by net trust score (positive - negative)
3. For each node, propagate trust to neighbors if it improves their score
4. The algorithm ensures trust diminishes as it propagates through the graph

Key formulas:
- Node score: `max(positive_score - negative_score, 0)`
- Positive propagation: Only if source node score > neighbor's positive score
- Negative propagation: Only if source node score > neighbor's negative score

### Testing Strategy

- Tests are written using Jest with TypeScript support (ts-jest)
- Test files are located in `tests/` directory
- Coverage thresholds are set at 80% for all metrics
- Tests cover:
  - Graph construction and edge validation
  - Trust score computation with various graph topologies
  - Edge cases (empty strings, invalid weights, non-existent nodes)
  - Priority queue operations including heapify operations