-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscout.sh
More file actions
executable file
·105 lines (91 loc) · 3.11 KB
/
Copy pathscout.sh
File metadata and controls
executable file
·105 lines (91 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# Launch a Paper Scout reading-agent run.
#
# Usage: ./scout.sh <agent>
# agent – codex | kimi | qoder (add your own below)
#
# Optional:
# PAPER_SCOUT_NOTIFY_USER_ID Feishu/Lark open_id to notify when launch aborts.
#
# Runs the reading agent from workspace/ with the date-stamped prompt.txt as its
# trigger. Add new backends in the case statement below.
set -euo pipefail
agent="${1:-}"
if [[ -z "$agent" ]]; then
echo "Usage: $0 <agent>" >&2
echo "Supported agents: codex, kimi, qoder" >&2
exit 1
fi
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Ensure user-local CLI tools (e.g. huggingface-papers) are found before
# any environment-specific shadows (e.g. conda env's huggingface_hub hf).
if [[ -d "$HOME/.local/bin" ]]; then
case ":$PATH:" in
*:"$HOME/.local/bin":*) ;;
*) export PATH="$HOME/.local/bin:$PATH" ;;
esac
fi
notify_abort() {
local reason="$1"
local details="${2:-}"
echo "Paper Scout launch aborted: $reason" >&2
if [[ -n "$details" ]]; then
printf '%s\n' "$details" >&2
fi
if [[ -z "${PAPER_SCOUT_NOTIFY_USER_ID:-}" ]]; then
echo "PAPER_SCOUT_NOTIFY_USER_ID is unset; skipping Feishu abort notification." >&2
return
fi
if ! command -v lark-cli >/dev/null 2>&1; then
echo "lark-cli not found; skipping Feishu abort notification." >&2
return
fi
local branch host message
branch="$(git branch --show-current 2>/dev/null || printf 'unknown')"
host="$(hostname 2>/dev/null || printf 'unknown')"
message="$(printf 'Paper Scout launch aborted.\n\nReason: %s\nRepo: %s\nBranch: %s\nHost: %s' "$reason" "$repo_root" "$branch" "$host")"
if [[ -n "$details" ]]; then
message="$(printf '%s\n\n%s' "$message" "$details")"
fi
if ! lark-cli im +messages-send --as bot --user-id "$PAPER_SCOUT_NOTIFY_USER_ID" --text "$message" >/dev/null; then
echo "Failed to send Feishu abort notification." >&2
fi
}
cd "$repo_root"
status="$(git status --short)"
if [[ -n "$status" ]]; then
notify_abort "worktree is not clean before launch" "$status"
exit 1
fi
if [[ "$(git branch --show-current)" != "main" ]]; then
if ! git switch main; then
notify_abort "failed to switch to main before launch"
exit 1
fi
fi
cd "$repo_root/workspace"
today="$(date +%F)"
prompt="$(printf '今天是 %s。\n\n' "$today"; cat "$repo_root/prompt.txt")"
case "$agent" in
codex)
# Non-interactive / unattended: workspace-write sandbox, no approval prompts,
# network enabled (needed for web search, HF, Lark, etc.).
exec codex exec \
--sandbox workspace-write \
--ask-for-approval never \
-c 'sandbox_workspace_write.network_access=true' \
"$prompt"
;;
kimi)
exec kimi --afk -p "$prompt"
;;
qoder)
# -p = headless/print mode; --yolo = auto-confirm tool calls.
exec qodercli -p --yolo "$prompt"
;;
*)
echo "Unknown agent: $agent" >&2
echo "Supported agents: codex, kimi, qoder" >&2
exit 1
;;
esac