Feature: Add todo pattern detection and auto-capture system
This commit is contained in:
26
lib/detect-todo.js
Normal file
26
lib/detect-todo.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Detect "todo [task]" pattern in text
|
||||||
|
* Usage: node detect-todo.js "I need to todo [Setup CI/CD]"
|
||||||
|
* Output: Setup CI/CD (or empty if no match)
|
||||||
|
*/
|
||||||
|
|
||||||
|
const text = process.argv[2] || '';
|
||||||
|
|
||||||
|
// Match: "todo [text]" or "todo: text" or "todo text"
|
||||||
|
const patterns = [
|
||||||
|
/\btodo\s*\[\s*([^\]]+)\s*\]/i, // todo [text]
|
||||||
|
/\btodo:\s*([^\n]+?)(?:\s*$|\s*[.!?])/i, // todo: text or todo: text.
|
||||||
|
/\btodo\s+([^\n.!?]+?)(?:\s*$|\s*[.!?])/i, // todo text
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const pattern of patterns) {
|
||||||
|
const match = text.match(pattern);
|
||||||
|
if (match && match[1]) {
|
||||||
|
console.log(match[1].trim());
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No match
|
||||||
|
process.exit(1);
|
||||||
48
lib/process-todo.sh
Normal file
48
lib/process-todo.sh
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Process "todo [task]" patterns in a text string
|
||||||
|
# If found: add to Tududi and output status
|
||||||
|
# If not found: exit silently with code 0
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
input_text="${1:-}"
|
||||||
|
dry_run="${2:-false}"
|
||||||
|
|
||||||
|
if [ -z "$input_text" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect todo pattern using Node script
|
||||||
|
detect_script="$(dirname "$0")/detect-todo.js"
|
||||||
|
task_name=$(node "$detect_script" "$input_text" 2>/dev/null) || exit 0
|
||||||
|
|
||||||
|
# If we get here, task_name was found
|
||||||
|
if [ "$dry_run" == "true" ]; then
|
||||||
|
echo "🎯 Would add task: $task_name"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add to Tududi
|
||||||
|
API_URL="${TUDUDI_API_URL:-https://todo.dilain.com/api/v1}"
|
||||||
|
API_KEY="${TUDUDI_API_KEY:-}"
|
||||||
|
|
||||||
|
if [ -z "$API_KEY" ]; then
|
||||||
|
echo "⚠️ TUDUDI_API_KEY not set, skipping task capture"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
response=$(curl -s -X POST \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"name\":\"$task_name\"}" \
|
||||||
|
"$API_URL/task")
|
||||||
|
|
||||||
|
task_uid=$(echo "$response" | jq -r '.uid // empty' 2>/dev/null) || task_uid=""
|
||||||
|
|
||||||
|
if [ -n "$task_uid" ]; then
|
||||||
|
echo "✅ Added to Tududi: $task_name"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "⚠️ Failed to add task: $task_name"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user