docs: document the full sys__* reserved-variable surface (issue #37) - #50
docs: document the full sys__* reserved-variable surface (issue #37)#50zoharbabin wants to merge 3 commits into
Conversation
Live testing confirms 3 undocumented reserved template variables beyond the 5 already documented: sys__ks (raw session token — credential-exposure risk if referenced in a prompt that gets echoed or logged), sys__is_new_thread, and sys__user_obj.* (first_name/last_name/title/company/gender/email). Adds a canonical "Reserved Template Variables" table covering all 8 names in one place, with an explicit security warning on sys__ks, and a dated note tracking the silent turn-failure behavior on sys__user_obj.* (backend issue, not fixable from the SDK) with previewPrompt()'s pre-shipping warning (issue #45 / PR #49) as the mitigation available today. Also notes sys__user_id can now be bound via Sessions.createConversationToken({userId}) (issue #36 / PR #48). Closes #37. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
audit-pr50-clean found this doc overclaiming that sys__user_id binding (PR #48) and previewPrompt()'s reserved_user_attr_unresolved warning (PR #49) already work today. Both PRs are unmerged. Hedge both claims so a developer reading this before those land doesn't rely on behavior that doesn't exist yet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Metadata fix: removed a literal "Closes #37" from the PR body. This PR only satisfies issue #37's documentation scope — the backend fix and |
Independent audit:
|
Live verification: remaining reserved-var claims — all confirmedThis PR's body already noted 3/8 vars ( Setup:
One caveat worth recording: an early pass on No inaccuracies found — every row in the Reserved Template Variables table is accurate as written. No doc changes needed. |
Summary
sys__*)" table toAPI-REFERENCE.md, right after the Converse section, covering all 8 known reserved variables. None of the 8 had a dedicated table inAPI-REFERENCE.mdbefore this PR — 5 (sys__thread_id,sys__message_id,sys__user_id,sys__user_message,secrets) were already named in source-level JSDoc (RESERVED_VARSinsrc/management/conversations.js,SYS_VARSinsrc/management/prompt-lint.js) but never spelled out for API consumers; the other 3 (sys__ks,sys__is_new_thread,sys__user_obj.*) are confirmed live via testing but aren't enforced or named anywhere else in the SDK yet.sys__kscarries an explicit, unambiguous security warning: never reference it in a prompt whose output could be echoed back to a user or logged, cross-linked toSECURITY.md's existing KS guidance.sys__user_obj.*— confirmed backend behavior, not fixable from the SDK — cross-referencing this issue (Document and stabilize the full sys__* reserved-variable surface (includes a silent turn-failure bug) #37) and namingpreviewPrompt()'sreserved_user_attr_unresolvedwarning as the mitigation once PR Flag unresolvable reserved-variable references in previewPrompt() (#45) #49 (issue Harden previewPrompt() to flag unresolvable reserved-variable references #45), not yet merged, lands. Until then the warning doesn't exist and an unresolvedsys__user_obj.*reference is rendered silently.sys__user_idwill resolve viaSessions.createConversationToken({ userId })once PR Bind a session to a real end-user identity (userId on session creation) #48 (issue Bind a session to a real end-user identity (userId on session creation) #36), not yet merged, lands — until then, passinguserIdis silently ignored and the value stays empty on every session.Fixed post-audit:
audit-pr50-clean(independent, context-free subagent) found both notes above originally documented PR #48's and PR #49's capabilities as already shipped. Hedged in the file and here to reflect that neither PR is merged yet.request_varspre-flight guard rejects — verified againstsrc/management/conversations.js'sRESERVED_VARS(only 5 of the 8 names are guarded client-side today) rather than assuming parity across all 8.Why this doesn't duplicate PR #49's table
PR #49 (not yet merged) adds its own reserved-variable table scoped to
previewPrompt()'s client-side simulation. This PR's table is the canonical, live-behavior reference (not simulation-scoped) and lives in a different section (right after Converse, not inside "Preview a Prompt"). Since PR #49 isn't merged into this branch's base, I can't edit its content directly — flagging for the human reviewer merging both: once PR #49 lands, its own table should either link to this canonical one instead of repeating it, or be trimmed to only the simulation-specific caveats (_meta,draftPrompts, etc.), to avoid two tables describing the same 8 variables.Deviations from the harnessed-build plan
docs:gate's secret-pattern scan against text that namessys__ks). A separate, genuinely independent clean subagent (audit-pr50-clean, top-level, worktree-isolated, no prior context) then reviewed the merged diff and found two overclaiming defects the self-review missed — see the fix commit on this branch and the note above.Test plan
node tools/check-docs.mjs— all 12 doc-gate suites pass (secrets, GFM hygiene, cross-doc links, preview/loading annotation, etc.)node scripts/harness/run.mjs— all 3 gates pass (npm run verify, semgrep SAST,npm run docs:gate)SECURITY.md/issue/PR cross-reference and anchor slug resolves🤖 Generated with Claude Code
This satisfies issue #37's documentation scope; left for the human reviewer to close manually after merge review.