diff --git a/docs/SUPPORT_COMPOSITION.md b/docs/SUPPORT_COMPOSITION.md
index 87e5edb..0612d58 100644
--- a/docs/SUPPORT_COMPOSITION.md
+++ b/docs/SUPPORT_COMPOSITION.md
@@ -2,7 +2,8 @@
Public host composition notes for authenticated product feedback on
[pegma.dev](https://pegma.dev). This is the ecosystem's Cloudflare reference
-environment for Support Desk customer create / list / read / reply.
+environment for Support Desk customer create / list / read / reply and a small
+staff operator surface over the same application services.
## Packages
@@ -36,6 +37,8 @@ two never share a cursor key.
## Authorization
+### Customer
+
Any authenticated pegma.dev account receives customer permissions through host
AccessContext defaults (no paid entitlement):
@@ -43,8 +46,34 @@ AccessContext defaults (no paid entitlement):
- `support.ticket.read.own`
- `support.ticket.reply.own`
-`principalId` is the Identity principal / account id from the server-side
-session (`__Host-pegma_session`). Browser-supplied identity fields are ignored.
+Policy version: `pegma.dev-support-customer-1`.
+
+### Staff (host allowlist)
+
+Staff are **not** a full role store. Operators are allowlisted via env:
+
+| Env | Meaning |
+| --- | --- |
+| `SUPPORT_STAFF_EMAILS` | Comma-separated verified emails (case-insensitive) |
+| `SUPPORT_STAFF_PRINCIPALS` | Comma-separated Identity principal / subject ids |
+
+A principal is staff only when authenticated **and** (principal id is in
+`SUPPORT_STAFF_PRINCIPALS` **or** verified user email is in
+`SUPPORT_STAFF_EMAILS`). Non-staff callers of staff routes receive **403**
+`forbidden` (not 404). Unauthenticated callers receive **401**.
+
+Staff AccessContext policy version: `pegma.dev-support-staff-1`. Permissions:
+
+- `support.queue.read`
+- `support.ticket.reply.any`
+- `support.ticket.note`
+- `support.ticket.assign`
+- `support.ticket.manage`
+- `support.audit.read`
+
+`principalId` is always the Identity principal / account id from the
+server-side session (`__Host-pegma_session`). Browser-supplied identity fields
+are ignored.
## Categories and markers
@@ -56,7 +85,9 @@ Display marker: `[PEG-{number}]`. Public tracking URL:
## HTTP boundary
-Worker routes (same-origin session + CSRF `X-Pegma-CSRF`):
+Worker routes (same-origin session + CSRF `X-Pegma-CSRF` for mutations):
+
+### Customer
| Method | Path | Notes |
| --- | --- | --- |
@@ -66,19 +97,56 @@ Worker routes (same-origin session + CSRF `X-Pegma-CSRF`):
| `GET` | `/api/support/tickets/:id` | Read own; missing/non-owned → same 404 |
| `POST` | `/api/support/tickets/:id/replies` | Reply (rate-limited) |
+### Staff (`/api/support/admin/…`)
+
+| Method | Path | Notes |
+| --- | --- | --- |
+| `GET` | `/api/support/admin/queue` | `listStaffQueue`; query: `status`, `priority`, `sort` (`updated_newest` / `updated_oldest`), `unassignedOnly` |
+| `GET` | `/api/support/admin/tickets/:id` | `readStaffTicket` (includes requester email when present, internal notes) |
+| `POST` | `/api/support/admin/tickets/:id/messages` | Public staff reply → `replyAsStaff` body `{ body }` (rate-limited) |
+| `POST` | `/api/support/admin/tickets/:id/notes` | Internal note → `addNote` body `{ body }` (rate-limited) |
+| `PATCH` | `/api/support/admin/tickets/:id` | Lifecycle / assign / priority |
+
+`PATCH` body (strict keys):
+
+```json
+{
+ "action": "assign" | "unassign" | "change_priority" | "resolve" | "close" | "reopen",
+ "priority": "low" | "normal" | "high" | "urgent"
+}
+```
+
+- `assign` assigns the caller's principal; `unassign` clears assignee.
+- `change_priority` requires a valid `priority`.
+- resolve / close / reopen map to the corresponding application methods.
+- Command, correlation, and message IDs are server-minted.
+
+**Compose modes are distinct endpoints.** Public replies use `/messages`;
+internal notes use `/notes`. The staff UI requires an explicit mode selection
+with no default and styles the two modes differently. Mail / outbound
+notification is still deferred (Task 10) — staff reply omits `notification`
+like customer create/reply.
+
Durable rate-limit policies (separate from Identity):
- `pegma.support.ticket.create`
-- `pegma.support.ticket.reply`
+- `pegma.support.ticket.reply` (customer replies and staff message/note posts)
-Site pages: `/feedback` (create + list), `/feedback/ticket/?id=…` (read + reply; static shell).
+## Site pages
+
+| URL | Audience |
+| --- | --- |
+| `/feedback` | Customer create + list |
+| `/feedback/ticket/?id=…` | Customer read + reply |
+| `/staff/support` | Staff queue (allowlisted operators) |
+| `/staff/support/ticket/?id=…` | Staff ticket detail, compose, lifecycle |
## Maintenance and health
Minute cron runs Support Desk queue repair and inactive projection sweep with
independent cursors, plus Support Desk rate-limit sweeps. Mail send for support
-notifications is deferred (templates are defined; create/reply omit
-notification for this first host PR).
+notifications is deferred (templates are defined; create/reply/staff reply omit
+notification for this host surface).
Health always reports Support Desk package detail without message content. A
store probe runs only when `SUPPORT_HEALTH_PROBE` is exactly `"true"`.
@@ -89,7 +157,11 @@ store probe runs only when `SUPPORT_HEALTH_PROBE` is exactly `"true"`.
authorized operators.
- Feedback is not automatically published to the roadmap, documentation, or
GitHub Issues.
-- Staff UI is deferred.
+- The staff surface is only for allowlisted operators (env allowlist). It is
+ not a shared control plane with other hosts.
+- Staff ticket views may include requester email after staff authz; customer
+ endpoints never gain staff fields.
+- Internal notes must never appear on customer reads.
- Queue projection terminal retention follows Support Desk's default
(30 days) for inactive projection rows; authoritative ticket retention and
export/redaction procedures remain host operational policy and will be
diff --git a/public/staff-support-ticket.js b/public/staff-support-ticket.js
new file mode 100644
index 0000000..1551874
--- /dev/null
+++ b/public/staff-support-ticket.js
@@ -0,0 +1,308 @@
+const statusNode = document.querySelector('#staff-ticket-status');
+const signedOut = document.querySelector('#staff-ticket-signed-out');
+const forbidden = document.querySelector('#staff-ticket-forbidden');
+const detail = document.querySelector('#staff-ticket-detail');
+const heading = document.querySelector('#staff-ticket-heading');
+const meta = document.querySelector('#staff-ticket-meta');
+const requesterNode = document.querySelector('#staff-ticket-requester');
+const messageList = document.querySelector('#staff-message-list');
+const composeForm = document.querySelector('#staff-compose-form');
+const composeBody = document.querySelector('#compose-body');
+const composeSubmit = document.querySelector('#compose-submit');
+const prioritySelect = document.querySelector('#priority-select');
+const ticketId = new URL(window.location.href).searchParams.get('id') ?? '';
+
+let csrfToken = '';
+let currentView = null;
+
+function showStatus(message, isError = false) {
+ statusNode.textContent = message;
+ statusNode.dataset.tone = isError ? 'error' : 'neutral';
+}
+
+function hideAll() {
+ signedOut.hidden = true;
+ forbidden.hidden = true;
+ detail.hidden = true;
+}
+
+async function api(path, init = {}) {
+ const headers = new Headers(init.headers);
+ if (init.body !== undefined) {
+ headers.set('Content-Type', 'application/json');
+ }
+ if (csrfToken !== '') {
+ headers.set('X-Pegma-CSRF', csrfToken);
+ }
+ const response = await fetch(path, {
+ ...init,
+ headers,
+ credentials: 'same-origin',
+ });
+ const body = await response.json();
+ if (!response.ok) {
+ const error = new Error(
+ typeof body.error === 'string' ? body.error : 'request_failed',
+ );
+ error.status = response.status;
+ throw error;
+ }
+ return body;
+}
+
+function authorLabel(message) {
+ if (message.visibility === 'internal') {
+ return 'Internal note';
+ }
+ if (message.authorKind === 'customer') {
+ return 'Customer';
+ }
+ if (message.authorKind === 'staff') {
+ return 'Staff (public)';
+ }
+ return 'System';
+}
+
+function renderMessages(messages) {
+ messageList.replaceChildren();
+ for (const message of messages) {
+ const item = document.createElement('li');
+ if (message.visibility === 'internal') {
+ item.className = 'staff-message-internal';
+ } else if (message.authorKind === 'staff') {
+ item.className = 'staff-message-public-staff';
+ } else if (message.authorKind === 'customer') {
+ item.className = 'staff-message-customer';
+ }
+
+ const who = document.createElement('strong');
+ who.textContent = authorLabel(message);
+ const when = document.createElement('span');
+ when.className = 'form-note';
+ when.textContent = new Date(message.createdAt).toLocaleString();
+ const body = document.createElement('p');
+ body.textContent = message.body;
+ item.append(who, ' · ', when, body);
+ messageList.append(item);
+ }
+}
+
+function renderTicket(view) {
+ currentView = view;
+ const marker =
+ typeof view.ticket.marker === 'string'
+ ? view.ticket.marker
+ : `[PEG-${view.ticket.number}]`;
+ heading.textContent = `${marker} ${view.ticket.subject}`;
+ meta.textContent = [
+ view.ticket.status,
+ view.ticket.priority,
+ view.ticket.category ?? 'uncategorized',
+ view.ticket.channel,
+ `rev ${view.ticket.revision}`,
+ view.ticket.assignedTo
+ ? `assigned:${view.ticket.assignedTo}`
+ : 'unassigned',
+ ].join(' · ');
+
+ const requester = view.ticket.requester ?? {};
+ const requesterParts = [
+ `association: ${requester.association ?? 'unknown'}`,
+ ];
+ if (typeof requester.email === 'string') {
+ requesterParts.push(`email: ${requester.email}`);
+ }
+ if (typeof requester.principalId === 'string') {
+ requesterParts.push(`principal: ${requester.principalId}`);
+ }
+ requesterNode.textContent = requesterParts.join(' · ');
+
+ if (prioritySelect) {
+ prioritySelect.value = view.ticket.priority;
+ }
+
+ renderMessages(view.messages);
+ updateComposeEnabled();
+}
+
+function selectedComposeMode() {
+ const selected = composeForm.querySelector(
+ 'input[name="composeMode"]:checked',
+ );
+ return selected ? selected.value : '';
+}
+
+function updateComposeEnabled() {
+ const mode = selectedComposeMode();
+ const body = composeBody.value.trim();
+ composeSubmit.disabled = mode === '' || body === '';
+ composeForm.dataset.mode = mode === '' ? 'unset' : mode;
+}
+
+async function patchTicket(action, extra = {}) {
+ showStatus(`Applying ${action}…`);
+ const view = await api(
+ `/api/support/admin/tickets/${encodeURIComponent(ticketId)}`,
+ {
+ method: 'PATCH',
+ body: JSON.stringify({ action, ...extra }),
+ },
+ );
+ if (typeof view.csrfToken === 'string') {
+ csrfToken = view.csrfToken;
+ }
+ renderTicket(view);
+ showStatus(`Action ${action} applied.`);
+}
+
+async function loadTicket() {
+ if (ticketId === '') {
+ showStatus('Missing ticket id.', true);
+ return;
+ }
+ const idDisplay = document.querySelector('#staff-ticket-id-display');
+ if (idDisplay) idDisplay.textContent = ticketId;
+
+ hideAll();
+ try {
+ await api('/api/identity/account');
+ } catch (error) {
+ if (error.status === 401) {
+ signedOut.hidden = false;
+ showStatus('Sign in to view this ticket.');
+ return;
+ }
+ showStatus(`Staff ticket unavailable: ${error.message}`, true);
+ return;
+ }
+
+ try {
+ const view = await api(
+ `/api/support/admin/tickets/${encodeURIComponent(ticketId)}`,
+ );
+ if (typeof view.csrfToken === 'string') {
+ csrfToken = view.csrfToken;
+ }
+ detail.hidden = false;
+ renderTicket(view);
+ showStatus('Ticket loaded.');
+ } catch (error) {
+ if (error.status === 401) {
+ signedOut.hidden = false;
+ showStatus('Sign in to view this ticket.');
+ return;
+ }
+ if (error.status === 403) {
+ forbidden.hidden = false;
+ showStatus('You do not have staff access.', true);
+ return;
+ }
+ if (error.status === 404) {
+ showStatus('Ticket not found.', true);
+ return;
+ }
+ showStatus(`Could not load ticket: ${error.message}`, true);
+ }
+}
+
+function bindLifecycle() {
+ document
+ .querySelector('#action-assign')
+ ?.addEventListener('click', async () => {
+ try {
+ await patchTicket('assign');
+ } catch (error) {
+ showStatus(`Assign failed: ${error.message}`, true);
+ }
+ });
+ document
+ .querySelector('#action-unassign')
+ ?.addEventListener('click', async () => {
+ try {
+ await patchTicket('unassign');
+ } catch (error) {
+ showStatus(`Unassign failed: ${error.message}`, true);
+ }
+ });
+ document
+ .querySelector('#action-priority')
+ ?.addEventListener('click', async () => {
+ try {
+ await patchTicket('change_priority', {
+ priority: prioritySelect.value,
+ });
+ } catch (error) {
+ showStatus(`Priority change failed: ${error.message}`, true);
+ }
+ });
+ document
+ .querySelector('#action-resolve')
+ ?.addEventListener('click', async () => {
+ try {
+ await patchTicket('resolve');
+ } catch (error) {
+ showStatus(`Resolve failed: ${error.message}`, true);
+ }
+ });
+ document
+ .querySelector('#action-close')
+ ?.addEventListener('click', async () => {
+ try {
+ await patchTicket('close');
+ } catch (error) {
+ showStatus(`Close failed: ${error.message}`, true);
+ }
+ });
+ document
+ .querySelector('#action-reopen')
+ ?.addEventListener('click', async () => {
+ try {
+ await patchTicket('reopen');
+ } catch (error) {
+ showStatus(`Reopen failed: ${error.message}`, true);
+ }
+ });
+}
+
+composeForm.addEventListener('change', updateComposeEnabled);
+composeForm.addEventListener('input', updateComposeEnabled);
+
+let composeInFlight = false;
+
+composeForm.addEventListener('submit', async (event) => {
+ event.preventDefault();
+ if (composeInFlight) return;
+ const mode = selectedComposeMode();
+ const body = composeBody.value.trim();
+ if (mode === '' || body === '') {
+ showStatus('Select Public reply or Internal note, and enter a body.', true);
+ return;
+ }
+
+ const path =
+ mode === 'public'
+ ? `/api/support/admin/tickets/${encodeURIComponent(ticketId)}/messages`
+ : `/api/support/admin/tickets/${encodeURIComponent(ticketId)}/notes`;
+
+ composeInFlight = true;
+ composeSubmit.disabled = true;
+ try {
+ showStatus(mode === 'public' ? 'Sending public reply…' : 'Saving note…');
+ const view = await api(path, {
+ method: 'POST',
+ body: JSON.stringify({ body }),
+ });
+ composeForm.reset();
+ renderTicket(view);
+ showStatus(mode === 'public' ? 'Public reply sent.' : 'Internal note saved.');
+ } catch (error) {
+ showStatus(`Compose failed: ${error.message}`, true);
+ } finally {
+ composeInFlight = false;
+ updateComposeEnabled();
+ }
+});
+
+bindLifecycle();
+updateComposeEnabled();
+loadTicket();
diff --git a/public/staff-support.js b/public/staff-support.js
new file mode 100644
index 0000000..0d8a2e5
--- /dev/null
+++ b/public/staff-support.js
@@ -0,0 +1,152 @@
+const statusNode = document.querySelector('#staff-queue-status');
+const signedOut = document.querySelector('#staff-queue-signed-out');
+const forbidden = document.querySelector('#staff-queue-forbidden');
+const panel = document.querySelector('#staff-queue-panel');
+const emailNode = document.querySelector('#staff-queue-email');
+const queueList = document.querySelector('#queue-list');
+const filterForm = document.querySelector('#queue-filters');
+
+let csrfToken = '';
+
+function showStatus(message, isError = false) {
+ statusNode.textContent = message;
+ statusNode.dataset.tone = isError ? 'error' : 'neutral';
+}
+
+function hideAll() {
+ signedOut.hidden = true;
+ forbidden.hidden = true;
+ panel.hidden = true;
+}
+
+async function api(path, init = {}) {
+ const headers = new Headers(init.headers);
+ if (init.body !== undefined) {
+ headers.set('Content-Type', 'application/json');
+ }
+ if (csrfToken !== '') {
+ headers.set('X-Pegma-CSRF', csrfToken);
+ }
+ const response = await fetch(path, {
+ ...init,
+ headers,
+ credentials: 'same-origin',
+ });
+ const body = await response.json();
+ if (!response.ok) {
+ const error = new Error(
+ typeof body.error === 'string' ? body.error : 'request_failed',
+ );
+ error.status = response.status;
+ throw error;
+ }
+ return body;
+}
+
+function renderQueue(items) {
+ queueList.replaceChildren();
+ if (items.length === 0) {
+ const empty = document.createElement('li');
+ empty.textContent = 'No tickets match these filters.';
+ queueList.append(empty);
+ return;
+ }
+ for (const item of items) {
+ const li = document.createElement('li');
+ const link = document.createElement('a');
+ link.href = `/staff/support/ticket/?id=${encodeURIComponent(item.ticketId)}`;
+ link.textContent = item.ticketId;
+ const meta = document.createElement('span');
+ meta.className = 'form-note';
+ const parts = [
+ item.status,
+ item.priority,
+ item.category ?? 'uncategorized',
+ item.requesterAssociation,
+ item.assignedTo ? `assigned:${item.assignedTo}` : 'unassigned',
+ new Date(item.updatedAt).toLocaleString(),
+ ];
+ meta.textContent = parts.join(' · ');
+ li.append(link, meta);
+ queueList.append(li);
+ }
+}
+
+function filterQuery() {
+ const form = new FormData(filterForm);
+ const params = new URLSearchParams();
+ const status = form.get('status');
+ const sort = form.get('sort');
+ if (typeof status === 'string' && status !== '') {
+ params.set('status', status);
+ }
+ if (typeof sort === 'string' && sort !== '') {
+ params.set('sort', sort);
+ }
+ const query = params.toString();
+ return query === ''
+ ? '/api/support/admin/queue'
+ : `/api/support/admin/queue?${query}`;
+}
+
+async function refreshQueue() {
+ const result = await api(filterQuery());
+ if (typeof result.csrfToken === 'string') {
+ csrfToken = result.csrfToken;
+ }
+ renderQueue(result.items);
+}
+
+async function start() {
+ hideAll();
+ try {
+ const account = await api('/api/identity/account');
+ csrfToken = account.csrfToken;
+ emailNode.textContent = account.account.email;
+ } catch (error) {
+ if (error.status === 401) {
+ signedOut.hidden = false;
+ showStatus('Sign in to use the staff queue.');
+ return;
+ }
+ showStatus(`Staff queue unavailable: ${error.message}`, true);
+ return;
+ }
+
+ try {
+ await refreshQueue();
+ panel.hidden = false;
+ showStatus('Queue loaded.');
+ } catch (error) {
+ if (error.status === 401) {
+ signedOut.hidden = false;
+ showStatus('Sign in to use the staff queue.');
+ return;
+ }
+ if (error.status === 403) {
+ forbidden.hidden = false;
+ showStatus('You do not have staff access.', true);
+ return;
+ }
+ showStatus(`Could not load queue: ${error.message}`, true);
+ }
+}
+
+filterForm.addEventListener('submit', async (event) => {
+ event.preventDefault();
+ try {
+ showStatus('Refreshing queue…');
+ await refreshQueue();
+ showStatus('Queue updated.');
+ } catch (error) {
+ if (error.status === 403) {
+ hideAll();
+ forbidden.hidden = false;
+ showStatus('You do not have staff access.', true);
+ return;
+ }
+ showStatus(`Could not load queue: ${error.message}`, true);
+ }
+});
+
+start();
diff --git a/src/pages/staff/support.astro b/src/pages/staff/support.astro
new file mode 100644
index 0000000..5ec40a9
--- /dev/null
+++ b/src/pages/staff/support.astro
@@ -0,0 +1,83 @@
+---
+import Base from '../../layouts/Base.astro';
+---
+
+
+
+
Staff · Support Desk
+
Support queue
+
+ Review and act on product feedback tickets. Access is limited to operators
+ listed in the host staff allowlist — this is not a public control plane.
+
+
+
+
+ Checking staff access…
+
+
+
+
Sign in required
+
+ Staff tools use your pegma.dev account session.
+ Sign in first.
+
+
+
+
+
You do not have staff access
+
+ This surface is only available to allowlisted operators. If you expected
+ access, contact an administrator.
+