groundswell 0.0.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.
Files changed (120) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.claude/system_prompts/task-breakdown.md +100 -0
  3. package/PRPs/001-hierarchical-workflow-engine.md +2438 -0
  4. package/PRPs/PRDs/001-hierarchical-workflow-engine.md +543 -0
  5. package/PRPs/PRDs/002-agent-prompt.md +390 -0
  6. package/PRPs/PRDs/003-agent-prompt.md +943 -0
  7. package/PRPs/PRDs/004-agent-prompt.md +1136 -0
  8. package/PRPs/PRDs/tasks-001.json +492 -0
  9. package/PRPs/README.md +83 -0
  10. package/PRPs/templates/prp_base.md +222 -0
  11. package/README.md +218 -0
  12. package/docs/agent.md +422 -0
  13. package/docs/prompt.md +419 -0
  14. package/docs/workflow.md +600 -0
  15. package/examples/README.md +244 -0
  16. package/examples/examples/01-basic-workflow.ts +100 -0
  17. package/examples/examples/02-decorator-options.ts +217 -0
  18. package/examples/examples/03-parent-child.ts +241 -0
  19. package/examples/examples/04-observers-debugger.ts +340 -0
  20. package/examples/examples/05-error-handling.ts +387 -0
  21. package/examples/examples/06-concurrent-tasks.ts +352 -0
  22. package/examples/examples/07-agent-loops.ts +432 -0
  23. package/examples/examples/08-sdk-features.ts +667 -0
  24. package/examples/examples/09-reflection.ts +573 -0
  25. package/examples/examples/10-introspection.ts +550 -0
  26. package/examples/index.ts +143 -0
  27. package/examples/utils/helpers.ts +57 -0
  28. package/llms_full.txt +5890 -0
  29. package/package.json +63 -0
  30. package/plan/P1P2/PRP.md +527 -0
  31. package/plan/P1P2/research/LRU_CACHE_BEST_PRACTICES.md +1929 -0
  32. package/plan/P1P2/research/LRU_CACHE_CODE_PATTERNS.md +857 -0
  33. package/plan/P1P2/research/LRU_CACHE_INTEGRATION_GUIDE.md +738 -0
  34. package/plan/P1P2/research/LRU_CACHE_RESEARCH_INDEX.md +424 -0
  35. package/plan/P1P2/research/REFLECTION_INDEX.md +291 -0
  36. package/plan/P1P2/research/REFLECTION_RESEARCH_REPORT.md +1342 -0
  37. package/plan/P1P2/research/RESEARCH_SUMMARY.md +342 -0
  38. package/plan/P1P2/research/anthropic-sdk.md +174 -0
  39. package/plan/P1P2/research/async-local-storage.md +200 -0
  40. package/plan/P1P2/research/reflection-code-patterns.md +1205 -0
  41. package/plan/P1P2/research/reflection-decision-matrix.md +421 -0
  42. package/plan/P1P2/research/reflection-implementation-guide.md +1341 -0
  43. package/plan/P1P2/research/reflection-integration-guide.md +834 -0
  44. package/plan/P1P2/research/reflection-patterns.md +1468 -0
  45. package/plan/P1P2/research/reflection-quick-reference.md +558 -0
  46. package/plan/P1P2/research/zod-schema.md +152 -0
  47. package/plan/P3P4/PRP.md +1388 -0
  48. package/plan/P3P4/research/caching-lru.md +116 -0
  49. package/plan/P3P4/research/introspection-tools.md +177 -0
  50. package/plan/P3P4/research/reflection-patterns.md +117 -0
  51. package/plan/P4P5/PRP.md +1136 -0
  52. package/plan/P4P5/research/RESEARCH_SUMMARY.md +151 -0
  53. package/plan/architecture/external_deps.md +358 -0
  54. package/plan/architecture/system_context.md +242 -0
  55. package/plan/backlog.json +867 -0
  56. package/plan/research/INTROSPECTION_RESEARCH_SUMMARY.md +378 -0
  57. package/plan/research/README-INTROSPECTION.md +352 -0
  58. package/plan/research/agent-introspection-patterns.md +1085 -0
  59. package/plan/research/introspection-security-guide.md +928 -0
  60. package/plan/research/introspection-tool-examples.md +875 -0
  61. package/scripts/generate-llms-full.ts +206 -0
  62. package/src/__tests__/integration/agent-workflow.test.ts +256 -0
  63. package/src/__tests__/integration/tree-mirroring.test.ts +114 -0
  64. package/src/__tests__/unit/agent.test.ts +169 -0
  65. package/src/__tests__/unit/cache-key.test.ts +182 -0
  66. package/src/__tests__/unit/cache.test.ts +172 -0
  67. package/src/__tests__/unit/context.test.ts +138 -0
  68. package/src/__tests__/unit/decorators.test.ts +100 -0
  69. package/src/__tests__/unit/introspection-tools.test.ts +277 -0
  70. package/src/__tests__/unit/prompt.test.ts +135 -0
  71. package/src/__tests__/unit/reflection.test.ts +210 -0
  72. package/src/__tests__/unit/tree-debugger.test.ts +85 -0
  73. package/src/__tests__/unit/workflow.test.ts +81 -0
  74. package/src/cache/cache-key.ts +244 -0
  75. package/src/cache/cache.ts +236 -0
  76. package/src/cache/index.ts +8 -0
  77. package/src/core/agent.ts +573 -0
  78. package/src/core/context.ts +119 -0
  79. package/src/core/event-tree.ts +260 -0
  80. package/src/core/factory.ts +123 -0
  81. package/src/core/index.ts +17 -0
  82. package/src/core/logger.ts +87 -0
  83. package/src/core/mcp-handler.ts +184 -0
  84. package/src/core/prompt.ts +150 -0
  85. package/src/core/workflow-context.ts +349 -0
  86. package/src/core/workflow.ts +302 -0
  87. package/src/debugger/index.ts +1 -0
  88. package/src/debugger/tree-debugger.ts +210 -0
  89. package/src/decorators/index.ts +3 -0
  90. package/src/decorators/observed-state.ts +95 -0
  91. package/src/decorators/step.ts +139 -0
  92. package/src/decorators/task.ts +96 -0
  93. package/src/examples/index.ts +2 -0
  94. package/src/examples/tdd-orchestrator.ts +65 -0
  95. package/src/examples/test-cycle-workflow.ts +64 -0
  96. package/src/index.ts +140 -0
  97. package/src/reflection/index.ts +5 -0
  98. package/src/reflection/reflection.ts +407 -0
  99. package/src/tools/index.ts +36 -0
  100. package/src/tools/introspection.ts +464 -0
  101. package/src/types/agent.ts +90 -0
  102. package/src/types/decorators.ts +25 -0
  103. package/src/types/error-strategy.ts +13 -0
  104. package/src/types/error.ts +20 -0
  105. package/src/types/events.ts +74 -0
  106. package/src/types/index.ts +55 -0
  107. package/src/types/logging.ts +24 -0
  108. package/src/types/observer.ts +18 -0
  109. package/src/types/prompt.ts +40 -0
  110. package/src/types/reflection.ts +117 -0
  111. package/src/types/sdk-primitives.ts +128 -0
  112. package/src/types/snapshot.ts +14 -0
  113. package/src/types/workflow-context.ts +163 -0
  114. package/src/types/workflow.ts +37 -0
  115. package/src/utils/id.ts +11 -0
  116. package/src/utils/index.ts +3 -0
  117. package/src/utils/observable.ts +77 -0
  118. package/tasks.json +0 -0
  119. package/tsconfig.json +22 -0
  120. package/vitest.config.ts +16 -0
@@ -0,0 +1,222 @@
1
+ # PRP Template: {Feature Name}
2
+
3
+ > **PRP**: Product Requirements Package - A comprehensive implementation guide enabling one-pass success
4
+
5
+ ## Pre-Implementation Checklist
6
+
7
+ Before implementing, verify you have:
8
+ - [ ] Read and understood this entire PRP
9
+ - [ ] Access to all referenced files and documentation
10
+ - [ ] Development environment properly configured
11
+ - [ ] Understanding of existing codebase patterns
12
+
13
+ ---
14
+
15
+ ## 1. Goal
16
+
17
+ ### Feature Goal
18
+ {One clear sentence describing what this feature accomplishes}
19
+
20
+ ### Deliverable
21
+ {Concrete, measurable output - what files/functionality will exist when done}
22
+
23
+ ### Success Definition
24
+ {How to verify the feature works correctly - specific criteria}
25
+
26
+ ---
27
+
28
+ ## 2. Context
29
+
30
+ ### External Documentation
31
+ ```yaml
32
+ primary_docs:
33
+ - url: "{documentation_url}#specific-section"
34
+ purpose: "{what to learn from this}"
35
+ key_sections:
36
+ - "{section name}"
37
+
38
+ reference_implementations:
39
+ - url: "{github_url}"
40
+ purpose: "{what patterns to follow}"
41
+ files_to_study:
42
+ - "{specific file path}"
43
+ ```
44
+
45
+ ### Codebase Context
46
+ ```yaml
47
+ existing_patterns:
48
+ - file: "{path/to/file.ts}"
49
+ pattern: "{pattern name}"
50
+ follow_for: "{what aspect to replicate}"
51
+
52
+ related_files:
53
+ - path: "{path/to/related.ts}"
54
+ relationship: "{how it relates to this feature}"
55
+
56
+ naming_conventions:
57
+ files: "{convention description}"
58
+ classes: "{convention description}"
59
+ functions: "{convention description}"
60
+ ```
61
+
62
+ ### Technical Constraints
63
+ ```yaml
64
+ typescript:
65
+ version: "{minimum version}"
66
+ config_requirements:
67
+ - "{specific tsconfig setting}"
68
+
69
+ dependencies:
70
+ required:
71
+ - name: "{package name}"
72
+ version: "{version range}"
73
+ purpose: "{why needed}"
74
+ avoid:
75
+ - name: "{package to avoid}"
76
+ reason: "{why to avoid}"
77
+
78
+ runtime:
79
+ node_version: "{minimum version}"
80
+ target: "{ES target}"
81
+ ```
82
+
83
+ ### Known Gotchas
84
+ ```yaml
85
+ pitfalls:
86
+ - issue: "{description of common mistake}"
87
+ solution: "{how to avoid/fix}"
88
+
89
+ - issue: "{another common mistake}"
90
+ solution: "{how to avoid/fix}"
91
+ ```
92
+
93
+ ---
94
+
95
+ ## 3. Implementation Tasks
96
+
97
+ > Tasks are ordered by dependency. Complete each task fully before moving to the next.
98
+
99
+ ### Task 1: {Task Name}
100
+ **Depends on**: None (or list dependencies)
101
+
102
+ **Input**: {What you need before starting}
103
+
104
+ **Steps**:
105
+ 1. {Specific action with exact file names}
106
+ 2. {Next action}
107
+ 3. {Continue...}
108
+
109
+ **Output**: {What should exist when done}
110
+
111
+ **Validation**: {How to verify this task is complete}
112
+
113
+ ---
114
+
115
+ ### Task 2: {Task Name}
116
+ **Depends on**: Task 1
117
+
118
+ **Input**: {What you need}
119
+
120
+ **Steps**:
121
+ 1. {Actions}
122
+
123
+ **Output**: {Results}
124
+
125
+ **Validation**: {Verification steps}
126
+
127
+ ---
128
+
129
+ {Continue with additional tasks...}
130
+
131
+ ---
132
+
133
+ ## 4. Implementation Details
134
+
135
+ ### Code Patterns to Follow
136
+
137
+ ```typescript
138
+ // Example pattern with annotations
139
+ {code example showing the pattern to follow}
140
+ ```
141
+
142
+ ### File Structure
143
+ ```
144
+ {directory structure showing where files should be created}
145
+ ```
146
+
147
+ ### Interface Definitions
148
+ ```typescript
149
+ // Key interfaces that must be implemented
150
+ {interface definitions}
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 5. Testing Strategy
156
+
157
+ ### Unit Tests
158
+ ```yaml
159
+ test_files:
160
+ - path: "{test file path}"
161
+ covers:
162
+ - "{what it tests}"
163
+
164
+ test_patterns:
165
+ - "{describe the testing pattern to follow}"
166
+ ```
167
+
168
+ ### Integration Tests
169
+ ```yaml
170
+ scenarios:
171
+ - name: "{test scenario}"
172
+ validates: "{what it validates}"
173
+ ```
174
+
175
+ ### Manual Validation
176
+ ```yaml
177
+ steps:
178
+ - action: "{what to do}"
179
+ expected: "{expected result}"
180
+ ```
181
+
182
+ ---
183
+
184
+ ## 6. Final Validation Checklist
185
+
186
+ ### Code Quality
187
+ - [ ] All TypeScript compiles without errors
188
+ - [ ] No linting warnings
189
+ - [ ] Follows existing code patterns
190
+ - [ ] Proper error handling
191
+
192
+ ### Functionality
193
+ - [ ] {Specific functional requirement}
194
+ - [ ] {Another requirement}
195
+
196
+ ### Testing
197
+ - [ ] Unit tests pass
198
+ - [ ] Integration tests pass
199
+ - [ ] Manual validation complete
200
+
201
+ ### Documentation
202
+ - [ ] Code is self-documenting with clear names
203
+ - [ ] Complex logic has comments
204
+ - [ ] Public APIs have JSDoc
205
+
206
+ ---
207
+
208
+ ## 7. "No Prior Knowledge" Test
209
+
210
+ **Validation**: If someone knew nothing about this codebase, would they have everything needed to implement this successfully using only this PRP?
211
+
212
+ - [ ] All file paths are absolute and specific
213
+ - [ ] All patterns have concrete examples
214
+ - [ ] All dependencies are explicitly listed
215
+ - [ ] All validation steps are executable
216
+ - [ ] No assumed knowledge of codebase internals
217
+
218
+ ---
219
+
220
+ ## Confidence Score: {X}/10
221
+
222
+ **Rationale**: {Brief explanation of confidence level and any remaining uncertainties}
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # Groundswell
2
+
3
+ Hierarchical workflow orchestration engine with full observability.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install groundswell
9
+ ```
10
+
11
+ **Requirements:** Node.js 18+, TypeScript 5.2+
12
+
13
+ ## Quick Start
14
+
15
+ ### Class-Based Workflow
16
+
17
+ ```typescript
18
+ import { Workflow, Step, ObservedState, WorkflowTreeDebugger } from 'groundswell';
19
+
20
+ class DataProcessor extends Workflow {
21
+ @ObservedState()
22
+ progress = 0;
23
+
24
+ @Step({ trackTiming: true, snapshotState: true })
25
+ async process(): Promise<string[]> {
26
+ this.progress = 100;
27
+ return ['item1', 'item2', 'item3'];
28
+ }
29
+
30
+ async run(): Promise<string[]> {
31
+ this.setStatus('running');
32
+ const result = await this.process();
33
+ this.setStatus('completed');
34
+ return result;
35
+ }
36
+ }
37
+
38
+ const workflow = new DataProcessor('DataProcessor');
39
+ const debugger_ = new WorkflowTreeDebugger(workflow);
40
+
41
+ const result = await workflow.run();
42
+ console.log(debugger_.toTreeString());
43
+ ```
44
+
45
+ ### Functional Workflow
46
+
47
+ ```typescript
48
+ import { createWorkflow } from 'groundswell';
49
+
50
+ const workflow = createWorkflow(
51
+ { name: 'DataPipeline' },
52
+ async (ctx) => {
53
+ const loaded = await ctx.step('load', async () => fetchData());
54
+ const processed = await ctx.step('process', async () => transform(loaded));
55
+ return processed;
56
+ }
57
+ );
58
+
59
+ const result = await workflow.run();
60
+ ```
61
+
62
+ ### Agent with Prompt
63
+
64
+ ```typescript
65
+ import { createAgent, createPrompt } from 'groundswell';
66
+ import { z } from 'zod';
67
+
68
+ const agent = createAgent({
69
+ name: 'AnalysisAgent',
70
+ enableCache: true,
71
+ });
72
+
73
+ const prompt = createPrompt({
74
+ user: 'Analyze this code for bugs',
75
+ data: { code: 'function foo() { return 42; }' },
76
+ responseFormat: z.object({
77
+ bugs: z.array(z.string()),
78
+ severity: z.enum(['low', 'medium', 'high']),
79
+ }),
80
+ });
81
+
82
+ const result = await agent.prompt(prompt);
83
+ // result is typed as { bugs: string[], severity: 'low' | 'medium' | 'high' }
84
+ ```
85
+
86
+ ## Documentation
87
+
88
+ - [Workflows](docs/workflow.md) - Hierarchical task orchestration
89
+ - [Agents](docs/agent.md) - LLM execution with caching and reflection
90
+ - [Prompts](docs/prompt.md) - Type-safe prompt definitions with Zod
91
+
92
+ ### For AI Agents
93
+
94
+ Full documentation in a single file: [`llms_full.txt`](llms_full.txt)
95
+
96
+ Generate with `npm run generate:llms`
97
+
98
+ ## Core Concepts
99
+
100
+ ### Workflows
101
+
102
+ The primary orchestration unit. Manage execution status, emit events, and support hierarchical parent-child relationships. Two patterns are supported:
103
+ - **Class-based**: Extend `Workflow` and override `run()`
104
+ - **Functional**: Use `createWorkflow()` with an executor function
105
+
106
+ ### Agents
107
+
108
+ Lightweight wrappers around the Anthropic SDK. Execute prompts, manage tool invocation cycles, and integrate with caching and reflection systems.
109
+
110
+ ### Prompts
111
+
112
+ Immutable value objects defining what to send to an agent and how to validate the response using Zod schemas.
113
+
114
+ ## Decorators
115
+
116
+ ```typescript
117
+ // Emit lifecycle events and track timing
118
+ @Step({ trackTiming: true, snapshotState: true })
119
+ async processData(): Promise<void> { }
120
+
121
+ // Spawn and manage child workflows
122
+ @Task({ concurrent: true })
123
+ async createWorkers(): Promise<WorkerWorkflow[]> { }
124
+
125
+ // Mark fields for state snapshots
126
+ @ObservedState()
127
+ progress: number = 0;
128
+
129
+ @ObservedState({ redact: true }) // Shown as '***'
130
+ apiKey: string = 'secret';
131
+ ```
132
+
133
+ ## Caching
134
+
135
+ LLM responses are cached using deterministic SHA-256 keys:
136
+
137
+ ```typescript
138
+ import { createAgent, defaultCache } from 'groundswell';
139
+
140
+ const agent = createAgent({ enableCache: true });
141
+
142
+ const result1 = await agent.prompt(prompt); // API call
143
+ const result2 = await agent.prompt(prompt); // Cached
144
+
145
+ console.log(defaultCache.metrics()); // { hits: 1, misses: 1, hitRate: 50 }
146
+ ```
147
+
148
+ ## Reflection
149
+
150
+ Multi-level error recovery with automatic retry:
151
+
152
+ ```typescript
153
+ const workflow = createWorkflow(
154
+ { name: 'MyWorkflow', enableReflection: true },
155
+ async (ctx) => {
156
+ await ctx.step('unreliable-operation', async () => {
157
+ // If this fails, reflection will analyze and retry
158
+ });
159
+ }
160
+ );
161
+ ```
162
+
163
+ ## Introspection Tools
164
+
165
+ Agents can inspect their position in the workflow hierarchy:
166
+
167
+ ```typescript
168
+ import { INTROSPECTION_TOOLS, createAgent } from 'groundswell';
169
+
170
+ const agent = createAgent({
171
+ name: 'IntrospectionAgent',
172
+ tools: INTROSPECTION_TOOLS, // 6 tools for hierarchy navigation
173
+ });
174
+ ```
175
+
176
+ ## Examples
177
+
178
+ ```bash
179
+ npm run start:all # Interactive runner
180
+ npm run start:basic # Basic workflow
181
+ npm run start:decorators # Decorator options
182
+ npm run start:parent-child # Hierarchical workflows
183
+ npm run start:observers # Observers and debugger
184
+ npm run start:errors # Error handling
185
+ npm run start:concurrent # Concurrent tasks
186
+ npm run start:agent-loops # Agent loops
187
+ npm run start:sdk-features # Tools, MCPs, hooks
188
+ npm run start:reflection # Multi-level reflection
189
+ npm run start:introspection # Introspection tools
190
+ ```
191
+
192
+ See [examples/](examples/) for source code.
193
+
194
+ ## API Reference
195
+
196
+ | Category | Exports |
197
+ |----------|---------|
198
+ | **Core** | `Workflow`, `Agent`, `Prompt`, `MCPHandler` |
199
+ | **Factories** | `createWorkflow`, `createAgent`, `createPrompt` |
200
+ | **Decorators** | `@Step`, `@Task`, `@ObservedState` |
201
+ | **Caching** | `LLMCache`, `defaultCache`, `generateCacheKey` |
202
+ | **Reflection** | `ReflectionManager`, `executeWithReflection` |
203
+ | **Introspection** | `INTROSPECTION_TOOLS`, `handleInspectCurrentNode`, ... |
204
+ | **Debugging** | `WorkflowTreeDebugger`, `Observable` |
205
+
206
+ ## Contributing
207
+
208
+ Contributions and issues are welcome.
209
+
210
+ ## Support
211
+
212
+ If Groundswell helps you build something great, consider fueling future development:
213
+
214
+ <a href="https://buymeacoffee.com/dustindsch2" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="50"></a>
215
+
216
+ ## License
217
+
218
+ MIT