Files
ss-tools/specs/035-agent-chat-context/checklists/requirements.md
busya ff60865183 feat(agent-chat): 035-agent-chat-context — контекст, guardrails, tools, database discovery
== User stories ==
US1: Контекст с дашборда/датасета → /agent с URL params
US2: Guardrails card — env badge, 7 risk tones, countdown, permission_denied
US3: Tools optimization — retry, timeout, summarise, RBAC + context affinity

== Backend ==
- _context.py (NEW): UIContext validation (7 checks)
- _tool_filter.py (NEW): RBAC + context affinity pipeline
- _confirmation.py: build_confirmation_contract_v2, permission_denied_payload
- tools.py: superset_list_databases, retry/summarise/timeout wrappers
- app.py: _inject_uicontext, _inject_env_id_into_tools, database
  prefetch в runtime context
- _persistence.py: prefetch_databases()
- agent_superset_explore.py: GET /databases endpoint
- _llm_async_http.py, _persistence.py: fix double /v1 в LLM URL
  (LM Studio Unexpected endpoint)

== Frontend ==
- AgentChatModel.svelte.ts: 5 atoms, 3 actions, countdown, context
- AgentChat.svelte: production banner, process steps, debug panel
- ConfirmationCard.svelte: 7 risk tones, permission_denied, countdown
- ToolCallCard.svelte: retrying/timeout/cancelled states
- StreamProcessor.svelte.ts: tool_retry, timeout, permission_denied
- TopNavbar: sparkles icon + Ассистент
- sidebarNavigation: AI section
- DashboardHeader, datasets/+page: contextual AI buttons
- Icon: sparkles, brain, cpu icons
- tailwind: assistant category colors
- i18n: en/ru nav keys

== Tests ==
- 159 backend agent tests (+16 US3: retry, timeout, summarise, contracts)
- 2544 frontend tests (+11 model + component tests)
- 15 JSON fixtures (10 API + 5 model)

== Specs ==
- specs/035-agent-chat-context/: spec, UX, plan, tasks, research,
  data-model, contracts, quickstart, traceability, fixtures, checklists

Closes #035
2026-07-04 22:47:17 +03:00

7.1 KiB
Raw Blame History

#region RequirementsChecklist [C:2] [TYPE Checklist] [SEMANTICS requirements,validation,quality,agent-chat] @BRIEF Requirements quality validation for 035-agent-chat-context spec.

Feature Branch: 035-agent-chat-context Checked: 2026-07-04 (revised after orthogonal review — Path B consolidation) | Status: PASS

Revision Notes

The following issues were resolved per orthogonal review findings:

Finding Resolution
B1 (context model contradiction) Spec updated to Path B: dedicated /agent page with URL-transferred context. "Any page" language removed.
B2 (Gradio payload breakage) uicontext appended at position END (6), not middle. Default None ensures backward-compat.
B3 (route field) Spec clarifies route is passed via URL param route=/dashboards/42.
B4 (envId duality) Env resolution canonical rule defined. updateActiveEnv() syncs both _activeEnvId AND uiContext.envId.
B5 (tool filtering inconsistency) build_tool_pipeline() defines ordered pipeline: RBAC→context. "Prioritise" → "hard filter". Embedding router deferred to AGTL-FR-006 (SHOULD).
B6 (permission denied UX) Permission denied flows to separate SSE event permission_denied — bypasses HITL checkpoint. Two-layer enforcement added.
B7 (impact estimate) Removed from acceptance criteria — not implemented in this feature scope.
B8 (toolAffinity debug data) Removed frontend-only toolAffinity atom. Debug tool list comes from backend SSE pipeline_result event.
B9 (UIContext trust model) validate_uicontext() with enum checks, size limits, field lengths. Prompt block marked "not instructions".
B10 (traceability out of sync) Traceability rebuilt from updated tasks and contract IDs.
M3 (contextVersion) All examples include contextVersion: 1.
M4 (risk remains heuristic) Documented as known limitation. Tool metadata (operation_type, idempotency, required_roles) deferred to tool registry ADR-0008 extension.
M5 (permission source) User role extracted from JWT. _TOOL_PERMISSIONS dict defines tool→role mapping.
M6 (manual retry unsafe) Write tool timeout: no retry button ("check operation status"). Read tool timeout: retry button.
M7 (timeout semantics) Write tool timeout: is_write_tool=true, retryable=false. Frontend shows "operation status unknown" — no retry.
M8 (structured truncation naming) Renamed from "semantic summarisation". Behavior defined for arrays, objects, text.
M9 (objectName) Provided by source page in URL param when navigating to /agent.
M10 (success criteria) SC-001 updated to 100% (context injection is deterministic). SC-004 removed function name leakage. SC-006 added for context validation.
4.6 (countdown duplication) Model owns countdown. Component reads model atom only.
4.10 (JWT expiry) Edge case documented. No new FR — handled by existing 401 flow.
1.3 (initialContext in store) Removed. Context from URL params only.

