feat(server): add PUT /api/knowledge/{scenario} write endpoint#1059
Merged
Conversation
Companion to the read endpoint from #1056. The cowork GUI's knowledge editor and document-to-knowledge flow need to write curated knowledge back: this overwrites a scenario's playbook.md / hints.md / dead_ends.md from a {playbook, hints, deadEnds} JSON payload, writing only the fields provided as strings and reporting which files were written. Same scenario-id validation and resolve-under-knowledge-root path guard as the GET. Tests cover the write + GET round-trip, partial payloads, and invalid-id rejection (the read endpoint shipped untested in #1056; these tests exercise both directions).
ArtifactStore.read_hints prefers structured hint_state.json over flat hints.md, so a GUI hints edit that only wrote hints.md was silently ignored by the next run/export/MCP read (reviewer P2). Drop hint_state.json when the PUT accepts hints: the operator's flat edit becomes authoritative for both read paths. read_hints returns it verbatim, and read_hint_manager lazily rebuilds structured state from it via the existing legacy fallback. Clearing beats rewriting the structured state through HintManager.from_hint_text, whose line-based parse and max-hints cap would mangle arbitrary GUI markdown. A PUT without hints leaves hint_state.json untouched. Regression test reproduces the reviewer's seeded hint_state scenario and was verified to fail without the fix.
Contributor
Author
|
Addressed the P2 in 8ec4b39: when the PUT accepts Chose clearing over rewriting structured state through Added a regression test reproducing the seeded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to the read endpoint merged in #1056. The cowork GUI's knowledge editor ("Save changes") and document-to-knowledge flow need to write curated knowledge back to the engine.
PUT /api/knowledge/{scenario}overwrites a scenario'splaybook.md/hints.md/dead_ends.mdfrom a{playbook, hints, deadEnds}JSON payload:{scenario, written: [...]}listing which files were written._/-) and resolve-under-knowledge_rootpath guard as the GET.Tests
tests/test_knowledge_endpoint.py(the GET shipped untested in #1056; these exercise both directions):bad!name,dots..dots, 129 chars) are rejected with 400.Checks in a clean worktree off
main: new tests +test_server_health.pypass,ruffclean,mypyclean.