agent-trajectories 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,9 +80,20 @@ Over time, trajectories become a searchable knowledge base:
80
80
 
81
81
  ## Quick Start
82
82
 
83
+ ### CLI
84
+
85
+ ```bash
86
+ # Install globally (trail command available directly)
87
+ npm install -g agent-trajectories
88
+
89
+ # Or install locally (requires npx prefix)
90
+ npm install agent-trajectories
91
+ ```
92
+
83
93
  ```bash
84
94
  # Start tracking a task
85
95
  trail start "Implement auth module"
96
+ # (use `npx trail start ...` if installed locally)
86
97
 
87
98
  # View current status
88
99
  trail status
@@ -103,6 +114,67 @@ trail export traj_abc123 --format markdown
103
114
  trail export --format html --open # Opens in browser
104
115
  ```
105
116
 
117
+ ### SDK
118
+
119
+ For programmatic usage, install the package and use the SDK:
120
+
121
+ ```bash
122
+ npm install agent-trajectories
123
+ ```
124
+
125
+ **Using the Client (with storage):**
126
+
127
+ ```typescript
128
+ import { TrajectoryClient } from 'agent-trajectories';
129
+
130
+ const client = new TrajectoryClient({ defaultAgent: 'my-agent' });
131
+ await client.init();
132
+
133
+ // Start a new trajectory
134
+ const session = await client.start('Implement auth module');
135
+
136
+ // Record work in chapters
137
+ await session.chapter('Research');
138
+ await session.note('Found existing auth patterns');
139
+ await session.finding('Current system uses sessions');
140
+
141
+ // Record decisions
142
+ await session.decide(
143
+ 'JWT vs Sessions?',
144
+ 'JWT',
145
+ 'Better for horizontal scaling'
146
+ );
147
+
148
+ // Complete with retrospective
149
+ await session.done('Implemented JWT-based authentication', 0.9);
150
+
151
+ await client.close();
152
+ ```
153
+
154
+ **Using the Builder (in-memory, no storage):**
155
+
156
+ ```typescript
157
+ import { trajectory } from 'agent-trajectories';
158
+
159
+ const result = trajectory('Fix login bug')
160
+ .withSource({ system: 'github', id: 'GH#456' })
161
+ .chapter('Investigation', 'claude')
162
+ .finding('Null pointer in session handler')
163
+ .decide('Fix approach', 'Add null check', 'Minimal change')
164
+ .chapter('Implementation', 'claude')
165
+ .note('Added validation')
166
+ .done('Fixed null pointer exception', 0.95);
167
+
168
+ // Export the trajectory
169
+ console.log(result); // Full trajectory object
170
+ ```
171
+
172
+ **SDK Features:**
173
+ - **Auto-save**: Changes persist automatically with the client
174
+ - **Fluent API**: Chain operations naturally
175
+ - **Resume support**: Pick up where you left off with `client.resume()`
176
+ - **Multiple exports**: Markdown, JSON, timeline, PR summary
177
+
106
178
  ## Why "Trail"?
107
179
 
108
180
  > **Trajectory** = the complete path an agent takes through a task
@@ -290,6 +362,107 @@ Agent-generated code faces a trust problem. Developers hesitate to ship code the
290
362
 
291
363
  The result: teams can ship agent code with the same confidence as human-written code—because they understand it just as well.
292
364
 
365
+ ## Installation
366
+
367
+ ```bash
368
+ npm install agent-trajectories
369
+ ```
370
+
371
+ The package provides:
372
+ - **CLI** (`trail` command) - For command-line usage
373
+ - **SDK** - For programmatic integration
374
+
375
+ ```typescript
376
+ // Main import (includes SDK)
377
+ import { TrajectoryClient, trajectory } from 'agent-trajectories';
378
+
379
+ // Or import from SDK subpath
380
+ import { TrajectoryClient, TrajectoryBuilder } from 'agent-trajectories/sdk';
381
+ ```
382
+
383
+ ## SDK Reference
384
+
385
+ ### TrajectoryClient
386
+
387
+ The client manages trajectories with persistent storage.
388
+
389
+ ```typescript
390
+ const client = new TrajectoryClient({
391
+ defaultAgent: 'my-agent', // Default agent name
392
+ dataDir: '.trajectories', // Storage directory
393
+ autoSave: true, // Auto-save after operations
394
+ });
395
+
396
+ await client.init(); // Required before use
397
+
398
+ // Lifecycle
399
+ const session = await client.start('Task title');
400
+ const session = await client.resume(); // Resume active trajectory
401
+ const traj = await client.get('traj_xxx'); // Get by ID
402
+
403
+ // Query
404
+ const list = await client.list({ status: 'completed' });
405
+ const results = await client.search('auth');
406
+
407
+ // Export
408
+ const md = await client.exportMarkdown('traj_xxx');
409
+ const json = await client.exportJSON('traj_xxx');
410
+
411
+ await client.close();
412
+ ```
413
+
414
+ ### TrajectorySession
415
+
416
+ Sessions provide chainable operations on active trajectories.
417
+
418
+ ```typescript
419
+ const session = await client.start('Task');
420
+
421
+ // Chapters organize work phases
422
+ await session.chapter('Research');
423
+ await session.chapter('Implementation');
424
+
425
+ // Events record what happened
426
+ await session.note('Observation or note');
427
+ await session.finding('Important discovery');
428
+ await session.error('Something went wrong');
429
+
430
+ // Decisions capture choices
431
+ await session.decide('Question?', 'Choice', 'Reasoning');
432
+
433
+ // Complete or abandon
434
+ await session.done('Summary of work', 0.9);
435
+ await session.abandon('Reason for abandoning');
436
+ ```
437
+
438
+ ### TrajectoryBuilder
439
+
440
+ The builder creates trajectories in memory without storage.
441
+
442
+ ```typescript
443
+ import { trajectory, TrajectoryBuilder } from 'agent-trajectories';
444
+
445
+ // Shorthand function
446
+ const t = trajectory('Task title')
447
+ .chapter('Work', 'agent-name')
448
+ .note('Did something')
449
+ .done('Completed', 0.9);
450
+
451
+ // Or use the class directly
452
+ const t = TrajectoryBuilder.create('Task')
453
+ .withDescription('Detailed description')
454
+ .withSource({ system: 'linear', id: 'ENG-123' })
455
+ .withTags('feature', 'auth')
456
+ .chapter('Phase 1', 'claude')
457
+ .complete({
458
+ summary: 'What was done',
459
+ approach: 'How it was done',
460
+ confidence: 0.85,
461
+ challenges: ['What was hard'],
462
+ learnings: ['What was learned'],
463
+ });
464
+ ```
465
+
293
466
  ## Status
294
467
 
295
468
  This project is in early development. See [PROPOSAL-trajectories.md](./PROPOSAL-trajectories.md) for the full design document.