Skip to content

Add project knowledge documents (upload .md files for the agent) - #302

Open
zwanski-start wants to merge 2 commits into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-22-dennis
Open

zwanski-start wants to merge 2 commits into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-22-dennis

Conversation

@zwanski-start

Copy link
Copy Markdown

Closes #22

What changed

You can already attach .md files in the spec-creation and expand-project chats, but only for that one conversation. This PR adds project knowledge documents that stay with the project and that every agent session uses.

  • Storage: files go in {project}/.autoforge/knowledge/ (autoforge_paths.get_knowledge_dir). The folder is not gitignored, so the docs are versioned with the project.
  • Agent integration: prompts.with_project_knowledge() puts a ## PROJECT KNOWLEDGE section at the top of every agent prompt (initializer, coding, single/batch, testing, auto-improve). The section lists the docs and tells the agent to read them before planning or coding. Files are referenced by path, not pasted in, so large docs don't bloat every prompt. The agent already has Read(./**) access. If there are no docs, the prompt stays exactly the same.
  • API (server/routers/knowledge.py), under /api/projects/{name}/knowledge:
    • GET lists the files
    • GET /{filename} returns a file's content
    • POST {filename, content} creates a file or overwrites one with the same name
    • DELETE /{filename} removes a file
    • Limits: only .md, .markdown and .txt. Filenames are checked against a strict regex (no path separators, no .., no leading dot). Each file is limited to 1 MB and each project to 50 files.
  • UI: a new book button in the agent controls, next to the schedule button. It shows how many docs the project has and opens a Project Knowledge modal where you can upload (file picker or drag & drop, several files at once), preview and delete docs. The client changes filenames the server would reject, e.g. Research Notes (v2).md becomes Research Notes _v2_.md.
  • Updated CLAUDE.md.

Verification

  • Added test_knowledge.py with 10 pytest tests: the prompt section, upload/list/read/overwrite/delete, rejection of bad filenames, the size limit and unknown projects. All pass.
  • ruff check . is clean. mypy reports no new errors in the changed files; the errors it does report are already on master.
  • npm run lint shows no new warnings and npm run build succeeds.
  • Manual end-to-end test: ran the server on port 5247 with an isolated HOME and a temporary project. In the browser (Playwright) I opened the modal, uploaded Research Notes (v2).md, and saw it stored as .autoforge/knowledge/Research Notes _v2_.md. The count badge and the preview worked. The initializer prompt started with the knowledge section listing the file, and deleting through the API left the list empty.

Assumptions

  • The issue asks for persistent project knowledge for the agent, not just chat attachments (those already exist).
  • Docs are referenced by path rather than pasted into the prompt, to keep token use bounded.
  • Spec-creation, expand and assistant chats do not read the knowledge folder yet. A follow-up could add that.

🤖 Generated with Claude Code

zwanski-start and others added 2 commits October 22, 2026 09:18
Markdown/text files stored in .autoforge/knowledge/ are listed at the top of
every agent prompt so the agent reads them before planning or coding. Adds a
REST API (list/read/upload/delete) under /api/projects/{name}/knowledge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Book button in the agent controls opens a modal to upload (picker or drag &
drop), preview and delete .md/.txt knowledge documents for the project.

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

Copy link
Copy Markdown
Author

🔍 QA report: ✅ Passed

Tester: Barbara (cubefarm agent, in a fresh session) · Round: 1 · Author: Dennis

Project knowledge documents work end to end. Uploading in the new modal (file picker, several files at once) cleans filenames as described, rejects non-markdown files, updates the count badge, previews and deletes. Every agent prompt starts with a PROJECT KNOWLEDGE section listing the docs and is unchanged when there are none. Lint, the new tests, the security suites and the UI build pass; the only pytest failures are the 21 that also fail on master, and mypy shows no new errors. Minor, non-blocking: the server accepts a filename with a trailing newline because re.match with '$' matches before a final newline (use re.fullmatch).

