修正 role 記憶同意與睡眠排程安裝 #10

Merged
admin merged 3 commits from develop into master 2026-07-28 05:36:13 +00:00
Showing only changes of commit 294a2c1e1c - Show all commits
+27 -3
View File
@@ -6,7 +6,7 @@
# 連結/抽象化/提取線索)→ 壓縮歸檔 → 日常與其他依使用頻率與優先度遺忘。
# 另提供 --catchupcron 未執行時的補跑)、--force(手動立即整理)、
# --install-cron--remove-cron(排程安裝與移除)、--status(狀態)。
# 更新時間:2026/07/28 12:40:24
# 更新時間:2026/07/28 12:59:41
# 相依:bash、node、任一 headless CLI、crontab(僅排程安裝需要)、
# 同目錄的 role_lib.sh 與 memory.js。
# 退出碼:0 成功或無事可做;1 參數錯誤或整理失敗(cron 觸發時不影響使用者)。
@@ -137,7 +137,7 @@ EOF_PROMPT
}
# ------------------------------------------------------------------------------
# 排程安裝:cron 環境沒有互動 shell 的環境變數,需把必要變數與 PATH 一併寫入
# 排程安裝:cron 環境沒有互動 shell 的環境變數,需把必要變數與精簡 PATH 一併寫入
# ------------------------------------------------------------------------------
cron_quote() {
@@ -146,9 +146,33 @@ cron_quote() {
printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g; s/%/\\\\%/g")"
}
cron_path_append() {
# 把單一路徑加入 PATH 清單並去重;cron 單行過長時會拒收 crontab。
local list="$1" item="$2"
[ -n "$item" ] || { printf '%s' "$list"; return 0; }
case ":${list}:" in
*":${item}:"*) printf '%s' "$list" ;;
*) printf '%s%s%s' "$list" "${list:+:}" "$item" ;;
esac
}
cron_path() {
# cron 只需要系統工具、node 與摘要 CLI;避免把互動 shell 的超長 PATH 原樣寫入。
local value="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
local command_path cli
command_path="$(command -v node 2>/dev/null || true)"
[ -n "$command_path" ] && value="$(cron_path_append "$value" "$(dirname "$command_path")")"
cli="$(role_select_cli 2>/dev/null || true)"
if [ -n "$cli" ]; then
command_path="$(command -v "$cli" 2>/dev/null || true)"
[ -n "$command_path" ] && value="$(cron_path_append "$value" "$(dirname "$command_path")")"
fi
printf '%s' "$value"
}
cron_line() {
# 組出 crontab 條目:睡眠時段內每小時檢查一次
local env_prefix="PATH=$(cron_quote "$PATH")"
local env_prefix="PATH=$(cron_quote "$(cron_path)")"
local var
for var in ROLE_ENABLED ROLE_NAME ROLE_HOME ROLE_MEMORY_HOME ROLE_CLI ROLE_MODEL ROLE_SLEEP_START ROLE_SLEEP_END ROLE_SCOPE; do
if [ -n "${!var:-}" ]; then