pi-chassis 0.0.0-stage → 0.7.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/CHANGELOG.md +118 -0
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/THIRD_PARTY_NOTICES +30 -0
- package/dist/chassis/alert.d.ts +50 -0
- package/dist/chassis/alert.js +107 -0
- package/dist/chassis/api.d.ts +411 -0
- package/dist/chassis/api.js +676 -0
- package/dist/chassis/bash-output.d.ts +89 -0
- package/dist/chassis/bash-output.js +157 -0
- package/dist/chassis/brand.d.ts +99 -0
- package/dist/chassis/brand.js +79 -0
- package/dist/chassis/client.d.ts +87 -0
- package/dist/chassis/client.js +271 -0
- package/dist/chassis/commands.d.ts +60 -0
- package/dist/chassis/commands.js +211 -0
- package/dist/chassis/editor.d.ts +70 -0
- package/dist/chassis/editor.js +213 -0
- package/dist/chassis/footer.d.ts +14 -0
- package/dist/chassis/footer.js +136 -0
- package/dist/chassis/header.d.ts +12 -0
- package/dist/chassis/header.js +38 -0
- package/dist/chassis/home.d.ts +48 -0
- package/dist/chassis/home.js +184 -0
- package/dist/chassis/icons.d.ts +203 -0
- package/dist/chassis/icons.js +190 -0
- package/dist/chassis/index.d.ts +21 -0
- package/dist/chassis/index.js +582 -0
- package/dist/chassis/layout.d.ts +40 -0
- package/dist/chassis/layout.js +264 -0
- package/dist/chassis/message-modes.d.ts +21 -0
- package/dist/chassis/message-modes.js +49 -0
- package/dist/chassis/messages.d.ts +75 -0
- package/dist/chassis/messages.js +392 -0
- package/dist/chassis/modes.d.ts +21 -0
- package/dist/chassis/modes.js +99 -0
- package/dist/chassis/palette.d.ts +84 -0
- package/dist/chassis/palette.js +235 -0
- package/dist/chassis/peek.d.ts +61 -0
- package/dist/chassis/peek.js +156 -0
- package/dist/chassis/prompt-row.d.ts +42 -0
- package/dist/chassis/prompt-row.js +68 -0
- package/dist/chassis/provider-view.d.ts +34 -0
- package/dist/chassis/provider-view.js +107 -0
- package/dist/chassis/provider.d.ts +69 -0
- package/dist/chassis/provider.js +73 -0
- package/dist/chassis/readonly-command.d.ts +19 -0
- package/dist/chassis/readonly-command.js +454 -0
- package/dist/chassis/sanitize.d.ts +42 -0
- package/dist/chassis/sanitize.js +103 -0
- package/dist/chassis/session-info.d.ts +39 -0
- package/dist/chassis/session-info.js +107 -0
- package/dist/chassis/sidebar.d.ts +48 -0
- package/dist/chassis/sidebar.js +273 -0
- package/dist/chassis/state.d.ts +38 -0
- package/dist/chassis/state.js +19 -0
- package/dist/chassis/telemetry.d.ts +60 -0
- package/dist/chassis/telemetry.js +191 -0
- package/dist/chassis/tools.d.ts +112 -0
- package/dist/chassis/tools.js +588 -0
- package/dist/chassis/version.d.ts +2 -0
- package/dist/chassis/version.js +20 -0
- package/dist/diff/git-diff.d.ts +71 -0
- package/dist/diff/git-diff.js +325 -0
- package/dist/diff/host.d.ts +34 -0
- package/dist/diff/host.js +50 -0
- package/dist/diff/index.d.ts +13 -0
- package/dist/diff/index.js +86 -0
- package/dist/diff/render.d.ts +67 -0
- package/dist/diff/render.js +196 -0
- package/dist/diff/types.d.ts +60 -0
- package/dist/diff/types.js +4 -0
- package/dist/diff/view.d.ts +118 -0
- package/dist/diff/view.js +528 -0
- package/dist/git/flows.d.ts +92 -0
- package/dist/git/flows.js +415 -0
- package/dist/git/forge.d.ts +26 -0
- package/dist/git/forge.js +41 -0
- package/dist/git/index.d.ts +20 -0
- package/dist/git/index.js +121 -0
- package/dist/git/repo.d.ts +64 -0
- package/dist/git/repo.js +186 -0
- package/dist/git/run.d.ts +38 -0
- package/dist/git/run.js +127 -0
- package/dist/git/settings.d.ts +8 -0
- package/dist/git/settings.js +38 -0
- package/dist/git/text.d.ts +51 -0
- package/dist/git/text.js +109 -0
- package/dist/widgets/container/detect.d.ts +23 -0
- package/dist/widgets/container/detect.js +67 -0
- package/dist/widgets/container/index.d.ts +9 -0
- package/dist/widgets/container/index.js +26 -0
- package/dist/widgets/mcp/index.d.ts +13 -0
- package/dist/widgets/mcp/index.js +50 -0
- package/dist/widgets/mcp/status.d.ts +50 -0
- package/dist/widgets/mcp/status.js +70 -0
- package/dist/widgets/session-todos/index.d.ts +12 -0
- package/dist/widgets/session-todos/index.js +52 -0
- package/dist/widgets/subagents/index.d.ts +16 -0
- package/dist/widgets/subagents/index.js +173 -0
- package/dist/widgets/subagents/status.d.ts +61 -0
- package/dist/widgets/subagents/status.js +198 -0
- package/dist/widgets/todo/index.d.ts +13 -0
- package/dist/widgets/todo/index.js +65 -0
- package/dist/widgets/todo/parse.d.ts +29 -0
- package/dist/widgets/todo/parse.js +122 -0
- package/docs/branding.md +25 -0
- package/docs/development.md +22 -0
- package/docs/diff-api.md +18 -0
- package/docs/git.md +23 -0
- package/docs/internals.md +13 -0
- package/docs/provider-status.md +23 -0
- package/docs/status-widgets.md +157 -0
- package/docs/tool-rows.md +50 -0
- package/docs/usage.md +62 -0
- package/docs/widgets.md +113 -0
- package/extensions/chassis/alert.ts +127 -0
- package/extensions/chassis/api.ts +967 -0
- package/extensions/chassis/bash-output.ts +186 -0
- package/extensions/chassis/brand.ts +151 -0
- package/extensions/chassis/client.ts +284 -0
- package/extensions/chassis/commands.ts +244 -0
- package/extensions/chassis/editor.ts +253 -0
- package/extensions/chassis/footer.ts +131 -0
- package/extensions/chassis/header.ts +43 -0
- package/extensions/chassis/home.ts +186 -0
- package/extensions/chassis/icons.ts +220 -0
- package/extensions/chassis/index.ts +605 -0
- package/extensions/chassis/layout.ts +298 -0
- package/extensions/chassis/message-modes.ts +48 -0
- package/extensions/chassis/messages.ts +403 -0
- package/extensions/chassis/modes.ts +108 -0
- package/extensions/chassis/palette.ts +258 -0
- package/extensions/chassis/peek.ts +167 -0
- package/extensions/chassis/prompt-row.ts +86 -0
- package/extensions/chassis/provider-view.ts +118 -0
- package/extensions/chassis/provider.ts +115 -0
- package/extensions/chassis/readonly-command.ts +440 -0
- package/extensions/chassis/sanitize.ts +108 -0
- package/extensions/chassis/session-info.ts +127 -0
- package/extensions/chassis/sidebar.ts +285 -0
- package/extensions/chassis/state.ts +50 -0
- package/extensions/chassis/telemetry.ts +222 -0
- package/extensions/chassis/tools.ts +618 -0
- package/extensions/chassis/version.ts +20 -0
- package/extensions/diff/git-diff.ts +365 -0
- package/extensions/diff/host.ts +58 -0
- package/extensions/diff/index.ts +101 -0
- package/extensions/diff/render.ts +217 -0
- package/extensions/diff/types.ts +67 -0
- package/extensions/diff/view.ts +523 -0
- package/extensions/git/flows.ts +485 -0
- package/extensions/git/forge.ts +54 -0
- package/extensions/git/index.ts +117 -0
- package/extensions/git/repo.ts +200 -0
- package/extensions/git/run.ts +143 -0
- package/extensions/git/settings.ts +38 -0
- package/extensions/git/text.ts +133 -0
- package/extensions/widgets/container/detect.ts +81 -0
- package/extensions/widgets/container/index.ts +29 -0
- package/extensions/widgets/mcp/index.ts +53 -0
- package/extensions/widgets/mcp/status.ts +94 -0
- package/extensions/widgets/session-todos/index.ts +55 -0
- package/extensions/widgets/subagents/index.ts +170 -0
- package/extensions/widgets/subagents/status.ts +237 -0
- package/extensions/widgets/todo/index.ts +66 -0
- package/extensions/widgets/todo/parse.ts +119 -0
- package/package.json +91 -4
- package/scripts/link-pi.mjs +76 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container detection (no pi imports, so tests run standalone).
|
|
3
|
+
* Moved from ~/.pi/agent/extensions/container-status.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { hostname } from "node:os";
|
|
7
|
+
const realProbe = {
|
|
8
|
+
env: process.env,
|
|
9
|
+
exists: (p) => existsSync(p),
|
|
10
|
+
read: (p) => {
|
|
11
|
+
try {
|
|
12
|
+
return readFileSync(p, "utf8");
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
hostname: () => hostname(),
|
|
19
|
+
};
|
|
20
|
+
/** Podman writes `name="..."` into /run/.containerenv (rootful; often empty when rootless). */
|
|
21
|
+
function podmanName(text) {
|
|
22
|
+
const m = text?.match(/^name="([^"]*)"/m);
|
|
23
|
+
return m?.[1] || undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Container runtime evidence in cgroup/mount tables (catches runtimes without marker files). */
|
|
26
|
+
function cgroupRuntime(p) {
|
|
27
|
+
const text = `${p.read("/proc/1/cgroup") ?? ""}\n${p.read("/proc/self/mountinfo") ?? ""}`;
|
|
28
|
+
if (/kubepods/.test(text))
|
|
29
|
+
return "kubernetes";
|
|
30
|
+
if (/\/docker\/containers\/|\/docker[-/][0-9a-f]{12,}/.test(text))
|
|
31
|
+
return "docker";
|
|
32
|
+
if (/\/containers\/storage\/|libpod/.test(text))
|
|
33
|
+
return "podman";
|
|
34
|
+
if (/containerd|\/lxc\//.test(text))
|
|
35
|
+
return "container";
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
export function detectContainer(p = realProbe) {
|
|
39
|
+
const e = p.env;
|
|
40
|
+
const host = p.hostname().split(".")[0] || "container";
|
|
41
|
+
// Devcontainers / Codespaces first: they are containers too, and have better names.
|
|
42
|
+
if (e.CODESPACES === "true")
|
|
43
|
+
return { kind: "codespace", name: e.CODESPACE_NAME || host };
|
|
44
|
+
if (e.REMOTE_CONTAINERS === "true" || e.DEVCONTAINER === "true" || e.REMOTE_CONTAINERS_IPC) {
|
|
45
|
+
// An explicit DEVCONTAINER_NAME (set by a devcontainer launcher) is shown as-is, without the kind prefix.
|
|
46
|
+
if (e.DEVCONTAINER_NAME)
|
|
47
|
+
return { kind: "devcontainer", name: e.DEVCONTAINER_NAME, named: true };
|
|
48
|
+
return { kind: "devcontainer", name: e.DEVCONTAINER_ID || host };
|
|
49
|
+
}
|
|
50
|
+
if (e.KUBERNETES_SERVICE_HOST)
|
|
51
|
+
return { kind: "kubernetes", name: host };
|
|
52
|
+
if (p.exists("/run/.containerenv") || e.container === "podman") {
|
|
53
|
+
return { kind: "podman", name: podmanName(p.read("/run/.containerenv")) || host };
|
|
54
|
+
}
|
|
55
|
+
if (p.exists("/.dockerenv") || e.container === "docker")
|
|
56
|
+
return { kind: "docker", name: host };
|
|
57
|
+
if (e.container)
|
|
58
|
+
return { kind: e.container, name: host };
|
|
59
|
+
const cg = cgroupRuntime(p);
|
|
60
|
+
if (cg)
|
|
61
|
+
return { kind: cg, name: host };
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Label for a container: the kind is prefixed unless the name already says it. */
|
|
65
|
+
export function containerLabel(c) {
|
|
66
|
+
return c.named || c.name.toLowerCase().includes(c.kind) ? c.name : `${c.kind}:${c.name}`;
|
|
67
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container widget: shows when pi itself runs inside a container, devcontainer, Codespace or
|
|
3
|
+
* Kubernetes pod (first footer segment, sidebar "Host" row). On the workstation it shows nothing.
|
|
4
|
+
*
|
|
5
|
+
* Detection is pi's own process only: a container reached through `docker exec` from a pi running
|
|
6
|
+
* on the host is not detected, because pi is still on the host.
|
|
7
|
+
*/
|
|
8
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
export default function (pi: ExtensionAPI): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container widget: shows when pi itself runs inside a container, devcontainer, Codespace or
|
|
3
|
+
* Kubernetes pod (first footer segment, sidebar "Host" row). On the workstation it shows nothing.
|
|
4
|
+
*
|
|
5
|
+
* Detection is pi's own process only: a container reached through `docker exec` from a pi running
|
|
6
|
+
* on the host is not detected, because pi is still on the host.
|
|
7
|
+
*/
|
|
8
|
+
import { registerWidget } from "../../chassis/api.js";
|
|
9
|
+
import { ICONS } from "../../chassis/icons.js";
|
|
10
|
+
import { containerLabel, detectContainer } from "./detect.js";
|
|
11
|
+
// Nerd Font glyphs: md-docker, md-kubernetes.
|
|
12
|
+
const ICON_CONTAINER = { nerd: ICONS.widgetContainer.nerd, plain: ICONS.widgetContainer.plain };
|
|
13
|
+
const ICON_K8S = { nerd: ICONS.widgetK8s.nerd, plain: ICONS.widgetK8s.plain };
|
|
14
|
+
export default function (pi) {
|
|
15
|
+
// Can't change during a process's life, so detect once.
|
|
16
|
+
const info = detectContainer();
|
|
17
|
+
if (!info)
|
|
18
|
+
return;
|
|
19
|
+
registerWidget(pi, {
|
|
20
|
+
id: "container",
|
|
21
|
+
title: "Host",
|
|
22
|
+
order: 0,
|
|
23
|
+
render: () => ({ icon: info.kind === "kubernetes" ? ICON_K8S : ICON_CONTAINER, text: containerLabel(info), color: "accent" }),
|
|
24
|
+
detail: () => [info.kind],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP widget: "<plug> MCP 6/6" = connected/enabled servers for pi's built-in MCP support.
|
|
3
|
+
* Green when all are connected, yellow when some are, red when none are; hidden when no server is
|
|
4
|
+
* enabled. See status.ts for how "connected" is inferred and its limits; /mcp is authoritative.
|
|
5
|
+
*
|
|
6
|
+
* There is no event for MCP connection changes, so it polls (an in-memory tool list and two small
|
|
7
|
+
* JSON reads). It deliberately does not handle `mcp_servers_change`: handling that event marks an
|
|
8
|
+
* extension as the one that connects registered servers, taking that job from the built-in support.
|
|
9
|
+
*
|
|
10
|
+
* Tests: node --experimental-strip-types test/mcp-status.test.ts
|
|
11
|
+
*/
|
|
12
|
+
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
export default function (pi: ExtensionAPI): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP widget: "<plug> MCP 6/6" = connected/enabled servers for pi's built-in MCP support.
|
|
3
|
+
* Green when all are connected, yellow when some are, red when none are; hidden when no server is
|
|
4
|
+
* enabled. See status.ts for how "connected" is inferred and its limits; /mcp is authoritative.
|
|
5
|
+
*
|
|
6
|
+
* There is no event for MCP connection changes, so it polls (an in-memory tool list and two small
|
|
7
|
+
* JSON reads). It deliberately does not handle `mcp_servers_change`: handling that event marks an
|
|
8
|
+
* extension as the one that connects registered servers, taking that job from the built-in support.
|
|
9
|
+
*
|
|
10
|
+
* Tests: node --experimental-strip-types test/mcp-status.test.ts
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import { registerWidget } from "../../chassis/api.js";
|
|
16
|
+
import { ICONS } from "../../chassis/icons.js";
|
|
17
|
+
import { connectedServers, enabledServers, formatStatus, parseMcpServers, summarize } from "./status.js";
|
|
18
|
+
const POLL_MS = 2000;
|
|
19
|
+
// Nerd Font "md-power-plug" (U+F06A5).
|
|
20
|
+
const ICON = { nerd: ICONS.widgetMcp.nerd, plain: ICONS.widgetMcp.plain };
|
|
21
|
+
function readText(path) {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(path, "utf8");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export default function (pi) {
|
|
30
|
+
let status;
|
|
31
|
+
registerWidget(pi, {
|
|
32
|
+
id: "mcp",
|
|
33
|
+
title: "MCP",
|
|
34
|
+
order: 30,
|
|
35
|
+
refreshMs: POLL_MS,
|
|
36
|
+
update: (ctx) => {
|
|
37
|
+
const global = parseMcpServers(readText(join(getAgentDir(), "mcp.json")));
|
|
38
|
+
const project = ctx.isProjectTrusted() ? parseMcpServers(readText(join(ctx.cwd, ".pi", "mcp.json"))) : {};
|
|
39
|
+
const enabled = enabledServers(global, project, pi.getMcpServers());
|
|
40
|
+
status = summarize(enabled, connectedServers(enabled, pi.getAllTools()));
|
|
41
|
+
},
|
|
42
|
+
render: () => {
|
|
43
|
+
if (!status)
|
|
44
|
+
return undefined;
|
|
45
|
+
const level = status.level === "ok" ? "ok" : status.level === "partial" ? "warn" : "error";
|
|
46
|
+
return { icon: ICON, label: "MCP", text: formatStatus(status), level };
|
|
47
|
+
},
|
|
48
|
+
detail: () => (status?.pending.length ? status.pending.map((s) => `○ ${s} not connected`) : undefined),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure logic for the MCP footer status (no pi imports, so the tests run standalone).
|
|
3
|
+
*
|
|
4
|
+
* pi's built-in MCP support has no public connection-state API, so the state is inferred:
|
|
5
|
+
* - configured: enabled servers from ~/.pi/agent/mcp.json, the trusted project's
|
|
6
|
+
* .pi/mcp.json (project entries replace global ones of the same name), plus servers
|
|
7
|
+
* extensions registered with pi.registerMcpServer() (mcp.json wins on name clashes).
|
|
8
|
+
* - connected: the server has at least one registered tool in namespace mcp__<server>
|
|
9
|
+
* whose exposure is not "hidden". Tools register when a server connects; a disabled
|
|
10
|
+
* server's tools are re-registered as hidden.
|
|
11
|
+
* Limits: a dropped connection keeps its tools registered until the next call reconnects it,
|
|
12
|
+
* and a server that offers zero tools never counts as connected.
|
|
13
|
+
*/
|
|
14
|
+
/** Only `enabled` is read; other mcp.json fields (url, command, ...) pass through untyped. */
|
|
15
|
+
export interface ServerConfig {
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
url?: string;
|
|
18
|
+
command?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ToolLike {
|
|
21
|
+
exposure: string;
|
|
22
|
+
namespace?: {
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Same rule as pi's mcpNamespace(): "-" and "_" are equivalent in server names. */
|
|
27
|
+
export declare function mcpNamespace(server: string): string;
|
|
28
|
+
/** The mcpServers object of an mcp.json text, or {} when missing or invalid. */
|
|
29
|
+
export declare function parseMcpServers(text: string | undefined): Record<string, ServerConfig>;
|
|
30
|
+
/**
|
|
31
|
+
* Names of enabled servers, in precedence order: global < project (replaces by namespace),
|
|
32
|
+
* then registered servers whose namespace no config file defines.
|
|
33
|
+
*/
|
|
34
|
+
export declare function enabledServers(global: Record<string, ServerConfig>, project: Record<string, ServerConfig>, registered: Array<{
|
|
35
|
+
name: string;
|
|
36
|
+
config: ServerConfig;
|
|
37
|
+
}>): string[];
|
|
38
|
+
/** Servers among `servers` that have at least one non-hidden registered tool. */
|
|
39
|
+
export declare function connectedServers(servers: string[], tools: ToolLike[]): string[];
|
|
40
|
+
export type StatusLevel = "ok" | "partial" | "down";
|
|
41
|
+
export interface McpStatus {
|
|
42
|
+
connected: number;
|
|
43
|
+
enabled: number;
|
|
44
|
+
level: StatusLevel;
|
|
45
|
+
/** Enabled servers that are not connected yet. */
|
|
46
|
+
pending: string[];
|
|
47
|
+
}
|
|
48
|
+
/** Undefined when no server is enabled (the footer segment is hidden). */
|
|
49
|
+
export declare function summarize(enabled: string[], connected: string[]): McpStatus | undefined;
|
|
50
|
+
export declare function formatStatus(s: McpStatus): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure logic for the MCP footer status (no pi imports, so the tests run standalone).
|
|
3
|
+
*
|
|
4
|
+
* pi's built-in MCP support has no public connection-state API, so the state is inferred:
|
|
5
|
+
* - configured: enabled servers from ~/.pi/agent/mcp.json, the trusted project's
|
|
6
|
+
* .pi/mcp.json (project entries replace global ones of the same name), plus servers
|
|
7
|
+
* extensions registered with pi.registerMcpServer() (mcp.json wins on name clashes).
|
|
8
|
+
* - connected: the server has at least one registered tool in namespace mcp__<server>
|
|
9
|
+
* whose exposure is not "hidden". Tools register when a server connects; a disabled
|
|
10
|
+
* server's tools are re-registered as hidden.
|
|
11
|
+
* Limits: a dropped connection keeps its tools registered until the next call reconnects it,
|
|
12
|
+
* and a server that offers zero tools never counts as connected.
|
|
13
|
+
*/
|
|
14
|
+
/** Same rule as pi's mcpNamespace(): "-" and "_" are equivalent in server names. */
|
|
15
|
+
export function mcpNamespace(server) {
|
|
16
|
+
return `mcp__${server.replace(/-/g, "_")}`;
|
|
17
|
+
}
|
|
18
|
+
/** The mcpServers object of an mcp.json text, or {} when missing or invalid. */
|
|
19
|
+
export function parseMcpServers(text) {
|
|
20
|
+
if (!text)
|
|
21
|
+
return {};
|
|
22
|
+
try {
|
|
23
|
+
const servers = JSON.parse(text)?.mcpServers;
|
|
24
|
+
if (typeof servers !== "object" || servers === null || Array.isArray(servers))
|
|
25
|
+
return {};
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const [name, cfg] of Object.entries(servers)) {
|
|
28
|
+
if (typeof cfg === "object" && cfg !== null && !Array.isArray(cfg))
|
|
29
|
+
out[name] = cfg;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Names of enabled servers, in precedence order: global < project (replaces by namespace),
|
|
39
|
+
* then registered servers whose namespace no config file defines.
|
|
40
|
+
*/
|
|
41
|
+
export function enabledServers(global, project, registered) {
|
|
42
|
+
const byNs = new Map();
|
|
43
|
+
for (const [name, config] of Object.entries(global))
|
|
44
|
+
byNs.set(mcpNamespace(name), { name, config });
|
|
45
|
+
for (const [name, config] of Object.entries(project))
|
|
46
|
+
byNs.set(mcpNamespace(name), { name, config });
|
|
47
|
+
for (const r of registered) {
|
|
48
|
+
const ns = mcpNamespace(r.name);
|
|
49
|
+
if (!byNs.has(ns))
|
|
50
|
+
byNs.set(ns, r);
|
|
51
|
+
}
|
|
52
|
+
return [...byNs.values()].filter((s) => s.config.enabled !== false).map((s) => s.name);
|
|
53
|
+
}
|
|
54
|
+
/** Servers among `servers` that have at least one non-hidden registered tool. */
|
|
55
|
+
export function connectedServers(servers, tools) {
|
|
56
|
+
const live = new Set(tools.filter((t) => t.exposure !== "hidden" && t.namespace).map((t) => t.namespace.name));
|
|
57
|
+
return servers.filter((s) => live.has(mcpNamespace(s)));
|
|
58
|
+
}
|
|
59
|
+
/** Undefined when no server is enabled (the footer segment is hidden). */
|
|
60
|
+
export function summarize(enabled, connected) {
|
|
61
|
+
if (enabled.length === 0)
|
|
62
|
+
return undefined;
|
|
63
|
+
const live = new Set(connected);
|
|
64
|
+
const pending = enabled.filter((s) => !live.has(s));
|
|
65
|
+
const level = pending.length === 0 ? "ok" : connected.length === 0 ? "down" : "partial";
|
|
66
|
+
return { connected: connected.length, enabled: enabled.length, level, pending };
|
|
67
|
+
}
|
|
68
|
+
export function formatStatus(s) {
|
|
69
|
+
return `${s.connected}/${s.enabled}`;
|
|
70
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session todos widget: the latest todo list that a todo-style tool (pi's todo example, todowrite,
|
|
3
|
+
* ...) reported in this session, as its own sidebar section. Hidden when there is no list or
|
|
4
|
+
* everything is done. Separate from the TODO widget, which reads a TODO file in the repo.
|
|
5
|
+
*
|
|
6
|
+
* Todo
|
|
7
|
+
* [✓] Read the API
|
|
8
|
+
* [•] Write the tests
|
|
9
|
+
* [ ] Update the README
|
|
10
|
+
*/
|
|
11
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
export default function (pi: ExtensionAPI): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session todos widget: the latest todo list that a todo-style tool (pi's todo example, todowrite,
|
|
3
|
+
* ...) reported in this session, as its own sidebar section. Hidden when there is no list or
|
|
4
|
+
* everything is done. Separate from the TODO widget, which reads a TODO file in the repo.
|
|
5
|
+
*
|
|
6
|
+
* Todo
|
|
7
|
+
* [✓] Read the API
|
|
8
|
+
* [•] Write the tests
|
|
9
|
+
* [ ] Update the README
|
|
10
|
+
*/
|
|
11
|
+
import { registerWidget } from "../../chassis/api.js";
|
|
12
|
+
import { ICONS } from "../../chassis/icons.js";
|
|
13
|
+
import { primary } from "../../chassis/palette.js";
|
|
14
|
+
import { branchKey, latestTodos } from "../../chassis/session-info.js";
|
|
15
|
+
const SHOWN = 12;
|
|
16
|
+
/** Open todos only count as visible; a stale ctx after a session switch reads as "none". */
|
|
17
|
+
function todosOf(ctx) {
|
|
18
|
+
if (!ctx)
|
|
19
|
+
return [];
|
|
20
|
+
try {
|
|
21
|
+
return latestTodos(ctx);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default function (pi) {
|
|
28
|
+
registerWidget(pi, {
|
|
29
|
+
id: "session-todos",
|
|
30
|
+
title: "Todo",
|
|
31
|
+
icon: { nerd: ICONS.widgetSessionTodos.nerd, plain: ICONS.widgetSessionTodos.plain },
|
|
32
|
+
slots: ["sidebar"],
|
|
33
|
+
sidebar: "section",
|
|
34
|
+
order: 50,
|
|
35
|
+
// latestTodos scans the branch; redo it only when the branch changes.
|
|
36
|
+
cacheKey: ({ ctx }) => {
|
|
37
|
+
try {
|
|
38
|
+
return ctx ? branchKey(ctx) : "";
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return ""; // stale ctx after a session switch
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
render: ({ ctx }) => (todosOf(ctx).some((t) => !t.done) ? {} : undefined),
|
|
45
|
+
detail: ({ theme, ctx }) => todosOf(ctx)
|
|
46
|
+
.slice(0, SHOWN)
|
|
47
|
+
.map((t) => {
|
|
48
|
+
const box = t.done ? theme.fg("success", "[✓]") : t.active ? primary(theme, "[•]") : theme.fg("muted", "[ ]");
|
|
49
|
+
return `${box} ${t.done ? theme.fg("muted", t.text) : theme.fg("text", t.text)}`;
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagents widget: a sidebar section with this session's pi-subagents children.
|
|
3
|
+
*
|
|
4
|
+
* Subagents 2 running · 1 done
|
|
5
|
+
* ● build-api bash 1m02s
|
|
6
|
+
* ● scout fg 18s
|
|
7
|
+
* ✓ reviewer 2m10s
|
|
8
|
+
* ↓ on an empty prompt to inspect
|
|
9
|
+
*
|
|
10
|
+
* Data comes from pi-subagents' public in-process RPC (`status`, see its docs/extension-api.md),
|
|
11
|
+
* never from its files on disk, so this keeps working as pi-subagents changes internally.
|
|
12
|
+
* Inspecting, steering and stopping are FleetView's job (pi-subagents' own UI under the
|
|
13
|
+
* editor); the hint line points there. Hidden when pi-subagents isn't installed or nothing ran.
|
|
14
|
+
*/
|
|
15
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
export default function (pi: ExtensionAPI): void;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagents widget: a sidebar section with this session's pi-subagents children.
|
|
3
|
+
*
|
|
4
|
+
* Subagents 2 running · 1 done
|
|
5
|
+
* ● build-api bash 1m02s
|
|
6
|
+
* ● scout fg 18s
|
|
7
|
+
* ✓ reviewer 2m10s
|
|
8
|
+
* ↓ on an empty prompt to inspect
|
|
9
|
+
*
|
|
10
|
+
* Data comes from pi-subagents' public in-process RPC (`status`, see its docs/extension-api.md),
|
|
11
|
+
* never from its files on disk, so this keeps working as pi-subagents changes internally.
|
|
12
|
+
* Inspecting, steering and stopping are FleetView's job (pi-subagents' own UI under the
|
|
13
|
+
* editor); the hint line points there. Hidden when pi-subagents isn't installed or nothing ran.
|
|
14
|
+
*/
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
17
|
+
import { registerWidget } from "../../chassis/api.js";
|
|
18
|
+
import { ICONS } from "../../chassis/icons.js";
|
|
19
|
+
import { readFileSync } from "node:fs";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { asyncActiveFrom, elapsed, fmtCount, GLYPH, limitsLine, orderRows, parallelFrom, rowsFromStatus, shortModel, spawnedFrom, summary } from "./status.js";
|
|
23
|
+
const REQUEST = "subagents:rpc:v1:request";
|
|
24
|
+
const REPLY = "subagents:rpc:v1:reply:";
|
|
25
|
+
const READY = "subagents:rpc:v1:ready";
|
|
26
|
+
const POLL_MS = 2_000;
|
|
27
|
+
const TIMEOUT_MS = 5_000;
|
|
28
|
+
const SHOWN = 8;
|
|
29
|
+
/** Running children that also get a model and token line, so the section stays short. */
|
|
30
|
+
const SHOWN_DETAIL = 5;
|
|
31
|
+
/** The spawn budget needs the heavier executor-backed status call: at most this often. */
|
|
32
|
+
const BUDGET_MIN_MS = 5_000;
|
|
33
|
+
/** Even lifecycle events (which can come in bursts) wait this long between budget calls. */
|
|
34
|
+
const BUDGET_FLOOR_MS = 1_000;
|
|
35
|
+
function readConfigText() {
|
|
36
|
+
try {
|
|
37
|
+
return readFileSync(join(process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"), "extensions", "subagent", "config.json"), "utf8");
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** One `status` request; resolves to the reply's data, or undefined without pi-subagents. */
|
|
44
|
+
function requestStatus(pi, params = {}) {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const requestId = randomUUID();
|
|
47
|
+
let off;
|
|
48
|
+
const timer = setTimeout(() => {
|
|
49
|
+
off?.();
|
|
50
|
+
resolve(undefined);
|
|
51
|
+
}, TIMEOUT_MS);
|
|
52
|
+
timer.unref?.();
|
|
53
|
+
off = pi.events.on(`${REPLY}${requestId}`, (raw) => {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
off?.();
|
|
56
|
+
const r = raw;
|
|
57
|
+
resolve(r?.success ? r.data : undefined);
|
|
58
|
+
});
|
|
59
|
+
pi.events.emit(REQUEST, { version: 1, requestId, method: "status", params, source: { extension: "pi-chassis" } });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export default function (pi) {
|
|
63
|
+
let rows = [];
|
|
64
|
+
let inFlight = false;
|
|
65
|
+
let limits = {};
|
|
66
|
+
let budgetBusy = false;
|
|
67
|
+
let budgetAt = 0;
|
|
68
|
+
/** Spawn count and cap. Rarely needed, and costlier than the poll, so throttled. */
|
|
69
|
+
const refreshBudget = async (force = false) => {
|
|
70
|
+
if (budgetBusy || Date.now() - budgetAt < (force ? BUDGET_FLOOR_MS : BUDGET_MIN_MS))
|
|
71
|
+
return;
|
|
72
|
+
budgetBusy = true;
|
|
73
|
+
budgetAt = Date.now();
|
|
74
|
+
try {
|
|
75
|
+
const data = await requestStatus(pi, { view: "fleet" });
|
|
76
|
+
if (data !== undefined)
|
|
77
|
+
limits = { ...limits, spawned: spawnedFrom(data) ?? limits.spawned };
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
budgetBusy = false;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const update = async (_ctx) => {
|
|
84
|
+
if (inFlight)
|
|
85
|
+
return;
|
|
86
|
+
inFlight = true;
|
|
87
|
+
try {
|
|
88
|
+
const data = await requestStatus(pi);
|
|
89
|
+
if (data !== undefined) {
|
|
90
|
+
rows = orderRows(rowsFromStatus(data));
|
|
91
|
+
limits = { ...limits, asyncActive: asyncActiveFrom(data), parallel: parallelFrom(readConfigText()) };
|
|
92
|
+
// A new child changes the spawn count, so look again while something is active.
|
|
93
|
+
if (rows.some((r) => r.state === "running" || r.state === "queued"))
|
|
94
|
+
void refreshBudget();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
inFlight = false;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const handle = registerWidget(pi, {
|
|
102
|
+
id: "subagents",
|
|
103
|
+
title: "Subagents",
|
|
104
|
+
icon: { nerd: ICONS.widgetSubagents.nerd, plain: ICONS.widgetSubagents.plain },
|
|
105
|
+
// pi-subagents' slash commands publish short-lived statuses ("0 tools | ctrl+o live detail")
|
|
106
|
+
// that this section already covers with per-child rows, so they're not listed a second time.
|
|
107
|
+
statusKeys: ["subagent-slash", "subagent-slash-text"],
|
|
108
|
+
slots: ["sidebar", "footer"],
|
|
109
|
+
sidebar: "section",
|
|
110
|
+
order: 35,
|
|
111
|
+
refreshMs: POLL_MS,
|
|
112
|
+
update,
|
|
113
|
+
render: () => {
|
|
114
|
+
if (!rows.length)
|
|
115
|
+
return undefined;
|
|
116
|
+
const s = summary(rows);
|
|
117
|
+
return { label: "subagents", text: s.text, level: s.running ? "ok" : s.failed ? "warn" : "off", color: s.running ? "text" : undefined };
|
|
118
|
+
},
|
|
119
|
+
detail: ({ theme, width }) => {
|
|
120
|
+
if (!rows.length)
|
|
121
|
+
return undefined;
|
|
122
|
+
const tone = (r, x) => theme.fg(r.state === "running" ? "accent" : r.state === "done" ? "success" : r.state === "failed" ? "error" : r.state === "paused" ? "warning" : "dim", x);
|
|
123
|
+
const lines = rows.slice(0, SHOWN).map((r) => {
|
|
124
|
+
const active = r.state === "running" || r.state === "queued" || r.state === "paused";
|
|
125
|
+
const left = `${tone(r, GLYPH[r.state])} ${theme.fg(active ? "text" : "muted", r.label)}${r.foreground ? theme.fg("dim", " fg") : ""}`;
|
|
126
|
+
const right = theme.fg("dim", [r.currentTool, elapsed(r)].filter(Boolean).join(" "));
|
|
127
|
+
const gap = width - visibleWidth(left) - visibleWidth(right);
|
|
128
|
+
return gap >= 1 ? `${left}${" ".repeat(gap)}${right}` : truncateToWidth(left, width, "…");
|
|
129
|
+
});
|
|
130
|
+
// Model and tokens under running children: " opus-5-5 · 16k tokens".
|
|
131
|
+
const withFacts = [];
|
|
132
|
+
let factRows = 0;
|
|
133
|
+
rows.slice(0, SHOWN).forEach((r, i) => {
|
|
134
|
+
withFacts.push(lines[i]);
|
|
135
|
+
const facts = [r.model ? shortModel(r.model) : "", r.tokens ? `${fmtCount(r.tokens)} tokens` : ""].filter(Boolean).join(" · ");
|
|
136
|
+
if (facts && r.state === "running" && factRows < SHOWN_DETAIL) {
|
|
137
|
+
factRows++;
|
|
138
|
+
withFacts.push(truncateToWidth(` ${theme.fg("dim", facts)}`, width, "…"));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
lines.length = 0;
|
|
142
|
+
lines.push(...withFacts);
|
|
143
|
+
if (rows.length > SHOWN)
|
|
144
|
+
lines.push(theme.fg("dim", `+${rows.length - SHOWN} more`));
|
|
145
|
+
const limit = limitsLine(limits);
|
|
146
|
+
if (limit)
|
|
147
|
+
lines.push(theme.fg("dim", limit));
|
|
148
|
+
if (summary(rows).running)
|
|
149
|
+
lines.push(theme.fg("dim", "↓ on an empty prompt to inspect"));
|
|
150
|
+
return lines;
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
// Refresh promptly on pi-subagents' lifecycle events, on top of the poll.
|
|
154
|
+
for (const ev of [READY, "subagent:async-started", "subagent:async-complete", "subagent:child-status"]) {
|
|
155
|
+
pi.events.on(ev, () => {
|
|
156
|
+
setTimeout(() => handle.refresh(), 150);
|
|
157
|
+
void refreshBudget(true);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
pi.on("tool_execution_start", async (e) => {
|
|
161
|
+
if (e.toolName === "subagent")
|
|
162
|
+
setTimeout(() => handle.refresh(), 300);
|
|
163
|
+
});
|
|
164
|
+
pi.on("tool_execution_end", async (e) => {
|
|
165
|
+
if (e.toolName === "subagent")
|
|
166
|
+
setTimeout(() => handle.refresh(), 300);
|
|
167
|
+
});
|
|
168
|
+
pi.on("session_start", async () => {
|
|
169
|
+
rows = [];
|
|
170
|
+
limits = {};
|
|
171
|
+
budgetAt = 0;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projection of pi-subagents' public `status` RPC reply into sidebar rows.
|
|
3
|
+
*
|
|
4
|
+
* Reads only the documented, versioned shapes from pi-subagents' docs/extension-api.md:
|
|
5
|
+
* `data.asyncSnapshot` (kind "pi-subagents.async-status-snapshot", version 1) for background
|
|
6
|
+
* runs, and `data.fleet` (version 1) for active foreground children, which the snapshot doesn't
|
|
7
|
+
* cover. Unknown fields are ignored, as that doc asks. No pi imports, so tests stay light.
|
|
8
|
+
*/
|
|
9
|
+
export type RowState = "running" | "queued" | "done" | "failed" | "paused" | "stopped";
|
|
10
|
+
export interface Row {
|
|
11
|
+
label: string;
|
|
12
|
+
state: RowState;
|
|
13
|
+
currentTool?: string;
|
|
14
|
+
startedAt?: number;
|
|
15
|
+
endedAt?: number;
|
|
16
|
+
/** A foreground child (from the fleet DTO). */
|
|
17
|
+
foreground?: boolean;
|
|
18
|
+
/** Model as the fleet DTO reports it, e.g. "anthropic/claude-opus-5-5". Active children only. */
|
|
19
|
+
model?: string;
|
|
20
|
+
/** Tokens so far (input + output). Active children only. */
|
|
21
|
+
tokens?: number;
|
|
22
|
+
}
|
|
23
|
+
/** What the sidebar shows about the limits, from the status reply and the config file. */
|
|
24
|
+
export interface Limits {
|
|
25
|
+
/** Children launched this session, and the cap (null: no cap). */
|
|
26
|
+
spawned?: {
|
|
27
|
+
used: number;
|
|
28
|
+
limit: number | null;
|
|
29
|
+
};
|
|
30
|
+
/** Background runs active in this session, and the cap (only when a cap is configured). */
|
|
31
|
+
asyncActive?: {
|
|
32
|
+
used: number;
|
|
33
|
+
limit: number;
|
|
34
|
+
};
|
|
35
|
+
/** `globalConcurrencyLimit`: children running at once inside one run. */
|
|
36
|
+
parallel?: number;
|
|
37
|
+
}
|
|
38
|
+
/** Rows from a `status` reply's `data`: background leaves, then active foreground children. */
|
|
39
|
+
export declare function rowsFromStatus(data: unknown): Row[];
|
|
40
|
+
/** "anthropic/claude-opus-5-5" becomes "opus-5-5". */
|
|
41
|
+
export declare function shortModel(model: string): string;
|
|
42
|
+
/** 16147 becomes "16k", 1_200_000 becomes "1.2M". */
|
|
43
|
+
export declare function fmtCount(n: number): string;
|
|
44
|
+
/** Spawn budget from a `status` reply made with `view: "fleet"` (`data.details.spawnBudget`). */
|
|
45
|
+
export declare function spawnedFrom(data: unknown): Limits["spawned"];
|
|
46
|
+
/** Active async runs and their cap from the fleet DTO; undefined when no cap is configured. */
|
|
47
|
+
export declare function asyncActiveFrom(data: unknown): Limits["asyncActive"];
|
|
48
|
+
/** `globalConcurrencyLimit` from pi-subagents' config.json text (default 20 when absent). */
|
|
49
|
+
export declare function parallelFrom(configText: string | undefined): number;
|
|
50
|
+
/** The limits line under the rows, or undefined when there is nothing to say. */
|
|
51
|
+
export declare function limitsLine(l: Limits): string | undefined;
|
|
52
|
+
/** Active first (oldest first), then finished (newest first). */
|
|
53
|
+
export declare function orderRows(rows: Row[]): Row[];
|
|
54
|
+
export declare function summary(rows: Row[]): {
|
|
55
|
+
text: string;
|
|
56
|
+
running: number;
|
|
57
|
+
failed: number;
|
|
58
|
+
};
|
|
59
|
+
export declare function elapsed(r: Row, now?: number): string;
|
|
60
|
+
/** Plain glyphs that exist in common monospace fonts. */
|
|
61
|
+
export declare const GLYPH: Record<RowState, string>;
|