COS v0.2 Draft ChaptersSingle pageJSON Schema

Context Object Specification (COS)

Version: 0.2
Chapter: 500 — Examples
Status: Informative
Category: Adoption & Evolution


1. Purpose

This chapter provides lean examples of COS v0.2 Context Objects.

The examples demonstrate the first principle of COS:

Selected text becomes useful when paired with source-grounded context.


2. General Flow

External Environment
    ↓
Adapter
    ↓
Selection + Source
    ↓
Context Construction
    ↓
Context Object
    ↓
Consumer

3. Example: Word in Paragraph

Scenario

A user selects the word nearby inside a paragraph.

Raw text alone is ambiguous.

COS preserves the local sentence context.

{
  "version": "0.2",
  "source": {
    "type": "webpage",
    "title": "Mixed Article",
    "uri": "about:srcdoc"
  },
  "selection": {
    "text": "nearby"
  },
  "context": {
    "scope": "inline",
    "segments": [
      {
        "id": "p1",
        "type": "paragraph",
        "text": "The adapter should preserve nearby context without turning the selection into a prompt.",
        "selectedText": "nearby",
        "beforeText": "The adapter should preserve ",
        "afterText": " context without turning the selection into a prompt."
      }
    ],
    "relations": [
      { "type": "section", "label": "Pricing Rules" }
    ]
  },
  "meta": {
    "adapter": "web-adapter"
  }
}

4. Example: Table Cell

Scenario

A user selects $19 inside a product table.

Raw text alone does not say what $19 means.

COS preserves table relationships.

{
  "version": "0.2",
  "source": {
    "type": "webpage",
    "title": "Product Table",
    "uri": "about:srcdoc"
  },
  "selection": {
    "text": "$19"
  },
  "context": {
    "scope": "container",
    "segments": [
      {
        "id": "cell-price-starter",
        "type": "table",
        "text": "$19",
        "selectedText": "$19",
        "relations": [
          { "type": "column_header", "label": "Base price" },
          { "type": "row_header", "label": "Starter" }
        ]
      }
    ],
    "relations": [
      { "type": "section", "label": "Quarterly Pricing Snapshot" }
    ]
  }
}

5. Example: Multi-Container Selection

Scenario

A user selects from the middle of a paragraph into a list.

Raw text loses the per-container boundaries.

COS preserves each covered segment.

{
  "version": "0.2",
  "source": {
    "type": "webpage",
    "title": "Mixed Article"
  },
  "selection": {
    "text": "adapter should preserve nearby context without turning the selection into a prompt.\n\nSelections can begin in ordinary prose.\nThey can cross list items and code "
  },
  "context": {
    "scope": "multi-container",
    "segments": [
      {
        "id": "p1",
        "type": "paragraph",
        "text": "The adapter should preserve nearby context without turning the selection into a prompt.",
        "selectedText": "adapter should preserve nearby context without turning the selection into a prompt.",
        "beforeText": "The "
      },
      {
        "id": "li1",
        "type": "list",
        "text": "Selections can begin in ordinary prose.",
        "selectedText": "Selections can begin in ordinary prose.",
        "relations": [
          { "type": "list_item", "label": "item 1" }
        ]
      },
      {
        "id": "li2",
        "type": "list",
        "text": "They can cross list items and code blocks.",
        "selectedText": "They can cross list items and code ",
        "afterText": "blocks.",
        "relations": [
          { "type": "list_item", "label": "item 2" }
        ]
      }
    ],
    "relations": [
      { "type": "section", "label": "Pricing Rules" }
    ]
  }
}

6. Example: Dashboard Value

Scenario

A user selects Degraded in a dashboard.

COS preserves the label that makes the value meaningful.

{
  "version": "0.2",
  "source": {
    "type": "webpage",
    "title": "Deployment Console"
  },
  "selection": {
    "text": "Degraded"
  },
  "context": {
    "scope": "container",
    "segments": [
      {
        "id": "health-value",
        "type": "text",
        "text": "Degraded",
        "selectedText": "Degraded",
        "relations": [
          { "type": "label", "label": "Health" }
        ]
      }
    ]
  }
}

7. Example: Code Selection

Scenario

A user selects a code expression.

COS preserves that the selected text comes from a code segment.

{
  "version": "0.2",
  "source": {
    "type": "webpage",
    "title": "Pricing Rules"
  },
  "selection": {
    "text": "return basePrice * (1 + taxRate);"
  },
  "context": {
    "scope": "container",
    "segments": [
      {
        "id": "code-1",
        "type": "code",
        "role": "code_snippet",
        "text": "return basePrice * (1 + taxRate);",
        "selectedText": "return basePrice * (1 + taxRate);"
      }
    ]
  }
}

8. Summary

Lean COS examples should be readable without knowing the whole protocol.

Consumers should understand the selected content by reading: