返回 last30days-skill
runtime.md
根目录 / skills / last30days / references / runtime.md
1 # Runtime and configuration
2
3 Read before any engine command. Bind `SKILL_DIR` to the loaded root SKILL.md before running these snippets. A reference directory is never an install root.
4
5 # STEP 0: STALE-CLONE SELF-CHECK — RUN BEFORE READING BELOW
6
7 Before reading anything else in this file, check whether you loaded SKILL.md from the one known stale-clone location: Claude Code's marketplaces directory.
8
9 **Run this check:**
10
11 ```bash
12 CLAUDE_CACHE_LATEST=$(find "$HOME/.claude/plugins/cache/last30days-skill/last30days" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sort -V | tail -1)
13 # Two cache layouts ship in the wild — nested ({version}/skills/last30days/SKILL.md)
14 # and flat ({version}/SKILL.md). Resolve to whichever shape actually exists.
15 CLAUDE_CACHE_SKILL_MD=""
16 if [ -n "$CLAUDE_CACHE_LATEST" ]; then
17 if [ -f "$CLAUDE_CACHE_LATEST/skills/last30days/SKILL.md" ]; then
18 CLAUDE_CACHE_SKILL_MD="$CLAUDE_CACHE_LATEST/skills/last30days/SKILL.md"
19 elif [ -f "$CLAUDE_CACHE_LATEST/SKILL.md" ]; then
20 CLAUDE_CACHE_SKILL_MD="$CLAUDE_CACHE_LATEST/SKILL.md"
21 fi
22 fi
23 echo "CLAUDE_CACHE_SKILL_MD=$CLAUDE_CACHE_SKILL_MD"
24 ```
25
26 If the loaded root SKILL.md path contains `/.claude/plugins/marketplaces/` AND `$CLAUDE_CACHE_SKILL_MD` is non-empty, STOP and re-read `$CLAUDE_CACHE_SKILL_MD` before proceeding. Otherwise the SKILL.md you have is fine — continue.
27
28 **Other install paths are fine:** `~/.codex/skills/`, `~/.agents/skills/`, an `npx skills add` install dir, or a repo checkout are all valid load points - the root `SKILL_DIR` binding picks them up. Do NOT abort or hop on those paths.
29
30 ---
31
32
33 ## Runtime Preflight
34
35 Before running any `last30days.py` command in this skill, resolve a Python 3.12+ interpreter once and keep it in `LAST30DAYS_PYTHON`:
36
37 ```bash
38 try_last30days_python() {
39 candidate="${1}"
40 [ -n "$candidate" ] || return 1
41 if [ -x "$candidate" ]; then
42 :
43 elif command -v "$candidate" >/dev/null 2>&1; then
44 :
45 else
46 return 1
47 fi
48 "$candidate" -I -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 12) else 1)' || return 1
49 LAST30DAYS_PYTHON="$candidate"
50 return 0
51 }
52
53 windows_path_to_unix() {
54 path="${1}"
55 [ -n "$path" ] || return 1
56 if command -v cygpath >/dev/null 2>&1; then
57 cygpath -u "$path"
58 else
59 printf '%s\n' "$path"
60 fi
61 }
62
63 if [ -z "${LAST30DAYS_PYTHON:-}" ]; then
64 while IFS= read -r windows_python_root; do
65 [ -n "$windows_python_root" ] && [ -d "$windows_python_root" ] || continue
66 while IFS= read -r py; do
67 try_last30days_python "$py" && break 2
68 done <<EOF_PYTHON_CANDIDATES
69 $(find "$windows_python_root" -maxdepth 2 -type f -iname python.exe 2>/dev/null | sort -r)
70 EOF_PYTHON_CANDIDATES
71 done <<EOF_WINDOWS_PYTHON_ROOTS
72 $([ -n "${LOCALAPPDATA:-}" ] && printf '%s\n' "$(windows_path_to_unix "$LOCALAPPDATA")/Programs/Python")
73 $([ -n "${ProgramFiles:-}" ] && windows_path_to_unix "$ProgramFiles")
74 $([ -n "${PROGRAMFILES:-}" ] && windows_path_to_unix "$PROGRAMFILES")
75 $(program_files_x86="$(printenv 'ProgramFiles(x86)' 2>/dev/null || true)"; [ -n "$program_files_x86" ] && windows_path_to_unix "$program_files_x86")
76 EOF_WINDOWS_PYTHON_ROOTS
77 fi
78
79 if [ -z "${LAST30DAYS_PYTHON:-}" ]; then
80 for py in python3.14 python3.13 python3.12 python3 python; do
81 try_last30days_python "$py" && break
82 done
83 fi
84
85 # uv fallback: on hosts without a system 3.12 but with `uv` on PATH (most agent
86 # sandboxes: Cowork, Codex, etc.), provision a managed 3.12 automatically instead
87 # of hard-failing. No-op when uv is absent — those hosts still hit the error below.
88 if [ -z "${LAST30DAYS_PYTHON:-}" ] && command -v uv >/dev/null 2>&1; then
89 uv_py="$(uv python find '>=3.12' 2>/dev/null)"
90 if [ -z "$uv_py" ] || [ ! -x "$uv_py" ]; then
91 echo "NOTE: no Python 3.12+ found; installing a managed CPython 3.12 via uv (~28MB, one-time)." >&2
92 if UV_HTTP_TIMEOUT=30 uv python install 3.12 >/dev/null 2>&1; then
93 uv_py="$(uv python find '>=3.12' 2>/dev/null)"
94 else
95 echo "WARN: 'uv python install 3.12' failed (network, disk space, or proxy?); falling through to the version-gate error below." >&2
96 fi
97 fi
98 try_last30days_python "$uv_py"
99 fi
100
101 if [ -z "${LAST30DAYS_PYTHON:-}" ]; then
102 echo "ERROR: last30days v4 requires Python 3.12+. Install Python 3.12+ or set LAST30DAYS_PYTHON to a supported interpreter." >&2
103 exit 1
104 fi
105
106 "${LAST30DAYS_PYTHON}" -I -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 12) else 1)' || {
107 echo "ERROR: LAST30DAYS_PYTHON must point to Python 3.12+." >&2
108 exit 1
109 }
110
111 last30days_python_path="$(command -v "$LAST30DAYS_PYTHON")" || exit 1
112 case "$last30days_python_path" in
113 /*) LAST30DAYS_PYTHON="$last30days_python_path" ;;
114 */*) last30days_python_dir="$(cd -P -- "${last30days_python_path%/*}" && pwd -P)" || exit 1
115 LAST30DAYS_PYTHON="$last30days_python_dir/${last30days_python_path##*/}" ;;
116 *) echo "ERROR: selected Python must resolve to an executable path." >&2; exit 1 ;;
117 esac
118 export LAST30DAYS_PYTHON
119 "${LAST30DAYS_PYTHON}" -I -c 'import os, shlex; print("LAST30DAYS_PYTHON=" + shlex.quote(os.environ["LAST30DAYS_PYTHON"]))'
120
121 ```
122
123 **PYTHON VERSION GATE — when the Runtime Preflight Bash block above exits with a Python version error:**
124
125 If the preflight script (including the uv fallback above) emits `ERROR: last30days v4 requires Python 3.12+` (or `LAST30DAYS_PYTHON must point to Python 3.12+`) and exits, you MUST:
126
127 1. Display this message to the user:
128 > "The last30days engine needs Python 3.12+. Your system has an older version. Install it with one command:
129 > - **Mac:** `brew install python@3.12`
130 > - **Windows:** `winget install Python.Python.3.12`
131 > - **Linux:** `sudo apt install python3.12` (or `pyenv install 3.12`)
132 >
133 > Then re-run `/last30days <your topic>` and the setup wizard will configure everything automatically."
134 2. **Stop.** Do not attempt research. Do not fall back to WebSearch-only synthesis.
135
136 WebSearch-only synthesis is not equivalent to running the engine — it misses Reddit community data, X/Twitter timelines, YouTube transcripts, TikTok, and Polymarket. Presenting it without disclosure misleads the user about what was actually searched. This is the same category of failure as a WebSearch-only run with no engine footer.
137
138 **Native-search signal (web coverage).** If you (the hosting model) have your own web-search tool available, export `LAST30DAYS_NATIVE_SEARCH=1` in the same shell before invoking the engine:
139
140 ```bash
141 export LAST30DAYS_NATIVE_SEARCH=1 # ONLY when you have a native web-search tool
142 ```
143
144 Your host search is better than the engine's keyless web fallback, so this tells the engine to skip that fallback and leave general web to you (you already run web-search supplements in Step 2). If you have NO web-search tool in the agent session, do **not** set this: the engine's keyless web floor supplies general-web coverage automatically. The rule is capability-based, not host-name-based — set it only when you genuinely have a better search, never to suppress the floor on a host that has nothing else.
145
146 ## Save-directory resolution
147
148 After interpreter bootstrap, resolve the save directory once before the first engine operation that needs it. If the user supplied a one-off directory, add `--save-dir="<requested directory>"` to the resolver command below before running it. Remove any duplicate save-directory flag from the later research arguments. Never source a `.env` file.
149
150 ```bash
151 LAST30DAYS_MEMORY_DIR="$("${LAST30DAYS_PYTHON}" "${SKILL_DIR}/scripts/last30days.py" --resolve-save-dir)" || exit
152 printf 'Resolved save directory: <%s>\n' "$LAST30DAYS_MEMORY_DIR" >&2
153 ```
154
155 Capture that exact value, including an empty string. Later library, discovery, and research recipes use this captured value and do not resolve it again. When shell calls do not share variables, restore the captured value explicitly. All discovery legs use the same value even if configuration or working directory changes.
156
157 ## Configuration
158
159 Set `LAST30DAYS_MEMORY_DIR` in the process environment, trusted project config, or global `~/.config/last30days/.env` to choose where raw research files are saved. Resolution follows that order after an explicit `--save-dir`. Only an absent setting defaults the skill to `~/Documents/Last30Days`; an explicitly empty value disables research file saves. The engine creates a nonempty directory on first save.
160
161 The engine reads `LAST30DAYS_MEMORY_DIR` from either the process env or `~/.config/last30days/.env`, so direct CLI invocations (`python3 scripts/last30days.py ...`) without `--save-dir` will still save when the env var is set. Mirrors the `LAST30DAYS_STORE` env-or-flag convention. Explicit `--save-dir` always wins.
162
163 When both `LAST30DAYS_API_KEY` and `LAST30DAYS_API_BASE` are set, and `LAST30DAYS_API_MODE` is not `proxy`, the engine routes ordinary research through the configured remote API. Leave either variable unset to use local sources. A configured `--corpus` / `LAST30DAYS_CORPUS_DIRS`, `--mock`, and `--deep-research` use the local engine. An explicit `--perplexity-search-type` uses the local engine when a direct `PERPLEXITY_API_KEY` is available. Without a direct key, the run stays hosted and reports that it skipped that option. A value set only through `LAST30DAYS_PERPLEXITY_SEARCH_TYPE` also keeps hosted routing.
164
165 For hosted research, pass the topic with optional `--quick`, `--deep`, and `--register`. The API chooses the sources and synthesizes the result. Use compact or Markdown output, or `--emit=json --json-profile=raw` for the server's JSON. Explicit date bounds, source restrictions, local plans, targeting flags, and HTML requests exit 2 before submission. Use the local engine when the request needs those controls. Per-source keys and setup-wizard credentials are unnecessary for a hosted search.
166
167 Hosted progress streams on stderr and the synthesized report prints on stdout. Exit 3 means the API requested clarification. Present its question and options, then rerun the same topic with `--clarify-angle "<query>"`, using the query printed beside the option the user chose, or with `--clarify-broadly` when the user wants the topic run as asked. A failed hosted run prints the server's failure reason. When the hosted engine's major version differs from the local skill's, the engine prints one notice on stderr; relay it if the user asks why results differ from a local run. If the backend returns HTTP 402, relay the reported balance, required credits, and billing link verbatim. Wait for the user's direction before attempting a different search.
168
169 With `LAST30DAYS_API_MODE=proxy` plus the same key and base, research runs on the local engine with every flag, and only paid provider calls the user has no key for (ScrapeCreators, xAI, Serper, Parallel) go through the API key's metered proxy. Free sources never touch it, and a provider key the user set wins for that provider. The emoji footer ends with a `💳 API key:` line giving the credits this run charged; relay it with the footer. When the key runs out of credits or hits its hourly ceiling, the engine prints one line with the billing link, skips paid sources for the rest of the run, and still renders the free-source report.
170
171 **Developer-only eval capture:** `--record-fixtures <dir>` is a hidden direct-engine flag for maintaining the deterministic research-quality suite. It records scrubbed HTTP and CLI-adapter responses to `<dir>/http.json`; it is never part of the user-facing slash-command invocation. Follow `docs/reference/eval.md` for fixture review, replay, and baseline rules.
172
172 lines MARKDOWN