@mergeline/agent 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/init.js ADDED
@@ -0,0 +1,225 @@
1
+ // `board init`: installs the agent kit (rules, pick and done) into a work
2
+ // repository without overwriting what is there.
3
+ //
4
+ // - AGENTS.md (read by Codex and many other tools) and, with --claude,
5
+ // CLAUDE.md get one section between mergeline markers; the rest of each
6
+ // file is left alone, and running init again updates only that section.
7
+ // - Command and prompt files are written only when missing or when they carry
8
+ // the kit's marker line; a file of the same name that the kit did not write
9
+ // is skipped with a note.
10
+ // - .claude/settings.json gets the kit's permissions added to its lists;
11
+ // .mcp.json gets a `board` server unless it already has one. The agent key
12
+ // is never written: .mcp.json refers to ${BOARD_URL} and ${BOARD_AGENT_KEY}.
13
+ // The permissions also allow the repository's own package manager (from its
14
+ // lockfile) to install and to run its test, lint and typecheck scripts, so an
15
+ // unattended agent does not stop at `pnpm install` in a new worktree.
16
+ // - .mergeline.json (repo.ts) gets the kit's version and, with --url, the
17
+ // board's address, so the board commands in this repository pick that
18
+ // board's saved key. The version is also in the section's start marker and
19
+ // in each kit file's marker line; init finds both by their prefix, so files
20
+ // from an older kit are still updated.
21
+ // - --codex writes the prompts into $CODEX_HOME/prompts (default
22
+ // ~/.codex/prompts) and prints the MCP snippet for ~/.codex/config.toml,
23
+ // which init does not edit. The snippet names the agent; its key stays in
24
+ // the store `board login` writes, not in config.toml.
25
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
26
+ import { homedir } from "node:os";
27
+ import { dirname, join, relative } from "node:path";
28
+ import { fileURLToPath } from "node:url";
29
+ import { readRepoFile, REPO_FILE } from "./repo.js";
30
+ const KIT = fileURLToPath(new URL("../kit/", import.meta.url));
31
+ const PACKAGE = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
32
+ /** This package's npm name, for the npx commands init writes (one place to rename it). */
33
+ export const PACKAGE_NAME = PACKAGE.name;
34
+ /** Sent with every claim as `client`. */
35
+ export const PACKAGE_VERSION = PACKAGE.version;
36
+ /**
37
+ * The version of agent/kit: raise it with every change to the kit's files
38
+ * (kit-check fails until you do). Kit 1 is everything up to package 0.4.0,
39
+ * which wrote no version. The board says when a claim's kit is older than it
40
+ * expects (KIT_MIN in pocketbase/pb_hooks/board_lib.js).
41
+ */
42
+ export const KIT_VERSION = 2;
43
+ const START = `<!-- mergeline:start (kit ${KIT_VERSION}; managed by \`board init\`; edit outside these markers) -->`;
44
+ /** Markers are found by these prefixes, so an edited marker line or an older kit's still counts. */
45
+ const START_PREFIX = "<!-- mergeline:start";
46
+ const END = "<!-- mergeline:end -->";
47
+ const MANAGED = `<!-- mergeline: written by \`board init\` (kit ${KIT_VERSION}); init updates this file while this line is here -->`;
48
+ const MANAGED_PREFIX = "<!-- mergeline: written by `board init`";
49
+ function kit(name) {
50
+ return readFileSync(join(KIT, name), "utf8").replace(/\s+$/, "") + "\n";
51
+ }
52
+ const COMMANDS = {
53
+ pick: "Take the next ticket from the board and work on it",
54
+ done: "Finish the current ticket: test, push, open a PR, submit for review",
55
+ };
56
+ /** Scripts the agent runs before a PR (done.md), when the project has them. */
57
+ const CHECK_SCRIPTS = ["test", "lint", "typecheck", "check"];
58
+ /**
59
+ * The package manager (from the lockfile) and the commands an agent needs in
60
+ * this repository: install, and the check scripts its package.json has.
61
+ */
62
+ export function projectCommands(dir) {
63
+ const has = (f) => existsSync(join(dir, f));
64
+ const manager = has("pnpm-lock.yaml") ? "pnpm" : has("yarn.lock") ? "yarn" : has("bun.lockb") || has("bun.lock") ? "bun" : "npm";
65
+ let scripts = {};
66
+ try {
67
+ scripts = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).scripts ?? {};
68
+ }
69
+ catch {
70
+ if (!has("package.json"))
71
+ return { manager, commands: [] };
72
+ }
73
+ const run = (name) => (manager === "npm" ? (name === "test" ? "npm test" : `npm run ${name}`) : `${manager} ${name}`);
74
+ const commands = [manager === "npm" ? "npm ci" : `${manager} install`, `${manager} install`];
75
+ for (const name of CHECK_SCRIPTS)
76
+ if (typeof scripts[name] === "string")
77
+ commands.push(run(name));
78
+ return { manager, commands: [...new Set(commands)] };
79
+ }
80
+ export function init(opts) {
81
+ const actions = [];
82
+ const write = (path, content, kind) => {
83
+ if (!opts.dryRun && (kind === "create" || kind === "update")) {
84
+ mkdirSync(dirname(path), { recursive: true });
85
+ writeFileSync(path, content);
86
+ }
87
+ };
88
+ const label = (path) => {
89
+ const rel = relative(opts.dir, path);
90
+ return rel.startsWith("..") ? path : rel;
91
+ };
92
+ const record = (path, kind, note) => actions.push({ path: label(path), kind, ...(note ? { note } : {}) });
93
+ /** One marked section in a markdown file; the rest of the file stays. */
94
+ function section(path, body) {
95
+ const block = `${START}\n${body.replace(/\s+$/, "")}\n${END}\n`;
96
+ if (!existsSync(path)) {
97
+ write(path, block, "create");
98
+ return record(path, "create");
99
+ }
100
+ const current = readFileSync(path, "utf8");
101
+ const start = current.indexOf(START_PREFIX);
102
+ const end = current.indexOf(END);
103
+ if (start >= 0 !== end >= 0 || (start >= 0 && end < start)) {
104
+ return record(path, "skip", "its mergeline markers are broken; fix or remove them and run init again");
105
+ }
106
+ let next;
107
+ if (start >= 0) {
108
+ const after = current.slice(end + END.length).replace(/^\n/, "");
109
+ next = current.slice(0, start) + block + after;
110
+ }
111
+ else {
112
+ next = current.replace(/\s*$/, "") + "\n\n" + block;
113
+ }
114
+ if (next === current)
115
+ return record(path, "unchanged");
116
+ write(path, next, "update");
117
+ record(path, "update", start >= 0 ? "mergeline section replaced" : "mergeline section added at the end");
118
+ }
119
+ /** A whole file the kit owns, written only if missing or still marked as the kit's. */
120
+ function owned(path, content) {
121
+ if (!existsSync(path)) {
122
+ write(path, content, "create");
123
+ return record(path, "create");
124
+ }
125
+ const current = readFileSync(path, "utf8");
126
+ if (!current.includes(MANAGED_PREFIX))
127
+ return record(path, "skip", "a file of this name exists and was not written by board init");
128
+ if (current === content)
129
+ return record(path, "unchanged");
130
+ write(path, content, "update");
131
+ record(path, "update");
132
+ }
133
+ /** A JSON file changed by fn; skipped if it does not parse. */
134
+ function json(path, fn) {
135
+ let data = {};
136
+ const exists = existsSync(path);
137
+ const before = exists ? readFileSync(path, "utf8") : "";
138
+ if (exists) {
139
+ try {
140
+ data = JSON.parse(before);
141
+ }
142
+ catch {
143
+ return record(path, "skip", "not valid JSON; left as it is");
144
+ }
145
+ }
146
+ fn(data);
147
+ const next = JSON.stringify(data, null, 2) + "\n";
148
+ if (exists && JSON.stringify(JSON.parse(before)) === JSON.stringify(data))
149
+ return record(path, "unchanged");
150
+ const kind = exists ? "update" : "create";
151
+ write(path, next, kind);
152
+ record(path, kind);
153
+ }
154
+ const promptFile = (name) => `---\ndescription: ${COMMANDS[name]}\n---\n\n${MANAGED}\n\n${kit(`${name}.md`)}`;
155
+ /** .mergeline.json: the kit's version and the board's address (from --url, else the one there). */
156
+ function repoFile(path, url) {
157
+ let current = {};
158
+ if (existsSync(path)) {
159
+ try {
160
+ current = readRepoFile(path);
161
+ }
162
+ catch (err) {
163
+ if (!url) {
164
+ record(path, "skip", `${err instanceof Error ? err.message : String(err)}`);
165
+ return undefined;
166
+ }
167
+ }
168
+ }
169
+ const board = url ?? current.board;
170
+ const content = JSON.stringify({ ...(board ? { board } : {}), kit: KIT_VERSION }, null, 2) + "\n";
171
+ if (!existsSync(path)) {
172
+ write(path, content, "create");
173
+ record(path, "create");
174
+ }
175
+ else if (readFileSync(path, "utf8") === content) {
176
+ record(path, "unchanged");
177
+ }
178
+ else {
179
+ write(path, content, "update");
180
+ record(path, "update", current.board && url && current.board !== url ? `board ${current.board} -> ${url}` : undefined);
181
+ }
182
+ return board;
183
+ }
184
+ const board = repoFile(join(opts.dir, REPO_FILE), opts.url);
185
+ let project = [];
186
+ const rules = kit("rules.md");
187
+ section(join(opts.dir, "AGENTS.md"), rules);
188
+ if (opts.claude) {
189
+ section(join(opts.dir, "CLAUDE.md"), rules);
190
+ owned(join(opts.dir, ".claude", "commands", "pick.md"), promptFile("pick"));
191
+ owned(join(opts.dir, ".claude", "commands", "done.md"), promptFile("done"));
192
+ const ours = JSON.parse(kit("claude-settings.json").replaceAll("{{package}}", PACKAGE_NAME)).permissions;
193
+ project = projectCommands(opts.dir).commands;
194
+ ours.allow = [...ours.allow, ...project.map((c) => `Bash(${c}*)`)];
195
+ json(join(opts.dir, ".claude", "settings.json"), (data) => {
196
+ data.permissions ??= {};
197
+ for (const [list, entries] of Object.entries(ours)) {
198
+ const have = Array.isArray(data.permissions[list]) ? data.permissions[list] : [];
199
+ data.permissions[list] = [...have, ...entries.filter((e) => !have.includes(e))];
200
+ }
201
+ });
202
+ json(join(opts.dir, ".mcp.json"), (data) => {
203
+ data.mcpServers ??= {};
204
+ data.mcpServers.board ??= {
205
+ command: opts.noNpx ? "board" : "npx",
206
+ args: opts.noNpx ? ["mcp"] : ["-y", PACKAGE_NAME, "mcp"],
207
+ // Empty defaults: started by `board start` these are set; otherwise
208
+ // the server uses the key `board login` saved.
209
+ env: { BOARD_URL: "${BOARD_URL:-}", BOARD_AGENT_KEY: "${BOARD_AGENT_KEY:-}", BOARD_AGENT: "${BOARD_AGENT:-}" },
210
+ };
211
+ });
212
+ }
213
+ let codexConfig;
214
+ if (opts.codex) {
215
+ const home = opts.codexHome || process.env.CODEX_HOME || join(homedir(), ".codex");
216
+ owned(join(home, "prompts", "pick.md"), promptFile("pick"));
217
+ owned(join(home, "prompts", "done.md"), promptFile("done"));
218
+ codexConfig = [
219
+ "[mcp_servers.board]",
220
+ ...(opts.noNpx ? ['command = "board"', 'args = ["mcp"]'] : ['command = "npx"', `args = ["-y", "${PACKAGE_NAME}", "mcp"]`]),
221
+ 'env = { BOARD_AGENT = "<agent name>" } # the key saved by: board login <agent name> --url <board> --key <key>',
222
+ ].join("\n");
223
+ }
224
+ return { actions, projectCommands: project, codexConfig, ...(board ? { board } : {}) };
225
+ }
package/dist/mcp.js ADDED
@@ -0,0 +1,133 @@
1
+ // MCP server for a Mergeline board (stdio). One process = one agent session.
2
+ // Started by `board mcp` (cli.ts) or `node dist/index.js`.
3
+ // Credentials come from BOARD_AGENT_KEY (or BOARD_AGENT_EMAIL / BOARD_AGENT_PASSWORD); BOARD_URL
4
+ // defaults to http://127.0.0.1:8090. All board access goes through
5
+ // TicketService.
6
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
+ import { z } from "zod";
9
+ import { PACKAGE_VERSION } from "./init.js";
10
+ import { agentCredentialsFromEnv } from "./pb.js";
11
+ import { BoardError, TicketService } from "./service.js";
12
+ const ticketId = z.string().min(1).describe("Ticket id, as returned by claim");
13
+ const usage = z
14
+ .object({
15
+ input_tokens: z.number().int().min(0).optional(),
16
+ output_tokens: z.number().int().min(0).optional(),
17
+ cache_read_tokens: z.number().int().min(0).optional(),
18
+ cache_write_tokens: z.number().int().min(0).optional(),
19
+ cost: z.number().min(0).optional(),
20
+ currency: z.string().length(3).optional(),
21
+ source: z.string().max(80).optional(),
22
+ })
23
+ .optional()
24
+ .describe("Optional: what this work cost, if your tool reports it (tokens, cost). Leave it out otherwise.");
25
+ async function run(fn) {
26
+ try {
27
+ const result = await fn();
28
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
29
+ }
30
+ catch (err) {
31
+ const message = err instanceof BoardError ? err.message : `board tool failed: ${err instanceof Error ? err.message : String(err)}`;
32
+ return { content: [{ type: "text", text: message }], isError: true };
33
+ }
34
+ }
35
+ export function createServer(board) {
36
+ const server = new McpServer({ name: "board", version: PACKAGE_VERSION });
37
+ server.registerTool("list_mine", {
38
+ title: "List my tickets",
39
+ description: "List the tickets assigned to you that are not done, with status, priority and block. " +
40
+ "Use it to orient yourself; it does not claim anything.",
41
+ annotations: { readOnlyHint: true },
42
+ }, () => run(() => board.listMine()));
43
+ server.registerTool("claim", {
44
+ title: "Claim my next ticket",
45
+ description: "Take your next ticket. Returns the highest-priority ready ticket assigned to you, or " +
46
+ "{ ticket: null } when there is nothing to do: then say so and stop. " +
47
+ "If you already had a ticket in progress (for example after a restart) it returns that one " +
48
+ "with resumed: true; continue it. You hold one ticket at a time. " +
49
+ "The ticket comes with spec_path, branch, answer and notes: the spec on main plus answer and " +
50
+ "notes are your only requirements. Claiming starts a lease (claimed_until); keep it alive with heartbeat. " +
51
+ "If it fails because another session of yours holds your ticket, say so and stop: do not retry and do not " +
52
+ "start other work. If the answer has kit_outdated, tell the human what it says and go on with the ticket.",
53
+ }, () => run(() => board.claim()));
54
+ server.registerTool("heartbeat", {
55
+ title: "Extend lease",
56
+ description: "Extend your lease on the ticket and optionally log a one-line progress note. " +
57
+ "Call it after every meaningful step, at least every 10 minutes. " +
58
+ "If it fails saying to claim again, stop working on the ticket and call claim. If it fails saying another " +
59
+ "session holds the ticket, stop at once: no commit, no push, no PR.",
60
+ inputSchema: {
61
+ ticket_id: ticketId,
62
+ note: z.string().max(500).optional().describe("One line on what you just finished"),
63
+ },
64
+ }, ({ ticket_id, note }) => run(() => board.heartbeat(ticket_id, note)));
65
+ server.registerTool("log_event", {
66
+ title: "Log to ticket",
67
+ description: "Add one human-readable line to the ticket's event log. kind: plan (your 3 to 6 step plan, " +
68
+ "once, after reading the spec), progress (a step done), warn (something a human should notice).",
69
+ inputSchema: {
70
+ ticket_id: ticketId,
71
+ kind: z.enum(["plan", "progress", "warn"]),
72
+ text: z.string().min(1).max(2000),
73
+ },
74
+ }, ({ ticket_id, kind, text }) => run(() => board.logEvent(ticket_id, kind, text)));
75
+ server.registerTool("record_spec", {
76
+ title: "Record spec commit",
77
+ description: "Record which commit of main you read the spec from. Call it once, right after reading the " +
78
+ "spec, with the output of `git rev-parse origin/main`.",
79
+ inputSchema: {
80
+ ticket_id: ticketId,
81
+ sha: z.string().regex(/^[0-9a-fA-F]{7,40}$/, "a git commit hash"),
82
+ },
83
+ }, ({ ticket_id, sha }) => run(() => board.recordSpec(ticket_id, sha)));
84
+ server.registerTool("ask_human", {
85
+ title: "Ask a human",
86
+ description: "Use when the spec (plus the ticket's answer and notes) does not answer a question that " +
87
+ "changes behavior. Ask exactly one concrete question. After calling it, stop working on this " +
88
+ "ticket and do not guess: no further commits, no PR. The ticket goes back to ready with a " +
89
+ "question block and comes back to you with the answer on a later claim.",
90
+ inputSchema: {
91
+ ticket_id: ticketId,
92
+ question: z.string().min(1).max(2000).describe("One concrete question a human can answer in a sentence"),
93
+ },
94
+ }, ({ ticket_id, question }) => run(() => board.askHuman(ticket_id, question)));
95
+ server.registerTool("submit_for_review", {
96
+ title: "Submit for review",
97
+ description: "Hand the ticket back for human review once its PR is open. pr_url is the URL printed by " +
98
+ "`gh pr create`; summary is 2 to 4 lines on what changed. This ends your work on the ticket. " +
99
+ "Never try to mark a ticket done: only a human does that.",
100
+ inputSchema: {
101
+ ticket_id: ticketId,
102
+ pr_url: z.string().regex(/^https?:\/\/\S+$/, "the pull request URL"),
103
+ summary: z.string().min(1).max(1500),
104
+ usage,
105
+ },
106
+ }, ({ ticket_id, pr_url, summary, usage }) => run(() => board.submitForReview(ticket_id, pr_url, summary, usage)));
107
+ server.registerTool("release", {
108
+ title: "Release ticket",
109
+ description: "Give the ticket back unfinished when you cannot continue for a reason that is not a spec " +
110
+ "question (for a spec question use ask_human). reason: one line. Stop working on it afterwards.",
111
+ inputSchema: {
112
+ ticket_id: ticketId,
113
+ reason: z.string().min(1).max(500),
114
+ usage,
115
+ },
116
+ }, ({ ticket_id, reason, usage }) => run(() => board.release(ticket_id, reason, usage)));
117
+ return server;
118
+ }
119
+ export async function runMcpServer() {
120
+ let board;
121
+ try {
122
+ board = new TicketService(agentCredentialsFromEnv());
123
+ }
124
+ catch (err) {
125
+ console.error(`board MCP: ${err instanceof Error ? err.message : String(err)}`);
126
+ process.exit(1);
127
+ }
128
+ // Log in up front so a bad config shows in the MCP logs right away. On
129
+ // failure keep serving: every tool call retries the login and returns the
130
+ // reason as a plain tool error.
131
+ 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)}`));
132
+ await createServer(board).connect(new StdioServerTransport());
133
+ }
package/dist/pb.js ADDED
@@ -0,0 +1,25 @@
1
+ // Board connection settings for an agent session: the environment first,
2
+ // else a key saved on this machine by `board login` (credentials.ts) for the
3
+ // board in use (BOARD_URL, or the repository's .mergeline.json: repo.ts).
4
+ // The PocketBase client itself lives in service.ts, the only module that
5
+ // imports the PocketBase SDK.
6
+ import { pickSaved } from "./credentials.js";
7
+ import { boardInContext } from "./repo.js";
8
+ export const DEFAULT_BOARD_URL = "http://127.0.0.1:8090";
9
+ export function agentCredentialsFromEnv(env = process.env, cwd = process.cwd()) {
10
+ const board = boardInContext(env, cwd);
11
+ const url = board?.url || DEFAULT_BOARD_URL;
12
+ const key = env.BOARD_AGENT_KEY?.trim();
13
+ if (key)
14
+ return { url, key };
15
+ const email = env.BOARD_AGENT_EMAIL?.trim();
16
+ const password = env.BOARD_AGENT_PASSWORD;
17
+ if (email && password)
18
+ return { url, email, password };
19
+ // BOARD_AGENT names a saved agent; without it, the only one saved (for the board in use, if any).
20
+ const saved = pickSaved(env.BOARD_AGENT?.trim() || undefined, board, env);
21
+ if (saved)
22
+ return { url: saved.url, key: saved.key };
23
+ throw new Error(`No agent key${board ? ` for ${board.url}` : ""}: run board login <name> --url ${board?.url ?? "<board>"} --key <key> once ` +
24
+ "(the key is shown when the agent is added on the board), or set BOARD_AGENT_KEY");
25
+ }
package/dist/repo.js ADDED
@@ -0,0 +1,86 @@
1
+ // Which board a repository works with and which kit it has: `board init`
2
+ // writes .mergeline.json at the repository's root (no secrets; committed),
3
+ // with the board's address when given --url, so `board start <name>` there
4
+ // picks that board's saved key, and the kit's version, which claims carry so
5
+ // the board can say when the kit is old.
6
+ //
7
+ // { "board": "https://acme.mergeline.app", "kit": 2 }
8
+ //
9
+ // The file is looked up from the current folder upwards, up to the root of
10
+ // the git checkout (a folder with .git, which is a file in a worktree such as
11
+ // ../.wt/<ticket>). BOARD_URL, when set, wins over it.
12
+ import { existsSync, readFileSync } from "node:fs";
13
+ import { dirname, join } from "node:path";
14
+ export const REPO_FILE = ".mergeline.json";
15
+ /**
16
+ * A board address in one form, so the same board is the same string wherever
17
+ * it was typed: http(s) only, scheme and host lower-case, no default port, no
18
+ * trailing slash.
19
+ */
20
+ export function normalizeBoardUrl(raw) {
21
+ let url;
22
+ try {
23
+ url = new URL(raw.trim());
24
+ }
25
+ catch {
26
+ throw new Error(`"${raw}" is not a board address; give it as shown on the board, e.g. https://acme.mergeline.app`);
27
+ }
28
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
29
+ throw new Error(`"${raw}" is not a board address: it must start with https:// (or http://)`);
30
+ }
31
+ return (url.origin + url.pathname).replace(/\/+$/, "");
32
+ }
33
+ /** The .mergeline.json that applies in dir, or null. */
34
+ export function findRepoFile(dir) {
35
+ for (let d = dir;; d = dirname(d)) {
36
+ const file = join(d, REPO_FILE);
37
+ if (existsSync(file))
38
+ return file;
39
+ if (existsSync(join(d, ".git")) || dirname(d) === d)
40
+ return null;
41
+ }
42
+ }
43
+ /** A .mergeline.json's contents; an error that says which file when it is broken. */
44
+ export function readRepoFile(file) {
45
+ let data;
46
+ try {
47
+ data = JSON.parse(readFileSync(file, "utf8"));
48
+ }
49
+ catch {
50
+ throw new Error(`${file} is not valid JSON; run board init --url <board> to write it again`);
51
+ }
52
+ const { board, kit } = (data ?? {});
53
+ const out = {};
54
+ if (board !== undefined) {
55
+ if (typeof board !== "string" || !board)
56
+ throw new Error(`${file} has no "board" address; run board init --url <board>`);
57
+ try {
58
+ out.board = normalizeBoardUrl(board);
59
+ }
60
+ catch (err) {
61
+ throw new Error(`${file}: ${err instanceof Error ? err.message : String(err)}`);
62
+ }
63
+ }
64
+ if (typeof kit === "number" && Number.isInteger(kit))
65
+ out.kit = kit;
66
+ return out;
67
+ }
68
+ /** The kit version of the repository around cwd, or undefined (no file, no version, or a broken file). */
69
+ export function repoKit(cwd = process.cwd()) {
70
+ const file = findRepoFile(cwd);
71
+ try {
72
+ return file ? readRepoFile(file).kit : undefined;
73
+ }
74
+ catch {
75
+ return undefined;
76
+ }
77
+ }
78
+ /** The board in use here: BOARD_URL, else the repository's .mergeline.json, else null. */
79
+ export function boardInContext(env = process.env, cwd = process.cwd()) {
80
+ const fromEnv = env.BOARD_URL?.trim();
81
+ if (fromEnv)
82
+ return { url: normalizeBoardUrl(fromEnv), from: "BOARD_URL" };
83
+ const file = findRepoFile(cwd);
84
+ const board = file ? readRepoFile(file).board : undefined;
85
+ return board ? { url: board, from: file } : null;
86
+ }