bump to 0.7.1
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
# echo.sh delete <path> # DELETE (destructive; explicit use only)
|
||||
# echo.sh lock <owner-id> # acquire advisory lock (exit 75 if held by someone else & fresh)
|
||||
# echo.sh unlock <owner-id> # release advisory lock if owned by <owner-id>
|
||||
# echo.sh scope show # print active scope, its freshness, and sessions-since
|
||||
# echo.sh scope set "<text>" # switch scope atomically (history + replace + stamp scope_updated)
|
||||
#
|
||||
# Exit codes: 0 ok · 44 not-found(404) · 75 lock-held · 2 usage · 1 other HTTP/transport error.
|
||||
|
||||
@@ -194,6 +196,50 @@ case "$cmd" in
|
||||
[ "$HTTP" = "404" ] || _check "unlock"
|
||||
echo "ok: unlocked" ;;
|
||||
|
||||
scope)
|
||||
# scope show | scope set "<new scope text>"
|
||||
# 'set' archives the prior scope to ## Scope History, replaces ## Scope, and stamps
|
||||
# the scope_updated freshness timestamp — one command instead of three error-prone PATCHes.
|
||||
sub="${1:-show}"; shift || true
|
||||
ccpath="_agent/context/current-context.md"
|
||||
case "$sub" in
|
||||
show)
|
||||
_curl GET "$(_vault_url "$ccpath")"; _check "scope show"
|
||||
cur="$RESP"
|
||||
echo "── Active scope ──"
|
||||
awk '/^## Scope[[:space:]]*$/{f=1;next} /^## /{if(f)exit} f' "$cur"
|
||||
su="$(sed -n 's/^scope_updated:[[:space:]]*//p' "$cur" | head -1)"
|
||||
su="${su//\"/}"
|
||||
echo "scope_updated: ${su:-<missing — drift cannot be detected; run scope set or repair>}"
|
||||
_curl GET "$(_vault_url "_agent/sessions/")"
|
||||
if [ "$HTTP" = "200" ] && [ -n "$su" ]; then
|
||||
n="$(python3 -c "import json,sys;f=json.load(open('$RESP'))['files'];print(sum(1 for x in f if x.endswith('.md') and x[:10]>'$su'))" 2>/dev/null || echo '?')"
|
||||
echo "sessions logged since: ${n}"
|
||||
fi ;;
|
||||
set)
|
||||
[ $# -ge 1 ] || die "scope set needs the new scope text"
|
||||
new="$1"
|
||||
_curl GET "$(_vault_url "$ccpath")"; _check "scope set(read)"
|
||||
prior="$(awk '/^## Scope[[:space:]]*$/{f=1;next} /^## /{if(f)exit} f' "$RESP" \
|
||||
| tr '\n' ' ' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | cut -c1-140)"
|
||||
BODY="$(mktemp)"; printf -- '- %s: %s\n' "$(_today)" "${prior:-(prior scope)}" > "$BODY"
|
||||
_curl PATCH "$(_vault_url "$ccpath")" -H 'Operation: prepend' -H 'Target-Type: heading' \
|
||||
-H 'Target: Current Context::Scope History' -H 'Content-Type: text/markdown' --data-binary @"$BODY"
|
||||
_check "scope set(history)"
|
||||
BODY="$(mktemp)"; printf '%s\n' "$new" > "$BODY"
|
||||
_curl PATCH "$(_vault_url "$ccpath")" -H 'Operation: replace' -H 'Target-Type: heading' \
|
||||
-H 'Target: Current Context::Scope' -H 'Content-Type: text/markdown' --data-binary @"$BODY"
|
||||
_check "scope set(replace)"
|
||||
BODY="$(mktemp)"; printf '"%s"' "$(_today)" > "$BODY"
|
||||
_curl PATCH "$(_vault_url "$ccpath")" -H 'Operation: replace' -H 'Target-Type: frontmatter' \
|
||||
-H 'Target: scope_updated' -H 'Content-Type: application/json' --data-binary @"$BODY"
|
||||
if [ "${HTTP:-000}" -ge 400 ]; then
|
||||
die "scope set: body switched, but scope_updated frontmatter is missing (run bootstrap.sh repair to add it) [HTTP $HTTP]"
|
||||
fi
|
||||
echo "ok: scope switched (prior archived to Scope History; scope_updated=$(_today))" ;;
|
||||
*) die "scope: use 'show' or 'set \"<text>\"'" ;;
|
||||
esac ;;
|
||||
|
||||
""|-h|--help|help) usage ;;
|
||||
*) die "unknown command '$cmd' (try: get map ls search put post append patch fm bump delete lock unlock)" ;;
|
||||
*) die "unknown command '$cmd' (try: get map ls search put post append patch fm bump delete lock unlock scope)" ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user