Skip to content
Back to skills

Using Trajectories Sdk

ASecurity

Use when programmatically creating or managing agent trajectories in TypeScript - provides TrajectoryClient for persistent storage and TrajectoryBuilder for in-memory construction

  • 666 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added June 10, 2026
ai-agentstypescriptbashapici/cd

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned June 10, 2026

npx -y skills add majiayu000/claude-skill-registry --skill using-trajectories-sdk --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Using Trajectories Sdk?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Using Trajectories Sdk
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-using-trajectories-sdk/badge)](https://www.skillsdirectory.com/skills/majiayu000-using-trajectories-sdk)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: using-trajectories-sdk
description: Use when programmatically creating or managing agent trajectories in TypeScript - provides TrajectoryClient for persistent storage and TrajectoryBuilder for in-memory construction
---

# Using the Trajectories SDK

## Overview

The `agent-trajectories` SDK provides two APIs for programmatically capturing agent work trajectories: **TrajectoryClient** (persistent, async) and **TrajectoryBuilder** (in-memory, sync).

## When to Use

- Building tools or agents that need to record their work programmatically
- Integrating trajectory capture into CI/CD or automation pipelines
- Creating trajectories from code rather than CLI
- **Not for**: Manual CLI usage (use `trail` CLI instead)

## Quick Reference

| Need | Use |
|------|-----|
| Persist trajectories to disk | `TrajectoryClient` |
| Build trajectories in memory | `TrajectoryBuilder` or `trajectory()` |
| One-liner start | `trajectory('title')` shorthand |
| Export formats | `.toMarkdown()`, `.toJSON()`, `.toTimeline()`, `.toPRSummary()` |

## Installation

```bash
npm install agent-trajectories
```

## TrajectoryClient (Persistent Storage)

Use when you need trajectories saved to `.trajectories/` on disk.

```typescript
import { TrajectoryClient } from 'agent-trajectories/sdk';

const client = new TrajectoryClient({ defaultAgent: 'my-agent' });
await client.init(); // Required before use

// Start a trajectory
const session = await client.start('Implement feature X');

// Record work in chapters
await session.chapter('Research');
await session.note('Found existing auth patterns');
await session.finding('Current implementation uses JWT');

await session.chapter('Implementation');
await session.decide(
  'JWT vs Session tokens',
  'JWT',
  'Better for stateless API clients',
  [{ option: 'Session tokens', reason: 'Simpler but requires server state' }]
);

// Complete with retrospective
await session.done('Implemented JWT auth', 0.9, {
  approach: 'Extended existing auth module',
  learnings: ['JWT refresh flow needs careful error handling'],
});

await client.close();
```

### Client Options

```typescript
new TrajectoryClient({
  dataDir: '.trajectories',    // Storage location (default)
  defaultAgent: 'agent-name',  // Default agent for chapters
  autoSave: true,              // Auto-persist after each operation (default)
});
```

### Key Client Methods

| Method | Description |
|--------|-------------|
| `client.start(title)` | Start new trajectory, returns session |
| `client.resume()` | Resume active trajectory |
| `client.get(id)` | Get trajectory by ID |
| `client.list(query?)` | List trajectories with optional filter |
| `client.search(text)` | Full-text search |

### Session Methods

| Method | Description |
|--------|-------------|
| `session.chapter(title, agent?)` | Start a new chapter |
| `session.note(content)` | Record a note |
| `session.finding(content)` | Record a finding (medium significance) |
| `session.reflect(content, confidence?)` | Record a reflection (high significance) |
| `session.error(content)` | Record an error (high significance) |
| `session.decide(question, chosen, reasoning, alts?)` | Record a decision |
| `session.done(summary, confidence, opts?)` | Complete trajectory |
| `session.abandon(reason?)` | Abandon trajectory |

## TrajectoryBuilder (In-Memory)

Use when you don't need persistence - just building a trajectory data structure.

```typescript
import { TrajectoryBuilder, trajectory } from 'agent-trajectories/sdk';

// Shorthand
const result = trajectory('Fix auth bug')
  .chapter('Investigation', 'claude')
  .finding('Null pointer in login handler')
  .decide('Fix approach', 'Add null check', 'Simplest correct fix')
  .done('Fixed null pointer exception', 0.95);

// Export
console.log(TrajectoryBuilder.create('Task')
  .chapter('Work', 'agent')
  .note('Did the thing')
  .toMarkdown());
```

Builder is synchronous and chainable. Call `.done()`, `.complete()`, or `.build()` to get the `Trajectory` object.

## Export Formats

Both Client sessions and Builder support:

```typescript
session.toMarkdown();    // Human-readable markdown
session.toJSON();        // Raw JSON data
session.toJSON(true);    // Compact JSON
session.toTimeline();    // Chronological timeline view
session.toPRSummary();   // Optimized for PR descriptions
```

## Common Mistakes

| Mistake | Fix |
|---------|-----|
| Forgetting `await client.init()` | Always call init before using client |
| Using Builder when you need persistence | Use TrajectoryClient instead |
| Not calling `client.close()` | Always close when done |
| Starting a trajectory when one is active | Complete or abandon the active one first |
| Missing `await` on session methods | Client session methods are async |

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.