MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / handleInitializationFlowLocally

Function handleInitializationFlowLocally

cli/src/commands/init.ts:56–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54]
55
56export function handleInitializationFlowLocally(): {
57 postUserMessage: PostUserMessageFn
58} {
59 const projectRoot = getProjectRoot()
60 const knowledgePath = path.join(projectRoot, PRIMARY_KNOWLEDGE_FILE_NAME)
61 const messages: string[] = []
62
63 if (existsSync(knowledgePath)) {
64 messages.push(`📋 \`${PRIMARY_KNOWLEDGE_FILE_NAME}\` already exists.`)
65 } else {
66 writeFileSync(knowledgePath, INITIAL_KNOWLEDGE_FILE)
67 messages.push(`✅ Created \`${PRIMARY_KNOWLEDGE_FILE_NAME}\``)
68
69 // Track knowledge file creation
70 trackEvent(AnalyticsEvent.KNOWLEDGE_FILE_UPDATED, {
71 action: 'created',
72 fileName: PRIMARY_KNOWLEDGE_FILE_NAME,
73 fileSizeBytes: Buffer.byteLength(INITIAL_KNOWLEDGE_FILE, 'utf8'),
74 })
75 }
76
77 const agentsDir = path.join(projectRoot, '.agents')
78 const agentsTypesDir = path.join(agentsDir, 'types')
79
80 if (existsSync(agentsDir)) {
81 messages.push('📋 `.agents/` already exists.')
82 } else {
83 mkdirSync(agentsDir, { recursive: true })
84 messages.push('✅ Created `.agents/`')
85 }
86
87 if (existsSync(agentsTypesDir)) {
88 messages.push('📋 `.agents/types/` already exists.')
89 } else {
90 mkdirSync(agentsTypesDir, { recursive: true })
91 messages.push('✅ Created `.agents/types/`')
92 }
93
94 for (const { fileName, source } of COMMON_TYPE_FILES) {
95 const targetPath = path.join(agentsTypesDir, fileName)
96 if (existsSync(targetPath)) {
97 messages.push(`📋 \`.agents/types/${fileName}\` already exists.`)
98 continue
99 }
100
101 try {
102 if (!source || source.trim().length === 0) {
103 throw new Error('Source content is empty')
104 }
105 writeFileSync(targetPath, source)
106 messages.push(`✅ Copied \`.agents/types/${fileName}\``)
107 } catch (error) {
108 messages.push(
109 `⚠️ Failed to copy \`.agents/types/${fileName}\`: ${
110 error instanceof Error ? error.message : String(error ?? 'Unknown')
111 }`,
112 )
113 }

Callers 2

init.test.tsFile · 0.90

Calls 2

getProjectRootFunction · 0.90
trackEventFunction · 0.90

Tested by

no test coverage detected