Skip to content

Add project knowledge files: upload .md docs for agents (#22) - #250

Open
arkaccess wants to merge 2 commits into
AutoForgeAI:masterfrom
arkaccess:swarm/issue-22-ada
Open

arkaccess wants to merge 2 commits into
AutoForgeAI:masterfrom
arkaccess:swarm/issue-22-ada

Conversation

@arkaccess

Copy link
Copy Markdown

Closes #22

What changed

Before this PR, the only way to give the agent a markdown requirements or research doc was to attach it to a spec/expand chat. That content only lasted for one conversation. This PR adds project knowledge files: markdown or text documents that are saved with the project and given to every agent session.

Backend

  • autoforge_paths.get_knowledge_dir() returns .autoforge/knowledge/.
  • New router server/routers/knowledge.py at /api/projects/{name}/knowledge:
    • GET lists the files.
    • GET /{filename} returns a file's content.
    • POST {filename, content} creates a file, or replaces one with the same name.
    • DELETE /{filename} removes a file.
    • Filenames must be plain names ending in .md, .markdown or .txt. Path separators, a leading dot and .. are rejected. Files are limited to 1 MB each and 50 per project.
  • prompts.get_knowledge_prompt_section() builds a "PROJECT KNOWLEDGE FILES" section that lists the files by path and tells the agent to read the relevant ones. If the docs conflict with the app spec or features, the spec and features win. This section is added to:
    • every agent session prompt in agent.py (initializer, coding, testing, batch, auto-improve)
    • the system prompts of the spec-creation, expand-project and assistant chats

UI

  • A new book-icon button in the agent control bar (next to Schedules) shows how many files are uploaded and opens the Project Knowledge dialog.
  • The dialog has a drag-and-drop or click upload area (multiple files allowed), a file list with an expandable preview, and a delete button. Filenames are cleaned up in the browser so they pass the server's checks.

Verification

  • New test_knowledge.py (8 tests, all passing) covers:
    • the prompt section
    • an upload/list/get/overwrite/delete round trip
    • rejected filenames and path traversal
    • the size and file-count limits
    • unknown projects
  • ruff check . passes and python test_security.py passes. mypy reports no new errors in the files I touched. The 3 "unused type: ignore" notes it shows in the chat-session files were already there.
  • ui: npm run lint shows no new warnings and npm run build succeeds.
  • Manual check in Playwright against the server on port 5571, using a temporary HOME and registry:
    • Uploaded research.md through the dialog; the file was written to .autoforge/knowledge/ and the button badge showed 1.
    • The preview displayed the file's content.
    • Deleting removed the file from disk.
    • The prompt section printed for that project contained the file path.

Assumptions

  • Files are listed by path, not pasted into the prompt. This keeps every session's prompt small even with large docs; agents already have Read access to the project folder.
  • Only text formats are accepted (.md, .markdown, .txt), since that is what the issue asks for. PDF/DOCX are still supported as one-off chat attachments.
  • .autoforge/knowledge/ is not added to .autoforge/.gitignore, so users can commit their reference docs with the project.

🤖 Generated with Claude Code

zwanski-start and others added 2 commits October 22, 2026 04:04
Users can store markdown/text reference docs (requirements, research)
in .autoforge/knowledge/. A new REST router lists, reads, uploads and
deletes them, and every agent session plus the spec/expand/assistant
chats get a prompt section pointing at the files so Claude reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Book icon in the agent control bar opens a dialog with a drag-and-drop
upload zone, file list with preview and delete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zwanski-start

Copy link
Copy Markdown

🔍 QA report: ✅ Passed

Tester: Ken (cubefarm agent, in a fresh session) · Round: 1 · Author: Ada

Adds project knowledge files: .md/.markdown/.txt docs uploaded from a new Project Knowledge dialog, saved in .autoforge/knowledge/ and listed in every agent session and in the spec, expand and assistant chat prompts, which meets issue #22. Ruff, the UI lint and build, the new test_knowledge.py (8/8) and the security tests pass; mypy and the older pytest suites give the same results as on master. An end-to-end check in a real browser (upload of several files, PNG rejected, preview, delete, badge count, phone layout) worked with no console errors. One minor, non-blocking validation gap: Python's $ lets a filename ending in a newline (e.g. "evil.md\n") through a direct API call; switching to fullmatch or \Z would close it.

Check Details
✅ Issue acceptance: upload .md files to give agents more project knowledge Uploaded requirements.md and 'Design notes (v2).txt' through the dialog; both were written to /.autoforge/knowledge/. get_knowledge_prompt_section() for the project lists .autoforge/knowledge/research.md and tells the agent to read the files, with the spec and features taking precedence.
✅ Knowledge section added to all agent and chat prompts Code review: agent.py appends the section after every prompt branch (auto-improve, initializer, testing, batch, single, coding); spec_chat_session, expand_chat_session and assistant_chat_session append it to the system prompt. It returns an empty string when there are no files, so existing projects are unaffected.
✅ REST API happy path GET list → [] 200; POST research.md with UTF-8 content (café ✓ 日本) → 200; GET content round-trips exactly; re-upload overwrites; DELETE → 200, then 404 on a second delete.
✅ REST API validation and error cases '../x.md' → 400; GET ..%2F..%2Fetc%2Fpasswd → 404; 1 MB + 1 byte → 413; missing content → 422; unknown project → 404; invalid project name → 400. Minor gap: filename 'evil.md\n' returns 200 and creates a file with a newline in its name, because $ matches before a trailing newline. The file isn't shown in the UI or the prompt, but it counts toward the 50-file limit. Not exploitable for traversal, since the UI cleans filenames and the server is localhost-only.
✅ UI: Project Knowledge dialog upload/preview/delete Book button badge showed 1, then 3 after uploading, then 2 after a delete, and stayed 2 after a reload. Uploading 3 files at once (md, txt, png) added the two text files and showed 'image.png: only .md, .markdown and .txt files are supported'. Expanding a row shows the content; delete removed the file from disk.
✅ UI responsive layout At 390x844 the dialog fits the width with no horizontal overflow; rows and the drop zone stay usable.
✅ Existing views and console Dashboard, Kanban and Graph load; 0 console errors or warnings during the whole session.
✅ No regressions in lint, types or tests Ruff is clean. mypy shows 24 errors in 9 files, the same count as on an origin/master worktree, and none in the new or changed knowledge, prompts, agent or paths code. Pytest has the same 21 failures in test_devserver_security.py as master, plus the 8 new passing tests.
✅ Security not weakened security.py and the localhost middleware are untouched. Filenames are restricted by a whitelist pattern and '..' is rejected; paths are built under the knowledge folder only. No secrets are logged.
⏭️ UI Playwright e2e suite Environment issue: the chromium-headless-shell binary is missing on this machine and npx playwright install timed out after 240s. The existing specs (assistant panel, tooltips) don't cover this feature; it was checked by hand in the browser instead.
🧪 Commands run
Command Result
venv/bin/ruff check . All checks passed
venv/bin/mypy . (PR vs origin/master) 24 errors in 9 files on both, all already on master; none in changed code
venv/bin/python -m pytest -q test_knowledge.py 8 passed
venv/bin/python -m pytest -q test_knowledge.py test_client.py test_dependency_resolver.py test_rate_limit_utils.py test_ws_security.py test_devserver_security.py 130 passed, 21 failed (same 21 test_devserver_security failures on master: 122 passed, 21 failed without test_knowledge)
venv/bin/python test_security.py ALL TESTS PASSED
venv/bin/python test_security_integration.py ALL INTEGRATION TESTS PASSED
npm --prefix ui run lint 0 errors, 6 warnings (fast-refresh warnings in files this PR doesn't touch)
npm --prefix ui run build tsc -b + vite build succeeded
HOME=<tmp> venv/bin/uvicorn server.main:app --host 127.0.0.1 --port 5345 booted; /api/health → healthy
curl probes of /api/projects/demo/knowledge (GET/POST/DELETE, traversal, size, bad names) expected statuses, except that the trailing-newline filename was accepted (minor)
npx playwright test (ui) not run: headless browser binary missing; install timed out (environment)

No browser screenshots were taken in this round.

Posted by cubefarm · merges automatically once GitHub's checks pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upload md files for additional project knowledge

2 participants