feat(collectives): Add Collectives support (13 tools for page management)#159
feat(collectives): Add Collectives support (13 tools for page management)#159Pavlinchen wants to merge 2 commits intonextcloud:mainfrom
Conversation
Add a new tool module wrapping the Collectives OCS API (under /ocs/v2.php/apps/collectives/api/v1.0) plus WebDAV for page markdown content, giving the agent 13 tools covering the full page lifecycle. Read (safe): - list_collectives: enumerate the user's collectives with permissions - list_collective_pages: flat list of pages with tree metadata (parentId + subpageOrder) for a collective - get_page: metadata for a single page - get_page_content: markdown body via WebDAV, empty string on 404 - list_page_trash: enumerate trashed pages Write (dangerous): - create_page: new page under a parent - update_page_content: overwrite markdown body via WebDAV PUT - rename_page: change title (also renames the .md file) - move_page: change parentId within the collective - set_page_emoji: set/clear page emoji - trash_page: soft-delete - restore_page: from trash - delete_page_permanently: purge a trashed page Markdown I/O uses the same WebDAV adapter pattern as files.py (nc._session._create_adapter(True)) and the page's collectivePath + filePath + fileName from the metadata. Paths are URL-encoded via urllib.parse.quote. Collectives does not register an OCS capability, so is_available() probes the API (matching the pattern in mail.py) rather than checking nc.capabilities. Unified search already exposes three Collectives providers (collectives, collectives-pages, collectives-page-content) via search.py, so no separate search tool is added here. Tested against Nextcloud 32.0.8 with Collectives 3.6.1 on the full lifecycle (create, write, read, rename, move, emoji, trash, restore, permanent delete) plus URL construction for top-level and nested pages with spaces in names. Signed-off-by: Pavlinchen <paulm.schmidt@icloud.com>
|
Tested and confirmed working. |
|
Likely open to do: add AI disclaimer (like for PR #155)? @marcelklehr What do you think? |
|
not sure either, will discuss internally :) |
|
To avoid this entirely, perhaps we can replace the update_page_content with more of a "surgical" insert? |
|
How about, we add to the tool description to make sure there is a note at the bottom of the article that says it was edited with the help of AI? Then the agent can make sure the note is always there and we don't have the problem of adding or removing it superfluously |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
Summary
collectives.pytool module wrapping the Collectives OCS API plus WebDAV for page markdown I/Osearch.pyalready auto-generates 3 Collectives search tools from the existing search providers (collectives,collectives-pages,collectives-page-content)Motivation
The Context Agent currently has no interaction with Collectives, Nextcloud's wiki-style knowledge base app. This prevents the agent from reading, creating, or editing user knowledge bases — a core collaboration use case. The existing unified search tools can find Collectives pages, but not enumerate, create, or modify them.
Implementation Details
Disclaimer
Implementation from a technical perspective was done mainly by a LLM (Claude Opus 4.7 max effort).
Every tool and endpoint response shape was validated end-to-end against Nextcloud 32.0.8 + Collectives 3.6.1, with a full lifecycle smoke test completed before opening the PR.
Endpoints used
All OCS endpoints are under
/ocs/v2.php/apps/collectives/api/v1.0/. Markdown I/O uses WebDAV at/remote.php/dav/files/{user}/{collectivePath}/{filePath}/{fileName}, with the path components coming from the page's own metadata./collectives/collectives/{cid}/pages/collectives/{cid}/pages/{pid}/collectives/{cid}/pages/trash/collectives/{cid}/pages/{parentId}/collectives/{cid}/pages/{pid}(body{title})/collectives/{cid}/pages/{pid}(body{parentId})/collectives/{cid}/pages/{pid}/emoji/collectives/{cid}/pages/{pid}/collectives/{cid}/pages/trash/{pid}/collectives/{cid}/pages/trash/{pid}Patterns followed
nc.ocs()(matchescircles.py,shares.py)nc._session._create_adapter(True).request(...)(matchesfiles.py)is_available()probes the OCS endpoint and returnsFalseon exception (matchesmail.py, since Collectives does not register an OCS capability)urllib.parse.quoteto handle spaces and special characters in collective/page namesDesign decisions
No AI disclaimer is appended to content writes. Unlike chat messages or card descriptions (where modules like
talk.py/deck.pyappend a note), wiki page content is the user's authored source material. Auto-appending "Edited by Nextcloud AI Assistant." to every page edit would pollute the wiki with notes that can't be cleanly removed later. If a user wants such a disclaimer, they can ask the agent to include it in the content itself.get_page_contentreturns an empty string on 404. Pages typically materialize their.mdfile on creation, but under transient conditions the file may not yet exist — the empty string gives the agent a consistent contract.No standalone search tool.
search.pyalready generatessearch_collectives,search_collectives_pages, andsearch_collectives_page_contentvia unified search providers. Adding a scoped search would be redundant.No Collective-level create/delete tools. Creating a Collective also provisions a backing Circle/Team, which is tied to membership management. Better addressed in a separate PR if desired.
No tag tools in this PR. Tags (Collectives 3.1.0+) are a small, well-contained sub-feature that can be added in a follow-up PR without affecting the page tools.
Test Plan
Tested against Nextcloud 32.0.8 + Collectives 3.6.1 with a full-lifecycle smoke test:
list_collectivesreturns all user's collectives withlevel,canEdit,canSharelist_collective_pagesreturns flat list withparentIdandsubpageOrderfor tree reconstructionget_pagereturns single-page metadataget_page_contentfetches markdown via WebDAV for a top-level page (landing)get_page_contentfetches markdown via WebDAV for a nested page in a collective whose name contains spaceslist_page_trashreturns empty when no trashed pagescreate_pagecreates a child under the specified parentupdate_page_contentwrites markdown; subsequentget_page_contentreturns the written contentrename_pageupdates title and thefileNameon diskmove_pageupdatesparentIdand the resultingfilePathset_page_emojiround-trips UTF-8 emoji characterstrash_pagesetstrashTimestamp; page appears inlist_page_trashrestore_pageclearstrashTimestampdelete_page_permanentlyremoves the trashed page (HTTP 200)