Skip to content

πŸ› fix(agent-documents): render system docs in editor#15462

Merged
Innei merged 3 commits into
canaryfrom
fix/agent-doc-default-md-render
Jun 5, 2026
Merged

πŸ› fix(agent-documents): render system docs in editor#15462
Innei merged 3 commits into
canaryfrom
fix/agent-doc-default-md-render

Conversation

@Innei

@Innei Innei commented Jun 4, 2026

Copy link
Copy Markdown
Member

πŸ’» ε˜ζ›΄η±»εž‹ | Change Type

  • πŸ› Bug fix

πŸ”€ ε˜ζ›΄θ―΄ζ˜Ž | Description of Change

  • Keep ordinary agent-created documents as LobeHub system Documents without forcing a .md suffix into the title or visible filename.
  • Render extensionless agent/document / system document entries with the rich Document Editor instead of the highlight/code editor.
  • Preserve explicit code/text extensions such as .json and .txt so those files still open in highlight mode.
  • Share agent document file/category/source constants from @lobechat/const across app, server, and database usage.

πŸ§ͺ ζ΅‹θ―• | Testing

  • bunx vitest run --silent=passed-only src/server/services/agentDocuments/index.test.ts src/server/routers/lambda/__tests__/integration/agentDocumentVfs.integration.test.ts src/server/services/agentDocumentVfs/index.test.ts src/utils/__tests__/documentRenderMode.test.ts
  • bunx vitest run --silent=passed-only src/features/AgentDocumentsExplorer/types.test.ts src/features/AgentDocumentsExplorer/utils/canDrop.test.ts src/features/AgentDocumentsExplorer/DocumentExplorerTree.test.tsx src/routes/(main)/agent/features/Conversation/WorkingSidebar/ResourcesSection/AgentDocumentsGroup.test.tsx src/store/file/slices/document/action.test.ts
  • cd packages/database && bunx vitest run --silent=passed-only src/models/agentDocuments/__tests__/agentDocument.test.ts src/models/agentDocuments/__tests__/deriveFields.test.ts
  • git diff --check

@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Jun 4, 2026 6:16pm

