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.
- package/.claude/settings.local.json +9 -0
- package/.claude/system_prompts/task-breakdown.md +100 -0
- package/PRPs/001-hierarchical-workflow-engine.md +2438 -0
- package/PRPs/PRDs/001-hierarchical-workflow-engine.md +543 -0
- package/PRPs/PRDs/002-agent-prompt.md +390 -0
- package/PRPs/PRDs/003-agent-prompt.md +943 -0
- package/PRPs/PRDs/004-agent-prompt.md +1136 -0
- package/PRPs/PRDs/tasks-001.json +492 -0
- package/PRPs/README.md +83 -0
- package/PRPs/templates/prp_base.md +222 -0
- package/README.md +218 -0
- package/docs/agent.md +422 -0
- package/docs/prompt.md +419 -0
- package/docs/workflow.md +600 -0
- package/examples/README.md +244 -0
- package/examples/examples/01-basic-workflow.ts +100 -0
- package/examples/examples/02-decorator-options.ts +217 -0
- package/examples/examples/03-parent-child.ts +241 -0
- package/examples/examples/04-observers-debugger.ts +340 -0
- package/examples/examples/05-error-handling.ts +387 -0
- package/examples/examples/06-concurrent-tasks.ts +352 -0
- package/examples/examples/07-agent-loops.ts +432 -0
- package/examples/examples/08-sdk-features.ts +667 -0
- package/examples/examples/09-reflection.ts +573 -0
- package/examples/examples/10-introspection.ts +550 -0
- package/examples/index.ts +143 -0
- package/examples/utils/helpers.ts +57 -0
- package/llms_full.txt +5890 -0
- package/package.json +63 -0
- package/plan/P1P2/PRP.md +527 -0
- package/plan/P1P2/research/LRU_CACHE_BEST_PRACTICES.md +1929 -0
- package/plan/P1P2/research/LRU_CACHE_CODE_PATTERNS.md +857 -0
- package/plan/P1P2/research/LRU_CACHE_INTEGRATION_GUIDE.md +738 -0
- package/plan/P1P2/research/LRU_CACHE_RESEARCH_INDEX.md +424 -0
- package/plan/P1P2/research/REFLECTION_INDEX.md +291 -0
- package/plan/P1P2/research/REFLECTION_RESEARCH_REPORT.md +1342 -0
- package/plan/P1P2/research/RESEARCH_SUMMARY.md +342 -0
- package/plan/P1P2/research/anthropic-sdk.md +174 -0
- package/plan/P1P2/research/async-local-storage.md +200 -0
- package/plan/P1P2/research/reflection-code-patterns.md +1205 -0
- package/plan/P1P2/research/reflection-decision-matrix.md +421 -0
- package/plan/P1P2/research/reflection-implementation-guide.md +1341 -0
- package/plan/P1P2/research/reflection-integration-guide.md +834 -0
- package/plan/P1P2/research/reflection-patterns.md +1468 -0
- package/plan/P1P2/research/reflection-quick-reference.md +558 -0
- package/plan/P1P2/research/zod-schema.md +152 -0
- package/plan/P3P4/PRP.md +1388 -0
- package/plan/P3P4/research/caching-lru.md +116 -0
- package/plan/P3P4/research/introspection-tools.md +177 -0
- package/plan/P3P4/research/reflection-patterns.md +117 -0
- package/plan/P4P5/PRP.md +1136 -0
- package/plan/P4P5/research/RESEARCH_SUMMARY.md +151 -0
- package/plan/architecture/external_deps.md +358 -0
- package/plan/architecture/system_context.md +242 -0
- package/plan/backlog.json +867 -0
- package/plan/research/INTROSPECTION_RESEARCH_SUMMARY.md +378 -0
- package/plan/research/README-INTROSPECTION.md +352 -0
- package/plan/research/agent-introspection-patterns.md +1085 -0
- package/plan/research/introspection-security-guide.md +928 -0
- package/plan/research/introspection-tool-examples.md +875 -0
- package/scripts/generate-llms-full.ts +206 -0
- package/src/__tests__/integration/agent-workflow.test.ts +256 -0
- package/src/__tests__/integration/tree-mirroring.test.ts +114 -0
- package/src/__tests__/unit/agent.test.ts +169 -0
- package/src/__tests__/unit/cache-key.test.ts +182 -0
- package/src/__tests__/unit/cache.test.ts +172 -0
- package/src/__tests__/unit/context.test.ts +138 -0
- package/src/__tests__/unit/decorators.test.ts +100 -0
- package/src/__tests__/unit/introspection-tools.test.ts +277 -0
- package/src/__tests__/unit/prompt.test.ts +135 -0
- package/src/__tests__/unit/reflection.test.ts +210 -0
- package/src/__tests__/unit/tree-debugger.test.ts +85 -0
- package/src/__tests__/unit/workflow.test.ts +81 -0
- package/src/cache/cache-key.ts +244 -0
- package/src/cache/cache.ts +236 -0
- package/src/cache/index.ts +8 -0
- package/src/core/agent.ts +573 -0
- package/src/core/context.ts +119 -0
- package/src/core/event-tree.ts +260 -0
- package/src/core/factory.ts +123 -0
- package/src/core/index.ts +17 -0
- package/src/core/logger.ts +87 -0
- package/src/core/mcp-handler.ts +184 -0
- package/src/core/prompt.ts +150 -0
- package/src/core/workflow-context.ts +349 -0
- package/src/core/workflow.ts +302 -0
- package/src/debugger/index.ts +1 -0
- package/src/debugger/tree-debugger.ts +210 -0
- package/src/decorators/index.ts +3 -0
- package/src/decorators/observed-state.ts +95 -0
- package/src/decorators/step.ts +139 -0
- package/src/decorators/task.ts +96 -0
- package/src/examples/index.ts +2 -0
- package/src/examples/tdd-orchestrator.ts +65 -0
- package/src/examples/test-cycle-workflow.ts +64 -0
- package/src/index.ts +140 -0
- package/src/reflection/index.ts +5 -0
- package/src/reflection/reflection.ts +407 -0
- package/src/tools/index.ts +36 -0
- package/src/tools/introspection.ts +464 -0
- package/src/types/agent.ts +90 -0
- package/src/types/decorators.ts +25 -0
- package/src/types/error-strategy.ts +13 -0
- package/src/types/error.ts +20 -0
- package/src/types/events.ts +74 -0
- package/src/types/index.ts +55 -0
- package/src/types/logging.ts +24 -0
- package/src/types/observer.ts +18 -0
- package/src/types/prompt.ts +40 -0
- package/src/types/reflection.ts +117 -0
- package/src/types/sdk-primitives.ts +128 -0
- package/src/types/snapshot.ts +14 -0
- package/src/types/workflow-context.ts +163 -0
- package/src/types/workflow.ts +37 -0
- package/src/utils/id.ts +11 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/observable.ts +77 -0
- package/tasks.json +0 -0
- package/tsconfig.json +22 -0
- package/vitest.config.ts +16 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Groundswell Orchestration Framework - System Context
|
|
2
|
+
|
|
3
|
+
## Document Purpose
|
|
4
|
+
This document provides architectural context for the Agent/Prompt integration layer (PRD-002). It is the source of truth for implementing agents that understand their position within the existing Groundswell hierarchy.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Current System Architecture (Phase 1 - Complete)
|
|
9
|
+
|
|
10
|
+
### Core Components
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
src/
|
|
14
|
+
├── core/
|
|
15
|
+
│ ├── workflow.ts # Abstract Workflow base class with hierarchy
|
|
16
|
+
│ └── logger.ts # WorkflowLogger with observer emission
|
|
17
|
+
├── decorators/
|
|
18
|
+
│ ├── step.ts # @Step() - method instrumentation
|
|
19
|
+
│ ├── task.ts # @Task() - child workflow spawning
|
|
20
|
+
│ └── observed-state.ts # @ObservedState() - field state tracking
|
|
21
|
+
├── debugger/
|
|
22
|
+
│ └── tree-debugger.ts # WorkflowTreeDebugger - visualization
|
|
23
|
+
├── types/
|
|
24
|
+
│ ├── workflow.ts # WorkflowNode, WorkflowStatus
|
|
25
|
+
│ ├── events.ts # WorkflowEvent discriminated union
|
|
26
|
+
│ ├── observer.ts # WorkflowObserver interface
|
|
27
|
+
│ ├── logging.ts # LogEntry, LogLevel
|
|
28
|
+
│ ├── snapshot.ts # SerializedWorkflowState
|
|
29
|
+
│ └── error.ts # WorkflowError with context
|
|
30
|
+
└── utils/
|
|
31
|
+
├── observable.ts # Zero-dependency Observable<T>
|
|
32
|
+
└── id.ts # generateId() utility
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Hierarchy Patterns
|
|
36
|
+
|
|
37
|
+
1. **Parent-Child Relationships**
|
|
38
|
+
- `Workflow.parent: Workflow | null`
|
|
39
|
+
- `Workflow.children: Workflow[]`
|
|
40
|
+
- Automatic attachment via constructor `parent` parameter
|
|
41
|
+
|
|
42
|
+
2. **Node Mirroring**
|
|
43
|
+
- Every `Workflow` instance has a `WorkflowNode` representation
|
|
44
|
+
- Nodes form a parallel tree for serialization/inspection
|
|
45
|
+
- `getNode()` returns the node representation
|
|
46
|
+
|
|
47
|
+
3. **Observer Pattern**
|
|
48
|
+
- Observers attach to ROOT workflow only
|
|
49
|
+
- Events propagate from any workflow to root observers
|
|
50
|
+
- `WorkflowObserver` interface: `onLog`, `onEvent`, `onStateUpdated`, `onTreeChanged`
|
|
51
|
+
|
|
52
|
+
4. **Event System**
|
|
53
|
+
- Discriminated union: `WorkflowEvent`
|
|
54
|
+
- Current types: `childAttached`, `stateSnapshot`, `stepStart`, `stepEnd`, `error`, `taskStart`, `taskEnd`, `treeUpdated`
|
|
55
|
+
- Events stored in `node.events[]` and emitted to observers
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Where Agent/Prompt Layer Fits
|
|
60
|
+
|
|
61
|
+
### New Directory Structure (Phase 2)
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
src/
|
|
65
|
+
├── core/
|
|
66
|
+
│ ├── workflow.ts # (existing)
|
|
67
|
+
│ ├── logger.ts # (existing)
|
|
68
|
+
│ ├── agent.ts # NEW: Agent class wrapping Anthropic SDK
|
|
69
|
+
│ ├── prompt.ts # NEW: Prompt<T> class with Zod schema
|
|
70
|
+
│ └── context.ts # NEW: WorkflowContext for step/spawnWorkflow
|
|
71
|
+
├── decorators/ # (existing - may extend for agent methods)
|
|
72
|
+
├── debugger/ # (existing)
|
|
73
|
+
├── cache/
|
|
74
|
+
│ ├── cache.ts # NEW: Cache interface + LRU implementation
|
|
75
|
+
│ └── cache-key.ts # NEW: SHA-256 key generation
|
|
76
|
+
├── reflection/
|
|
77
|
+
│ └── reflection.ts # NEW: ReflectionAPI at all three levels
|
|
78
|
+
├── tools/
|
|
79
|
+
│ └── introspection.ts # NEW: Standard agent tools for hierarchy inspection
|
|
80
|
+
├── types/
|
|
81
|
+
│ ├── (existing types)
|
|
82
|
+
│ ├── agent.ts # NEW: AgentConfig, PromptOverrides
|
|
83
|
+
│ ├── prompt.ts # NEW: PromptConfig<T>
|
|
84
|
+
│ ├── cache.ts # NEW: Cache interface
|
|
85
|
+
│ └── introspection.ts # NEW: Tool definitions
|
|
86
|
+
└── utils/ # (existing)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Integration Points
|
|
90
|
+
|
|
91
|
+
1. **Agent as Workflow Participant**
|
|
92
|
+
- Agents execute WITHIN workflow steps
|
|
93
|
+
- Agent prompt executions appear as events in the workflow tree
|
|
94
|
+
- Agent can spawn workflows dynamically
|
|
95
|
+
|
|
96
|
+
2. **Event Tree Extension**
|
|
97
|
+
- New event types: `agentPromptStart`, `agentPromptEnd`, `toolInvocation`, `mcpEvent`, `reflectionStart`, `reflectionEnd`
|
|
98
|
+
- Events attach to current workflow node automatically
|
|
99
|
+
|
|
100
|
+
3. **Hierarchy Mounting**
|
|
101
|
+
- When `agent.prompt()` is called inside a workflow step:
|
|
102
|
+
- Create event node under current step
|
|
103
|
+
- Track tool/MCP events as children
|
|
104
|
+
- Propagate completion back up
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Key Implementation Constraints
|
|
109
|
+
|
|
110
|
+
### 1. Zero-Plumbing Mounting (PRD Requirement)
|
|
111
|
+
Current pattern to maintain:
|
|
112
|
+
```typescript
|
|
113
|
+
// Constructor automatically attaches to parent
|
|
114
|
+
constructor(name?: string, parent?: Workflow) {
|
|
115
|
+
// ...
|
|
116
|
+
if (parent) {
|
|
117
|
+
parent.attachChild(this);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
New classes MUST follow this pattern - no manual tree assembly.
|
|
122
|
+
|
|
123
|
+
### 2. Observer Propagation
|
|
124
|
+
All new events MUST propagate to root observers:
|
|
125
|
+
```typescript
|
|
126
|
+
// Existing pattern in Workflow class
|
|
127
|
+
protected emitEvent(event: WorkflowEvent): void {
|
|
128
|
+
this.node.events.push(event);
|
|
129
|
+
const observers = this.getRootObservers();
|
|
130
|
+
for (const obs of observers) {
|
|
131
|
+
obs.onEvent(event);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 3. State Snapshot Integration
|
|
137
|
+
Use existing `@ObservedState()` decorator pattern for Agent/Prompt state tracking.
|
|
138
|
+
|
|
139
|
+
### 4. Anthropic SDK Pass-Through
|
|
140
|
+
All SDK properties (`tools`, `mcps`, `skills`, `hooks`, `env`) MUST pass through unchanged. No custom abstractions.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Architectural Decisions
|
|
145
|
+
|
|
146
|
+
### Decision 1: Agent is NOT a Workflow Subclass
|
|
147
|
+
**Rationale**: Agents execute prompts; they don't have their own lifecycle. Agents are lightweight wrappers around the Anthropic SDK.
|
|
148
|
+
|
|
149
|
+
**Pattern**:
|
|
150
|
+
```typescript
|
|
151
|
+
class Agent {
|
|
152
|
+
prompt<T>(prompt: Prompt<T>, overrides?: PromptOverrides): Promise<T>;
|
|
153
|
+
reflect<T>(prompt: Prompt<T>, overrides?: PromptOverrides): Promise<T>;
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Decision 2: Prompts are Immutable Value Objects
|
|
158
|
+
**Rationale**: Prompts define what to send; they don't execute. Execution happens via `Agent.prompt()`.
|
|
159
|
+
|
|
160
|
+
**Pattern**:
|
|
161
|
+
```typescript
|
|
162
|
+
class Prompt<T> {
|
|
163
|
+
readonly user: string;
|
|
164
|
+
readonly data: Record<string, any>;
|
|
165
|
+
readonly responseFormat: ZodSchema<T>;
|
|
166
|
+
// ...other readonly fields
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Decision 3: WorkflowContext Provides step() and spawnWorkflow()
|
|
171
|
+
**Rationale**: PRD requires `step()` callable anywhere in JS control flow. Context pattern allows this.
|
|
172
|
+
|
|
173
|
+
**Pattern**:
|
|
174
|
+
```typescript
|
|
175
|
+
interface WorkflowContext {
|
|
176
|
+
workflowId: string;
|
|
177
|
+
parentWorkflowId?: string;
|
|
178
|
+
step(name: string, fn: () => Promise<any>): Promise<any>;
|
|
179
|
+
spawnWorkflow(wf: Workflow): Promise<any>;
|
|
180
|
+
eventTree: EventTreeHandle;
|
|
181
|
+
reflection: ReflectionAPI;
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Decision 4: Cache Key is Deterministic SHA-256
|
|
186
|
+
**Rationale**: PRD specifies exact fields for cache key. Use crypto.subtle for browser compat.
|
|
187
|
+
|
|
188
|
+
**Fields**:
|
|
189
|
+
- user message
|
|
190
|
+
- data
|
|
191
|
+
- system value
|
|
192
|
+
- model settings
|
|
193
|
+
- temperature
|
|
194
|
+
- tools (hashed)
|
|
195
|
+
- mcps (hashed)
|
|
196
|
+
- skills (hashed)
|
|
197
|
+
- schema version/hash
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## File Path References for Implementers
|
|
202
|
+
|
|
203
|
+
| Concept | File Path | Purpose |
|
|
204
|
+
|---------|-----------|---------|
|
|
205
|
+
| Workflow base | `/src/core/workflow.ts` | Abstract base class, hierarchy management |
|
|
206
|
+
| Event types | `/src/types/events.ts` | WorkflowEvent discriminated union |
|
|
207
|
+
| Node structure | `/src/types/workflow.ts` | WorkflowNode interface |
|
|
208
|
+
| Observer interface | `/src/types/observer.ts` | WorkflowObserver contract |
|
|
209
|
+
| State decorator | `/src/decorators/observed-state.ts` | @ObservedState, getObservedState |
|
|
210
|
+
| Step decorator | `/src/decorators/step.ts` | @Step() pattern to replicate |
|
|
211
|
+
| ID generation | `/src/utils/id.ts` | generateId() function |
|
|
212
|
+
| Observable | `/src/utils/observable.ts` | Zero-dep Observable<T> |
|
|
213
|
+
| Logger | `/src/core/logger.ts` | WorkflowLogger pattern |
|
|
214
|
+
| Debugger | `/src/debugger/tree-debugger.ts` | WorkflowTreeDebugger reference |
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Dependencies to Add
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"dependencies": {
|
|
223
|
+
"@anthropic-ai/sdk": "^0.71.1",
|
|
224
|
+
"zod": "^3.23.0"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Note**: Use Zod v3.x (not v4.x) for stability. The SDK compatibility has been verified with v3.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Next Steps for PRP Implementation
|
|
234
|
+
|
|
235
|
+
1. Add dependencies to package.json
|
|
236
|
+
2. Implement Agent class (src/core/agent.ts)
|
|
237
|
+
3. Implement Prompt class (src/core/prompt.ts)
|
|
238
|
+
4. Extend WorkflowEvent union with agent events
|
|
239
|
+
5. Implement Cache layer
|
|
240
|
+
6. Implement Reflection API
|
|
241
|
+
7. Implement Introspection tools
|
|
242
|
+
8. Create 10 canonical examples
|