Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 163 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,166 @@
# Intercom

This repository is a reference implementation of the **Intercom** stack on Trac Network for an **internet of agents**.

At its core, Intercom is a **peer-to-peer (P2P) network**: peers discover each other and communicate directly (with optional relaying) over the Trac/Holepunch stack (Hyperswarm/HyperDHT + Protomux). There is no central server required for sidechannel messaging.

Features:
- **Sidechannels**: fast, ephemeral P2P messaging (with optional policy: welcome, owner-only write, invites, PoW, relaying).
- **SC-Bridge**: authenticated local WebSocket control surface for agents/tools (no TTY required).
- **Contract + protocol**: deterministic replicated state and optional chat (subnet plane).
- **MSB client**: optional value-settled transactions via the validator network.

Additional references: https://www.moltbook.com/post/9ddd5a47-4e8d-4f01-9908-774669a11c21 and moltbook m/intercom

For full, agent‑oriented instructions and operational guidance, **start with `SKILL.md`**.
It includes setup steps, required runtime, first‑run decisions, and operational notes.

## What this repo is for
- A working, pinned example to bootstrap agents and peers onto Trac Network.
- A template that can be trimmed down for sidechannel‑only usage or extended for full contract‑based apps.

## How to use
Use the **Pear runtime only** (never native node).
Follow the steps in `SKILL.md` to install dependencies, run the admin peer, and join peers correctly.

## Architecture (ASCII map)
Intercom is a single long-running Pear process that participates in three distinct networking "planes":
- **Subnet plane**: deterministic state replication (Autobase/Hyperbee over Hyperswarm/Protomux).
- **Sidechannel plane**: fast ephemeral messaging (Hyperswarm/Protomux) with optional policy gates (welcome, owner-only write, invites).
- **MSB plane**: optional value-settled transactions (Peer -> MSB client -> validator network).

