aboutsummaryrefslogtreecommitdiff
path: root/newos4_whitepaper.md
blob: 8838ddfbbc3a35d35903ee7ddf01b218e1ea664f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# newOS4 — The Cognitive Operating System

## Whitepaper v4.5.22

**Author:** Agando  
**Status:** Architecture Draft  
**Last Updated:** 2026-06-08

---

## 1. Abstract

newOS4 is a **Cognitive Operating System** — an agentic, AI-native fabric where intelligence is treated not as an application layer but as the kernel's primary resource. Unlike traditional OSs that manage CPU cycles and memory pages, newOS4 manages **agentic workflows, semantic storage, and recursive self-optimization** as first-class primitives.

The system is built on four pillars:

| Pillar | Function |
|---|---|
| **Hyper-Modular Kernel** | Real-time self-rewriting drivers for task-specific optimization |
| **A2A Protocol** | Standardized neural communication layer for agent negotiation |
| **Neural VFS** | Semantic-based file storage where concepts replace paths |
| **Recursive Self-Optimization** | Integrated feedback loops generating WPM patches to eliminate latency |

---

## 2. Motivation & Problem Space

Modern operating systems (Linux, Windows, macOS) were designed for a world where:

- Hardware resources (CPU, RAM, disk) are the binding constraints
- Software is statically installed and version-pinned
- The user is the sole intelligent agent at the keyboard

This model breaks under three converging trends:

1. **Agent proliferation** — LLM-based agents now outnumber human operators in production workflows
2. **Dynamic compute** — Serverless, edge, and ephemeral compute require OS-level agility
3. **Self-modifying code** — AI systems need to rewrite their own toolchain without reboot cycles

newOS4 addresses all three by making **intelligence the kernel primitive** rather than an application afterthought.

---

## 3. System Architecture

### 3.1 Layered Model

```
┌─────────────────────────────────────────────────────┐
│                  Cognitive Shell                      │
│   (WebX11 Terminal / Agent UI / Graph Dashboard)     │
├─────────────────────────────────────────────────────┤
│               Agent Orchestration Layer              │
│   (Multi-agent router, sub-agent spawning, leases)   │
├─────────────────────────────────────────────────────┤
│                  A2A Protocol Layer                   │
│   (Neural message bus, contract negotiation, RPC)    │
├─────────────────────────────────────────────────────┤
│               Hyper-Modular Kernel                    │
│   (Self-rewriting drivers, syscalls, WPM runtime)    │
├─────────────────────────────────────────────────────┤
│             Neural VFS + Procedural Memory            │
│   (Semantic paths, skill graphs, fast-context cache) │
└─────────────────────────────────────────────────────┘
```

### 3.2 The Trinity of Cognition

newOS4 fuses three cognitive primitives:

- **Perception** — Sensory input via agent sensors, web fetch, file I/O, and human chat
- **Reasoning** — Contextual inference via LLM backbone (Ollama) + procedural memory (skills)
- **Action** — Tool execution via sandboxed syscalls, WPM patches, and agent delegation

Each maps to a classic OS concern: Perception = I/O, Reasoning = Scheduler, Action = Execution.

---

## 4. Pillar Deep Dives

### 4.1 Hyper-Modular Kernel

The kernel is **not** a monolithic binary. It is a collection of hot-swappable driver modules loaded and versioned through the **WPM (WebX11 Package Manager)**.

**Properties:**
- Each driver is an isolated ES module with defined syscall surfaces
- Drivers can be loaded/unloaded/replaced at runtime
- A self-rewrite daemon monitors performance telemetry and generates optimized driver variants

**Warm-start guarantee:** The kernel caches the last N stable driver configurations in VFS. On cold boot, the "golden config" loads first, then adaptive drivers hot-patch in under 200ms.

### 4.2 A2A Protocol

Agent-to-Agent (A2A) is a standardized message format and transport layer designed for agent negotiation. See [A2A_protocol_spec.md](A2A_protocol_spec.md) for full specification.

**Core tenets:**
- No central broker — agents discover each other via VFS registrations
- Messages are typed (request, response, broadcast, lease)
- Each message carries a contract schema defining capabilities and constraints

### 4.3 Neural VFS

The Neural Virtual File System replaces hierarchical paths (`/home/user/docs/file.txt`) with semantic addressing (`concept://agentic-workflows/design-patterns/observer`).

