Skip to content

Commit f2cdc4b

Browse files
Copilottoolate28
andcommitted
Fix code review issues: use crypto.randomUUID consistently, proper ES6 imports, remove uuid dependency
Co-authored-by: toolate28 <105518313+toolate28@users.noreply.github.com>
1 parent 405b5fd commit f2cdc4b

7 files changed

Lines changed: 153 additions & 25 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ Thumbs.db
3939

4040
# Wave protocol data
4141
.wave/
42+
.wave-example/

examples/handshake-workflow.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Example: Full H&&S Protocol Workflow
5+
*
6+
* Demonstrates a complete multi-agent workflow:
7+
* User -> Grok -> Claude -> Repos
8+
*/
9+
10+
const { HandshakeProtocol } = require('../dist/index');
11+
const fs = require('fs');
12+
const path = require('path');
13+
14+
async function main() {
15+
console.log('🌊 Wave Toolkit - H&&S Protocol Example\n');
16+
17+
// Initialize protocol with custom directories
18+
const protocol = new HandshakeProtocol(
19+
'.wave-example/handoffs',
20+
'.wave-example/atom-trail'
21+
);
22+
23+
const sessionId = `example-${Date.now()}`;
24+
console.log(`Session ID: ${sessionId}\n`);
25+
26+
// Step 1: User initiates task with Grok
27+
console.log('Step 1: User → Grok (PASS)');
28+
const step1 = await protocol.createHandoff(
29+
'user',
30+
'grok',
31+
'PASS',
32+
{
33+
task: 'Explore architectural patterns for microservices',
34+
requirements: ['scalability', 'resilience', 'observability']
35+
},
36+
sessionId
37+
);
38+
console.log(` ✓ Created handoff: ${step1.id}`);
39+
console.log(` ✓ Context: ${JSON.stringify(step1.context)}\n`);
40+
41+
// Step 2: Grok completes exploration, passes to Claude with high coherence
42+
console.log('Step 2: Grok → Claude (WAVE with 88% coherence)');
43+
const step2 = await protocol.createHandoff(
44+
'grok',
45+
'claude',
46+
'WAVE',
47+
{
48+
insights: [
49+
'Event-driven architecture for loose coupling',
50+
'API Gateway pattern for unified interface',
51+
'Circuit breaker for fault tolerance'
52+
],
53+
recommendedApproach: 'Hybrid synchronous/asynchronous communication'
54+
},
55+
sessionId,
56+
88 // High coherence score
57+
);
58+
console.log(` ✓ Created handoff: ${step2.id}`);
59+
console.log(` ✓ Coherence Score: ${step2.coherenceScore}%`);
60+
console.log(` ✓ Insights: ${step2.context.insights.length} patterns identified\n`);
61+
62+
// Step 3: Claude implements and commits
63+
console.log('Step 3: Claude → Repos (PASS)');
64+
const step3 = await protocol.createHandoff(
65+
'claude',
66+
'repos',
67+
'PASS',
68+
{
69+
status: 'committed',
70+
files: [
71+
'src/gateway/api-gateway.ts',
72+
'src/services/event-bus.ts',
73+
'src/middleware/circuit-breaker.ts',
74+
'tests/integration.test.ts'
75+
],
76+
branch: 'feature/microservices-architecture'
77+
},
78+
sessionId
79+
);
80+
console.log(` ✓ Created handoff: ${step3.id}`);
81+
console.log(` ✓ Files committed: ${step3.context.files.length}`);
82+
console.log(` ✓ Branch: ${step3.context.branch}\n`);
83+
84+
// Display the complete chain
85+
console.log('📊 Complete Handoff Chain:');
86+
console.log('─'.repeat(60));
87+
const chain = await protocol.getHandoffChain(sessionId);
88+
chain.forEach((marker, index) => {
89+
console.log(`${index + 1}. [${new Date(marker.timestamp).toLocaleTimeString()}]`);
90+
console.log(` ${marker.fromAgent} --${marker.state}${marker.coherenceScore ? `(${marker.coherenceScore}%)` : ''}-> ${marker.toAgent}`);
91+
});
92+
console.log('─'.repeat(60) + '\n');
93+
94+
// Generate Mermaid visualization
95+
console.log('📈 Workflow Visualization (Mermaid):');
96+
console.log('─'.repeat(60));
97+
const diagram = await protocol.visualizeWorkflow(sessionId);
98+
console.log(diagram);
99+
console.log('─'.repeat(60) + '\n');
100+
101+
// Validate all handoffs
102+
console.log('✅ Validation Results:');
103+
for (let i = 0; i < chain.length; i++) {
104+
const result = await protocol.validateHandoff(chain[i]);
105+
console.log(` Step ${i + 1}: ${result.valid ? '✓ Valid' : '✗ Invalid'}`);
106+
if (result.warnings && result.warnings.length > 0) {
107+
result.warnings.forEach(warning => {
108+
console.log(` ⚠️ ${warning}`);
109+
});
110+
}
111+
}
112+
console.log('');
113+
114+
// Show ATOM trail
115+
console.log('📜 ATOM Trail Entries:');
116+
console.log('─'.repeat(60));
117+
const atomFile = path.join('.wave-example/atom-trail', `${sessionId}.atom.jsonl`);
118+
if (fs.existsSync(atomFile)) {
119+
const content = fs.readFileSync(atomFile, 'utf-8');
120+
const entries = content.trim().split('\n').map(line => JSON.parse(line));
121+
entries.forEach((entry, index) => {
122+
console.log(`${index + 1}. ${entry.actor}${entry.decision}`);
123+
console.log(` ${entry.rationale}`);
124+
});
125+
}
126+
console.log('─'.repeat(60) + '\n');
127+
128+
console.log('✨ Example complete!');
129+
console.log(`\n💾 Data stored in: .wave-example/`);
130+
console.log(` Handoffs: .wave-example/handoffs/${sessionId}.jsonl`);
131+
console.log(` ATOM Trail: .wave-example/atom-trail/${sessionId}.atom.jsonl`);
132+
}
133+
134+
// Run the example
135+
main().catch(error => {
136+
console.error('Error:', error);
137+
process.exit(1);
138+
});

