COS v0.2 Draft ChaptersSingle pageJSON Schema

Context Object Specification (COS)

Version: 0.2
Chapter: 220 — Document
Status: Informative — Supporting
Category: Core Model


1. Purpose

This chapter defines the abstract concept of a Document within the Context Object Specification (COS).

A Document represents the structural and logical container in which a Selection exists.

It provides the spatial, hierarchical, and semantic boundary for contextual interpretation.


2. Conceptual Role

A Document is the source environment of a Selection.

While Selection represents user intent, Document represents contextual space.

Without Document, a Selection has no meaningful interpretation.


3. Definition

A Document is a structured content container that provides:

A Document is NOT a rendering artifact.

It is a logical representation of content space.


4. Document vs File vs Page

A Document MUST NOT be confused with physical or storage-level concepts.

Concept Meaning
File Storage unit (filesystem level)
Page Rendering unit (visual layout)
Document Logical content structure

A Document MAY be derived from files or pages, but is not equivalent to them.


5. Document Scope

In COS v0.2, a Document MAY originate from:

Future extensions MAY include:


6. Relationship to Lean Core

In COS v0.2 lean core, Document is a supporting concept rather than a required top-level field.

Producer implementations MAY use an internal Document model to derive:

The emitted Context Object SHOULD NOT duplicate a full Document tree unless a Consumer explicitly needs it.


7. Document Structure (Conceptual Model)

When an implementation needs a Document model, it MAY use:

interface Document {
  id: string;
  type: DocumentType;
  title?: string;
  content: ContentNode;
  structure: DocumentStructure;
  metadata?: DocumentMetadata;
}

This definition is conceptual and independent of implementation.


8. Document Type

A Document MUST declare its type:

type DocumentType =
  | "webpage"
  | "pdf"
  | "markdown"
  | "editor"
  | "richtext";

Document type influences interpretation strategies in later Pipeline stages.


9. Content Model

A Document contains structured content represented as nodes.

interface ContentNode {
  type: string;
  text?: string;
  children?: ContentNode[];
}

This structure enables hierarchical traversal.


10. Document Structure

The Document structure represents logical organization.

It defines how content is organized into meaningful hierarchical units.

interface DocumentStructure {
  sections?: Section[];
  hierarchyDepth: number;
}

Structure is independent of visual layout.


10.1 Document Metadata

Definition

DocumentMetadata describes non-semantic information about a Document.

It does NOT describe content meaning.

It only describes origin, lifecycle, and system-level attributes.


Conceptual Model

interface DocumentMetadata {
  source: DocumentSource;
  createdAt?: number;
  updatedAt?: number;
  language?: string;
  version?: string;
}

Document Source

interface DocumentSource {
  type: "webpage" | "pdf" | "markdown" | "editor" | "unknown";
  uri?: string;
}

Constraints

DocumentMetadata MUST NOT contain:


Motivation

Metadata exists to ensure:

It is strictly non-semantic.


11. Relationship to Selection

A Producer MAY maintain an internal Document model when the source has reusable logical structure. The emitted Selection is linked to its origin by the Context Object’s top-level source field and does not require a serialized Document.

Relationship:

Document
   │
   ├── contains
   ▼
Selection

A Selection without a Document is invalid within COS.

11.1 Selection Anchor References

A Document SHOULD expose stable logical content identifiers that can be referenced by Selection ranges and Hierarchy nodes.

These identifiers allow Consumers to locate the selected region from either direction:

The Document itself MUST NOT embed user Selection state.

Selection state belongs to the Context Object lifecycle, not to the source Document.


12. Document Immutability Principle

A Document SHOULD be treated as immutable during a Pipeline execution.

If modifications are required:


13. Document as Context Space

A Document defines the contextual boundary for interpretation.

It provides:

Without Document, semantic inference becomes undefined.


14. Document vs Context Object

It is critical to distinguish:

Entity Role
Document Source space
Selection Input signal
Context Object Enriched result

Flow:

Document → Selection → Context Object

15. Implementation Independence

A Document is NOT tied to any specific format:

Any system capable of representing hierarchical content MAY implement a Document.


16. Example (Informative)

{
  "id": "doc-123",
  "type": "markdown",
  "title": "React Hooks Guide",
  "content": {
    "type": "root",
    "children": [
      {
        "type": "paragraph",
        "text": "useEffect is a React Hook..."
      }
    ]
  },
  "structure": {
    "hierarchyDepth": 3
  },
  "metadata": {
    "author": "example"
  }
}

17. Design Notes (Informative)

Document is intentionally defined in a minimal form.

The goal is not to replicate DOM or file systems.

Instead, it defines a portable semantic container that can be adapted across environments.


18. Summary

A Document is the logical content space in which a Selection exists.

It provides structural and semantic boundaries necessary for contextual interpretation.

Within the Context Object Specification, Document is the foundational spatial abstraction that enables meaningful enrichment in later pipeline stages.