1. Spec Completeness

  • Feature short name is concise (2-4 words): agent-chat-context
  • Branch created: 035-agent-chat-context
  • Spec file exists: specs/035-agent-chat-context/spec.md
  • UX reference exists: specs/035-agent-chat-context/ux_reference.md
  • All three user stories have priority (P1/P2/P3), acceptance criteria, and independent test descriptions
  • Edge cases documented (6 cases covering navigation, auth expiry, history backward-compat, connection loss, multi-tab)

2. Implementation Leakage Prevention

  • No Python module names in spec (e.g., no _confirmation.py, tools.py, langgraph_setup.py)
  • No Svelte component file names in spec (existing component names only referenced in UX ref, which is appropriate)
  • No Pydantic schema names in spec
  • No database table or ORM references in spec
  • Spec uses domain language: «агент», «дашборд», «окружение», «инструмент», «подтверждение»
  • Success criteria are user/operator-facing metrics, not code metrics

3. Stack Compatibility

  • Backend context: Python 3.9+ / FastAPI / SQLAlchemy — feature is compatible (context enrichment is HTTP payload, not a new protocol)
  • Frontend context: SvelteKit 5 / Svelte 5 runes / Tailwind — feature uses existing patterns (Model atoms, $derived, component props)
  • No conflict with ADR-0003 (orchestrator pattern) — agent remains external orchestrator over Superset
  • No conflict with ADR-0006 (frontend architecture) — uses existing Model pattern, no legacy Svelte 4 stores
  • No conflict with ADR-0008 (tool registry) — RBAC tool filtering aligns with decorator registry design
  • No conflict with ADR-0005 (RBAC) — permission checks extend existing role model

4. Measurable Success Criteria

  • SC-001: Contextual response accuracy — measurable via QA test scenarios (percentage)
  • SC-002: Guardrails card render performance — measurable via browser performance API (milliseconds)
  • SC-003: Tool invocation error reduction — measurable via structured audit logs (percentage over baseline)
  • SC-004: Response size reduction — measurable via log analysis (percentage)
  • SC-005: RBAC enforcement — measurable via integration test (zero violations)

5. Edge Cases & Recovery

  • Page navigation during streaming → agent completes with launch-time context (documented)
  • No environment selected → agent operates in env-agnostic mode (documented)
  • JWT expiry mid-conversation → explicit session-expired message, no retry loop (documented)
  • Old conversation history without context metadata → graceful degradation (documented)
  • Connection drop during HITL confirmation → checkpoint preservation, re-render on reconnect (documented)
  • Multi-tab isolation → independent context per tab (documented)

6. Decision-Memory Readiness

  • Spec documents @RATIONALE for each story's priority
  • UX reference captures persona, happy path, error scenarios, and tone/voice
  • All functional requirements use hierarchical IDs (AGCTX-, AGGRD-, AGTL-) for HCA 128× survival
  • Key entities are defined without implementation details
  • No [NEEDS CLARIFICATION] markers remain — all decisions have informed defaults

7. Verification Readiness

  • Each user story has an independently verifiable acceptance scenario
  • Success criteria are quantifiable and testable
  • Edge cases provide clear expected behaviors for test authoring
  • UX reference provides explicit UI states for browser-driven validation

Summary

Status: PASS — All checks pass. Spec is ready for /speckit.clarify or /speckit.plan.

No blocking issues found. The feature is well-scoped across three independent stories (context, guardrails, tools) that can be implemented and verified independently. The context enrichment is additive (doesn't break existing flows). Guardrails refinement extends existing HITL patterns. Tool optimisation is bounded by existing tool registry and RBAC infrastructure.

#endregion RequirementsChecklist