@dp-pcs/ogp 0.2.0

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 (82) hide show
  1. package/README.md +437 -0
  2. package/dist/cli/agent-comms.d.ts +55 -0
  3. package/dist/cli/agent-comms.d.ts.map +1 -0
  4. package/dist/cli/agent-comms.js +217 -0
  5. package/dist/cli/agent-comms.js.map +1 -0
  6. package/dist/cli/expose.d.ts +3 -0
  7. package/dist/cli/expose.d.ts.map +1 -0
  8. package/dist/cli/expose.js +104 -0
  9. package/dist/cli/expose.js.map +1 -0
  10. package/dist/cli/federation.d.ts +28 -0
  11. package/dist/cli/federation.d.ts.map +1 -0
  12. package/dist/cli/federation.js +409 -0
  13. package/dist/cli/federation.js.map +1 -0
  14. package/dist/cli/install.d.ts +3 -0
  15. package/dist/cli/install.d.ts.map +1 -0
  16. package/dist/cli/install.js +111 -0
  17. package/dist/cli/install.js.map +1 -0
  18. package/dist/cli/setup.d.ts +2 -0
  19. package/dist/cli/setup.d.ts.map +1 -0
  20. package/dist/cli/setup.js +33 -0
  21. package/dist/cli/setup.js.map +1 -0
  22. package/dist/cli.d.ts +3 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +305 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/daemon/agent-comms.d.ts +76 -0
  27. package/dist/daemon/agent-comms.d.ts.map +1 -0
  28. package/dist/daemon/agent-comms.js +188 -0
  29. package/dist/daemon/agent-comms.js.map +1 -0
  30. package/dist/daemon/doorman.d.ts +52 -0
  31. package/dist/daemon/doorman.d.ts.map +1 -0
  32. package/dist/daemon/doorman.js +203 -0
  33. package/dist/daemon/doorman.js.map +1 -0
  34. package/dist/daemon/intent-registry.d.ts +11 -0
  35. package/dist/daemon/intent-registry.d.ts.map +1 -0
  36. package/dist/daemon/intent-registry.js +101 -0
  37. package/dist/daemon/intent-registry.js.map +1 -0
  38. package/dist/daemon/keypair.d.ts +5 -0
  39. package/dist/daemon/keypair.d.ts.map +1 -0
  40. package/dist/daemon/keypair.js +25 -0
  41. package/dist/daemon/keypair.js.map +1 -0
  42. package/dist/daemon/message-handler.d.ts +20 -0
  43. package/dist/daemon/message-handler.d.ts.map +1 -0
  44. package/dist/daemon/message-handler.js +159 -0
  45. package/dist/daemon/message-handler.js.map +1 -0
  46. package/dist/daemon/notify.d.ts +7 -0
  47. package/dist/daemon/notify.d.ts.map +1 -0
  48. package/dist/daemon/notify.js +54 -0
  49. package/dist/daemon/notify.js.map +1 -0
  50. package/dist/daemon/peers.d.ts +66 -0
  51. package/dist/daemon/peers.d.ts.map +1 -0
  52. package/dist/daemon/peers.js +171 -0
  53. package/dist/daemon/peers.js.map +1 -0
  54. package/dist/daemon/reply-handler.d.ts +67 -0
  55. package/dist/daemon/reply-handler.d.ts.map +1 -0
  56. package/dist/daemon/reply-handler.js +176 -0
  57. package/dist/daemon/reply-handler.js.map +1 -0
  58. package/dist/daemon/scopes.d.ts +62 -0
  59. package/dist/daemon/scopes.d.ts.map +1 -0
  60. package/dist/daemon/scopes.js +113 -0
  61. package/dist/daemon/scopes.js.map +1 -0
  62. package/dist/daemon/server.d.ts +8 -0
  63. package/dist/daemon/server.d.ts.map +1 -0
  64. package/dist/daemon/server.js +286 -0
  65. package/dist/daemon/server.js.map +1 -0
  66. package/dist/shared/config.d.ts +42 -0
  67. package/dist/shared/config.d.ts.map +1 -0
  68. package/dist/shared/config.js +42 -0
  69. package/dist/shared/config.js.map +1 -0
  70. package/dist/shared/signing.d.ts +13 -0
  71. package/dist/shared/signing.d.ts.map +1 -0
  72. package/dist/shared/signing.js +46 -0
  73. package/dist/shared/signing.js.map +1 -0
  74. package/docs/agent-comms.md +277 -0
  75. package/docs/federation-flow.md +407 -0
  76. package/docs/quickstart.md +241 -0
  77. package/docs/scopes.md +198 -0
  78. package/package.json +57 -0
  79. package/scripts/install-skills.js +32 -0
  80. package/skills/ogp/SKILL.md +235 -0
  81. package/skills/ogp-agent-comms/SKILL.md +345 -0
  82. package/skills/ogp-expose/SKILL.md +281 -0
