@thehammer/danx-dashboard-mcp 0.1.175 → 0.1.176
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/background-work.js +19 -18
- package/dist/event-text.js +6 -5
- package/dist/index.js +31 -14
- package/dist/one-shot-session-request.js +11 -12
- package/dist/plan-state.js +174 -0
- package/package.json +1 -1
package/dist/background-work.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* WHO RUNS IT. The danxbot Claude Code plugin's `Stop` / `SubagentStop` /
|
|
6
6
|
* `SessionStart` / `StopFailure` hooks (`danxbot/hooks/hooks.json` in
|
|
7
7
|
* claude-plugins), via the SAME `npx -y @thehammer/danx-dashboard-mcp`
|
|
8
|
-
* MECHANISM the plugin already uses for `bridge`
|
|
9
|
-
* deep import of this package's `dist/` internals.
|
|
8
|
+
* MECHANISM the plugin already uses for `bridge` and `plan-state` — no
|
|
9
|
+
* separate install, no deep import of this package's `dist/` internals.
|
|
10
10
|
* DX-3367 fix-up — that does NOT mean the SAME PINNED VERSION: `npx -y
|
|
11
11
|
* <pkg>` resolves whatever version string that ONE hook's own invocation
|
|
12
12
|
* names, and this plugin's hooks pin each call independently (verified
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
* sending `clear` on `SessionStart`/`StopFailure`); this module only
|
|
19
19
|
* delivers the report.
|
|
20
20
|
*
|
|
21
|
-
* THE CONTRACT
|
|
22
|
-
* trust it without re-reading
|
|
21
|
+
* THE CONTRACT, mirroring `plan-state.ts`'s (binding the same way, so a
|
|
22
|
+
* future plugin build against this module can trust it without re-reading
|
|
23
|
+
* this file):
|
|
23
24
|
* - print EXACTLY ONE JSON line on stdout, and ALWAYS exit 0 — success or
|
|
24
25
|
* failure alike, because a hook must stay silent rather than spam the
|
|
25
26
|
* session's own turn with a stack trace;
|
|
@@ -39,21 +40,21 @@
|
|
|
39
40
|
* reports by this time;
|
|
40
41
|
* - human-readable diagnostics go to stderr only, never stdout.
|
|
41
42
|
*
|
|
42
|
-
* THE CREDENTIAL — the SAME resolver `bridge`
|
|
43
|
-
* (`bridge.ts`): the dashboard URL, credential
|
|
44
|
-
* from the connection record this session's OWN
|
|
45
|
-
* wrote on its last successful `plan_connect`
|
|
46
|
-
* never from this process's own ambient env
|
|
43
|
+
* THE CREDENTIAL — the SAME resolver `bridge` and `plan-state` use, via
|
|
44
|
+
* `resolveBridgeOptions` (`bridge.ts`): the dashboard URL, credential
|
|
45
|
+
* source, and credential come from the connection record this session's OWN
|
|
46
|
+
* danx-dashboard MCP server wrote on its last successful `plan_connect`
|
|
47
|
+
* (`session-connection.ts`), never from this process's own ambient env —
|
|
48
|
+
* the identical DX-2862 reasoning `plan-state.ts` already gives for itself.
|
|
47
49
|
*
|
|
48
50
|
* A HARD TIMEOUT — `BACKGROUND_WORK_REQUEST_TIMEOUT_MS`. A `Stop` hook
|
|
49
51
|
* blocks the session's turn boundary, so this call must never hang: a slow
|
|
50
52
|
* or wedged dashboard is `{ok:false, reason:"timeout"}`, not a stuck hook.
|
|
51
53
|
*
|
|
52
|
-
* THE REQUEST/RUN SCAFFOLDING
|
|
53
|
-
* fix-up)
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* resolution boilerplate.
|
|
54
|
+
* THE REQUEST/RUN SCAFFOLDING IS SHARED WITH `plan-state.ts`
|
|
55
|
+
* (`one-shot-session-request.ts`, DX-3367 fix-up) — the two subcommands no
|
|
56
|
+
* longer maintain independent copies of the authenticated-fetch-with-
|
|
57
|
+
* timeout logic or the session/credential resolution boilerplate.
|
|
57
58
|
*/
|
|
58
59
|
import { resolveSessionOptions, sendSessionRequest, tryParseJsonBody } from "./one-shot-session-request.js";
|
|
59
60
|
export const BACKGROUND_WORK_SUBCOMMAND = "background-work";
|
|
@@ -89,10 +90,10 @@ export function parseEventAtArg(raw) {
|
|
|
89
90
|
* DX-3367 fix-up — STATUS IS CHECKED BEFORE THE BODY IS EVER PARSED. A 5xx
|
|
90
91
|
* (or any other non-2xx) response can carry an HTML error page instead of
|
|
91
92
|
* JSON; parsing first would misreport that as `bad_response` when the true
|
|
92
|
-
* classification is `http_error`.
|
|
93
|
-
* the BODY inspected to classify
|
|
94
|
-
* equivalent), so status alone decides
|
|
95
|
-
* attempted.
|
|
93
|
+
* classification is `http_error`. Unlike `plan-state.ts`'s `fetchTurnState`,
|
|
94
|
+
* this subcommand has no status that needs the BODY inspected to classify
|
|
95
|
+
* (no `409 session_not_connected` equivalent), so status alone decides
|
|
96
|
+
* whether a body read is even attempted.
|
|
96
97
|
*/
|
|
97
98
|
export async function putBackgroundWork(options, report, deps) {
|
|
98
99
|
const sent = await sendSessionRequest(options, BACKGROUND_WORK_PATH, { method: "PUT", body: JSON.stringify({ count: report.count, eventAt: report.eventAt }) }, deps);
|
package/dist/event-text.js
CHANGED
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
* collapse into the one hook + this one subcommand). `<event>` is one of
|
|
11
11
|
* `session_start` | `session_resume` | `after_compaction` |
|
|
12
12
|
* `sub_agent_start` — the SAME `npx -y @thehammer/danx-dashboard-mcp@<pin>`
|
|
13
|
-
* path the plugin's other dashboard calls already use (`
|
|
14
|
-
* separate install, never a deep import of this
|
|
13
|
+
* path the plugin's other dashboard calls already use (`plan-state`,
|
|
14
|
+
* `bridge`) — never a separate install, never a deep import of this
|
|
15
|
+
* package's `dist/` internals.
|
|
15
16
|
*
|
|
16
|
-
* THE CREDENTIAL — the SAME resolver `bridge`
|
|
17
|
+
* THE CREDENTIAL — the SAME resolver `bridge` / `plan-state` use
|
|
17
18
|
* (`resolveBridgeOptions`, `bridge.ts`): the dashboard URL, credential source
|
|
18
19
|
* and credential all come from the connection record this session's OWN
|
|
19
20
|
* danx-dashboard MCP server wrote on its last successful `plan_connect`
|
|
@@ -36,8 +37,8 @@
|
|
|
36
37
|
* stderr, exit 1. `event-hook.sh` is the one that decides what to print
|
|
37
38
|
* for the agent — this module only reports whether the fetch worked.
|
|
38
39
|
*
|
|
39
|
-
* A HARD TIMEOUT — a SessionStart hook must never
|
|
40
|
-
* dashboard.
|
|
40
|
+
* A HARD TIMEOUT (mirrors `plan-state.ts`) — a SessionStart hook must never
|
|
41
|
+
* hang on a wedged dashboard.
|
|
41
42
|
*/
|
|
42
43
|
import { SESSION_ID_HEADER, resolveBridgeOptions } from "./bridge.js";
|
|
43
44
|
export const EVENT_TEXT_SUBCOMMAND = "event-text";
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
*/
|
|
75
75
|
import { isEntrypointModule } from "./entrypoint.js";
|
|
76
76
|
import { BRIDGE_SUBCOMMAND, runBridgeCommand } from "./bridge.js";
|
|
77
|
+
import { PLAN_STATE_SUBCOMMAND, runPlanStateCommand } from "./plan-state.js";
|
|
77
78
|
import { BACKGROUND_WORK_SUBCOMMAND, runBackgroundWorkCommand } from "./background-work.js";
|
|
78
79
|
import { EVENT_TEXT_SUBCOMMAND, runEventTextCommand } from "./event-text.js";
|
|
79
80
|
import { resolveDeclaredCredential } from "./credential.js";
|
|
@@ -459,14 +460,22 @@ async function main() {
|
|
|
459
460
|
// symlink-aware (DX-1647) so it holds under the symlinked `npx` bin the worker
|
|
460
461
|
// spawns, not just a direct `node dist/index.js`.
|
|
461
462
|
//
|
|
462
|
-
// `bridge`
|
|
463
|
-
// event
|
|
464
|
-
//
|
|
465
|
-
// the dashboard URL, credential source,
|
|
466
|
-
// session-connection record this server's
|
|
467
|
-
// (`session-connection.ts`), never from the bridge's
|
|
468
|
-
// (DX-2862: a bridge trusting its own ambient
|
|
469
|
-
// exact bug this repo fixed).
|
|
463
|
+
// `bridge` and `plan-state` are the two subcommands. `bridge` is the session
|
|
464
|
+
// event stream client the danxbot plugin's plan event bridge runs. It never
|
|
465
|
+
// boots the MCP server; its only input is `CLAUDE_CODE_SESSION_ID` (read from
|
|
466
|
+
// its environment) plus `--resume-ids` — the dashboard URL, credential source,
|
|
467
|
+
// and credential itself come from the session-connection record this server's
|
|
468
|
+
// own `plan_connect` wrote (`session-connection.ts`), never from the bridge's
|
|
469
|
+
// own environment (DX-2862: a bridge trusting its own ambient
|
|
470
|
+
// `DANXBOT_DISPATCH_TOKEN` is the exact bug this repo fixed).
|
|
471
|
+
//
|
|
472
|
+
// `plan-state` (DX-2921) is the ONE-SHOT client of
|
|
473
|
+
// `GET /api/plan-sessions/me/turn-state`, run by the DX-2888 plugin's
|
|
474
|
+
// turn-start / turn-end hooks — see `plan-state.ts`'s own doc comment for the
|
|
475
|
+
// full contract. It ALWAYS exits 0 (success or failure alike: the hook must
|
|
476
|
+
// stay silent), so even an unexpected rejection here is caught and reported
|
|
477
|
+
// the same `{ok:false, reason}` way rather than propagating a non-zero exit
|
|
478
|
+
// or an uncaught stack trace into the hook.
|
|
470
479
|
//
|
|
471
480
|
// Any OTHER argument is refused rather than ignored, so a typo cannot
|
|
472
481
|
// silently start an MCP server on stdio where a subcommand was meant to run.
|
|
@@ -478,6 +487,13 @@ if (isEntrypointModule(import.meta.url, process.argv[1])) {
|
|
|
478
487
|
process.exit(1);
|
|
479
488
|
});
|
|
480
489
|
}
|
|
490
|
+
else if (subcommand === PLAN_STATE_SUBCOMMAND) {
|
|
491
|
+
runPlanStateCommand(rest).then((code) => process.exit(code), (err) => {
|
|
492
|
+
console.error(`[danx-dashboard-mcp] plan-state fatal: ${err.message}`);
|
|
493
|
+
process.stdout.write(`${JSON.stringify({ ok: false, reason: "fatal" })}\n`);
|
|
494
|
+
process.exit(0);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
481
497
|
else if (subcommand === BACKGROUND_WORK_SUBCOMMAND) {
|
|
482
498
|
runBackgroundWorkCommand(rest).then((code) => process.exit(code), (err) => {
|
|
483
499
|
console.error(`[danx-dashboard-mcp] background-work fatal: ${err.message}`);
|
|
@@ -486,11 +502,12 @@ if (isEntrypointModule(import.meta.url, process.argv[1])) {
|
|
|
486
502
|
});
|
|
487
503
|
}
|
|
488
504
|
else if (subcommand === EVENT_TEXT_SUBCOMMAND) {
|
|
489
|
-
// DX-3421 (was DX-3366's `mantra` subcommand) — unlike
|
|
490
|
-
// rejection here is a genuine fatal (never expected:
|
|
491
|
-
// itself already classifies every network/shape
|
|
492
|
-
// {ok:false} exit 1), so it exits 1 too rather than
|
|
493
|
-
// silent" contract
|
|
505
|
+
// DX-3421 (was DX-3366's `mantra` subcommand) — unlike plan-state/
|
|
506
|
+
// background-work, a rejection here is a genuine fatal (never expected:
|
|
507
|
+
// runEventTextCommand itself already classifies every network/shape
|
|
508
|
+
// failure into its own {ok:false} exit 1), so it exits 1 too rather than
|
|
509
|
+
// the "always 0, stay silent" contract those two hook-only subcommands
|
|
510
|
+
// use.
|
|
494
511
|
runEventTextCommand(rest).then((code) => process.exit(code), (err) => {
|
|
495
512
|
console.error(`[danx-dashboard-mcp] event-text fatal: ${err.message}`);
|
|
496
513
|
process.exit(1);
|
|
@@ -498,7 +515,7 @@ if (isEntrypointModule(import.meta.url, process.argv[1])) {
|
|
|
498
515
|
}
|
|
499
516
|
else if (subcommand !== undefined) {
|
|
500
517
|
console.error(`[danx-dashboard-mcp] unknown subcommand "${subcommand}" (the only ones are ` +
|
|
501
|
-
`"${BRIDGE_SUBCOMMAND}", "${BACKGROUND_WORK_SUBCOMMAND}", and "${EVENT_TEXT_SUBCOMMAND}")`);
|
|
518
|
+
`"${BRIDGE_SUBCOMMAND}", "${PLAN_STATE_SUBCOMMAND}", "${BACKGROUND_WORK_SUBCOMMAND}", and "${EVENT_TEXT_SUBCOMMAND}")`);
|
|
502
519
|
process.exit(2);
|
|
503
520
|
}
|
|
504
521
|
else {
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DX-3367 fix-up — shared scaffolding for a "one-shot session request"
|
|
3
|
-
* subcommand
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* instead of copying `background-work.ts` again.
|
|
3
|
+
* subcommand: `plan-state` (`GET /api/plan-sessions/me/turn-state`) and
|
|
4
|
+
* `background-work` (`PUT /api/plan-sessions/me/background-work`) each
|
|
5
|
+
* duplicated this exact shape independently (`fetchTurnState` /
|
|
6
|
+
* `putBackgroundWork`, `runPlanStateCommand` / `runBackgroundWorkCommand`).
|
|
7
|
+
* This module is the ONE place that shape lives now; a future one-shot
|
|
8
|
+
* subcommand extends it instead of copying either file again.
|
|
10
9
|
*
|
|
11
|
-
* Two pieces:
|
|
10
|
+
* Two pieces, matching the two duplicated concerns:
|
|
12
11
|
* - `sendSessionRequest` — the authenticated HTTP call itself: bearer +
|
|
13
12
|
* session header, a hard abort-timeout, and network-level failure
|
|
14
13
|
* classification (`timeout` / `request_failed`). Returns the raw
|
|
15
14
|
* `{status, text}` UNPARSED — each caller decides for itself which
|
|
16
|
-
* statuses need the body inspected
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* (`bad_response`).
|
|
15
|
+
* statuses need the body inspected (e.g. `plan-state`'s 409
|
|
16
|
+
* `session_not_connected`) and which don't, so a non-2xx status with an
|
|
17
|
+
* unparseable (e.g. HTML) body is classified from the status alone
|
|
18
|
+
* rather than colliding with "the JSON didn't parse" (`bad_response`).
|
|
20
19
|
* - `resolveSessionOptions` — session-id + credential resolution via
|
|
21
20
|
* `resolveBridgeOptions`, with `BridgeStartError` narrowed by
|
|
22
21
|
* `instanceof` rather than an unchecked `as BridgeStartError` cast, so
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `danx-dashboard-mcp plan-state` — the ONE-SHOT client of
|
|
3
|
+
* `GET /api/plan-sessions/me/turn-state` (DX-2921).
|
|
4
|
+
*
|
|
5
|
+
* WHO RUNS IT. The danxbot Claude Code plugin's DX-2888 turn-start /
|
|
6
|
+
* turn-end hooks, via the plugin's existing `bridgeCommand()` npx path — the
|
|
7
|
+
* SAME package pin, no separate install, no deep import of this package's
|
|
8
|
+
* `dist/` internals (that was DX-2921's whole reason to exist: the DX-2888
|
|
9
|
+
* architecture review found the first build of this logic vendored a private
|
|
10
|
+
* copy of the MCP package and hardcoded the dashboard HTTP contract inside
|
|
11
|
+
* the PLUGIN). The plugin decides what to DO with the answer (inject plan
|
|
12
|
+
* numbers at turn start, refuse to let a turn end while the session could
|
|
13
|
+
* legally start work and has nothing running); this module only fetches it.
|
|
14
|
+
*
|
|
15
|
+
* THE CONTRACT (agreed with the DX-2888 plugin side, issue comment 4245 on
|
|
16
|
+
* DX-2921 — binding, because the plugin is already built against it):
|
|
17
|
+
* - print EXACTLY ONE JSON line on stdout, and ALWAYS exit 0 — success or
|
|
18
|
+
* failure alike, because the hook must stay silent rather than spam the
|
|
19
|
+
* session's own turn with a stack trace;
|
|
20
|
+
* - a session that is not connected to a plan prints
|
|
21
|
+
* `{"ok":false,"reason":"session_not_connected"}` — that EXACT literal,
|
|
22
|
+
* because the plugin keys its no-log-spam rule on it (it is also the
|
|
23
|
+
* dashboard's own 409 error code for this case — see
|
|
24
|
+
* `requireConnectedPlanId`, `plan-session-context.ts`);
|
|
25
|
+
* - on success, every count is a finite number, `plan` carries `id` +
|
|
26
|
+
* `name`, and every `startable` / `held` entry carries a string `id` +
|
|
27
|
+
* `title` — the plugin rejects anything else as `bad_response`, so this
|
|
28
|
+
* module validates the server's response BEFORE printing it, rather than
|
|
29
|
+
* trusting a 200 status to mean a well-shaped body;
|
|
30
|
+
* - human-readable diagnostics go to stderr only, never stdout.
|
|
31
|
+
*
|
|
32
|
+
* THE CREDENTIAL — the SAME resolver `bridge` uses (DX-2862 / DX-2921 AC),
|
|
33
|
+
* via `resolveBridgeOptions` (`bridge.ts`): the dashboard URL, credential
|
|
34
|
+
* source and credential all come from the connection record this session's
|
|
35
|
+
* OWN danx-dashboard MCP server wrote on its last successful `plan_connect`
|
|
36
|
+
* (`session-connection.ts`), never from this process's own ambient env. That
|
|
37
|
+
* is deliberate here for the identical reason it is deliberate for `bridge`:
|
|
38
|
+
* a hook process trusting whatever `DANXBOT_DISPATCH_TOKEN` happens to be in
|
|
39
|
+
* its environment is precisely the DX-2862 bug (a hook's ambient credential
|
|
40
|
+
* silently pointed at a different dashboard from the one the session's tools
|
|
41
|
+
* actually use).
|
|
42
|
+
*
|
|
43
|
+
* A HARD TIMEOUT (AC 30672) — `PLAN_STATE_REQUEST_TIMEOUT_MS`. This call
|
|
44
|
+
* blocks a turn boundary the plugin is holding open, so it must never hang:
|
|
45
|
+
* a slow or wedged dashboard is `{ok:false, reason:"timeout"}`, not a stuck
|
|
46
|
+
* hook.
|
|
47
|
+
*
|
|
48
|
+
* THE REQUEST/RUN SCAFFOLDING IS SHARED WITH `background-work.ts`
|
|
49
|
+
* (`one-shot-session-request.ts`, DX-3367 fix-up).
|
|
50
|
+
*/
|
|
51
|
+
import { resolveSessionOptions, sendSessionRequest, tryParseJsonBody } from "./one-shot-session-request.js";
|
|
52
|
+
export const PLAN_STATE_SUBCOMMAND = "plan-state";
|
|
53
|
+
export const TURN_STATE_PATH = "/api/plan-sessions/me/turn-state";
|
|
54
|
+
/** How long this one-shot call may take before it counts as a timeout. */
|
|
55
|
+
export const PLAN_STATE_REQUEST_TIMEOUT_MS = 5_000;
|
|
56
|
+
const USAGE = `usage: CLAUDE_CODE_SESSION_ID=<session-id> danx-dashboard-mcp ${PLAN_STATE_SUBCOMMAND}`;
|
|
57
|
+
function errorCodeOf(body) {
|
|
58
|
+
return typeof body === "object" && body !== null && typeof body.error === "string"
|
|
59
|
+
? body.error
|
|
60
|
+
: null;
|
|
61
|
+
}
|
|
62
|
+
function isFiniteNumber(v) {
|
|
63
|
+
return typeof v === "number" && Number.isFinite(v);
|
|
64
|
+
}
|
|
65
|
+
function isCardRef(v) {
|
|
66
|
+
return (typeof v === "object" &&
|
|
67
|
+
v !== null &&
|
|
68
|
+
typeof v.id === "string" &&
|
|
69
|
+
typeof v.title === "string");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The strict shape check the contract pins (comment 4245): finite counts, a
|
|
73
|
+
* `plan` with `id` + `name`, and a string `id` + `title` on every
|
|
74
|
+
* `startable` / `held` entry. `null` on anything short of that — a 200 whose
|
|
75
|
+
* body does not match is `bad_response`, exactly like a non-2xx.
|
|
76
|
+
*/
|
|
77
|
+
export function parseTurnStateBody(body) {
|
|
78
|
+
if (typeof body !== "object" || body === null)
|
|
79
|
+
return null;
|
|
80
|
+
const b = body;
|
|
81
|
+
const plan = b.plan;
|
|
82
|
+
if (typeof plan !== "object" || plan === null)
|
|
83
|
+
return null;
|
|
84
|
+
const p = plan;
|
|
85
|
+
if (!isFiniteNumber(p.id) || typeof p.name !== "string")
|
|
86
|
+
return null;
|
|
87
|
+
const counts = b.counts;
|
|
88
|
+
if (typeof counts !== "object" || counts === null)
|
|
89
|
+
return null;
|
|
90
|
+
const c = counts;
|
|
91
|
+
if (!isFiniteNumber(c.open) || !isFiniteNumber(c.inProgress) || !isFiniteNumber(c.needsYou))
|
|
92
|
+
return null;
|
|
93
|
+
if (!Array.isArray(b.startable) || !b.startable.every(isCardRef))
|
|
94
|
+
return null;
|
|
95
|
+
if (!Array.isArray(b.held) || !b.held.every(isCardRef))
|
|
96
|
+
return null;
|
|
97
|
+
return {
|
|
98
|
+
plan: { id: p.id, name: p.name },
|
|
99
|
+
counts: { open: c.open, inProgress: c.inProgress, needsYou: c.needsYou },
|
|
100
|
+
startable: b.startable,
|
|
101
|
+
held: b.held,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* One authenticated GET, with a hard timeout, classified into the output
|
|
106
|
+
* shape this subcommand always prints — never a throw, never a non-2xx
|
|
107
|
+
* bubbling past this function.
|
|
108
|
+
*
|
|
109
|
+
* DX-3367 fix-up — status is checked BEFORE the body is parsed, except for
|
|
110
|
+
* the ONE status (`409`) whose classification genuinely depends on the body
|
|
111
|
+
* (`session_not_connected`). Any other non-2xx — including a 5xx that comes
|
|
112
|
+
* back as an HTML error page instead of JSON — is `http_error` without ever
|
|
113
|
+
* attempting to parse it, so a body-parse failure on those statuses can
|
|
114
|
+
* never be misreported as `bad_response`.
|
|
115
|
+
*/
|
|
116
|
+
export async function fetchTurnState(options, deps) {
|
|
117
|
+
const sent = await sendSessionRequest(options, TURN_STATE_PATH, { method: "GET" }, deps);
|
|
118
|
+
if ("reason" in sent)
|
|
119
|
+
return sent;
|
|
120
|
+
const { status, text } = sent;
|
|
121
|
+
if (status === 409) {
|
|
122
|
+
// The exact literal the plugin's no-log-spam rule keys on (AC 30672 /
|
|
123
|
+
// comment 4245) — the dashboard's own 409 error code for an unconnected
|
|
124
|
+
// session, passed through verbatim rather than renamed. A 409 whose body
|
|
125
|
+
// does NOT carry that code falls through to the ordinary `http_error`
|
|
126
|
+
// classification below, same as any other non-2xx.
|
|
127
|
+
const parsed409 = tryParseJsonBody(text);
|
|
128
|
+
if (parsed409.ok && errorCodeOf(parsed409.body) === "session_not_connected") {
|
|
129
|
+
return { ok: false, reason: "session_not_connected" };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (status === 401 || status === 403) {
|
|
133
|
+
return { ok: false, reason: "unauthorized" };
|
|
134
|
+
}
|
|
135
|
+
if (status < 200 || status >= 300) {
|
|
136
|
+
return { ok: false, reason: "http_error" };
|
|
137
|
+
}
|
|
138
|
+
const parsed = tryParseJsonBody(text);
|
|
139
|
+
if (!parsed.ok)
|
|
140
|
+
return { ok: false, reason: "bad_response" };
|
|
141
|
+
const turnState = parseTurnStateBody(parsed.body);
|
|
142
|
+
if (turnState === null) {
|
|
143
|
+
return { ok: false, reason: "bad_response" };
|
|
144
|
+
}
|
|
145
|
+
return { ok: true, ...turnState };
|
|
146
|
+
}
|
|
147
|
+
/** The bin's `plan-state` subcommand, wired to the real process. Always resolves to exit code 0. */
|
|
148
|
+
export async function runPlanStateCommand(argv, env = process.env,
|
|
149
|
+
/** Test seam: the home the session's connection record is read from. */
|
|
150
|
+
resolveFrom = {}) {
|
|
151
|
+
const write = (output) => {
|
|
152
|
+
process.stdout.write(`${JSON.stringify(output)}\n`);
|
|
153
|
+
};
|
|
154
|
+
if (argv.length !== 0) {
|
|
155
|
+
// A malformed invocation is still a "the hook must stay silent" failure,
|
|
156
|
+
// not a crash — same ok:false/exit-0 contract as every other failure
|
|
157
|
+
// path here, with the usage line reserved for a human reading stderr.
|
|
158
|
+
write({ ok: false, reason: "usage" });
|
|
159
|
+
process.stderr.write(`${USAGE}\n`);
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
const resolved = await resolveSessionOptions(env, resolveFrom, USAGE);
|
|
163
|
+
if (!resolved.ok) {
|
|
164
|
+
write(resolved.output);
|
|
165
|
+
process.stderr.write(`${resolved.detail}\n`);
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
const output = await fetchTurnState(resolved.options, {
|
|
169
|
+
fetch: (input, init) => fetch(input, init),
|
|
170
|
+
requestTimeoutMs: PLAN_STATE_REQUEST_TIMEOUT_MS,
|
|
171
|
+
});
|
|
172
|
+
write(output);
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thehammer/danx-dashboard-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.176",
|
|
4
4
|
"description": "Stdio MCP server fronting danxbot's dashboard API for agents (operator sessions and dispatched workers alike): the generic danxbot_api/danxbot_api_list/danxbot_api_spec tools reach any route the caller's credential may call, plus dedicated agent-specific tools (plan_connect, danxbot_complete, and other per-dispatch lifecycle callbacks) (DX-3465, PLN-11 R-25).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|