Skip to content

feat(tools): save_user_section — agent writes per-user app sections - #49

Merged
cryptolir merged 1 commit into
mainfrom
feat/save-user-section-tool
Jun 1, 2026
Merged

cryptolir merged 1 commit into
mainfrom
feat/save-user-section-tool

Conversation

@cryptolir

Copy link
Copy Markdown
Owner

Write half of the Havaya per-user integration. The openclaw-dashboard reader endpoint (PR #107) serves what this writes. Plan: openclaw-dashboard:docs/peruser-user-file-plan.md; contract: AGENTGLOB_USER_FILE_API.md.

What it does

Adds a save_user_section(section, content) agent tool. The life agent calls it mid-chat to persist an allowlisted field (User_D_Prompt, app_note) into the chatting user's per-user file users/<appUserId>.md, as an <!-- app:<section>:start -->…end --> marker block. Upsert semantics (replace in place if present, else append); lazy file creation.

Identity (the key design point)

Resolved server-side, never by the model: Havaya sends an explicit appUserId on chat.send → the gateway persists it on the SessionEntry → the tool reads it back via loadSessionEntry(agentSessionKey). The id is lowercased to match the reader (which lowercases the query userId). This keeps the gateway free of any Havaya sessionKey-format parsing (Guidance §1: partitioning stays app-owned).

Changes

  • src/agents/tools/save-user-section.ts — tool + pure upsertSection().
  • src/agents/openclaw-tools.ts — register (conditional on workspaceDir).
  • src/config/sessions/types.ts — SessionEntry.appUserId? (additive).
  • src/gateway/protocol/schema/logs-chat.ts — chat.send accepts appUserId (required since schema is additionalProperties:false).
  • src/gateway/server-methods/chat.ts — persist appUserId before dispatch (best-effort; never blocks the turn).

Gates

  • npx vitest run -c vitest.unit.config.ts src/agents/tools/save-user-section.test.ts → 9/9.
  • npx tsgo --noEmit → 0 new errors (9 pre-existing on origin/main — self-info-tool.e2e, skills-bundled, login-qr, chat.ts:417 — verified identical by stashing this branch's changes).

Deploy / coordination

  • ⚠️ Needs the heavyweight gateway deploy (build-and-push.sh + deploy.sh vYYYY.MM.DD.N) to take effect on the life host — not auto-deployed. Holding for explicit authorization.
  • Pairs with: a dashboard PR (forward appUserId through chatSendAndWait + the public chat route) and a Havaya PR (send appUserId in src/lib/agentglob.ts). Until all three + deploy land, the reader keeps returning 404 (Havaya degrades to empty UI by design).
  • life's AGENTS.md will want a line telling the agent when to call save_user_section — intentionally not included here (it's per-agent workspace config on the host, not repo code).

🤖 Generated with Claude Code

Write half of the Havaya per-user integration (the openclaw-dashboard
reader endpoint serves what this writes). Lets the `life` agent persist an
allowlisted field (User_D_Prompt, app_note) into the chatting user's
per-user workspace file users/<appUserId>.md as an HTML-comment marker
section, so the connected app can display it.

Identity is resolved SERVER-SIDE, never by the model: the integrating app
(Havaya) sends an explicit appUserId on chat.send; the gateway persists it
on the session entry; the tool reads it back via loadSessionEntry. The id
is lowercased to match the dashboard reader (which lowercases the query
userId). Sections are upserted (replace if present, append otherwise);
duplicate/malformed markers fail closed rather than corrupt the file.
Lazy provisioning — the file is created on first write.

Changes:
- src/agents/tools/save-user-section.ts: the tool + pure upsertSection().
- src/agents/openclaw-tools.ts: register it (conditional, needs workspaceDir).
- src/config/sessions/types.ts: SessionEntry.appUserId (optional, additive).
- src/gateway/protocol/schema/logs-chat.ts: chat.send accepts appUserId
  (required because the schema is additionalProperties:false).
- src/gateway/server-methods/chat.ts: persist appUserId onto the session
  entry before dispatch (best-effort; never blocks the turn).

Tests: src/agents/tools/save-user-section.test.ts — 9 vitest cases for
upsertSection (append / replace-in-place / isolation / trim / duplicate
fail-closed / round-trip) + the writable-section allowlist.

Gates: npx vitest run save-user-section.test.ts → 9/9; npx tsgo --noEmit
introduces 0 new errors (9 pre-existing on origin/main, unchanged).

NOTE: requires the heavyweight gateway deploy (build-and-push + deploy.sh)
to take effect on the `life` host — NOT auto-deployed. Pairs with a
dashboard PR (appUserId passthrough) and a Havaya PR (send appUserId).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@cryptolir
cryptolir merged commit ef5cdc9 into main Jun 1, 2026
16 of 20 checks passed
cryptolir pushed a commit that referenced this pull request Jun 1, 2026
Adds docs/tools/save-user-section.md describing the save_user_section agent
tool shipped in #49: the writable allowlist (User_D_Prompt, app_note), the
users/<appUserId>.md marker-section upsert, server-side appUserId identity
resolution (chat.send -> SessionEntry -> resolveAppUserId), wiring, and the
security model. Registers the page under 'Built-in tools' in docs.json.

Docs-only; reflects code already on main.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
cryptolir added a commit that referenced this pull request Jun 1, 2026
…51)

Adds docs/tools/save-user-section.md describing the save_user_section agent
tool shipped in #49: the writable allowlist (User_D_Prompt, app_note), the
users/<appUserId>.md marker-section upsert, server-side appUserId identity
resolution (chat.send -> SessionEntry -> resolveAppUserId), wiring, and the
security model. Registers the page under 'Built-in tools' in docs.json.

Docs-only; reflects code already on main.

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
cryptolir added a commit that referenced this pull request Jun 2, 2026
…ssion (#52)

Records the 2026-06-01/02 session: save_user_section gateway tool (PR #49),
appUserId passthrough (dashboard #108/#110), reader endpoint (#107), life-only
deploy to v2026.06.01.1, AGENTS.md update, security remediation (key rotation
+ history scrub), and prod validation results.

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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