tools: add task_plan and task_complete as shell/python scripts
Replaces the removed built-in task server. Plans are written to $OLLIE_9MOUNT/pl/ (persistent, shared across sessions). Scripts live in the tools directory and are invoked via execute_tool. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f03bf6b629
commit
e4aaa25991
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
# description: Mark a plan step complete; returns remaining steps
|
||||
# Args: <plan-file> <step-substring>
|
||||
import sys, os, re
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("usage: task_complete <plan-file> <step-substring>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
ollie = os.environ.get('OLLIE_9MOUNT', os.path.expanduser('~/mnt/ollie'))
|
||||
plan_dir = os.path.join(ollie, 'pl')
|
||||
|
||||
# Accept either a bare filename or a path; always resolve against plan_dir
|
||||
filepath = os.path.join(plan_dir, os.path.basename(sys.argv[1]))
|
||||
substring = sys.argv[2].lower()
|
||||
|
||||
with open(filepath) as f:
|
||||
lines = f.readlines()
|
||||
|
||||
matched = False
|
||||
for i, line in enumerate(lines):
|
||||
if re.match(r'^- \[ \] ', line) and substring in line.lower():
|
||||
lines[i] = line.replace('- [ ] ', '- [x] ', 1)
|
||||
matched = True
|
||||
break
|
||||
|
||||
if not matched:
|
||||
print(f"no unchecked step matching {sys.argv[2]!r}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
remaining = [line[6:].strip() for line in lines if re.match(r'^- \[ \] ', line)]
|
||||
|
||||
def restat(path, status):
|
||||
return re.sub(r'__(todo|wip|complete)\.md$', f'__{status}.md', path)
|
||||
|
||||
if '__todo' in filepath:
|
||||
newpath = restat(filepath, 'wip')
|
||||
elif not remaining and '__wip' in filepath:
|
||||
newpath = restat(filepath, 'complete')
|
||||
else:
|
||||
newpath = filepath
|
||||
|
||||
with open(filepath, 'w') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
if newpath != filepath:
|
||||
os.rename(filepath, newpath)
|
||||
|
||||
if remaining:
|
||||
print('\n'.join(f'- {s}' for s in remaining))
|
||||
else:
|
||||
print('all steps complete')
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
# description: Create a task plan with ordered steps as a markdown checklist
|
||||
# Args: <goal> <step1> [step2] ...
|
||||
# Output: relative path to the created plan file
|
||||
set -euo pipefail
|
||||
|
||||
OLLIE="${OLLIE_9MOUNT:-$HOME/mnt/ollie}"
|
||||
PLAN_DIR="$OLLIE/pl"
|
||||
|
||||
GOAL="${1:?usage: task_plan <goal> <step1> [step2] ...}"
|
||||
shift
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "error: at least one step required" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TIMESTAMP=$(date '+%Y%m%dT%H%M%S')
|
||||
UID8=$(cat /proc/sys/kernel/random/uuid 2>/dev/null | tr -d '-' | cut -c1-8 \
|
||||
|| od -A n -t x1 /dev/urandom | tr -d ' \n' | cut -c1-8)
|
||||
SLUG=$(printf '%s' "$GOAL" \
|
||||
| tr '[:upper:]' '[:lower:]' \
|
||||
| tr -cs 'a-z0-9' '-' \
|
||||
| sed 's/^-//;s/-$//' \
|
||||
| cut -c1-48)
|
||||
|
||||
FILENAME="${TIMESTAMP}_${UID8}--${SLUG}__todo.md"
|
||||
FILEPATH="$PLAN_DIR/$FILENAME"
|
||||
|
||||
{
|
||||
printf '# %s\n\n' "$GOAL"
|
||||
for step in "$@"; do
|
||||
printf '- [ ] %s\n' "$step"
|
||||
done
|
||||
} > "$FILEPATH"
|
||||
|
||||
echo "$FILENAME"
|
||||
Loading…
Reference in New Issue