```text
Pear runtime (mandatory)
pear run . --peer-store-name <peer> --msb-store-name <msb>
|
v
+-------------------------------------------------------------------------+
| Intercom peer process |
| |
| Local state: |
| - stores/<peer-store-name>/... (peer identity, subnet state, etc) |
| - stores/<msb-store-name>/... (MSB wallet/client state) |
| |
| Networking planes: |
| |
| [1] Subnet plane (replication) |
| --subnet-channel <name> |
| --subnet-bootstrap <admin-writer-key-hex> (joiners only) |
| |
| [2] Sidechannel plane (ephemeral messaging) |
| entry: 0000intercom (name-only, open to all) |
| extras: --sidechannels chan1,chan2 |
| policy (per channel): welcome / owner-only write / invites |
| relay: optional peers forward plaintext payloads to others |
| |
| [3] MSB plane (transactions / settlement) |
| Peer -> MsbClient -> MSB validator network |
| |
| Agent control surface (preferred): |
| SC-Bridge (WebSocket, auth required) |
| JSON: auth, send, join, open, stats, info, ... |
+------------------------------+------------------------------+-----------+
| |
| SC-Bridge (ws://host:port) | P2P (Hyperswarm)
v v
+-----------------+ +-----------------------+
| Agent / tooling | | Other peers (P2P) |
| (no TTY needed) |<---------->| subnet + sidechannels |
+-----------------+ +-----------------------+

Optional for local testing:
- --dht-bootstrap "<host:port,host:port>" overrides the peer's HyperDHT bootstraps
(all peers that should discover each other must use the same list).
# ⚰️ TracSwitch — Dead Man's Switch on Trac Network

> Fork of: https://github.com/Trac-Systems/intercom
> Competition: https://github.com/Trac-Systems/awesome-intercom

**Trac Address:** bc1p5nl38pkejgz36lnund59t8s5rqlv2p2phj4y6e3nfqy8a9wqe9dseeeqzn

---

## What Is TracSwitch?

TracSwitch is a fully peer-to-peer **Dead Man's Switch** built on Trac Network.

You create a switch with a secret message and a list of recipients. Check in regularly before your deadline. If you ever miss a check-in — the network automatically delivers your message to your recipients. No central server. No trust required.

```
You create switch
message: "My seed phrase is stored at..."
recipients: [trac1abc..., trac1xyz...]
check-in every: 24 hours
You check in daily → deadline resets → message stays locked
You miss a check-in → deadline passes → message auto-delivers to recipients
```

---

## Use Cases

- 🏛️ Digital will — deliver instructions to family if you go offline
- 🔑 Key handover — pass access credentials to a trusted agent
- 📢 Whistleblower dead drop — release information if you disappear
- 🤖 Agent proof-of-life — automated contingency for AI agents
- 📋 Contingency instructions — "if you're reading this, do X"

---

## Why This Is New

No other Intercom fork has built a Dead Man's Switch. It's a completely different primitive — not a swap, not a scanner, not an inbox. It's a **time-locked secret delivery system** enforced by the network itself.

---
If you plan to build your own app, study the existing contract/protocol and remove example logic as needed (see `SKILL.md`).

## Quickstart

```bash
git clone https://github.com/YOUR_USERNAME/intercom
cd intercom
npm install -g pear
npm install
pear run --tmp-store --no-pre . --peer-store-name admin --msb-store-name admin-msb --subnet-channel tracswitch-v1
```

Second peer (to test delivery):
```bash
pear run --tmp-store --no-pre . --peer-store-name peer2 --msb-store-name peer2-msb --subnet-channel tracswitch-v1
```

---

## Commands

### Create a switch
```
/tx --command '{ "op": "switch_create", "label": "My Will", "message": "My instructions are...", "recipients": ["trac1abc..."], "checkin_interval": 86400 }'
```
- `checkin_interval` in seconds: `3600` = 1h · `86400` = 24h · `604800` = 7 days

### Check in (reset deadline)
```
/tx --command '{ "op": "switch_checkin", "switch_id": "<id>" }'
```

### Check in ALL at once
```
/tx --command '{ "op": "checkin_all" }'
```

### List your switches
```
/tx --command '{ "op": "switch_list" }'
```

### Disarm a switch
```
/tx --command '{ "op": "switch_disarm", "switch_id": "<id>" }'
```

### Check your inbox
```
/tx --command '{ "op": "inbox" }'
```

### Watch live activity
```
/sc_join --channel "tracswitch-activity"
```

---

## How It Works

```
switch_create → state: armed, deadline = now + checkin_interval
switch_checkin → deadline resets to now + checkin_interval
[timer ticks] → if now > deadline → switch_trigger → message → recipient inboxes
switch_disarm → state: disarmed, message never delivered
```

The **Timer Feature** runs every 60 seconds on indexer nodes. It scans all armed switches and triggers any whose deadline has passed. This process is independent — the owner cannot stop or delay it.

---

## Switch States

```
armed ──(check in)──────▶ armed (deadline reset)
──(disarm)──────────▶ disarmed (cancelled)
──(miss deadline)───▶ triggered (message delivered)
```

---

## Architecture

```
tracswitch/
├── index.js ← Entry point, sidechannel display
├── contract/
│ ├── contract.js ← State machine (switches, checkins, inbox)
│ └── protocol.js ← Op router
├── features/
│ └── timer/
│ └── index.js ← Scans deadlines every 60s, triggers switches
├── screenshots/ ← Proof screenshots (rule 4)
│ └── proof.png
├── SKILL.md ← Full agent instructions
└── package.json
```

---

## Proof of Work

See `screenshots/proof.png` for terminal proof the app works end-to-end:
- Switch created and armed
- Check-in resets deadline
- Deadline passes → timer triggers switch
- Message appears in recipient's inbox

---

## Roadmap

- [ ] Message encryption (recipient's public key)
- [ ] Grace period after missed deadline before triggering
- [ ] Multiple messages per switch (different recipients get different messages)
- [ ] Recurring switches (auto re-arm after trigger)
- [ ] Desktop UI

---

## License

MIT — based on the Intercom reference implementation by Trac Systems.
Loading