@@ -0,0 +1,241 @@
1
+ # OGP Quick Start Guide
2
+
3
+ Get started with OGP federation in 5 minutes.
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js >= 18
8
+ - OpenClaw running locally or remotely
9
+ - OpenClaw API token
10
+
11
+ ## Step 1: Install
12
+
13
+ ```bash
14
+ npm install -g @dp-pcs/ogp
15
+ ```
16
+
17
+ ## Step 2: Configure
18
+
19
+ Run the interactive setup:
20
+
21
+ ```bash
22
+ ogp setup
23
+ ```
24
+
25
+ Answer the prompts:
26
+
27
+ ```
28
+ Daemon port [18790]: <enter>
29
+ OpenClaw URL [http://localhost:18789]: <enter>
30
+ OpenClaw API token: your-token-here
31
+ Gateway URL (your public URL): https://temporary-url.com
32
+ Display name: Alice
33
+ Email: alice@example.com
34
+ State directory [~/.ogp]: <enter>
35
+ ```
36
+
37
+ Don't worry about the gateway URL yet — we'll get a real one in the next step.
38
+
39
+ ## Step 3: Start Daemon
40
+
41
+ ```bash
42
+ ogp start
43
+ ```
44
+
45
+ You should see:
46
+
47
+ ```
48
+ [OGP] Daemon listening on port 18790
49
+ [OGP] Public key: 302a300506032b6570032100...
50
+ ```
51
+
52
+ ## Step 4: Expose to Internet
53
+
54
+ In a new terminal:
55
+
56
+ ```bash
57
+ ogp expose
58
+ ```
59
+
60
+ This starts a cloudflared tunnel and shows your public URL:
61
+
62
+ ```
63
+ https://abc-def-123.trycloudflare.com
64
+ ```
65
+
66
+ **Important:** Copy this URL!
67
+
68
+ ## Step 5: Update Gateway URL
69
+
70
+ 1. Stop the daemon (Ctrl+C in the daemon terminal)
71
+ 2. Edit `~/.ogp/config.json`
72
+ 3. Update `"gatewayUrl"` to your tunnel URL
73
+ 4. Restart: `ogp start`
74
+
75
+ ## Step 6: Verify Setup
76
+
77
+ Test your public endpoint:
78
+
79
+ ```bash
80
+ curl https://abc-def-123.trycloudflare.com/.well-known/ogp
81
+ ```
82
+
83
+ You should see:
84
+
85
+ ```json
86
+ {
87
+ "version": "0.1.0",
88
+ "displayName": "Alice",
89
+ "email": "alice@example.com",
90
+ "gatewayUrl": "https://abc-def-123.trycloudflare.com",
91
+ "publicKey": "302a300506032b6570032100...",
92
+ "endpoints": {
93
+ "request": "https://abc-def-123.trycloudflare.com/federation/request",
94
+ "approve": "https://abc-def-123.trycloudflare.com/federation/approve",
95
+ "reply": "https://abc-def-123.trycloudflare.com/federation/reply/:nonce"
96
+ }
97
+ }
98
+ ```
99
+
100
+ ✓ Your OGP daemon is now publicly accessible!
101
+
102
+ ## Step 7: Federate with a Peer
103
+
104
+ Ask a friend to share their OGP gateway URL, then:
105
+
106
+ ```bash
107
+ ogp federation request https://peer.example.com peer-bob
108
+ ```
109
+
110
+ You'll see:
111
+
112
+ ```
113
+ ✓ Federation request sent
114
+ Status: pending
115
+ Message: Federation request received and pending approval
116
+ ```
117
+
118
+ Wait for Bob to approve your request:
119
+
120
+ ```bash
121
+ # Bob runs this on their end:
122
+ ogp federation approve peer-alice
123
+ ```
124
+
125
+ Check your approved peers:
126
+
127
+ ```bash
128
+ ogp federation list --status approved
129
+ ```
130
+
131
+ ## Step 8: Send Your First Message
132
+
133
+ ```bash
134
+ ogp federation send peer-bob message '{"text":"Hello from OGP!"}'
135
+ ```
136
+
137
+ Bob's OpenClaw agent will receive:
138
+
139
+ ```
140
+ [OGP] Message from Alice: Hello from OGP!
141
+ ```
142
+
143
+ ## Next Steps
144
+
145
+ ### Send Different Message Types
146
+
147
+ ```bash
148
+ # Task request
149
+ ogp federation send peer-bob task-request '{
150
+ "taskType": "analysis",
151
+ "description": "Analyze server logs from last hour"
152
+ }'
153
+
154
+ # Status update
155
+ ogp federation send peer-bob status-update '{
156
+ "status": "online",
157
+ "message": "Ready to collaborate"
158
+ }'
159
+ ```
160
+
161
+ ### Manage Incoming Requests
162
+
163
+ When someone sends you a federation request:
164
+
165
+ ```bash
166
+ # List pending
167
+ ogp federation list --status pending
168
+
169
+ # Approve
170
+ ogp federation approve peer-charlie
171
+
172
+ # Or reject
173
+ ogp federation reject peer-charlie
174
+ ```
175
+
176
+ ### Keep Tunnel Running
177
+
178
+ For production use, set up a permanent tunnel:
179
+
180
+ **Option 1: Named cloudflared tunnel**
181
+
182
+ ```bash
183
+ cloudflared tunnel login
184
+ cloudflared tunnel create ogp-daemon
185
+ # Edit config.yml with your tunnel settings
186
+ cloudflared tunnel run ogp-daemon
187
+ ```
188
+
189
+ **Option 2: Run as system service**
190
+
191
+ See [ogp-expose skill](../skills/ogp-expose/SKILL.md) for systemd/launchd setup.
192
+
193
+ ## Troubleshooting
194
+
195
+ ### "No configuration found"
196
+
197
+ Run `ogp setup` first.
198
+
199
+ ### "Failed to notify OpenClaw"
200
+
201
+ - Verify OpenClaw URL is correct
202
+ - Check API token is valid
203
+ - Ensure OpenClaw is running
204
+
205
+ ### "Peer not approved"
206
+
207
+ The peer must approve your federation request first. Contact them or check their status.
208
+
209
+ ### Tunnel URL not accessible
210
+
211
+ - Check firewall settings
212
+ - Verify daemon is running
213
+ - Try accessing locally first: `curl http://localhost:18790/.well-known/ogp`
214
+
215
+ ## Common Commands Cheat Sheet
216
+
217
+ ```bash
218
+ # Setup
219
+ ogp setup
220
+ ogp start
221
+ ogp expose
222
+
223
+ # Status
224
+ ogp status
225
+ ogp federation list
226
+
227
+ # Federation
228
+ ogp federation request <url> <peer-id>
229
+ ogp federation approve <peer-id>
230
+ ogp federation send <peer-id> <intent> '<json>'
231
+
232
+ # Stop
233
+ ogp stop
234
+ ```
235
+
236
+ ## What's Next?
237
+
238
+ - Read [Federation Flow](./federation-flow.md) for detailed message flow
239
+ - Check [Skills](../skills/) for Claude Code integration
240
+ - Explore custom intents in `~/.ogp/intents.json`
241
+ - Set up automatic peer discovery
package/docs/scopes.md ADDED
@@ -0,0 +1,198 @@
1
+ # OGP Scope Negotiation (v0.2.0)
2
+
3
+ OGP v0.2.0 introduces a three-layer scope model for per-peer access control, inspired by BGP route filtering.
4
+
5
+ ## The Three-Layer Model
6
+
7
+ ```
8
+ Layer 1: Gateway Capabilities → What I CAN support (advertised globally)
9
+ Layer 2: Peer Negotiation → What I WILL grant YOU (per-peer, during approval)
10
+ Layer 3: Runtime Enforcement → Is THIS request within YOUR granted scope (doorman)
11
+ ```
12
+
13
+ ### Layer 1: Gateway Capabilities
14
+
15
+ Your gateway advertises its capabilities in the federation card at `/.well-known/ogp`:
16
+
17
+ ```json
18
+ {
19
+ "version": "0.2.0",
20
+ "displayName": "David's Gateway",
21
+ "capabilities": {
22
+ "intents": ["message", "task-request", "status-update", "agent-comms"],
23
+ "features": ["scope-negotiation", "reply-callback"]
24
+ }
25
+ }
26
+ ```
27
+
28
+ This tells other gateways what you **can** support, not what you **will** grant.
29
+
30
+ ### Layer 2: Peer Negotiation
31
+
32
+ When you approve a federation request, you decide what to grant **this specific peer**:
33
+
34
+ ```bash
35
+ # Grant Stan only agent-comms with specific topics
36
+ ogp federation approve stan \
37
+ --intents agent-comms \
38
+ --topics memory-management,task-delegation \
39
+ --rate 10/60
40
+
41
+ # Grant Alice full access to message and task-request
42
+ ogp federation approve alice \
43
+ --intents message,task-request,status-update \
44
+ --rate 100/3600
45
+ ```
46
+
47
+ Scope grants are stored with the peer record and sent to the remote gateway during approval.
48
+
49
+ ### Layer 3: Runtime Enforcement (Doorman)
50
+
51
+ The doorman validates every incoming request:
52
+
53
+ 1. **Peer verification** - Is the sender approved?
54
+ 2. **Scope check** - Is this intent in their granted scopes?
55
+ 3. **Topic check** - For agent-comms, is this topic allowed?
56
+ 4. **Rate limit** - Is the peer within their request quota?
57
+
58
+ Requests that fail any check receive appropriate error codes:
59
+ - `403 Forbidden` - Scope or topic not allowed
60
+ - `429 Too Many Requests` - Rate limit exceeded (includes `Retry-After`)
61
+
62
+ ## Scope Grant Structure
63
+
64
+ ```typescript
65
+ interface ScopeGrant {
66
+ intent: string; // e.g., "agent-comms"
67
+ enabled: boolean; // Can disable without removing
68
+ rateLimit?: {
69
+ requests: number; // Max requests allowed
70
+ windowSeconds: number; // Time window
71
+ };
72
+ topics?: string[]; // For agent-comms only
73
+ expiresAt?: string; // Optional expiration (ISO timestamp)
74
+ }
75
+
76
+ interface ScopeBundle {
77
+ version: "0.2.0";
78
+ grantedAt: string; // When this grant was created
79
+ scopes: ScopeGrant[];
80
+ }
81
+ ```
82
+
83
+ ## CLI Commands
84
+
85
+ ### View Scopes
86
+
87
+ ```bash
88
+ ogp federation scopes <peer-id>
89
+ ```
90
+
91
+ Shows both:
92
+ - **Granted to peer**: What they can request from you
93
+ - **Received from peer**: What you can request from them
94
+
95
+ ### Approve with Scopes
96
+
97
+ ```bash
98
+ ogp federation approve <peer-id> \
99
+ --intents <comma-separated-list> \
100
+ --rate <requests>/<seconds> \
101
+ --topics <comma-separated-list>
102
+ ```
103
+
104
+ ### Update Grants
105
+
106
+ ```bash
107
+ ogp federation grant <peer-id> \
108
+ --intents <comma-separated-list> \
109
+ --rate <requests>/<seconds> \
110
+ --topics <comma-separated-list>
111
+ ```
112
+
113
+ ## Rate Limiting
114
+
115
+ Rate limits are enforced per-peer, per-intent using a sliding window algorithm:
116
+
117
+ ```bash
118
+ # 10 requests per minute for agent-comms
119
+ ogp federation approve stan --intents agent-comms --rate 10/60
120
+
121
+ # 100 requests per hour for all intents
122
+ ogp federation approve stan --intents message,task-request --rate 100/3600
123
+ ```
124
+
125
+ When a peer exceeds their rate limit:
126
+ - Response: `429 Too Many Requests`
127
+ - Header: `Retry-After: <seconds>`
128
+ - Message: Rate limit exceeded for intent 'agent-comms'
129
+
130
+ ## Topic Restrictions (agent-comms)
131
+
132
+ Topics provide fine-grained control over agent communication categories:
133
+
134
+ ```bash
135
+ # Allow only memory-related topics
136
+ ogp federation approve stan --intents agent-comms --topics memory-management,context-persistence
137
+
138
+ # Peer can send:
139
+ ogp federation agent me memory-management "Question" # ✓
140
+
141
+ # Peer cannot send:
142
+ ogp federation agent me billing "Question" # ✗ 403 Topic not allowed
143
+ ```
144
+
145
+ Topics support prefix matching:
146
+ - Allowing `memory` matches `memory`, `memory/contexts`, `memory/persistence`
147
+ - Use specific topics for tighter control
148
+
149
+ ## Backward Compatibility
150
+
151
+ OGP v0.2.0 is fully backward compatible with v0.1 peers:
152
+
153
+ | Scenario | Behavior |
154
+ |----------|----------|
155
+ | v0.2 approves v0.1 peer | No scopes sent, default rate limits apply |
156
+ | v0.1 peer sends message | Allowed with default limit (100/hour) |
157
+ | v0.2 sends to v0.1 peer | Works normally, no scope enforcement on their end |
158
+
159
+ Protocol version is detected automatically from:
160
+ 1. `protocolVersion` field in approval
161
+ 2. Presence of `scopeGrants` field
162
+ 3. Federation card version
163
+
164
+ ## Security Considerations
165
+
166
+ - **Principle of least privilege**: Grant only what's needed
167
+ - **Review grants periodically**: Use `ogp federation scopes` to audit
168
+ - **Monitor rate limits**: Watch for peers hitting limits frequently
169
+ - **Use topic restrictions**: Especially for agent-comms
170
+ - **Set expiration**: For temporary access, use `expiresAt` in code
171
+
172
+ ## Examples
173
+
174
+ ### Minimal Access
175
+
176
+ ```bash
177
+ # Grant only ping intent
178
+ ogp federation approve stan --intents message --rate 10/3600
179
+ ```
180
+
181
+ ### Full Agent Access
182
+
183
+ ```bash
184
+ # Grant full agent-comms with generous limits
185
+ ogp federation approve alice \
186
+ --intents agent-comms \
187
+ --rate 1000/3600
188
+ ```
189
+
190
+ ### Scoped Agent Access
191
+
192
+ ```bash
193
+ # Grant agent-comms for specific project
194
+ ogp federation approve bob \
195
+ --intents agent-comms \
196
+ --topics project-alpha,planning \
197
+ --rate 50/3600
198
+ ```
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@dp-pcs/ogp",
3
+ "version": "0.2.0",
4
+ "description": "Open Gateway Protocol (OGP) - Peer-to-peer federation daemon for OpenClaw AI gateways with cryptographic signatures",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "ogp": "./dist/cli.js",
10
+ "ogp-install-skills": "./scripts/install-skills.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "dev": "tsc --watch",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "ogp",
19
+ "openclaw",
20
+ "federation",
21
+ "ai-gateway",
22
+ "protocol",
23
+ "peer-to-peer",
24
+ "ed25519",
25
+ "cryptographic-signatures"
26
+ ],
27
+ "author": "David Proctor",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/dp-pcs/ogp.git"
32
+ },
33
+ "homepage": "https://github.com/dp-pcs/ogp#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/dp-pcs/ogp/issues"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "skills",
40
+ "scripts",
41
+ "docs",
42
+ "README.md",
43
+ "package.json"
44
+ ],
45
+ "dependencies": {
46
+ "commander": "^12.0.0",
47
+ "express": "^4.18.2"
48
+ },
49
+ "devDependencies": {
50
+ "@types/express": "^4.17.21",
51
+ "@types/node": "^20.11.0",
52
+ "typescript": "^5.3.3"
53
+ },
54
+ "engines": {
55
+ "node": ">=18.0.0"
56
+ }
57
+ }
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, mkdirSync, cpSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { homedir } from 'node:os';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { dirname } from 'node:path';
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const skillsSrc = join(__dirname, '..', 'skills');
10
+ const skillsDest = join(homedir(), '.openclaw', 'skills');
11
+
12
+ const skills = ['ogp', 'ogp-expose'];
13
+
14
+ try {
15
+ if (!existsSync(skillsDest)) {
16
+ mkdirSync(skillsDest, { recursive: true });
17
+ }
18
+
19
+ for (const skill of skills) {
20
+ const src = join(skillsSrc, skill);
21
+ const dest = join(skillsDest, skill);
22
+ if (existsSync(src)) {
23
+ cpSync(src, dest, { recursive: true });
24
+ console.log(`✓ Installed skill: ${skill} → ${dest}`);
25
+ }
26
+ }
27
+
28
+ console.log('\nOGP skills installed. Restart your OpenClaw gateway to load them.');
29
+ } catch (err) {
30
+ console.warn('Note: Could not auto-install OpenClaw skills:', err.message);
31
+ console.warn('Manual install: cp -r $(npm root -g)/ogp/skills/ogp ~/.openclaw/skills/');
32
+ }