Skip to content

forcedotcom/sf-skills / plugins/builder/agentforce-adlc/skills/agentforce-d360-analyze

agentforce-d360-analyze

Verified

Data Cloud 360° view of a single Agentforce session. TRIGGER when user asks to trace, inspect, summarize, or describe a specific Agentforce session by session id (Agent Session UUID `019d…` or MessagingSession id `0Mw…`). Also triggers on session discovery — find/list/search sessions by time, agent, channel, outcome, or conversation text — when the user has no session id yet. DO NOT TRIGGER for design-time architecture questions (use agentforce-architecture-analyze instead) or for runtime perf/latency/SLO questions that require platform telemetry beyond Data Cloud.

FileKindSize
README.mdmarkdown6.2 KB
SKILL.mdskill md13.2 KB
assets/dc/app_generation.sqlother1.9 KB
assets/dc/content_category.sqlother1.5 KB
assets/dc/content_quality.sqlother1.3 KB
assets/dc/discover_sessions.sqlother2.3 KB
assets/dc/feedback.sqlother1.5 KB
assets/dc/feedback_details.sqlother1.3 KB
assets/dc/gateway_records.sqlother1.6 KB
assets/dc/gateway_request_llm.sqlother1.6 KB
assets/dc/gateway_request_metadata.sqlother1.5 KB
assets/dc/gateway_request_tags.sqlother1.4 KB
assets/dc/gateway_requests.sqlother3.4 KB
assets/dc/gateway_responses.sqlother1.7 KB
assets/dc/generations.sqlother1.9 KB
assets/dc/interactions.sqlother2.0 KB
assets/dc/messages.sqlother2.1 KB
assets/dc/messaging_session.sqlother1.7 KB
assets/dc/moment_interactions.sqlother1.4 KB
assets/dc/moments.sqlother1.5 KB
assets/dc/participants.sqlother1.8 KB
assets/dc/sessions.sqlother3.0 KB
assets/dc/steps.sqlother2.6 KB
assets/dc/tag_associations.sqlother1.7 KB
assets/dc/tag_definition_associations.sqlother1.4 KB
assets/dc/tag_definitions.sqlother1.8 KB
assets/dc/tags.sqlother1.3 KB
assets/dc/telemetry_spans.sqlother2.1 KB
references/artifacts.mdmarkdown2.7 KB
references/dc_dmo_fields.mdmarkdown42.1 KB
references/dc_pipeline_contract.mdmarkdown26.3 KB
scripts/_shared/__init__.pyscript122 B
scripts/_shared/cli_override.pyscript3.3 KB
scripts/_shared/fs_guard.pyexecutablescript13.2 KB
scripts/_shared/paths.pyscript5.8 KB
scripts/_shared/runtime.pyscript2.0 KB
scripts/_shared/sql.pyscript548 B
scripts/assemble_dc.pyscript69.6 KB
scripts/config.pyscript1.8 KB
scripts/dc.pyscript13.8 KB
scripts/discover_sessions.pyscript21.1 KB
scripts/fetch_dc.pyscript45.1 KB
scripts/render_dc.pyscript69.7 KB
scripts/resolve_session.pyscript10.8 KB
scripts/storage.pyscript3.1 KB
scripts/tests/__init__.pyscript0 B
scripts/tests/_bootstrap.pyscript483 B
scripts/tests/fixtures/__init__.pyscript0 B
scripts/tests/fixtures/synthetic_session.pyscript14.6 KB
scripts/tests/test_assemble_dc_bootstrap_and_mode.pyscript4.2 KB
scripts/tests/test_assemble_dc_gateway_direct.pyscript8.3 KB
scripts/tests/test_assemble_dc_gateway_direct_integration.pyscript6.4 KB
scripts/tests/test_assemble_dc_helpers.pyscript10.0 KB
scripts/tests/test_assemble_dc_integration.pyscript9.3 KB
scripts/tests/test_dc_and_resolve_session.pyscript26.7 KB
scripts/tests/test_default_target_org.pyscript18.8 KB
scripts/tests/test_discover_sessions.pyscript19.0 KB
scripts/tests/test_discover_sessions_grep_ci.pyscript8.2 KB
scripts/tests/test_fetch_dc_helpers.pyscript10.6 KB
scripts/tests/test_fetch_dc_identity.pyscript22.0 KB
scripts/tests/test_fetch_dc_main.pyscript9.4 KB
scripts/tests/test_fetch_dc_waterfall.pyscript8.6 KB
scripts/tests/test_fetch_dc_waterfall_full.pyscript11.2 KB
scripts/tests/test_identity_coherence.pyscript13.8 KB
scripts/tests/test_render_dc_branches.pyscript9.9 KB
scripts/tests/test_render_dc_gateway_direct.pyscript5.1 KB
scripts/tests/test_render_dc_helpers.pyscript10.5 KB
scripts/tests/test_render_dc_integration.pyscript7.7 KB
scripts/tests/test_render_dc_planner_llm_calls.pyscript11.8 KB
scripts/tests/test_render_dc_show_prompts_gating.pyscript8.7 KB
scripts/tests/test_resolve_from_disk.pyscript4.1 KB
scripts/tests/test_resolve_session_main.pyscript5.2 KB
scripts/tests/test_runtime_override.pyscript4.2 KB
scripts/tests/test_session_shape.pyscript3.5 KB
scripts/tests/test_session_shape_dropped_by_stdm.pyscript3.5 KB
scripts/tests/test_skill_md_prefix_block.pyscript6.8 KB

