@minecraftbot-com/plugin 0.0.0-stage → 0.1.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 (128) hide show
  1. package/AGENTS.md +177 -0
  2. package/README.md +45 -2
  3. package/dist/api.d.ts +351 -0
  4. package/dist/api.js +2 -0
  5. package/dist/cli/api.d.ts +26 -0
  6. package/dist/cli/api.js +61 -0
  7. package/dist/cli/build.d.ts +23 -0
  8. package/dist/cli/build.js +65 -0
  9. package/dist/cli/check.d.ts +10 -0
  10. package/dist/cli/check.js +98 -0
  11. package/dist/cli/config.d.ts +11 -0
  12. package/dist/cli/config.js +38 -0
  13. package/dist/cli/create.d.ts +2 -0
  14. package/dist/cli/create.js +39 -0
  15. package/dist/cli/dev-mcp.d.ts +36 -0
  16. package/dist/cli/dev-mcp.js +101 -0
  17. package/dist/cli/dev.d.ts +15 -0
  18. package/dist/cli/dev.js +261 -0
  19. package/dist/cli/fetch-guard.d.ts +7 -0
  20. package/dist/cli/fetch-guard.js +66 -0
  21. package/dist/cli/main.d.ts +2 -0
  22. package/dist/cli/main.js +112 -0
  23. package/dist/cli/mcp.d.ts +24 -0
  24. package/dist/cli/mcp.js +136 -0
  25. package/dist/cli/output.d.ts +11 -0
  26. package/dist/cli/output.js +25 -0
  27. package/dist/cli/test.d.ts +2 -0
  28. package/dist/cli/test.js +39 -0
  29. package/dist/errors.d.ts +22 -0
  30. package/dist/errors.js +35 -0
  31. package/dist/generated/block-states.d.ts +4087 -0
  32. package/dist/generated/block-states.js +2 -0
  33. package/dist/generated/blocks.d.ts +1289 -0
  34. package/dist/generated/blocks.js +1291 -0
  35. package/dist/generated/contracts.d.ts +304 -0
  36. package/dist/generated/contracts.js +327 -0
  37. package/dist/generated/effects.d.ts +43 -0
  38. package/dist/generated/effects.js +45 -0
  39. package/dist/generated/entities.d.ts +164 -0
  40. package/dist/generated/entities.js +166 -0
  41. package/dist/generated/items.d.ts +1661 -0
  42. package/dist/generated/items.js +1663 -0
  43. package/dist/generated/operations.d.ts +7 -0
  44. package/dist/generated/operations.js +65 -0
  45. package/dist/generated/permission-labels.d.ts +3 -0
  46. package/dist/generated/permission-labels.js +17 -0
  47. package/dist/generated/version.d.ts +2 -0
  48. package/dist/generated/version.js +3 -0
  49. package/dist/host/index.d.ts +7 -0
  50. package/dist/host/index.js +5 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +13 -0
  53. package/dist/permissions.d.ts +11 -0
  54. package/dist/permissions.js +18 -0
  55. package/dist/plugin.d.ts +86 -0
  56. package/dist/plugin.js +26 -0
  57. package/dist/protocol.d.ts +167 -0
  58. package/dist/protocol.js +4 -0
  59. package/dist/runtime/connection.d.ts +52 -0
  60. package/dist/runtime/connection.js +132 -0
  61. package/dist/runtime/handles.d.ts +95 -0
  62. package/dist/runtime/handles.js +289 -0
  63. package/dist/runtime/memory-transport.d.ts +6 -0
  64. package/dist/runtime/memory-transport.js +39 -0
  65. package/dist/runtime/runtime.d.ts +57 -0
  66. package/dist/runtime/runtime.js +265 -0
  67. package/dist/runtime/scope.d.ts +25 -0
  68. package/dist/runtime/scope.js +94 -0
  69. package/dist/runtime/storage-runtime.d.ts +10 -0
  70. package/dist/runtime/storage-runtime.js +131 -0
  71. package/dist/settings.d.ts +111 -0
  72. package/dist/settings.js +78 -0
  73. package/dist/storage.d.ts +78 -0
  74. package/dist/storage.js +24 -0
  75. package/dist/testing/fake-container.d.ts +175 -0
  76. package/dist/testing/fake-container.js +483 -0
  77. package/dist/testing/index.d.ts +37 -0
  78. package/dist/testing/index.js +54 -0
  79. package/dist/types.d.ts +65 -0
  80. package/dist/types.js +54 -0
  81. package/llms.txt +11 -0
  82. package/package.json +55 -4
  83. package/src/api.ts +334 -0
  84. package/src/cli/api.ts +79 -0
  85. package/src/cli/build.ts +76 -0
  86. package/src/cli/check.ts +103 -0
  87. package/src/cli/config.ts +48 -0
  88. package/src/cli/create.ts +38 -0
  89. package/src/cli/dev-mcp.ts +131 -0
  90. package/src/cli/dev.ts +272 -0
  91. package/src/cli/fetch-guard.ts +61 -0
  92. package/src/cli/main.ts +113 -0
  93. package/src/cli/mcp.ts +168 -0
  94. package/src/cli/output.ts +30 -0
  95. package/src/cli/test.ts +38 -0
  96. package/src/errors.ts +34 -0
  97. package/src/generated/block-states.ts +892 -0
  98. package/src/generated/blocks.ts +1291 -0
  99. package/src/generated/contracts.ts +329 -0
  100. package/src/generated/effects.ts +45 -0
  101. package/src/generated/entities.ts +166 -0
  102. package/src/generated/items.ts +1663 -0
  103. package/src/generated/operations.ts +69 -0
  104. package/src/generated/permission-labels.ts +19 -0
  105. package/src/generated/version.ts +3 -0
  106. package/src/host/index.ts +9 -0
  107. package/src/index.ts +34 -0
  108. package/src/permissions.ts +23 -0
  109. package/src/plugin.ts +105 -0
  110. package/src/protocol.ts +107 -0
  111. package/src/runtime/connection.ts +167 -0
  112. package/src/runtime/handles.ts +337 -0
  113. package/src/runtime/memory-transport.ts +41 -0
  114. package/src/runtime/runtime.ts +281 -0
  115. package/src/runtime/scope.ts +101 -0
  116. package/src/runtime/storage-runtime.ts +138 -0
  117. package/src/settings.ts +118 -0
  118. package/src/storage.ts +82 -0
  119. package/src/testing/fake-container.ts +571 -0
  120. package/src/testing/index.ts +70 -0
  121. package/src/types.ts +88 -0
  122. package/templates/basic/AGENTS.md +31 -0
  123. package/templates/basic/README.md +13 -0
  124. package/templates/basic/gitignore +3 -0
  125. package/templates/basic/package.json +18 -0
  126. package/templates/basic/src/index.ts +20 -0
  127. package/templates/basic/test/plugin.test.ts +14 -0
  128. package/templates/basic/tsconfig.json +14 -0
