DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
Merge pull request #1360 from fetw882/feat/grok-cli-connector
Bingxi Zhao (Frank)dadb7627440e
diff --cc AGENTS.mdindex 1bdb97f3f,fe380125f..1651c6492--- a/AGENTS.md+++ b/AGENTS.md@@@ -121,9 -106,10 +121,10 @@@ deeptutor start # bac| `deeptutor/runtime/registry/` | Tool + Capability registries || `deeptutor/runtime/bootstrap/builtin_capabilities.py` | Built-in capability class paths || `deeptutor/services/config/runtime_settings.py` | JSON settings + process-env overrides |+ | `deeptutor/services/subagent/` | Local/remote agent connectors; register each backend in `registry.py` and its model options in `models.py` (Grok CLI uses native `streaming-json`) |-| `deeptutor/core/stream.py`, `stream_bus.py` | StreamEvent protocol + async fan-out |+| `deeptutor/core/stream.py`, `deeptutor/runtime/stream_bus.py` | StreamEvent protocol + async fan-out || `deeptutor/core/tool_protocol.py` | `BaseTool` + `ToolDefinition` |-| `deeptutor/core/capability_protocol.py` | `BaseCapability` + `CapabilityManifest` |+| `deeptutor/core/capability_protocol.py` | `TurnCapability` + `CapabilityManifest` || `deeptutor/core/context.py` | `UnifiedContext` dataclass || `deeptutor/tools/builtin/__init__.py` | All built-in tool wrappers || `deeptutor/capabilities/` | Built-in capability implementations |diff --cc README.mdindex be64cf1e2,95c7b44dd..06ba629d1--- a/README.md+++ b/README.md@@@ -232,8 -225,8 +232,8 @@@ DeepTutor is an agent-native learning w- **One runtime for every mode** — Chat, Ask Questions, Quiz, Research, Visualize, Solve, Course Study, Mastery Path, Immersive Reading, and Immersive Watching share one capability runtime and session context while keeping purpose-built loops and pipelines.- **Connected learning context** — Knowledge bases, books, Co-Writer drafts, notebooks, question banks, personas, and Memory can be reused across the workflows that support them, subject to account grants and learning policies.- **Immersive video learning** — paste a YouTube link for privacy-enhanced native playback, synchronized captions, timestamp-grounded tutoring, and resumable progress; administrators can switch playback to a self-hosted Invidious instance without rebuilding materials.- - **Subagents and Partners** — from Chat, consult a live agent harness (Claude Code, Codex, Antigravity, Kimi, opencode, MiMo, Hermes, OpenClaw, or DeepSeek) or a Partner, import past conversations, and run persistent IM companions on the same brain.+ - **Subagents and Partners** — from Chat, consult a live agent harness (Claude Code, Codex, Grok CLI, Antigravity, Kimi, opencode, MiMo, Hermes, OpenClaw, or DeepSeek) or a Partner, import past conversations, and run persistent IM companions on the same brain.-- **Multi-engine knowledge** — versioned RAG libraries across LlamaIndex, PageIndex, GraphRAG, LightRAG, a remote LightRAG Server, a self-hosted WeKnora knowledge base, a Tencent IMA or MarginNote 4 library, or a linked Obsidian vault, with pluggable document parsing.+- **Multi-engine knowledge** — versioned RAG libraries across LlamaIndex, PageIndex, GraphRAG, LightRAG, a remote LightRAG Server, a self-hosted WeKnora knowledge base, a Tencent IMA or MarginNote 4 library, or a linked Obsidian vault, with pluggable document parsing. See [native LightRAG role models](deeptutor/services/rag/pipelines/lightrag/README.md) for independent extraction, query and vision settings, default-only creation and confirmed rebuilds.- **Extensible tools and skills** — built-in tools, MCP servers, CLI apps, image / video / voice generation models, and installable community skills from EduHub.- **Inspectable memory** — L1 traces, L2 surface summaries, and L3 synthesis make personalization visible and editable; the Memory Graph links L2 facts to L1 evidence and L3 synthesis to contributing surfaces.@@@ -700,7 -683,32 +700,32 @@@ For faster setup, the Partner channel p<img src="assets/figs/web-1.4.6+/myagents/00-overview.png" alt="DeepTutor My Agents workspace" width="900"></div>- My Agents turns other agents into context for DeepTutor, and does two distinct things. **Connect a live agent** — Claude Code, Codex, Antigravity, Kimi, opencode, MiMo Code, Hermes Agent, OpenClaw, or DeepSeek Harness on your machine, a remote Hermes gateway, or one of your Partners — and consult it from inside a chat turn: DeepTutor actually *runs* the other agent and streams its work into the Activity panel via the `consult_subagent` tool. Select it and its round limit with the Agent chip, or filter the same connected-agent list with `@`; the choice stays attached to the session.-My Agents turns other agents into context for DeepTutor, and does two distinct things. **Connect a live agent** — Claude Code, Codex, Grok CLI, Antigravity, Kimi, opencode, MiMo Code, Hermes Agent, OpenClaw, or DeepSeek Harness on your machine, or one of your Partners — and consult it from inside a chat turn: DeepTutor actually *runs* the other agent and streams its work into the Activity panel via the `consult_subagent` tool. Select it and its round limit with the Agent chip, or filter the same connected-agent list with `@`; the choice stays attached to the session.++My Agents turns other agents into context for DeepTutor, and does two distinct things. **Connect a live agent** — Claude Code, Codex, Grok CLI, Antigravity, Kimi, opencode, MiMo Code, Hermes Agent, OpenClaw, or DeepSeek Harness on your machine, a remote Hermes gateway, or one of your Partners — and consult it from inside a chat turn: DeepTutor actually *runs* the other agent and streams its work into the Activity panel via the `consult_subagent` tool. Select it and its round limit with the Agent chip, or filter the same connected-agent list with `@`; the choice stays attached to the session.++ **Connect Grok CLI.** Install xAI's Grok CLI on the machine running the DeepTutor+ backend, run `grok login` there, and verify that `grok --help` lists+ `--output-format streaming-json`. Then open **My Agents → Connect**, select+ **Grok CLI**, and choose a working directory. Detection checks the executable's+ protocol support; it does not verify login or model access. The connector has+ been exercised with Grok CLI 1.0.3; unrelated third-party commands also named+ `grok` are not supported.++ In **Settings → Partners & Agents → Grok CLI**, leave model and reasoning effort+ empty to use the CLI defaults, or enter values supported by your account's+ `grok models` output. System instructions are passed through `--rules`. The+ default permission mode is `dontAsk`: Grok uses its existing rules and built-in+ read-only handling, and denies operations that need approval. This is a CLI+ permission policy, not a filesystem sandbox. Broader modes can be selected+ explicitly in settings; advanced CLI flags remain available through+ `backends.grok.extra_args` in the subagent settings API.++ Grok uses its own authentication and session storage; DeepTutor does not copy+ its credentials. Follow-up consults resume the connection's session in the same+ working directory. Text and tool activity stream live; private thought payloads+ are omitted. Cross-session Grok memory is disabled by default. This connector+ supports text questions and CLI tools, not image forwarding or importing past+ Grok conversations. In Docker, install and authenticate Grok inside the backend+ container; a CLI installed only on the browser's computer is not reachable.<div align="center"><img src="assets/figs/web-1.4.6+/home/08-subagent%20demo%20with%20claude%20code.png" alt="Consulting a Claude Code subagent live" width="900">diff --cc web/components/agents/ConnectedAgents.tsxindex 2a3930d7a,9e3e6af84..f9fa297b1--- a/web/components/agents/ConnectedAgents.tsx+++ b/web/components/agents/ConnectedAgents.tsx@@@ -21,9 -34,10 +21,10 @@@ const REMOTE_HERMES_KIND = "hermes_remotype Lang = { zh: string; en: string };-function backendLabel(kind: string, tr: (l: Lang) => string): string {+function backendLabel(kind: string): string {if (kind === "claude_code") return "Claude Code";if (kind === "codex") return "Codex";+ if (kind === "grok") return "Grok CLI";if (kind === "antigravity") return "Antigravity CLI";if (kind === "kimi") return "Kimi CLI";if (kind === "opencode") return "opencode";diff --cc web/components/settings/SettingsPageContent.tsxindex 93cc55425,000000000..1c8039759mode 100644,000000..100644--- a/web/components/settings/SettingsPageContent.tsx+++ b/web/components/settings/SettingsPageContent.tsx@@@ -1,275 -1,0 +1,276 @@@+"use client";++import dynamic from "next/dynamic";+import Link from "next/link";+import { useEffect } from "react";+import { useRouter } from "next/navigation";+import { useTranslation } from "react-i18next";+import { useSettings } from "@/features/settings/store/SettingsStore";+import { useSettingsAccess } from "@/features/settings/navigation/SettingsAccessProvider";+import {+ resolveSettingsKey,+ settingsAnchorHref,+} from "@/features/settings/navigation/settings-nav";+import {+ settingsPageFamily,+ visibleSettingsPages,+} from "@/features/settings/navigation/settings-pages";++const loading = () => (+ <div+ className="min-h-48 animate-pulse rounded-xl bg-[var(--muted)]/30"+ aria-busy="true"+ />+);+const General = dynamic(() => import("./SettingsOverview"), { loading });+const Usage = dynamic(() => import("@/features/settings/sections/UsageSettingsSection"), { loading });+const DataMigration = dynamic(() => import("@/features/settings/sections/DataMigrationSettingsSection"), { loading });+const Status = dynamic(() => import("./SettingsRuntimePage"), { loading });+const Appearance = dynamic(+ () => import("@/features/settings/sections/AppearanceSettingsSection"),+ {+ loading,+ },+);+const Network = dynamic(+ () => import("@/features/settings/sections/NetworkSettingsSection"),+ {+ loading,+ },+);+const Workspace = dynamic(+ () => import("@/features/settings/sections/WorkspaceSettingsSection"),+ {+ loading,+ },+);+const Knowledge = dynamic(+ () => import("@/features/settings/sections/DocumentParsingSettingsSection"),+ { loading },+);+const Memory = dynamic(+ () => import("@/features/settings/sections/MemorySettingsSection"),+ {+ loading,+ },+);+const About = dynamic(+ () => import("@/features/settings/sections/AboutSettingsSection"),+ {+ loading,+ },+);+const Learner = dynamic(+ () => import("@/features/settings/sections/LearnerProfileSettingsSection"),+ { loading },+);+const Guardian = dynamic(+ () => import("@/features/settings/sections/GuardianSettingsSection"),+ {+ loading,+ },+);+const Connections = dynamic(+ () =>+ import("@/features/settings/sections/models/ConnectionsSettingsSection"),+ { loading },+);+const Llm = dynamic(+ () => import("@/features/settings/sections/models/LlmSettingsSection"),+ {+ loading,+ },+);+const Task = dynamic(+ () => import("@/features/settings/sections/models/TaskModelsSettingsSection"),+ { loading },+);+const Embedding = dynamic(+ () => import("@/features/settings/sections/models/EmbeddingSettingsSection"),+ { loading },+);+const Search = dynamic(+ () => import("@/features/settings/sections/models/SearchSettingsSection"),+ {+ loading,+ },+);+const Tts = dynamic(+ () => import("@/features/settings/sections/models/TtsSettingsSection"),+ {+ loading,+ },+);+const Stt = dynamic(+ () => import("@/features/settings/sections/models/SttSettingsSection"),+ {+ loading,+ },+);+const Image = dynamic(+ () => import("@/features/settings/sections/models/ImageSettingsSection"),+ {+ loading,+ },+);+const Video = dynamic(+ () => import("@/features/settings/sections/models/VideoSettingsSection"),+ {+ loading,+ },+);+const VideoLearning = dynamic(+ () => import("@/features/settings/sections/VideoLearningSettingsSection"),+ { loading },+);+const Tools = dynamic(+ () => import("@/features/settings/sections/ToolsSettingsSection"),+ {+ loading,+ },+);+const Capabilities = dynamic(+ () => import("@/features/settings/sections/CapabilitiesSettingsSection"),+ { loading },+);+const Starters = dynamic(+ () => import("@/features/settings/sections/StartersSettingsSection"),+ {+ loading,+ },+);+const Attachments = dynamic(+ () => import("@/features/settings/sections/AttachmentsSettingsSection"),+ { loading },+);+const Agent = dynamic(+ () =>+ import("./SubagentSettingsEditor").then(+ (module) => module.SubagentSettingsEditor,+ ),+ { loading },+);++const Archive = dynamic(+ () => import("@/features/settings/sections/ArchivedChatsSettingsSection"),+ {+ loading,+ },+);++const Voice = dynamic(+ () => import("@/features/settings/sections/models/VoiceSettingsSection"),+ { loading },+);++const Multimodal = dynamic(+ () => import("@/features/settings/sections/models/MultimodalSettingsSection"),+ { loading },+);++const PAGES: Record<string, React.ComponentType> = {+ "data-migration": DataMigration,+ voice: Voice,+ multimodal: Multimodal,+ archive: Archive,+ general: General,+ status: Status,+ usage: Usage,+ appearance: Appearance,+ network: Network,+ workspace: Workspace,+ knowledge: Knowledge,+ memory: Memory,+ about: About,+ "learner-profile": Learner,+ guardian: Guardian,+ connections: Connections,+ llm: Llm,+ "task-models": Task,+ embedding: Embedding,+ search: Search,+ tts: Tts,+ stt: Stt,+ imagegen: Image,+ videogen: Video,+ "video-learning": VideoLearning,+ tools: Tools,+ capabilities: Capabilities,+ starters: Starters,+ attachments: Attachments,+};+const AGENTS = {+ "agent-claude-code": "claude_code",+ "agent-codex": "codex",++ "agent-grok": "grok",+ "agent-antigravity": "antigravity",+ "agent-kimi": "kimi",+ "agent-opencode": "opencode",+ "agent-mimo": "mimo",+ "agent-hermes": "hermes",+ "agent-hermes-remote": "hermes_remote",+ "agent-openclaw": "openclaw",+ "agent-deepseek-harness": "deepseek_harness",+} as const;++export default function SettingsPageContent({ section }: { section: string }) {+ const { t, i18n } = useTranslation();+ const router = useRouter();+ const access = useSettingsAccess();+ const { settingsLoading, saving, applying } = useSettings();+ const key = resolveSettingsKey(section);+ const pages = visibleSettingsPages(access);+ const page = pages.find((item) => item.key === key);+ const family = settingsPageFamily(key).flatMap((member) =>+ pages.filter((item) => item.key === member),+ );+ const zh = i18n.language?.toLowerCase().startsWith("zh");+ useEffect(() => {+ if (key !== section)+ router.replace(settingsAnchorHref(key) + window.location.search, {+ scroll: false,+ });+ }, [key, section, router]);+ if (!access.resolved) return loading();+ if (settingsLoading) return loading();+ if (!page)+ return (+ <div className="space-y-4">+ <h1 className="text-xl font-semibold">+ {t("This settings page is unavailable.")}+ </h1>+ <Link href="/settings/general" className="text-sm underline">+ {t("Back to settings")}+ </Link>+ </div>+ );+ const Component = PAGES[key];+ const kind = AGENTS[key as keyof typeof AGENTS];+ return (+ <fieldset disabled={saving || applying} aria-busy={saving || applying} className="min-w-0" data-settings-page={key}>+ {family.length > 1 && (+ <nav+ aria-label={t("Related settings")}+ className="mb-8 flex flex-wrap gap-1 border-b border-[var(--border)]/60 pb-3"+ >+ {family.map((item) => (+ <Link+ key={item.key}+ href={settingsAnchorHref(item.key)}+ scroll={false}+ aria-current={item.key === key ? "page" : undefined}+ className={`rounded-lg px-3 py-2 text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] ${item.key === key ? "bg-[var(--accent)] font-medium" : "text-[var(--muted-foreground)] hover:bg-[var(--accent)]/50"}`}+ >+ {zh ? item.label.zh : item.label.en}+ </Link>+ ))}+ </nav>+ )}+ {Component ? (+ <Component key={key} />+ ) : kind ? (+ <Agent key={key} kind={kind} />+ ) : null}+ </fieldset>+ );+}diff --cc web/components/settings/SubagentSettingsEditor.tsxindex 29b27e1bd,3e67e0637..2e8fbf113--- a/web/components/settings/SubagentSettingsEditor.tsx+++ b/web/components/settings/SubagentSettingsEditor.tsx@@@ -277,8 -326,9 +327,10 @@@ export function SubagentSettingsEditor(const tr = useCallback((l: Lang) => (zh ? l.zh : l.en), [zh]);const [options, setOptions] = useState<SubagentBackendOptions | null>(null);- const [liveConfig, setLiveConfig] = useState<SubagentBackendConfig>({ ...DEFAULTS });- const [config, setConfig] = useState<SubagentBackendConfig>({++ const [liveConfig, setLiveConfig] = useState<SubagentBackendConfig>({+ ...defaultsForKind(kind),+ });+ const [config, setConfig] = useStagedSettings(`subagent:${kind}`, liveConfig, setLiveConfig);const [customModel, setCustomModel] = useState(false);const [loading, setLoading] = useState(true);const [syncing, setSyncing] = useState(false);@@@ -302,7 -352,7 +354,7 @@@]);setOptions(opts);const stored = settings.backends?.[kind] ?? {};- setLiveConfig({ ...DEFAULTS, ...stored });- setConfig({ ...defaultsForKind(kind), ...stored });++ setLiveConfig({ ...defaultsForKind(kind), ...stored });} catch (err) {setError(err instanceof Error ? err.message : String(err));} finally {diff --cc web/tests/subagent-grok-settings.spec.tsxindex 000000000,ac2cf6161..085d30f4bmode 000000,100644..100644--- a/web/tests/subagent-grok-settings.spec.tsx+++ b/web/tests/subagent-grok-settings.spec.tsx@@@ -1,0 -1,136 +1,165 @@@+ import {+ fireEvent,+ render,+ screen,+ waitFor,+ within,+ } from "@testing-library/react";+ import { beforeEach, describe, expect, it, vi } from "vitest";++ import { SubagentSettingsEditor } from "@/components/settings/SubagentSettingsEditor";+ import {+ getBackendOptions,+ getSubagentSettings,- updateSubagentSettings,+ } from "@/lib/subagents-api";++ vi.mock("react-i18next", () => ({+ useTranslation: () => ({ i18n: { language: "en" } }),+ }));+++const staged = vi.hoisted(() => {++ const payloads = new Map<string, unknown>();++ return {++ payloads,++ pendingExtensionPayload: (key: string) => payloads.get(key),++ registerExtension: vi.fn(++ (key: string, edit: { payload: unknown } | null) => {++ if (edit) payloads.set(key, edit.payload);++ else payloads.delete(key);++ },++ ),++ };++});++++vi.mock("@/features/settings/store/SettingsStore", () => ({++ useSettings: () => ({++ applying: false,++ draftRevision: 0,++ pendingExtensionPayload: staged.pendingExtensionPayload,++ registerExtension: staged.registerExtension,++ }),++}));+++ vi.mock("@/lib/subagents-api", () => ({+ getBackendOptions: vi.fn(),+ getSubagentSettings: vi.fn(),- updateSubagentSettings: vi.fn(),+ syncBackendOptions: vi.fn(),+ }));++ beforeEach(() => {++ staged.payloads.clear();++ staged.registerExtension.mockClear();+ vi.mocked(getBackendOptions).mockResolvedValue([+ {+ kind: "grok",+ display_name: "Grok CLI",+ available: true,+ version: "installed",+ default_model: "",+ models: [],+ efforts: [],+ allow_custom_model: true,+ synced_at: "",+ detail: "",+ },+ ]);+ vi.mocked(getSubagentSettings).mockResolvedValue({+ consult_budget: 5,+ backends: {},+ });- vi.mocked(updateSubagentSettings).mockResolvedValue({- consult_budget: 5,- backends: {},- });+ });++ describe("Grok CLI settings", () => {+ it("defaults to dontAsk and exposes only supported permission and input controls", async () => {+ render(<SubagentSettingsEditor kind="grok" />);++ const permissions = await screen.findByRole("combobox", {+ name: "Permission mode",+ });+ expect(permissions).toHaveValue("dontAsk");+ expect(+ within(permissions)+ .getAllByRole("option")+ .map((option) => (option as HTMLOptionElement).value),+ ).toEqual([+ "dontAsk",+ "plan",+ "default",+ "acceptEdits",+ "auto",+ "bypassPermissions",+ ]);+ expect(+ screen.getByRole("textbox", { name: "Reasoning effort" }),+ ).toBeEnabled();+ expect(screen.queryByText("Forward images")).not.toBeInTheDocument();+ expect(screen.queryByText("Auto-approve")).not.toBeInTheDocument();- expect(updateSubagentSettings).not.toHaveBeenCalled();++ expect(staged.payloads.size).toBe(0);++ fireEvent.change(permissions, { target: { value: "plan" } });+ await waitFor(() =>- expect(updateSubagentSettings).toHaveBeenCalledWith({- backends: { grok: { permission_mode: "plan" } },++ expect(staged.payloads.get("subagent:grok")).toMatchObject({++ permission_mode: "plan",+ }),+ );+ });++ it("saves a manually entered model, effort, and rules without overwriting permissions", async () => {+ vi.mocked(getSubagentSettings).mockResolvedValue({+ consult_budget: 5,+ backends: { grok: { permission_mode: "plan" } },+ });- render(<SubagentSettingsEditor kind="grok" />);++ const { rerender } = render(<SubagentSettingsEditor kind="grok" />);++ const modelSelector = await screen.findByRole("combobox", {+ name: "Model",+ });+ expect(within(modelSelector).getAllByRole("option")).toHaveLength(2);+ fireEvent.change(modelSelector, { target: { value: "__custom__" } });+ const model = screen.getByRole("textbox", { name: "Custom model" });+ fireEvent.change(model, { target: { value: " user-model " } });++ rerender(<SubagentSettingsEditor kind="grok" />);+ fireEvent.blur(model);+ await waitFor(() =>- expect(updateSubagentSettings).toHaveBeenCalledWith({- backends: { grok: { model: "user-model" } },++ expect(staged.payloads.get("subagent:grok")).toMatchObject({++ model: "user-model",++ permission_mode: "plan",+ }),+ );++ rerender(<SubagentSettingsEditor kind="grok" />);++ const effort = screen.getByRole("textbox", { name: "Reasoning effort" });+ await waitFor(() => expect(effort).toBeEnabled());+ fireEvent.change(effort, { target: { value: " high " } });++ rerender(<SubagentSettingsEditor kind="grok" />);+ fireEvent.blur(effort);+ await waitFor(() =>- expect(updateSubagentSettings).toHaveBeenCalledWith({- backends: { grok: { effort: "high" } },++ expect(staged.payloads.get("subagent:grok")).toMatchObject({++ model: "user-model",++ effort: "high",++ permission_mode: "plan",+ }),+ );++ rerender(<SubagentSettingsEditor kind="grok" />);++ const rules = screen.getByRole("textbox", { name: "System prompt" });+ await waitFor(() => expect(rules).toBeEnabled());+ fireEvent.change(rules, {+ target: { value: "Check the textbook before explaining." },+ });++ rerender(<SubagentSettingsEditor kind="grok" />);+ fireEvent.blur(rules);+ await waitFor(() =>- expect(updateSubagentSettings).toHaveBeenCalledWith({- backends: {- grok: { system_prompt: "Check the textbook before explaining." },- },++ expect(staged.payloads.get("subagent:grok")).toMatchObject({++ model: "user-model",++ effort: "high",++ permission_mode: "plan",++ system_prompt: "Check the textbook before explaining.",+ }),+ );++ rerender(<SubagentSettingsEditor kind="grok" />);+ expect(+ screen.getByRole("combobox", { name: "Permission mode" }),+ ).toHaveValue("plan");+ });+ });