Check Details
✅ Issue #22: upload .md files to give the agent project knowledge In the browser, opened the Project Knowledge modal from the new book button and uploaded 'Research Notes (v2).md', notes.txt and image.png at once. The .md was stored as '.autoforge/knowledge/Research Notes v2.md', notes.txt was stored, and image.png was rejected with a clear message. The badge count updated.
✅ Agent prompt integration with_project_knowledge() put a '## PROJECT KNOWLEDGE' section listing both docs (including the filename with spaces) above the initializer prompt and returned the prompt unchanged without docs. In agent.py it runs after every prompt branch (auto-improve, initializer, testing, batch, single, legacy). client.py grants Read(./**), so the agent can read the paths.
✅ REST API happy path and status codes (live server) GET list 200, POST 201 (UTF-8 content preserved), GET file 200, overwrite works, DELETE 204, missing file 404 on GET and DELETE, unknown project 404, invalid project name 400, missing content 422.
✅ Path traversal and filename validation ..%2F and %2E%2E%2F paths return 404, DELETE with an encoded traversal path returns 405, and '..\x.md', 'C:x.md', NUL bytes, '.hidden.md', 'notes.exe', 'sub/dir.md' and 'a..md' return 400. Minor gap: 'x.md\n' is accepted (re.match with '$' matches before a trailing newline) and creates a file that isn't listed. It cannot leave the knowledge folder and the UI cleans names first, so it is not blocking.
✅ Limits: 50 files, 1 MB The 51st file returned 400 'Maximum of 50 knowledge files'; overwriting an existing file at the limit still returned 201. The oversize 413 is covered by the unit test.
✅ Knowledge folder not gitignored .autoforge/.gitignore lists only runtime files (features.db, locks etc.); knowledge/ is not ignored, so docs are versioned as described.
✅ UI preview, delete, responsive layout, other views Preview shows UTF-8 content (Café ✓ üñí). Deleting notes.txt removed it from disk and the list. The modal fits at 390x844. Kanban and Graph render. No console errors; one Radix accessibility warning about the missing DialogDescription.
✅ Backend lint, types and tests ruff clean. test_knowledge.py 10/10 pass. Full pytest: 21 failures, all in test_devserver_security.py, also failing on an origin/master worktree. mypy: no new errors (the extra one is from venv/activate_this.py in my local checkout).
✅ Frontend build and lint npm --prefix ui run build (tsc -b && vite build) succeeds; lint has 0 errors and 6 warnings, all in files this PR does not touch.
⏭️ UI e2e suite The bundled headless shell was missing and playwright install timed out, so I ran it with a throwaway config pointing at /usr/bin/chromium (deleted afterwards). All 15 specs skip themselves ('No projects available'). The suite does not cover this feature.
✅ Security / cleanup security.py and the localhost middleware are untouched; security unit and integration tests pass. Servers on 5443 and 5173 stopped and the ports are free; worktree clean.
🧪 Commands run
Command Result
ruff check . All checks passed
python -m pytest -q test_knowledge.py 10 passed
python -m pytest -q 154 passed, 21 failed (all in test_devserver_security.py; master also has 21 failed, 144 passed)
mypy . (PR vs origin/master) No new errors (25 vs 24; the extra one is venv/activate_this.py in the local checkout)
python test_security.py ALL TESTS PASSED
python test_security_integration.py ALL INTEGRATION TESTS PASSED
npm --prefix ui run build success
npm --prefix ui run lint 0 errors, 6 warnings (all in files this PR does not touch)
uvicorn server.main:app --port 5443 (isolated HOME) + curl tests of /api/projects/qa-demo/knowledge Expected 200/201/204/400/404/405/422 codes; trailing-newline filename accepted (minor)
VITE_API_PORT=5443 npx playwright test (throwaway config using system chromium) 15 skipped (No projects available)

No browser screenshots were taken in this round.

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

cabana8471-arch pushed a commit to cabana8471-arch/autoforge that referenced this pull request Nov 8, 2026
Upload markdown/text documents (requirements, research notes) to
.autoforge/knowledge/ from the agent controls; every agent prompt starts with
a list of them.

Adaptations on integration:
- every file access goes through api/safe_project_io: .autoforge/ is
  agent-writable, so a symlink or hard link planted in knowledge/ is never
  read (409), written through (the link is replaced) or deleted through; the
  listing and the prompt pointer skip links;
- the knowledge directory must resolve inside the project (resolve() +
  is_relative_to, as in server/routers/documentation.py);
- tests for the link cases.

Integrates AutoForgeAI#302

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeH26pcsqoxPb3CDs8g1VN
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

1 participant