tokensafe-ui 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +215 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # tokensafe-ui
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
+ [![npm version](https://img.shields.io/badge/npm-tokensafe--ui-orange)](https://www.npmjs.com/package/@tokensafe/ui)
5
+ [![Protocol: OUMV](https://img.shields.io/badge/protocol-OUMV%20v1.0-brightgreen.svg)](https://github.com/tokensafe-dev/oumv)
6
+
7
+ > **The native reactive micro-framework and runtime for AI coding agents implementing OUMV: The Universal Agent-UI Protocol (Observe · Understand · Mutate · Verify).**
8
+
9
+ Part of the **[TokenSafe](https://github.com/tokensafe-dev)** autonomous agent developer ecosystem.
10
+
11
+ ---
12
+
13
+ ## The Philosophy
14
+
15
+ > *"Do not try to build a framework that is merely easier for AI agents to write.
16
+ > Build a framework where an AI agent can Observe, Understand, Mutate, and Verify the interface through a standardized protocol."*
17
+
18
+ Traditional frontend frameworks (React, Vue, Angular) were designed for human developers working inside desktop IDEs. When AI agents interact with them, they hit severe friction:
19
+ - **Reactivity Traps**: Stale closures (`useEffect`, dependency arrays) cause hallucinations and infinite render loops.
20
+ - **Context Bloat**: Feeding raw HTML or DOM trees to an LLM costs tens of thousands of tokens per inspection.
21
+ - **Invisible Causality**: The agent cannot see *why* an element is in a given state or what will break if a state changes.
22
+ - **Fragile Verification Loops**: Verifying a minor UI mutation requires launching heavy, slow browser automation suites.
23
+
24
+ **`tokensafe-ui`** establishes an isomorphic reactive runtime and natively implements **[OUMV: The Universal Agent-UI Protocol](https://github.com/tokensafe-dev/oumv)** (Observe · Understand · Mutate · Verify) to close the autonomous feedback loop between AI agents and user interfaces.
25
+
26
+ ---
27
+
28
+ ## OUMV: The Universal Agent-UI Protocol Architecture
29
+
30
+ ```
31
+ ┌────────────────────────────────────────────────────────────────────────┐
32
+ │ TOKENSAFE-UI RUNTIME ENGINE │
33
+ ├───────────────────────────────┬────────────────────────────────────────┤
34
+ │ 1. OBSERVE │ 2. UNDERSTAND │
35
+ │ • Multi-Level Snapshot L0–L4 │ • Dynamic Reactive Signals Graph │
36
+ │ • A11y & Interactive Surface │ • Causality Engine (Why this state?) │
37
+ │ • Active State Values │ • Invariant & Schema Contracts │
38
+ ├───────────────────────────────┼────────────────────────────────────────┤
39
+ │ 3. MUTATE │ 4. VERIFY │
40
+ │ • Symbol-Level Edits with OCC│ • Low-ms Sync Action Testing │
41
+ │ • Transactions & Rollbacks │ • Structured State & A11y Diffs │
42
+ │ • Ephemeral Sandbox State │ • Type Guard & Diagnostics Intercept │
43
+ └───────────────────────────────┴────────────────────────────────────────┘
44
+ ```
45
+
46
+ ### 1. OBSERVE: Multi-Level Context (L0–L4)
47
+ Progressive context disclosure guarantees the agent never wastes tokens:
48
+ - **L0 (Pulse)**: Current route, mounted root components, error count (~20 tokens).
49
+ - **L1 (Interactive Surface)**: Actionable controls, ARIA roles, current values, and triggers (~100–250 tokens).
50
+ - **L2 (Component Contract)**: Targeted state schema, props, and actions (~80 tokens).
51
+ - **L3 (Isolated Source)**: Symbol-level component source code with AST line numbers.
52
+ - **L4 (Runtime Traces)**: Event stream, signal mutations, and active subscriptions.
53
+
54
+ ### 2. UNDERSTAND: Dynamic Dependency Graph & Causality Telemetry
55
+ - **Dynamic Reactive Signals Graph**: Tracks runtime dependencies (`signal -> computed -> effect -> DOM binding`) without relying solely on static AST imports.
56
+ - **Runtime Causality Inspector (`why_state`)**: Identifies root causes of UI states (e.g., *"Why is the Submit button disabled?"* $\rightarrow$ validation invariant failure in `email` field).
57
+
58
+ ### 3. MUTATE: Symbol-Level Edits with Optimistic Concurrency Control (OCC)
59
+ - **Symbol-Level Source Editing**: Agents modify clean, isolated TypeScript components with automated post-edit type checking (`tsc --noEmit`) and auto-formatting before triggering HMR.
60
+ - **Optimistic Concurrency Control (OCC)**: Every component inspection returns a content version hash; mutations require `expectedVersion` to prevent overwriting concurrent edits.
61
+ - **Ephemeral Sandbox**: Test state transitions and dispatch actions in memory without touching disk files.
62
+
63
+ ### 4. VERIFY: Local Low-Millisecond Multi-Metric Verification
64
+ - **Action Testing API**: Directly execute actions against components and receive structured state diffs and A11y surface diffs in single-digit milliseconds—without launching headless browsers.
65
+ - **Multi-Metric Latency Telemetry**: Telemetry breaks down timing across action reducer execution, schema validation, signal propagation, and DOM binding updates.
66
+ - **Contract Invariant Assertions**: Real-time schema validation via Zod contracts.
67
+
68
+ ---
69
+
70
+ ## Documentation
71
+
72
+ - [OUMV Protocol Manifesto](docs/plans/2026-11-22-agent-ui-protocol-manifesto.md)
73
+ - [Architecture & Design Specification](docs/plans/2026-11-22-agent-dom-framework-design.md)
74
+ - [MVP Implementation Plan](docs/plans/2026-11-22-agent-dom-implementation-plan.md)
75
+
76
+ ---
77
+
78
+ ## Installation
79
+
80
+ ```bash
81
+ # Using pnpm
82
+ pnpm add tokensafe-ui zod
83
+
84
+ # Using npm
85
+ npm install tokensafe-ui zod
86
+
87
+ # Or using the scoped package
88
+ pnpm add @tokensafe/ui zod
89
+ ```
90
+
91
+ ### Quickstart Scaffolding
92
+
93
+ Create a new TokenSafe UI project with pre-configured Vite, TypeScript, and AI Agent MCP integration:
94
+
95
+ ```bash
96
+ pnpm create tokensafe-ui my-app
97
+ # or
98
+ npm create tokensafe-ui my-app
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Quick Example
104
+
105
+ ### Defining an Agent-Friendly Component
106
+
107
+ ```typescript
108
+ import { defineComponent, z, bind } from 'tokensafe-ui';
109
+
110
+ export const TaskItem = defineComponent({
111
+ id: 'task-item',
112
+
113
+ // 1. Explicit State Contract (AI inspects schema in <30 tokens)
114
+ state: {
115
+ id: z.string(),
116
+ title: z.string(),
117
+ completed: z.boolean().default(false),
118
+ status: z.enum(['idle', 'saving', 'saved', 'error']).default('idle'),
119
+ },
120
+
121
+ // 2. Pure Synchronous Actions (Deterministic reducers)
122
+ actions: {
123
+ toggle: (s) => ({ ...s, completed: !s.completed }),
124
+ rename: (s, newTitle: string) => ({ ...s, title: newTitle }),
125
+ setStatus: (s, status) => ({ ...s, status }),
126
+ },
127
+
128
+ // 3. Managed Effects (Decoupled async with concurrency policy)
129
+ effects: {
130
+ save: {
131
+ concurrency: 'latest-wins',
132
+ handler: async ({ dispatch, signal, state }) => {
133
+ dispatch('setStatus', 'saving');
134
+ try {
135
+ await api.saveTask(state.id, { completed: state.completed }, { signal });
136
+ if (!signal.aborted) dispatch('setStatus', 'saved');
137
+ } catch (err: any) {
138
+ if (!signal.aborted) dispatch('setStatus', 'error');
139
+ }
140
+ },
141
+ },
142
+ },
143
+
144
+ // 4. Pure Projection with Two-Way Binding
145
+ render: ({ state, emit }) => (
146
+ <div class="task-card" data-agent-id="root">
147
+ <input
148
+ type="checkbox"
149
+ data-agent-id="checkbox"
150
+ {...bind(emit.toggle, state.completed)}
151
+ />
152
+ <span data-agent-id="title" class={state.completed ? 'done' : ''}>
153
+ {state.title}
154
+ </span>
155
+ <button data-agent-id="btn-save" onClick={emit.save} disabled={state.status === 'saving'}>
156
+ {state.status === 'saving' ? 'Saving...' : 'Save'}
157
+ </button>
158
+ </div>
159
+ ),
160
+ });
161
+ ```
162
+
163
+ ### Inspecting the Semantic Snapshot (Agent Vision)
164
+
165
+ ```typescript
166
+ import { getSemanticSnapshot } from 'tokensafe-ui/observer';
167
+
168
+ const snapshot = getSemanticSnapshot(document.getElementById('app'));
169
+ console.log(snapshot);
170
+ ```
171
+
172
+ **Output (<60 tokens for the LLM context):**
173
+ ```yaml
174
+ view: task-item#root
175
+ state: { id: "t-1", title: "Ship agent-dom", completed: false, status: "idle" }
176
+ elements:
177
+ - input#checkbox [role: checkbox, checked: false, action: toggle]
178
+ - span#title: "Ship agent-dom"
179
+ - button#btn-save: "Save" [action: save]
180
+ ```
181
+
182
+ ---
183
+
184
+ ## Roadmap
185
+
186
+ - [x] **P0: Core Reactive Substrate & Observer Foundation**
187
+ - [x] Micro-signals implementation (dependency-free, zero-closure traps).
188
+ - [x] Virtual DOM / Direct Reactive DOM mounting.
189
+ - [x] Control-flow reactive primitives (`Show`, `For`, `Portal`, `ErrorBoundary`).
190
+ - [x] Component contract specification (`defineComponent`, schema validation).
191
+ - [x] Multi-Level Observer L0–L2 (`getSemanticSnapshot`, `getPulse`, `getComponentContract`).
192
+ - [x] Vite plugin & DevServer JSON-RPC bridge.
193
+ - [x] **P1: Causality Engine & Local Verification**
194
+ - [x] Actions vs Effects separation with concurrency policies (`latest-wins`, `take-leading`, `queue`, `parallel`).
195
+ - [x] Dynamic Reactive Signals Graph (`signal -> computed -> effect -> DOM binding`).
196
+ - [x] Causality Engine query tool (`why_state`).
197
+ - [x] Local low-millisecond Action Testing API with structured state & A11y diffs.
198
+ - [x] Model Context Protocol (MCP) server tools for OUMV.
199
+ - [x] **P2: Resilient Mutations & Optimistic Concurrency Control**
200
+ - [x] Symbol-level mutation manager with OCC versioning (`version`, `expectedVersion`, atomic rollback).
201
+ - [x] Automated post-edit type-checking and formatting guard.
202
+ - [x] Native OUMV Protocol Adapter (`@agent-dom/oumv`).
203
+ - [x] Observer L3 (Isolated Source) & L4 (Runtime Traces).
204
+ - [ ] **P3: Ecosystem & Benchmarking**
205
+ - [ ] AUI-Bench autonomous agent benchmark suite.
206
+ - [ ] React / Vue adapters for the OUMV protocol.
207
+ - [x] Isomorphic SSR hydration runtime (`renderToString` + `hydrate`).
208
+ - [x] Two-way form binding helpers (`bind`).
209
+ - [x] Scaffolding CLI (`create-tokensafe-ui`).
210
+
211
+ ---
212
+
213
+ ## License
214
+
215
+ [MIT](LICENSE) © 2026 TokenSafe & Contributors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe-ui",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Deterministic, token-efficient frontend reactive micro-framework for AI coding agents",
5
5
  "type": "module",
6
6
  "files": [