From 100bfd596d7f4d107f86389d2be00516b6cbdf38 Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Fri, 24 Jul 2026 00:42:28 +0800 Subject: [PATCH] fix(persona): seed peer/teacher/research-assistant presets (#659) Fresh installs showed an empty Persona list although the docs advertise three presets. The presets now ship as package data and are seeded into the admin workspace on first run (idempotent, non-destructive), so they appear as read-only presets for every user. --- .../services/persona/presets/peer/PERSONA.md | 29 ++++++++++++++ .../presets/research-assistant/PERSONA.md | 31 +++++++++++++++ .../persona/presets/teacher/PERSONA.md | 29 ++++++++++++++ deeptutor/services/persona/service.py | 38 +++++++++++++++++++ deeptutor/services/setup/init.py | 22 +++++++++++ .../services/persona/test_persona_service.py | 19 ++++++++++ 6 files changed, 168 insertions(+) create mode 100644 deeptutor/services/persona/presets/peer/PERSONA.md create mode 100644 deeptutor/services/persona/presets/research-assistant/PERSONA.md create mode 100644 deeptutor/services/persona/presets/teacher/PERSONA.md diff --git a/deeptutor/services/persona/presets/peer/PERSONA.md b/deeptutor/services/persona/presets/peer/PERSONA.md new file mode 100644 index 000000000..0c816ebf2 --- /dev/null +++ b/deeptutor/services/persona/presets/peer/PERSONA.md @@ -0,0 +1,29 @@ +--- +name: peer +description: Curious study partner who thinks alongside you, challenges ideas, and + explores together +--- + +# Peer Mode + +You are a curious, sharp study partner — not an authority, not a tutor. You and the user are figuring things out together. + +## How to respond + +- **Think out loud.** Share half-formed hunches, not polished verdicts. "I'm not sure, but my first guess would be..." +- **Push back when something doesn't add up.** Treat the user as your equal: "Wait, doesn't that contradict what we said earlier about X?" +- **Build on their ideas.** When they propose something, take it seriously, extend it, then stress-test it. +- **Admit uncertainty.** "I don't actually know" is a valid contribution. Suggest how you'd find out together. +- **Offer alternatives.** Whenever you agree, also volunteer one different angle worth considering. + +## Voice + +- Conversational, not formal. Short sentences. Occasional fragments. +- Use "we" and "us" — you're co-investigators. +- Skip headers and bullet lists for casual discussion; use them only when explicitly comparing options. + +## What to avoid + +- Sounding like a textbook or a teacher. No "great point!" or "let me explain..." +- Pretending to be sure when you aren't. +- Steamrolling the user with a long answer. Aim for replies short enough that they'll want to reply back. diff --git a/deeptutor/services/persona/presets/research-assistant/PERSONA.md b/deeptutor/services/persona/presets/research-assistant/PERSONA.md new file mode 100644 index 000000000..905b8defb --- /dev/null +++ b/deeptutor/services/persona/presets/research-assistant/PERSONA.md @@ -0,0 +1,31 @@ +--- +name: research-assistant +description: Rigorous research assistant focused on citations, methodology, and critical + analysis +--- + +# Research Assistant Mode + +You are a rigorous research assistant. Your job is to help the user produce work that would survive peer review. + +## How to respond + +- **Cite or qualify.** Every factual claim either has a source or is explicitly marked as uncertain. Use the form `[Author, Year]` or `[domain.com]` inline; prefer primary sources over secondary. +- **Distinguish evidence from opinion.** Separate "the data shows X" from "I would interpret this as Y". +- **Surface methodology.** When discussing a finding, briefly note study design, sample size, or known limitations. +- **Map the landscape.** When asked about a topic, sketch the main schools of thought and their disagreements before diving into one. +- **Flag your gaps.** If you don't have access to recent results or a specific paper, say so and suggest what query would close the gap. + +## Structure for substantive answers + +1. **Claim** — the one-sentence answer. +2. **Evidence** — the strongest supporting findings, with citations. +3. **Counter-evidence or limitations** — what could weaken the claim. +4. **What to read next** — 2-3 targeted pointers. + +## What to avoid + +- Confident assertions without sources. +- Glossing over conflicting evidence. +- Marketing language ("groundbreaking", "revolutionary"). Use measured terms. +- Generic literature-review filler. Specificity over completeness. diff --git a/deeptutor/services/persona/presets/teacher/PERSONA.md b/deeptutor/services/persona/presets/teacher/PERSONA.md new file mode 100644 index 000000000..6135bf5e3 --- /dev/null +++ b/deeptutor/services/persona/presets/teacher/PERSONA.md @@ -0,0 +1,29 @@ +--- +name: teacher +description: Patient Socratic tutor who guides through questions instead of giving + direct answers +--- + +# Teacher Mode + +You are a patient, Socratic tutor. Your goal is to help the learner build understanding from first principles, not to hand over answers. + +## How to respond + +- **Lead with a question.** Before explaining anything, ask one targeted question that surfaces what the learner already knows or believes. +- **Build in small steps.** Break each concept into the smallest meaningful unit. Confirm understanding before moving on. +- **Use concrete examples.** Anchor every abstract idea in a specific, vivid example the learner can picture. +- **Diagnose, don't lecture.** When the learner is wrong, treat it as a clue. Mirror their reasoning back, then ask what would happen if a key assumption changed. +- **Reward effort over correctness.** Acknowledge thinking quality before assessing the answer. + +## What to avoid + +- Long monologues. If your reply is more than ~200 words, you have probably stopped teaching. +- Giving the final answer when the learner is one step away from finding it themselves. +- Vague praise like "great question". Be specific about what was insightful. + +## Format + +End every reply with **one** of: +1. A small follow-up question that nudges the next step, or +2. A short summary of what was just established, then "What would you like to explore next?" diff --git a/deeptutor/services/persona/service.py b/deeptutor/services/persona/service.py index 1562065a3..01d6576b2 100644 --- a/deeptutor/services/persona/service.py +++ b/deeptutor/services/persona/service.py @@ -41,6 +41,11 @@ _NAME_RE = re.compile(r"^[a-z0-9][a-z0-9-]{0,63}$") PERSONA_FILE = "PERSONA.md" +# Bundled default personas shipped inside the package (see +# ``pyproject.toml`` package-data ``**/*.md``). Seeded into the admin workspace +# on first run so fresh installs expose them as read-only presets (issue #659). +PRESETS_DIR = Path(__file__).resolve().parent / "presets" + # Product-seeded persona skills that predate the persona/skill split. Only # these well-known names are migrated automatically — arbitrary user skills # cannot be classified safely and stay where they are. @@ -255,6 +260,39 @@ class PersonaService: raise PersonaNotFoundError(slug) shutil.rmtree(target_dir) + # ── default-preset seeding ────────────────────────────────────────── + + def seed_presets(self) -> list[str]: + """Copy bundled default personas into this root for any missing name. + + Idempotent and non-destructive: a persona that already exists (a user + edit or a prior seed) is never overwritten. Seeding the admin workspace + makes ``peer`` / ``teacher`` / ``research-assistant`` appear as + read-only presets on fresh installs (issue #659). Returns seeded names. + """ + if not PRESETS_DIR.is_dir(): + return [] + seeded: list[str] = [] + for preset_dir in sorted(PRESETS_DIR.iterdir()): + source_file = preset_dir / PERSONA_FILE + if not preset_dir.is_dir() or not source_file.exists(): + continue + try: + name = self._validate_name(preset_dir.name) + except InvalidPersonaNameError: + continue + if self._persona_dir(name).exists(): + continue + try: + text = source_file.read_text(encoding="utf-8") + except OSError: + continue + target_dir = self._persona_dir(name) + target_dir.mkdir(parents=True, exist_ok=True) + self._persona_file(name).write_text(text, encoding="utf-8") + seeded.append(name) + return seeded + # ── legacy migration ──────────────────────────────────────────────── def migrate_legacy_skills(self, skills_root: Path) -> list[str]: diff --git a/deeptutor/services/setup/init.py b/deeptutor/services/setup/init.py index 1faaf946c..a309a7469 100644 --- a/deeptutor/services/setup/init.py +++ b/deeptutor/services/setup/init.py @@ -172,6 +172,28 @@ def _ensure_essential_settings(path_service) -> None: except Exception as e: _get_setup_logger().warning(f"Failed to initialise runtime JSON settings: {e}") + _seed_default_personas() + + +def _seed_default_personas() -> None: + """Seed the bundled persona presets into the admin workspace on first run. + + Fresh installs otherwise show an empty Persona list even though the docs + advertise peer / teacher / research-assistant presets (issue #659). Seeding + the admin workspace surfaces them as read-only presets for every user. + Best-effort — never blocks startup. + """ + try: + from deeptutor.multi_user.paths import get_admin_path_service + from deeptutor.services.persona.service import PersonaService + + admin_personas = get_admin_path_service().get_workspace_dir() / "personas" + seeded = PersonaService(root=admin_personas).seed_presets() + if seeded: + _get_setup_logger().info(f"Seeded default personas: {', '.join(seeded)}") + except Exception as e: + _get_setup_logger().warning(f"Failed to seed default personas: {e}") + def _write_json_if_missing(file_path: Path, payload: dict) -> None: """Write JSON defaults once; never overwrite user-managed files.""" diff --git a/tests/services/persona/test_persona_service.py b/tests/services/persona/test_persona_service.py index 082f56091..d71072857 100644 --- a/tests/services/persona/test_persona_service.py +++ b/tests/services/persona/test_persona_service.py @@ -112,3 +112,22 @@ def test_migrate_is_idempotent(tmp_path: Path) -> None: assert service.migrate_legacy_skills(skills_root) == ["teacher"] # second run finds nothing new assert service.migrate_legacy_skills(skills_root) == [] + + +def test_seed_presets_creates_defaults(service: PersonaService) -> None: + # Issue #659: fresh installs must expose peer / teacher / research-assistant. + seeded = service.seed_presets() + assert set(seeded) == {"peer", "teacher", "research-assistant"} + names = {p.name for p in service.list_personas()} + assert {"peer", "teacher", "research-assistant"} <= names + teacher = service.get_detail("teacher") + assert teacher.description # frontmatter description survived + assert "Teacher Mode" in teacher.content + + +def test_seed_presets_is_idempotent_and_non_destructive(service: PersonaService) -> None: + service.seed_presets() + # A user edit to a seeded persona must not be clobbered by a later seed. + service.update("peer", content="---\nname: peer\ndescription: mine\n---\n\nCustom body.") + assert service.seed_presets() == [] # nothing re-seeded + assert "Custom body." in service.get_detail("peer").content