scripts/tests/test_render_dc_branches.py

View on GitHub
"""Additional ``render_dc`` tests targeting branches not covered by
``test_render_dc_integration.py``:

- ``main_for_session``     reads tree + manifest from disk; emits markdown
- ``main``                  argparse → main_for_session
- ``_parse_finish_reason``  HTML-escaped JSON parsing
- ``_decoded_line``         tool-call JSON detection
- mermaid sequence diagram  (requires ≥2 ACTION_STEPs OR an error_text)
- mermaid topic flowchart   (requires repeating topics across turns)
- schema-version refusal    on unsupported _schema_version
"""
from __future__ import annotations

import json
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest import mock

from . import _bootstrap  # noqa: F401  — sys.path setup

import assemble_dc  # type: ignore
import render_dc  # type: ignore
from config import paths  # type: ignore
from .fixtures.synthetic_session import IDS, write_to_disk  # type: ignore


# -----------------------------------------------------------------------------
# main_for_session — disk-backed entry point
# -----------------------------------------------------------------------------


class MainForSessionTests(unittest.TestCase):

    def test_reads_tree_writes_summary_md(self):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            sdir = write_to_disk(tmp)
            with mock.patch.object(paths, "DATA_ROOT", tmp):
                tree, _ = assemble_dc.assemble(IDS.SID)
                (sdir / "dc._session_tree.json").write_text(
                    json.dumps(tree, default=str)
                )
                rc = render_dc.main_for_session(IDS.SID)
                self.assertEqual(rc, 0)
                summary_path = sdir / "dc._session_summary.md"
                self.assertTrue(summary_path.is_file())
                self.assertGreater(len(summary_path.read_text()), 1000)

    def test_raises_when_tree_missing(self):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            write_to_disk(tmp)  # creates session dir but not tree
            with mock.patch.object(paths, "DATA_ROOT", tmp):
                with self.assertRaises(SystemExit) as ctx:
                    render_dc.main_for_session(IDS.SID)
        self.assertIn("tree not found", str(ctx.exception))

    def test_tolerates_missing_manifest_with_warning(self):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            sdir = write_to_disk(tmp)
            with mock.patch.object(paths, "DATA_ROOT", tmp):
                tree, _ = assemble_dc.assemble(IDS.SID)
                (sdir / "dc._session_tree.json").write_text(
                    json.dumps(tree, default=str)
                )
                # Wipe the manifest. main_for_session should still succeed
                # (manifest is optional; missing → no manifest-driven sections).
                (sdir / "dc._session_manifest.json").unlink()
                rc = render_dc.main_for_session(IDS.SID)
                self.assertEqual(rc, 0)


# -----------------------------------------------------------------------------
# main — argparse + resolve
# -----------------------------------------------------------------------------


class MainTests(unittest.TestCase):

    def test_main_invokes_main_for_session_with_resolved_sid(self):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            sdir = write_to_disk(tmp)
            with mock.patch.object(paths, "DATA_ROOT", tmp):
                tree, _ = assemble_dc.assemble(IDS.SID)
                (sdir / "dc._session_tree.json").write_text(
                    json.dumps(tree, default=str)
                )
                with mock.patch.object(
                    render_dc.sys, "argv",
                    ["render_dc.py", "--session", IDS.SID],
                ):
                    rc = render_dc.main()
        self.assertEqual(rc, 0)


# -----------------------------------------------------------------------------
# _parse_finish_reason — HTML-escaped JSON
# -----------------------------------------------------------------------------


class ParseFinishReasonTests(unittest.TestCase):

    def test_extracts_stop_from_double_escaped_json(self):
        # Real wire format: `{"finish_reason":"\"stop\""}`
        params = '{"finish_reason":"\\"stop\\""}'
        self.assertEqual(render_dc._parse_finish_reason(params), "stop")

    def test_returns_none_for_empty(self):
        self.assertIsNone(render_dc._parse_finish_reason(None))
        self.assertIsNone(render_dc._parse_finish_reason(""))

    def test_returns_none_for_unparseable_json(self):
        self.assertIsNone(render_dc._parse_finish_reason("<<<not json>>>"))

    def test_returns_none_when_finish_reason_not_string(self):
        params = '{&quot;finish_reason&quot;: 42}'
        self.assertIsNone(render_dc._parse_finish_reason(params))


