@@ -40,8 +40,11 @@ export interface SubagentResponse {
4040export class ClaudeCodeSubagentClient {
4141 private tempDir : string ;
4242 private activeSubagents : Map < string , AbortController > = new Map ( ) ;
43+ private mockMode : boolean ;
4344
44- constructor ( ) {
45+ constructor ( mockMode : boolean = true ) { // Default to mock mode for testing
46+ this . mockMode = mockMode ;
47+
4548 // Create temp directory for subagent communication
4649 this . tempDir = path . join ( os . tmpdir ( ) , 'stackmemory-rlm' ) ;
4750 if ( ! fs . existsSync ( this . tempDir ) ) {
@@ -50,6 +53,7 @@ export class ClaudeCodeSubagentClient {
5053
5154 logger . info ( 'Claude Code Subagent Client initialized' , {
5255 tempDir : this . tempDir ,
56+ mockMode : this . mockMode ,
5357 } ) ;
5458 }
5559
@@ -64,8 +68,14 @@ export class ClaudeCodeSubagentClient {
6468 logger . info ( `Spawning ${ request . type } subagent` , {
6569 subagentId,
6670 task : request . task . slice ( 0 , 100 ) ,
71+ mockMode : this . mockMode ,
6772 } ) ;
6873
74+ // Return mock responses for testing
75+ if ( this . mockMode ) {
76+ return this . getMockResponse ( request , startTime , subagentId ) ;
77+ }
78+
6979 try {
7080 // Create subagent prompt based on type
7181 const prompt = this . buildSubagentPrompt ( request ) ;
@@ -361,6 +371,118 @@ echo '{"status": "completed", "type": "${request.type}"}' > "${resultFile}"
361371 }
362372 }
363373
374+ /**
375+ * Get mock response for testing
376+ */
377+ private async getMockResponse (
378+ request : SubagentRequest ,
379+ startTime : number ,
380+ subagentId : string
381+ ) : Promise < SubagentResponse > {
382+ // Simulate some processing time
383+ await new Promise ( resolve => setTimeout ( resolve , Math . random ( ) * 20 + 10 ) ) ;
384+
385+ const mockResponses : Record < string , any > = {
386+ planning : {
387+ tasks : [
388+ { id : 'task-1' , name : 'Analyze requirements' , type : 'analysis' } ,
389+ { id : 'task-2' , name : 'Design solution' , type : 'design' } ,
390+ { id : 'task-3' , name : 'Implement solution' , type : 'implementation' } ,
391+ ] ,
392+ dependencies : [ ] ,
393+ estimated_time : 300 ,
394+ } ,
395+
396+ code : {
397+ implementation : `function greetUser(name: string): string {
398+ if (!name || typeof name !== 'string') {
399+ throw new Error('Invalid name parameter');
400+ }
401+ return \`Hello, \${name}!\`;
402+ }` ,
403+ files_modified : [ 'src/greet.ts' ] ,
404+ lines_added : 6 ,
405+ lines_removed : 0 ,
406+ } ,
407+
408+ testing : {
409+ tests : [
410+ {
411+ name : 'greetUser should return greeting' ,
412+ code : `test('greetUser should return greeting', () => {
413+ expect(greetUser('Alice')).toBe('Hello, Alice!');
414+ });` ,
415+ type : 'unit' ,
416+ } ,
417+ ] ,
418+ coverage : { lines : 100 , branches : 100 , functions : 100 } ,
419+ } ,
420+
421+ linting : {
422+ issues : [ ] ,
423+ fixes : [ ] ,
424+ passed : true ,
425+ } ,
426+
427+ review : {
428+ quality : 0.85 ,
429+ issues : [
430+ 'Consider adding JSDoc comments' ,
431+ 'Could add more edge case tests' ,
432+ ] ,
433+ suggestions : [
434+ 'Add documentation for the function' ,
435+ 'Consider adding internationalization support' ,
436+ 'Add performance tests for large inputs' ,
437+ ] ,
438+ improvements : [ ] ,
439+ } ,
440+
441+ improve : {
442+ improved_code : `/**
443+ * Greets a user with their name
444+ * @param name - The name of the user to greet
445+ * @returns A greeting message
446+ * @throws {Error} If name is invalid
447+ */
448+ function greetUser(name: string): string {
449+ if (!name || typeof name !== 'string') {
450+ throw new Error('Invalid name parameter: name must be a non-empty string');
451+ }
452+ return \`Hello, \${name}!\`;
453+ }` ,
454+ changes_made : [
455+ 'Added JSDoc documentation' ,
456+ 'Improved error message' ,
457+ ] ,
458+ } ,
459+
460+ context : {
461+ relevant_files : [ 'src/greet.ts' , 'test/greet.test.ts' ] ,
462+ patterns : [ 'greeting functions' , 'input validation' ] ,
463+ dependencies : [ ] ,
464+ } ,
465+
466+ publish : {
467+ version : '1.0.0' ,
468+ changelog : 'Initial release' ,
469+ published : false ,
470+ reason : 'Mock mode - no actual publishing' ,
471+ } ,
472+ } ;
473+
474+ const result = mockResponses [ request . type ] || { } ;
475+
476+ return {
477+ success : true ,
478+ result,
479+ output : `Mock ${ request . type } subagent completed successfully` ,
480+ duration : Date . now ( ) - startTime ,
481+ subagentType : request . type ,
482+ tokens : this . estimateTokens ( JSON . stringify ( result ) ) ,
483+ } ;
484+ }
485+
364486 /**
365487 * Estimate token usage
366488 */
0 commit comments