You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PLUGIN_ECOSYSTEM.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,10 +37,11 @@ The plugin ecosystem consists of several interconnected components:
37
37
38
38
**Features**:
39
39
- Plugin interface with lifecycle methods
40
-
- Message processing and response system
40
+
- Message processing and response system with extended context (channel, encryption status, message ID, recipient, edited flag)
41
41
- Command registration and execution
42
42
- Configuration management
43
43
- Manifest validation
44
+
- Backwards-compatible JSON wire format (new `omitempty` fields are silently ignored by older plugins)
44
45
45
46
### 2. Plugin Host (`plugin/host/`)
46
47
@@ -145,7 +146,27 @@ The plugin ecosystem consists of several interconnected components:
145
146
}
146
147
```
147
148
148
-
### Message Types
149
+
### Message Data (type "message")
150
+
151
+
When the hub sends a `"message"` request, the `data` payload is an `sdk.Message` object:
152
+
153
+
```json
154
+
{
155
+
"sender": "alice",
156
+
"content": "hello world",
157
+
"created_at": "2025-07-24T15:04:00Z",
158
+
"type": "text",
159
+
"channel": "general",
160
+
"encrypted": false,
161
+
"message_id": 42,
162
+
"recipient": "",
163
+
"edited": false
164
+
}
165
+
```
166
+
167
+
Zero-value fields (`channel` empty, `encrypted` false, `message_id` 0, etc.) are omitted from JSON via `omitempty`. Plugins compiled against older SDK versions silently ignore new keys.
168
+
169
+
### Request Types
149
170
150
171
1.**init**: Plugin initialization with configuration
Copy file name to clipboardExpand all lines: PROTOCOL.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -241,7 +241,7 @@ Sensitive values (like `admin_key`) are passed only during handshake and are not
241
241
242
242
## Notes on Extensibility
243
243
244
-
The protocol is intentionally JSON-based. **Plugins** extend the server through a managed plugin host (separate processes, JSON IPC); chat messages with `type``"text"` can be forwarded to plugins for automation, while `:`-prefixed lines and `admin_command` messages participate in the command pipeline (including built-in admin commands where authorized). Clients and tools should use the `type` field and optional structured fields (`message_id`, `channel`, `reaction`, etc.) to interpret each payload.
244
+
The protocol is intentionally JSON-based. **Plugins** extend the server through a managed plugin host (separate processes, JSON IPC); chat messages with `type``"text"` can be forwarded to plugins for automation, while `:`-prefixed lines and `admin_command` messages participate in the command pipeline (including built-in admin commands where authorized). The plugin SDK's `Message` struct mirrors the core wire fields (`sender`, `content`, `created_at`, `type`, `channel`, `encrypted`, `message_id`, `recipient`, `edited`) so plugins receive full message context. All extended fields use `omitempty`, making the wire format backwards-compatible with older compiled plugins. Clients and tools should use the `type` field and optional structured fields (`message_id`, `channel`, `reaction`, etc.) to interpret each payload.
@@ -385,10 +385,10 @@ When adding new functionality to Marchat:
385
385
386
386
## Test Metrics
387
387
388
-
-**Top-level tests**: 334 `Test*` entrypoints from `go test -list . ./...` on the main module; the nested **`plugin/sdk`** module adds 6 more (`cd plugin/sdk && go test -list . ./...`).
388
+
-**Top-level tests**: 334 `Test*` entrypoints from `go test -list . ./...` on the main module; the nested **`plugin/sdk`** module adds 10 more (`cd plugin/sdk && go test -list . ./...`).
389
389
-**Test files**: 38 `_test.go` files in the repo tree (including `plugin/sdk/plugin_test.go`).
390
390
-**Packages (`go list ./...`)**: 14 in the main module; `plugin/sdk` is a nested module with its own `go.mod`.
-**Overall Coverage**: **37.7%** across main-module packages (regenerate with `go test -coverprofile=mergedcoverage ./...` then `go tool cover -func=mergedcoverage`; on PowerShell avoid `-coverprofile=*.out`--see note above)
393
393
-**Lines of code (approx.)**: non-test `.go` lines per package directory, same totals as the **Current Coverage Status** table (e.g. `server` 6298, `client` 4966); re-count with:
394
394
`python -c "import os; ..."` walking the tree and skipping `*_test.go`, or equivalent `find` + `wc -l`.
Copy file name to clipboardExpand all lines: plugin/README.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,18 +65,55 @@ type Plugin interface {
65
65
}
66
66
```
67
67
68
+
### Message Type
69
+
70
+
The `sdk.Message` struct carries chat context from the hub to plugins and back:
71
+
72
+
```go
73
+
typeMessagestruct {
74
+
Senderstring`json:"sender"`
75
+
Contentstring`json:"content"`
76
+
CreatedAt time.Time`json:"created_at"`
77
+
Typestring`json:"type,omitempty"`
78
+
Channelstring`json:"channel,omitempty"`
79
+
Encryptedbool`json:"encrypted,omitempty"`
80
+
MessageIDint64`json:"message_id,omitempty"`
81
+
Recipientstring`json:"recipient,omitempty"`
82
+
Editedbool`json:"edited,omitempty"`
83
+
}
84
+
```
85
+
86
+
| Field | Description |
87
+
|-------|-------------|
88
+
|`Sender`| Username of the message author |
89
+
|`Content`| Message text (opaque ciphertext when `Encrypted` is true) |
90
+
|`CreatedAt`| Timestamp |
91
+
|`Type`|`"text"`, `"file"`, `"dm"`, etc. (matches `shared.MessageType` values) |
92
+
|`Channel`| Channel the message belongs to (empty = default `general`) |
93
+
|`Encrypted`|`true` when content is E2E encrypted; plugins should skip parsing |
94
+
|`MessageID`| Server-assigned ID (useful for reactions, edits) |
95
+
|`Recipient`| Target user for DMs (empty = broadcast) |
96
+
|`Edited`|`true` if the message was edited after send |
97
+
98
+
**Backwards compatibility**: All extended fields use `omitempty`. Plugins compiled against older SDK versions silently ignore unknown JSON keys and omit them on output — no recompile required.
99
+
68
100
### Message Processing
69
101
70
102
Plugins receive messages and can respond with additional messages:
0 commit comments