Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/tools/manual-kpi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ test('still records an activity that arrived before stdin ended', async () => {
test('still treats a blank line as the end of input', async () => {
assert.deepEqual(activitiesFrom(await collect('Paired on the auth bug\n\n')), ['Paired on the auth bug'])
})

// Every line lands in one stdin chunk here, which is what a paste looks like.
test('keeps every activity when the lines arrive together rather than one at a time', async () => {
assert.deepEqual(activitiesFrom(await collect('Reviewed 3 PRs\nRan the release\nMentored a junior\ndone\n')), [
'Reviewed 3 PRs',
'Ran the release',
'Mentored a junior',
])
})
28 changes: 11 additions & 17 deletions src/tools/manual-kpi.tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ import { z } from 'zod'
import * as readline from 'readline'
import { logger, prompt } from '../utils/logger.js'

function promptUser(question: string): Promise<string> {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })

return new Promise((resolve) => {
rl.on('close', () => resolve(''))

rl.question(question, (answer) => {
resolve(answer.trim())

rl.close()
})
})
}

// Read activities from env var (GitHub Actions) or fall back to interactive readline (local terminal)
async function collectActivities(): Promise<string[]> {
const now = new Date().toISOString()
Expand All @@ -38,15 +24,23 @@ async function collectActivities(): Promise<string[]> {
prompt('📝 (Enter each activity on a new line)')
prompt('📝 Type "done" when finished.\n')

const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
const activities: string[] = []

while (true) {
const input = await promptUser(' > ')
rl.setPrompt(' > ')
rl.prompt()

for await (const line of rl) {
const input = line.trim()

if (input.toLowerCase() === 'done' || input === '') break
if (input.length > 0) activities.push(input)

activities.push(input)
rl.prompt()
}

rl.close()

prompt('──────────────────────────────────────────\n')

return activities
Expand Down
Loading