agent-trajectories 0.1.0

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 (54) hide show
  1. package/.beads/.local_version +1 -0
  2. package/.beads/README.md +81 -0
  3. package/.beads/config.yaml +62 -0
  4. package/.beads/issues.jsonl +0 -0
  5. package/.beads/metadata.json +4 -0
  6. package/.gitattributes +3 -0
  7. package/IMPLEMENTATION-PROPOSAL.md +1598 -0
  8. package/PROPOSAL-trajectories.md +1582 -0
  9. package/README.md +275 -0
  10. package/biome.json +20 -0
  11. package/docs/architecture/core.md +477 -0
  12. package/docs/architecture/memory-integration.md +186 -0
  13. package/docs/architecture/web-viewer.md +213 -0
  14. package/package.json +47 -0
  15. package/src/cli/commands/abandon.ts +32 -0
  16. package/src/cli/commands/complete.ts +51 -0
  17. package/src/cli/commands/decision.ts +49 -0
  18. package/src/cli/commands/export.ts +100 -0
  19. package/src/cli/commands/index.ts +39 -0
  20. package/src/cli/commands/list.ts +90 -0
  21. package/src/cli/commands/show.ts +98 -0
  22. package/src/cli/commands/start.ts +53 -0
  23. package/src/cli/commands/status.ts +68 -0
  24. package/src/cli/index.ts +25 -0
  25. package/src/cli/runner.ts +67 -0
  26. package/src/core/id.ts +62 -0
  27. package/src/core/index.ts +54 -0
  28. package/src/core/schema.ts +272 -0
  29. package/src/core/trajectory.ts +283 -0
  30. package/src/core/types.ts +272 -0
  31. package/src/export/index.ts +10 -0
  32. package/src/export/json.ts +26 -0
  33. package/src/export/markdown.ts +216 -0
  34. package/src/export/pr-summary.ts +57 -0
  35. package/src/export/timeline.ts +69 -0
  36. package/src/index.ts +69 -0
  37. package/src/storage/file.ts +394 -0
  38. package/src/storage/index.ts +6 -0
  39. package/src/storage/interface.ts +92 -0
  40. package/src/web/generator.ts +347 -0
  41. package/src/web/index.ts +6 -0
  42. package/src/web/styles.ts +355 -0
  43. package/src/workspace/index.ts +6 -0
  44. package/src/workspace/storage.ts +231 -0
  45. package/src/workspace/types.ts +88 -0
  46. package/tests/cli/commands.test.ts +476 -0
  47. package/tests/core/trajectory.test.ts +426 -0
  48. package/tests/export/export.test.ts +376 -0
  49. package/tests/storage/storage.test.ts +410 -0
  50. package/tests/web/generator.test.ts +197 -0
  51. package/tests/workspace/storage.test.ts +275 -0
  52. package/tsconfig.json +26 -0
  53. package/tsup.config.ts +14 -0
  54. package/vitest.config.ts +15 -0
