Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

refactor(prompt): scope companion principles and Show history (#1924)

Call Whitee8060055d291
diff --git a/core/prompt_registry.py b/core/prompt_registry.py
index 646e5849c..0e9526139 100644
--- a/core/prompt_registry.py
+++ b/core/prompt_registry.py
@@ -83,9 +83,6 @@ PROMPT_MODULES: tuple[PromptModule, ...] = (
PromptModule("skills-prompt", "Skills Usage", "skills.md", leading_newlines=2, trailing_newlines=2),
PromptModule("codex-generated-images", "Codex-generated images", "codex-generated-images.md", leading_newlines=1, trailing_newlines=1, placeholders=("example_uri",)),
PromptModule("show-pages-prompt", "Show Pages Prompt", "show-pages.md", leading_newlines=1, trailing_newlines=1),
- PromptModule("show-history-heading", "Show History Heading", "show-history-heading.md", leading_newlines=1, trailing_newlines=1),
- PromptModule("show-history-managed", "Show History: Managed Workspace", "show-history-managed.md"),
- PromptModule("show-history-self-managed", "Show History: User Repository", "show-history-self-managed.md"),
PromptModule("quick-replies-prompt", "Quick Replies Prompt", "quick-replies.md", leading_newlines=1, trailing_newlines=1),
PromptModule("vault-routing-prompt", "Vault Routing Prompt", "vault.md", leading_newlines=1, trailing_newlines=1),
PromptModule("harness-routing-prompt", "Harness Routing Prompt", "harness.md", leading_newlines=1, trailing_newlines=1),
diff --git a/core/prompts/agent-working-principles.md b/core/prompts/agent-working-principles.md
index a6f4519f9..c35531542 100644
--- a/core/prompts/agent-working-principles.md
+++ b/core/prompts/agent-working-principles.md
@@ -1,10 +1,10 @@
You are a long-lived AGI that exercises independent judgment and takes responsibility for long-term outcomes.
-- **Understand the goal.** Start with the real-world change the user wants. Use context to identify necessary implicit needs, and distinguish discussion, investigation, and execution.
-- **Exercise independent judgment.** Reason from facts, constraints, and causal relationships. Proactively identify problems and recommend solutions. Treat feedback as new evidence and revise your judgment around the original goal.
-- **Take initiative.** Do everything within your capabilities to gather information, complete necessary steps, and act. When facing major trade-offs, irreversible risks, or genuine ambiguity about direction, seek confirmation with a recommendation.
+- **Understand the person.** Approach the other person with sincerity, empathy, and curiosity. Use context to understand their real needs and what lies between the lines.
+- **Exercise independent judgment.** Form your own judgment from facts and revise it with new evidence. Understand the actual scope of agreements and constraints; neither broaden local restrictions nor narrow boundaries that genuinely apply.
+- **Take initiative.** Do everything within your capabilities to help the other person, carrying entrusted work through its necessary steps without repeatedly seeking the same permission or expanding the mandate yourself. Weigh the costs of acting, not acting, and interrupting them. Resolve ordinary uncertainty independently; bring recommendations when discussing key matters that need their decision.
- **Reason and choose.** Understand problems through first principles. Choose solutions using Occam’s razor. Seek the smallest complete solution.
-- **Follow through.** Continue while the goal remains unmet and a viable path exists. When repeatedly blocked, revisit assumptions and root causes; when necessary, step back from local details and reconsider the approach from a higher-level perspective. When waiting, define the conditions for resuming; when unable to proceed, explain the blocker.
-- **Verify and communicate.** Confirm outcomes with practical evidence appropriate to the task. Distinguish facts, inferences, and unverified claims. Lead with the conclusion, and clearly explain implications, key trade-offs, and decisions requiring the user’s input.
+- **Follow through.** Maintain ongoing responsibility for entrusted work rather than forgetting it when a turn ends. When repeatedly blocked, revisit assumptions and root causes; when necessary, step back from local details and reconsider the approach from a higher-level perspective. When waiting, define the conditions for resuming; when unable to proceed, explain the blocker.
+- **Verify and communicate.** Confirm outcomes with evidence appropriate to the matter, and be honest about uncertainty. When reporting, lead with the conclusion and explain implications and matters that need the other person's decision.
Weigh these principles against the actual context and the user’s preferences, without taking any one principle to an extreme.
diff --git a/core/prompts/show-history-heading.md b/core/prompts/show-history-heading.md
deleted file mode 100644
index f2e0e092f..000000000
--- a/core/prompts/show-history-heading.md
+++ /dev/null
@@ -1 +0,0 @@
-History contract:
diff --git a/core/prompts/show-history-managed.md b/core/prompts/show-history-managed.md
deleted file mode 100644
index 0c885d9cd..000000000
--- a/core/prompts/show-history-managed.md
+++ /dev/null
@@ -1,5 +0,0 @@
-History is saved automatically around each turn; do not manage versions yourself.
-Read freely: `git -C <workspace> status / log / diff / show`.
-Restore only via `git restore --source=<ref> -- <path>`; the turn-end checkpoint records it as a forward commit.
-Never move HEAD, switch branches, rewrite history, or run gc; if you do, the platform self-heals with the worktree as truth.
-Never add remotes, push, or publish the workspace anywhere unless the user explicitly asks.
diff --git a/core/prompts/show-history-self-managed.md b/core/prompts/show-history-self-managed.md
deleted file mode 100644
index ed7662964..000000000
--- a/core/prompts/show-history-self-managed.md
+++ /dev/null
@@ -1,3 +0,0 @@
-Avibe's shadow history continues automatically in the background; you don't manage it.
-`git -C <workspace>` addresses the **user's repo**, not Avibe history: never commit, push, or publish on their behalf, and never use it for Avibe restore.
-Never locate or mutate Avibe's shadow gitdir on your own initiative. Only if the user explicitly asks to recover from Avibe history, use standard git with explicit `--git-dir` and `--work-tree` against the session's shadow gitdir for read or restore only; never commit to it.
diff --git a/core/prompts/show-pages.md b/core/prompts/show-pages.md
index bf0f05df2..bbe5dd838 100644
--- a/core/prompts/show-pages.md
+++ b/core/prompts/show-pages.md
@@ -1,2 +1,2 @@
## Show Pages
-When a visual page would materially improve the result, load the `use-show-pages` Skill before creating or updating the page.
+Use Show Pages when a visual page would materially help the user understand, compare, or decide. Before creating, updating, or restoring a Show Page, load the `use-show-pages` Skill.
diff --git a/core/show_git.py b/core/show_git.py
index 87054a9b0..09a2582a4 100644
--- a/core/show_git.py
+++ b/core/show_git.py
@@ -16,7 +16,6 @@ from typing import Any
from config import paths
from core.git_binary import ResolvedGit, resolve_git
-from core.prompt_registry import RenderedPromptBlock, prompt_text
from vibe.message_types import input_author_type_pairs
logger = logging.getLogger(__name__)
@@ -72,8 +71,7 @@ _INPUT_TURN_MESSAGE_TYPES = tuple(
dict.fromkeys(message_type for _, message_type in input_author_type_pairs())
)
-SHOW_GIT_AGENT_CONTRACT = tuple(prompt_text("show-history-managed").splitlines())
-SHOW_GIT_SELF_MANAGED_AGENT_CONTRACT = tuple(prompt_text("show-history-self-managed").splitlines())
+
class ShowGitError(RuntimeError):
"""A platform Git operation failed."""
@@ -178,39 +176,15 @@ def _workspace_is_self_managed(session_id: str) -> bool:
return not managed
-def format_agent_contract(
- *,
- numbered: bool = False,
- checkpointing_available: bool | None = None,
- session_id: str | None = None,
-) -> str:
- block = agent_contract_block(
- numbered=numbered, checkpointing_available=checkpointing_available, session_id=session_id,
- )
- return block.text if block else ""
-
-
-def agent_contract_block(
- *,
- numbered: bool = False,
- checkpointing_available: bool | None = None,
- session_id: str | None = None,
-) -> RenderedPromptBlock | None:
- if checkpointing_available is None:
- checkpointing_available = show_git_checkpointing_active()
- if not checkpointing_available:
- return None
- if session_id is not None and _workspace_is_self_managed(session_id):
- lines = SHOW_GIT_SELF_MANAGED_AGENT_CONTRACT
- module_id = "show-history-self-managed"
- else:
- lines = SHOW_GIT_AGENT_CONTRACT
- module_id = "show-history-managed"
- if numbered:
- text = "\n".join(f"{index}. {line}" for index, line in enumerate(lines, start=1))
- else:
- text = "\n".join(f"- {line}" for line in lines)
- return RenderedPromptBlock(module_id, text)
+def show_history_status(session_id: str) -> dict[str, Any]:
+ """Describe this page's history on demand without creating or changing it."""
+ if not _SESSION_ID_PATTERN.fullmatch(str(session_id or "")):
+ raise ValueError("Invalid Show Page session id")
+ return {
+ "mode": "self-managed" if _workspace_is_self_managed(session_id) else "managed",
+ "checkpointing_active": show_git_checkpointing_active(),
+ "git_dir": str(paths.get_show_git_dir(session_id)),
+ }
def _single_line(value: Any) -> str:
diff --git a/core/system_prompt_injection.py b/core/system_prompt_injection.py
index b8c91e3f8..9616011eb 100644
--- a/core/system_prompt_injection.py
+++ b/core/system_prompt_injection.py
@@ -12,7 +12,6 @@ from typing import Any, Iterable, Optional
from config import paths
from core.message_context import resolve_context_platform
from core.prompt_registry import RenderedPromptBlock, join_prompt_blocks, order_prompt_blocks, render_prompt, render_prompt_block
-from core.show_git import agent_contract_block
from modules.im import MessageContext
logger = logging.getLogger(__name__)
@@ -26,6 +25,8 @@ logger = logging.getLogger(__name__)
# health. Runtime policy belongs in the enforcing layer, not in its description.
# - Keep every generated collection deterministic, including Agent and Skill order.
# - Required built-in Skill routing is unconditional; installation guarantees it.
+# - Show Page history rules live in its Skill; inspect workspace ownership only
+# on demand, never while composing the conversation's stable prompt.
# - Working principles are a static, unconditional prefix before Session and
# capability details; never gate them on a backend, Skill, or Turn.
# - Author all injected prose in the registry. Production text and debug JSON
@@ -235,10 +236,6 @@ def build_system_prompt_blocks(
blocks.append(_codex_generated_images_block())
if include_show_pages and context is not None:
blocks.append(render_prompt_block("show-pages-prompt"))
- history = agent_contract_block(numbered=True, session_id=_extract_default_session_id(context))
- if history:
- blocks.append(render_prompt_block("show-history-heading"))
- blocks.append(RenderedPromptBlock(history.module_id, history.text + "\n"))
if include_quick_replies:
blocks.append(render_prompt_block("quick-replies-prompt"))
if vault_skill_available:
diff --git a/docs/plans/companion-principles-and-show-history.md b/docs/plans/companion-principles-and-show-history.md
new file mode 100644
index 000000000..71b261a2c
--- /dev/null
+++ b/docs/plans/companion-principles-and-show-history.md
@@ -0,0 +1,62 @@
+# Companion Principles and Skill-Scoped Show History
+
+## Goal
+
+Keep Avibe's resident behavior guidance appropriate for a general AI companion,
+not just an execution agent. The owner-approved six principles remain one static,
+unconditional, source-addressable block. The English translation lives in
+`core/prompts/agent-working-principles.md`.
+
+Initiative includes understanding the person and following through on entrusted
+work. Ordinary necessary steps do not require repeated permission; initiative
+does not expand the mandate. First principles, Occam's razor, ongoing
+responsibility, and honest reporting remain part of the guidance. No new
+interaction classifier, authorization switch, or per-turn prompt branch is added.
+
+## Show History Ownership
+
+The resident Show Pages block routes creation, editing, and restoration to
+`skills/use-show-pages/SKILL.md`. That Skill owns page history guidance, including
+the distinction between Avibe-managed Git and a user's repository with separate
+Avibe shadow history. These local rules do not govern unrelated repositories.
+They protect Avibe checkpoints without prohibiting separately entrusted work in
+the user's repository.
+
+`vibe show status --json` exposes the current page's history facts on demand:
+
+| Field | Meaning |
+| --- | --- |
+| `path` | The existing Show Page workspace, as before |
+| `history.mode` | `managed` or `self-managed`, from the existing ownership probe |
+| `history.checkpointing_active` | Whether the running checkpoint service is active |
+| `history.git_dir` | The Avibe history directory, never the user's Git directory |
+
+Status does not initialize or repair Git. The reported directory may not exist
+before the first checkpoint. The Skill checks the resolved Git directory before
+using workspace-relative Git, so an enclosing user repository cannot stand in
+for an uninitialized Show repository. Inactive checkpointing does not imply that
+old history is gone or that new edits have been saved.
+
+The old history prompt sources, registry entries, and rendering helpers are
+removed rather than kept as a second instruction source. Automatic checkpoint
+creation, recovery mechanics, and repository ownership detection are unchanged.
+
+## Acceptance
+
+- Production and debug export emit the same ordered, source-addressable blocks
+ for every supported backend. Principles remain unconditional and occur once.
+- Show history state is not a prompt-rendering dependency. Changing checkpoint
+ availability or repository ownership cannot change prompt bytes or revisions.
+- Every unaffected prompt block retains its bytes and relative order against
+ baseline commit `627ed97aebe26f4cc01cca3ffe159433d721ebdf`.
+- Studio exports history instructions in the Show Pages Skill, not Runtime Core.
+- Status reports ownership and checkpoint state without changing either history.
+- Native Git inspection and file restoration work with the Skill's commands in
+ isolated managed and user-owned repositories; checkpoints remain platform-owned.
+
+Behavioral assessment should contrast conversation, research, delegated action,
+and ongoing responsibility. Check appropriate initiative and restraint together,
+not just fewer questions or more tool calls. Deterministic tests establish prompt
+composition and Git mechanics, not a guarantee about every model's behavior.
+
+This change does not deploy the running Avibe or modify Studio's saved drafts.
diff --git a/skills/use-show-pages/SKILL.md b/skills/use-show-pages/SKILL.md
index 5fd328b76..f94c183ba 100644
--- a/skills/use-show-pages/SKILL.md
+++ b/skills/use-show-pages/SKILL.md
@@ -1,8 +1,8 @@
---
name: use-show-pages
slug: use-show-pages
-description: Build, inspect, update, or share an Avibe Show Page when a visual explanation, diagram, dashboard, report, or interactive prototype would materially help.
-version: 0.2.1
+description: Build, inspect, update, restore, or share Avibe Show Pages for visual explanations, diagrams, reports, or interactive prototypes. Covers the page workspace and its Git history.
+version: 0.3.0
---
# Use Show Pages
@@ -35,10 +35,46 @@ For more usage details, run `vibe show --help` or a subcommand help such as `vib
- After reworking a page area you may leave a short callout: `vibe show mark <selector-or-anchor> --message '...'` (same target replaces), or an `agent-note="..."` attribute on elements you author. Marks retire once read — leave at most 1-2 per turn.
- Inspect/withdraw: `vibe show marks` / `vibe show unmark <id|target> ...`; toggle the user's annotation mode: `vibe show annotate --on|--off [--mode smart|screenshot]`.
-Follow the History contract in the current System Prompt when Avibe supplies
-one. For live runtime, visibility, and URL availability, treat
+For live runtime, visibility, and URL availability, treat
`vibe show status` and the relevant command output as authoritative.
+### Show Page workspace history
+
+These rules apply only to this Session's Show Page workspace and its Avibe
+history. Avibe manages page checkpoints automatically; do not create versions
+manually for page edits.
+
+Before operating on history, run `vibe show status --json`. Use its `path`
+as `<show-workspace>` and inspect `history.mode`, `history.checkpointing_active`,
+and `history.git_dir`. Status is read-only; it does not initialize a repository.
+If checkpointing is inactive, do not assume new edits have automatic checkpoints
+or start managing Avibe history yourself. Existing history can still be inspected
+and restored when requested.
+
+When `history.mode` is `managed`:
+- Before using `git -C`, check that `git -C <show-workspace> rev-parse --absolute-git-dir`
+ resolves to `history.git_dir`. If it does not, do not use an enclosing repository
+ or initialize one in its place.
+- Read freely with `git -C <show-workspace> status / log / diff / show`.
+- Restore files with `git -C <show-workspace> restore --source=<ref> -- <path>`.
+ When checkpointing is active, Avibe records the restored files in a new forward
+ checkpoint. Do not move HEAD, switch branches, rewrite history, run gc, or
+ commit checkpoints yourself, regardless of checkpoint availability.
+- Adding remotes, pushing, or publishing the page requires the user's
+ corresponding authorization.
+
+When `history.mode` is `self-managed`, the workspace has the user's own Git
+repository, separate from Avibe's shadow history:
+- `git -C <show-workspace>` addresses the user's repository, not Avibe history.
+ Do not commit or modify that repository to manage Avibe page checkpoints.
+- Separately entrusted repository work follows the user's mandate; page
+ checkpoint rules do not prohibit it.
+- Only when the user asks to recover from Avibe history, use the returned
+ `history.git_dir` as `<shadow-git-dir>` with explicit paths:
+ `git --git-dir=<shadow-git-dir> --work-tree=<show-workspace> log` to inspect,
+ and `git --git-dir=<shadow-git-dir> --work-tree=<show-workspace> restore --source=<ref> -- <path>`
+ to restore files. Do not commit to or otherwise mutate the shadow history.
+
Guidance:
- New Show Page workspaces are managed React/Vite apps that start as a clean "being generated" placeholder page (what the user sees while you build) plus a minimal file-based router (`src/router.tsx`) and one example page. When that router is present, add a route by creating a file under `src/pages/` — a folder becomes a nested path segment and a `[param]` file a dynamic segment — and customize the layout in `src/App.tsx`, styles in `src/styles.css`, and optional `api/*.ts` handlers. The starter is only a starting point, not a required structure: replace the placeholder with the real page, add or remove pages, and organize them however fits the app (flat, sections, or nested). Built-in UI is available to import, e.g. `@/components/ui/card`, `@/components/ui/button`, `@/components/ui/badge`.
- An older Show Page with no `src/router.tsx` is a single-page app that renders `src/App.tsx` directly. There, edit `src/App.tsx` (or adopt the router scaffold: add `src/router.tsx` + `src/pages/` and render it from `App.tsx`) — do not just drop files under `src/pages/`, since nothing would route them.
diff --git a/tests/test_prompt_render_export.py b/tests/test_prompt_render_export.py
index 453b2aa59..b04a1a95d 100644
--- a/tests/test_prompt_render_export.py
+++ b/tests/test_prompt_render_export.py
@@ -165,13 +165,10 @@ def test_exported_sources_cover_all_rendered_branches(monkeypatch):
assert visited == {module.id for module in PROMPT_MODULES}
[email protected]("history", ["managed", "self-managed"])
-def test_history_and_pagination_keep_their_own_source_provenance(monkeypatch, history):
- _environment(monkeypatch, history=history)
- rendered = render_prompt_context(_inputs(history=history))
+def test_pagination_keeps_its_own_source_provenance(monkeypatch):
+ _environment(monkeypatch)
+ rendered = render_prompt_context(_inputs())
blocks = {block["id"]: block for block in rendered["blocks"]}
- assert blocks["show-history-heading"]["text"] == prompt_text("show-history-heading")
- assert "History contract:" not in blocks[f"show-history-{history}"]["text"]
rows = "\n".join(f"- skill-{index:02}: Description skill-{index:02}" for index in range(25))
assert blocks["skills-catalog-heading"]["text"] == "\n\n## Available skills\n"
assert blocks["skills-catalog"]["text"] == prompt_text("skills-catalog").format(skill_rows=rows)
@@ -183,6 +180,21 @@ def test_history_and_pagination_keep_their_own_source_provenance(monkeypatch, hi
assert "| Agent Name | Backend | Agent Description |" in prompt_text("harness-agents-prompt")
[email protected]("backend", ["claude", "codex", "opencode"])
+def test_history_state_is_not_a_prompt_dependency(monkeypatch, backend):
+ _environment(monkeypatch)
+ request = _inputs(backend)
+ before = render_prompt_context(request)
+
+ def unexpected_probe(*_args):
+ raise AssertionError("Prompt composition must not inspect Show history")
+
+ monkeypatch.setattr(show_git, "show_git_checkpointing_active", unexpected_probe)
+ monkeypatch.setattr(show_git, "_workspace_is_self_managed", unexpected_probe)
+ assert render_prompt_context(request) == before
+ assert not any(block["id"].startswith("show-history-") for block in before["blocks"])
+
+
def test_rendered_revision_changes_only_when_rendered_bytes_change(monkeypatch):
_environment(monkeypatch)
request = _inputs()
@@ -373,33 +385,19 @@ def test_cli_localizes_invalid_context_files(monkeypatch, tmp_path, capsys, lang
assert output.err == cli.i18n_t("debug.cli.error.promptExport", language, error=error) + "\n"
-def test_working_principles_addition_preserves_all_other_injection_bytes(monkeypatch):
+def test_companion_principles_and_history_move_preserve_all_other_injection_bytes(monkeypatch):
outputs = []
+ changed = {
+ "agent-working-principles", "show-pages-prompt",
+ "show-history-heading", "show-history-managed", "show-history-self-managed",
+ }
for backend, memory, history, skill_mode in itertools.product(
("claude", "codex", "opencode"), (False, True), ("off", "managed", "self-managed"), ("empty", "manual", "pages"),
):
_environment(monkeypatch, history, skill_mode)
blocks = render_prompt_context(_inputs(backend, memory, history, skill_mode))["blocks"]
- # Undo the usage move and independent heading boundaries, never prose changes.
- blocks = [dict(block) for block in blocks if block["id"] != "skills-catalog-heading"]
- for block in blocks:
- if block["id"] == "skills-catalog":
- block["text"] = "### Available skills\n" + block["text"]
- elif block["id"] == "codex-generated-images":
- block["text"] = block["text"].replace("\n## Codex-generated images\n", "\n### Codex-generated images\n", 1)
- usage = next((block for block in blocks if block["id"] == "skills-prompt"), None)
- if usage:
- blocks.remove(usage)
- catalog_start = next(
- index for index, block in enumerate(blocks)
- if block["id"] in {"skills-pagination-prompt", "skills-catalog"}
- )
- blocks.insert(catalog_start, usage)
- rendered = "".join(block["text"] for block in blocks)
- principles = prompt_text("agent-working-principles")
- assert rendered.count(principles) == 1
- outputs.append(rendered.replace(principles, "", 1))
+ outputs.append("".join(block["text"] for block in blocks if block["id"] not in changed))
digest = hashlib.sha256(json.dumps(outputs, ensure_ascii=False).encode()).hexdigest()
- # Captured from the pre-migration renderer at 928924dd82bb48c7eea67ff06ddd844d442cb2a1.
- # Only working principles, Skills Usage placement, and heading boundaries differ.
- assert digest == "adbf608248e0b0a03d6646f57d31816cdb520c86113225e281b2aa007b100bc5"
+ # Captured independently from 627ed97aebe26f4cc01cca3ffe159433d721ebdf,
+ # omitting only this change's approved principles, routing, and history blocks.
+ assert digest == "6dae9db6263a2dd4aec5e6be5b545ea5ed3daeb7140a4f228dc749f8247b3915"
diff --git a/tests/test_prompt_studio_catalog.py b/tests/test_prompt_studio_catalog.py
index 5a03e0c56..782109998 100644
--- a/tests/test_prompt_studio_catalog.py
+++ b/tests/test_prompt_studio_catalog.py
@@ -105,6 +105,17 @@ def test_skill_sections_ignore_heading_like_lines_inside_code_fences() -> None:
assert blocks[1]["source_line"] == 14
+def test_show_history_is_source_addressable_only_in_its_skill() -> None:
+ catalog = export_prompt_studio_catalog()
+ runtime = next(document for document in catalog["documents"] if document["id"] == "runtime-core")
+ assert not any("show-history" in block["id"] for block in runtime["blocks"])
+ show = next(document for document in catalog["documents"] if document.get("name") == "use-show-pages")
+ history = next(block for block in show["blocks"] if block["heading"] == "Show Page workspace history")
+ assert history["source_path"] == "skills/use-show-pages/SKILL.md"
+ assert "history.mode" in history["source"]
+ assert "--git-dir=<shadow-git-dir>" in history["source"]
+
+
def test_debug_prompt_export_cli_contract(capsys) -> None:
args = cli.build_parser().parse_args(["debug", "prompt", "export", "--format", "json"])
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index 2ccf7cca3..53f0b88d6 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -1884,7 +1884,7 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertIn("## Personal Memory", human_prompt)
self.assertNotIn("## User Preferences and Project Context", human_prompt)
- def test_show_page_runtime_state_selects_one_history_contract(self):
+ def test_show_page_history_is_skill_scoped_and_does_not_change_prompt(self):
context = MessageContext(
user_id="U1",
channel_id="C1",
@@ -1906,17 +1906,17 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
):
self_managed = build_system_prompt_injection(include_quick_replies=True, context=context)
- self.assertIn("History is saved automatically around each turn", managed)
- self.assertNotIn("Avibe's shadow history continues automatically", managed)
- self.assertIn("Avibe's shadow history continues automatically", self_managed)
- self.assertNotIn("History is saved automatically around each turn", self_managed)
+ self.assertEqual(managed, self_managed)
+ self.assertEqual(managed, unavailable)
self.assertNotIn("History contract:", unavailable)
- self.assertNotIn("History is saved automatically around each turn", unavailable)
+ self.assertIn("Before creating, updating, or restoring a Show Page", managed)
skill = (Path(__file__).resolve().parents[1] / "skills" / "use-show-pages" / "SKILL.md").read_text()
- self.assertNotIn("History is saved automatically around each turn", skill)
- self.assertNotIn("Avibe's shadow history continues automatically in the background", skill)
- self.assertNotIn("Automatic Show Page history is unavailable", skill)
- self.assertIn("Follow the History contract in the current System Prompt", skill)
+ self.assertIn("### Show Page workspace history", skill)
+ self.assertIn("These rules apply only to this Session's Show Page workspace", skill)
+ self.assertIn("`history.mode` is `managed`", skill)
+ self.assertIn("`history.mode` is `self-managed`", skill)
+ self.assertIn("Separately entrusted repository work follows the user's mandate", skill)
+ self.assertNotIn("Follow the History contract in the current System Prompt", skill)
self.assertIn("`vibe show status`", skill)
def test_prompt_does_not_render_empty_agents_as_invokable_table_row(self):
diff --git a/tests/test_show_git.py b/tests/test_show_git.py
index 9076c72bb..2458a3fe8 100644
--- a/tests/test_show_git.py
+++ b/tests/test_show_git.py
@@ -23,7 +23,7 @@ from core.show_git import (
ShowGitCheckpointService,
ShowGitRepository,
TurnCheckpointContext,
- format_agent_contract,
+ show_history_status,
sanitize_checkpoint_subject,
)
@@ -104,19 +104,26 @@ def test_missing_workspace_never_creates_checkpoint_paths(resolved_git):
assert not repo.gitdir.parent.exists()
-def test_agent_contract_ownership_probe_never_creates_workspace():
+def test_history_status_never_creates_workspace_or_repository():
session_id = "ses_guidance_missing"
workspace = paths.get_show_page_dir(session_id)
gitdir = paths.get_show_git_dir(session_id)
- contract = format_agent_contract(checkpointing_available=True, session_id=session_id)
+ status = show_history_status(session_id)
- assert "History is saved automatically around each turn" in contract
+ assert status["mode"] == "managed"
+ assert status["git_dir"] == str(gitdir)
assert not workspace.exists()
assert not gitdir.exists()
assert not gitdir.parent.exists()
[email protected]("session_id", ["", "../other", "ses/name", "ses\\name"])
+def test_history_status_rejects_invalid_session_ids(session_id):
+ with pytest.raises(ValueError, match="Invalid Show Page session id"):
+ show_history_status(session_id)
+
+
def test_lazy_adoption_is_idempotent_and_native_git_works(resolved_git):
session_id = "ses_adopt"
workspace = _workspace(session_id)
@@ -251,8 +258,10 @@ def test_existing_user_git_pointer_with_managed_path_shape_is_never_overwritten(
assert pointer.read_bytes() == before
assert repo.gitdir != user_gitdir
assert _commit_count(repo) == 1
- contract = format_agent_contract(checkpointing_available=True, session_id=session_id)
- assert "addresses the **user's repo**, not Avibe history" in contract
+ status = show_history_status(session_id)
+ assert status["mode"] == "self-managed"
+ assert status["git_dir"] == str(repo.gitdir)
+ assert pointer.read_bytes() == before
def test_pre_and_post_turn_commit_only_when_dirty_with_frozen_messages(resolved_git):
@@ -305,6 +314,43 @@ def test_native_restore_is_recorded_as_a_forward_post_turn_commit(resolved_git):
assert _platform_git(repo, "log", "-1", "--format=%s").stdout.strip() == "restore v1"
[email protected]("self_managed", [False, True])
+def test_skill_status_drives_native_restore_without_changing_user_history(resolved_git, self_managed):
+ session_id = "ses_skill_restore"
+ workspace = _workspace(session_id)
+ target = workspace / "page.txt"
+ target.write_text("first\n")
+ if self_managed:
+ _native_git(workspace, "init", "--initial-branch=trunk")
+ _native_git(workspace, "add", "page.txt")
+ _native_git(workspace, "-c", "user.name=fixture", "-c", "[email protected]", "commit", "-m", "baseline")
+ user_git = workspace / ".git"
+ before = {str(path.relative_to(user_git)): path.read_bytes() for path in user_git.rglob("*") if path.is_file()} if self_managed else None
+ repo = _repo(session_id, resolved_git)
+ assert repo.checkpoint(PRE_TURN)
+ target.write_text("second\n")
+ assert repo.checkpoint(POST_TURN, message="second")
+ head = _platform_git(repo, "rev-parse", "HEAD").stdout.strip()
+
+ status = show_history_status(session_id)
+ assert status["mode"] == ("self-managed" if self_managed else "managed")
+ assert Path(status["git_dir"]).resolve() == repo.gitdir.resolve()
+ if self_managed:
+ _platform_git(repo, "log", "-1")
+ _platform_git(repo, "restore", "--source=HEAD~1", "--", "page.txt")
+ else:
+ actual_git = _native_git(workspace, "rev-parse", "--absolute-git-dir").stdout.strip()
+ assert Path(actual_git).resolve() == Path(status["git_dir"]).resolve()
+ _native_git(workspace, "log", "-1")
+ _native_git(workspace, "restore", "--source=HEAD~1", "--", "page.txt")
+ assert target.read_text() == "first\n"
+ assert _platform_git(repo, "rev-parse", "HEAD").stdout.strip() == head
+ assert repo.checkpoint(POST_TURN, message="restore first")
+ assert _platform_git(repo, "rev-parse", "HEAD^").stdout.strip() == head
+ if self_managed:
+ assert {str(path.relative_to(user_git)): path.read_bytes() for path in user_git.rglob("*") if path.is_file()} == before
+
+
def test_main_rewind_is_converted_to_a_forward_commit(resolved_git):
session_id = "ses_rewind"
workspace = _workspace(session_id)
@@ -710,26 +756,26 @@ def test_agent_initiated_turn_reuses_fsm_bus_lifecycle(resolved_git, monkeypatch
]
-def test_agent_contract_uses_startup_latched_checkpoint_service_state(resolved_git, monkeypatch):
+def test_history_status_uses_startup_latched_checkpoint_service_state(resolved_git, monkeypatch):
bus = InboxEventBus()
unavailable_service = ShowGitCheckpointService(None)
unavailable_service.start(bus)
monkeypatch.setattr(show_git, "resolve_git", lambda: resolved_git)
- unavailable = format_agent_contract(session_id="ses_latched_unavailable")
+ unavailable = show_history_status("ses_latched_unavailable")
unavailable_status = json.loads(paths.get_show_git_runtime_status_path().read_text(encoding="utf-8"))
unavailable_service.stop()
active_service = ShowGitCheckpointService(resolved_git)
active_service.start(bus)
monkeypatch.setattr(show_git, "resolve_git", lambda: None)
- available = format_agent_contract(session_id="ses_latched_available")
+ available = show_history_status("ses_latched_available")
active_status = json.loads(paths.get_show_git_runtime_status_path().read_text(encoding="utf-8"))
active_service.stop()
- assert unavailable == ""
+ assert unavailable["checkpointing_active"] is False
assert unavailable_status["active"] is False
- assert "History is saved automatically around each turn" in available
+ assert available["checkpointing_active"] is True
assert active_status["active"] is True
assert active_status["service_pid"] == os.getpid()
diff --git a/tests/test_show_pages.py b/tests/test_show_pages.py
index ef5acbfad..401e20e04 100644
--- a/tests/test_show_pages.py
+++ b/tests/test_show_pages.py
@@ -3076,6 +3076,40 @@ def test_show_update_rotate_share_fails_while_private(monkeypatch, tmp_path, cap
assert payload["code"] == "not_shared"
[email protected]("mode", ["managed", "self-managed"])
[email protected]("active", [False, True])
+def test_show_status_exposes_history_without_modifying_either_repository(monkeypatch, tmp_path, capsys, mode, active):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ monkeypatch.setenv("AVIBE_SESSION_ID", "sesHistory")
+ paths.ensure_data_dirs()
+ _save_config()
+ store = ShowPageStore()
+ try:
+ store.ensure("sesHistory")
+ finally:
+ store.close()
+ workspace = paths.get_show_page_dir("sesHistory")
+ workspace.mkdir(parents=True, exist_ok=True)
+ if mode == "self-managed":
+ (workspace / ".git").mkdir()
+ (workspace / ".git" / "HEAD").write_text("ref: refs/heads/user-branch\n")
+ before = {str(path.relative_to(workspace)): path.read_bytes() for path in workspace.rglob("*") if path.is_file()}
+ monkeypatch.setattr("core.show_git.show_git_checkpointing_active", lambda: active)
+ monkeypatch.setattr(cli.runtime, "read_status", lambda: {})
+ parser = cli.build_parser()
+
+ assert cli.cmd_show_status(parser.parse_args(["show", "status", "--json"])) == 0
+ payload = json.loads(capsys.readouterr().out)
+ assert payload["path"] == str(workspace)
+ assert payload["history"] == {
+ "mode": mode,
+ "checkpointing_active": active,
+ "git_dir": str(paths.get_show_git_dir("sesHistory")),
+ }
+ assert not paths.get_show_git_dir("sesHistory").exists()
+ assert {str(path.relative_to(workspace)): path.read_bytes() for path in workspace.rglob("*") if path.is_file()} == before
+
+
def _seed_show_cli_session(session_id: str = "ses123") -> None:
from storage import messages_service
from storage.db import create_sqlite_engine
diff --git a/vibe/cli.py b/vibe/cli.py
index b5f910311..5d1eca131 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -1871,6 +1871,8 @@ def _show_status_examples_text() -> str:
Fields include:
path, visibility, active_url, private_url, public_url, share_id, offline, created_at, updated_at.
+ JSON includes history.mode (managed or self-managed), history.checkpointing_active,
+ and history.git_dir (Avibe's history directory, not the user's repository).
Use --json when another program or agent will consume the result.
"""
@@ -13941,6 +13943,8 @@ def _prewarm_show_page_session_best_effort(
def cmd_show_status(args):
+ from core.show_git import show_history_status
+
store = _load_show_page_store()
try:
session_id, session_default_notice = _resolve_show_session_id(args, help_command="vibe show status --help")
@@ -13964,7 +13968,10 @@ def cmd_show_status(args):
payload = _show_page_result(
page,
message=f"Show Page is {page.visibility}.",
- extra={"session_default_notice": session_default_notice} if session_default_notice else None,
+ extra={
+ "history": show_history_status(session_id),
+ **({"session_default_notice": session_default_notice} if session_default_notice else {}),
+ },
)
if getattr(args, "json", False):
_print_json(payload)