@bli-cockpit/mcp 0.1.0 → 0.1.2
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/README.md +64 -8
- package/dist/jarvis-answer-envelope.d.ts +107 -0
- package/dist/jarvis-answer-envelope.js +82 -0
- package/dist/jarvis-door.d.ts +95 -0
- package/dist/jarvis-door.js +163 -0
- package/dist/jarvis-tools.d.ts +50 -0
- package/dist/jarvis-tools.js +248 -0
- package/dist/jarvis-turn-bookmark.d.ts +25 -0
- package/dist/jarvis-turn-bookmark.js +43 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +11 -1
- package/dist/verb-census.d.ts +41 -0
- package/dist/verb-census.js +108 -0
- package/dist/work-tools.d.ts +28 -0
- package/dist/work-tools.js +233 -0
- package/package.json +2 -2
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `jarvis_*` MCP tools (BLI-3732) — JARVIS on the `bli-tower` server, over the
|
|
3
|
+
* exact doors `cockpit jarvis` calls with this machine's device token.
|
|
4
|
+
*
|
|
5
|
+
* The point of this file in one sentence: an agent on Codex or Claude Code
|
|
6
|
+
* should be able to ask JARVIS a question, read how it answered, and spend a
|
|
7
|
+
* human's coding-arm approval, without a browser and without a second
|
|
8
|
+
* vocabulary. Four tools, three doors, no new server-side surface:
|
|
9
|
+
*
|
|
10
|
+
* jarvis_ask POST /api/jarvis/cli one turn, the same one
|
|
11
|
+
* `cockpit jarvis` takes
|
|
12
|
+
* jarvis_trace GET /api/ops/trace/<id> that turn's step tree, rendered
|
|
13
|
+
* SERVER-side and printed verbatim
|
|
14
|
+
* jarvis_dispatch POST /api/jarvis/cli a coding-arm turn, carrying the
|
|
15
|
+
* jarvis_check person's own approval code
|
|
16
|
+
*
|
|
17
|
+
* The wire mechanics they share — the session gate, the request the dashboard
|
|
18
|
+
* actually receives, the envelope it becomes, and what `last` resolves to —
|
|
19
|
+
* live in `jarvis-door.ts`, so this file reads as four tool descriptions,
|
|
20
|
+
* which is the part a person and a model both have to understand.
|
|
21
|
+
*
|
|
22
|
+
* ## The one contract
|
|
23
|
+
*
|
|
24
|
+
* `jarvis_ask` answers with `jarvis-answer-envelope.ts` — the same object
|
|
25
|
+
* `cockpit jarvis --json` prints. A script and an agent read one shape.
|
|
26
|
+
*
|
|
27
|
+
* ## The approval code, and what this surface can and cannot prove
|
|
28
|
+
*
|
|
29
|
+
* The coding arm's gate (BLI-2981) has two locks: the code is an HMAC over the
|
|
30
|
+
* exact plan folded with the asking account, and it must have come out of the
|
|
31
|
+
* HUMAN's own message. Lock 1 is untouched here — this server holds no secret
|
|
32
|
+
* and cannot compute a code for any plan, so an invented code is refused by
|
|
33
|
+
* the dashboard exactly as it always was.
|
|
34
|
+
*
|
|
35
|
+
* Lock 2 is weaker on THIS surface than it is in a terminal, and saying so is
|
|
36
|
+
* the honest thing to do. In a terminal the person types the code themselves.
|
|
37
|
+
* Through MCP the code arrives as a tool argument, and the dashboard cannot
|
|
38
|
+
* tell a code a person handed their agent from one the agent lifted out of the
|
|
39
|
+
* previous answer by itself. So: this tool takes the code as a parameter, it
|
|
40
|
+
* NEVER derives, guesses or fabricates one, its description tells the model in
|
|
41
|
+
* plain words that the code must come from the person, and every relay is
|
|
42
|
+
* logged (presence and length only, never the code). Anything stronger — a
|
|
43
|
+
* per-code single use, an out-of-band confirmation — is a server-side change
|
|
44
|
+
* to the gate itself and belongs with the gate, not here.
|
|
45
|
+
*/
|
|
46
|
+
import { z } from "zod";
|
|
47
|
+
import { callAgentDoor } from "./agent-door.js";
|
|
48
|
+
import { APPROVAL_CODE, defaultLog, doorFailureText, errorResult, READ_TIMEOUT_MS, resolveLastTurn, TAG, takeTurn, textResult, withSession, } from "./jarvis-door.js";
|
|
49
|
+
export function registerJarvisTools(server, deps) {
|
|
50
|
+
const register = server.registerTool.bind(server);
|
|
51
|
+
// The newest turn this SERVER took, so `jarvis_trace last` works in a fresh
|
|
52
|
+
// process that has asked something but never opened a terminal. It is only
|
|
53
|
+
// ever read here; the collector's own bookmark file is read as a fallback
|
|
54
|
+
// and deliberately never written, so a background agent cannot clobber the
|
|
55
|
+
// turn a person is in the middle of tracing.
|
|
56
|
+
let lastTurn = { turnId: null, traceThreadId: null };
|
|
57
|
+
const remember = (turn) => {
|
|
58
|
+
if (turn.turnId || turn.traceThreadId)
|
|
59
|
+
lastTurn = turn;
|
|
60
|
+
};
|
|
61
|
+
register("jarvis_ask", {
|
|
62
|
+
title: "Ask JARVIS",
|
|
63
|
+
description: "Asks JARVIS one question and returns its answer, the Source: lines behind it, this turn's "
|
|
64
|
+
+ "turn_id and the conversation's thread_id. Same JARVIS, same tool belt and same evidence "
|
|
65
|
+
+ "rules as Tower web chat, the Slack DM and `cockpit jarvis`. Pass thread to continue an "
|
|
66
|
+
+ "earlier conversation; pass the returned turn_id to jarvis_trace to see how the answer was "
|
|
67
|
+
+ "reached. JARVIS speaks as the person this machine is paired to and cannot be made to "
|
|
68
|
+
+ "speak as anyone else.",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
question: z.string().min(1).max(50_000).describe("What to ask, in plain words."),
|
|
71
|
+
thread: z
|
|
72
|
+
.string()
|
|
73
|
+
.min(1)
|
|
74
|
+
.max(200)
|
|
75
|
+
.optional()
|
|
76
|
+
.describe('The conversation to continue. Omit for "main", the default terminal thread.'),
|
|
77
|
+
subject: z
|
|
78
|
+
.string()
|
|
79
|
+
.min(1)
|
|
80
|
+
.max(200)
|
|
81
|
+
.optional()
|
|
82
|
+
.describe("Whose person page the question is ABOUT (a name or email). Never who is authenticated — "
|
|
83
|
+
+ "the server decides what this caller may read about them."),
|
|
84
|
+
date: z
|
|
85
|
+
.string()
|
|
86
|
+
.min(1)
|
|
87
|
+
.max(20)
|
|
88
|
+
.optional()
|
|
89
|
+
.describe('YYYY-MM-DD, "today" or "yesterday" — binds that day\'s page. Sent verbatim.'),
|
|
90
|
+
model: z
|
|
91
|
+
.string()
|
|
92
|
+
.min(1)
|
|
93
|
+
.max(120)
|
|
94
|
+
.optional()
|
|
95
|
+
.describe("A provider:model key to request. An unknown key is refused by the dashboard."),
|
|
96
|
+
},
|
|
97
|
+
}, async (args) => withSession(deps, async (session) => {
|
|
98
|
+
const { result } = await takeTurn(deps, session, "jarvis_ask", {
|
|
99
|
+
question: String(args.question ?? ""),
|
|
100
|
+
thread: typeof args.thread === "string" ? args.thread : "main",
|
|
101
|
+
...(typeof args.subject === "string" ? { subject: args.subject } : {}),
|
|
102
|
+
...(typeof args.date === "string" ? { date: args.date } : {}),
|
|
103
|
+
...(typeof args.model === "string" ? { model: args.model } : {}),
|
|
104
|
+
}, remember);
|
|
105
|
+
return result;
|
|
106
|
+
}));
|
|
107
|
+
register("jarvis_trace", {
|
|
108
|
+
title: "How JARVIS answered",
|
|
109
|
+
description: "The step tree of one JARVIS turn — every model step, tool call and server-side memory step, "
|
|
110
|
+
+ "with how long each took, which model ran it, what it spent and what failed. This is the "
|
|
111
|
+
+ "same tree `cockpit jarvis --trace` prints, rendered by the server and relayed verbatim. "
|
|
112
|
+
+ 'Metadata only: no prompt, no answer, no tool argument. Pass "last" for the newest turn '
|
|
113
|
+
+ "this server asked, or the turn_id jarvis_ask returned.",
|
|
114
|
+
inputSchema: {
|
|
115
|
+
turn_id: z
|
|
116
|
+
.string()
|
|
117
|
+
.min(1)
|
|
118
|
+
.max(200)
|
|
119
|
+
.describe('A turn_id from jarvis_ask, or "last".'),
|
|
120
|
+
},
|
|
121
|
+
}, async (args) => withSession(deps, async (session) => {
|
|
122
|
+
const log = deps.log ?? defaultLog;
|
|
123
|
+
const requested = String(args.turn_id ?? "");
|
|
124
|
+
let traceId = requested;
|
|
125
|
+
let resolvedFrom = "argument";
|
|
126
|
+
if (requested.toLowerCase() === "last") {
|
|
127
|
+
const resolved = await resolveLastTurn(deps, session, lastTurn);
|
|
128
|
+
if (!resolved.ok) {
|
|
129
|
+
log(`${TAG} trace unavailable ${JSON.stringify({ reason: resolved.reason })}`);
|
|
130
|
+
return errorResult(resolved.message);
|
|
131
|
+
}
|
|
132
|
+
traceId = resolved.traceId;
|
|
133
|
+
resolvedFrom = resolved.from;
|
|
134
|
+
}
|
|
135
|
+
const response = await callAgentDoor(session, deps.fetchImpl, "GET", `/api/ops/trace/${encodeURIComponent(traceId)}`, undefined, READ_TIMEOUT_MS);
|
|
136
|
+
if (!response.ok)
|
|
137
|
+
return errorResult(doorFailureText("jarvis_trace", response));
|
|
138
|
+
const body = response.body;
|
|
139
|
+
if (body.ok === false) {
|
|
140
|
+
log(`${TAG} trace unavailable ${JSON.stringify({ reason: body.error ?? "trace_unavailable" })}`);
|
|
141
|
+
return errorResult(`Tower has no step tree for that turn (${body.error ?? "trace_unavailable"}). `
|
|
142
|
+
+ (body.message ?? "Traces are kept for 30 days."));
|
|
143
|
+
}
|
|
144
|
+
const lines = body.lines ?? [];
|
|
145
|
+
log(`${TAG} trace read ${JSON.stringify({
|
|
146
|
+
resolved_from: resolvedFrom,
|
|
147
|
+
lines: lines.length,
|
|
148
|
+
truncated: body.truncated ?? false,
|
|
149
|
+
})}`);
|
|
150
|
+
const rendered = [
|
|
151
|
+
`Turn ${traceId}`,
|
|
152
|
+
...(body.headline ? [body.headline] : []),
|
|
153
|
+
"",
|
|
154
|
+
...(lines.length > 0 ? lines : ["That turn recorded no steps."]),
|
|
155
|
+
...(body.truncated ? ["", "Only the first 1000 spans of this turn are shown."] : []),
|
|
156
|
+
].join("\n");
|
|
157
|
+
return textResult(rendered, {
|
|
158
|
+
turn_id: traceId,
|
|
159
|
+
resolved_from: resolvedFrom,
|
|
160
|
+
headline: body.headline ?? null,
|
|
161
|
+
lines,
|
|
162
|
+
truncated: body.truncated ?? false,
|
|
163
|
+
...(body.trace ? { trace: body.trace } : {}),
|
|
164
|
+
});
|
|
165
|
+
}));
|
|
166
|
+
register("jarvis_dispatch", {
|
|
167
|
+
title: "Dispatch a coding task to JARVIS's coding arm",
|
|
168
|
+
description: "Asks JARVIS to run a coding task on the runner: it clones the repo, works, pushes a branch "
|
|
169
|
+
+ "and opens a pull request. It never merges. TWO CALLS, always. Call this once WITHOUT "
|
|
170
|
+
+ "approval_code to get the plan and the 8-character confirmation code back; show both to the "
|
|
171
|
+
+ "person; call it again with the code THEY give you and the same instruction. Never derive, "
|
|
172
|
+
+ "guess, or reuse a code the person has not just handed you — a code you produce yourself is "
|
|
173
|
+
+ "exactly what the approval gate exists to refuse.",
|
|
174
|
+
inputSchema: {
|
|
175
|
+
instruction: z
|
|
176
|
+
.string()
|
|
177
|
+
.min(1)
|
|
178
|
+
.max(50_000)
|
|
179
|
+
.describe("What the coding task should do, in full. This is the birth prompt the arm runs."),
|
|
180
|
+
repo: z
|
|
181
|
+
.string()
|
|
182
|
+
.min(1)
|
|
183
|
+
.max(200)
|
|
184
|
+
.optional()
|
|
185
|
+
.describe("Which repo, if the instruction does not already name one. Server-side allowlist applies."),
|
|
186
|
+
approval_code: z
|
|
187
|
+
.string()
|
|
188
|
+
.min(1)
|
|
189
|
+
.max(64)
|
|
190
|
+
.optional()
|
|
191
|
+
.describe("The 8-character hex confirmation code THE PERSON read back to you from the previous "
|
|
192
|
+
+ "call's plan. Omit it on the first call."),
|
|
193
|
+
thread: z.string().min(1).max(200).optional().describe('Defaults to "main".'),
|
|
194
|
+
},
|
|
195
|
+
}, async (args) => withSession(deps, async (session) => {
|
|
196
|
+
const log = deps.log ?? defaultLog;
|
|
197
|
+
const code = typeof args.approval_code === "string" ? args.approval_code.trim() : "";
|
|
198
|
+
if (code.length > 0 && !APPROVAL_CODE.test(code)) {
|
|
199
|
+
// Refused HERE rather than relayed: a malformed code cannot be the
|
|
200
|
+
// one JARVIS issued, and pasting it into the question would put
|
|
201
|
+
// unvalidated text where the server scans for approvals.
|
|
202
|
+
log(`${TAG} dispatch refused ${JSON.stringify({ reason: "approval_code_malformed", chars: code.length })}`);
|
|
203
|
+
return errorResult("That approval code is not a confirmation code (it must be exactly 8 hex characters, "
|
|
204
|
+
+ "e.g. 3f9c1a02). Ask the person for the code JARVIS printed with the plan — do not "
|
|
205
|
+
+ "construct one.");
|
|
206
|
+
}
|
|
207
|
+
log(`${TAG} dispatch relay ${JSON.stringify({
|
|
208
|
+
approval_code_present: code.length > 0,
|
|
209
|
+
instruction_chars: String(args.instruction ?? "").length,
|
|
210
|
+
repo_named: typeof args.repo === "string",
|
|
211
|
+
})}`);
|
|
212
|
+
const question = [
|
|
213
|
+
code.length > 0
|
|
214
|
+
? "Dispatch this coding task to the coding arm now."
|
|
215
|
+
: "Propose a coding task for the coding arm. Do not dispatch it yet — read back the plan and the confirmation code so the person can approve it.",
|
|
216
|
+
...(typeof args.repo === "string" ? [`Repo: ${args.repo}`] : []),
|
|
217
|
+
"",
|
|
218
|
+
String(args.instruction ?? ""),
|
|
219
|
+
...(code.length > 0
|
|
220
|
+
? ["", `The person approved this plan. Confirmation code: ${code.toLowerCase()}`]
|
|
221
|
+
: []),
|
|
222
|
+
].join("\n");
|
|
223
|
+
const { result } = await takeTurn(deps, session, "jarvis_dispatch", { question, thread: typeof args.thread === "string" ? args.thread : "main" }, remember);
|
|
224
|
+
return result;
|
|
225
|
+
}));
|
|
226
|
+
register("jarvis_check", {
|
|
227
|
+
title: "Check a dispatched coding task",
|
|
228
|
+
description: "Asks JARVIS where a coding task it dispatched has got to — queued, running, pushed, or "
|
|
229
|
+
+ "failed, and the pull request when there is one. Takes no approval: reading a task's state "
|
|
230
|
+
+ "starts nothing.",
|
|
231
|
+
inputSchema: {
|
|
232
|
+
task: z
|
|
233
|
+
.string()
|
|
234
|
+
.min(1)
|
|
235
|
+
.max(200)
|
|
236
|
+
.optional()
|
|
237
|
+
.describe("The task id JARVIS named when it dispatched. Omit to ask about the recent ones."),
|
|
238
|
+
thread: z.string().min(1).max(200).optional().describe('Defaults to "main".'),
|
|
239
|
+
},
|
|
240
|
+
}, async (args) => withSession(deps, async (session) => {
|
|
241
|
+
const task = typeof args.task === "string" ? args.task.trim() : "";
|
|
242
|
+
const question = task.length > 0
|
|
243
|
+
? `Check the coding task ${task} and tell me its status, its branch and its pull request if it has one.`
|
|
244
|
+
: "Check the coding tasks dispatched for me recently and tell me the status of each.";
|
|
245
|
+
const { result } = await takeTurn(deps, session, "jarvis_check", { question, thread: typeof args.thread === "string" ? args.thread : "main" }, remember);
|
|
246
|
+
return result;
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The turn `cockpit jarvis --trace last` would open, read from the same
|
|
3
|
+
* bookmark the collector writes (BLI-3560, read here for BLI-3732).
|
|
4
|
+
*
|
|
5
|
+
* `jarvis_trace last` prefers the turn THIS server just took. This file is the
|
|
6
|
+
* fallback for the other case: a fresh MCP process that has asked nothing yet,
|
|
7
|
+
* on a machine where the person has been talking to JARVIS in a terminal. Both
|
|
8
|
+
* surfaces then mean the same turn by "last", which is the whole point.
|
|
9
|
+
*
|
|
10
|
+
* READ ONLY, deliberately. A background agent asking questions must not
|
|
11
|
+
* overwrite the bookmark a person is in the middle of tracing, so this server
|
|
12
|
+
* never writes the file — only `cockpit jarvis` does.
|
|
13
|
+
*
|
|
14
|
+
* The file holds two opaque ids and a timestamp. No question, no answer, no
|
|
15
|
+
* name. Nothing here ever throws: a missing or unreadable bookmark is "nothing
|
|
16
|
+
* is remembered", which is a real answer and the caller says so in a sentence.
|
|
17
|
+
*/
|
|
18
|
+
/** The collector's own name for it — `jarvis-trace.ts` `LAST_TURN_FILE`. */
|
|
19
|
+
export declare const LAST_TURN_FILE = "last-turn-trace.json";
|
|
20
|
+
export interface CollectorTurnBookmark {
|
|
21
|
+
traceId: string | null;
|
|
22
|
+
threadId: string | null;
|
|
23
|
+
}
|
|
24
|
+
export declare function collectorTurnBookmarkPath(homeDir?: string): string;
|
|
25
|
+
export declare function readCollectorTurnBookmark(homeDir?: string): Promise<CollectorTurnBookmark | null>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The turn `cockpit jarvis --trace last` would open, read from the same
|
|
3
|
+
* bookmark the collector writes (BLI-3560, read here for BLI-3732).
|
|
4
|
+
*
|
|
5
|
+
* `jarvis_trace last` prefers the turn THIS server just took. This file is the
|
|
6
|
+
* fallback for the other case: a fresh MCP process that has asked nothing yet,
|
|
7
|
+
* on a machine where the person has been talking to JARVIS in a terminal. Both
|
|
8
|
+
* surfaces then mean the same turn by "last", which is the whole point.
|
|
9
|
+
*
|
|
10
|
+
* READ ONLY, deliberately. A background agent asking questions must not
|
|
11
|
+
* overwrite the bookmark a person is in the middle of tracing, so this server
|
|
12
|
+
* never writes the file — only `cockpit jarvis` does.
|
|
13
|
+
*
|
|
14
|
+
* The file holds two opaque ids and a timestamp. No question, no answer, no
|
|
15
|
+
* name. Nothing here ever throws: a missing or unreadable bookmark is "nothing
|
|
16
|
+
* is remembered", which is a real answer and the caller says so in a sentence.
|
|
17
|
+
*/
|
|
18
|
+
import { readFile } from "node:fs/promises";
|
|
19
|
+
import os from "node:os";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { getUserLocalCockpitPaths } from "@bli-cockpit/telemetry-core";
|
|
22
|
+
/** The collector's own name for it — `jarvis-trace.ts` `LAST_TURN_FILE`. */
|
|
23
|
+
export const LAST_TURN_FILE = "last-turn-trace.json";
|
|
24
|
+
export function collectorTurnBookmarkPath(homeDir = os.homedir()) {
|
|
25
|
+
return path.join(getUserLocalCockpitPaths(homeDir).state_dir, LAST_TURN_FILE);
|
|
26
|
+
}
|
|
27
|
+
export async function readCollectorTurnBookmark(homeDir) {
|
|
28
|
+
try {
|
|
29
|
+
const raw = await readFile(collectorTurnBookmarkPath(homeDir), "utf8");
|
|
30
|
+
const parsed = JSON.parse(raw);
|
|
31
|
+
const traceId = typeof parsed.traceId === "string" ? parsed.traceId : null;
|
|
32
|
+
const threadId = typeof parsed.threadId === "string" ? parsed.threadId : null;
|
|
33
|
+
if (!traceId && !threadId)
|
|
34
|
+
return null;
|
|
35
|
+
return { traceId, threadId };
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Missing, unreadable, or not JSON — all three mean the same thing to the
|
|
39
|
+
// one caller, which names it (`no_remembered_turn`) rather than printing
|
|
40
|
+
// nothing.
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/server.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface ServerDeps {
|
|
|
19
19
|
fetchImpl: FetchImpl;
|
|
20
20
|
}
|
|
21
21
|
export declare const PACKAGE_NAME = "@bli-cockpit/mcp";
|
|
22
|
-
export declare const PACKAGE_VERSION = "0.1.
|
|
22
|
+
export declare const PACKAGE_VERSION = "0.1.2";
|
|
23
23
|
export declare const emitEventInput: {
|
|
24
24
|
ticket_id: z.ZodString;
|
|
25
25
|
event_type: z.ZodString;
|
package/dist/server.js
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { registerDocsMsgTools } from "./docs-msg-tools.js";
|
|
10
|
+
import { registerJarvisTools } from "./jarvis-tools.js";
|
|
11
|
+
import { registerWorkTools } from "./work-tools.js";
|
|
10
12
|
export const PACKAGE_NAME = "@bli-cockpit/mcp";
|
|
11
|
-
export const PACKAGE_VERSION = "0.1.
|
|
13
|
+
export const PACKAGE_VERSION = "0.1.2";
|
|
12
14
|
// ---- input schemas (Zod raw shapes) -----------------------------------------
|
|
13
15
|
export const emitEventInput = {
|
|
14
16
|
ticket_id: z
|
|
@@ -370,5 +372,13 @@ export function createServer(deps) {
|
|
|
370
372
|
// no `cockpit login` pairing yet still serves the three event tools; only a
|
|
371
373
|
// docs/msg call on that machine fails, by name.
|
|
372
374
|
registerDocsMsgTools(server, { fetchImpl: deps.fetchImpl });
|
|
375
|
+
// BLI-3716: `work_*` — the issue tracker, on the same device-token path as
|
|
376
|
+
// the docs/msg tools above, for the same reason: a coding session should
|
|
377
|
+
// file and move a Tower issue the way it files and moves a Linear one.
|
|
378
|
+
registerWorkTools(server, { fetchImpl: deps.fetchImpl });
|
|
379
|
+
// BLI-3732: `jarvis_*` — the assistant itself, on the same device-token path
|
|
380
|
+
// as the three families above, over the doors `cockpit jarvis` already
|
|
381
|
+
// calls. It is the last Tower surface that had a CLI door and no MCP one.
|
|
382
|
+
registerJarvisTools(server, { fetchImpl: deps.fetchImpl });
|
|
373
383
|
return server;
|
|
374
384
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `cockpit <noun> <verb>` that talks to Tower, read off the collector's
|
|
3
|
+
* own decision tables (BLI-3732).
|
|
4
|
+
*
|
|
5
|
+
* This is a test helper with no runtime consumer, kept out of the suite file
|
|
6
|
+
* so the census itself — the three lists a person actually reviews — reads as
|
|
7
|
+
* a list and not as a parser. It reads SOURCE TEXT rather than importing the
|
|
8
|
+
* collector, because this package declares no dependency on it (the same
|
|
9
|
+
* reason `agent-door-session.ts` copies a session reader instead of importing
|
|
10
|
+
* one).
|
|
11
|
+
*
|
|
12
|
+
* ## Where each half comes from
|
|
13
|
+
*
|
|
14
|
+
* - The NOUNS are the `parse<Noun>Args` functions `local-args-tower.ts`
|
|
15
|
+
* re-exports. That file is the authoritative "these are the commands that
|
|
16
|
+
* talk to Tower" table — its siblings are a filing decision, not a contract.
|
|
17
|
+
* - The VERBS are each noun's `action:` union in `LocalCommand`
|
|
18
|
+
* (`local-args.ts`), with an `XAction` alias resolved from whichever
|
|
19
|
+
* `local-args-tower-*.ts` declares it. A noun with no `action` field is one
|
|
20
|
+
* verb wearing the noun's own name (`jarvis`, `correct`, `workbook`).
|
|
21
|
+
*
|
|
22
|
+
* ## What it deliberately does NOT see
|
|
23
|
+
*
|
|
24
|
+
* Mode FLAGS. `cockpit jarvis --trace`, `--threads` and `--history` are three
|
|
25
|
+
* different acts behind one noun, and no decision table calls them verbs, so
|
|
26
|
+
* the mechanical rule cannot find them. They are covered by hand in the
|
|
27
|
+
* census's own twin map (`jarvis --trace` → `jarvis_trace`); a flag that grows
|
|
28
|
+
* into a verb will show up here the moment it becomes an `action`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const COLLECTOR_COMMANDS_DIR: string;
|
|
31
|
+
export interface TowerVerb {
|
|
32
|
+
noun: string;
|
|
33
|
+
/** The action word, or "" for a noun that is its own single verb. */
|
|
34
|
+
action: string;
|
|
35
|
+
/** How a person types it: `docs read`, or just `jarvis`. */
|
|
36
|
+
spelling: string;
|
|
37
|
+
}
|
|
38
|
+
/** `parseJarvisArgs` → `jarvis`. The re-export table IS the noun list. */
|
|
39
|
+
export declare function towerNouns(): string[];
|
|
40
|
+
/** Every Tower verb a person may type today. */
|
|
41
|
+
export declare function towerVerbs(): TowerVerb[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `cockpit <noun> <verb>` that talks to Tower, read off the collector's
|
|
3
|
+
* own decision tables (BLI-3732).
|
|
4
|
+
*
|
|
5
|
+
* This is a test helper with no runtime consumer, kept out of the suite file
|
|
6
|
+
* so the census itself — the three lists a person actually reviews — reads as
|
|
7
|
+
* a list and not as a parser. It reads SOURCE TEXT rather than importing the
|
|
8
|
+
* collector, because this package declares no dependency on it (the same
|
|
9
|
+
* reason `agent-door-session.ts` copies a session reader instead of importing
|
|
10
|
+
* one).
|
|
11
|
+
*
|
|
12
|
+
* ## Where each half comes from
|
|
13
|
+
*
|
|
14
|
+
* - The NOUNS are the `parse<Noun>Args` functions `local-args-tower.ts`
|
|
15
|
+
* re-exports. That file is the authoritative "these are the commands that
|
|
16
|
+
* talk to Tower" table — its siblings are a filing decision, not a contract.
|
|
17
|
+
* - The VERBS are each noun's `action:` union in `LocalCommand`
|
|
18
|
+
* (`local-args.ts`), with an `XAction` alias resolved from whichever
|
|
19
|
+
* `local-args-tower-*.ts` declares it. A noun with no `action` field is one
|
|
20
|
+
* verb wearing the noun's own name (`jarvis`, `correct`, `workbook`).
|
|
21
|
+
*
|
|
22
|
+
* ## What it deliberately does NOT see
|
|
23
|
+
*
|
|
24
|
+
* Mode FLAGS. `cockpit jarvis --trace`, `--threads` and `--history` are three
|
|
25
|
+
* different acts behind one noun, and no decision table calls them verbs, so
|
|
26
|
+
* the mechanical rule cannot find them. They are covered by hand in the
|
|
27
|
+
* census's own twin map (`jarvis --trace` → `jarvis_trace`); a flag that grows
|
|
28
|
+
* into a verb will show up here the moment it becomes an `action`.
|
|
29
|
+
*/
|
|
30
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
31
|
+
import { dirname, join, resolve } from "node:path";
|
|
32
|
+
import { fileURLToPath } from "node:url";
|
|
33
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
export const COLLECTOR_COMMANDS_DIR = resolve(HERE, "../../cockpit-local-collector/src/commands");
|
|
35
|
+
function read(file) {
|
|
36
|
+
return readFileSync(join(COLLECTOR_COMMANDS_DIR, file), "utf8");
|
|
37
|
+
}
|
|
38
|
+
/** Every `local-args-tower*.ts` in the collector, so a new sibling is read too. */
|
|
39
|
+
function towerFiles() {
|
|
40
|
+
return readdirSync(COLLECTOR_COMMANDS_DIR).filter((name) => name.startsWith("local-args-tower") && name.endsWith(".ts") && !name.includes(".test."));
|
|
41
|
+
}
|
|
42
|
+
/** `parseJarvisArgs` → `jarvis`. The re-export table IS the noun list. */
|
|
43
|
+
export function towerNouns() {
|
|
44
|
+
const source = read("local-args-tower.ts");
|
|
45
|
+
const nouns = new Set();
|
|
46
|
+
for (const match of source.matchAll(/\bparse([A-Z][A-Za-z]*)Args\b/g)) {
|
|
47
|
+
nouns.add(match[1].replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase());
|
|
48
|
+
}
|
|
49
|
+
return [...nouns].sort();
|
|
50
|
+
}
|
|
51
|
+
/** `export type NotesAction = "list" | "show" | …` across every tower sibling. */
|
|
52
|
+
function actionAliases() {
|
|
53
|
+
const aliases = new Map();
|
|
54
|
+
for (const file of towerFiles()) {
|
|
55
|
+
const source = read(file);
|
|
56
|
+
for (const match of source.matchAll(/export type (\w+Action)\s*=\s*([\s\S]*?);/g)) {
|
|
57
|
+
aliases.set(match[1], [...match[2].matchAll(/"([a-z-]+)"/g)].map((m) => m[1]));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return aliases;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The `LocalCommand` variants, split the way the union is written: one chunk
|
|
64
|
+
* per ` | {` at the top level of the type.
|
|
65
|
+
*/
|
|
66
|
+
function commandVariants() {
|
|
67
|
+
const source = readFileSync(join(COLLECTOR_COMMANDS_DIR, "local-args.ts"), "utf8");
|
|
68
|
+
const start = source.indexOf("export type LocalCommand =");
|
|
69
|
+
if (start < 0)
|
|
70
|
+
throw new Error("LocalCommand union not found in local-args.ts");
|
|
71
|
+
const end = source.indexOf("\nexport ", start + 10);
|
|
72
|
+
return source.slice(start, end < 0 ? undefined : end).split(/\n\s{2}\|\s/);
|
|
73
|
+
}
|
|
74
|
+
/** Every Tower verb a person may type today. */
|
|
75
|
+
export function towerVerbs() {
|
|
76
|
+
const nouns = new Set(towerNouns());
|
|
77
|
+
const aliases = actionAliases();
|
|
78
|
+
const verbs = [];
|
|
79
|
+
const seenNouns = new Set();
|
|
80
|
+
for (const variant of commandVariants()) {
|
|
81
|
+
const kind = /kind:\s*"([a-z-]+)"/.exec(variant)?.[1];
|
|
82
|
+
if (!kind || !nouns.has(kind) || seenNouns.has(kind))
|
|
83
|
+
continue;
|
|
84
|
+
seenNouns.add(kind);
|
|
85
|
+
const action = /\n\s*action:\s*([^;]+);/.exec(variant)?.[1]?.trim();
|
|
86
|
+
if (!action) {
|
|
87
|
+
verbs.push({ noun: kind, action: "", spelling: kind });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const words = action.endsWith("Action")
|
|
91
|
+
? (aliases.get(action) ?? [])
|
|
92
|
+
: [...action.matchAll(/"([a-z-]+)"/g)].map((m) => m[1]);
|
|
93
|
+
if (words.length === 0) {
|
|
94
|
+
throw new Error(`No action vocabulary found for cockpit ${kind} (read "${action}")`);
|
|
95
|
+
}
|
|
96
|
+
for (const word of words) {
|
|
97
|
+
verbs.push({ noun: kind, action: word, spelling: `${kind} ${word}` });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const missing = [...nouns].filter((noun) => !seenNouns.has(noun));
|
|
101
|
+
if (missing.length > 0) {
|
|
102
|
+
// A parser with no `LocalCommand` variant means the extraction has drifted
|
|
103
|
+
// from the source, and a census that quietly reads fewer verbs than exist
|
|
104
|
+
// is worse than no census at all.
|
|
105
|
+
throw new Error(`Tower nouns with no LocalCommand variant: ${missing.join(", ")}`);
|
|
106
|
+
}
|
|
107
|
+
return verbs.sort((a, b) => a.spelling.localeCompare(b.spelling));
|
|
108
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `work_*` MCP tools (BLI-3716) — Tower's issue tracker on the `bli-tower`
|
|
3
|
+
* server, over the same `/api/work/**` doors `cockpit issue` and the browser
|
|
4
|
+
* call, authenticated with this machine's collector device token.
|
|
5
|
+
*
|
|
6
|
+
* The point of this file, in one sentence: a Claude Code or Codex session
|
|
7
|
+
* should be able to file and move a TOWER issue exactly the way it files and
|
|
8
|
+
* moves a Linear one — no browser, no uuid archaeology, no second vocabulary.
|
|
9
|
+
* So every tool takes `BLI-####` wherever an issue is named (the SERVER
|
|
10
|
+
* resolves it, `lib/work/issue-ref.ts`), and `work_create_issue` answers with
|
|
11
|
+
* the identifier it minted.
|
|
12
|
+
*
|
|
13
|
+
* Same session discipline as `docs-msg-tools.ts`: the session is loaded fresh
|
|
14
|
+
* per call, so a machine with no `cockpit login` pairing still serves this
|
|
15
|
+
* server's other tools and only a `work_` call fails, by name.
|
|
16
|
+
*/
|
|
17
|
+
import { loadAgentDoorSession } from "./agent-door-session.js";
|
|
18
|
+
import { type FetchImpl } from "./agent-door.js";
|
|
19
|
+
export interface WorkDeps {
|
|
20
|
+
fetchImpl: FetchImpl;
|
|
21
|
+
/** Injectable for tests; defaults to reading `~/.config/bli-cockpit/session.json`. */
|
|
22
|
+
loadSession?: typeof loadAgentDoorSession;
|
|
23
|
+
}
|
|
24
|
+
/** The closed state vocabulary, verbatim from `lib/work/api-doors.ts` `WORK_ISSUE_STATES`. */
|
|
25
|
+
export declare const WORK_ISSUE_STATES: readonly ["backlog", "todo", "in_progress", "in_review", "done", "canceled"];
|
|
26
|
+
export declare function registerWorkTools(server: {
|
|
27
|
+
registerTool: (...args: never[]) => unknown;
|
|
28
|
+
}, deps: WorkDeps): void;
|