@mergeline/agent 0.5.3 → 0.5.4
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/cli.js +7 -6
- package/dist/mcp.js +3 -2
- package/dist/repo.js +3 -2
- package/dist/terminal.js +30 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -32,6 +32,7 @@ import { forgetAgent, pickSaved, saveAgent, savedAgents } from "./credentials.js
|
|
|
32
32
|
import { agentCredentialsFromEnv } from "./pb.js";
|
|
33
33
|
import { boardInContext, normalizeBoardUrl, REPO_FILE } from "./repo.js";
|
|
34
34
|
import { BoardError, TicketService } from "./service.js";
|
|
35
|
+
import { terminalJson, terminalLine, terminalText } from "./terminal.js";
|
|
35
36
|
const HELP = `board: a Mergeline board from the command line
|
|
36
37
|
|
|
37
38
|
Usage:
|
|
@@ -163,7 +164,7 @@ function runInit(args) {
|
|
|
163
164
|
dryRun,
|
|
164
165
|
noNpx: args.includes("--no-npx"),
|
|
165
166
|
});
|
|
166
|
-
const out = process.stdout;
|
|
167
|
+
const out = { write: (s) => process.stdout.write(terminalText(s)) };
|
|
167
168
|
out.write(`${dryRun ? "Would change" : "Agent kit"} in ${dir}:\n`);
|
|
168
169
|
for (const a of result.actions)
|
|
169
170
|
out.write(` ${a.kind.padEnd(9)} ${a.path}${a.note ? ` (${a.note})` : ""}\n`);
|
|
@@ -256,7 +257,7 @@ async function runStart(args) {
|
|
|
256
257
|
}
|
|
257
258
|
const b = new TicketService({ url: saved.url, key: saved.key });
|
|
258
259
|
await b.login();
|
|
259
|
-
process.stderr.write(`board: ${command[0]} as ${saved.name} on ${saved.url}${command[0] === "claude" ? "; type /pick to take a ticket" : ""}\n`);
|
|
260
|
+
process.stderr.write(terminalText(`board: ${command[0]} as ${saved.name} on ${saved.url}${command[0] === "claude" ? "; type /pick to take a ticket" : ""}\n`));
|
|
260
261
|
const child = spawn(command[0], command.slice(1), {
|
|
261
262
|
stdio: "inherit",
|
|
262
263
|
env: { ...process.env, BOARD_URL: saved.url, BOARD_AGENT_KEY: saved.key, BOARD_AGENT: saved.name },
|
|
@@ -264,7 +265,7 @@ async function runStart(args) {
|
|
|
264
265
|
const code = await new Promise((res) => {
|
|
265
266
|
child.on("exit", (c, signal) => res(c ?? (signal ? 1 : 0)));
|
|
266
267
|
child.on("error", (err) => {
|
|
267
|
-
process.stderr.write(`board: could not start ${command[0]}: ${err.message}\n`);
|
|
268
|
+
process.stderr.write(terminalText(`board: could not start ${command[0]}: ${err.message}\n`));
|
|
268
269
|
res(127);
|
|
269
270
|
});
|
|
270
271
|
});
|
|
@@ -349,7 +350,7 @@ async function main(argvIn) {
|
|
|
349
350
|
follow: opts.includes("--follow"),
|
|
350
351
|
intervalSec: num("--interval", 30),
|
|
351
352
|
lockFile: file.replace(/session-([^/\\]+)\.json$/, "watch-$1.lock"),
|
|
352
|
-
log: (line) => process.stderr.write(`board watch: ${line}\n`),
|
|
353
|
+
log: (line) => process.stderr.write(`board watch: ${terminalLine(line)}\n`),
|
|
353
354
|
usageFrom: usageFrom,
|
|
354
355
|
});
|
|
355
356
|
process.exitCode = code;
|
|
@@ -398,9 +399,9 @@ async function main(argvIn) {
|
|
|
398
399
|
}
|
|
399
400
|
main(process.argv.slice(2)).then((result) => {
|
|
400
401
|
if (result !== undefined)
|
|
401
|
-
process.stdout.write(
|
|
402
|
+
process.stdout.write(terminalJson(result, 2) + "\n");
|
|
402
403
|
}, (err) => {
|
|
403
404
|
const message = err instanceof BoardError || err instanceof UsageError || err instanceof Error ? err.message : String(err);
|
|
404
|
-
process.stderr.write(`board: ${message.split("\n")[0]}\n`);
|
|
405
|
+
process.stderr.write(`board: ${terminalText(message.split("\n")[0])}\n`);
|
|
405
406
|
process.exit(err instanceof UsageError ? 2 : 1);
|
|
406
407
|
});
|
package/dist/mcp.js
CHANGED
|
@@ -10,6 +10,7 @@ import { z } from "zod";
|
|
|
10
10
|
import { PACKAGE_VERSION } from "./init.js";
|
|
11
11
|
import { agentCredentialsFromEnv } from "./pb.js";
|
|
12
12
|
import { BoardError, TicketService } from "./service.js";
|
|
13
|
+
import { terminalText } from "./terminal.js";
|
|
13
14
|
const ticketId = z.string().min(1).describe("Ticket id, as returned by claim");
|
|
14
15
|
const usage = z
|
|
15
16
|
.object({
|
|
@@ -127,14 +128,14 @@ export async function runMcpServer() {
|
|
|
127
128
|
// here may not get): serve anyway, so the agent sees why on its first
|
|
128
129
|
// tool call, and send nothing to any board.
|
|
129
130
|
const message = err instanceof Error ? err.message : String(err);
|
|
130
|
-
console.error(`board MCP: ${message}`);
|
|
131
|
+
console.error(terminalText(`board MCP: ${message}`));
|
|
131
132
|
await createServer(refusingBoard(message)).connect(new StdioServerTransport());
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
// Log in up front so a bad config shows in the MCP logs right away. On
|
|
135
136
|
// failure keep serving: every tool call retries the login and returns the
|
|
136
137
|
// reason as a plain tool error.
|
|
137
|
-
await board.login().then(() => console.error(`board MCP: logged in as ${board.agentName}`), (err) => console.error(`board MCP: ${err instanceof Error ? err.message : String(err)}`));
|
|
138
|
+
await board.login().then(() => console.error(terminalText(`board MCP: logged in as ${board.agentName}`)), (err) => console.error(terminalText(`board MCP: ${err instanceof Error ? err.message : String(err)}`)));
|
|
138
139
|
await createServer(board).connect(new StdioServerTransport());
|
|
139
140
|
}
|
|
140
141
|
/** A stand-in for TicketService whose every call fails with message, before any request. */
|
package/dist/repo.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// ../.wt/<ticket>). BOARD_URL, when set, wins over it.
|
|
12
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
13
13
|
import { dirname, join } from "node:path";
|
|
14
|
+
import { terminalJson } from "./terminal.js";
|
|
14
15
|
export const REPO_FILE = ".mergeline.json";
|
|
15
16
|
/**
|
|
16
17
|
* A board address in one form, so the same board is the same string wherever
|
|
@@ -23,10 +24,10 @@ export function normalizeBoardUrl(raw) {
|
|
|
23
24
|
url = new URL(raw.trim());
|
|
24
25
|
}
|
|
25
26
|
catch {
|
|
26
|
-
throw new Error(
|
|
27
|
+
throw new Error(`${terminalJson(raw)} is not a board address; give it as shown on the board, e.g. https://acme.mergeline.app`);
|
|
27
28
|
}
|
|
28
29
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
29
|
-
throw new Error(
|
|
30
|
+
throw new Error(`${terminalJson(raw)} is not a board address: it must start with https:// (or http://)`);
|
|
30
31
|
}
|
|
31
32
|
return (url.origin + url.pathname).replace(/\/+$/, "");
|
|
32
33
|
}
|
package/dist/terminal.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Text that others chose (a repository's .mergeline.json, a board's ticket
|
|
2
|
+
// titles, event text and error messages) must not drive the developer's
|
|
3
|
+
// terminal: an escape sequence in it can erase or rewrite the lines around
|
|
4
|
+
// it, set the window title, add hyperlinks or write the clipboard. Whatever
|
|
5
|
+
// the CLI, `board watch` and the MCP server write to stdout or stderr goes
|
|
6
|
+
// through one of these; what tools return to the model does not.
|
|
7
|
+
/**
|
|
8
|
+
* The one list. DEL, C1 (U+009B is a CSI on its own) and the bidirectional
|
|
9
|
+
* controls (U+061C, U+200E, U+200F, U+202A to U+202E, U+2066 to U+2069):
|
|
10
|
+
* JSON.stringify leaves them raw.
|
|
11
|
+
*/
|
|
12
|
+
const BEYOND_JSON_CLASS = "\\u007f-\\u009f\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069";
|
|
13
|
+
/** C0 but LF and TAB. */
|
|
14
|
+
const C0_CLASS = "\\u0000-\\u0008\\u000b-\\u001f";
|
|
15
|
+
const BEYOND_JSON = new RegExp(`[${BEYOND_JSON_CLASS}]`, "g");
|
|
16
|
+
const UNSAFE = new RegExp(`[${C0_CLASS}${BEYOND_JSON_CLASS}]`, "g");
|
|
17
|
+
const UNSAFE_OR_LF = new RegExp(`[\\n${C0_CLASS}${BEYOND_JSON_CLASS}]`, "g");
|
|
18
|
+
const escape = (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
19
|
+
/** Text safe for a terminal: every control character but LF and TAB written as a visible \uXXXX. */
|
|
20
|
+
export function terminalText(text) {
|
|
21
|
+
return text.replace(UNSAFE, escape);
|
|
22
|
+
}
|
|
23
|
+
/** One line safe for a terminal: terminalText, with LF also written as \u000a so the text cannot start a line of its own. */
|
|
24
|
+
export function terminalLine(text) {
|
|
25
|
+
return text.replace(UNSAFE_OR_LF, escape);
|
|
26
|
+
}
|
|
27
|
+
/** JSON (still valid) safe for a terminal: JSON.stringify, with DEL, C1 and the bidirectional controls as \u escapes. */
|
|
28
|
+
export function terminalJson(value, indent) {
|
|
29
|
+
return JSON.stringify(value, null, indent).replace(BEYOND_JSON, escape);
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mergeline/agent",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "The agent's side of a Mergeline board: an MCP server and the `board` CLI. Works with any agent tool that runs MCP servers or shell commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "frontender-ua",
|