Skip to content

feat(knowledge): stage/delete knowledge pack task handlers#32

Open
ysyneu wants to merge 3 commits intomainfrom
feat/knowledge-pack-tasks
Open

feat(knowledge): stage/delete knowledge pack task handlers#32
ysyneu wants to merge 3 commits intomainfrom
feat/knowledge-pack-tasks

Conversation

@ysyneu
Copy link
Copy Markdown
Collaborator

@ysyneu ysyneu commented Apr 15, 2026

Summary

Adds two WebSocket task handlers so the runner can receive knowledge-pack files pushed from Safari at session start and remove them on demand. Implements the Safari-side contract in fc-safari:docs/knowledge-runner-tasks.md.

  • stage_knowledge_files — decodes each {rel_path, checksum, content_b64}, writes atomically (temp + rename), then merges entries into <workspace>/.safari-knowledge-sentinel.json under an advisory lock (flock) to handle concurrent BYOC sessions.
  • delete_knowledge_files — unlinks each rel_path (idempotent) and removes its sentinel entry under the same lock.
  • Path validation rejects /, \\, .., dotfiles (including the sentinel name itself — the runner owns the sentinel, clients don't stage it).
  • 14 subtests cover single-file stage, overwrite, mixed-validity, stage+delete cycles, missing-path idempotency, and the path-rejection matrix.

Context

Safari's EnvironmentMiddleware.BeforeModelCall lazy-stages the account's knowledge pack into the runner's workspace root so DUTY.md and @-referenced runbooks survive across sessions and ephemeral cloud pod restarts. Without these handlers the Safari end dispatches the tasks but the runner ignores them, and the agent sees an empty workspace.

Test plan

  • Unit: go test ./workspace/ -run \"TestStage|TestDelete|TestValidate\" -v — 14/14 PASS.
  • Integration with Safari: attach a rebuilt runner to a Safari session, save a file via Settings → Knowledge Packs, start a new session, confirm the file appears at workspace root.
  • Concurrent sessions on BYOC: two sessions on the same runner concurrently trigger stage — sentinel stays consistent.

🤖 Generated with Claude Code

ysyneu and others added 3 commits April 15, 2026 17:17
…k handlers

Implements the Safari-side contract documented in fc-safari's
docs/knowledge-runner-tasks.md. Atomic writes via temp+rename; sentinel
rewrites under flock to handle concurrent BYOC sessions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…trict '..' check

- Remove the unused `removed []string` accumulator in DeleteKnowledgeFiles;
  valid paths now go straight into `toRemove` in one loop pass, eliminating
  the second validateKnowledgeRelPath call per path.
- Tighten the '..' guard to reject only the bare ".." token — the old
  strings.Contains check wrongly rejected valid filenames like "foo..bar".
- Add test assertions confirming double-dot-in-middle filenames are accepted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant