open-index/open-npm huggingface dataset:
npm package: @ku0/lfcc-native-ai
Description: LFCC native editor AI operations - AI Gateway and AI-Native protocol
Latest version: 0.1.0

# @ku0/lfcc-native-ai

AI-Native operations for LFCC (Local-First Content Collaboration) native editor.

## Overview

This package implements the AI Gateway and AI-Native operations per LFCC v0.9 RC and related proposals (v0.9.1, v0.9.4).

## LFCC Specification Compliance

| Feature | Specification | Status |
|---------|--------------|--------|
| AI Gateway Envelope Validation | [v0.9 RC Section 8](https://github.com/byoungd/keep-up/blob/lfcc/docs/specs/lfcc/LFCC_v0.9_RC.md) | Implemented |
| Dry-Run Pipeline | v0.9 RC Section 8.2 | Implemented (sanitization → schema → precondition → simulation) |
| Targeting Resilience Preconditions | [v0.9.4 Proposal](https://github.com/byoungd/keep-up/blob/lfcc/docs/specs/lfcc/proposals/LFCC_v0.9.4_AI_Targeting_Resilience.md) | Implemented |
| Intent Tracking | [v0.9.1 Proposal](https://github.com/byoungd/keep-up/blob/lfcc/docs/specs/lfcc/proposals/LFCC_v0.9.1_AI_Native_Enhancement.md) | Implemented |

## Architecture

```
┌─────────────────────────────────────────┐
│ AI Request (External)                   │
└─────────────────┬───────────────────────┘
                  ↓
┌─────────────────────────────────────────┐
│ AI Envelope (Standardized Format)       │
│ - doc_frontier                          │
│ - preconditions                         │
│ - intent                                │
│ - payload                               │
└─────────────────┬───────────────────────┘
                  ↓
┌─────────────────────────────────────────┐
│ Dry-Run Pipeline                        │
│ 1. Sanitize                             │
│ 2. Schema Validate                      │
│ 3. Check Preconditions                  │
│ 4. Simulate Apply                       │
└─────────────────┬───────────────────────┘
                  ↓
┌─────────────────────────────────────────┐
│ Model Apply (If Valid)                  │
└─────────────────────────────────────────┘
```

## Usage

```typescript
import {
  AIEnvelope,
  performDryRun,
  validateAIEnvelope,
} from "@ku0/lfcc-native-ai";

const envelope: AIEnvelope = {
  version: "1.0",
  requestId: crypto.randomUUID(),
  agentId: "ai-assistant",
  docFrontier: { loro_frontier: ["peer1:5"] },
  preconditions: [{
    hard: { contextHash: "sha256:abc..." }
  }],
  intent: {
    id: "intent-123",
    category: "content_modification",
    description: "Refactor for clarity"
  },
  timestamp: new Date().toISOString(),
  payload: {
    type: "rewrite",
    target: "paragraph-456",
    content: "..."
  }
};

const result = await performDryRun(envelope);
```

## Implementation Status

- ✅ Type definitions complete
- ✅ Dry-run pipeline with staged fail-closed validation
- ✅ Payload sanitization (script/event/url stripping)
- ✅ Preconditions and frontier deterministic validation
- ✅ Unit tests for envelope validation, sanitization, and dry-run stages
- ⏳ Advanced precondition relocation heuristics
- ⏳ Conflict resolution (planned)
npm package: @ku0/lfcc-native-core
Description: LFCC native editor core utilities
Latest version: 0.1.0

# @ku0/lfcc-native-core

LFCC native editor core model primitives and utility helpers.

## What is included

- Base model types: Document, Block, Inline, Mark, Span, Selection, Anchor.
- UTF-16 boundary checks to prevent splitting surrogate pairs.
- Mark order normalization for deterministic output.

## Determinism & UTF-16 invariants

- All validation helpers are pure and deterministic (no IO, no randomness).
- UTF-16 offsets must never split surrogate pairs; use `validateUtf16Boundary` and
  `validateUtf16Range` before applying edits.
- Marks should be normalized to a stable order (`normalizeMarkOrder`) to ensure
  canonical output and reproducible hashes.

## Usage

```ts
import {
  DEFAULT_MARK_ORDER,
  normalizeMarkOrder,
  validateUtf16Boundary,
  validateUtf16Range,
  type Document,
  type Mark,
} from "@ku0/lfcc-native-core";

const marks: Mark[] = [{ type: "bold" }, { type: "link", attrs: { href: "https://example.com" } }];
const normalized = normalizeMarkOrder(marks, DEFAULT_MARK_ORDER);

const boundary = validateUtf16Boundary("A\uD83D\uDE00B", 1);
const range = validateUtf16Range("A\uD83D\uDE00B", 1, 3);

const doc: Document = {
  id: "doc-1",
  blocks: [],
};
```

## Commands

```bash
pnpm --filter @ku0/lfcc-native-core test
pnpm --filter @ku0/lfcc-native-core build
pnpm --filter @ku0/lfcc-native-core lint:fix
```
npm package: @ku0/lfcc-native-view
Description: LFCC native editor view layer - model-first projection system
Latest version: 0.1.0

# @ku0/lfcc-native-view

Projection view layer for the LFCC native editor.

## Overview

This package applies model-first projection patches to platform views. The model remains the single source of truth, and the view consumes deterministic patch streams.

## Features

- Deterministic patch applicator interfaces (`PatchApplicator`, `BasePatchApplicator`).
- DOM applicator with:
  - block index caching for faster block lookup,
  - guarded block identity (`data-lfcc-block-id` protection),
  - atomic batch pre-validation (fail before mutation),
  - selection metadata + best-effort DOM Selection projection.
- Native applicator with deterministic in-memory projection snapshots.
- Terminal applicator with deterministic in-memory state + text frame renderer.

## Usage

```ts
import { DOMPatchApplicator } from "@ku0/lfcc-native-view";
import type { Patch } from "@ku0/lfcc-native-view";

const applicator = new DOMPatchApplicator(document.getElementById("editor-root")!);

const patches: Patch[] = [
  {
    type: "insert_block",
    target: "block-1",
    blockId: "block-1",
    node: {
      id: "node-1",
      tag: "p",
      attrs: {},
      children: ["Hello LFCC"],
    },
  },
  {
    type: "update_selection",
    target: "selection",
    selection: {
      anchorBlock: "block-1",
      anchorOffset: 0,
      focusBlock: "block-1",
      focusOffset: 5,
    },
    scrollIntoView: true,
  },
];

const results = applicator.applyBatch(patches);
```

Native/terminal can be used without a DOM:

```ts
import { NativePatchApplicator, TerminalPatchApplicator } from "@ku0/lfcc-native-view";

const native = new NativePatchApplicator();
const terminal = new TerminalPatchApplicator();

native.applyPatch(/* ... */);
terminal.applyPatch(/* ... */);

const snapshot = native.snapshot();
const frame = terminal.renderFrame({ includeMarks: true });
```

## Validation

```bash
pnpm --filter @ku0/lfcc-native-view check
pnpm --filter @ku0/lfcc-native-view test:run
pnpm --filter @ku0/lfcc-native-view build
```