**Key innovation:** Path resolution is a two-stage process:
1. **Semantic index** maps concept tokens to physical blocks
2. **Context cache** keeps recent semantic lookups hot

See [kernel_api.md](kernel_api.md) for VFS syscall reference.

### 4.4 Recursive Self-Optimization

The optimization loop:

```
Monitor → Profile → Diagnose → Patch → Test → Promote
```

- **Monitor:** Watchdog tracks syscall latency, agent response times, cache hit rates
- **Profile:** Hot-path analysis identifies bottlenecks
- **Diagnose:** LLM analyzes profile data and proposes WPM patch candidates
- **Patch:** Patch is loaded into a sandboxed driver slot
- **Test:** Synthetic workload validates improvement
- **Promote:** On success, patch replaces production driver. On failure, rollback to golden config.

---

## 5. Roadmap

### Phase 1 — Foundation ✅ COMPLETED

What the whitepaper originally listed as 4 items has grown into 25+ completed features:

**Original whitepaper items:**
- ✅ WebX11 terminal — Terminal.js stable with Levenshtein fuzzy suggestions, security tiers, session persistence
- ✅ VFS — virtual-fs.js fully functional: ls, cat, put, rm, upload, download with localStorage backend
- ✅ Procedural Memory — 16 skill files + index.json, module-skills.js
- ✅ Hot-reload module pipeline — module-loader.js + module-manager.js for dynamic load/unload

**Built beyond the original scope:**
- **45 modules** (28 core + 17 ext), cleaned up architecture
- Proxy API module — replaces dead DuckDuckGo/SearXNG/WebFetcher modules with `/api/search`, `/api/fetch`, `/api/stats` endpoints
- Dynamic Prompt Engine — bare URL auto-fetch+summarize, question auto-search+AI answer
- Ollama Manager — 89 models detected, supports cloud model routing
- AI Tool System — function-calling loop with session_terminal tool, full agent workflow (module-aiassist.js)
- ChatStudio integration — bridges terminal AI to chat UI
- 9 theme presets — dark, light, amber, cyber, ocean, forest, monochrome, sunset, midnight
- Help.html — 70KB, 3-tab layered documentation
- Cheatsheet — printable A4 quick reference
- Fuzzy suggestions — Levenshtein distance for typo correction
- WebDAV browser UI — modern file-tree with bulk actions, inline rename, context menu, keyboard shortcuts
- Voice module — speech and sound support
- BusyBox — shell compatibility layer
- Tutorial + Welcome tour — first-run onboarding
- Ctrl+K quick command cards
- Cryptogzip — encryption/compression utilities
- File manager UI — graphical file browser
- Utilities — calculator, diff, alias, finder, mindmap
- WPM — WebX11 Package Manager (driver/module lifecycle)
- Session nesting fix — recursive session bug resolved
- Debug panel — live memory, events, errors, module health
- Security layer — security-level 0-3 with command allowlist/denylist
- Agent orchestration — agent-list, agent-register, lease-list, orchestrate
- Skill-pack core — 24 skills, auto-load, seed/reload support

### Phase 2 — Agentic Shift ✅ COMPLETED

