oasis_test_v2 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+ # Shared wrapper logic for CLI connectors.
3
+ #
4
+ # Source this from your connector wrapper and call oasis_resolve_bin + oasis_check_available.
5
+ # Before sourcing, set:
6
+ # OASIS_BIN_VAR — name of env var that holds the absolute binary path (e.g., "GH_BIN")
7
+ # OASIS_CMD_NAME — command name to find (e.g., "gh")
8
+ #
9
+ # Example:
10
+ # OASIS_BIN_VAR="GH_BIN"
11
+ # OASIS_CMD_NAME="gh"
12
+ # source "$(dirname "$(realpath "$0")")/../_base/wrapper-base.sh"
13
+ # oasis_resolve_bin
14
+ # oasis_check_available
15
+ # # Add connector-specific env injection here
16
+ # exec "$GH_BIN" "$@"
17
+
18
+ set -euo pipefail
19
+
20
+ # Resolve the real binary path (avoid recursion into self).
21
+ # If ${OASIS_BIN_VAR} is already set (injected by inject()), use it — unless it points
22
+ # back at this very wrapper. Otherwise scan PATH for the first executable that isn't us.
23
+ oasis_resolve_bin() {
24
+ local bin_var="${OASIS_BIN_VAR:?OASIS_BIN_VAR must be set}"
25
+ local cmd_name="${OASIS_CMD_NAME:?OASIS_CMD_NAME must be set}"
26
+
27
+ local SELF
28
+ SELF="$(realpath "$0" 2>/dev/null || echo "$0")"
29
+
30
+ # If already set by inject() AND executable on THIS machine, skip the PATH scan —
31
+ # but **only if it isn't this wrapper itself**.
32
+ #
33
+ # 为什么要查自指(2026-08-03 实测踩到):inject() 用 `which <cmd>` 在 **daemon 进程的
34
+ # PATH** 下解析真实二进制,而 daemon 的 PATH 可能被 agent 会话的 wrapper 目录污染
35
+ # (`oasis daemon start` 会把当时 shell 的 PATH 固化进 systemd unit;在 agent 会话里
36
+ # 触发更新就会把 /tmp/oasis-conn-* 带进去)。于是 GH_BIN 指向 wrapper 自己 →
37
+ # 这里的快路径直接 return → 后面 exec "$GH_BIN" 就是无限递归调用自身。
38
+ # 症状还特别误导:递归被 oasis_check_available 拦下,报的是「cli is upgrading」。
39
+ if [ -n "${!bin_var:-}" ] && [ -x "${!bin_var:-}" ] \
40
+ && [ "$(realpath "${!bin_var}" 2>/dev/null)" != "$SELF" ]; then
41
+ return 0
42
+ fi
43
+ # 空 / 不可执行 / 指向自己:清掉,让下面的 PATH 扫描重新填。
44
+ unset "$bin_var" 2>/dev/null || true
45
+
46
+ # Fallback: scan PATH for real binary (skip self to avoid recursion)
47
+ local candidate
48
+ while IFS= read -r dir; do
49
+ candidate="$dir/$cmd_name"
50
+ if [ -x "$candidate" ] && [ "$(realpath "$candidate" 2>/dev/null)" != "$SELF" ]; then
51
+ printf -v "$bin_var" '%s' "$candidate"
52
+ export "$bin_var"
53
+ return 0
54
+ fi
55
+ done <<< "$(echo "$PATH" | tr ':' '\n')"
56
+ }
57
+
58
+ # Check that the resolved binary is accessible and responds to --version.
59
+ # If not (e.g., locked during upgrade), exit with user-friendly message.
60
+ oasis_check_available() {
61
+ local bin_var="${OASIS_BIN_VAR:?OASIS_BIN_VAR must be set}"
62
+ local bin_path="${!bin_var:-}"
63
+
64
+ # 报错要分流:说清是「PATH 上根本没有真实 CLI」还是「找到了但跑不起来」。
65
+ # 旧实现两种都打「cli is upgrading, try again in 30 seconds」——那句话在真正的
66
+ # 升级窗口里是对的,但在「PATH 被污染、解析到 wrapper 自己」时纯属误导:等多久都不会好。
67
+ if [ -z "$bin_path" ]; then
68
+ echo "error: ${OASIS_CMD_NAME:-cli} not found on PATH — 连接器需要的真实 CLI 未安装,或 PATH 上只剩 oasis wrapper。" >&2
69
+ exit 1
70
+ fi
71
+
72
+ if [ ! -x "$bin_path" ]; then
73
+ echo "error: ${OASIS_BIN_VAR} 指向的 $bin_path 不可执行。" >&2
74
+ exit 1
75
+ fi
76
+
77
+ if ! "$bin_path" --version >/dev/null 2>&1; then
78
+ echo "error: $bin_path --version 失败——真实 CLI 可能正在升级,30 秒后重试;若持续失败请检查该路径是否指向 oasis wrapper 自身。" >&2
79
+ exit 1
80
+ fi
81
+ }
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ # Feishu CLI wrapper — 通过前置 PATH 替换 lark-cli。
3
+ #
4
+ # 凭据保护:敏感凭据(App Secret / User Access Token)**不**放进 agent 环境变量,
5
+ # 而是写在只有本 wrapper 读取的临时文件里(inject() 写,chmod 600)。agent 环境里
6
+ # 只有一个非敏感的文件路径指针 FEISHU_CREDS_FILE。wrapper 在调用真实 lark-cli 前
7
+ # `source` 该文件,把 LARKSUITE_CLI_* 外部凭据变量注入**本 wrapper 子进程**——
8
+ # 这些秘密从不出现在 agent 自身的 env / /proc/self/environ,也不被 agent 其它子进程继承。
9
+ #
10
+ # 环境变量:
11
+ # LARK_BIN — 真实 lark-cli 绝对路径(避免递归调用自身)
12
+ # FEISHU_CREDS_FILE — 凭据文件路径(内含 export LARKSUITE_CLI_* 行)
13
+
14
+ set -euo pipefail
15
+
16
+ OASIS_BIN_VAR="LARK_BIN"
17
+ OASIS_CMD_NAME="lark-cli"
18
+ # shellcheck source=../_base/wrapper-base.sh
19
+ source "$(dirname "$(realpath "$0")")/../_base/wrapper-base.sh"
20
+
21
+ oasis_resolve_bin
22
+ oasis_check_available
23
+
24
+ # Load feishu credentials into THIS process only (not visible to the agent).
25
+ if [ -n "${FEISHU_CREDS_FILE:-}" ] && [ -f "${FEISHU_CREDS_FILE}" ]; then
26
+ # shellcheck disable=SC1090
27
+ source "${FEISHU_CREDS_FILE}"
28
+ fi
29
+
30
+ exec "$LARK_BIN" "$@"
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+ # GitHub CLI wrapper — replaces `gh` in the agent's PATH.
3
+ #
4
+ # The wrapper reads the token from an env var injected by inject(),
5
+ # never exposing it in a way the agent can read directly (the agent
6
+ # sees the wrapper name "gh" on PATH, not the token value).
7
+ #
8
+ # Environment variables (written by inject(), read here only):
9
+ # GH_CREDS_FILE — path to a chmod-600 file with `export GH_TOKEN=...` lines
10
+ # (token value is NOT in the agent env — only this path is)
11
+ # GH_BIN — absolute path to the real gh binary
12
+ # GIT_AUTHOR_NAME / GIT_COMMITTER_NAME — set by inject() directly (non-secret)
13
+
14
+ set -euo pipefail
15
+
16
+ OASIS_BIN_VAR="GH_BIN"
17
+ OASIS_CMD_NAME="gh"
18
+ # shellcheck source=../_base/wrapper-base.sh
19
+ source "$(dirname "$(realpath "$0")")/../_base/wrapper-base.sh"
20
+
21
+ oasis_resolve_bin
22
+ oasis_check_available
23
+
24
+ # Load the GitHub token into THIS process only (not visible to the agent).
25
+ # The token lives in a chmod-600 file the wrapper sources; the agent env only
26
+ # holds the non-secret path GH_CREDS_FILE.
27
+ if [ -n "${GH_CREDS_FILE:-}" ] && [ -f "${GH_CREDS_FILE}" ]; then
28
+ # shellcheck disable=SC1090
29
+ source "${GH_CREDS_FILE}"
30
+ fi
31
+
32
+ if [ "${OASIS_EXTERNAL_EFFECT_CAPTURE:-}" = "1" ]; then
33
+ exec oasis connector-effect-run github "$GH_BIN" "$@"
34
+ fi
35
+
36
+ exec "$GH_BIN" "$@"