agent-relay 4.0.18 → 4.0.20

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.
Files changed (96) hide show
  1. package/dist/index.cjs +1407 -537
  2. package/dist/src/cli/commands/setup.d.ts +28 -10
  3. package/dist/src/cli/commands/setup.d.ts.map +1 -1
  4. package/dist/src/cli/commands/setup.js +103 -68
  5. package/dist/src/cli/commands/setup.js.map +1 -1
  6. package/node_modules/@agent-relay/cloud/package.json +2 -2
  7. package/node_modules/@agent-relay/config/package.json +1 -1
  8. package/node_modules/@agent-relay/hooks/package.json +4 -4
  9. package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.d.ts +5 -35
  10. package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.d.ts.map +1 -1
  11. package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.js +158 -292
  12. package/node_modules/@agent-relay/sdk/dist/workflows/trajectory.js.map +1 -1
  13. package/node_modules/@agent-relay/sdk/package.json +3 -2
  14. package/node_modules/@agent-relay/telemetry/package.json +1 -1
  15. package/node_modules/@agent-relay/trajectory/package.json +2 -2
  16. package/node_modules/@agent-relay/user-directory/package.json +2 -2
  17. package/node_modules/@agent-relay/utils/package.json +2 -2
  18. package/node_modules/@clack/core/CHANGELOG.md +200 -0
  19. package/node_modules/@clack/core/LICENSE +9 -0
  20. package/node_modules/@clack/core/README.md +22 -0
  21. package/node_modules/@clack/core/dist/index.cjs +15 -0
  22. package/node_modules/@clack/core/dist/index.cjs.map +1 -0
  23. package/node_modules/@clack/core/dist/index.d.cts +151 -0
  24. package/node_modules/@clack/core/dist/index.d.mts +151 -0
  25. package/node_modules/@clack/core/dist/index.d.ts +151 -0
  26. package/node_modules/@clack/core/dist/index.mjs +15 -0
  27. package/node_modules/@clack/core/dist/index.mjs.map +1 -0
  28. package/node_modules/@clack/core/package.json +62 -0
  29. package/node_modules/@clack/prompts/CHANGELOG.md +256 -0
  30. package/node_modules/@clack/prompts/LICENSE +23 -0
  31. package/node_modules/@clack/prompts/README.md +158 -0
  32. package/node_modules/@clack/prompts/dist/index.cjs +77 -0
  33. package/node_modules/@clack/prompts/dist/index.d.ts +106 -0
  34. package/node_modules/@clack/prompts/dist/index.mjs +77 -0
  35. package/node_modules/@clack/prompts/node_modules/is-unicode-supported/index.d.ts +12 -0
  36. package/node_modules/@clack/prompts/node_modules/is-unicode-supported/index.js +17 -0
  37. package/node_modules/@clack/prompts/node_modules/is-unicode-supported/license +9 -0
  38. package/node_modules/@clack/prompts/node_modules/is-unicode-supported/package.json +43 -0
  39. package/node_modules/@clack/prompts/node_modules/is-unicode-supported/readme.md +35 -0
  40. package/node_modules/@clack/prompts/package.json +65 -0
  41. package/node_modules/agent-trajectories/README.md +562 -0
  42. package/node_modules/agent-trajectories/dist/chunk-W222QB6V.js +2036 -0
  43. package/node_modules/agent-trajectories/dist/chunk-W222QB6V.js.map +1 -0
  44. package/node_modules/agent-trajectories/dist/cli/index.d.ts +2 -0
  45. package/node_modules/agent-trajectories/dist/cli/index.js +4592 -0
  46. package/node_modules/agent-trajectories/dist/cli/index.js.map +1 -0
  47. package/node_modules/agent-trajectories/dist/index-7tzw_CMS.d.ts +1777 -0
  48. package/node_modules/agent-trajectories/dist/index.d.ts +90 -0
  49. package/node_modules/agent-trajectories/dist/index.js +73 -0
  50. package/node_modules/agent-trajectories/dist/index.js.map +1 -0
  51. package/node_modules/agent-trajectories/dist/sdk/index.d.ts +2 -0
  52. package/node_modules/agent-trajectories/dist/sdk/index.js +39 -0
  53. package/node_modules/agent-trajectories/dist/sdk/index.js.map +1 -0
  54. package/node_modules/agent-trajectories/package.json +72 -0
  55. package/node_modules/commander/LICENSE +22 -0
  56. package/node_modules/commander/Readme.md +1157 -0
  57. package/node_modules/commander/esm.mjs +16 -0
  58. package/node_modules/commander/index.js +24 -0
  59. package/node_modules/commander/lib/argument.js +149 -0
  60. package/node_modules/commander/lib/command.js +2509 -0
  61. package/node_modules/commander/lib/error.js +39 -0
  62. package/node_modules/commander/lib/help.js +520 -0
  63. package/node_modules/commander/lib/option.js +330 -0
  64. package/node_modules/commander/lib/suggestSimilar.js +101 -0
  65. package/node_modules/commander/package-support.json +16 -0
  66. package/node_modules/commander/package.json +84 -0
  67. package/node_modules/commander/typings/esm.d.mts +3 -0
  68. package/node_modules/commander/typings/index.d.ts +969 -0
  69. package/node_modules/follow-redirects/README.md +7 -5
  70. package/node_modules/follow-redirects/index.js +24 -1
  71. package/node_modules/follow-redirects/package.json +1 -1
  72. package/node_modules/picocolors/LICENSE +15 -0
  73. package/node_modules/picocolors/README.md +21 -0
  74. package/node_modules/picocolors/package.json +25 -0
  75. package/node_modules/picocolors/picocolors.browser.js +4 -0
  76. package/node_modules/picocolors/picocolors.d.ts +5 -0
  77. package/node_modules/picocolors/picocolors.js +75 -0
  78. package/node_modules/picocolors/types.d.ts +51 -0
  79. package/node_modules/sisteransi/license +21 -0
  80. package/node_modules/sisteransi/package.json +34 -0
  81. package/node_modules/sisteransi/readme.md +113 -0
  82. package/node_modules/sisteransi/src/index.js +58 -0
  83. package/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
  84. package/package.json +10 -10
  85. package/packages/cloud/package.json +2 -2
  86. package/packages/config/package.json +1 -1
  87. package/packages/hooks/package.json +4 -4
  88. package/packages/sdk/dist/workflows/trajectory.d.ts +5 -35
  89. package/packages/sdk/dist/workflows/trajectory.d.ts.map +1 -1
  90. package/packages/sdk/dist/workflows/trajectory.js +158 -292
  91. package/packages/sdk/dist/workflows/trajectory.js.map +1 -1
  92. package/packages/sdk/package.json +3 -2
  93. package/packages/telemetry/package.json +1 -1
  94. package/packages/trajectory/package.json +2 -2
  95. package/packages/user-directory/package.json +2 -2
  96. package/packages/utils/package.json +2 -2
