@meshpoint/cli 1.6.0 → 1.8.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/dist/agents-md.js +90 -0
- package/dist/bin.js +79 -8
- package/dist/items.js +5 -0
- package/dist/mcp/connect.js +61 -0
- package/dist/mcp/server.js +111 -0
- package/dist/mcp/tools.js +90 -0
- package/dist/opencode/hooks.js +1 -1
- package/dist/pi/extension.js +1 -1
- package/dist/runtime.js +2 -2
- package/dist/tap.js +30 -12
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isExpired } from "@meshpoint/sdk";
|
|
4
|
+
// The team's conventions as a committed block in AGENTS.md, for agents that read that file but
|
|
5
|
+
// have no Meshpoint hook (and for teammates without Meshpoint at all). The block is the only
|
|
6
|
+
// part of the file the CLI touches; every line carries its item id so the session-start inject
|
|
7
|
+
// can leave out what the harness already read from the file.
|
|
8
|
+
export const AGENTS_FILE = "AGENTS.md";
|
|
9
|
+
export const BLOCK_START = "<!-- meshpoint:conventions start -->";
|
|
10
|
+
export const BLOCK_END = "<!-- meshpoint:conventions end -->";
|
|
11
|
+
const ID_TAG = /<!--\s*mp:([A-Za-z0-9_-]{8,})\s*-->/g;
|
|
12
|
+
const CLAUDE_IMPORT = /^@(?:\.\/)?AGENTS\.md\s*$/m;
|
|
13
|
+
// Harnesses that read AGENTS.md at the repository root on their own. Claude Code reads CLAUDE.md
|
|
14
|
+
// and follows an `@AGENTS.md` import line; the rest get no deduplication.
|
|
15
|
+
const AGENTS_MD_READERS = new Set(["codex", "cursor", "pi", "opencode"]);
|
|
16
|
+
export function currentConventions(items, now = Date.now()) {
|
|
17
|
+
return items
|
|
18
|
+
.filter((i) => i.kind === "convention" && !i.retracted && i.state !== "dropped" && i.state !== "superseded" && !isExpired(i, now))
|
|
19
|
+
.sort((a, b) => a.created_at - b.created_at || (a.id < b.id ? -1 : 1));
|
|
20
|
+
}
|
|
21
|
+
function oneLine(s) {
|
|
22
|
+
return s.replace(/\s+/g, " ").trim();
|
|
23
|
+
}
|
|
24
|
+
function sentence(s) {
|
|
25
|
+
const t = oneLine(s);
|
|
26
|
+
return /[.!?:]$/.test(t) ? t : `${t}.`;
|
|
27
|
+
}
|
|
28
|
+
export function renderBlock(items) {
|
|
29
|
+
const lines = [BLOCK_START, "## Team conventions", "Kept by Meshpoint from the team's conventions. Refresh with `meshpoint export agents`; change the items in Meshpoint, not here.", ""];
|
|
30
|
+
if (items.length === 0)
|
|
31
|
+
lines.push("No conventions recorded yet.");
|
|
32
|
+
for (const i of items)
|
|
33
|
+
lines.push(`- ${sentence(i.title)} ${oneLine(i.body)} <!-- mp:${i.id} -->`);
|
|
34
|
+
lines.push(BLOCK_END);
|
|
35
|
+
return lines.join("\n");
|
|
36
|
+
}
|
|
37
|
+
// Replaces the block in place, appends it to a file without one, or starts a new file.
|
|
38
|
+
export function applyBlock(existing, block) {
|
|
39
|
+
if (existing === null)
|
|
40
|
+
return `# Agent instructions\n\n${block}\n`;
|
|
41
|
+
const start = existing.indexOf(BLOCK_START);
|
|
42
|
+
const end = existing.indexOf(BLOCK_END, start);
|
|
43
|
+
if (start >= 0 && end > start)
|
|
44
|
+
return `${existing.slice(0, start)}${block}${existing.slice(end + BLOCK_END.length)}`;
|
|
45
|
+
const head = existing.replace(/\s+$/, "");
|
|
46
|
+
return `${head ? `${head}\n\n` : ""}${block}\n`;
|
|
47
|
+
}
|
|
48
|
+
export function blockIds(text) {
|
|
49
|
+
return new Set([...text.matchAll(ID_TAG)].map((m) => m[1]));
|
|
50
|
+
}
|
|
51
|
+
export function exportConventions(items, root, opts = {}) {
|
|
52
|
+
const rel = opts.file ?? AGENTS_FILE;
|
|
53
|
+
const abs = path.join(root, rel);
|
|
54
|
+
const existing = read(abs);
|
|
55
|
+
const conventions = currentConventions(items, opts.now);
|
|
56
|
+
const next = applyBlock(existing, renderBlock(conventions));
|
|
57
|
+
const changed = next !== existing;
|
|
58
|
+
if (changed && !opts.check)
|
|
59
|
+
writeFileSync(abs, next);
|
|
60
|
+
return { file: rel, created: existing === null, changed, count: conventions.length };
|
|
61
|
+
}
|
|
62
|
+
export function hasBlock(root, file = AGENTS_FILE) {
|
|
63
|
+
const text = read(path.join(root, file));
|
|
64
|
+
return text !== null && text.includes(BLOCK_START) && text.includes(BLOCK_END);
|
|
65
|
+
}
|
|
66
|
+
// Convention ids this harness already has in front of it from a committed file, or null.
|
|
67
|
+
export function committedConventions(root, harness) {
|
|
68
|
+
if (harness === "claude-code") {
|
|
69
|
+
const claude = read(path.join(root, "CLAUDE.md"));
|
|
70
|
+
if (!claude)
|
|
71
|
+
return null;
|
|
72
|
+
const ids = blockIds(claude);
|
|
73
|
+
if (CLAUDE_IMPORT.test(claude))
|
|
74
|
+
for (const id of blockIds(read(path.join(root, AGENTS_FILE)) ?? ""))
|
|
75
|
+
ids.add(id);
|
|
76
|
+
return ids.size > 0 ? { file: "CLAUDE.md", ids } : null;
|
|
77
|
+
}
|
|
78
|
+
if (!AGENTS_MD_READERS.has(harness))
|
|
79
|
+
return null;
|
|
80
|
+
const ids = blockIds(read(path.join(root, AGENTS_FILE)) ?? "");
|
|
81
|
+
return ids.size > 0 ? { file: AGENTS_FILE, ids } : null;
|
|
82
|
+
}
|
|
83
|
+
function read(abs) {
|
|
84
|
+
try {
|
|
85
|
+
return readFileSync(abs, "utf8");
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
package/dist/bin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { readFileSync } from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -17,15 +18,19 @@ import { connectPi } from "./pi/connect.js";
|
|
|
17
18
|
import { Checkpoints } from "./checkpoints.js";
|
|
18
19
|
import { configPath, deleteConfig, loadConfig, repoContext, saveConfig, spoolDir, stateDir } from "./config.js";
|
|
19
20
|
import { SessionCache } from "./context.js";
|
|
20
|
-
import { localChecks } from "./tap.js";
|
|
21
|
+
import { localChecks, Tap } from "./tap.js";
|
|
21
22
|
import { Touched } from "./touched.js";
|
|
22
23
|
import { MeshpointError } from "@meshpoint/sdk";
|
|
23
24
|
import { api, ApiError, canOpenBrowser, deviceLogin, freshConfig, login } from "./control.js";
|
|
24
25
|
import { detectHarnesses, renderDetected } from "./detect.js";
|
|
25
26
|
import { renderDoctor, runDoctor } from "./doctor.js";
|
|
26
|
-
import { confirmItems, parseItemArgs, parseItems, putItems, retractItems } from "./items.js";
|
|
27
|
+
import { branchItems, confirmItems, parseItemArgs, parseItems, putItems, retractItems } from "./items.js";
|
|
27
28
|
import { importOffer } from "./import/offer.js";
|
|
28
29
|
import { applyProposalFile, DEFAULT_SINCE_DAYS, importSessions } from "./import/run.js";
|
|
30
|
+
import { AGENTS_FILE, exportConventions, hasBlock } from "./agents-md.js";
|
|
31
|
+
import { connectMcp } from "./mcp/connect.js";
|
|
32
|
+
import { McpServer } from "./mcp/server.js";
|
|
33
|
+
import { MCP_INSTRUCTIONS, MCP_SERVER_NAME, meshpointTools } from "./mcp/tools.js";
|
|
29
34
|
import { detectRunner } from "./import/runner.js";
|
|
30
35
|
import { Spool } from "./spool.js";
|
|
31
36
|
const IMPORT_USAGE = ` import sessions [--since <days>] [--all-repos] [--with-turns] [--apply | --propose] [--yes] [--fresh]
|
|
@@ -87,12 +92,22 @@ const USAGE = `meshpoint <command>
|
|
|
87
92
|
opencode [--config-dir <dir>] <dir>/plugins/meshpoint.js + <dir>/skills/meshpoint
|
|
88
93
|
(default dir: ~/.config/opencode)
|
|
89
94
|
openclaw hook pack installed through 'openclaw plugins install'
|
|
95
|
+
mcp prints where MCP clients take the server; --project <dir>
|
|
96
|
+
writes <dir>/.mcp.json (Claude Code project scope, VS Code
|
|
97
|
+
with Copilot)
|
|
98
|
+
mcp [--cwd <dir>] stdio MCP server for clients without a hook: tools for recall,
|
|
99
|
+
file context and item writes; the repository is the working
|
|
100
|
+
directory
|
|
90
101
|
items put --item <kind> <title> <body> [--item ...]
|
|
91
102
|
items put --file <path> | items put < items.json
|
|
92
103
|
write items for the current repo and branch; the file or
|
|
93
104
|
stdin form takes a JSON array of {kind, title, body}
|
|
94
105
|
items retract <id>... retract items on the current branch; an id may be a prefix
|
|
95
106
|
items confirm <id>... confirm items on the current branch (counts toward their rank)
|
|
107
|
+
export agents [--file <path>] [--check] write the branch's conventions as a marked block in AGENTS.md
|
|
108
|
+
(or --file, repo-relative) for agents that read that file
|
|
109
|
+
without a hook; the block is the only part touched, rerun to
|
|
110
|
+
refresh. --check exits 1 when the block is out of date
|
|
96
111
|
${IMPORT_USAGE} tap claude-code | codex | cursor | antigravity [<event>] | openclaw
|
|
97
112
|
hook entry point; reads one hook payload on stdin
|
|
98
113
|
`;
|
|
@@ -101,6 +116,9 @@ function flag(args, name) {
|
|
|
101
116
|
const i = args.indexOf(name);
|
|
102
117
|
return i >= 0 ? args[i + 1] : undefined;
|
|
103
118
|
}
|
|
119
|
+
function installedVersion() {
|
|
120
|
+
return JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8")).version;
|
|
121
|
+
}
|
|
104
122
|
const DEFAULT_BASE_URL = "https://api.meshpoint.dev";
|
|
105
123
|
async function requireConfig() {
|
|
106
124
|
const config = loadConfig();
|
|
@@ -171,8 +189,7 @@ async function main(argv) {
|
|
|
171
189
|
case "--version":
|
|
172
190
|
case "-v":
|
|
173
191
|
case "version": {
|
|
174
|
-
|
|
175
|
-
process.stdout.write(`${pkg.version}\n`);
|
|
192
|
+
process.stdout.write(`${installedVersion()}\n`);
|
|
176
193
|
return 0;
|
|
177
194
|
}
|
|
178
195
|
case "login": {
|
|
@@ -251,14 +268,19 @@ async function main(argv) {
|
|
|
251
268
|
console.log(connectOpenclaw({ remove }));
|
|
252
269
|
else if (rest[0] === "opencode")
|
|
253
270
|
console.log(connectOpencode({ remove, ...(configDir ? { configDir } : {}) }));
|
|
271
|
+
else if (rest[0] === "mcp")
|
|
272
|
+
console.log(connectMcp({ remove, ...inProject }));
|
|
254
273
|
else
|
|
255
|
-
throw new Error("connect supports: claude-code, codex, cursor, antigravity, pi, opencode, openclaw");
|
|
256
|
-
if (!remove) {
|
|
274
|
+
throw new Error("connect supports: claude-code, codex, cursor, antigravity, pi, opencode, openclaw, mcp");
|
|
275
|
+
if (!remove && rest[0] !== "mcp") {
|
|
257
276
|
// Past sessions for this repository are worth a line; the offer never fails the connect.
|
|
258
277
|
try {
|
|
259
|
-
const
|
|
278
|
+
const repo = repoContext(process.cwd());
|
|
279
|
+
const offer = importOffer({ repo, env: process.env, runner: detectRunner(process.env)?.name ?? null });
|
|
260
280
|
if (offer)
|
|
261
281
|
console.log(`\n${offer}`);
|
|
282
|
+
if (repo && !hasBlock(repo.root))
|
|
283
|
+
console.log(`\nAgents without a hook read ${AGENTS_FILE}: meshpoint export agents writes the team's conventions there.`);
|
|
262
284
|
}
|
|
263
285
|
catch {
|
|
264
286
|
// unreadable store or no git
|
|
@@ -289,6 +311,55 @@ async function main(argv) {
|
|
|
289
311
|
console.log(JSON.stringify({ ...out, project: repo.project, branch: repo.branch }));
|
|
290
312
|
return 0;
|
|
291
313
|
}
|
|
314
|
+
case "mcp": {
|
|
315
|
+
const cwd = flag(rest, "--cwd") ?? process.cwd();
|
|
316
|
+
if (!path.isAbsolute(cwd))
|
|
317
|
+
throw new Error("--cwd must be an absolute path");
|
|
318
|
+
const stored = loadConfig();
|
|
319
|
+
const config = stored ? await freshConfig(stored).catch(() => stored) : null;
|
|
320
|
+
const repo = repoContext(cwd);
|
|
321
|
+
const tap = config && repo
|
|
322
|
+
? new Tap({
|
|
323
|
+
config,
|
|
324
|
+
repo,
|
|
325
|
+
session: `mcp-${randomUUID()}`,
|
|
326
|
+
spool: new Spool(spoolDir()),
|
|
327
|
+
checkpoints: new Checkpoints(stateDir()),
|
|
328
|
+
touched: new Touched(stateDir()),
|
|
329
|
+
cache: new SessionCache(stateDir()),
|
|
330
|
+
local: localChecks(repo.root),
|
|
331
|
+
refresh: () => freshConfig(config, { force: true }).catch(() => null),
|
|
332
|
+
})
|
|
333
|
+
: null;
|
|
334
|
+
const server = new McpServer({
|
|
335
|
+
name: MCP_SERVER_NAME,
|
|
336
|
+
version: installedVersion(),
|
|
337
|
+
instructions: MCP_INSTRUCTIONS,
|
|
338
|
+
tools: meshpointTools({ tap, cwd, config: requireConfig, checkpoints: new Checkpoints(stateDir()), touched: new Touched(stateDir()) }),
|
|
339
|
+
});
|
|
340
|
+
await server.serve(process.stdin, process.stdout);
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
case "export": {
|
|
344
|
+
if (rest[0] !== "agents")
|
|
345
|
+
throw new Error("export supports: agents");
|
|
346
|
+
const config = await requireConfig();
|
|
347
|
+
const repo = repoContext(process.cwd());
|
|
348
|
+
if (!repo)
|
|
349
|
+
throw new Error("not inside a git repo with an origin remote");
|
|
350
|
+
const file = flag(rest, "--file");
|
|
351
|
+
if (file !== undefined && (path.isAbsolute(file) || file.split(/[\\/]/).includes("..")))
|
|
352
|
+
throw new Error("--file is a path inside the repository");
|
|
353
|
+
const check = rest.includes("--check");
|
|
354
|
+
const items = await withAuth(config, (c) => branchItems({ config: c, repo }));
|
|
355
|
+
const out = exportConventions(items, repo.root, { ...(file ? { file } : {}), check });
|
|
356
|
+
const what = `${out.count} convention${out.count === 1 ? "" : "s"} on ${repo.branch}`;
|
|
357
|
+
if (check)
|
|
358
|
+
console.log(out.changed ? `${out.file} is out of date (${what}); run meshpoint export agents` : `${out.file} is up to date (${what})`);
|
|
359
|
+
else
|
|
360
|
+
console.log(out.changed ? `${out.created ? "created" : "updated"} ${out.file}: ${what}. Commit it so every agent and teammate reads it.` : `${out.file} already up to date (${what})`);
|
|
361
|
+
return check && out.changed ? 1 : 0;
|
|
362
|
+
}
|
|
292
363
|
case "import": {
|
|
293
364
|
if (rest[0] !== "sessions")
|
|
294
365
|
throw new Error("import supports: sessions");
|
|
@@ -358,7 +429,7 @@ async function main(argv) {
|
|
|
358
429
|
checkpoints: new Checkpoints(stateDir()),
|
|
359
430
|
touched: new Touched(stateDir()),
|
|
360
431
|
cache: new SessionCache(stateDir()),
|
|
361
|
-
local: (root) => localChecks(root),
|
|
432
|
+
local: (root) => localChecks(root, harness),
|
|
362
433
|
});
|
|
363
434
|
// Each harness has its own "do nothing" answer, needed even without a login.
|
|
364
435
|
if (harness === "cursor") {
|
package/dist/items.js
CHANGED
|
@@ -134,6 +134,11 @@ async function resolveIds(prefixes, deps, client) {
|
|
|
134
134
|
return matches[0];
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
+
// Every live item on the branch, fresh from the origin.
|
|
138
|
+
export async function branchItems(deps) {
|
|
139
|
+
const { items } = await clientFor(deps).recall({ budget: ALL_ITEMS_BUDGET, fresh: true });
|
|
140
|
+
return items;
|
|
141
|
+
}
|
|
137
142
|
export async function confirmItems(prefixes, deps) {
|
|
138
143
|
if (prefixes.length === 0)
|
|
139
144
|
throw new Error("confirm needs at least one item id");
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
// Registers the stdio server where MCP clients look. One file is written: <repo>/.mcp.json, which
|
|
5
|
+
// Claude Code (project scope) and VS Code with Copilot both read. Other clients keep their own
|
|
6
|
+
// user-level files; connect prints the entry for them instead of guessing at those files.
|
|
7
|
+
export const MCP_FILE = ".mcp.json";
|
|
8
|
+
export const MCP_ENTRY = { type: "stdio", command: "meshpoint", args: ["mcp"] };
|
|
9
|
+
export function installMcpEntry(file) {
|
|
10
|
+
return { ...file, mcpServers: { ...file.mcpServers, meshpoint: MCP_ENTRY } };
|
|
11
|
+
}
|
|
12
|
+
export function removeMcpEntry(file) {
|
|
13
|
+
const { meshpoint: _dropped, ...servers } = file.mcpServers ?? {};
|
|
14
|
+
const { mcpServers: _old, ...rest } = file;
|
|
15
|
+
return Object.keys(servers).length > 0 ? { ...rest, mcpServers: servers } : rest;
|
|
16
|
+
}
|
|
17
|
+
export function mcpSnippets(home = homedir(), platform = process.platform) {
|
|
18
|
+
const entry = JSON.stringify({ mcpServers: { meshpoint: MCP_ENTRY } }, null, 2);
|
|
19
|
+
const desktop = platform === "darwin" ? path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json") : platform === "win32" ? "%APPDATA%\\Claude\\claude_desktop_config.json" : path.join(home, ".config", "Claude", "claude_desktop_config.json");
|
|
20
|
+
return [
|
|
21
|
+
"Add the Meshpoint MCP server to a client by hand:",
|
|
22
|
+
"",
|
|
23
|
+
` Claude Code, VS Code with Copilot (one repository): meshpoint connect mcp --project <repo> writes <repo>/${MCP_FILE}`,
|
|
24
|
+
` Claude Code (every repository): claude mcp add --scope user meshpoint -- meshpoint mcp`,
|
|
25
|
+
` VS Code with Copilot (every repository): ${path.join(home, ".copilot", "mcp-config.json")}`,
|
|
26
|
+
` Claude Desktop: ${desktop}`,
|
|
27
|
+
` Zed: settings.json, key "context_servers": {"meshpoint": {"command": "meshpoint", "args": ["mcp"]}}`,
|
|
28
|
+
"",
|
|
29
|
+
"The entry for the mcpServers files:",
|
|
30
|
+
"",
|
|
31
|
+
entry.replace(/^/gm, " "),
|
|
32
|
+
"",
|
|
33
|
+
"The server finds the repository from its working directory; clients that start it elsewhere pass --cwd <repo> in args.",
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
export function connectMcp(opts) {
|
|
37
|
+
if (!opts.projectDir) {
|
|
38
|
+
if (opts.remove)
|
|
39
|
+
return "connect mcp --remove needs --project <repo>; user-level entries were added by hand and are removed the same way";
|
|
40
|
+
return mcpSnippets();
|
|
41
|
+
}
|
|
42
|
+
const file = path.join(opts.projectDir, MCP_FILE);
|
|
43
|
+
let current = {};
|
|
44
|
+
try {
|
|
45
|
+
current = JSON.parse(readFileSync(file, "utf8"));
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err.code !== "ENOENT")
|
|
49
|
+
throw new Error(`could not read ${file}: ${err.message}`);
|
|
50
|
+
}
|
|
51
|
+
if (opts.remove) {
|
|
52
|
+
const next = removeMcpEntry(current);
|
|
53
|
+
if (Object.keys(next).length > 0)
|
|
54
|
+
writeFileSync(file, `${JSON.stringify(next, null, 2)}\n`);
|
|
55
|
+
else
|
|
56
|
+
rmSync(file, { force: true });
|
|
57
|
+
return `removed the meshpoint server from ${file}`;
|
|
58
|
+
}
|
|
59
|
+
writeFileSync(file, `${JSON.stringify(installMcpEntry(current), null, 2)}\n`);
|
|
60
|
+
return `registered the meshpoint MCP server in ${file} (Claude Code project scope, VS Code with Copilot). Commit it so the team gets it; Claude Code asks once to approve a project server.`;
|
|
61
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// A stdio MCP server: JSON-RPC 2.0, one message per line. Only the lifecycle and the tools
|
|
2
|
+
// methods are implemented; everything else answers "method not found". No SDK: the protocol
|
|
3
|
+
// surface used here is five methods and fits in a file.
|
|
4
|
+
export const PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
5
|
+
const DEFAULT_PROTOCOL = PROTOCOL_VERSIONS[0];
|
|
6
|
+
const PARSE_ERROR = -32700;
|
|
7
|
+
const INVALID_REQUEST = -32600;
|
|
8
|
+
const METHOD_NOT_FOUND = -32601;
|
|
9
|
+
const INVALID_PARAMS = -32602;
|
|
10
|
+
const INTERNAL = -32603;
|
|
11
|
+
class RpcError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
constructor(code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class McpServer {
|
|
19
|
+
opts;
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
this.opts = opts;
|
|
22
|
+
}
|
|
23
|
+
// One request in, one result or error out; null for notifications.
|
|
24
|
+
async handle(req) {
|
|
25
|
+
const id = req.id ?? null;
|
|
26
|
+
if (req.jsonrpc !== "2.0" || typeof req.method !== "string")
|
|
27
|
+
return id === null ? null : error(id, INVALID_REQUEST, "invalid request");
|
|
28
|
+
if (req.method.startsWith("notifications/"))
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
return { jsonrpc: "2.0", id, result: await this.dispatch(req.method, req.params ?? {}) };
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof RpcError)
|
|
35
|
+
return error(id, err.code, err.message);
|
|
36
|
+
return error(id, INTERNAL, err instanceof Error ? err.message : String(err));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async dispatch(method, params) {
|
|
40
|
+
switch (method) {
|
|
41
|
+
case "initialize": {
|
|
42
|
+
const asked = typeof params.protocolVersion === "string" ? params.protocolVersion : "";
|
|
43
|
+
return {
|
|
44
|
+
protocolVersion: PROTOCOL_VERSIONS.includes(asked) ? asked : DEFAULT_PROTOCOL,
|
|
45
|
+
capabilities: { tools: {} },
|
|
46
|
+
serverInfo: { name: this.opts.name, version: this.opts.version },
|
|
47
|
+
instructions: this.opts.instructions,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case "ping":
|
|
51
|
+
return {};
|
|
52
|
+
case "tools/list":
|
|
53
|
+
return { tools: this.opts.tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })) };
|
|
54
|
+
case "tools/call": {
|
|
55
|
+
const tool = this.opts.tools.find((t) => t.name === params.name);
|
|
56
|
+
if (!tool)
|
|
57
|
+
throw new RpcError(INVALID_PARAMS, `unknown tool: ${String(params.name)}`);
|
|
58
|
+
const args = params.arguments;
|
|
59
|
+
if (args !== undefined && (typeof args !== "object" || args === null || Array.isArray(args)))
|
|
60
|
+
throw new RpcError(INVALID_PARAMS, "arguments must be an object");
|
|
61
|
+
try {
|
|
62
|
+
return { content: [{ type: "text", text: await tool.run(args ?? {}) }], isError: false };
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return { content: [{ type: "text", text: err instanceof Error ? err.message : String(err) }], isError: true };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
default:
|
|
69
|
+
throw new RpcError(METHOD_NOT_FOUND, `method not found: ${method}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Reads lines until the input ends; answers are written as they are ready.
|
|
73
|
+
async serve(input, output) {
|
|
74
|
+
let buffer = "";
|
|
75
|
+
const pending = [];
|
|
76
|
+
const write = (msg) => {
|
|
77
|
+
output.write(`${JSON.stringify(msg)}\n`);
|
|
78
|
+
};
|
|
79
|
+
const take = (line) => {
|
|
80
|
+
const text = line.trim();
|
|
81
|
+
if (!text)
|
|
82
|
+
return;
|
|
83
|
+
let req;
|
|
84
|
+
try {
|
|
85
|
+
req = JSON.parse(text);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
write(error(null, PARSE_ERROR, "parse error"));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
pending.push(this.handle(req).then((res) => {
|
|
92
|
+
if (res)
|
|
93
|
+
write(res);
|
|
94
|
+
}));
|
|
95
|
+
};
|
|
96
|
+
for await (const chunk of input) {
|
|
97
|
+
buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
98
|
+
let nl = buffer.indexOf("\n");
|
|
99
|
+
while (nl >= 0) {
|
|
100
|
+
take(buffer.slice(0, nl));
|
|
101
|
+
buffer = buffer.slice(nl + 1);
|
|
102
|
+
nl = buffer.indexOf("\n");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
take(buffer);
|
|
106
|
+
await Promise.all(pending);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function error(id, code, message) {
|
|
110
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
111
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { KINDS } from "@meshpoint/sdk";
|
|
2
|
+
import { confirmItems, ITEMS_MAX, parseItems, putItems, retractItems } from "../items.js";
|
|
3
|
+
// The Meshpoint tools an MCP client gets: the session-start context, the notice for one file,
|
|
4
|
+
// and the three item writes. Capture and presence need a hook or plugin and are not here.
|
|
5
|
+
export const MCP_SERVER_NAME = "meshpoint";
|
|
6
|
+
export const MCP_INSTRUCTIONS = `Meshpoint is the team's shared memory for this repository, per branch.
|
|
7
|
+
Call meshpoint_recall once at the start of a task: it lists what teammates' agents learned (decisions, gotchas, conventions, facts, status, todos) and who is active now. Before editing a file, meshpoint_file_context tells you what is known about that file and whether a teammate is on it.
|
|
8
|
+
Record what you establish with meshpoint_items_put: one item per decision, gotcha, convention, fact, status or todo, bodies concrete (repo-relative file names, commands, values, reasons), nothing already listed by recall unless it changed, no secrets. Retract items you proved wrong with meshpoint_items_retract.`;
|
|
9
|
+
const IDS_SCHEMA = { type: "array", items: { type: "string" }, minItems: 1, description: "Item ids or unique id prefixes, as recall lists them." };
|
|
10
|
+
function strings(v, what) {
|
|
11
|
+
if (!Array.isArray(v) || v.length === 0 || !v.every((s) => typeof s === "string" && s.trim()))
|
|
12
|
+
throw new Error(`${what} must be a non-empty list of strings`);
|
|
13
|
+
return v.map((s) => s.trim());
|
|
14
|
+
}
|
|
15
|
+
export function meshpointTools(deps) {
|
|
16
|
+
const tap = () => {
|
|
17
|
+
if (!deps.tap)
|
|
18
|
+
throw new Error(`${deps.cwd} is not inside a git repository with an origin remote; start the server in one or pass --cwd`);
|
|
19
|
+
return deps.tap;
|
|
20
|
+
};
|
|
21
|
+
const repo = () => tap().repo;
|
|
22
|
+
const itemDeps = async () => ({ config: await deps.config(), repo: repo(), ...(deps.fetch ? { fetch: deps.fetch } : {}) });
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
name: "meshpoint_recall",
|
|
26
|
+
description: "Team knowledge for this repository and branch: items from teammates' agents (first column is the item id, ? marks an item whose referenced file changed since) and who is active now. Call once at the start of a task.",
|
|
27
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
28
|
+
run: async () => {
|
|
29
|
+
const text = await tap().start();
|
|
30
|
+
return text || `No team knowledge for ${repo().project} @ ${repo().branch} yet.`;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "meshpoint_file_context",
|
|
35
|
+
description: "What is known about one file before you edit it: items naming it and teammates editing it now. Path is repo-relative or absolute.",
|
|
36
|
+
inputSchema: { type: "object", properties: { path: { type: "string", description: "File path, repo-relative or absolute." } }, required: ["path"], additionalProperties: false },
|
|
37
|
+
run: async (args) => {
|
|
38
|
+
if (typeof args.path !== "string" || !args.path.trim())
|
|
39
|
+
throw new Error("path is required");
|
|
40
|
+
const text = await tap().fileContext(args.path.trim());
|
|
41
|
+
return text || `Nothing recorded about ${args.path.trim()}; nobody else is on it.`;
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "meshpoint_items_put",
|
|
46
|
+
description: `Write knowledge items for this repository and branch. Each item: kind (${KINDS.join(", ")}), one-line title, one to three concrete sentences as body; optional key (a stable slot such as test-runner; a later item with the same key replaces this one) and supersedes (ids this item replaces). At most ${ITEMS_MAX} per call. Name files by repo-relative path; the result lists paths that do not exist in the checkout.`,
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
items: {
|
|
51
|
+
type: "array",
|
|
52
|
+
minItems: 1,
|
|
53
|
+
maxItems: ITEMS_MAX,
|
|
54
|
+
items: {
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
kind: { type: "string", enum: [...KINDS] },
|
|
58
|
+
title: { type: "string" },
|
|
59
|
+
body: { type: "string" },
|
|
60
|
+
key: { type: "string" },
|
|
61
|
+
supersedes: { type: "array", items: { type: "string" } },
|
|
62
|
+
},
|
|
63
|
+
required: ["kind", "title", "body"],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
required: ["items"],
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
},
|
|
71
|
+
run: async (args) => {
|
|
72
|
+
const drafts = parseItems(JSON.stringify(args.items ?? null));
|
|
73
|
+
const { missing, ...out } = await putItems(drafts, { ...(await itemDeps()), checkpoints: deps.checkpoints, touched: deps.touched });
|
|
74
|
+
return JSON.stringify({ ...out, project: repo().project, branch: repo().branch, ...(missing.length ? { ref_not_found: missing } : {}) });
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "meshpoint_items_retract",
|
|
79
|
+
description: "Retract items on this branch that this session proved wrong: a finished todo, a reversed decision with nothing in its place.",
|
|
80
|
+
inputSchema: { type: "object", properties: { ids: IDS_SCHEMA }, required: ["ids"], additionalProperties: false },
|
|
81
|
+
run: async (args) => JSON.stringify(await retractItems(strings(args.ids, "ids"), await itemDeps())),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "meshpoint_items_confirm",
|
|
85
|
+
description: "Confirm items that held true in this session; confirmations raise an item in recall and keep status and todo items from expiring.",
|
|
86
|
+
inputSchema: { type: "object", properties: { ids: IDS_SCHEMA }, required: ["ids"], additionalProperties: false },
|
|
87
|
+
run: async (args) => JSON.stringify(await confirmItems(strings(args.ids, "ids"), await itemDeps())),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
package/dist/opencode/hooks.js
CHANGED
package/dist/pi/extension.js
CHANGED
|
@@ -47,7 +47,7 @@ export function meshpointExtension(pi, deps = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
pi.on("session_start", (_event, ctx) => quiet(async () => {
|
|
50
|
-
tap = await open(ctx.sessionManager.getSessionId(), ctx.cwd);
|
|
50
|
+
tap = await open(ctx.sessionManager.getSessionId(), ctx.cwd, "pi");
|
|
51
51
|
if (!tap)
|
|
52
52
|
return;
|
|
53
53
|
entries = assistantEntries(ctx.sessionManager.getBranch());
|
package/dist/runtime.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Touched } from "./touched.js";
|
|
|
8
8
|
// A Tap for one harness session, wired to the stored login and the on-disk spool. Null when the
|
|
9
9
|
// machine is not logged in or the directory is not a repo with an origin remote. In-process
|
|
10
10
|
// adapters (pi, opencode, openclaw) call this once per harness session.
|
|
11
|
-
export async function openTap(session, cwd) {
|
|
11
|
+
export async function openTap(session, cwd, harness) {
|
|
12
12
|
const stored = loadConfig();
|
|
13
13
|
if (!stored)
|
|
14
14
|
return null;
|
|
@@ -25,7 +25,7 @@ export async function openTap(session, cwd) {
|
|
|
25
25
|
checkpoints: new Checkpoints(stateDir()),
|
|
26
26
|
touched: new Touched(stateDir()),
|
|
27
27
|
cache: new SessionCache(stateDir()),
|
|
28
|
-
local: localChecks(repo.root),
|
|
28
|
+
local: localChecks(repo.root, harness),
|
|
29
29
|
refresh: () => freshConfig(config, { force: true }).catch(() => null),
|
|
30
30
|
});
|
|
31
31
|
}
|
package/dist/tap.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { isExpired, MeshpointClient, MeshpointError, redact } from "@meshpoint/sdk";
|
|
3
|
+
import { committedConventions } from "./agents-md.js";
|
|
3
4
|
import { SKILL_NAME } from "./claude-code/skill.js";
|
|
4
5
|
import { instructionFiles, itemsForFile, renderEditNotice, renderImportNudge } from "./context.js";
|
|
5
6
|
import { ID_PREFIX_CHARS } from "./items.js";
|
|
6
7
|
import { gitRunner, sightings, verifyItems } from "./verify.js";
|
|
7
|
-
export function localChecks(root) {
|
|
8
|
+
export function localChecks(root, harness) {
|
|
8
9
|
const git = gitRunner(root);
|
|
9
10
|
return {
|
|
10
11
|
verify: (items) => verifyItems(items, root, { git }),
|
|
11
12
|
instructionFiles: () => instructionFiles(git),
|
|
13
|
+
committedConventions: () => (harness ? committedConventions(root, harness) : null),
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
16
|
const DEFAULT_PRESENCE_WAIT_MS = 1500;
|
|
@@ -61,7 +63,7 @@ export class Tap {
|
|
|
61
63
|
presence,
|
|
62
64
|
new Promise((r) => setTimeout(() => r([]), this.deps.presenceWaitMs ?? DEFAULT_PRESENCE_WAIT_MS)),
|
|
63
65
|
]);
|
|
64
|
-
let text = renderInject(this.repo, recall, teammates, this.now(), verdicts);
|
|
66
|
+
let text = renderInject(this.repo, recall, teammates, this.now(), verdicts, this.deps.local?.committedConventions?.() ?? null);
|
|
65
67
|
const nudge = this.importNudge(recall);
|
|
66
68
|
if (nudge)
|
|
67
69
|
text = `${text || `# Meshpoint: ${this.repo.project} @ ${this.repo.branch}`}\n\n${nudge}`;
|
|
@@ -91,18 +93,25 @@ export class Tap {
|
|
|
91
93
|
return "";
|
|
92
94
|
if (this.deps.cache && !this.deps.cache.firstEdit(this.deps.session, rel))
|
|
93
95
|
return "";
|
|
94
|
-
|
|
95
|
-
const ctx = await Promise.race([
|
|
96
|
-
this.client(this.repo.branch).context(rel).catch(() => null),
|
|
97
|
-
new Promise((r) => setTimeout(() => r(null), EDIT_WAIT_MS)),
|
|
98
|
-
]);
|
|
99
|
-
const items = cached ? itemsForFile(cached.items, cached.verdicts, rel) : (ctx?.items ?? []);
|
|
100
|
-
return renderEditNotice(rel, items, ctx?.presence ?? [], this.now());
|
|
96
|
+
return await this.fileContext(rel);
|
|
101
97
|
}
|
|
102
98
|
catch {
|
|
103
99
|
return "";
|
|
104
100
|
}
|
|
105
101
|
}
|
|
102
|
+
// The same notice on demand, every time it is asked for (the MCP tool).
|
|
103
|
+
async fileContext(filePath) {
|
|
104
|
+
const rel = this.relative(filePath);
|
|
105
|
+
if (!rel)
|
|
106
|
+
return "";
|
|
107
|
+
const cached = this.deps.cache?.loadRecall(this.deps.session);
|
|
108
|
+
const ctx = await Promise.race([
|
|
109
|
+
this.client(this.repo.branch).context(rel).catch(() => null),
|
|
110
|
+
new Promise((r) => setTimeout(() => r(null), EDIT_WAIT_MS)),
|
|
111
|
+
]);
|
|
112
|
+
const items = cached ? itemsForFile(cached.items, cached.verdicts, rel) : (ctx?.items ?? []);
|
|
113
|
+
return renderEditNotice(rel, items, ctx?.presence ?? [], this.now());
|
|
114
|
+
}
|
|
106
115
|
async user(prompt) {
|
|
107
116
|
if (prompt)
|
|
108
117
|
this.spoolTurn(`[user] ${prompt}`);
|
|
@@ -227,7 +236,7 @@ function estimateTokens(item) {
|
|
|
227
236
|
// file is gone in this checkout) leave the list for a short section of their own; suspect items
|
|
228
237
|
// (a referenced file changed since) stay, marked. Items the platform already marks suspect from
|
|
229
238
|
// other checkouts carry the mark too.
|
|
230
|
-
export function renderInject(repo, recall, presence, now, verdicts = new Map()) {
|
|
239
|
+
export function renderInject(repo, recall, presence, now, verdicts = new Map(), committed = null) {
|
|
231
240
|
if (recall.items.length === 0 && !recall.checkpoint && presence.length === 0)
|
|
232
241
|
return "";
|
|
233
242
|
const lines = [`# Meshpoint: ${repo.project} @ ${repo.branch}`];
|
|
@@ -244,18 +253,27 @@ export function renderInject(repo, recall, presence, now, verdicts = new Map())
|
|
|
244
253
|
const stale = current.filter((i) => verdicts.get(i.id) === "stale");
|
|
245
254
|
const live = [];
|
|
246
255
|
let used = 0;
|
|
256
|
+
// Conventions the harness already read from the committed block are not repeated.
|
|
257
|
+
let inFile = 0;
|
|
247
258
|
for (const i of current) {
|
|
248
259
|
if (verdicts.get(i.id) === "stale")
|
|
249
260
|
continue;
|
|
261
|
+
if (i.kind === "convention" && committed?.ids.has(i.id)) {
|
|
262
|
+
inFile += 1;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
250
265
|
const t = estimateTokens(i);
|
|
251
266
|
if (used + t > INJECT_BUDGET_TOKENS)
|
|
252
267
|
break;
|
|
253
268
|
live.push(i);
|
|
254
269
|
used += t;
|
|
255
270
|
}
|
|
256
|
-
if (live.length > 0) {
|
|
271
|
+
if (live.length > 0 || inFile > 0) {
|
|
257
272
|
const marked = live.some((i) => isSuspect(i, verdicts));
|
|
258
|
-
|
|
273
|
+
const notes = live.length > 0 ? [`first column is the item id${marked ? ", ? means a referenced file changed since" : ""}`] : [];
|
|
274
|
+
if (inFile > 0)
|
|
275
|
+
notes.push(`${inFile} convention${inFile === 1 ? " is" : "s are"} in ${committed.file}`);
|
|
276
|
+
lines.push("", `## Team knowledge (${live.length > 0 ? `${live.length}; ` : ""}${notes.join("; ")})`);
|
|
259
277
|
for (const i of live)
|
|
260
278
|
lines.push(`- ${i.id.slice(0, ID_PREFIX_CHARS)}${isSuspect(i, verdicts) ? "?" : ""} [${i.kind}] ${i.title}: ${i.body}`);
|
|
261
279
|
}
|