@ramme-io/devkit 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +116 -2
- package/dist/chunk-LEO24C5C.js +285 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +143 -0
- package/dist/index.d.ts +164 -0
- package/dist/index.js +38 -0
- package/package.json +36 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Excesspool Limited Liability Company
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ramme-io/devkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Make Ramme apps on your own machine, with your own coding agent and your own
|
|
4
|
+
model keys. The devkit checks an app the way the boards do, lists your boards
|
|
5
|
+
and sends one an app — as the `ramme` command, or as a local MCP server any
|
|
6
|
+
agent can use. ramme.io only checks and delivers; it never runs a model for
|
|
7
|
+
you. Why it exists: `docs/superpowers/community-platform-plan.md`.
|
|
8
|
+
|
|
9
|
+
A Ramme app is a JSON document the board draws, never code it runs.
|
|
10
|
+
`ramme guide` prints the whole format.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
Node 20 or newer.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @ramme-io/devkit
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
That gives you the `ramme` command. Or run it without installing, as
|
|
21
|
+
`npx @ramme-io/devkit <command>`.
|
|
22
|
+
|
|
23
|
+
## Get a token
|
|
24
|
+
|
|
25
|
+
On ramme.io, open **Settings → Access tokens** and make one. Tick **See my
|
|
26
|
+
boards** and **Send apps to my boards**, choose how long it lasts, and copy it
|
|
27
|
+
— it is shown once. Then either save it:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
ramme login --token rmk_…
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or give it to the process that needs it, which is what an agent or a CI job
|
|
34
|
+
should do:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export RAMME_TOKEN=rmk_…
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Revoke it on the same page whenever you like; anything using it stops at once.
|
|
41
|
+
|
|
42
|
+
## Your own server
|
|
43
|
+
|
|
44
|
+
The devkit works the same against a Ramme you run yourself
|
|
45
|
+
(`npx @ramme-io/create-app my-ramme --template device`). When that server
|
|
46
|
+
starts, it prints the two values to set:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export RAMME_API_URL=http://192.168.1.20:3000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
export RAMME_TOKEN=rmh_…
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Every command and tool then talks to that server instead of ramme.io.
|
|
57
|
+
|
|
58
|
+
## Commands
|
|
59
|
+
|
|
60
|
+
| command | what it does |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `ramme guide` | how an app is written: every block, source and limit |
|
|
63
|
+
| `ramme validate app.json` | check an app; exits 1 and names each problem when it is not valid |
|
|
64
|
+
| `ramme login` / `ramme logout` | save or forget a token |
|
|
65
|
+
| `ramme boards` | your boards, by name and id, and when each last checked in |
|
|
66
|
+
| `ramme send "Kitchen shelf" app.json` | validate, then send to a board by name or id |
|
|
67
|
+
| `ramme mcp` | all of the above as an MCP server on stdio |
|
|
68
|
+
|
|
69
|
+
A board picks up a new app at its next check-in: within about 30 seconds if
|
|
70
|
+
someone is using it, five minutes if it is idle.
|
|
71
|
+
|
|
72
|
+
## With a coding agent (MCP)
|
|
73
|
+
|
|
74
|
+
The server offers these tools, and tells the agent to read the guide first and
|
|
75
|
+
validate before sending:
|
|
76
|
+
|
|
77
|
+
- `ramme_app_guide`: how an app document is written.
|
|
78
|
+
- `ramme_validate_app`: checks one against the schema the boards use.
|
|
79
|
+
- `ramme_list_boards`: your boards, and when each last checked in.
|
|
80
|
+
- `ramme_board_parts`: what one board has plugged in, whether each part works,
|
|
81
|
+
and each sensor's latest reading as a Signal (a temperature probe's
|
|
82
|
+
`temperature` in °C, say).
|
|
83
|
+
- `ramme_send_app`: sends a validated app to a board, by id or name.
|
|
84
|
+
|
|
85
|
+
Claude Code:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
claude mcp add ramme --env RAMME_TOKEN=rmk_… -- npx -y @ramme-io/devkit mcp
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Any other client takes the same command with `RAMME_TOKEN` (and, for your
|
|
92
|
+
own server, `RAMME_API_URL`) in its environment. Nothing but protocol messages is ever written to stdout.
|
|
93
|
+
|
|
94
|
+
## From this repo
|
|
95
|
+
|
|
96
|
+
Build it, then run the built command:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pnpm --filter @ramme-io/devkit build
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
node framework/devkit/dist/cli.js boards
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Its tests run offline against a fake ramme.io:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pnpm --filter @ramme-io/devkit test
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## What the server still checks
|
|
113
|
+
|
|
114
|
+
Everything. A token reaches only your own boards and only what its scopes
|
|
115
|
+
allow, 60 requests a minute; every app is validated again on arrival; and a
|
|
116
|
+
token cannot make tokens, change your account or see anyone else's boards.
|
|
117
|
+
See `products/ramme-marketing/lib/auth/guard.ts`.
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// src/credentials.ts
|
|
2
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync, chmodSync, existsSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
import { ACCESS_TOKEN_PREFIX } from "@ramme-io/shared";
|
|
6
|
+
var DEFAULT_API = "https://www.ramme.io";
|
|
7
|
+
var credentialsPath = (env = process.env) => join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "ramme", "credentials.json");
|
|
8
|
+
var apiBase = (env = process.env) => (env.RAMME_API_URL || DEFAULT_API).replace(/\/+$/, "");
|
|
9
|
+
var findToken = (env = process.env) => {
|
|
10
|
+
if (env.RAMME_TOKEN) return { token: env.RAMME_TOKEN.trim(), from: "env" };
|
|
11
|
+
const path = credentialsPath(env);
|
|
12
|
+
if (!existsSync(path)) return null;
|
|
13
|
+
try {
|
|
14
|
+
const { token } = JSON.parse(readFileSync(path, "utf8"));
|
|
15
|
+
return token ? { token, from: "file" } : null;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var looksLikeToken = (token) => /^rmk_[A-Za-z0-9_-]{43}$/.test(token) && token.startsWith(ACCESS_TOKEN_PREFIX) || /^rmh_[A-Za-z0-9_-]{24}$/.test(token);
|
|
21
|
+
var serverLabel = (base) => base === DEFAULT_API ? "ramme.io" : base.replace(/^https?:\/\//, "");
|
|
22
|
+
var saveToken = (token, env = process.env) => {
|
|
23
|
+
const path = credentialsPath(env);
|
|
24
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
25
|
+
writeFileSync(path, JSON.stringify({ token }) + "\n", { mode: 384 });
|
|
26
|
+
chmodSync(path, 384);
|
|
27
|
+
return path;
|
|
28
|
+
};
|
|
29
|
+
var forgetToken = (env = process.env) => {
|
|
30
|
+
const path = credentialsPath(env);
|
|
31
|
+
if (!existsSync(path)) return false;
|
|
32
|
+
rmSync(path);
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/api.ts
|
|
37
|
+
import { DeviceIdSchema } from "@ramme-io/shared";
|
|
38
|
+
var RammeApiError = class extends Error {
|
|
39
|
+
constructor(status, code, message) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.status = status;
|
|
42
|
+
this.code = code;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var HINTS = {
|
|
46
|
+
NOT_SIGNED_IN: "No working token. Make one on ramme.io under Settings \u2192 Access tokens (or use the one your own server printed), then run `ramme login` or set RAMME_TOKEN.",
|
|
47
|
+
TOKEN_SCOPE: "",
|
|
48
|
+
RATE_LIMITED: ""
|
|
49
|
+
};
|
|
50
|
+
var createClient = (options) => {
|
|
51
|
+
const doFetch = options.fetch ?? fetch;
|
|
52
|
+
const call = async (method, path, body) => {
|
|
53
|
+
if (!options.token) throw new RammeApiError(401, "NOT_SIGNED_IN", HINTS.NOT_SIGNED_IN);
|
|
54
|
+
const res = await doFetch(`${options.base}${path}`, {
|
|
55
|
+
method,
|
|
56
|
+
headers: {
|
|
57
|
+
authorization: `Bearer ${options.token}`,
|
|
58
|
+
"content-type": "application/json",
|
|
59
|
+
"user-agent": "ramme-devkit"
|
|
60
|
+
},
|
|
61
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
62
|
+
});
|
|
63
|
+
const json = await res.json().catch(() => ({}));
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
const code = json.error ?? `HTTP_${res.status}`;
|
|
66
|
+
throw new RammeApiError(res.status, code, HINTS[code] || json.message || `${serverLabel(options.base)} answered ${res.status}.`);
|
|
67
|
+
}
|
|
68
|
+
return json;
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
boards: async () => (await call("GET", "/api/device/list")).devices,
|
|
72
|
+
parts: async (deviceId) => {
|
|
73
|
+
const page = await call("GET", `/api/device/vitals?id=${encodeURIComponent(deviceId)}`);
|
|
74
|
+
return { features: page.vitals?.features ?? {}, readings: page.readings ?? [] };
|
|
75
|
+
},
|
|
76
|
+
send: async (deviceId, document) => await call("POST", "/api/device/send", { deviceId, document })
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
var resolveBoard = (boards, said) => {
|
|
80
|
+
const want = said.trim();
|
|
81
|
+
const byId = boards.find((b) => b.deviceId === want.toUpperCase());
|
|
82
|
+
if (byId) return byId;
|
|
83
|
+
const named = boards.filter((b) => (b.label ?? "").trim().toLowerCase() === want.toLowerCase());
|
|
84
|
+
if (named.length === 1) return named[0];
|
|
85
|
+
if (named.length > 1) throw new RammeApiError(400, "AMBIGUOUS", `More than one board is called \u201C${said}\u201D: ${named.map((b) => b.deviceId).join(", ")}. Use its id.`);
|
|
86
|
+
const hint = DeviceIdSchema.safeParse(want.toUpperCase()).success ? "No board of yours has that id." : "No board of yours is called that.";
|
|
87
|
+
throw new RammeApiError(404, "NO_SUCH_BOARD", `${hint} Yours: ${boards.map((b) => `${b.label ?? "(unnamed)"} ${b.deviceId}`).join("; ") || "none"}.`);
|
|
88
|
+
};
|
|
89
|
+
var ago = (then, now = Date.now()) => {
|
|
90
|
+
if (!then) return "never";
|
|
91
|
+
const s = Math.max(0, Math.round((now - then) / 1e3));
|
|
92
|
+
if (s < 90) return "just now";
|
|
93
|
+
const m = Math.round(s / 60);
|
|
94
|
+
if (m < 90) return `${m} minutes ago`;
|
|
95
|
+
const h = Math.round(m / 60);
|
|
96
|
+
if (h < 36) return `${h} hours ago`;
|
|
97
|
+
return `${Math.round(h / 24)} days ago`;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/validate.ts
|
|
101
|
+
import { AppDocumentSchema } from "@ramme-io/shared";
|
|
102
|
+
var validateApp = (value) => {
|
|
103
|
+
const parsed = AppDocumentSchema.safeParse(value);
|
|
104
|
+
if (!parsed.success) {
|
|
105
|
+
return { ok: false, issues: parsed.error.issues.map((i) => `${i.path.length ? i.path.join(".") : "(the app)"}: ${i.message}`) };
|
|
106
|
+
}
|
|
107
|
+
return { ok: true, document: parsed.data, bytes: Buffer.byteLength(JSON.stringify(parsed.data)) };
|
|
108
|
+
};
|
|
109
|
+
var validateAppText = (text2) => {
|
|
110
|
+
let value;
|
|
111
|
+
try {
|
|
112
|
+
value = JSON.parse(text2);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
return { ok: false, issues: [`not JSON: ${e.message}`] };
|
|
115
|
+
}
|
|
116
|
+
return validateApp(value);
|
|
117
|
+
};
|
|
118
|
+
var describeValidation = (v) => v.ok ? `Valid: \u201C${v.document.name}\u201D (${v.document.blocks.length} block${v.document.blocks.length === 1 ? "" : "s"}, ${v.bytes} bytes).` : `Not valid:
|
|
119
|
+
${v.issues.map((i) => ` - ${i}`).join("\n")}`;
|
|
120
|
+
|
|
121
|
+
// src/mcp.ts
|
|
122
|
+
import { createInterface } from "readline";
|
|
123
|
+
import { APP_DOCUMENT_SYSTEM_PROMPT } from "@ramme-io/shared";
|
|
124
|
+
var SERVER_INFO = { name: "ramme", version: "0.1.0" };
|
|
125
|
+
var PROTOCOL_VERSION = "2025-06-18";
|
|
126
|
+
var INSTRUCTIONS = [
|
|
127
|
+
"Ramme boards are 2.8-inch touch screens that draw apps described as JSON documents \u2014 never code.",
|
|
128
|
+
"Call ramme_app_guide first: it is the format, with its limits.",
|
|
129
|
+
"Check every app with ramme_validate_app before sending it, and fix what it reports.",
|
|
130
|
+
"ramme_list_boards shows the boards this token can reach; ramme_board_parts shows what one has plugged in and what its sensors last read;",
|
|
131
|
+
"ramme_send_app sends an app to one, by id or by name.",
|
|
132
|
+
"A board picks up a new app at its next check-in: within about 30 seconds if someone is using it, 5 minutes if idle."
|
|
133
|
+
].join(" ");
|
|
134
|
+
var DOCUMENT = { type: "object", description: "The app document, as JSON \u2014 see ramme_app_guide." };
|
|
135
|
+
var TOOLS = [
|
|
136
|
+
{
|
|
137
|
+
name: "ramme_app_guide",
|
|
138
|
+
description: "How a Ramme app document is written: every block, source and limit. Read this before writing an app.",
|
|
139
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "ramme_validate_app",
|
|
143
|
+
description: 'Check an app document against the schema the boards and ramme.io use. Returns "Valid" or each problem with its path.',
|
|
144
|
+
inputSchema: { type: "object", properties: { document: DOCUMENT }, required: ["document"], additionalProperties: false }
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "ramme_list_boards",
|
|
148
|
+
description: "List the owner's boards: name, id, and when each last checked in. Needs a token that can see boards.",
|
|
149
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "ramme_board_parts",
|
|
153
|
+
description: "What one of the owner's boards has and is measuring: its parts (screen, speaker, a temperature probe\u2026) and whether each works, and each sensor's latest reading as a Signal with its id, value, unit and age. By the board's id or name. Needs a token that can see boards.",
|
|
154
|
+
inputSchema: {
|
|
155
|
+
type: "object",
|
|
156
|
+
properties: { board: { type: "string", description: "The board\u2019s id or its name." } },
|
|
157
|
+
required: ["board"],
|
|
158
|
+
additionalProperties: false
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "ramme_send_app",
|
|
163
|
+
description: "Send a validated app to one of the owner\u2019s boards, by its id (8 characters) or its name. Needs a token that can send apps.",
|
|
164
|
+
inputSchema: {
|
|
165
|
+
type: "object",
|
|
166
|
+
properties: { board: { type: "string", description: "The board\u2019s id or its name." }, document: DOCUMENT },
|
|
167
|
+
required: ["board", "document"],
|
|
168
|
+
additionalProperties: false
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
];
|
|
172
|
+
var describeParts = (name, parts, now = Date.now()) => {
|
|
173
|
+
const features = Object.entries(parts.features);
|
|
174
|
+
const lines = [name, ""];
|
|
175
|
+
lines.push(
|
|
176
|
+
features.length ? `Parts: ${features.map(([k, state]) => `${k} (${state})`).join(", ")}.` : "Parts: not reported yet. Boards say what they have from firmware 2026-10-25 on."
|
|
177
|
+
);
|
|
178
|
+
if (!parts.readings.length) {
|
|
179
|
+
lines.push("Readings: none. A sensor reports while it is plugged in, at the board\u2019s check-in rhythm.");
|
|
180
|
+
} else {
|
|
181
|
+
lines.push("Readings:");
|
|
182
|
+
for (const s of parts.readings) {
|
|
183
|
+
lines.push(`- ${s.key}: ${s.value}${s.unit ? ` ${s.unit}` : ""}, ${ago(s.timestamp, now)} (Signal ${s.id})`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return lines.join("\n");
|
|
187
|
+
};
|
|
188
|
+
var text = (t, isError = false) => ({ content: [{ type: "text", text: t }], ...isError ? { isError: true } : {} });
|
|
189
|
+
var callTool = async (client, name, args = {}) => {
|
|
190
|
+
try {
|
|
191
|
+
switch (name) {
|
|
192
|
+
case "ramme_app_guide":
|
|
193
|
+
return text(APP_DOCUMENT_SYSTEM_PROMPT.trim());
|
|
194
|
+
case "ramme_validate_app": {
|
|
195
|
+
const v = validateApp(args.document);
|
|
196
|
+
return text(describeValidation(v), !v.ok);
|
|
197
|
+
}
|
|
198
|
+
case "ramme_list_boards": {
|
|
199
|
+
const boards = await client.boards();
|
|
200
|
+
if (!boards.length) return text("No boards yet. On ramme.io, claim one from its screen; on your own server, point a board at it from its setup page.");
|
|
201
|
+
return text(boards.map((b) => `${b.label ?? "(unnamed)"} \u2014 ${b.deviceId} \u2014 checked in ${ago(b.lastPollAt ?? b.lastSeenAt)}`).join("\n"));
|
|
202
|
+
}
|
|
203
|
+
case "ramme_board_parts": {
|
|
204
|
+
const board = resolveBoard(await client.boards(), String(args.board ?? ""));
|
|
205
|
+
return text(describeParts(`${board.label ?? "(unnamed)"} \u2014 ${board.deviceId}`, await client.parts(board.deviceId)));
|
|
206
|
+
}
|
|
207
|
+
case "ramme_send_app": {
|
|
208
|
+
const v = validateApp(args.document);
|
|
209
|
+
if (!v.ok) return text(`Not sent. ${describeValidation(v)}`, true);
|
|
210
|
+
const board = resolveBoard(await client.boards(), String(args.board ?? ""));
|
|
211
|
+
const sent = await client.send(board.deviceId, v.document);
|
|
212
|
+
return text(
|
|
213
|
+
[`Sent \u201C${v.document.name}\u201D to ${board.label ?? board.deviceId} (${board.deviceId}), revision ${sent.revision ?? "?"}. It shows at the board\u2019s next check-in.`, sent.message].filter(Boolean).join(" ")
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
default:
|
|
217
|
+
return text(`No tool called ${name}.`, true);
|
|
218
|
+
}
|
|
219
|
+
} catch (e) {
|
|
220
|
+
const message = e instanceof RammeApiError ? `${e.message} (${e.code})` : `Could not reach the Ramme server (RAMME_API_URL): ${e.message}`;
|
|
221
|
+
return text(message, true);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var handleMessage = async (client, message) => {
|
|
225
|
+
const id = message.id;
|
|
226
|
+
const method = String(message.method ?? "");
|
|
227
|
+
const params = message.params ?? {};
|
|
228
|
+
const reply = (result) => ({ jsonrpc: "2.0", id, result });
|
|
229
|
+
if (id === void 0 || id === null) return null;
|
|
230
|
+
switch (method) {
|
|
231
|
+
case "initialize":
|
|
232
|
+
return reply({
|
|
233
|
+
protocolVersion: typeof params.protocolVersion === "string" ? params.protocolVersion : PROTOCOL_VERSION,
|
|
234
|
+
capabilities: { tools: {} },
|
|
235
|
+
serverInfo: SERVER_INFO,
|
|
236
|
+
instructions: INSTRUCTIONS
|
|
237
|
+
});
|
|
238
|
+
case "ping":
|
|
239
|
+
return reply({});
|
|
240
|
+
case "tools/list":
|
|
241
|
+
return reply({ tools: TOOLS });
|
|
242
|
+
case "tools/call":
|
|
243
|
+
return reply(await callTool(client, String(params.name ?? ""), params.arguments ?? {}));
|
|
244
|
+
default:
|
|
245
|
+
return { jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } };
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var serveMcp = async (client, input = process.stdin, output = process.stdout) => {
|
|
249
|
+
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
250
|
+
for await (const line of lines) {
|
|
251
|
+
if (!line.trim()) continue;
|
|
252
|
+
let message;
|
|
253
|
+
try {
|
|
254
|
+
message = JSON.parse(line);
|
|
255
|
+
} catch {
|
|
256
|
+
output.write(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } }) + "\n");
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const answer = await handleMessage(client, message);
|
|
260
|
+
if (answer) output.write(JSON.stringify(answer) + "\n");
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export {
|
|
265
|
+
DEFAULT_API,
|
|
266
|
+
credentialsPath,
|
|
267
|
+
apiBase,
|
|
268
|
+
findToken,
|
|
269
|
+
looksLikeToken,
|
|
270
|
+
serverLabel,
|
|
271
|
+
saveToken,
|
|
272
|
+
forgetToken,
|
|
273
|
+
RammeApiError,
|
|
274
|
+
createClient,
|
|
275
|
+
resolveBoard,
|
|
276
|
+
ago,
|
|
277
|
+
validateApp,
|
|
278
|
+
validateAppText,
|
|
279
|
+
describeValidation,
|
|
280
|
+
SERVER_INFO,
|
|
281
|
+
TOOLS,
|
|
282
|
+
callTool,
|
|
283
|
+
handleMessage,
|
|
284
|
+
serveMcp
|
|
285
|
+
};
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
RammeApiError,
|
|
4
|
+
SERVER_INFO,
|
|
5
|
+
ago,
|
|
6
|
+
apiBase,
|
|
7
|
+
createClient,
|
|
8
|
+
describeValidation,
|
|
9
|
+
findToken,
|
|
10
|
+
forgetToken,
|
|
11
|
+
looksLikeToken,
|
|
12
|
+
resolveBoard,
|
|
13
|
+
saveToken,
|
|
14
|
+
serveMcp,
|
|
15
|
+
serverLabel,
|
|
16
|
+
validateAppText
|
|
17
|
+
} from "./chunk-LEO24C5C.js";
|
|
18
|
+
|
|
19
|
+
// src/cli.ts
|
|
20
|
+
import { readFileSync, realpathSync } from "fs";
|
|
21
|
+
import { fileURLToPath } from "url";
|
|
22
|
+
import { createInterface } from "readline/promises";
|
|
23
|
+
import { APP_DOCUMENT_SYSTEM_PROMPT } from "@ramme-io/shared";
|
|
24
|
+
var USAGE = `ramme ${SERVER_INFO.version} \u2014 Ramme apps from your own machine
|
|
25
|
+
|
|
26
|
+
ramme guide how an app is written
|
|
27
|
+
ramme validate <app.json> check an app the way the boards do
|
|
28
|
+
ramme login [--token rmk_\u2026] save a token: ramme.io \u2192 Settings \u2192 Access tokens, or your own server's
|
|
29
|
+
ramme logout forget the saved token
|
|
30
|
+
ramme boards [--json] list your boards
|
|
31
|
+
ramme send <board> <app.json> send an app to a board, by its id or name
|
|
32
|
+
ramme mcp run as a local MCP server (stdio)
|
|
33
|
+
|
|
34
|
+
Token: RAMME_TOKEN, or the one \`ramme login\` saved. Server: RAMME_API_URL (default https://www.ramme.io, or your own).`;
|
|
35
|
+
var out = (s) => process.stdout.write(s + "\n");
|
|
36
|
+
var err = (s) => process.stderr.write(s + "\n");
|
|
37
|
+
var client = () => createClient({ base: apiBase(), token: findToken()?.token ?? null });
|
|
38
|
+
var readApp = (path) => {
|
|
39
|
+
if (!path) throw new RammeApiError(2, "USAGE", "Give the app file: ramme validate app.json");
|
|
40
|
+
return validateAppText(readFileSync(path === "-" ? 0 : path, "utf8"));
|
|
41
|
+
};
|
|
42
|
+
var main = async (argv) => {
|
|
43
|
+
const [command, ...rest] = argv;
|
|
44
|
+
const flag = (name) => {
|
|
45
|
+
const i = rest.indexOf(name);
|
|
46
|
+
return i >= 0 ? rest[i + 1] ?? "" : void 0;
|
|
47
|
+
};
|
|
48
|
+
const positional = rest.filter((a, i) => !a.startsWith("--") && !rest[i - 1]?.startsWith("--token"));
|
|
49
|
+
switch (command) {
|
|
50
|
+
case "guide":
|
|
51
|
+
out(APP_DOCUMENT_SYSTEM_PROMPT.trim());
|
|
52
|
+
return 0;
|
|
53
|
+
case "validate": {
|
|
54
|
+
const v = readApp(positional[0]);
|
|
55
|
+
(v.ok ? out : err)(describeValidation(v));
|
|
56
|
+
return v.ok ? 0 : 1;
|
|
57
|
+
}
|
|
58
|
+
case "login": {
|
|
59
|
+
let token = flag("--token");
|
|
60
|
+
if (!token) {
|
|
61
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
62
|
+
token = (await rl.question(`Paste a token for ${serverLabel(apiBase())}: `)).trim();
|
|
63
|
+
rl.close();
|
|
64
|
+
}
|
|
65
|
+
if (!looksLikeToken(token)) {
|
|
66
|
+
err("That does not look like a Ramme token: ramme.io\u2019s start with rmk_, a home server\u2019s with rmh_.");
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
const boards = await createClient({ base: apiBase(), token }).boards().catch((e) => e);
|
|
70
|
+
if (boards instanceof RammeApiError && boards.code !== "TOKEN_SCOPE") {
|
|
71
|
+
err(`${serverLabel(apiBase())} did not accept it: ${boards.message}`);
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
out(`Saved to ${saveToken(token)}${Array.isArray(boards) ? ` \u2014 it can see ${boards.length} board${boards.length === 1 ? "" : "s"}.` : "."}`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
case "logout":
|
|
78
|
+
out(forgetToken() ? "Forgotten." : "No saved token.");
|
|
79
|
+
return 0;
|
|
80
|
+
case "boards": {
|
|
81
|
+
const boards = await client().boards();
|
|
82
|
+
if (rest.includes("--json")) out(JSON.stringify(boards, null, 2));
|
|
83
|
+
else if (!boards.length) out(`No boards on ${serverLabel(apiBase())} yet.`);
|
|
84
|
+
else for (const b of boards) out(`${(b.label ?? "(unnamed)").padEnd(24)} ${b.deviceId} checked in ${ago(b.lastPollAt ?? b.lastSeenAt)}`);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
case "send": {
|
|
88
|
+
const [said, file] = positional;
|
|
89
|
+
if (!said || !file) {
|
|
90
|
+
err("ramme send <board> <app.json>");
|
|
91
|
+
return 2;
|
|
92
|
+
}
|
|
93
|
+
const v = readApp(file);
|
|
94
|
+
if (!v.ok) {
|
|
95
|
+
err(`Not sent. ${describeValidation(v)}`);
|
|
96
|
+
return 1;
|
|
97
|
+
}
|
|
98
|
+
const c = client();
|
|
99
|
+
const board = resolveBoard(await c.boards(), said);
|
|
100
|
+
const sent = await c.send(board.deviceId, v.document);
|
|
101
|
+
out(`Sent \u201C${v.document.name}\u201D to ${board.label ?? board.deviceId} (${board.deviceId}), revision ${sent.revision ?? "?"}.`);
|
|
102
|
+
if (sent.message) err(sent.message);
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
case "mcp":
|
|
106
|
+
await serveMcp(client());
|
|
107
|
+
return 0;
|
|
108
|
+
case void 0:
|
|
109
|
+
case "help":
|
|
110
|
+
case "--help":
|
|
111
|
+
case "-h":
|
|
112
|
+
out(USAGE);
|
|
113
|
+
return 0;
|
|
114
|
+
case "--version":
|
|
115
|
+
case "-v":
|
|
116
|
+
out(SERVER_INFO.version);
|
|
117
|
+
return 0;
|
|
118
|
+
default:
|
|
119
|
+
err(`Unknown command: ${command}
|
|
120
|
+
|
|
121
|
+
${USAGE}`);
|
|
122
|
+
return 2;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var invokedDirectly = () => {
|
|
126
|
+
try {
|
|
127
|
+
return !!process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if (invokedDirectly()) {
|
|
133
|
+
main(process.argv.slice(2)).then(
|
|
134
|
+
(code) => process.exit(code),
|
|
135
|
+
(e) => {
|
|
136
|
+
err(e instanceof RammeApiError ? e.message : `Could not reach ${serverLabel(apiBase())}: ${e.message}`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
main
|
|
143
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { AppDocument, DeviceFeatureState, Signal } from '@ramme-io/shared';
|
|
2
|
+
import { Readable, Writable } from 'node:stream';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Is this an app a board can draw? The same check the send route makes
|
|
6
|
+
* (AppDocumentSchema in @ramme-io/shared), run before anything leaves the
|
|
7
|
+
* machine, so an agent finds its mistakes in a second rather than a round
|
|
8
|
+
* trip — and the server still checks again, because it never trusts this.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type Validation = {
|
|
12
|
+
ok: true;
|
|
13
|
+
document: AppDocument;
|
|
14
|
+
bytes: number;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
issues: string[];
|
|
18
|
+
};
|
|
19
|
+
/** Validate a parsed value. */
|
|
20
|
+
declare const validateApp: (value: unknown) => Validation;
|
|
21
|
+
/** Validate JSON text, saying so plainly when it is not JSON at all. */
|
|
22
|
+
declare const validateAppText: (text: string) => Validation;
|
|
23
|
+
/** One line or a list, for a person or an agent to read. */
|
|
24
|
+
declare const describeValidation: (v: Validation) => string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The few ramme.io routes a personal access token can reach: list your
|
|
28
|
+
* boards and read one's parts and readings (`boards:read`), and send one an
|
|
29
|
+
* app (`boards:send`). Everything is
|
|
30
|
+
* authorised by the token; nothing here calls a model, so an agent's own keys
|
|
31
|
+
* do all the generating.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface Board {
|
|
35
|
+
deviceId: string;
|
|
36
|
+
label?: string;
|
|
37
|
+
lastSeenAt: number;
|
|
38
|
+
lastPollAt?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* What a board has and what it last measured: its parts, each with whether it
|
|
42
|
+
* works, and its sensors' latest readings as Signals (`<deviceId>:<key>`).
|
|
43
|
+
* Both come from the board itself (lib/routes/deviceVitals.ts).
|
|
44
|
+
*/
|
|
45
|
+
interface BoardParts {
|
|
46
|
+
features: Record<string, DeviceFeatureState>;
|
|
47
|
+
readings: Signal[];
|
|
48
|
+
}
|
|
49
|
+
/** What a send answers: the revision the board will draw, and a warning when there is one to pass on. */
|
|
50
|
+
interface SendResult {
|
|
51
|
+
revision?: number;
|
|
52
|
+
warning?: string;
|
|
53
|
+
message?: string;
|
|
54
|
+
}
|
|
55
|
+
declare class RammeApiError extends Error {
|
|
56
|
+
readonly status: number;
|
|
57
|
+
readonly code: string;
|
|
58
|
+
constructor(status: number, code: string, message: string);
|
|
59
|
+
}
|
|
60
|
+
interface Client {
|
|
61
|
+
boards(): Promise<Board[]>;
|
|
62
|
+
parts(deviceId: string): Promise<BoardParts>;
|
|
63
|
+
send(deviceId: string, document: AppDocument): Promise<SendResult>;
|
|
64
|
+
}
|
|
65
|
+
declare const createClient: (options: {
|
|
66
|
+
base: string;
|
|
67
|
+
token: string | null;
|
|
68
|
+
fetch?: typeof fetch;
|
|
69
|
+
}) => Client;
|
|
70
|
+
/**
|
|
71
|
+
* A board by its id or its name, as a person or an agent would say it:
|
|
72
|
+
* "A7K2M9QP", or "Kitchen shelf" in any case. Refuses an ambiguous name
|
|
73
|
+
* rather than guessing which board it meant.
|
|
74
|
+
*/
|
|
75
|
+
declare const resolveBoard: (boards: Board[], said: string) => Board;
|
|
76
|
+
|
|
77
|
+
declare const DEFAULT_API = "https://www.ramme.io";
|
|
78
|
+
declare const credentialsPath: (env?: NodeJS.ProcessEnv) => string;
|
|
79
|
+
declare const apiBase: (env?: NodeJS.ProcessEnv) => string;
|
|
80
|
+
/** The token to use, and where it came from; null when there is none. */
|
|
81
|
+
declare const findToken: (env?: NodeJS.ProcessEnv) => {
|
|
82
|
+
token: string;
|
|
83
|
+
from: "env" | "file";
|
|
84
|
+
} | null;
|
|
85
|
+
/** Save a token for this user only. */
|
|
86
|
+
declare const saveToken: (token: string, env?: NodeJS.ProcessEnv) => string;
|
|
87
|
+
declare const forgetToken: (env?: NodeJS.ProcessEnv) => boolean;
|
|
88
|
+
|
|
89
|
+
declare const SERVER_INFO: {
|
|
90
|
+
name: string;
|
|
91
|
+
version: string;
|
|
92
|
+
};
|
|
93
|
+
type Json = Record<string, unknown>;
|
|
94
|
+
declare const TOOLS: readonly [{
|
|
95
|
+
readonly name: "ramme_app_guide";
|
|
96
|
+
readonly description: "How a Ramme app document is written: every block, source and limit. Read this before writing an app.";
|
|
97
|
+
readonly inputSchema: {
|
|
98
|
+
readonly type: "object";
|
|
99
|
+
readonly properties: {};
|
|
100
|
+
readonly additionalProperties: false;
|
|
101
|
+
};
|
|
102
|
+
}, {
|
|
103
|
+
readonly name: "ramme_validate_app";
|
|
104
|
+
readonly description: "Check an app document against the schema the boards and ramme.io use. Returns \"Valid\" or each problem with its path.";
|
|
105
|
+
readonly inputSchema: {
|
|
106
|
+
readonly type: "object";
|
|
107
|
+
readonly properties: {
|
|
108
|
+
readonly document: {
|
|
109
|
+
type: string;
|
|
110
|
+
description: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
readonly required: readonly ["document"];
|
|
114
|
+
readonly additionalProperties: false;
|
|
115
|
+
};
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "ramme_list_boards";
|
|
118
|
+
readonly description: "List the owner's boards: name, id, and when each last checked in. Needs a token that can see boards.";
|
|
119
|
+
readonly inputSchema: {
|
|
120
|
+
readonly type: "object";
|
|
121
|
+
readonly properties: {};
|
|
122
|
+
readonly additionalProperties: false;
|
|
123
|
+
};
|
|
124
|
+
}, {
|
|
125
|
+
readonly name: "ramme_board_parts";
|
|
126
|
+
readonly description: "What one of the owner's boards has and is measuring: its parts (screen, speaker, a temperature probe…) and whether each works, and each sensor's latest reading as a Signal with its id, value, unit and age. By the board's id or name. Needs a token that can see boards.";
|
|
127
|
+
readonly inputSchema: {
|
|
128
|
+
readonly type: "object";
|
|
129
|
+
readonly properties: {
|
|
130
|
+
readonly board: {
|
|
131
|
+
readonly type: "string";
|
|
132
|
+
readonly description: "The board’s id or its name.";
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
readonly required: readonly ["board"];
|
|
136
|
+
readonly additionalProperties: false;
|
|
137
|
+
};
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "ramme_send_app";
|
|
140
|
+
readonly description: "Send a validated app to one of the owner’s boards, by its id (8 characters) or its name. Needs a token that can send apps.";
|
|
141
|
+
readonly inputSchema: {
|
|
142
|
+
readonly type: "object";
|
|
143
|
+
readonly properties: {
|
|
144
|
+
readonly board: {
|
|
145
|
+
readonly type: "string";
|
|
146
|
+
readonly description: "The board’s id or its name.";
|
|
147
|
+
};
|
|
148
|
+
readonly document: {
|
|
149
|
+
type: string;
|
|
150
|
+
description: string;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
readonly required: readonly ["board", "document"];
|
|
154
|
+
readonly additionalProperties: false;
|
|
155
|
+
};
|
|
156
|
+
}];
|
|
157
|
+
/** Run one tool. Every failure is a result the agent can read, never a thrown protocol error. */
|
|
158
|
+
declare const callTool: (client: Client, name: string, args?: Json) => Promise<Json>;
|
|
159
|
+
/** Answer one JSON-RPC message; null for a notification, which gets no answer. */
|
|
160
|
+
declare const handleMessage: (client: Client, message: Json) => Promise<Json | null>;
|
|
161
|
+
/** Serve until stdin closes. */
|
|
162
|
+
declare const serveMcp: (client: Client, input?: Readable, output?: Writable) => Promise<void>;
|
|
163
|
+
|
|
164
|
+
export { type Board, type Client, DEFAULT_API, RammeApiError, SERVER_INFO, type SendResult, TOOLS, type Validation, apiBase, callTool, createClient, credentialsPath, describeValidation, findToken, forgetToken, handleMessage, resolveBoard, saveToken, serveMcp, validateApp, validateAppText };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_API,
|
|
3
|
+
RammeApiError,
|
|
4
|
+
SERVER_INFO,
|
|
5
|
+
TOOLS,
|
|
6
|
+
apiBase,
|
|
7
|
+
callTool,
|
|
8
|
+
createClient,
|
|
9
|
+
credentialsPath,
|
|
10
|
+
describeValidation,
|
|
11
|
+
findToken,
|
|
12
|
+
forgetToken,
|
|
13
|
+
handleMessage,
|
|
14
|
+
resolveBoard,
|
|
15
|
+
saveToken,
|
|
16
|
+
serveMcp,
|
|
17
|
+
validateApp,
|
|
18
|
+
validateAppText
|
|
19
|
+
} from "./chunk-LEO24C5C.js";
|
|
20
|
+
export {
|
|
21
|
+
DEFAULT_API,
|
|
22
|
+
RammeApiError,
|
|
23
|
+
SERVER_INFO,
|
|
24
|
+
TOOLS,
|
|
25
|
+
apiBase,
|
|
26
|
+
callTool,
|
|
27
|
+
createClient,
|
|
28
|
+
credentialsPath,
|
|
29
|
+
describeValidation,
|
|
30
|
+
findToken,
|
|
31
|
+
forgetToken,
|
|
32
|
+
handleMessage,
|
|
33
|
+
resolveBoard,
|
|
34
|
+
saveToken,
|
|
35
|
+
serveMcp,
|
|
36
|
+
validateApp,
|
|
37
|
+
validateAppText
|
|
38
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramme-io/devkit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Make Ramme apps on your own machine with your own coding agent: validate an app, list your boards, send it to one — as a CLI or a local MCP server.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"ramme": "./dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@ramme-io/shared": "4.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.14.10",
|
|
28
|
+
"tsup": "^8.5.1",
|
|
29
|
+
"tsx": "4.21.0",
|
|
30
|
+
"typescript": "^5.4.5",
|
|
31
|
+
"vitest": "^2.1.9"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup src/cli.ts src/index.ts --format esm --dts --clean --target node20",
|
|
35
|
+
"ramme": "tsx src/cli.ts",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
38
|
+
}
|
|
6
39
|
}
|