jest.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,5 @@ module.exports = {
1414
lines: 90,
1515
statements: 90
1616
}
17-
},
18-
moduleNameMapper: {
19-
'^uuid$': require.resolve('uuid')
20-
},
21-
transformIgnorePatterns: [
22-
'node_modules/(?!(uuid)/)'
23-
]
17+
}
2418
};

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818
"test:coverage": "jest --coverage",
1919
"prepublishOnly": "npm run build"
2020
},
21-
"keywords": ["wave", "handshake", "protocol", "multi-agent", "coordination"],
21+
"keywords": [
22+
"wave",
23+
"handshake",
24+
"protocol",
25+
"multi-agent",
26+
"coordination"
27+
],
2228
"author": "toolate28",
2329
"license": "MIT",
2430
"devDependencies": {
2531
"@types/jest": "^30.0.0",
2632
"@types/node": "^25.0.9",
27-
"@types/uuid": "^10.0.0",
2833
"jest": "^30.2.0",
2934
"ts-jest": "^29.4.6",
3035
"typescript": "^5.9.3"
31-
},
32-
"dependencies": {
33-
"uuid": "^13.0.0"
3436
}
3537
}

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { HandshakeProtocol } from './handshake/protocol';
44
import { HandoffState } from './handshake/types';
5+
import * as fs from 'fs';
56

67
/**
78
* CLI for H&&S Protocol
@@ -185,7 +186,6 @@ async function handleVisualize(args: string[], protocol: HandshakeProtocol) {
185186
const diagram = await protocol.visualizeWorkflow(sessionId);
186187

187188
if (outputFile) {
188-
const fs = require('fs');
189189
await fs.promises.writeFile(outputFile, diagram, 'utf-8');
190190
console.log(`Workflow diagram written to: ${outputFile}`);
191191
} else {

src/handshake/protocol.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { v4 as uuidv4 } from 'uuid';
21
import { HandshakeMarker, HandoffState, ValidationResult } from './types';
32
import { HandoffStorage } from '../storage/HandoffStorage';
43
import { ATOMIntegration } from '../integrations/ATOMIntegration';
4+
import { randomUUID } from 'crypto';
55

66
/**
77
* Main HandshakeProtocol class for managing multi-agent handoffs
@@ -29,17 +29,14 @@ export class HandshakeProtocol {
2929
sessionId: string,
3030
coherenceScore?: number
3131
): Promise<HandshakeMarker> {
32-
// Generate UUID using a more Jest-friendly approach
33-
const uuid = require('crypto').randomUUID();
34-
3532
const marker: HandshakeMarker = {
36-
id: uuid,
33+
id: randomUUID(),
3734
timestamp: new Date().toISOString(),
3835
fromAgent,
3936
toAgent,
4037
state,
4138
context,
42-
atomTrailId: `ATOM-${require('crypto').randomUUID()}`,
39+
atomTrailId: `ATOM-${randomUUID()}`,
4340
coherenceScore,
4441
sessionId
4542
};

src/integrations/ATOMIntegration.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { HandshakeMarker } from '../handshake/types';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
24

35
/**
46
* ATOM Trail integration interface
@@ -37,9 +39,6 @@ export class ATOMIntegration {
3739

3840
// For now, we'll create a simple log file
3941
// In a real implementation, this would integrate with an existing ATOM trail system
40-
const fs = require('fs');
41-
const path = require('path');
42-
4342
await fs.promises.mkdir(this.atomDir, { recursive: true });
4443

4544
const atomFile = path.join(this.atomDir, `${marker.sessionId}.atom.jsonl`);
@@ -51,9 +50,6 @@ export class ATOMIntegration {
5150
* Get ATOM entries for a session
5251
*/
5352
async getEntries(sessionId: string): Promise<ATOMEntry[]> {
54-
const fs = require('fs');
55-
const path = require('path');
56-
5753
const atomFile = path.join(this.atomDir, `${sessionId}.atom.jsonl`);
5854

5955
try {

0 commit comments

Comments
 (0)