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,139 @@
|
|
|
1
|
+
import type { StepOptions, WorkflowError, WorkflowNode, LogEntry, WorkflowEvent } from '../types/index.js';
|
|
2
|
+
import { getObservedState } from './observed-state.js';
|
|
3
|
+
import { runInContext, type AgentExecutionContext } from '../core/context.js';
|
|
4
|
+
import { generateId } from '../utils/id.js';
|
|
5
|
+
|
|
6
|
+
// Type for workflow-like objects that @Step can decorate methods on
|
|
7
|
+
interface WorkflowLike {
|
|
8
|
+
id: string;
|
|
9
|
+
node: WorkflowNode;
|
|
10
|
+
logger: {
|
|
11
|
+
info(message: string, data?: unknown): void;
|
|
12
|
+
};
|
|
13
|
+
emitEvent(event: WorkflowEvent): void;
|
|
14
|
+
snapshotState(): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @Step decorator
|
|
19
|
+
* Wraps a method to emit step events, handle errors, and optionally snapshot state
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* class MyWorkflow extends Workflow {
|
|
23
|
+
* @Step({ snapshotState: true, trackTiming: true })
|
|
24
|
+
* async processData() {
|
|
25
|
+
* // ... step logic
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export function Step(opts: StepOptions = {}) {
|
|
30
|
+
return function <This, Args extends unknown[], Return>(
|
|
31
|
+
originalMethod: (this: This, ...args: Args) => Promise<Return>,
|
|
32
|
+
context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Promise<Return>>
|
|
33
|
+
) {
|
|
34
|
+
const methodName = String(context.name);
|
|
35
|
+
|
|
36
|
+
// CRITICAL: Use regular function, not arrow function, to preserve 'this'
|
|
37
|
+
async function stepWrapper(this: This, ...args: Args): Promise<Return> {
|
|
38
|
+
// Cast to WorkflowLike for type safety when accessing workflow properties
|
|
39
|
+
const wf = this as unknown as WorkflowLike;
|
|
40
|
+
const stepName = opts.name ?? methodName;
|
|
41
|
+
const startTime = Date.now();
|
|
42
|
+
|
|
43
|
+
// Log start if requested
|
|
44
|
+
if (opts.logStart) {
|
|
45
|
+
wf.logger.info(`STEP START: ${stepName}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Emit step start event
|
|
49
|
+
wf.emitEvent({
|
|
50
|
+
type: 'stepStart',
|
|
51
|
+
node: wf.node,
|
|
52
|
+
step: stepName,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Create step node for hierarchy tracking
|
|
56
|
+
const stepNode: WorkflowNode = {
|
|
57
|
+
id: generateId(),
|
|
58
|
+
name: stepName,
|
|
59
|
+
parent: wf.node,
|
|
60
|
+
children: [],
|
|
61
|
+
status: 'running',
|
|
62
|
+
logs: [],
|
|
63
|
+
events: [],
|
|
64
|
+
stateSnapshot: null,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Create execution context for agent/prompt operations within this step
|
|
68
|
+
const executionContext: AgentExecutionContext = {
|
|
69
|
+
workflowNode: stepNode,
|
|
70
|
+
emitEvent: (event: WorkflowEvent) => {
|
|
71
|
+
stepNode.events.push(event);
|
|
72
|
+
wf.emitEvent(event);
|
|
73
|
+
},
|
|
74
|
+
workflowId: wf.id,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
// Execute the original method within the execution context
|
|
79
|
+
// This allows Agent.prompt() calls to automatically capture events
|
|
80
|
+
const result = await runInContext(executionContext, async () => {
|
|
81
|
+
return originalMethod.call(this, ...args);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Update step node status
|
|
85
|
+
stepNode.status = 'completed';
|
|
86
|
+
|
|
87
|
+
// Snapshot state if requested
|
|
88
|
+
if (opts.snapshotState) {
|
|
89
|
+
wf.snapshotState();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Calculate duration and emit end event
|
|
93
|
+
const duration = Date.now() - startTime;
|
|
94
|
+
if (opts.trackTiming !== false) {
|
|
95
|
+
wf.emitEvent({
|
|
96
|
+
type: 'stepEnd',
|
|
97
|
+
node: wf.node,
|
|
98
|
+
step: stepName,
|
|
99
|
+
duration,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Log finish if requested
|
|
104
|
+
if (opts.logFinish) {
|
|
105
|
+
wf.logger.info(`STEP END: ${stepName} (${duration}ms)`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return result;
|
|
109
|
+
} catch (err: unknown) {
|
|
110
|
+
// Update step node status
|
|
111
|
+
stepNode.status = 'failed';
|
|
112
|
+
// Create rich error with context
|
|
113
|
+
const error = err as Error;
|
|
114
|
+
const snap = getObservedState(this as object);
|
|
115
|
+
|
|
116
|
+
const workflowError: WorkflowError = {
|
|
117
|
+
message: error?.message ?? 'Unknown error',
|
|
118
|
+
original: err,
|
|
119
|
+
workflowId: wf.id,
|
|
120
|
+
stack: error?.stack,
|
|
121
|
+
state: snap,
|
|
122
|
+
logs: [...wf.node.logs] as LogEntry[],
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Emit error event
|
|
126
|
+
wf.emitEvent({
|
|
127
|
+
type: 'error',
|
|
128
|
+
node: wf.node,
|
|
129
|
+
error: workflowError,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Re-throw the enriched error
|
|
133
|
+
throw workflowError;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return stepWrapper;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { TaskOptions, WorkflowNode, WorkflowEvent } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
// Type for workflow-like objects
|
|
4
|
+
interface WorkflowLike {
|
|
5
|
+
id: string;
|
|
6
|
+
node: WorkflowNode;
|
|
7
|
+
emitEvent(event: WorkflowEvent): void;
|
|
8
|
+
attachChild(child: WorkflowLike): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Minimal Workflow type for checking if something is a workflow
|
|
12
|
+
interface WorkflowClass {
|
|
13
|
+
id: string;
|
|
14
|
+
parent: WorkflowLike | null;
|
|
15
|
+
run(...args: unknown[]): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @Task decorator
|
|
20
|
+
* Wraps a method that returns child workflow(s), automatically attaching them
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* class ParentWorkflow extends Workflow {
|
|
24
|
+
* @Task({ concurrent: true })
|
|
25
|
+
* async createChildren(): Promise<ChildWorkflow[]> {
|
|
26
|
+
* return [
|
|
27
|
+
* new ChildWorkflow('child1', this),
|
|
28
|
+
* new ChildWorkflow('child2', this),
|
|
29
|
+
* ];
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
export function Task(opts: TaskOptions = {}) {
|
|
34
|
+
return function <This, Args extends unknown[], Return>(
|
|
35
|
+
originalMethod: (this: This, ...args: Args) => Promise<Return>,
|
|
36
|
+
context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Promise<Return>>
|
|
37
|
+
) {
|
|
38
|
+
const methodName = String(context.name);
|
|
39
|
+
|
|
40
|
+
// CRITICAL: Use regular function, not arrow function
|
|
41
|
+
async function taskWrapper(this: This, ...args: Args): Promise<Return> {
|
|
42
|
+
// Cast to WorkflowLike for type safety when accessing workflow properties
|
|
43
|
+
const wf = this as unknown as WorkflowLike;
|
|
44
|
+
const taskName = opts.name ?? methodName;
|
|
45
|
+
|
|
46
|
+
// Emit task start event
|
|
47
|
+
wf.emitEvent({
|
|
48
|
+
type: 'taskStart',
|
|
49
|
+
node: wf.node,
|
|
50
|
+
task: taskName,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Execute the original method
|
|
54
|
+
const result = await originalMethod.call(this, ...args);
|
|
55
|
+
|
|
56
|
+
// Process returned workflows
|
|
57
|
+
const workflows = Array.isArray(result) ? result : [result];
|
|
58
|
+
|
|
59
|
+
for (const workflow of workflows) {
|
|
60
|
+
// Type guard to check if it's a workflow
|
|
61
|
+
if (workflow && typeof workflow === 'object' && 'id' in workflow) {
|
|
62
|
+
const childWf = workflow as WorkflowClass;
|
|
63
|
+
|
|
64
|
+
// Only attach if not already attached (parent not set by constructor)
|
|
65
|
+
if (!childWf.parent) {
|
|
66
|
+
childWf.parent = wf;
|
|
67
|
+
wf.attachChild(childWf as unknown as WorkflowLike);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// If concurrent option is set and we have multiple workflows, run them in parallel
|
|
73
|
+
if (opts.concurrent && Array.isArray(result)) {
|
|
74
|
+
const runnable = workflows.filter(
|
|
75
|
+
(w): w is WorkflowClass =>
|
|
76
|
+
w && typeof w === 'object' && 'run' in w && typeof w.run === 'function'
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (runnable.length > 0) {
|
|
80
|
+
await Promise.all(runnable.map((w) => w.run()));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Emit task end event
|
|
85
|
+
wf.emitEvent({
|
|
86
|
+
type: 'taskEnd',
|
|
87
|
+
node: wf.node,
|
|
88
|
+
task: taskName,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return taskWrapper;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Workflow } from '../core/workflow.js';
|
|
2
|
+
import { Step } from '../decorators/step.js';
|
|
3
|
+
import { Task } from '../decorators/task.js';
|
|
4
|
+
import { ObservedState } from '../decorators/observed-state.js';
|
|
5
|
+
import { TestCycleWorkflow } from './test-cycle-workflow.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Example parent workflow demonstrating TDD orchestration
|
|
9
|
+
*/
|
|
10
|
+
export class TDDOrchestrator extends Workflow {
|
|
11
|
+
@ObservedState()
|
|
12
|
+
cycleCount: number = 0;
|
|
13
|
+
|
|
14
|
+
@ObservedState()
|
|
15
|
+
maxCycles: number = 3;
|
|
16
|
+
|
|
17
|
+
@ObservedState({ redact: true })
|
|
18
|
+
apiKey: string = 'secret-key';
|
|
19
|
+
|
|
20
|
+
@Step({ logStart: true, logFinish: true })
|
|
21
|
+
async setupEnvironment(): Promise<void> {
|
|
22
|
+
this.logger.info('Setting up TDD environment');
|
|
23
|
+
// Simulate environment setup
|
|
24
|
+
await this.delay(50);
|
|
25
|
+
this.logger.debug('Environment ready');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Task()
|
|
29
|
+
async runCycle(): Promise<TestCycleWorkflow> {
|
|
30
|
+
this.cycleCount++;
|
|
31
|
+
this.logger.info(`Starting cycle ${this.cycleCount}/${this.maxCycles}`);
|
|
32
|
+
return new TestCycleWorkflow(`Cycle-${this.cycleCount}`, this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async run(): Promise<void> {
|
|
36
|
+
this.setStatus('running');
|
|
37
|
+
this.logger.info('TDD Orchestrator starting');
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
await this.setupEnvironment();
|
|
41
|
+
|
|
42
|
+
while (this.cycleCount < this.maxCycles) {
|
|
43
|
+
try {
|
|
44
|
+
const cycle = await this.runCycle();
|
|
45
|
+
await cycle.run();
|
|
46
|
+
this.logger.info(`Cycle ${this.cycleCount} completed successfully`);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
this.logger.warn(`Cycle ${this.cycleCount} failed, continuing...`);
|
|
49
|
+
// In real implementation, analyze error and potentially restart
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.setStatus('completed');
|
|
54
|
+
this.logger.info('TDD Orchestrator completed all cycles');
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.setStatus('failed');
|
|
57
|
+
this.logger.error('TDD Orchestrator failed', { error });
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private delay(ms: number): Promise<void> {
|
|
63
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Workflow } from '../core/workflow.js';
|
|
2
|
+
import { Step } from '../decorators/step.js';
|
|
3
|
+
import { ObservedState } from '../decorators/observed-state.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Example child workflow demonstrating test cycle
|
|
7
|
+
*/
|
|
8
|
+
export class TestCycleWorkflow extends Workflow {
|
|
9
|
+
@ObservedState()
|
|
10
|
+
currentTest: string = '';
|
|
11
|
+
|
|
12
|
+
@ObservedState()
|
|
13
|
+
testResult: 'pending' | 'passed' | 'failed' = 'pending';
|
|
14
|
+
|
|
15
|
+
@Step({ snapshotState: true, trackTiming: true, logStart: true })
|
|
16
|
+
async generateTest(): Promise<string> {
|
|
17
|
+
this.logger.info('Generating test case');
|
|
18
|
+
this.currentTest = `test_${Date.now()}`;
|
|
19
|
+
// Simulate test generation
|
|
20
|
+
await this.delay(100);
|
|
21
|
+
return this.currentTest;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Step({ trackTiming: true })
|
|
25
|
+
async runTest(): Promise<boolean> {
|
|
26
|
+
this.logger.info(`Running test: ${this.currentTest}`);
|
|
27
|
+
// Simulate test execution
|
|
28
|
+
await this.delay(200);
|
|
29
|
+
|
|
30
|
+
// Randomly pass or fail for demonstration
|
|
31
|
+
const passed = Math.random() > 0.3;
|
|
32
|
+
this.testResult = passed ? 'passed' : 'failed';
|
|
33
|
+
|
|
34
|
+
if (!passed) {
|
|
35
|
+
throw new Error(`Test ${this.currentTest} failed`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Step({ snapshotState: true })
|
|
42
|
+
async updateImplementation(): Promise<void> {
|
|
43
|
+
this.logger.info('Updating implementation based on test results');
|
|
44
|
+
await this.delay(150);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async run(): Promise<void> {
|
|
48
|
+
this.setStatus('running');
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await this.generateTest();
|
|
52
|
+
await this.runTest();
|
|
53
|
+
await this.updateImplementation();
|
|
54
|
+
this.setStatus('completed');
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.setStatus('failed');
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private delay(ms: number): Promise<void> {
|
|
62
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
export type {
|
|
3
|
+
WorkflowStatus,
|
|
4
|
+
WorkflowNode,
|
|
5
|
+
LogLevel,
|
|
6
|
+
LogEntry,
|
|
7
|
+
SerializedWorkflowState,
|
|
8
|
+
StateFieldMetadata,
|
|
9
|
+
WorkflowError,
|
|
10
|
+
WorkflowEvent,
|
|
11
|
+
WorkflowObserver,
|
|
12
|
+
StepOptions,
|
|
13
|
+
TaskOptions,
|
|
14
|
+
ErrorMergeStrategy,
|
|
15
|
+
// SDK primitive types
|
|
16
|
+
Tool,
|
|
17
|
+
ToolResult,
|
|
18
|
+
MCPServer,
|
|
19
|
+
Skill,
|
|
20
|
+
HookHandler,
|
|
21
|
+
PreToolUseContext,
|
|
22
|
+
PostToolUseContext,
|
|
23
|
+
SessionStartContext,
|
|
24
|
+
SessionEndContext,
|
|
25
|
+
AgentHooks,
|
|
26
|
+
TokenUsage,
|
|
27
|
+
// Agent and Prompt types
|
|
28
|
+
AgentConfig,
|
|
29
|
+
PromptOverrides,
|
|
30
|
+
PromptConfig,
|
|
31
|
+
// WorkflowContext types
|
|
32
|
+
WorkflowContext,
|
|
33
|
+
WorkflowConfig,
|
|
34
|
+
WorkflowResult,
|
|
35
|
+
EventTreeHandle,
|
|
36
|
+
EventNode,
|
|
37
|
+
EventMetrics,
|
|
38
|
+
AgentLike,
|
|
39
|
+
PromptLike,
|
|
40
|
+
// Reflection types
|
|
41
|
+
ReflectionAPI,
|
|
42
|
+
ReflectionConfig,
|
|
43
|
+
ReflectionContext,
|
|
44
|
+
ReflectionResult,
|
|
45
|
+
ReflectionEntry,
|
|
46
|
+
} from './types/index.js';
|
|
47
|
+
|
|
48
|
+
// Re-export reflection utilities
|
|
49
|
+
export {
|
|
50
|
+
DEFAULT_REFLECTION_CONFIG,
|
|
51
|
+
createReflectionConfig,
|
|
52
|
+
} from './types/index.js';
|
|
53
|
+
|
|
54
|
+
// Core classes
|
|
55
|
+
export { Workflow, type WorkflowExecutor } from './core/workflow.js';
|
|
56
|
+
export { WorkflowLogger } from './core/logger.js';
|
|
57
|
+
export { Agent, type PromptResult } from './core/agent.js';
|
|
58
|
+
export { Prompt } from './core/prompt.js';
|
|
59
|
+
export { MCPHandler, type ToolExecutor } from './core/mcp-handler.js';
|
|
60
|
+
|
|
61
|
+
// Context and event tree
|
|
62
|
+
export { EventTreeHandleImpl, createEventTreeHandle } from './core/event-tree.js';
|
|
63
|
+
export { WorkflowContextImpl, createWorkflowContext } from './core/workflow-context.js';
|
|
64
|
+
export {
|
|
65
|
+
getExecutionContext,
|
|
66
|
+
requireExecutionContext,
|
|
67
|
+
runInContext,
|
|
68
|
+
runInContextSync,
|
|
69
|
+
hasExecutionContext,
|
|
70
|
+
createChildContext,
|
|
71
|
+
agentExecutionStorage,
|
|
72
|
+
type AgentExecutionContext,
|
|
73
|
+
} from './core/context.js';
|
|
74
|
+
|
|
75
|
+
// Decorators
|
|
76
|
+
export { Step } from './decorators/step.js';
|
|
77
|
+
export { Task } from './decorators/task.js';
|
|
78
|
+
export { ObservedState, getObservedState } from './decorators/observed-state.js';
|
|
79
|
+
|
|
80
|
+
// Debugger
|
|
81
|
+
export { WorkflowTreeDebugger } from './debugger/tree-debugger.js';
|
|
82
|
+
|
|
83
|
+
// Utilities
|
|
84
|
+
export { Observable } from './utils/observable.js';
|
|
85
|
+
export type { Subscription, Observer } from './utils/observable.js';
|
|
86
|
+
export { generateId } from './utils/id.js';
|
|
87
|
+
|
|
88
|
+
// Factory functions
|
|
89
|
+
export {
|
|
90
|
+
createWorkflow,
|
|
91
|
+
createAgent,
|
|
92
|
+
createPrompt,
|
|
93
|
+
quickWorkflow,
|
|
94
|
+
quickAgent,
|
|
95
|
+
} from './core/factory.js';
|
|
96
|
+
|
|
97
|
+
// Cache
|
|
98
|
+
export { LLMCache, defaultCache } from './cache/cache.js';
|
|
99
|
+
export { generateCacheKey, deterministicStringify, getSchemaHash } from './cache/cache-key.js';
|
|
100
|
+
export type { CacheConfig, CacheMetrics } from './cache/cache.js';
|
|
101
|
+
export type { CacheKeyInputs } from './cache/cache-key.js';
|
|
102
|
+
|
|
103
|
+
// Reflection
|
|
104
|
+
export { ReflectionManager, executeWithReflection } from './reflection/reflection.js';
|
|
105
|
+
|
|
106
|
+
// Introspection Tools
|
|
107
|
+
export {
|
|
108
|
+
INTROSPECTION_TOOLS,
|
|
109
|
+
INTROSPECTION_HANDLERS,
|
|
110
|
+
registerIntrospectionTools,
|
|
111
|
+
executeIntrospectionTool,
|
|
112
|
+
// Individual tools
|
|
113
|
+
inspectCurrentNodeTool,
|
|
114
|
+
readAncestorChainTool,
|
|
115
|
+
listSiblingsChildrenTool,
|
|
116
|
+
inspectPriorOutputsTool,
|
|
117
|
+
inspectCacheStatusTool,
|
|
118
|
+
requestSpawnWorkflowTool,
|
|
119
|
+
// Handlers
|
|
120
|
+
handleInspectCurrentNode,
|
|
121
|
+
handleReadAncestorChain,
|
|
122
|
+
handleListSiblingsChildren,
|
|
123
|
+
handleInspectPriorOutputs,
|
|
124
|
+
handleInspectCacheStatus,
|
|
125
|
+
handleRequestSpawnWorkflow,
|
|
126
|
+
} from './tools/introspection.js';
|
|
127
|
+
export type {
|
|
128
|
+
CurrentNodeInfo,
|
|
129
|
+
AncestorInfo,
|
|
130
|
+
AncestorChainResult,
|
|
131
|
+
NodeInfo,
|
|
132
|
+
SiblingsChildrenResult,
|
|
133
|
+
PriorOutputInfo,
|
|
134
|
+
CacheStatusResult,
|
|
135
|
+
SpawnWorkflowRequest,
|
|
136
|
+
} from './tools/introspection.js';
|
|
137
|
+
|
|
138
|
+
// Examples (for reference)
|
|
139
|
+
export { TestCycleWorkflow } from './examples/test-cycle-workflow.js';
|
|
140
|
+
export { TDDOrchestrator } from './examples/tdd-orchestrator.js';
|