Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(cli): default caller context for introspection (#696)
Call White706a884f9914
diff --git a/docs/CLI.md b/docs/CLI.mdindex a8fecf119..5c08c8f59 100644--- a/docs/CLI.md+++ b/docs/CLI.md@@ -166,12 +166,30 @@ vibe session list # active sessions, 10 per page, newest avibe session list --type slack # filter by platform (avibe = Web/Workbench)vibe session list --page 2 # next page (fixed 10 per page; there is no --limit)vibe session get sesk8m4q2p7x # full detail for one session+vibe session get # inside an Avibe Agent shell, show the caller Sessionvibe session update sesk8m4q2p7x --title 'Release review' # pass "" to clear the title+vibe session update --title 'Release review' # inside an Avibe Agent shell````--type` accepts a platform id: `avibe` (Web/Workbench), `slack`, `discord`,`telegram`, `lark`, `wechat`. For richer filtering — by agent, time range, messagecontent, or cross-table joins — `list` and `get` point you to `vibe data query`.+When `get` or `update` runs inside an Avibe-injected Agent shell, the session id+may be omitted and defaults to the caller Session from `AVIBE_SESSION_ID`.++### `vibe runs`++List and inspect Agent run records.++```bash+vibe runs list --session-id sesk8m4q2p7x --brief+vibe runs show run_abc123+vibe runs show # inside an Avibe Agent shell, show the caller Run+```++`vibe runs list` keeps its global listing behavior unless a filter such as+`--session-id` is provided. `vibe runs show` can omit the run id inside an+Avibe-injected Agent run and defaults to `AVIBE_RUN_ID`.### `vibe task`diff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.mdindex 2c0034ed3..7fdac3340 100644--- a/docs/CLI_ZH.md+++ b/docs/CLI_ZH.md@@ -150,10 +150,28 @@ vibe session list # 未归档会话,每页 10 条,按vibe session list --type slack # 按平台过滤(avibe = Web/Workbench)vibe session list --page 2 # 翻到下一页(固定每页 10 条;没有 --limit)vibe session get sesk8m4q2p7x # 单个会话的完整明细+vibe session get # 在 Avibe Agent shell 内查看调用方 Sessionvibe session update sesk8m4q2p7x --title 'Release review' # 传 "" 可清空标题+vibe session update --title 'Release review' # 在 Avibe Agent shell 内````--type` 取平台 id:`avibe`(Web/Workbench)、`slack`、`discord`、`telegram`、`lark`、`wechat`。需要更高级的筛选——按 Agent、时间段、消息内容或跨表联查——`list` 与 `get` 的返回都会引导你使用 `vibe data query`。+当 `get` 或 `update` 运行在 Avibe 已注入 caller context 的 Agent shell 内时,+可以省略 session id,并默认使用 `AVIBE_SESSION_ID` 对应的调用方 Session。++### `vibe runs`++列出和查看 Agent run 记录。++```bash+vibe runs list --session-id sesk8m4q2p7x --brief+vibe runs show run_abc123+vibe runs show # 在 Avibe Agent shell 内查看调用方 Run+```++`vibe runs list` 无过滤参数时仍保持全局列表语义;传入 `--session-id` 等参数+才会筛选。`vibe runs show` 在 Avibe 已注入 caller context 的 Agent run 内+可以省略 run id,并默认使用 `AVIBE_RUN_ID`。### `vibe task`diff --git a/tests/test_cli_pagination.py b/tests/test_cli_pagination.pyindex fc217c039..972d7703d 100644--- a/tests/test_cli_pagination.py+++ b/tests/test_cli_pagination.py@@ -143,6 +143,55 @@ def test_runs_list_cli_next_command_uses_absolute_time_filters(monkeypatch, tmp_assert payload["pagination"]["next_command"].endswith("--page 2 --limit 10")+def test_runs_show_defaults_to_caller_run(monkeypatch, tmp_path, capsys) -> None:+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ monkeypatch.setenv("AVIBE_SESSION_ID", "ses-alpha")+ monkeypatch.setenv("AVIBE_RUN_ID", "run-current")+ paths.ensure_data_dirs()+ store = SQLiteBackgroundTaskStore()+ try:+ store.enqueue_run(+ {+ "id": "run-current",+ "request_type": "agent_run",+ "status": "succeeded",+ "agent_name": "helper",+ "agent_backend": "codex",+ "session_id": "ses-alpha",+ "message": "current run",+ "created_at": "2026-05-25T00:00:00+00:00",+ "updated_at": "2026-05-25T00:00:00+00:00",+ }+ )+ finally:+ store.close()++ args = cli.build_parser().parse_args(["runs", "show"])+ assert cli.cmd_runs_show(args) == 0++ payload = json.loads(capsys.readouterr().out)+ assert payload["run"]["id"] == "run-current"+ assert payload["run_default_notice"] == {+ "code": "run_defaulted_to_caller",+ "message": "Run defaulted to the caller Run from AVIBE_RUN_ID.",+ "run_id": "run-current",+ }+++def test_runs_show_requires_run_without_caller(monkeypatch, tmp_path, capsys) -> None:+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ monkeypatch.delenv("AVIBE_SESSION_ID", raising=False)+ monkeypatch.delenv("AVIBE_RUN_ID", raising=False)+ paths.ensure_data_dirs()++ args = cli.build_parser().parse_args(["runs", "show"])+ assert cli.cmd_runs_show(args) == 1++ payload = json.loads(capsys.readouterr().err)+ assert payload["code"] == "missing_run_target"+ assert payload["help_command"] == "vibe runs show --help"++def test_data_query_cli_runs_read_only_sql(monkeypatch, tmp_path, capsys) -> None:monkeypatch.setenv("AVIBE_HOME", str(tmp_path))paths.ensure_data_dirs()diff --git a/tests/test_session_cli.py b/tests/test_session_cli.pyindex b3382506f..4bc0168f3 100644--- a/tests/test_session_cli.py+++ b/tests/test_session_cli.py@@ -126,6 +126,33 @@ def test_get_returns_detail_without_status_agentid_anchor(monkeypatch, tmp_path,assert "vibe runs list --session-id sesaaa" in payload["message"]+def test_get_defaults_to_caller_session(monkeypatch, tmp_path, capsys):+ engine = _setup(monkeypatch, tmp_path)+ _seed(engine, "sesaaa", platform="avibe", native="proj_a")+ monkeypatch.setenv("AVIBE_SESSION_ID", "sesaaa")++ code, payload = _run(cli.cmd_session_get, ["session", "get"], capsys)++ assert code == 0+ assert payload["session"]["id"] == "sesaaa"+ assert payload["session_default_notice"] == {+ "code": "session_defaulted_to_caller",+ "message": "Session defaulted to the caller Session from AVIBE_SESSION_ID.",+ "session_id": "sesaaa",+ }+++def test_get_requires_session_without_caller(monkeypatch, tmp_path, capsys):+ _setup(monkeypatch, tmp_path)+ monkeypatch.delenv("AVIBE_SESSION_ID", raising=False)++ code, payload = _run(cli.cmd_session_get, ["session", "get"], capsys)++ assert code == 1+ assert payload["code"] == "missing_session_target"+ assert payload["help_command"] == "vibe session get --help"++def test_get_archived_is_not_found(monkeypatch, tmp_path, capsys):engine = _setup(monkeypatch, tmp_path)_seed(engine, "sesarch", status="archived")@@ -156,6 +183,35 @@ def test_update_sets_title(monkeypatch, tmp_path, capsys):assert payload["session"]["metadata"]["title_source"] == "agent"+def test_update_defaults_to_caller_session(monkeypatch, tmp_path, capsys):+ engine = _setup(monkeypatch, tmp_path)+ _seed(engine, "sesaaa", title="Old")+ monkeypatch.setenv("AVIBE_SESSION_ID", "sesaaa")++ code, payload = _run(cli.cmd_session_update, ["session", "update", "--title", "New name"], capsys)++ assert code == 0+ assert payload["updated"] is True+ assert payload["session"]["id"] == "sesaaa"+ assert payload["session"]["title"] == "New name"+ assert payload["session_default_notice"] == {+ "code": "session_defaulted_to_caller",+ "message": "Session defaulted to the caller Session from AVIBE_SESSION_ID.",+ "session_id": "sesaaa",+ }+++def test_update_requires_session_without_caller(monkeypatch, tmp_path, capsys):+ _setup(monkeypatch, tmp_path)+ monkeypatch.delenv("AVIBE_SESSION_ID", raising=False)++ code, payload = _run(cli.cmd_session_update, ["session", "update", "--title", "New name"], capsys)++ assert code == 1+ assert payload["code"] == "missing_session_target"+ assert payload["help_command"] == "vibe session update --help"++def test_update_empty_title_clears(monkeypatch, tmp_path, capsys):engine = _setup(monkeypatch, tmp_path)_seed(engine, "sesaaa", title="Old")diff --git a/vibe/cli.py b/vibe/cli.pyindex c9e28ef09..376e3c40d 100644--- a/vibe/cli.py+++ b/vibe/cli.py@@ -1334,6 +1334,49 @@ def _resolve_show_session_id(args, *, help_command: str) -> tuple[str, Optional[return session_id, notice+def _resolve_caller_session_id(args, *, purpose: str, help_command: str) -> tuple[str, Optional[dict[str, str]]]:+ caller_context = caller_context_from_env()+ notice = _apply_caller_session_default(args, caller_context, purpose=purpose)+ session_id = (getattr(args, "session_id", None) or "").strip()+ if not session_id:+ raise TaskCliError(+ f"{purpose} id is required outside an Avibe Agent environment.",+ code="missing_session_target",+ hint="Pass the session id explicitly, or run this command from an Avibe Agent shell where AVIBE_SESSION_ID is injected.",+ help_command=help_command,+ )+ return session_id, notice+++def _default_run_id_from_caller(caller_context) -> Optional[str]:+ if caller_context is None:+ return None+ run_id = (getattr(caller_context, "run_id", None) or "").strip()+ if not run_id:+ return None+ return run_id+++def _resolve_caller_run_id(args, *, purpose: str, help_command: str) -> tuple[str, Optional[dict[str, str]]]:+ run_id = (getattr(args, "run_id", None) or "").strip()+ if run_id:+ return run_id, None+ default_run_id = _default_run_id_from_caller(caller_context_from_env())+ if not default_run_id:+ raise TaskCliError(+ f"{purpose} id is required outside an Avibe Agent run environment.",+ code="missing_run_target",+ hint="Pass the run id explicitly, or run this command from an Avibe Agent shell where AVIBE_RUN_ID is injected.",+ help_command=help_command,+ )+ setattr(args, "run_id", default_run_id)+ return default_run_id, {+ "code": "run_defaulted_to_caller",+ "message": f"{purpose} defaulted to the caller Run from AVIBE_RUN_ID.",+ "run_id": default_run_id,+ }++def _validate_delivery_args(*,session_key: str,@@ -3296,11 +3339,23 @@ def cmd_runs_list(args):def cmd_runs_show(args):- run = _task_request_store().get_run(args.run_id)+ try:+ run_id, run_default_notice = _resolve_caller_run_id(+ args,+ purpose="Run",+ help_command="vibe runs show --help",+ )+ except Exception as exc:+ _print_task_error(exc, help_command="vibe runs show --help")+ return 1+ run = _task_request_store().get_run(run_id)if run is None:- _print_task_error(TaskCliError(f"run '{args.run_id}' not found", code="run_not_found", details={"run_id": args.run_id}))+ _print_task_error(TaskCliError(f"run '{run_id}' not found", code="run_not_found", details={"run_id": run_id}))return 1- _print_cli_payload("agent_run", run=_run_payload(run))+ payload_fields = {"run": _run_payload(run)}+ if run_default_notice:+ payload_fields["run_default_notice"] = run_default_notice+ _print_cli_payload("agent_run", **payload_fields)return 0@@ -3458,15 +3513,20 @@ def cmd_session_get(args):from core.services import sessions as sessions_servicetry:+ session_id, session_default_notice = _resolve_caller_session_id(+ args,+ purpose="Session",+ help_command="vibe session get --help",+ )engine = _open_session_engine()with engine.connect() as conn:- payload = sessions_service.get_active_session(conn, args.session_id)+ payload = sessions_service.get_active_session(conn, session_id)except LookupError:_print_task_error(TaskCliError(- f"session '{args.session_id}' not found",+ f"session '{session_id}' not found",code="session_not_found",- details={"session_id": args.session_id},+ details={"session_id": session_id},),help_command="vibe session get --help",)@@ -3477,7 +3537,8 @@ def cmd_session_get(args):_print_cli_payload("agent_session",session=_session_row(payload, brief=False),- message=_session_get_hint(args.session_id),+ message=_session_get_hint(session_id),+ **({"session_default_notice": session_default_notice} if session_default_notice else {}),)return 0@@ -3486,23 +3547,28 @@ def cmd_session_update(args):from core.services import sessions as sessions_servicetry:+ session_id, session_default_notice = _resolve_caller_session_id(+ args,+ purpose="Session",+ help_command="vibe session update --help",+ )engine = _open_session_engine()with engine.begin() as conn:# Validate first so an archived/missing id is a clean not-found rather# than silently writing a title onto a soft-deleted row.- sessions_service.get_active_session(conn, args.session_id)+ sessions_service.get_active_session(conn, session_id)# title_source="agent": this is the agent setting its own session title (vs# "user" for a human Web UI edit). Both are deliberate, so neither gets# auto-overwritten nor re-nudged — see DELIBERATE_TITLE_SOURCES.payload = sessions_service.update_session(- conn, args.session_id, title=args.title, title_source="agent"+ conn, session_id, title=args.title, title_source="agent")except LookupError:_print_task_error(TaskCliError(- f"session '{args.session_id}' not found",+ f"session '{session_id}' not found",code="session_not_found",- details={"session_id": args.session_id},+ details={"session_id": session_id},),help_command="vibe session update --help",)@@ -3512,8 +3578,13 @@ def cmd_session_update(args):return 1# The DB write is committed above; ping a running UI so the rename shows live# (best-effort — never affects this command's result).- _post_session_activity_to_live_ui(args.session_id)- _print_cli_payload("agent_session", updated=True, session=_session_row(payload, brief=False))+ _post_session_activity_to_live_ui(session_id)+ _print_cli_payload(+ "agent_session",+ updated=True,+ session=_session_row(payload, brief=False),+ **({"session_default_notice": session_default_notice} if session_default_notice else {}),+ )return 0@@ -7593,7 +7664,7 @@ def build_parser():_add_pagination_args(runs_list_parser, help_command="vibe runs list --help")_add_json_noop(runs_list_parser)runs_show_parser = runs_subparsers.add_parser("show", help="Show one Agent run")- runs_show_parser.add_argument("run_id")+ runs_show_parser.add_argument("run_id", nargs="?")_add_json_noop(runs_show_parser)runs_cancel_parser = runs_subparsers.add_parser("cancel", help="Request best-effort cancellation for one run")runs_cancel_parser.add_argument("run_id")@@ -7633,7 +7704,7 @@ def build_parser():formatter_class=argparse.RawDescriptionHelpFormatter,error_help_command="vibe session get --help",)- session_get_parser.add_argument("session_id", help="Agent Session ID")+ session_get_parser.add_argument("session_id", nargs="?", help="Agent Session ID")_add_json_noop(session_get_parser)session_update_parser = session_subparsers.add_parser("update",@@ -7642,7 +7713,7 @@ def build_parser():formatter_class=argparse.RawDescriptionHelpFormatter,error_help_command="vibe session update --help",)- session_update_parser.add_argument("session_id", help="Agent Session ID")+ session_update_parser.add_argument("session_id", nargs="?", help="Agent Session ID")session_update_parser.add_argument("--title", required=True, help="New title. Pass an empty string to clear it (reverts to id-based display).")