Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(plugins): stop the installer aborting inside the credentials wizard (#4689)
t0saki75be3bd0f6c3
diff --git a/examples/memory-plugin-shared/install-tui.test.mjs b/examples/memory-plugin-shared/install-tui.test.mjsindex c89516439..85d4cb0eb 100644--- a/examples/memory-plugin-shared/install-tui.test.mjs+++ b/examples/memory-plugin-shared/install-tui.test.mjs@@ -56,6 +56,9 @@ installer_test_failureassert.match(result.stderr, /Exit status: 1/);assert.match(result.stderr, /Script line: [0-9]+/);assert.match(result.stderr, /Command: false/);+ // The handler restores the cursor on /dev/tty; with no controlling terminal+ // that redirection must not narrate itself ahead of the real diagnostic.+ assert.doesNotMatch(result.stderr, /\/dev\/tty/);});test("a pre-existing TRAE home directory keeps TRAE Desktop as the default", (t) => {@@ -152,3 +155,90 @@ printf '%s:%s:%s\\n' "$SELECTED_HARNESSES" "$(list_words "$CODEX_BINS")" "$(tui_assert.equal(result.status, 0, result.stderr);assert.equal(result.stdout.trim(), "codex:trae-cli:TraeCode CLI 2.0");});++test("keeping the stored API key leaves the wizard on its feet", () => {+ const result = runInstallerPrelude(`+tui_menu() { TUI_MENU_CHOICE=1; }+INTERACTIVE=1+exec 3< <(printf '\\n')+prompt_connection "https://example.invalid/openviking" "stored-key"+printf '%s|%s\\n' "$WIZ_URL" "$WIZ_KEY"+`);++ assert.equal(result.status, 0, result.stderr);+ assert.equal(+ result.stdout.trim().split("\n").pop(),+ "https://api.vikingdb.cn-beijing.volces.com/openviking|__OPENVIKING_KEEP__",+ );+});++test("the credentials step writes ovcli.conf when the stored key is kept", (t) => {+ const home = makeTempHome(t);+ const conf = join(home, "ovcli.conf");+ writeFileSync(conf, `${JSON.stringify({ url: "http://127.0.0.1:1933", api_key: "stored-key", output: "table" }, null, 2)}\n`);++ const result = runInstallerPrelude(`+tui_menu() { TUI_MENU_CHOICE=1; }+INTERACTIVE=1+OV_HOME=${JSON.stringify(home)}+OVCLI_CONF=${JSON.stringify(conf)}+exec 3< <(printf '\\n')+configure_ovcli+`);++ assert.equal(result.status, 0, result.stderr);+ assert.deepEqual(JSON.parse(readFileSync(conf, "utf8")), {+ url: "https://api.vikingdb.cn-beijing.volces.com/openviking",+ api_key: "stored-key",+ output: "table",+ });+});++test("menu digit shortcuts move the cursor instead of confirming", () => {+ // Confirming on the digit itself leaves the Enter most users press right+ // after it in the tty buffer, where the next prompt reads it as an empty+ // answer. Driving the real menus needs a pty, so pin the key handlers.+ const menuArm = /\[1-9\]\)([\s\S]*?);;/.exec(installerSource);+ assert.ok(menuArm, "tui_menu no longer has a [1-9] case arm");+ assert.doesNotMatch(menuArm[1], /\bbreak\b/);++ const chooseFormat = /^tui_choose_cli_format\(\) \{$[\s\S]*?^\}$/m.exec(installerSource);+ assert.ok(chooseFormat, "tui_choose_cli_format not found");+ assert.match(chooseFormat[0], /^ +1\) cursor=0 ;;$/m);+ assert.match(chooseFormat[0], /^ +2\) cursor=1 ;;$/m);+});++test("an empty element in a comma-separated list is skipped, not fatal", () => {+ // Assignments, like the call sites: a trailing comma used to make the loop --+ // and so the function -- exit 1, which `set -e` turned into an abort.+ const result = runInstallerPrelude(`+bins="$(normalize_bin_list "claude," claude)"+items="$(split_csv_list ",,seed, claude ,")"+harnesses="$(split_harnesses "claude,,CODEX,")"+printf '%s|%s|%s\\n' "$bins" "$items" "$harnesses"+`);++ assert.equal(result.status, 0, result.stderr);+ assert.equal(result.stdout.trim(), "claude|seed\nclaude|claude\ncodex");+});++test("the credentials step names the field it changed", (t) => {+ const home = makeTempHome(t);+ const conf = join(home, "ovcli.conf");+ const url = "https://api.vikingdb.cn-beijing.volces.com/openviking";+ writeFileSync(conf, `${JSON.stringify({ url, api_key: "stored-key" }, null, 2)}\n`);++ const result = runInstallerPrelude(`+tui_menu() { TUI_MENU_CHOICE=1; }+INTERACTIVE=1+OV_HOME=${JSON.stringify(home)}+OVCLI_CONF=${JSON.stringify(conf)}+exec 3< <(printf 'rotated-key\\n')+configure_ovcli+`);++ assert.equal(result.status, 0, result.stderr);+ assert.doesNotMatch(result.stdout, /Updated: url:/);+ assert.match(result.stdout, /Updated: api_key: stor…-key \(10\) -> rota…-key \(11\)/);+ assert.equal(JSON.parse(readFileSync(conf, "utf8")).api_key, "rotated-key");+});diff --git a/examples/memory-plugin-shared/install.sh b/examples/memory-plugin-shared/install.shindex c3e3f5601..61bbb7a39 100644--- a/examples/memory-plugin-shared/install.sh+++ b/examples/memory-plugin-shared/install.sh@@ -128,7 +128,7 @@ report_unexpected_error() { # report_unexpected_error <status> <line> <command>if [ "${BASH_SUBSHELL:-0}" -gt 0 ]; thenreturn "$status"fi- printf '\033[?25h' >/dev/tty 2>/dev/null || true+ printf '\033[?25h' 2>/dev/null >/dev/tty || trueprintf '\n' >&2err "$(t 'OpenViking installer stopped unexpectedly.' 'OpenViking 安装程序意外退出。')"printf ' %s: %s\n' "$(t 'Exit status' '状态码')" "$status" >&2@@ -255,7 +255,7 @@ tui_menu() { # tui_menu <title> <default-index> <option...> -> TUI_MENU_CHOICEfii=$((i + 1))done- printf '\r\033[K %s%s%s\n' "$CYAN" "$(t '↑/↓ move · 1-9 jump · enter confirm' '↑/↓ 移动 · 数字直选 · 回车确认')" "$RESET" >/dev/tty+ printf '\r\033[K %s%s%s\n' "$CYAN" "$(t '↑/↓ move · 1-9 jump · enter confirm' '↑/↓ 移动 · 数字跳转 · 回车确认')" "$RESET" >/dev/ttylines=$((n + 1))IFS= read -rsn1 key <&3 || key=""case "$key" in@@ -270,9 +270,11 @@ tui_menu() { # tui_menu <title> <default-index> <option...> -> TUI_MENU_CHOICEk) cursor=$(( (cursor + n - 1) % n )) ;;j) cursor=$(( (cursor + 1) % n )) ;;[1-9])+ # Jump only. Confirming on the digit leaves the Enter most users press+ # right after it in the tty buffer, where the next prompt reads it as+ # an empty answer.if [ "$key" -le "$n" ]; thencursor=$((key - 1))- breakfi;;''|$'\n'|$'\r') break ;;@@ -317,14 +319,20 @@ select_language() {split_harnesses() {printf '%s\n' "$1" | tr ',' '\n' | while IFS= read -r h; doh=$(printf '%s' "$h" | tr '[:upper:]' '[:lower:]' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')- [ -n "$h" ] && printf '%s\n' "$h"+ if [ -n "$h" ]; then+ printf '%s\n' "$h"+ fidone}split_csv_list() {printf '%s\n' "$1" | tr ',' '\n' | while IFS= read -r item; doitem=$(printf '%s' "$item" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')- [ -n "$item" ] && printf '%s\n' "$item"+ # An `&& ...` here would make an empty last element the loop's -- and so the+ # function's -- exit status, which `set -e` turns into an abort at the call.+ if [ -n "$item" ]; then+ printf '%s\n' "$item"+ fidone}@@ -811,8 +819,8 @@ tui_choose_cli_format() {esac;;k|j) cursor=$((1 - cursor)) ;;- 1) TUI_FORMAT_CHOICE="claude"; break ;;- 2) TUI_FORMAT_CHOICE="codex"; break ;;+ 1) cursor=0 ;;+ 2) cursor=1 ;;''|$'\n'|$'\r')if [ "$cursor" -eq 0 ]; then TUI_FORMAT_CHOICE="claude"; else TUI_FORMAT_CHOICE="codex"; fibreak@@ -1215,8 +1223,12 @@ prompt_connection() { # sets WIZ_URL / WIZ_KEY (WIZ_KEY may stay __OPENVIKING_KEelif [ -n "$reply" ]; thenWIZ_KEY="$reply"else+ # Not `[ -z ... ] && ...`: as the function's last command a false test makes+ # prompt_connection return 1, and `set -e` aborts the whole installer.WIZ_KEY="__OPENVIKING_KEEP__"- [ -z "$current_key" ] && WIZ_KEY=""+ if [ -z "$current_key" ]; then+ WIZ_KEY=""+ fifi}@@ -1272,9 +1284,12 @@ configure_ovcli() {cp "$OVCLI_CONF" "$OVCLI_CONF.bak.$(date +%s)"fijson_merge_ovcli "$OVCLI_CONF" "$url" "$key" "$account" "$user"- if [ "$url" != "$current_url" ] || { [ "$key" != "__OPENVIKING_KEEP__" ] && [ "$key" != "$current_key" ]; }; then+ if [ "$url" != "$current_url" ]; theninfo "$(t 'Updated:' '已更新:') url: ${current_url:-—} -> $url"fi+ if [ "$key" != "__OPENVIKING_KEEP__" ] && [ "$key" != "$current_key" ]; then+ info "$(t 'Updated:' '已更新:') api_key: $(mask_secret "$current_key") -> $(mask_secret "$key")"+ fiinfo "$(t 'Credentials ready:' '凭据已就绪:') $OVCLI_CONF"info "$(t 'Reconfigure later by re-running this installer.' '之后可重跑本安装脚本重新配置。')"}