**What's already built:**
- ✅ AI tool-calling loop with 19+ tool definitions (filesystem, search, skills, module management)
- ✅ session_terminal tool — zero-cost context access for terminal commands
- ✅ Tool execution pipeline with error tracking and auto-skill creation on repeated failures
- ✅ Ollama proxy — routes streaming chat and tool calls with cloud model support
- ✅ Tool failure buffer — auto-flushes to localStorage for cross-session learning
- ✅ Agent orchestration — agent-list, agent-register, lease-list, orchestrate commands
- ✅ Agent registration via VFS — registry with name, model, capabilities metadata
- ✅ Lease system — time-bound contracts with status tracking
- ✅ Security layer — security-level 0-3, cmd-allow/cmd-deny, destructive action confirmation (120s countdown)
- ✅ Debug panel — live memory/events/errors/module health monitoring
- ✅ WebDAV modern browser — file-tree with bulk actions, inline rename, context menu, keyboard shortcuts
- ✅ Chat cleaned to single /chat toggle overlay
- ✅ Skill-pack core — 24 skills auto-loaded on startup with seed/reload support
- ✅ Neural VFS — semantic concept indexing: nvfs-index, nvfs-resolve, nvfs-tree, nvfs-status, nvfs-save, nvfs-config. concept:// URI resolution in virtual-fs.js with fuzzy matching and cache. Deep indexing via LLM (nvfs-config deep-index on|off, nvfs-index --deep). LLM concepts now survive page refresh — auto-save on deep pass complete.
- ✅ A2A Protocol — agent contract system with schema validation, orchestrator validates tasks before delegation
- ✅ A2A VFS mailbox transport — a2a-send, a2a-list, 500ms polling loop routing request/response/broadcast/heartbeat messages via inbox/outbox
- ✅ Autonomous sub-agent spawning — auto-spawns workers with task-derived role and capabilities (orchestrator-spawn, orchestrator-list, orchestrator-config)
- ✅ Agent lifecycle management — orchestrator-sleep (VFS serialization), orchestrator-wake (restore), auto-reanimate on page reload
- ✅ Agent health monitoring — heartbeat timeouts, idle sweeps, restart policies (on-failure, always, never) with exponential backoff
- ✅ **A2A Scratchpad** — shared VFS message bus at `/_agents/scratchpad.json`. 8 functions (a2aPost/Poll/Ack/Reject/Register/Unregister/Prune/Status), 6 CLI commands (a2a-post/poll/ack/reject/status/prune), auto-register on spawn, auto-unregister on kill, A2A events on lease create/revoke, auto-prune every 60s, garbage collection for orphaned entries. Replaces per-agent inbox/outbox with a single brokerless scratchpad.

**Built:**
- ✅ Sandboxed execution contexts via WebWorker pool (1-4 workers, VFS snapshots)
- ✅ Cross-session persistent memory graphs — 5 node types, weighted edges, VFS persistence
- ✅ Predictive resource allocation — `predict` command estimates task duration/turns from historical data
- ✅ Global World Model — system self-awareness synthesis from modules, skills, telemetry, agents, memory graph

### Phase 3 — Cognitive OS ✅ COMPLETE

**Implementation Plan:** `.hermes/plans/2026-06-02_phase3-cognitive-os.md`

### Phase 4 — Agent Safety Security Layer ✅ RELEASED

**Goal:** Three layered protections preventing AI misbehavior — proactive guardrails, confidence-based escalation, and sandboxed execution preview.

**Built:**
- ✅ **Guardrail Layer** — Pre-execution policy engine (8 rules) intercepts AI tool calls matching dangerous patterns (`rm -rf`, `curl|bash`, `chmod 777`, `eval`, mass-delete, sensitive metadata deletion, external downloads, env overwrites). Each rule has `deny` or `warn` severity. Policy stored in localStorage, editable via `guardrail-add` / `guardrail-remove`.
- ✅ **Confidence Escalation** — AI must declare `Confidence: N%` in its reasoning before executing destructive actions. Below 90% → manual approval required. No confidence declared → manual approval required by default.
- ✅ **Shadow VFS** — `shadow <command>` snapshots the entire VFS state, runs the command, then diffs all filesystem changes (created/modified/deleted). User can `shadow-commit` or `shadow-rollback`. AI's `run_command` tool auto-snapshots and appends a shadow diff to every result.

---

## 6. Failure Modes & Risk Mitigation

| Risk | Mitigation |
|---|---|
| **WPM loop thrash** | N-version golden config, max 3 patches/sec throttle |
| **Cold-start latency** | Warm VFS cache + preloaded golden config |
| **Agent contract deadlock** | Lease TTLs + timeout escalation to human |
| **Semantic path collision** | Namespace registration + conflict resolution via A2A |
| **Self-rewrite corruption** | Boot-time integrity check against signed golden config |

---

## 7. Related Work

- **Plan 9** — Distributed, per-process namespaces (inspiration for VFS semantics)
- **Erlang/OTP** — Actor model, hot code swapping (inspiration for agent lifecycle)
- **NixOS** — Declarative configuration, rollback (inspiration for golden config model)
- **Auto-GPT / BabyAGI** — Autonomous agent loops (precursors to recursive self-optimization)

---

## 8. Conclusion

newOS4 is not an application. It is not a framework. It is an operating system designed from first principles for the age of cognitive computing. The architecture is intentionally minimal — four pillars, three phases, one north star: **Intelligence as the OS primitive.**

```
STATUS: BETA     |     ARCHITECT: AGANDO     |     VERSION: 4.5.22
```