@@ -0,0 +1,562 @@
1
+ # Agent Trajectories
2
+
3
+ **Capture the complete "train of thought" of agent work as first-class artifacts.**
4
+
5
+ When an agent completes a task today, the only artifacts are code changes, commit messages, and PR descriptions. The rich context of *how* the work happened disappears: why approach A was chosen over B, what dead ends were explored, what assumptions were made.
6
+
7
+ Agent Trajectories captures this missing context as structured, searchable, portable records that travel with the code.
8
+
9
+ ## What is a Trajectory?
10
+
11
+ A **trajectory** is the complete story of agent work on a task:
12
+
13
+ - **Chapters** - Logical segments of work (exploration, implementation, testing)
14
+ - **Events** - Prompts, tool calls, decisions, messages between agents
15
+ - **Retrospective** - Agent reflection on what was accomplished, challenges faced, and lessons learned
16
+ - **Artifacts** - Links to commits, files changed, and external task references
17
+
18
+ ## Key Features
19
+
20
+ ### Platform Agnostic
21
+ Works with any task system: Beads, Linear, Jira, GitHub Issues, or standalone. Trajectories are a universal format—like Markdown for documentation.
22
+
23
+ ### Multiple Storage Backends
24
+ - **File system** (default) - `.trajectories/` directory, git-friendly
25
+ - **SQLite** - Local indexing and search
26
+ - **PostgreSQL/S3** - For teams and archival
27
+
28
+ ### Rich Export Formats
29
+ - **Markdown** - Notion-style pages for documentation
30
+ - **Timeline** - Linear-style chronological view
31
+ - **JSON** - Full structured data for tooling
32
+
33
+ ### Native Multi-Agent Support
34
+
35
+ Trajectories is built for teams of agents working together:
36
+
37
+ - **Shared trajectory** — Multiple agents collaborate on a single task record
38
+ - **Agent participation** — Each agent logged as lead, contributor, or reviewer with timestamps
39
+ - **Chapter handoffs** — When work moves between agents, chapters capture the context shift
40
+ - **Cross-agent messaging** — Integrates with [agent-relay](https://github.com/khaliqgant/agent-relay) to record inter-agent communication as trajectory events
41
+ - **Parallel coordination** — Multiple agents working in parallel on related tasks can reference each other's trajectories
42
+
43
+ This is a key differentiator: no other tool in the AI dev stack tracks *who* (which agent, which model) made *which decisions* and *why*, across a coordinated multi-agent workflow.
44
+
45
+ ### Integration Ready
46
+ - Complements [claude-mem](https://github.com/thedotmack/claude-mem) for observation-level memory
47
+ - Integrates with [agent-relay](https://github.com/khaliqgant/agent-relay) for multi-agent messaging
48
+ - **Agent Trace integration** - Automatic code attribution following [agent-trace.dev](https://agent-trace.dev) spec
49
+
50
+ ### Code Attribution (Agent Trace)
51
+
52
+ Trajectories automatically generate [Agent Trace](https://agent-trace.dev) records that attribute code changes to AI agents:
53
+
54
+ ```bash
55
+ trail start "Implement auth module"
56
+ # ... agent writes code, makes commits ...
57
+ trail complete --summary "Added JWT auth" --confidence 0.85
58
+
59
+ # View trace attribution
60
+ trail show traj_abc123 --trace
61
+ ```
62
+
63
+ **What you get:**
64
+ - `.trace.json` files saved alongside each trajectory
65
+ - Line-level attribution of which code was AI-generated
66
+ - Model identification (Claude, GPT, etc.)
67
+ - Git revision tracking for change history
68
+
69
+ **Zero configuration required** - traces are generated automatically when completing trajectories in a git repository.
70
+
71
+ See the full [Agent Trace Integration Spec](./docs/specs/agent-trace-integration.md) for details.
72
+
73
+ ## Use Cases
74
+
75
+ ### Code Review
76
+ Instead of guessing at intent from 500 changed lines, reviewers can:
77
+ - Read the trajectory summary
78
+ - See what alternatives were considered and rejected
79
+ - Understand the agent's confidence level
80
+
81
+ ### Bug Diagnosis
82
+ When a bug surfaces months later:
83
+ - Query the trajectory for the commit that introduced the code
84
+ - See original requirements and edge cases considered
85
+ - Understand the context that led to this implementation
86
+
87
+ ### Institutional Memory
88
+ Over time, trajectories become a searchable knowledge base:
89
+ - "How have we solved caching problems before?"
90
+ - "What libraries did we evaluate for X?"
91
+ - "Why did we choose this architecture?"
92
+
93
+ ## Quick Start
94
+
95
+ ### CLI
96
+
97
+ ```bash
98
+ # Install globally (trail command available directly)
99
+ npm install -g agent-trajectories
100
+
101
+ # Or install locally (requires npx prefix)
102
+ npm install agent-trajectories
103
+ ```
104
+
105
+ ```bash
106
+ # Start tracking a task
107
+ trail start "Implement auth module"
108
+ # (use `npx trail start ...` if installed locally)
109
+
110
+ # View current status
111
+ trail status
112
+
113
+ # Record a decision (reasoning optional for minor decisions)
114
+ trail decision "Chose JWT over sessions" \
115
+ --reasoning "Stateless scaling requirements"
116
+
117
+ # Complete with retrospective
118
+ trail complete --summary "Added JWT auth" --confidence 0.85
119
+
120
+ # List all trajectories (with optional search)
121
+ trail list
122
+ trail list --search "auth"
123
+
124
+ # Export for documentation (markdown, json, timeline, or html)
125
+ trail export traj_abc123 --format markdown
126
+ trail export --format html --open # Opens in browser
127
+
128
+ # Compact trajectories (consolidate similar decisions)
129
+ trail compact # Uncompacted trajectories (default)
130
+ trail compact --branch main # Trajectories with commits not in main
131
+ trail compact --commits abc1234,def5678 # Trajectories matching specific commit SHAs
132
+ trail compact --pr 123 # Trajectories mentioning PR #123
133
+ trail compact --since 7d # Last 7 days
134
+ trail compact --all # Everything (including previously compacted)
135
+ ```
136
+
137
+ ### Automatic Compaction (GitHub Action)
138
+
139
+ Add these steps to any workflow that runs on PR merge (e.g., your release or publish flow). Requires `ref: ${{ github.event.pull_request.base.ref }}` and `fetch-depth: 0` on checkout, plus `contents: write` permission:
140
+
141
+ ```yaml
142
+ - name: Compact trajectories
143
+ run: |
144
+ PR_COMMITS=$(git log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} --format=%H | paste -sd, -)
145
+ OUTPUT=".trajectories/compacted/pr-${{ github.event.pull_request.number }}.json"
146
+ if [ -n "$PR_COMMITS" ]; then
147
+ npx agent-trajectories compact --commits "$PR_COMMITS" --output "$OUTPUT"
148
+ else
149
+ npx agent-trajectories compact --pr ${{ github.event.pull_request.number }} --output "$OUTPUT"
150
+ fi
151
+ - name: Commit compacted trajectories
152
+ run: |
153
+ git add .trajectories/compacted/ || true
154
+ git diff --cached --quiet || \
155
+ (git commit -m "chore: compact trajectories for PR #${{ github.event.pull_request.number }}" && git push)
156
+ ```
157
+
158
+ ### SDK
159
+
160
+ For programmatic usage, install the package and use the SDK:
161
+
162
+ ```bash
163
+ npm install agent-trajectories
164
+ ```
165
+
166
+ **Using the Client (with storage):**
167
+
168
+ ```typescript
169
+ import { TrajectoryClient } from 'agent-trajectories';
170
+
171
+ const client = new TrajectoryClient({ defaultAgent: 'my-agent' });
172
+ await client.init();
173
+
174
+ // Start a new trajectory
175
+ const session = await client.start('Implement auth module');
176
+
177
+ // Record work in chapters
178
+ await session.chapter('Research');
179
+ await session.note('Found existing auth patterns');
180
+ await session.finding('Current system uses sessions');
181
+
182
+ // Record decisions
183
+ await session.decide(
184
+ 'JWT vs Sessions?',
185
+ 'JWT',
186
+ 'Better for horizontal scaling'
187
+ );
188
+
189
+ // Complete with retrospective
190
+ await session.done('Implemented JWT-based authentication', 0.9);
191
+
192
+ await client.close();
193
+ ```
194
+
195
+ **Using the Builder (in-memory, no storage):**
196
+
197
+ ```typescript
198
+ import { trajectory } from 'agent-trajectories';
199
+
200
+ const result = trajectory('Fix login bug')
201
+ .withSource({ system: 'github', id: 'GH#456' })
202
+ .chapter('Investigation', 'claude')
203
+ .finding('Null pointer in session handler')
204
+ .decide('Fix approach', 'Add null check', 'Minimal change')
205
+ .chapter('Implementation', 'claude')
206
+ .note('Added validation')
207
+ .done('Fixed null pointer exception', 0.95);
208
+
209
+ // Export the trajectory
210
+ console.log(result); // Full trajectory object
211
+ ```
212
+
213
+ **SDK Features:**
214
+ - **Auto-save**: Changes persist automatically with the client
215
+ - **Fluent API**: Chain operations naturally
216
+ - **Resume support**: Pick up where you left off with `client.resume()`
217
+ - **Multiple exports**: Markdown, JSON, timeline, PR summary
218
+
219
+ ## Why "Trail"?
220
+
221
+ > **Trajectory** = the complete path an agent takes through a task
222
+ > **Trail** = what's left behind for others to follow
223
+
224
+ You don't see the whole trajectory in real-time, but you can always follow the trail.
225
+
226
+ The CLI is called `trail` because that's what you're doing—leaving a trail of breadcrumbs through your work. Future agents and humans can follow this trail to understand not just *what* was built, but *why* it was built that way.
227
+
228
+ ## Who Uses Trail?
229
+
230
+ **Both agents and humans—but differently.**
231
+
232
+ ### Agents: Write the Trail
233
+
234
+ Agents use trail commands to **record** their work as they go:
235
+
236
+ ```bash
237
+ # Agent starts work on a task
238
+ trail start "Add rate limiting to API"
239
+
240
+ # Agent records key decisions as it works
241
+ trail decision "Token bucket algorithm" \
242
+ --reasoning "Better burst handling than fixed window"
243
+
244
+ # Agent completes with reflection
245
+ trail complete --summary "Added rate limiting" --confidence 0.9
246
+ ```
247
+
248
+ This can be invoked programmatically by AI coding tools, or agents can learn to call `trail` as part of their workflow.
249
+
250
+ ### Humans: Read the Trail
251
+
252
+ Humans use trail commands to **understand** and **review** agent work:
253
+
254
+ ```bash
255
+ # List and search past work
256
+ trail list --search "authentication"
257
+
258
+ # See trajectory details and decisions
259
+ trail show traj_abc123 --decisions
260
+
261
+ # View in browser
262
+ trail export traj_abc123 --format html --open
263
+
264
+ # Export for code review
265
+ trail export traj_abc123 --format markdown
266
+ ```
267
+
268
+ ### The Handoff
269
+
270
+ The trail bridges the gap between agent work and human understanding:
271
+
272
+ ```
273
+ Agent works → Records decisions → Completes trajectory
274
+
275
+ Human reviews → Follows the trail → Understands the "why"
276
+ ```
277
+
278
+ Without the trail, humans see only the code. With it, they see the reasoning.
279
+
280
+ ## Agent Workspace
281
+
282
+ Trajectories power a broader vision: **a knowledge workspace for agents**—like Notion, but for AI.
283
+
284
+ ```
285
+ ┌─────────────────────────────────────────────────────────────────┐
286
+ │ AGENT WORKSPACE │
287
+ ├─────────────────────────────────────────────────────────────────┤
288
+ │ 📚 Knowledge Base 🛤️ Trajectories │
289
+ │ ├── Architecture docs ├── Active work │
290
+ │ ├── Code patterns ├── Recent history │
291
+ │ └── Conventions └── Searchable archive │
292
+ │ │
293
+ │ 🧠 Decision Log 📋 Pattern Library │
294
+ │ └── Why things are └── How to do things │
295
+ └─────────────────────────────────────────────────────────────────┘
296
+ ```
297
+
298
+ When an agent starts a new task, it can query the workspace for:
299
+ - Relevant past trajectories
300
+ - Applicable patterns and conventions
301
+ - Related decisions
302
+ - Potential gotchas from retrospectives
303
+
304
+ ## Architecture
305
+
306
+ ```
307
+ ┌─────────────────────────────────────────────────────────────────┐
308
+ │ AGENT-TRAJECTORIES (Layer 3) │
309
+ │ Task narratives, decisions, retrospectives │
310
+ │ ▲ │
311
+ │ │ aggregates │
312
+ │ CLAUDE-MEM (Layer 2) │
313
+ │ Tool observations, semantic concepts │
314
+ │ ▲ │
315
+ │ │ captures │
316
+ │ AGENT-RELAY (Layer 1) │
317
+ │ Real-time messaging, message persistence │
318
+ └─────────────────────────────────────────────────────────────────┘
319
+ ```
320
+
321
+ Each layer is independent and can be used alone, but together they form a complete agent memory stack.
322
+
323
+ ## The Narrative Layer in Your AI Stack
324
+
325
+ Trajectories sits at the top of an emerging ecosystem of AI development tools. Each layer answers a different question:
326
+
327
+ ```
328
+ ┌─────────────────────────────────────────────────────────────────┐
329
+ │ AGENT-TRAJECTORIES │
330
+ │ "Why was this built this way?" │
331
+ │ Narrative, decisions, retrospectives, institutional memory │
332
+ │ ▲ │
333
+ │ │ gives meaning to │
334
+ │ ENTIRE (entireio/cli) │
335
+ │ "What happened in this session?" │
336
+ │ Raw session capture, transcripts, recovery, rewind │
337
+ │ ▲ │
338
+ │ │ attributes │
339
+ │ AGENT-TRACE (agent-trace.dev) │
340
+ │ "Who wrote this line of code?" │
341
+ │ Line-level code attribution, model identification │
342
+ └─────────────────────────────────────────────────────────────────┘
343
+ ```
344
+
345
+ **Agent Trace** ([agent-trace.dev](https://agent-trace.dev)) is the attribution spec — trajectories implements it automatically, generating `.trace.json` files that comply with the spec on every `trail complete`.
346
+
347
+ **Entire** ([entireio/cli](https://github.com/entireio/cli)) captures raw session transcripts via git hooks — a complementary layer focused on recovery and rewind.
348
+
349
+ **Trajectories** is the narrative layer: structured meaning on top of raw events. Where entire captures *what happened*, trajectories captures *why decisions were made* and *what was learned*. Where agent-trace says *who wrote the code*, trajectories explains *why this approach was chosen*.
350
+
351
+ Used together, these tools give you a complete audit trail of AI-assisted development from attribution through narrative.
352
+
353
+ ## The Trajectory Format
354
+
355
+ ```json
356
+ {
357
+ "id": "traj_abc123",
358
+ "task": {
359
+ "title": "Implement user authentication",
360
+ "source": { "system": "linear", "id": "ENG-456" }
361
+ },
362
+ "status": "completed",
363
+ "chapters": [...],
364
+ "retrospective": {
365
+ "summary": "Implemented JWT-based auth with refresh tokens",
366
+ "decisions": [...],
367
+ "confidence": 0.85
368
+ }
369
+ }
370
+ ```
371
+
372
+ Trajectories are stored as `.trajectory.json` files (machine-readable) with auto-generated `.trajectory.md` summaries (human-readable).
373
+
374
+ ## Why Trajectories Matter
375
+
376
+ > "The trajectory is as valuable as the code."
377
+
378
+ As AI agents write more code faster than ever before, a critical gap emerges: **we're shipping code without understanding**. Trajectories close this gap.
379
+
380
+ ### The Health of Your Codebase
381
+
382
+ Without trajectories, agent-generated code becomes a black box:
383
+
384
+ | Problem | Impact | How Trajectories Help |
385
+ |---------|--------|----------------------|
386
+ | **Silent assumptions** | Bugs hide in undocumented edge cases | Decisions and reasoning are captured explicitly |
387
+ | **Inconsistent patterns** | Each agent reinvents approaches | Past solutions are queryable, patterns emerge |
388
+ | **Lost context** | Nobody knows why code exists | The "why" lives alongside the "what" |
389
+ | **Review theater** | PRs approved without real understanding | Reviewers see the full decision history |
390
+ | **Debugging blind** | Hours spent reverse-engineering intent | Original context is one query away |
391
+
392
+ ### The Flywheel Effect
393
+
394
+ Trajectories create a virtuous cycle that compounds over time:
395
+
396
+ ```
397
+ More trajectories → More extracted knowledge → Better agent context →
398
+ Better decisions → Better retrospectives → Richer trajectories → ...
399
+ ```
400
+
401
+ Each completed task makes future tasks easier:
402
+ - Agents make fewer mistakes by learning from past gotchas
403
+ - Decisions are more consistent across the codebase
404
+ - Onboarding new agents (or humans) becomes instant
405
+ - Institutional memory persists even as team members change
406
+
407
+ ### Future-Proofing Your Project
408
+
409
+ As agent usage scales, trajectories become essential infrastructure:
410
+
411
+ **Today (1-2 agents):**
412
+ - Nice to have for code review
413
+ - Helpful for debugging
414
+
415
+ **Tomorrow (5-10 agents working in parallel):**
416
+ - Critical for coordination
417
+ - Required for understanding who did what and why
418
+ - Enables agents to learn from each other
419
+
420
+ **Long-term (agents as primary contributors):**
421
+ - The authoritative record of how the system evolved
422
+ - Training data for project-specific agent improvements
423
+ - Audit trail for compliance and security review
424
+
425
+ ### Trust Through Transparency
426
+
427
+ Agent-generated code faces a trust problem. Developers hesitate to ship code they don't understand. Trajectories solve this by making agent reasoning transparent:
428
+
429
+ - **Confidence scores** tell you when to scrutinize more carefully
430
+ - **Decision logs** show trade-offs were considered
431
+ - **Retrospectives** surface known limitations and risks
432
+ - **Challenge documentation** reveals what was hard (and might break)
433
+
434
+ The result: teams can ship agent code with the same confidence as human-written code—because they understand it just as well.
435
+
436
+ ## Installation
437
+
438
+ ```bash
439
+ npm install agent-trajectories
440
+ ```
441
+
442
+ The package provides:
443
+ - **CLI** (`trail` command) - For command-line usage
444
+ - **SDK** - For programmatic integration
445
+
446
+ ```typescript
447
+ // Main import (includes SDK)
448
+ import { TrajectoryClient, trajectory } from 'agent-trajectories';
449
+
450
+ // Or import from SDK subpath
451
+ import { TrajectoryClient, TrajectoryBuilder } from 'agent-trajectories/sdk';
452
+ ```
453
+
454
+ ## SDK Reference
455
+
456
+ ### TrajectoryClient
457
+
458
+ The client manages trajectories with persistent storage.
459
+
460
+ ```typescript
461
+ const client = new TrajectoryClient({
462
+ defaultAgent: 'my-agent', // Default agent name
463
+ dataDir: '.trajectories', // Storage directory
464
+ autoSave: true, // Auto-save after operations
465
+ });
466
+
467
+ await client.init(); // Required before use
468
+
469
+ // Lifecycle
470
+ const session = await client.start('Task title');
471
+ const session = await client.resume(); // Resume active trajectory
472
+ const traj = await client.get('traj_xxx'); // Get by ID
473
+
474
+ // Query
475
+ const list = await client.list({ status: 'completed' });
476
+ const results = await client.search('auth');
477
+
478
+ // Export
479
+ const md = await client.exportMarkdown('traj_xxx');
480
+ const json = await client.exportJSON('traj_xxx');
481
+
482
+ await client.close();
483
+ ```
484
+
485
+ ### TrajectorySession
486
+
487
+ Sessions provide chainable operations on active trajectories.
488
+
489
+ ```typescript
490
+ const session = await client.start('Task');
491
+
492
+ // Chapters organize work phases
493
+ await session.chapter('Research');
494
+ await session.chapter('Implementation');
495
+
496
+ // Events record what happened
497
+ await session.note('Observation or note');
498
+ await session.finding('Important discovery');
499
+ await session.error('Something went wrong');
500
+
501
+ // Decisions capture choices
502
+ await session.decide('Question?', 'Choice', 'Reasoning');
503
+
504
+ // Complete or abandon
505
+ await session.done('Summary of work', 0.9);
506
+ await session.abandon('Reason for abandoning');
507
+ ```
508
+
509
+ ### TrajectoryBuilder
510
+
511
+ The builder creates trajectories in memory without storage.
512
+
513
+ ```typescript
514
+ import { trajectory, TrajectoryBuilder } from 'agent-trajectories';
515
+
516
+ // Shorthand function
517
+ const t = trajectory('Task title')
518
+ .chapter('Work', 'agent-name')
519
+ .note('Did something')
520
+ .done('Completed', 0.9);
521
+
522
+ // Or use the class directly
523
+ const t = TrajectoryBuilder.create('Task')
524
+ .withDescription('Detailed description')
525
+ .withSource({ system: 'linear', id: 'ENG-123' })
526
+ .withTags('feature', 'auth')
527
+ .chapter('Phase 1', 'claude')
528
+ .complete({
529
+ summary: 'What was done',
530
+ approach: 'How it was done',
531
+ confidence: 0.85,
532
+ challenges: ['What was hard'],
533
+ learnings: ['What was learned'],
534
+ });
535
+ ```
536
+
537
+ ## Roadmap
538
+
539
+ This project is in early development. See [PROPOSAL-trajectories.md](./PROPOSAL-trajectories.md) for the full design document.
540
+
541
+ **v1.0 (current)**
542
+ - [x] File-based storage (`.trajectories/`)
543
+ - [x] Core CLI commands (`start`, `decision`, `complete`, `list`, `show`, `export`)
544
+ - [x] Agent Trace spec compliance (`.trace.json` generation)
545
+ - [x] Multi-agent participation tracking
546
+ - [x] Rich export formats (Markdown, JSON, Timeline, HTML)
547
+
548
+ **v1.1 (next)**
549
+ - [ ] **MCP server** — Real-time bidirectional queries so Claude Code, Cursor, and other tools can read and write trajectories directly within agent sessions
550
+ - [ ] **Claude Code hooks** — Auto-capture on `PostToolUse` and session boundaries
551
+ - [ ] **SQLite storage** — Full-text search across all trajectories
552
+ - [ ] **Git hook integration** — Auto-start/complete trajectories on commit events
553
+ - [ ] **`CLAUDE.md` generation** — Extract patterns from trajectories into reusable context files
554
+
555
+ **Future**
556
+ - Workspace knowledge base (decisions, patterns, conventions as queryable memory)
557
+ - PostgreSQL/S3 storage for teams
558
+ - Training data export for project-specific model fine-tuning
559
+
560
+ ## License
561
+
562
+ MIT