package/README.md ADDED
@@ -0,0 +1,275 @@
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
+ ### Integration Ready
34
+ - Complements [claude-mem](https://github.com/thedotmack/claude-mem) for observation-level memory
35
+ - Integrates with [agent-relay](https://github.com/khaliqgant/agent-relay) for multi-agent messaging
36
+
37
+ ## Use Cases
38
+
39
+ ### Code Review
40
+ Instead of guessing at intent from 500 changed lines, reviewers can:
41
+ - Read the trajectory summary
42
+ - See what alternatives were considered and rejected
43
+ - Understand the agent's confidence level
44
+
45
+ ### Bug Diagnosis
46
+ When a bug surfaces months later:
47
+ - Query the trajectory for the commit that introduced the code
48
+ - See original requirements and edge cases considered
49
+ - Understand the context that led to this implementation
50
+
51
+ ### Institutional Memory
52
+ Over time, trajectories become a searchable knowledge base:
53
+ - "How have we solved caching problems before?"
54
+ - "What libraries did we evaluate for X?"
55
+ - "Why did we choose this architecture?"
56
+
57
+ ## Quick Start
58
+
59
+ ```bash
60
+ # Start tracking a task
61
+ trail start "Implement auth module"
62
+
63
+ # View current status
64
+ trail status
65
+
66
+ # Record a decision (reasoning optional for minor decisions)
67
+ trail decision "Chose JWT over sessions" \
68
+ --reasoning "Stateless scaling requirements"
69
+
70
+ # Complete with retrospective
71
+ trail complete --summary "Added JWT auth" --confidence 0.85
72
+
73
+ # List all trajectories (with optional search)
74
+ trail list
75
+ trail list --search "auth"
76
+
77
+ # Export for documentation (markdown, json, timeline, or html)
78
+ trail export traj_abc123 --format markdown
79
+ trail export --format html --open # Opens in browser
80
+ ```
81
+
82
+ ## Why "Trail"?
83
+
84
+ > **Trajectory** = the complete path an agent takes through a task
85
+ > **Trail** = what's left behind for others to follow
86
+
87
+ You don't see the whole trajectory in real-time, but you can always follow the trail.
88
+
89
+ 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.
90
+
91
+ ## Who Uses Trail?
92
+
93
+ **Both agents and humans—but differently.**
94
+
95
+ ### Agents: Write the Trail
96
+
97
+ Agents use trail commands to **record** their work as they go:
98
+
99
+ ```bash
100
+ # Agent starts work on a task
101
+ trail start "Add rate limiting to API"
102
+
103
+ # Agent records key decisions as it works
104
+ trail decision "Token bucket algorithm" \
105
+ --reasoning "Better burst handling than fixed window"
106
+
107
+ # Agent completes with reflection
108
+ trail complete --summary "Added rate limiting" --confidence 0.9
109
+ ```
110
+
111
+ This can be invoked programmatically by AI coding tools, or agents can learn to call `trail` as part of their workflow.
112
+
113
+ ### Humans: Read the Trail
114
+
115
+ Humans use trail commands to **understand** and **review** agent work:
116
+
117
+ ```bash
118
+ # List and search past work
119
+ trail list --search "authentication"
120
+
121
+ # See trajectory details and decisions
122
+ trail show traj_abc123 --decisions
123
+
124
+ # View in browser
125
+ trail export traj_abc123 --format html --open
126
+
127
+ # Export for code review
128
+ trail export traj_abc123 --format markdown
129
+ ```
130
+
131
+ ### The Handoff
132
+
133
+ The trail bridges the gap between agent work and human understanding:
134
+
135
+ ```
136
+ Agent works → Records decisions → Completes trajectory
137
+
138
+ Human reviews → Follows the trail → Understands the "why"
139
+ ```
140
+
141
+ Without the trail, humans see only the code. With it, they see the reasoning.
142
+
143
+ ## Agent Workspace
144
+
145
+ Trajectories power a broader vision: **a knowledge workspace for agents**—like Notion, but for AI.
146
+
147
+ ```
148
+ ┌─────────────────────────────────────────────────────────────────┐
149
+ │ AGENT WORKSPACE │
150
+ ├─────────────────────────────────────────────────────────────────┤
151
+ │ 📚 Knowledge Base 🛤️ Trajectories │
152
+ │ ├── Architecture docs ├── Active work │
153
+ │ ├── Code patterns ├── Recent history │
154
+ │ └── Conventions └── Searchable archive │
155
+ │ │
156
+ │ 🧠 Decision Log 📋 Pattern Library │
157
+ │ └── Why things are └── How to do things │
158
+ └─────────────────────────────────────────────────────────────────┘
159
+ ```
160
+
161
+ When an agent starts a new task, it can query the workspace for:
162
+ - Relevant past trajectories
163
+ - Applicable patterns and conventions
164
+ - Related decisions
165
+ - Potential gotchas from retrospectives
166
+
167
+ ## Architecture
168
+
169
+ ```
170
+ ┌─────────────────────────────────────────────────────────────────┐
171
+ │ AGENT-TRAJECTORIES (Layer 3) │
172
+ │ Task narratives, decisions, retrospectives │
173
+ │ ▲ │
174
+ │ │ aggregates │
175
+ │ CLAUDE-MEM (Layer 2) │
176
+ │ Tool observations, semantic concepts │
177
+ │ ▲ │
178
+ │ │ captures │
179
+ │ AGENT-RELAY (Layer 1) │
180
+ │ Real-time messaging, message persistence │
181
+ └─────────────────────────────────────────────────────────────────┘
182
+ ```
183
+
184
+ Each layer is independent and can be used alone, but together they form a complete agent memory stack.
185
+
186
+ ## The Trajectory Format
187
+
188
+ ```json
189
+ {
190
+ "id": "traj_abc123",
191
+ "task": {
192
+ "title": "Implement user authentication",
193
+ "source": { "system": "linear", "id": "ENG-456" }
194
+ },
195
+ "status": "completed",
196
+ "chapters": [...],
197
+ "retrospective": {
198
+ "summary": "Implemented JWT-based auth with refresh tokens",
199
+ "decisions": [...],
200
+ "confidence": 0.85
201
+ }
202
+ }
203
+ ```
204
+
205
+ Trajectories are stored as `.trajectory.json` files (machine-readable) with auto-generated `.trajectory.md` summaries (human-readable).
206
+
207
+ ## Why Trajectories Matter
208
+
209
+ > "The trajectory is as valuable as the code."
210
+
211
+ As AI agents write more code faster than ever before, a critical gap emerges: **we're shipping code without understanding**. Trajectories close this gap.
212
+
213
+ ### The Health of Your Codebase
214
+
215
+ Without trajectories, agent-generated code becomes a black box:
216
+
217
+ | Problem | Impact | How Trajectories Help |
218
+ |---------|--------|----------------------|
219
+ | **Silent assumptions** | Bugs hide in undocumented edge cases | Decisions and reasoning are captured explicitly |
220
+ | **Inconsistent patterns** | Each agent reinvents approaches | Past solutions are queryable, patterns emerge |
221
+ | **Lost context** | Nobody knows why code exists | The "why" lives alongside the "what" |
222
+ | **Review theater** | PRs approved without real understanding | Reviewers see the full decision history |
223
+ | **Debugging blind** | Hours spent reverse-engineering intent | Original context is one query away |
224
+
225
+ ### The Flywheel Effect
226
+
227
+ Trajectories create a virtuous cycle that compounds over time:
228
+
229
+ ```
230
+ More trajectories → More extracted knowledge → Better agent context →
231
+ Better decisions → Better retrospectives → Richer trajectories → ...
232
+ ```
233
+
234
+ Each completed task makes future tasks easier:
235
+ - Agents make fewer mistakes by learning from past gotchas
236
+ - Decisions are more consistent across the codebase
237
+ - Onboarding new agents (or humans) becomes instant
238
+ - Institutional memory persists even as team members change
239
+
240
+ ### Future-Proofing Your Project
241
+
242
+ As agent usage scales, trajectories become essential infrastructure:
243
+
244
+ **Today (1-2 agents):**
245
+ - Nice to have for code review
246
+ - Helpful for debugging
247
+
248
+ **Tomorrow (5-10 agents working in parallel):**
249
+ - Critical for coordination
250
+ - Required for understanding who did what and why
251
+ - Enables agents to learn from each other
252
+
253
+ **Long-term (agents as primary contributors):**
254
+ - The authoritative record of how the system evolved
255
+ - Training data for project-specific agent improvements
256
+ - Audit trail for compliance and security review
257
+
258
+ ### Trust Through Transparency
259
+
260
+ Agent-generated code faces a trust problem. Developers hesitate to ship code they don't understand. Trajectories solve this by making agent reasoning transparent:
261
+
262
+ - **Confidence scores** tell you when to scrutinize more carefully
263
+ - **Decision logs** show trade-offs were considered
264
+ - **Retrospectives** surface known limitations and risks
265
+ - **Challenge documentation** reveals what was hard (and might break)
266
+
267
+ The result: teams can ship agent code with the same confidence as human-written code—because they understand it just as well.
268
+
269
+ ## Status
270
+
271
+ This project is in early development. See [PROPOSAL-trajectories.md](./PROPOSAL-trajectories.md) for the full design document.
272
+
273
+ ## License
274
+
275
+ MIT
package/biome.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
3
+ "organizeImports": {
4
+ "enabled": true
5
+ },
6
+ "linter": {
7
+ "enabled": true,
8
+ "rules": {
9
+ "recommended": true
10
+ }
11
+ },
12
+ "formatter": {
13
+ "enabled": true,
14
+ "indentStyle": "space",
15
+ "indentWidth": 2
16
+ },
17
+ "files": {
18
+ "ignore": ["node_modules", "dist", "*.md"]
19
+ }
20
+ }