@@ -0,0 +1,23 @@
1
+ import * as esbuild from "esbuild";
2
+ import { type DefinedPlugin } from "../plugin.js";
3
+ export interface Project {
4
+ root: string;
5
+ entry: string;
6
+ name: string;
7
+ version: string;
8
+ }
9
+ /** The plugin project in the current folder: a package.json and src/index.ts (or the `minebot.entry` it names). */
10
+ export declare function findProject(root?: string): Project;
11
+ /**
12
+ * The bundle `minebot dev` runs in Node: the SDK stays an import so the plugin and the CLI share one copy of it
13
+ * (errors thrown by the SDK are the classes the plugin imports).
14
+ */
15
+ export declare function devBuildOptions(project: Project, outfile: string): esbuild.BuildOptions;
16
+ /**
17
+ * The bundle a hosted runner runs: everything included, minified, and the SDK compiled from its TypeScript
18
+ * source (the `minebot-source` condition) so enum members become plain strings and the enum objects drop out.
19
+ */
20
+ export declare function hostedBuildOptions(project: Project, outfile: string): esbuild.BuildOptions;
21
+ export declare function formatErrors(errors: esbuild.Message[]): string;
22
+ /** Imports a built plugin module and returns its default export, which must be `definePlugin(...)`. */
23
+ export declare function loadPlugin(file: string, cacheBust?: number | string): Promise<DefinedPlugin>;
@@ -0,0 +1,65 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { isDefinedPlugin } from "../plugin.js";
5
+ import { fail } from "./output.js";
6
+ /** The plugin project in the current folder: a package.json and src/index.ts (or the `minebot.entry` it names). */
7
+ export function findProject(root = process.cwd()) {
8
+ const packageFile = join(root, "package.json");
9
+ if (!existsSync(packageFile))
10
+ fail("No package.json here.", "Run minebot in your plugin's folder, or create one with `npx @minecraftbot-com/plugin create my-plugin`.");
11
+ const pkg = JSON.parse(readFileSync(packageFile, "utf8"));
12
+ const entry = resolve(root, pkg.minebot?.entry ?? "src/index.ts");
13
+ if (!existsSync(entry))
14
+ fail(`No ${entry}.`, "Your plugin's code goes in src/index.ts, with `export default definePlugin({ ... })`.");
15
+ return { root, entry, name: pkg.name ?? "plugin", version: pkg.version ?? "0.0.0" };
16
+ }
17
+ /**
18
+ * The bundle `minebot dev` runs in Node: the SDK stays an import so the plugin and the CLI share one copy of it
19
+ * (errors thrown by the SDK are the classes the plugin imports).
20
+ */
21
+ export function devBuildOptions(project, outfile) {
22
+ return {
23
+ entryPoints: [project.entry],
24
+ outfile,
25
+ bundle: true,
26
+ format: "esm",
27
+ platform: "node",
28
+ target: "node22",
29
+ sourcemap: "inline",
30
+ external: ["@minecraftbot-com/plugin", "@minecraftbot-com/plugin/*"],
31
+ logLevel: "silent",
32
+ };
33
+ }
34
+ /**
35
+ * The bundle a hosted runner runs: everything included, minified, and the SDK compiled from its TypeScript
36
+ * source (the `minebot-source` condition) so enum members become plain strings and the enum objects drop out.
37
+ */
38
+ export function hostedBuildOptions(project, outfile) {
39
+ return {
40
+ entryPoints: [project.entry],
41
+ outfile,
42
+ bundle: true,
43
+ format: "esm",
44
+ platform: "neutral",
45
+ target: "es2022",
46
+ minify: true,
47
+ treeShaking: true,
48
+ conditions: ["minebot-source"],
49
+ mainFields: ["module", "main"],
50
+ legalComments: "none",
51
+ metafile: true,
52
+ logLevel: "silent",
53
+ };
54
+ }
55
+ export function formatErrors(errors) {
56
+ return errors.map(e => (e.location ? `${e.location.file}:${e.location.line}:${e.location.column}: ${e.text}` : e.text)).join("\n");
57
+ }
58
+ /** Imports a built plugin module and returns its default export, which must be `definePlugin(...)`. */
59
+ export async function loadPlugin(file, cacheBust = Date.now()) {
60
+ const module = await import(`${pathToFileURL(file).href}?v=${cacheBust}`);
61
+ if (!isDefinedPlugin(module.default)) {
62
+ fail("The plugin's entry file has no plugin as its default export.", "End src/index.ts with `export default definePlugin({ name: ..., permissions: [...], async run(bot) { ... } })`.");
63
+ }
64
+ return module.default;
65
+ }
@@ -0,0 +1,10 @@
1
+ import type { Manifest } from "../protocol.js";
2
+ /** Problems with a manifest: each is a sentence a person (or an AI) can act on. */
3
+ export declare function review(manifest: Manifest, bytes: number): {
4
+ problems: string[];
5
+ notes: string[];
6
+ };
7
+ /** `minebot check`: builds the plugin as it would be uploaded and reports what users will be asked to allow. */
8
+ export declare function check(): Promise<void>;
9
+ /** `minebot build`: writes dist/plugin.js (the hosted bundle) and dist/manifest.json, for upload. */
10
+ export declare function build(): Promise<void>;
@@ -0,0 +1,98 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import * as esbuild from "esbuild";
4
+ import { PERMISSION_LABELS } from "../generated/permission-labels.js";
5
+ import { networkHost } from "../permissions.js";
6
+ import { buildManifest } from "../runtime/runtime.js";
7
+ import { devBuildOptions, findProject, formatErrors, hostedBuildOptions, loadPlugin } from "./build.js";
8
+ import { bold, dim, fail, green, info, warn, yellow } from "./output.js";
9
+ /** Above this a hosted plugin probably won't fit its memory after start (about 1.5 MB, mostly bundled code). */
10
+ const BUNDLE_WARNING_BYTES = 256 * 1024;
11
+ async function buildAll(outDir) {
12
+ const project = findProject();
13
+ mkdirSync(outDir, { recursive: true });
14
+ // The manifest comes from running the plugin's module in Node; that build stays out of the output folder.
15
+ mkdirSync(join(project.root, ".minebot"), { recursive: true });
16
+ const devFile = join(project.root, ".minebot", "probe.mjs");
17
+ try {
18
+ await esbuild.build(devBuildOptions(project, devFile));
19
+ }
20
+ catch (e) {
21
+ fail(`Build failed:\n${formatErrors(e.errors ?? [])}`);
22
+ }
23
+ const plugin = await loadPlugin(devFile);
24
+ const manifest = buildManifest(plugin, project.version);
25
+ const bundle = join(outDir, "plugin.js");
26
+ let result;
27
+ try {
28
+ result = await esbuild.build(hostedBuildOptions(project, bundle));
29
+ }
30
+ catch (e) {
31
+ fail(`Hosted build failed:\n${formatErrors(e.errors ?? [])}`);
32
+ }
33
+ const bytes = Object.values(result.metafile.outputs).reduce((n, o) => n + o.bytes, 0);
34
+ return { manifest, bundle, bytes };
35
+ }
36
+ /** Problems with a manifest: each is a sentence a person (or an AI) can act on. */
37
+ export function review(manifest, bytes) {
38
+ const problems = [];
39
+ const notes = [];
40
+ const permissions = new Set(manifest.permissions);
41
+ const hosts = manifest.permissions.map(networkHost).filter((h) => h !== null);
42
+ const urlSettings = Object.entries(manifest.settings).filter(([, s]) => s.type === "url");
43
+ if (manifest.name.length > 64)
44
+ problems.push("The name is longer than 64 characters.");
45
+ if (hosts.some(h => h === "*" || h.startsWith("*.") && h.split(".").length < 3))
46
+ problems.push("A network permission covers too much; name the hosts you call.");
47
+ if (permissions.has("ChatRead") && (hosts.length > 0 || urlSettings.length > 0)) {
48
+ notes.push(`Users will be told this plugin "can read chat and send it to ${[...hosts, ...urlSettings.map(([k]) => `the URL in "${k}"`)].join(", ")}".`);
49
+ }
50
+ if (permissions.has("ProfileBots"))
51
+ notes.push("ProfileBots lets the plugin connect and disconnect every bot of the profile; users see that at install.");
52
+ if (manifest.exclusive.length === 0 && (permissions.has("Move") || permissions.has("Interact"))) {
53
+ notes.push("The plugin moves or digs but declares no exclusive control units; another plugin may drive the same bot at once. Add exclusive: [ControlUnit.Movement, ...].");
54
+ }
55
+ if (bytes > BUNDLE_WARNING_BYTES) {
56
+ problems.push(`The hosted bundle is ${(bytes / 1024).toFixed(0)} KB; hosted plugins have about 1.5 MB after start, and bundled libraries are the usual cause. Import only what you use.`);
57
+ }
58
+ return { problems, notes };
59
+ }
60
+ /** `minebot check`: builds the plugin as it would be uploaded and reports what users will be asked to allow. */
61
+ export async function check() {
62
+ const project = findProject();
63
+ const { manifest, bytes } = await buildAll(join(project.root, ".minebot", "check"));
64
+ info(`${bold(manifest.name)} ${dim(manifest.version)}`);
65
+ info("\nUsers will be asked to allow:");
66
+ if (manifest.permissions.length === 0)
67
+ info(dim(" nothing (logs, settings, storage and timers are always allowed)"));
68
+ for (const p of manifest.permissions) {
69
+ const host = networkHost(p);
70
+ info(` • ${host ? `Can send and receive data from ${host}` : PERMISSION_LABELS[p] ?? p}`);
71
+ }
72
+ const settings = Object.entries(manifest.settings);
73
+ if (settings.length)
74
+ info(`\nSettings: ${settings.map(([k, s]) => `${k} (${s.type}${s.secret ? ", secret" : ""})`).join(", ")}`);
75
+ const storage = Object.entries(manifest.storage);
76
+ if (storage.length)
77
+ info(`Storage: ${storage.map(([k, s]) => `${k} (${s.kind}, ${s.scope})`).join(", ")}`);
78
+ info(`Hosted bundle: ${(bytes / 1024).toFixed(1)} KB`);
79
+ const { problems, notes } = review(manifest, bytes);
80
+ for (const n of notes)
81
+ info(`\n${yellow("note:")} ${n}`);
82
+ for (const p of problems)
83
+ warn(p);
84
+ if (problems.length)
85
+ process.exit(1);
86
+ info(`\n${green("ok")}`);
87
+ }
88
+ /** `minebot build`: writes dist/plugin.js (the hosted bundle) and dist/manifest.json, for upload. */
89
+ export async function build() {
90
+ const project = findProject();
91
+ const outDir = join(project.root, "dist");
92
+ const { manifest, bytes } = await buildAll(outDir);
93
+ writeFileSync(join(outDir, "manifest.json"), JSON.stringify(manifest, null, 2));
94
+ const { problems } = review(manifest, bytes);
95
+ for (const p of problems)
96
+ warn(p);
97
+ info(`Wrote dist/plugin.js (${(bytes / 1024).toFixed(1)} KB) and dist/manifest.json`);
98
+ }
@@ -0,0 +1,11 @@
1
+ /** The public API. `MINEBOT_API_URL` overrides it (for MineBot's own staging and local development). */
2
+ export declare const DEFAULT_API_URL = "https://api-v3.minecraftbot.com";
3
+ export interface Credentials {
4
+ apiUrl: string;
5
+ token: string;
6
+ }
7
+ export declare function apiUrl(): string;
8
+ export declare function readCredentials(): Credentials | null;
9
+ /** Saved readable by the user only: the token lets anyone ask dev tokens for the user's profiles. */
10
+ export declare function saveCredentials(credentials: Credentials): string;
11
+ export declare function deleteCredentials(): void;
@@ -0,0 +1,38 @@
1
+ import { mkdirSync, readFileSync, rmSync, writeFileSync, chmodSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ /** The public API. `MINEBOT_API_URL` overrides it (for MineBot's own staging and local development). */
5
+ export const DEFAULT_API_URL = "https://api-v3.minecraftbot.com";
6
+ function folder() {
7
+ return process.env.MINEBOT_CONFIG_DIR ?? join(homedir(), ".minebot");
8
+ }
9
+ function file() {
10
+ return join(folder(), "credentials.json");
11
+ }
12
+ export function apiUrl() {
13
+ return (process.env.MINEBOT_API_URL ?? readCredentials()?.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, "");
14
+ }
15
+ export function readCredentials() {
16
+ try {
17
+ const parsed = JSON.parse(readFileSync(file(), "utf8"));
18
+ return typeof parsed.token === "string" ? parsed : null;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ /** Saved readable by the user only: the token lets anyone ask dev tokens for the user's profiles. */
25
+ export function saveCredentials(credentials) {
26
+ mkdirSync(folder(), { recursive: true, mode: 0o700 });
27
+ writeFileSync(file(), JSON.stringify(credentials, null, 2), { mode: 0o600 });
28
+ try {
29
+ chmodSync(file(), 0o600);
30
+ }
31
+ catch {
32
+ // Windows has no POSIX modes; the file is in the user's profile folder.
33
+ }
34
+ return file();
35
+ }
36
+ export function deleteCredentials() {
37
+ rmSync(file(), { force: true });
38
+ }
@@ -0,0 +1,2 @@
1
+ /** `minebot create <folder>`: a new plugin project from the template. */
2
+ export declare function create(target: string | undefined, template?: string): void;
@@ -0,0 +1,39 @@
1
+ import { cpSync, existsSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
2
+ import { basename, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { SDK_VERSION } from "../runtime/runtime.js";
5
+ import { bold, dim, fail, green, info } from "./output.js";
6
+ const TEMPLATES = fileURLToPath(new URL("../../templates/", import.meta.url));
7
+ /** `minebot create <folder>`: a new plugin project from the template. */
8
+ export function create(target, template = "basic") {
9
+ if (!target)
10
+ fail("Name the folder: `minebot create my-plugin`.");
11
+ const folder = resolve(target);
12
+ if (existsSync(folder) && readdirSync(folder).length > 0)
13
+ fail(`${folder} isn't empty.`);
14
+ const source = join(TEMPLATES, template);
15
+ if (!existsSync(source))
16
+ fail(`No template "${template}".`, `Templates: ${readdirSync(TEMPLATES).join(", ")}`);
17
+ const name = basename(folder).toLowerCase().replace(/[^a-z0-9-_.]/g, "-");
18
+ const title = basename(folder).replace(/[-_]+/g, " ").replace(/\b\w/g, c => c.toUpperCase());
19
+ cpSync(source, folder, { recursive: true });
20
+ // npm drops files named .gitignore from published packages, so the template carries it without the dot.
21
+ if (existsSync(join(folder, "gitignore")))
22
+ renameSync(join(folder, "gitignore"), join(folder, ".gitignore"));
23
+ const fill = (dir) => {
24
+ for (const entry of readdirSync(dir)) {
25
+ const path = join(dir, entry);
26
+ if (statSync(path).isDirectory())
27
+ fill(path);
28
+ else
29
+ writeFileSync(path, readFileSync(path, "utf8").replaceAll("__NAME__", name).replaceAll("__TITLE__", title).replaceAll("__SDK_VERSION__", SDK_VERSION));
30
+ }
31
+ };
32
+ fill(folder);
33
+ info(`${green("Created")} ${bold(folder)}\n`);
34
+ info(` cd ${target}`);
35
+ info(" npm install");
36
+ info(" npx minebot login");
37
+ info(" npm run dev\n");
38
+ info(dim("src/index.ts is the plugin; AGENTS.md explains the API to AI assistants."));
39
+ }
@@ -0,0 +1,36 @@
1
+ import type { McpTool } from "./mcp.js";
2
+ export type DevLogLevel = "debug" | "info" | "warn" | "error" | "system";
3
+ /** A line of `minebot dev`: the plugin's logs, plus `system` lines for builds and connections. */
4
+ export interface DevLogLine {
5
+ seq: number;
6
+ time: string;
7
+ level: DevLogLevel;
8
+ bot: string | null;
9
+ message: string;
10
+ }
11
+ /** The last lines of a dev session, numbered so an agent can ask for what's new since it last looked. */
12
+ export declare class DevLog {
13
+ private readonly capacity;
14
+ private readonly lines;
15
+ private seq;
16
+ constructor(capacity?: number);
17
+ add(level: DevLogLevel, message: string, bot?: string | null): void;
18
+ /** Lines after `since` at `minLevel` or above, oldest first; `next` is the cursor for the following read. */
19
+ read(since?: number, minLevel?: DevLogLevel, limit?: number): {
20
+ lines: DevLogLine[];
21
+ next: number;
22
+ };
23
+ }
24
+ /** Operations `query` may run: reads only, so an agent can look around without moving or breaking anything. */
25
+ export declare const QUERY_OPERATIONS: readonly ["bot.status", "bot.position", "world.block", "world.findBlocks", "entities.nearby", "entities.players", "inventory.items", "inventory.held", "bot.recipes", "storage.get", "storage.entries"];
26
+ /** What the dev MCP tools need from `minebot dev`. */
27
+ export interface DevSession {
28
+ readonly log: DevLog;
29
+ status(): unknown;
30
+ /** Rebuilds and reconnects; resolves with how that went. */
31
+ reload(): Promise<unknown>;
32
+ /** Runs a read-only operation as the plugin; `bot` is a name or id, ignored for storage. */
33
+ query(bot: string | undefined, op: string, args: Record<string, unknown>): Promise<unknown>;
34
+ }
35
+ export declare const DEV_MCP_INSTRUCTIONS = "This is `minebot dev`: a MineBot plugin (TypeScript, @minecraftbot-com/plugin) running on the developer's machine,\nconnected to one of their Minecraft bot profiles. It rebuilds and restarts the plugin when a source file is saved.\nUse `status` first, `logs` to see what the plugin printed (pass `since` from the last call's `next`), `reload`\nafter editing if you want to wait for the result, and `query` to look at a bot's surroundings, inventory or the\nplugin's storage. Queries run as the plugin, so they need its permissions; they never move or change anything.\nThe SDK's own guide for writing plugins is AGENTS.md in node_modules/@minecraftbot-com/plugin.";
36
+ export declare function devTools(session: DevSession): McpTool[];
@@ -0,0 +1,101 @@
1
+ const LEVEL_ORDER = { debug: 0, info: 1, system: 1, warn: 2, error: 3 };
2
+ /** The last lines of a dev session, numbered so an agent can ask for what's new since it last looked. */
3
+ export class DevLog {
4
+ capacity;
5
+ lines = [];
6
+ seq = 0;
7
+ constructor(capacity = 1000) {
8
+ this.capacity = capacity;
9
+ }
10
+ add(level, message, bot = null) {
11
+ this.lines.push({ seq: ++this.seq, time: new Date().toISOString(), level, bot, message });
12
+ if (this.lines.length > this.capacity)
13
+ this.lines.splice(0, this.lines.length - this.capacity);
14
+ }
15
+ /** Lines after `since` at `minLevel` or above, oldest first; `next` is the cursor for the following read. */
16
+ read(since = 0, minLevel = "debug", limit = 100) {
17
+ const min = LEVEL_ORDER[minLevel] ?? 0;
18
+ const matching = this.lines.filter(l => l.seq > since && LEVEL_ORDER[l.level] >= min);
19
+ const lines = matching.slice(-Math.max(1, Math.min(limit, 500)));
20
+ return { lines, next: this.seq };
21
+ }
22
+ }
23
+ /** Operations `query` may run: reads only, so an agent can look around without moving or breaking anything. */
24
+ export const QUERY_OPERATIONS = [
25
+ "bot.status",
26
+ "bot.position",
27
+ "world.block",
28
+ "world.findBlocks",
29
+ "entities.nearby",
30
+ "entities.players",
31
+ "inventory.items",
32
+ "inventory.held",
33
+ "bot.recipes",
34
+ "storage.get",
35
+ "storage.entries",
36
+ ];
37
+ export const DEV_MCP_INSTRUCTIONS = `This is \`minebot dev\`: a MineBot plugin (TypeScript, @minecraftbot-com/plugin) running on the developer's machine,
38
+ connected to one of their Minecraft bot profiles. It rebuilds and restarts the plugin when a source file is saved.
39
+ Use \`status\` first, \`logs\` to see what the plugin printed (pass \`since\` from the last call's \`next\`), \`reload\`
40
+ after editing if you want to wait for the result, and \`query\` to look at a bot's surroundings, inventory or the
41
+ plugin's storage. Queries run as the plugin, so they need its permissions; they never move or change anything.
42
+ The SDK's own guide for writing plugins is AGENTS.md in node_modules/@minecraftbot-com/plugin.`;
43
+ export function devTools(session) {
44
+ return [
45
+ {
46
+ name: "status",
47
+ description: "The plugin, the profile it runs on, whether it's connected, its bots (and which it's running on), granted permissions, settings, and the last build's errors.",
48
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
49
+ run: () => session.status(),
50
+ },
51
+ {
52
+ name: "logs",
53
+ description: "Lines the plugin logged (log.info/warn/error/debug, with the bot), plus `system` lines for builds, connections and disconnections. Oldest first. Pass `since` = the previous call's `next` to get only new lines.",
54
+ inputSchema: {
55
+ type: "object",
56
+ properties: {
57
+ since: { type: "integer", minimum: 0, description: "Only lines after this cursor (the `next` of an earlier call)." },
58
+ level: { type: "string", enum: ["debug", "info", "warn", "error"], description: "Minimum level (default debug)." },
59
+ limit: { type: "integer", minimum: 1, maximum: 500, description: "At most this many lines, the newest (default 100)." },
60
+ },
61
+ additionalProperties: false,
62
+ },
63
+ run: args => session.log.read(typeof args.since === "number" ? args.since : 0, args.level ?? "debug", typeof args.limit === "number" ? args.limit : 100),
64
+ },
65
+ {
66
+ name: "reload",
67
+ description: "Rebuilds the plugin and restarts it on the profile, then reports whether the build passed and the plugin connected. Saving a file does the same on its own; use this to wait for the outcome.",
68
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
69
+ run: () => session.reload(),
70
+ },
71
+ {
72
+ name: "query",
73
+ description: [
74
+ "Runs one read-only operation on a bot as the plugin and returns the raw result ({ ok, value } or { ok: false, failure, message }).",
75
+ "The plugin must be running on the bot and hold the permission the operation needs. Arguments by operation:",
76
+ "bot.status {}; bot.position {} (WorldRead); world.block { x, y, z } (WorldRead);",
77
+ 'world.findBlocks { blocks: ["minecraft:wheat"], state?: { age: 7 }, radius?: 16, limit?: 16 } (WorldRead);',
78
+ "entities.nearby { types?: [], radius?: 16, limit?: 32 } and entities.players {} (EntitiesRead);",
79
+ "inventory.items {} and inventory.held {} (InventoryRead); bot.recipes { item: \"minecraft:bread\" } (what crafting it takes);",
80
+ 'storage.get { name, key?, bot?: "<uuid for Bot scope>" } and storage.entries { name, after?, limit? } (no bot needed).',
81
+ ].join(" "),
82
+ inputSchema: {
83
+ type: "object",
84
+ properties: {
85
+ op: { type: "string", enum: [...QUERY_OPERATIONS] },
86
+ bot: { type: "string", description: "Bot name or id (default: the first bot the plugin runs on)." },
87
+ args: { type: "object", description: "The operation's arguments (see the description).", additionalProperties: true },
88
+ },
89
+ required: ["op"],
90
+ additionalProperties: false,
91
+ },
92
+ run: args => {
93
+ const op = String(args.op);
94
+ if (!QUERY_OPERATIONS.includes(op))
95
+ throw new Error(`op must be one of ${QUERY_OPERATIONS.join(", ")}`);
96
+ const opArgs = args.args && typeof args.args === "object" ? args.args : {};
97
+ return session.query(typeof args.bot === "string" ? args.bot : undefined, op, opArgs);
98
+ },
99
+ },
100
+ ];
101
+ }
@@ -0,0 +1,15 @@
1
+ export interface DevArgs {
2
+ profile?: string;
3
+ bots: string[];
4
+ settingsFile?: string;
5
+ watch: boolean;
6
+ /** Port for the MCP endpoint (the next free one up to +9 is used), or null for none. */
7
+ mcpPort: number | null;
8
+ }
9
+ /**
10
+ * `minebot dev`: builds the plugin, runs it on your machine connected to one of your running profiles, and
11
+ * rebuilds and reconnects when a file changes. Your code, your profile: the manifest's permissions are granted
12
+ * without a prompt, and storage lives in a dev namespace apart from installed copies. An MCP endpoint lets an AI
13
+ * agent read the plugin's state and logs, look at its bots and reload it.
14
+ */
15
+ export declare function dev(args: DevArgs): Promise<void>;