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

Function main

scripts/grant-credits.ts:32–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30}
31
32async function main() {
33 const rl = createInterface({ input: process.stdin, output: process.stdout })
34
35 try {
36 // 1. Get user by email or ID
37 const userInput = await prompt(rl, 'Enter user email or user ID: ')
38 if (!userInput) {
39 console.error('No input provided.')
40 process.exit(1)
41 }
42
43 const isEmail = userInput.includes('@')
44 const user = isEmail
45 ? await lookupUserByEmail(userInput)
46 : await lookupUserById(userInput)
47
48 if (!user) {
49 console.error(`User not found: ${userInput}`)
50 process.exit(1)
51 }
52
53 console.log(`\nFound user: ${user.name ?? '(no name)'} <${user.email}> (${user.id})`)
54
55 // 2. Get credit amount
56 const amountStr = await prompt(rl, 'Enter credit amount (integer): ')
57 const amount = parseInt(amountStr, 10)
58 if (isNaN(amount) || amount <= 0) {
59 console.error('Amount must be a positive integer.')
60 process.exit(1)
61 }
62
63 // 3. Get description
64 const description = await prompt(rl, 'Enter description: ')
65 if (!description) {
66 console.error('Description is required.')
67 process.exit(1)
68 }
69
70 // 4. Generate operation ID
71 const operationId = `admin-${user.id}-${generateCompactId()}`
72
73 // 5. Confirm
74 console.log('\n--- Credit Grant Summary ---')
75 console.log(` User: ${user.name ?? '(no name)'} <${user.email}>`)
76 console.log(` User ID: ${user.id}`)
77 console.log(` Amount: ${amount}`)
78 console.log(` Type: admin`)
79 console.log(` Priority: 50`)
80 console.log(` Expires: never`)
81 console.log(` Description: ${description}`)
82 console.log(` Operation ID: ${operationId}`)
83 console.log('----------------------------\n')
84
85 const confirm = await prompt(rl, 'Proceed? (y/N): ')
86 if (!/^[Yy]$/.test(confirm)) {
87 console.log('Aborted.')
88 process.exit(0)
89 }

Callers 1

grant-credits.tsFile · 0.70

Calls 6

generateCompactIdFunction · 0.90
promptFunction · 0.85
lookupUserByEmailFunction · 0.85
lookupUserByIdFunction · 0.85
insertMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected