@monster-orange/den 0.4.2 → 0.4.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/CHANGELOG.md +273 -0
- package/README.md +9 -9
- package/docs/distributions.md +313 -50
- package/package.json +1 -1
- package/src/shared/agents/catalog-runtime.ts +178 -0
- package/src/shared/agents/catalog.ts +343 -0
- package/src/shared/agents/den-claude.ts +53 -12
- package/src/shared/agents/generic.ts +1 -0
- package/src/shared/agents/runtime-search.ts +543 -0
- package/src/shared/agents/runtime.ts +43 -1
- package/src/shared/agents/runtimes.ts +53 -4
- package/src/shared/auth/sudo-vault.ts +16 -0
- package/src/shared/den-config.ts +92 -2
- package/src/shared/edge/render.ts +31 -0
- package/src/shared/edge/status.ts +134 -0
- package/src/shared/environment-manager/health.ts +82 -8
- package/src/shared/environment-manager/workspaces.ts +54 -0
- package/src/shared/health/not-checked.ts +42 -0
- package/src/shared/health/rollup.ts +4 -0
- package/src/shared/process/spawn-streaming.ts +8 -3
- package/src/shared/sessions/client.ts +5 -1
- package/src/shared/sessions/host.ts +29 -1
- package/src/shared/sessions/protocol.ts +6 -1
- package/src/shared/sessions/types.ts +6 -0
- package/src/shared/stacks/status.ts +24 -0
- package/src/shared/strategies/registry.ts +5 -0
- package/src/shared/types/index.ts +6 -0
- package/src/ui/cli/agent-ops.ts +298 -19
- package/src/ui/cli/agents-command.ts +129 -4
- package/src/ui/cli/edge-command.ts +16 -3
- package/src/ui/cli/health-display.ts +4 -1
- package/src/ui/cli/sessions-command.ts +9 -4
- package/src/ui/cli/web-command.ts +53 -8
- package/src/ui/mcp/scope.ts +23 -3
- package/src/ui/mcp/server.ts +31 -7
- package/src/ui/mcp/tools.ts +327 -20
- package/src/ui/mcp/views.ts +450 -0
- package/src/ui/server/agent-routes.ts +123 -26
- package/src/ui/server/edge-exposure.ts +143 -0
- package/src/ui/server/index.ts +171 -25
- package/src/ui/server/public/agent-start.js +241 -0
- package/src/ui/server/public/agents-page.js +246 -45
- package/src/ui/server/public/agents-section.js +7 -21
- package/src/ui/server/public/agents.html +55 -1
- package/src/ui/server/public/graph-model.js +2 -0
- package/src/ui/server/public/header.js +2 -3
- package/src/ui/server/public/health-rollup.js +20 -8
- package/src/ui/server/public/i18n/es.js +26 -13
- package/src/ui/server/public/i18n/ja.js +25 -13
- package/src/ui/server/public/index.html +17 -4
- package/src/ui/server/public/local-dev.html +62 -22
- package/src/ui/server/public/services.html +21 -5
- package/src/ui/server/public/settings-page.js +3 -2
- package/src/ui/server/public/settings-registry.js +226 -1
- package/src/ui/server/public/settings.html +90 -1
- package/src/ui/server/public/shell.js +67 -22
- package/src/ui/server/public/topbar.js +217 -158
- package/src/ui/server/readonly-routes.ts +29 -5
- package/src/ui/server/request-guard.ts +123 -8
- package/src/ui/server/route-classes.ts +14 -2
- package/src/ui/server/session-routes.ts +9 -1
- package/src/ui/server/sudo-store.ts +170 -6
- package/src/ui/server/ui-assets.ts +2 -0
- package/src/ui/server/workspace-routes.ts +10 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP-2.4: why a service has no health verdict, in words. A row with `ok:
|
|
3
|
+
* null` and no reason reads as "broken" to an agent (it fell back to
|
|
4
|
+
* `docker ps`); every unchecked row says which of these it is. One rule for
|
|
5
|
+
* the web health row (/api/health) and the MCP `status` tool, which derives
|
|
6
|
+
* it from a row an older web server served without one.
|
|
7
|
+
*/
|
|
8
|
+
import { product } from "../product.js";
|
|
9
|
+
import type { Runs } from "../manifest/placement.js";
|
|
10
|
+
|
|
11
|
+
export interface NotCheckedInput {
|
|
12
|
+
/** The env being viewed. */
|
|
13
|
+
env: string;
|
|
14
|
+
runs: Runs | undefined;
|
|
15
|
+
/** A remote service's target (its env), when it has one. */
|
|
16
|
+
target?: { env?: string } | null;
|
|
17
|
+
/** false when the repo has no manifest at all. */
|
|
18
|
+
manifest?: boolean;
|
|
19
|
+
/** The conventional probe tried (and not answered 2xx), if any. */
|
|
20
|
+
conventional?: string | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function notCheckedReason(o: NotCheckedInput): string {
|
|
24
|
+
if (o.manifest === false)
|
|
25
|
+
return `not checked: the repo has no ${product().manifestYml}`;
|
|
26
|
+
if (o.runs === "remote") {
|
|
27
|
+
const where = o.target?.env ?? o.env;
|
|
28
|
+
return (
|
|
29
|
+
`not checked: remote (runs in ${where}), and the manifest declares ` +
|
|
30
|
+
`no health check or target.url for ${where}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (o.runs === "none" || o.runs === undefined)
|
|
34
|
+
return (
|
|
35
|
+
`not checked: not deployed in ${o.env} (the manifest has no ` +
|
|
36
|
+
`commands and no health check for ${o.env})`
|
|
37
|
+
);
|
|
38
|
+
return (
|
|
39
|
+
`not checked: no health check in the manifest for ${o.env}` +
|
|
40
|
+
(o.conventional ? `, and ${o.conventional} did not answer 2xx` : "")
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -17,6 +17,8 @@ export interface HealthSignal {
|
|
|
17
17
|
isEntrypoint?: boolean;
|
|
18
18
|
/** Not answered yet this cycle: the repo stays unknown until it has. */
|
|
19
19
|
awaiting?: boolean;
|
|
20
|
+
/** The check answered with a redirect (ok null): counted as a redirect. */
|
|
21
|
+
redirect?: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export interface RepoRollup {
|
|
@@ -29,6 +31,8 @@ export interface RepoRollup {
|
|
|
29
31
|
unchecked: number;
|
|
30
32
|
/** Checks that haven't answered yet; any holds the state at unknown. */
|
|
31
33
|
awaiting: number;
|
|
34
|
+
/** Checks that answered with a redirect (not in `unchecked`); absent at 0. */
|
|
35
|
+
redirected?: number;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export const STATE_RANK: Record<RepoState, number> = rollup.STATE_RANK;
|
|
@@ -86,6 +86,10 @@ export function spawnDaemon(
|
|
|
86
86
|
// Stamp the log so the tail starts reading from a clean boundary.
|
|
87
87
|
const ts = new Date().toISOString();
|
|
88
88
|
fs.appendFileSync(logPath, `\n\n─── ${product().cli} start ${ts} ───\n`);
|
|
89
|
+
// Where this run's output starts. The tail reads from here, not from "the
|
|
90
|
+
// end when tail opened": a fast command (a refused sudo, a typo) can write
|
|
91
|
+
// and exit before tail starts, and `-n 0` would drop those lines.
|
|
92
|
+
const startOffset = fs.statSync(logPath).size;
|
|
89
93
|
|
|
90
94
|
// Open the log fd in the parent so we can hand it to the child.
|
|
91
95
|
// MUST stay "a" (O_APPEND): rotation truncates this file in place, and only
|
|
@@ -120,9 +124,10 @@ export function spawnDaemon(
|
|
|
120
124
|
fs.closeSync(logFd); // parent closes its copy; child keeps its own fd
|
|
121
125
|
|
|
122
126
|
// Tail the log for streaming back to the caller.
|
|
123
|
-
// -F follows by name (handles log rotation). -
|
|
124
|
-
// after
|
|
125
|
-
|
|
127
|
+
// -F follows by name (handles log rotation). -c +N starts at this run's
|
|
128
|
+
// first byte (just after the stamp), so nothing the service wrote before
|
|
129
|
+
// tail opened the file is lost.
|
|
130
|
+
const tailProc = spawn("tail", ["-F", "-c", `+${startOffset + 1}`, logPath], {
|
|
126
131
|
stdio: ["ignore", "pipe", "ignore"],
|
|
127
132
|
});
|
|
128
133
|
|
|
@@ -76,7 +76,8 @@ export class HostClient extends EventEmitter {
|
|
|
76
76
|
const h = this.attachments.get(ev.aid);
|
|
77
77
|
if (!h) return;
|
|
78
78
|
if (ev.ev === "data") h.onData(Buffer.from(ev.data, "base64"));
|
|
79
|
-
else
|
|
79
|
+
else if (ev.ev === "size") h.onSize?.(ev.cols, ev.rows);
|
|
80
|
+
else if (ev.ev === "exit") {
|
|
80
81
|
this.attachments.delete(ev.aid);
|
|
81
82
|
h.onExit?.(ev.exitCode);
|
|
82
83
|
}
|
|
@@ -174,6 +175,9 @@ export class HostClient extends EventEmitter {
|
|
|
174
175
|
ref: id,
|
|
175
176
|
aid,
|
|
176
177
|
...(opts.replay !== undefined ? { replay: opts.replay } : {}),
|
|
178
|
+
// Only a client that handles them is sent size events: an older
|
|
179
|
+
// client would read an unknown event as the session's exit.
|
|
180
|
+
...(handlers.onSize ? { sizes: true } : {}),
|
|
177
181
|
}).then(
|
|
178
182
|
(r) => r.info as SessionInfo,
|
|
179
183
|
(e: Error) => {
|
|
@@ -63,6 +63,10 @@ interface Session {
|
|
|
63
63
|
log: ScrollbackLog;
|
|
64
64
|
/** aid → its connection. */
|
|
65
65
|
attachments: Map<string, Conn>;
|
|
66
|
+
/** The attachments that asked for size events (attach `sizes: true`). */
|
|
67
|
+
sizeAids?: Set<string>;
|
|
68
|
+
/** The PTY's size: the start's, then the last resize's (any client's). */
|
|
69
|
+
size?: { cols: number; rows: number };
|
|
66
70
|
/** The cap it counts against (start's `pool`), when one was named. */
|
|
67
71
|
pool?: SessionPool;
|
|
68
72
|
}
|
|
@@ -453,7 +457,15 @@ export class SessionHost {
|
|
|
453
457
|
const s = this.session(req.ref);
|
|
454
458
|
if (!isInt(req.cols, 1, 10_000) || !isInt(req.rows, 1, 10_000))
|
|
455
459
|
throw new Refusal("bad-request", "resize needs whole cols and rows");
|
|
456
|
-
if (s.pty && !s.info.exited)
|
|
460
|
+
if (s.pty && !s.info.exited) {
|
|
461
|
+
s.pty.resize(req.cols, req.rows);
|
|
462
|
+
// Last writer wins: every viewer that asked hears the new size,
|
|
463
|
+
// so one out of step knows to say its own again.
|
|
464
|
+
if (s.size?.cols !== req.cols || s.size?.rows !== req.rows) {
|
|
465
|
+
s.size = { cols: req.cols, rows: req.rows };
|
|
466
|
+
this.sendSize(s);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
457
469
|
return {};
|
|
458
470
|
}
|
|
459
471
|
case "signal": {
|
|
@@ -606,6 +618,7 @@ export class SessionHost {
|
|
|
606
618
|
},
|
|
607
619
|
),
|
|
608
620
|
attachments: new Map(),
|
|
621
|
+
size: { cols, rows },
|
|
609
622
|
...(pool !== undefined ? { pool: pool as SessionPool } : {}),
|
|
610
623
|
};
|
|
611
624
|
this.sessions.set(id, s);
|
|
@@ -626,6 +639,7 @@ export class SessionHost {
|
|
|
626
639
|
for (const [aid, c] of s.attachments)
|
|
627
640
|
c.send({ ev: "exit", aid, exitCode: s.info.exitCode });
|
|
628
641
|
s.attachments.clear();
|
|
642
|
+
s.sizeAids?.clear();
|
|
629
643
|
this.log(`session ${id} (${name}) exited (${s.info.exitCode})`);
|
|
630
644
|
}, EXIT_SETTLE_MS);
|
|
631
645
|
});
|
|
@@ -654,10 +668,24 @@ export class SessionHost {
|
|
|
654
668
|
} else {
|
|
655
669
|
conn.aids.add(aid);
|
|
656
670
|
s.attachments.set(aid, conn);
|
|
671
|
+
if (req.sizes === true) {
|
|
672
|
+
(s.sizeAids ??= new Set()).add(aid);
|
|
673
|
+
if (s.size) conn.send({ ev: "size", aid, ...s.size });
|
|
674
|
+
}
|
|
657
675
|
}
|
|
658
676
|
return s.info;
|
|
659
677
|
}
|
|
660
678
|
|
|
679
|
+
/** Tell each attachment that asked the session's current size. */
|
|
680
|
+
private sendSize(s: Session): void {
|
|
681
|
+
if (!s.size || !s.sizeAids?.size) return;
|
|
682
|
+
for (const aid of s.sizeAids) {
|
|
683
|
+
const c = s.attachments.get(aid);
|
|
684
|
+
if (c) c.send({ ev: "size", aid, ...s.size });
|
|
685
|
+
else s.sizeAids.delete(aid);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
661
689
|
/** Stop serving: running sessions get SIGHUP, scrollback is flushed. */
|
|
662
690
|
async close(): Promise<void> {
|
|
663
691
|
if (this.closed) return;
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* {id, ok: false, code, error}
|
|
8
8
|
* event {ev: "data", aid, data} host → client, per attachment
|
|
9
9
|
* {ev: "exit", aid, exitCode}
|
|
10
|
+
* {ev: "size", aid, cols, rows} only to an attachment that
|
|
11
|
+
* asked (attach `sizes: true`):
|
|
12
|
+
* the PTY's size on attach, and
|
|
13
|
+
* each time it changes
|
|
10
14
|
*
|
|
11
15
|
* ops: hello, start, list, attach, detach, write, resize, signal,
|
|
12
16
|
* scrollback, forget, shutdown. A request whose `v` is not the host's is
|
|
@@ -47,7 +51,8 @@ export type Reply =
|
|
|
47
51
|
|
|
48
52
|
export type HostEvent =
|
|
49
53
|
| { ev: "data"; aid: string; data: string }
|
|
50
|
-
| { ev: "exit"; aid: string; exitCode?: number }
|
|
54
|
+
| { ev: "exit"; aid: string; exitCode?: number }
|
|
55
|
+
| { ev: "size"; aid: string; cols: number; rows: number };
|
|
51
56
|
|
|
52
57
|
/** Splits a byte stream into lines; refuses one that grows too long. */
|
|
53
58
|
export class LineReader {
|
|
@@ -55,6 +55,12 @@ export interface AttachHandlers {
|
|
|
55
55
|
onData(data: Buffer): void;
|
|
56
56
|
/** The session ended (at once, after the replay, when it already had). */
|
|
57
57
|
onExit?(exitCode: number | undefined): void;
|
|
58
|
+
/**
|
|
59
|
+
* The PTY's size: once on attach (after the replay), then each time any
|
|
60
|
+
* client resizes it. The size is last-writer-wins across every viewer,
|
|
61
|
+
* so a viewer learns here that another one changed it.
|
|
62
|
+
*/
|
|
63
|
+
onSize?(cols: number, rows: number): void;
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
/** One attachment; a session has any number, each gets all the output. */
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* The CLI prints it; the web server serves it at /api/stacks (and through it
|
|
4
4
|
* the MCP `stacks` tool).
|
|
5
5
|
*/
|
|
6
|
+
import { product } from "../product.js";
|
|
6
7
|
import { spawnSync } from "child_process";
|
|
7
8
|
import * as fs from "fs";
|
|
8
9
|
import * as path from "path";
|
|
@@ -125,6 +126,29 @@ export function rejoinRunningStacks(
|
|
|
125
126
|
return rejoinEdgeNetworks(contexts, onLine);
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Why a workspace has no stacks (MCP-2.4): an empty list with no reason
|
|
131
|
+
* reads as "docker is broken". A stack is a `stacks:` entry in the org
|
|
132
|
+
* config, or a repo of the workspace whose manifest has a `compose:` block.
|
|
133
|
+
*/
|
|
134
|
+
export function emptyStacksReason(o: {
|
|
135
|
+
workspace: string;
|
|
136
|
+
workspaceExists: boolean;
|
|
137
|
+
/** How many stacks the org config itself declares. */
|
|
138
|
+
configStacks: number;
|
|
139
|
+
}): string {
|
|
140
|
+
const cfg = `the org config (${product().configFile}) declares no stacks:`;
|
|
141
|
+
if (!o.workspaceExists)
|
|
142
|
+
return (
|
|
143
|
+
`no stacks: workspace "${o.workspace}" does not exist here, so no ` +
|
|
144
|
+
`repo manifest was read, and ${cfg}`
|
|
145
|
+
);
|
|
146
|
+
return (
|
|
147
|
+
`no stacks: ${cfg}, and no repo of workspace "${o.workspace}" has a ` +
|
|
148
|
+
`compose: block in its ${product().manifestYml}`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
128
152
|
/** Each stack's name, project, routes and (optionally) container health. */
|
|
129
153
|
export function stackStatuses(
|
|
130
154
|
ctx: StackContext,
|
|
@@ -44,6 +44,11 @@ export function registerStrategy<K extends string, C>(
|
|
|
44
44
|
byId.set(entry.id, entry as StrategyEntry);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** Remove strategy `id` of `kind` (no-op when it isn't there). */
|
|
48
|
+
export function unregisterStrategy(kind: string, id: string): void {
|
|
49
|
+
registries.get(kind)?.delete(id);
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
/** The strategy `id` of `kind`, or undefined. */
|
|
48
53
|
export function getStrategy<K extends string, C>(
|
|
49
54
|
kind: K,
|
|
@@ -667,6 +667,12 @@ export interface WorkspaceServiceEntry {
|
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
export interface WorkspaceConfig {
|
|
670
|
+
/**
|
|
671
|
+
* Agents in this workspace, on this machine (AG-0.5):
|
|
672
|
+
* `agents.runtimes.<id>.bin`, a runtime's CLI for this workspace's
|
|
673
|
+
* agents, which wins over user.yml's and the search.
|
|
674
|
+
*/
|
|
675
|
+
agents?: { runtimes?: Record<string, { bin?: unknown } | null> };
|
|
670
676
|
/**
|
|
671
677
|
* Service entries keyed by service address.
|
|
672
678
|
* Single-service repos: "tasks-runner"
|