# -----------------------------------------------------------------------------
# _decoded_line — tool-call JSON detection
# -----------------------------------------------------------------------------


class DecodedLineTests(unittest.TestCase):

    def test_returns_dash_for_empty(self):
        self.assertEqual(render_dc._decoded_line(None), "—")
        self.assertEqual(render_dc._decoded_line(""), "—")

    def test_renders_quoted_truncated_text_for_plain_string(self):
        out = render_dc._decoded_line("Hello world")
        self.assertEqual(out, '"Hello world"')

    def test_summarizes_tool_call_json(self):
        # Real wire shape: HTML-escaped JSON with toolInvocations array.
        body = (
            '{"toolInvocations":[{'
            '"function":{"name":"search_orders",'
            '"arguments":"{\\"query\\":\\"refund\\"}"}}],'
            '"content":"I will search for orders."}'
        )
        out = render_dc._decoded_line(body)
        self.assertIn("1 tool call", out)
        self.assertIn("search_orders", out)
        self.assertIn("query=", out)


# -----------------------------------------------------------------------------
# Multi-turn fixture for mermaid branches
# -----------------------------------------------------------------------------


def _add_extra_turn_to_tree(tree: dict) -> None:
    """Mutate the assembled tree to have a 2nd TURN with a topic that
    repeats — triggers both the sequence diagram and the topic flowchart.
    """
    # Tag the existing turn with a topic
    sess = tree["session"]
    for iv in sess["interactions"]:
        if iv["type"] == "TURN":
            iv["topic"] = "Refunds"
            # Inject a 2nd action step so sequence diagram passes its
            # has_error/len(actions)>=2 gate.
            iv["steps"].append({
                "id": "step-extra-action",
                "type": "ACTION_STEP",
                "name": "ExtraAction",
                "start_ts": "2026-04-22T10:00:42.000Z",
                "end_ts":   "2026-04-22T10:00:48.000Z",
                "error_text": None,
                "generation": None,
                "gateway_request": None,
            })
            break
    # Append a 2nd TURN that uses the same topic — triggers flowchart edges.
    sess["interactions"].append({
        "id": "ixn-turn-002b",
        "type": "TURN",
        "topic": "Refunds",
        "trace_id": "trace-2nd",
        "start_ts": "2026-04-22T10:01:05.000Z",
        "end_ts":   "2026-04-22T10:01:25.000Z",
        "steps": [
            {"id": "step-2a", "type": "ACTION_STEP",
             "name": "ActionA",
             "start_ts": "2026-04-22T10:01:08.000Z",
             "end_ts":   "2026-04-22T10:01:12.000Z",
             "error_text": None,
             "generation": None,
             "gateway_request": None},
            {"id": "step-2b", "type": "ACTION_STEP",
             "name": "ActionB",
             "start_ts": "2026-04-22T10:01:13.000Z",
             "end_ts":   "2026-04-22T10:01:18.000Z",
             "error_text": "Action B failed: timeout",
             "generation": None,
             "gateway_request": None},
        ],
        "messages": [
            {"role": "USER", "text": "I want to escalate.", "ts": None},
            {"role": "AGENT", "text": "Connecting you to a human.", "ts": None},
        ],
        "tag_associations": [], "telemetry_spans": [],
        "timestamp_bound_gateway_calls": [],
    })


class MultiTurnRenderTests(unittest.TestCase):

    def _assemble_and_render(self, tree_mutator):
        with TemporaryDirectory() as t:
            tmp = Path(t)
            sdir = write_to_disk(tmp)
            with mock.patch.object(paths, "DATA_ROOT", tmp):
                tree, _ = assemble_dc.assemble(IDS.SID)
                tree_mutator(tree)
                manifest = json.loads(
                    (sdir / "dc._session_manifest.json").read_text()
                )
                return render_dc.render(tree, manifest=manifest, session_dir=sdir)

    def test_sequence_diagram_emitted_when_turn_has_two_actions(self):
        md = self._assemble_and_render(_add_extra_turn_to_tree)
        self.assertIn("sequenceDiagram", md)
        self.assertIn("participant U as USER", md)
        self.assertIn("participant P as Planner", md)

    def test_topic_flowchart_emitted_when_topics_repeat(self):
        md = self._assemble_and_render(_add_extra_turn_to_tree)
        self.assertIn("flowchart LR", md)
        self.assertIn("Refunds", md)


# -----------------------------------------------------------------------------
# Schema-version guard
# -----------------------------------------------------------------------------


class SchemaVersionGuardTests(unittest.TestCase):

    def test_render_refuses_unsupported_schema_version(self):
        # _assert_schema_version reads session._schema_version (per impl).
        bad_tree = {
            "session": {"id": IDS.SID, "interactions": [], "_schema_version": 999},
        }
        with self.assertRaises(SystemExit) as ctx:
            render_dc.render(bad_tree)
        self.assertIn("unsupported tree _schema_version", str(ctx.exception))


if __name__ == "__main__":
    unittest.main()
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall