livetap 0.2.0 → 0.2.1
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.
- package/README.md +133 -123
- package/package.json +15 -4
- package/src/mcp/tools.ts +2 -169
- package/src/shared/canonical/cli.ts +144 -0
- package/src/shared/canonical/index.ts +10 -0
- package/src/shared/canonical/meta.ts +222 -0
- package/src/shared/canonical/tools.ts +178 -0
- package/src/shared/catalog-generators.ts +53 -44
- package/src/shared/command-catalog.ts +3 -147
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generates help text, --llm-help JSON, and MCP instructions from
|
|
2
|
+
* Generates help text, --llm-help JSON, and MCP instructions from canonical data.
|
|
3
|
+
* All generators consume the single source of truth in ./canonical/.
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
|
-
import { CLI_COMMANDS, type CatalogCommand } from './
|
|
6
|
-
import { TOOLS } from '../mcp/tools.js'
|
|
6
|
+
import { CLI_COMMANDS, type CatalogCommand, TOOLS, META } from './canonical/index.js'
|
|
7
7
|
import { readFileSync } from 'fs'
|
|
8
8
|
import { resolve } from 'path'
|
|
9
9
|
|
|
@@ -15,18 +15,17 @@ const VERSION: string = PKG.version
|
|
|
15
15
|
*/
|
|
16
16
|
export function generateHelpText(): string {
|
|
17
17
|
const lines: string[] = [
|
|
18
|
-
|
|
18
|
+
`${META.name} — ${META.description}`,
|
|
19
19
|
'',
|
|
20
20
|
'Usage:',
|
|
21
21
|
]
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
{
|
|
27
|
-
{
|
|
28
|
-
{
|
|
29
|
-
{ label: '', commands: ['watch', 'unwatch', 'watchers'] },
|
|
23
|
+
const groups: { commands: string[] }[] = [
|
|
24
|
+
{ commands: ['setup'] },
|
|
25
|
+
{ commands: ['start', 'stop', 'status'] },
|
|
26
|
+
{ commands: ['tap', 'untap', 'taps'] },
|
|
27
|
+
{ commands: ['sip'] },
|
|
28
|
+
{ commands: ['watch', 'unwatch', 'watchers'] },
|
|
30
29
|
]
|
|
31
30
|
|
|
32
31
|
for (const group of groups) {
|
|
@@ -55,23 +54,12 @@ export function generateHelpText(): string {
|
|
|
55
54
|
*/
|
|
56
55
|
export function generateLlmHelp(): object {
|
|
57
56
|
return {
|
|
58
|
-
name:
|
|
57
|
+
name: META.name,
|
|
59
58
|
version: VERSION,
|
|
60
|
-
description:
|
|
59
|
+
description: META.description,
|
|
61
60
|
setup: {
|
|
62
|
-
steps:
|
|
63
|
-
|
|
64
|
-
'Step 2: npx livetap setup (creates .mcp.json and starts the daemon — do NOT create .mcp.json manually)',
|
|
65
|
-
'Step 3: Tell user to restart Claude Code: claude --dangerously-load-development-channels server:livetap --continue',
|
|
66
|
-
'Step 4: After restart, use create_connection to connect, read_stream to sample, create_watcher to alert',
|
|
67
|
-
],
|
|
68
|
-
do_not: [
|
|
69
|
-
'Do NOT add livetap to ~/.claude/mcp.json — it goes in .mcp.json in the project root',
|
|
70
|
-
'Do NOT configure livetap as type:http — it is a stdio MCP server (command + args)',
|
|
71
|
-
'Do NOT worry about the daemon — setup starts it, and the MCP proxy auto-starts it if needed',
|
|
72
|
-
'Do NOT guess field names — always read_stream first to see actual payload structure',
|
|
73
|
-
'Do NOT use npm init — use the existing project directory',
|
|
74
|
-
],
|
|
61
|
+
steps: META.setupSteps,
|
|
62
|
+
do_not: META.doNotRules,
|
|
75
63
|
},
|
|
76
64
|
commands: CLI_COMMANDS,
|
|
77
65
|
mcp_tools: TOOLS,
|
|
@@ -80,21 +68,50 @@ export function generateLlmHelp(): object {
|
|
|
80
68
|
|
|
81
69
|
/**
|
|
82
70
|
* Generate MCP instructions string for the LLM.
|
|
83
|
-
*
|
|
71
|
+
* Assembled entirely from canonical data — no hand-written prose.
|
|
84
72
|
*/
|
|
85
73
|
export function generateInstructions(): string {
|
|
86
74
|
const toolNames = TOOLS.map((t) => t.name)
|
|
87
75
|
const connectionTools = toolNames.filter((n) => n.includes('connection'))
|
|
88
76
|
const watcherTools = toolNames.filter((n) => n.includes('watcher') || n.includes('watch'))
|
|
89
77
|
|
|
78
|
+
// Build source type examples for CONNECT section
|
|
79
|
+
const sourceExamples = META.sourceTypes
|
|
80
|
+
.filter((s) => s.status !== 'built-deferred')
|
|
81
|
+
.map((s) => {
|
|
82
|
+
switch (s.type) {
|
|
83
|
+
case 'mqtt':
|
|
84
|
+
return ` - MQTT: create_connection({ type: "mqtt", broker: "hostname", port: 1883, tls: false, topics: ["topic/#"], username: "", password: "" })`
|
|
85
|
+
case 'websocket':
|
|
86
|
+
return ` - WebSocket: create_connection({ type: "websocket", url: "wss://..." })`
|
|
87
|
+
case 'file':
|
|
88
|
+
return ` - File: create_connection({ type: "file", path: "/var/log/app.log" }) → tails the file for new lines`
|
|
89
|
+
default:
|
|
90
|
+
return ` - ${s.type}: create_connection(${s.params})`
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
.join('\n')
|
|
94
|
+
|
|
95
|
+
// Build operator list from canonical
|
|
96
|
+
const operatorList = META.operators.join(', ')
|
|
97
|
+
|
|
98
|
+
// Build data shape section from canonical
|
|
99
|
+
const dataShapeLines = META.dataShapes.map((ds) => {
|
|
100
|
+
return `- ${ds.source} (${ds.format}): ${ds.description}\n ${ds.usage}`
|
|
101
|
+
}).join('\n')
|
|
102
|
+
|
|
103
|
+
// Build alert guidance from canonical
|
|
104
|
+
const alertGuidanceLines = META.alertGuidance.map((g) => `- ${g}`).join('\n')
|
|
105
|
+
|
|
106
|
+
// Build tips section from canonical
|
|
107
|
+
const tipLines = META.tips.map((t) => `- ${t}`).join('\n')
|
|
108
|
+
|
|
90
109
|
return `
|
|
91
110
|
You have access to LiveTap, a live data streaming tool. Use it to connect to data sources, sample streams, and set up expression-based watchers that alert you when conditions match.
|
|
92
111
|
|
|
93
112
|
WORKFLOW:
|
|
94
113
|
1. CONNECT: Use create_connection to tap into a data source.
|
|
95
|
-
|
|
96
|
-
- WebSocket: create_connection({ type: "websocket", url: "wss://..." })
|
|
97
|
-
- File: create_connection({ type: "file", path: "/var/log/app.log" }) → tails the file for new lines
|
|
114
|
+
${sourceExamples}
|
|
98
115
|
Note: for MQTT, set tls: false and port: 1883 for unencrypted brokers.
|
|
99
116
|
|
|
100
117
|
2. SAMPLE: Use read_stream to inspect what data is flowing.
|
|
@@ -104,7 +121,7 @@ WORKFLOW:
|
|
|
104
121
|
|
|
105
122
|
3. WATCH: Use create_watcher to set up expression-based alerts.
|
|
106
123
|
- create_watcher({ connectionId: "conn_xxx", conditions: [{ field: "sensors.temperature.value", op: ">", value: 50 }], match: "all", cooldown: 60 })
|
|
107
|
-
- Supported operators:
|
|
124
|
+
- Supported operators: ${operatorList} (regex)
|
|
108
125
|
- match: "all" = AND (all conditions must be true), "any" = OR (at least one)
|
|
109
126
|
- cooldown: seconds between repeated alerts. Use 0 for rare events, 30-60 for sensors, 300+ for high-frequency.
|
|
110
127
|
- Alerts arrive as <channel> events. When you see one, act on it as the user requested.
|
|
@@ -119,6 +136,9 @@ CHANNEL EVENTS:
|
|
|
119
136
|
- <channel source="LiveTap" type="alert"> = a watcher condition matched. Read the payload and act on it.
|
|
120
137
|
The payload contains: watcherId, expression, matched_values, and the full stream entry.
|
|
121
138
|
|
|
139
|
+
WHEN AN ALERT FIRES:
|
|
140
|
+
${alertGuidanceLines}
|
|
141
|
+
|
|
122
142
|
When the user asks to "monitor", "watch", or "alert on" something:
|
|
123
143
|
1. First check list_connections — reuse an existing connection if possible
|
|
124
144
|
2. If no connection exists, create one
|
|
@@ -129,21 +149,10 @@ When the user asks to "monitor", "watch", or "alert on" something:
|
|
|
129
149
|
AVAILABLE TOOLS: ${toolNames.join(', ')}
|
|
130
150
|
|
|
131
151
|
DATA SHAPE BY SOURCE:
|
|
132
|
-
|
|
133
|
-
Use dot-paths into the parsed JSON: "sensors.temperature.value", "metadata.device_name"
|
|
134
|
-
- File (plain text lines): entries have { payload: "the raw line", format: "text" }.
|
|
135
|
-
Use field "payload" with contains/matches: { field: "payload", op: "contains", value: "ERROR" }
|
|
136
|
-
or { field: "payload", op: "matches", value: "5[0-9]{2}" }
|
|
137
|
-
- File (JSON lines): entries have { payload: "{...json...}", format: "json" }. Parsed as JSON.
|
|
138
|
-
Use dot-paths like MQTT: "level", "msg", "status"
|
|
152
|
+
${dataShapeLines}
|
|
139
153
|
- IMPORTANT: always use read_stream first to see the actual field names. Do NOT guess — the field is "payload", not "line" or "message".
|
|
140
154
|
|
|
141
155
|
TIPS:
|
|
142
|
-
|
|
143
|
-
- Watcher IDs (w_xxx) are globally unique. You don't need the connectionId to get, update, or delete a watcher.
|
|
144
|
-
- Common MQTT brokers: broker.emqx.io (public demo), test.mosquitto.org (public test).
|
|
145
|
-
- For regex watchers, use the "matches" operator: { field: "payload", op: "matches", value: "ERROR|FATAL" }
|
|
146
|
-
- If a field path doesn't exist in the payload, the condition evaluates to false (no crash, no error).
|
|
147
|
-
- Fields with dots in the key name (like OBIS codes "2.8.0") are looked up as literal keys first, then as dot-paths.
|
|
156
|
+
${tipLines}
|
|
148
157
|
`.trim()
|
|
149
158
|
}
|
|
@@ -1,149 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Consumed by:
|
|
5
|
-
* 1. src/mcp/tools.ts → MCP tool registration (imports TOOLS directly)
|
|
6
|
-
* 2. src/mcp/channel.ts → LLM instructions (imports generateInstructions)
|
|
7
|
-
* 3. bin/livetap.ts --help → human-readable help (imports generateHelpText)
|
|
8
|
-
* 4. bin/livetap.ts --llm-help → machine-readable JSON (imports generateLlmHelp)
|
|
2
|
+
* Re-export from canonical source.
|
|
3
|
+
* @deprecated Import from './canonical/index.js' instead.
|
|
9
4
|
*/
|
|
10
|
-
|
|
11
|
-
export interface CatalogCommand {
|
|
12
|
-
name: string
|
|
13
|
-
usage: string
|
|
14
|
-
description: string
|
|
15
|
-
args?: { position: number; name: string; required: boolean; description?: string }[]
|
|
16
|
-
flags?: { name: string; type: string; default?: unknown; description: string }[]
|
|
17
|
-
examples?: string[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* All CLI commands. This is the single source — help text and --llm-help
|
|
22
|
-
* are generated from this array.
|
|
23
|
-
*/
|
|
24
|
-
export const CLI_COMMANDS: CatalogCommand[] = [
|
|
25
|
-
// --- Setup ---
|
|
26
|
-
{
|
|
27
|
-
name: 'setup',
|
|
28
|
-
usage: 'livetap setup',
|
|
29
|
-
description: 'Configure .mcp.json, start the daemon, and print restart instructions. Run this after npm install.',
|
|
30
|
-
},
|
|
31
|
-
// --- Daemon ---
|
|
32
|
-
{
|
|
33
|
-
name: 'start',
|
|
34
|
-
usage: 'livetap start',
|
|
35
|
-
description: 'Start the livetap daemon (HTTP API)',
|
|
36
|
-
flags: [
|
|
37
|
-
{ name: '--port', type: 'number', default: 8788, description: 'Daemon port (env: LIVETAP_PORT)' },
|
|
38
|
-
{ name: '--foreground', type: 'boolean', description: 'Run in foreground (don\'t detach)' },
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: 'stop',
|
|
43
|
-
usage: 'livetap stop',
|
|
44
|
-
description: 'Stop the daemon',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'status',
|
|
48
|
-
usage: 'livetap status',
|
|
49
|
-
description: 'Show daemon, taps, and watchers',
|
|
50
|
-
flags: [
|
|
51
|
-
{ name: '--json', type: 'boolean', description: 'Output as JSON' },
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
// --- Connections ---
|
|
55
|
-
{
|
|
56
|
-
name: 'tap',
|
|
57
|
-
usage: 'livetap tap <uri|file.json>',
|
|
58
|
-
description: 'Tap into a data source (MQTT, WebSocket, file, or webhook)',
|
|
59
|
-
args: [
|
|
60
|
-
{ position: 0, name: 'source', required: true, description: 'URI (mqtt://..., wss://..., file:///path), "webhook", or a .json config file' },
|
|
61
|
-
],
|
|
62
|
-
flags: [
|
|
63
|
-
{ name: '--name', type: 'string', description: 'Display name for the connection' },
|
|
64
|
-
],
|
|
65
|
-
examples: [
|
|
66
|
-
'livetap tap mqtt://broker.emqx.io:1883/sensors/#',
|
|
67
|
-
'livetap tap wss://stream.example.com/prices',
|
|
68
|
-
'livetap tap file:///var/log/nginx/error.log',
|
|
69
|
-
'livetap tap webhook',
|
|
70
|
-
'livetap tap connection.json',
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'untap',
|
|
75
|
-
usage: 'livetap untap <connectionId>',
|
|
76
|
-
description: 'Remove a tap',
|
|
77
|
-
args: [
|
|
78
|
-
{ position: 0, name: 'connectionId', required: true },
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'taps',
|
|
83
|
-
usage: 'livetap taps',
|
|
84
|
-
description: 'List active taps',
|
|
85
|
-
flags: [
|
|
86
|
-
{ name: '--json', type: 'boolean', description: 'Output as JSON' },
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
// --- Sampling ---
|
|
90
|
-
{
|
|
91
|
-
name: 'sip',
|
|
92
|
-
usage: 'livetap sip <connectionId>',
|
|
93
|
-
description: 'Sip from a stream (sample recent entries as pretty JSON)',
|
|
94
|
-
args: [
|
|
95
|
-
{ position: 0, name: 'connectionId', required: true },
|
|
96
|
-
],
|
|
97
|
-
flags: [
|
|
98
|
-
{ name: '--max', type: 'number', default: 10, description: 'Max entries to return' },
|
|
99
|
-
{ name: '--back', type: 'number', default: 60, description: 'Backfill seconds' },
|
|
100
|
-
{ name: '--raw', type: 'boolean', description: 'Output raw JSON' },
|
|
101
|
-
],
|
|
102
|
-
},
|
|
103
|
-
// --- Watchers ---
|
|
104
|
-
{
|
|
105
|
-
name: 'watch',
|
|
106
|
-
usage: 'livetap watch <connectionId> "expression"',
|
|
107
|
-
description: 'Create an expression-based watcher',
|
|
108
|
-
args: [
|
|
109
|
-
{ position: 0, name: 'connectionId', required: true },
|
|
110
|
-
{ position: 1, name: 'expression', required: true, description: '"field > value", supports AND/OR' },
|
|
111
|
-
],
|
|
112
|
-
flags: [
|
|
113
|
-
{ name: '--cooldown', type: 'number', default: 60, description: 'Seconds between repeated alerts (0 = every match)' },
|
|
114
|
-
{ name: '--action', type: 'string', description: '"channel_alert" (default), "webhook:URL", or "shell:command"' },
|
|
115
|
-
],
|
|
116
|
-
examples: [
|
|
117
|
-
'livetap watch conn_abc "temperature > 50"',
|
|
118
|
-
'livetap watch conn_abc "temp > 50 AND humidity > 90"',
|
|
119
|
-
'livetap watch conn_abc "temp > 50 OR smoke > 0.05"',
|
|
120
|
-
'livetap watch conn_abc "price > 70000" --cooldown 300',
|
|
121
|
-
],
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: 'unwatch',
|
|
125
|
-
usage: 'livetap unwatch <watcherId>',
|
|
126
|
-
description: 'Remove a watcher',
|
|
127
|
-
args: [
|
|
128
|
-
{ position: 0, name: 'watcherId', required: true },
|
|
129
|
-
],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'watchers',
|
|
133
|
-
usage: 'livetap watchers [connectionId|watcherId]',
|
|
134
|
-
description: 'List watchers, show watcher details, or view watcher logs',
|
|
135
|
-
args: [
|
|
136
|
-
{ position: 0, name: 'connectionId or watcherId', required: false, description: 'Filter by connection (conn_xxx) or show details for a watcher (w_xxx)' },
|
|
137
|
-
],
|
|
138
|
-
flags: [
|
|
139
|
-
{ name: '--json', type: 'boolean', description: 'Output as JSON' },
|
|
140
|
-
{ name: '--logs', type: 'string', description: 'Show evaluation logs for a watcher ID' },
|
|
141
|
-
],
|
|
142
|
-
examples: [
|
|
143
|
-
'livetap watchers',
|
|
144
|
-
'livetap watchers conn_abc',
|
|
145
|
-
'livetap watchers w_abc',
|
|
146
|
-
'livetap watchers --logs w_abc',
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
]
|
|
5
|
+
export { CLI_COMMANDS, type CatalogCommand } from './canonical/cli.js'
|