Request Review

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 4, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e39ad55bbc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/utils/documentRenderMode.ts Outdated
const isEditorDocument = (document: DocumentRenderModeFields): boolean => {
if (document.category === 'document') return true;
if (document.fileType && EDITOR_DOCUMENT_FILE_TYPES.has(document.fileType)) return true;
return !!document.sourceType && EDITOR_DOCUMENT_SOURCE_TYPES.has(document.sourceType);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't force code agent files into the rich editor

When an agent/VFS caller writes an explicit code filename such as ./config.json, writeOrdinaryDocument preserves that extension but AgentDocumentModel.create still defaults sourceType to agent; this check returns editor mode before the filename language detection runs. In the portal path I inspected (DocumentBody calls getDocumentRenderMode(documentMeta)), those .json/.txt agent documents will no longer open in the highlight/code editor and saving can route them through the rich markdown editor instead.

Useful? React with πŸ‘Β / πŸ‘Ž.

doc.fileType === DOCUMENT_FOLDER_TYPE
? trimmedTitle
: trimmedTitle
? ensureDefaultAgentDocumentExtension(buildDocumentFilename(trimmedTitle))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the stored title extensionless on rename

For a title-only rename like New title, this now passes New title.md into AgentDocumentModel.rename, but that model treats the argument as the human title as well as the source for the filename, so it persists documents.title = 'New title.md'. That regresses the existing create behavior, which stores title: 'New title' while using filename: 'New title.md', and causes UI/tool callers that compare against or display title to see an unexpected extension after revalidation.

Useful? React with πŸ‘Β / πŸ‘Ž.


export type DocumentRenderMode = { mode: 'editor' } | { language: string; mode: 'highlight' };

const EDITOR_DOCUMENT_FILE_TYPES = new Set([

@Innei Innei Jun 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this hardcoded?


This comment was translated by Claude.

Original Content θΏ™ι‡Œζ˜―η‘¬ηΌ–η οΌŸ

} from './headlessEditor';

const MAX_UNIQUE_FILENAME_ATTEMPTS = 1000;
const DEFAULT_AGENT_DOCUMENT_EXTENSION = '.md';

@Innei Innei Jun 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted it. This should be reusable with the file tree's new file creation constant.


This comment was translated by Claude.

Original Content

ζŠ½δΊ† εΊ”θ―₯可δ»₯ε’Œ file treeηš„ζ–°ε»Ίζ–‡δ»Άε€η”¨εΈΈι‡


const LOBE_PATH = './lobe';
const LOBE_SKILLS_PATH = './lobe/skills';
const DEFAULT_AGENT_DOCUMENT_EXTENSION = '.md';

@Innei Innei Jun 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


This comment was translated by Claude.

Original Content

θΏ™ι‡ŒδΉŸζ˜―

const title = newTitle.trim();
const trimmedTitle = newTitle.trim();
const title =
doc.fileType === DOCUMENT_FOLDER_TYPE

@Innei Innei Jun 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use complex nested ternaries.


This comment was translated by Claude.

Original Content δΈθ¦ε€ζ‚ε΅Œε₯—δΈ‰ε…ƒ

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.62963% with 44 lines in your changes missing coverage. Please review.
βœ… Project coverage is 70.85%. Comparing base (f7c46a3) to head (0eb3f74).
⚠️ Report is 2 commits behind head on canary.

Additional details and impacted files
@@             Coverage Diff             @@
##           canary   #15462       +/-   ##
===========================================
- Coverage   86.75%   70.85%   -15.91%     
===========================================
  Files         387     3255     +2868     
  Lines       41713   321430   +279717     
  Branches     6609    28427    +21818     
===========================================
+ Hits        36189   227747   +191558     
- Misses       5409    93501    +88092     
- Partials      115      182       +67     
Flag Coverage Ξ”
app 61.55% <78.32%> (?)
database 92.54% <100.00%> (+<0.01%) ⬆️
packages/agent-manager-runtime 49.69% <ΓΈ> (?)
packages/agent-runtime 81.08% <ΓΈ> (?)
packages/builtin-tool-lobe-agent 18.52% <ΓΈ> (?)
packages/context-engine 84.19% <ΓΈ> (?)
packages/conversation-flow 91.29% <ΓΈ> (?)
packages/device-gateway-client 90.51% <ΓΈ> (?)
packages/eval-dataset-parser 95.15% <ΓΈ> (?)
packages/eval-rubric 76.11% <ΓΈ> (?)
packages/fetch-sse 85.57% <ΓΈ> (?)
packages/file-loaders 87.89% <ΓΈ> (ΓΈ)
packages/memory-user-memory 74.99% <ΓΈ> (?)
packages/model-bank 99.99% <ΓΈ> (?)
packages/model-runtime 84.22% <ΓΈ> (ΓΈ)
packages/prompts 72.51% <ΓΈ> (ΓΈ)
packages/python-interpreter 92.90% <ΓΈ> (?)
packages/ssrf-safe-fetch 0.00% <ΓΈ> (?)
packages/types 35.38% <ΓΈ> (?)
packages/utils 84.98% <ΓΈ> (?)
packages/web-crawler 88.08% <ΓΈ> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Ξ”
Store 68.53% <78.57%> (βˆ…)
Services 54.77% <36.36%> (βˆ…)
Server 71.85% <70.42%> (βˆ…)
Libs 57.03% <ΓΈ> (βˆ…)
Utils 81.71% <100.00%> (-18.29%) ⬇️
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Innei Innei force-pushed the fix/agent-doc-default-md-render branch from e39ad55 to bd5563b Compare June 4, 2026 06:55
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 4, 2026
Comment thread src/const/agentDocument.ts Outdated
Comment on lines +3 to +12
export const AGENT_DOCUMENT_CATEGORY = 'document';

export const AGENT_DOCUMENT_FILE_TYPE = 'agent/document';
export const AGENT_PLAN_FILE_TYPE = 'agent/plan';
export const CUSTOM_DOCUMENT_FILE_TYPE = 'custom/document';

export const MARKDOWN_DOCUMENT_FILE_TYPES = ['markdown', 'text/markdown', 'text/x-markdown'];

export const EDITOR_DOCUMENT_SOURCE_TYPES = ['agent', 'agent-signal', 'document'];

@Innei Innei Jun 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these used? Need to replace other business-use constants.


This comment was translated by Claude.

Original Content

θΏ™δΊ›εœ¨ε“ͺι‡Œδ½Ώη”¨ηš„οΌŸ ιœ€θ¦ζ›Ώζ’ε…Άδ»–ηš„δΈšεŠ‘δ½Ώη”¨εΈΈι‡

@Innei Innei force-pushed the fix/agent-doc-default-md-render branch from bd5563b to 7cffd94 Compare June 4, 2026 07:17
@Innei Innei force-pushed the fix/agent-doc-default-md-render branch from 7cffd94 to edec04a Compare June 4, 2026 08:00
@Innei Innei changed the title πŸ› fix(agent-documents): default documents to markdown πŸ› fix(agent-documents): render system docs in editor Jun 4, 2026
@Innei Innei force-pushed the fix/agent-doc-default-md-render branch from edec04a to b3dc3ef Compare June 4, 2026 15:19
@Innei

Innei commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

Innei added 2 commits June 5, 2026 01:16
…flush

Add debounced autosave to the non-markdown highlight editor and a StrictMode-safe
unmount flush via queueMicrotask, plus a beforeunload guard against dirty buffers.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Innei Innei force-pushed the fix/agent-doc-default-md-render branch from a726641 to 0eb3f74 Compare June 4, 2026 17:24
@Innei Innei merged commit 65ba086 into canary Jun 5, 2026
35 of 37 checks passed
@Innei Innei deleted the fix/agent-doc-default-md-render branch June 5, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant