shellpuppet 0.0.1 → 0.1.0
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/LICENSE +202 -0
- package/NOTICE +31 -0
- package/README.md +340 -8
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.js +693 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/http.d.ts +82 -0
- package/dist/client/http.js +225 -0
- package/dist/client/http.js.map +1 -0
- package/dist/core/dialogs.d.ts +88 -0
- package/dist/core/dialogs.js +214 -0
- package/dist/core/dialogs.js.map +1 -0
- package/dist/core/echo.d.ts +71 -0
- package/dist/core/echo.js +249 -0
- package/dist/core/echo.js.map +1 -0
- package/dist/core/find.d.ts +34 -0
- package/dist/core/find.js +41 -0
- package/dist/core/find.js.map +1 -0
- package/dist/core/keys.d.ts +22 -0
- package/dist/core/keys.js +80 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/manager.d.ts +66 -0
- package/dist/core/manager.js +158 -0
- package/dist/core/manager.js.map +1 -0
- package/dist/core/nativePty.d.ts +69 -0
- package/dist/core/nativePty.js +156 -0
- package/dist/core/nativePty.js.map +1 -0
- package/dist/core/policy.d.ts +61 -0
- package/dist/core/policy.js +143 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/promptDetector.d.ts +75 -0
- package/dist/core/promptDetector.js +606 -0
- package/dist/core/promptDetector.js.map +1 -0
- package/dist/core/reasoning.d.ts +252 -0
- package/dist/core/reasoning.js +740 -0
- package/dist/core/reasoning.js.map +1 -0
- package/dist/core/regexBudget.d.ts +44 -0
- package/dist/core/regexBudget.js +79 -0
- package/dist/core/regexBudget.js.map +1 -0
- package/dist/core/renderer.d.ts +112 -0
- package/dist/core/renderer.js +225 -0
- package/dist/core/renderer.js.map +1 -0
- package/dist/core/session.d.ts +311 -0
- package/dist/core/session.js +966 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/types.d.ts +281 -0
- package/dist/core/types.js +47 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/waiter.d.ts +86 -0
- package/dist/core/waiter.js +317 -0
- package/dist/core/waiter.js.map +1 -0
- package/dist/core/windowsPtyStart.d.ts +90 -0
- package/dist/core/windowsPtyStart.js +129 -0
- package/dist/core/windowsPtyStart.js.map +1 -0
- package/dist/daemon/audit.d.ts +23 -0
- package/dist/daemon/audit.js +51 -0
- package/dist/daemon/audit.js.map +1 -0
- package/dist/daemon/auth.d.ts +127 -0
- package/dist/daemon/auth.js +241 -0
- package/dist/daemon/auth.js.map +1 -0
- package/dist/daemon/config.d.ts +76 -0
- package/dist/daemon/config.js +301 -0
- package/dist/daemon/config.js.map +1 -0
- package/dist/daemon/index.d.ts +7 -0
- package/dist/daemon/index.js +87 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/daemon/liveness.d.ts +36 -0
- package/dist/daemon/liveness.js +71 -0
- package/dist/daemon/liveness.js.map +1 -0
- package/dist/daemon/logger.d.ts +7 -0
- package/dist/daemon/logger.js +29 -0
- package/dist/daemon/logger.js.map +1 -0
- package/dist/daemon/meta.d.ts +9 -0
- package/dist/daemon/meta.js +24 -0
- package/dist/daemon/meta.js.map +1 -0
- package/dist/daemon/paths.d.ts +83 -0
- package/dist/daemon/paths.js +154 -0
- package/dist/daemon/paths.js.map +1 -0
- package/dist/daemon/screenshot.d.ts +87 -0
- package/dist/daemon/screenshot.js +256 -0
- package/dist/daemon/screenshot.js.map +1 -0
- package/dist/daemon/server.d.ts +244 -0
- package/dist/daemon/server.js +2187 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/terminalReports.d.ts +38 -0
- package/dist/daemon/terminalReports.js +84 -0
- package/dist/daemon/terminalReports.js.map +1 -0
- package/dist/daemon/viewerLauncher.d.ts +135 -0
- package/dist/daemon/viewerLauncher.js +280 -0
- package/dist/daemon/viewerLauncher.js.map +1 -0
- package/dist/daemon/viewerSync.d.ts +38 -0
- package/dist/daemon/viewerSync.js +83 -0
- package/dist/daemon/viewerSync.js.map +1 -0
- package/dist/mcp/config.d.ts +57 -0
- package/dist/mcp/config.js +106 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.js +69 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tools.d.ts +59 -0
- package/dist/mcp/tools.js +537 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/viewer/icon-16.png +0 -0
- package/dist/viewer/icon-180.png +0 -0
- package/dist/viewer/icon-32.png +0 -0
- package/dist/viewer/icon-512.png +0 -0
- package/dist/viewer/icon.svg +66 -0
- package/dist/viewer/index.html +56 -0
- package/dist/viewer/viewer.css +84 -0
- package/dist/viewer/viewer.js +661 -0
- package/package.json +66 -7
- package/index.js +0 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP adapter entry: a stdio MCP server that is a thin client to the shared
|
|
3
|
+
* daemon (design §2.1: it must never own PTYs itself).
|
|
4
|
+
*
|
|
5
|
+
* stdout belongs ENTIRELY to the MCP protocol. Nothing on this code path may
|
|
6
|
+
* print to it: diagnostics go to stderr, which MCP clients capture as logs.
|
|
7
|
+
* Importing this module starts the server; the CLI's `mcp` verb does exactly
|
|
8
|
+
* that.
|
|
9
|
+
*/
|
|
10
|
+
import process from 'node:process';
|
|
11
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
13
|
+
import { readMcpConfig } from './config.js';
|
|
14
|
+
import { readDaemonConfig } from '../daemon/config.js';
|
|
15
|
+
import { registerTools } from './tools.js';
|
|
16
|
+
import { assertNodeVersion, packageVersion } from '../daemon/meta.js';
|
|
17
|
+
import { shellpuppetHome } from '../daemon/paths.js';
|
|
18
|
+
const stderrLogger = {
|
|
19
|
+
debug: () => undefined,
|
|
20
|
+
info: (message, meta) => console.error(`shellpuppet-mcp: ${message}`, meta ?? ''),
|
|
21
|
+
warn: (message, meta) => console.error(`shellpuppet-mcp warning: ${message}`, meta ?? ''),
|
|
22
|
+
error: (message, meta) => console.error(`shellpuppet-mcp error: ${message}`, meta ?? ''),
|
|
23
|
+
};
|
|
24
|
+
async function main() {
|
|
25
|
+
assertNodeVersion();
|
|
26
|
+
const server = new McpServer({ name: 'shellpuppet', version: packageVersion() });
|
|
27
|
+
const home = shellpuppetHome();
|
|
28
|
+
const config = readMcpConfig(home, stderrLogger);
|
|
29
|
+
// The variable lists are read afresh at every terminal_start, so a change
|
|
30
|
+
// to config applies to the next session with no restart. The agents
|
|
31
|
+
// section is the daemon's to parse; its problems are reported once each.
|
|
32
|
+
const reported = new Set();
|
|
33
|
+
const reportOnce = (problem) => {
|
|
34
|
+
if (reported.has(problem))
|
|
35
|
+
return;
|
|
36
|
+
reported.add(problem);
|
|
37
|
+
stderrLogger.warn(problem);
|
|
38
|
+
};
|
|
39
|
+
const onceLogger = { ...stderrLogger, warn: (message) => reportOnce(message) };
|
|
40
|
+
const readPassLists = () => {
|
|
41
|
+
const agents = readDaemonConfig(home);
|
|
42
|
+
for (const problem of agents.problems.filter((p) => p.startsWith('agents')))
|
|
43
|
+
reportOnce(problem);
|
|
44
|
+
return {
|
|
45
|
+
passEnv: readMcpConfig(home, onceLogger).passEnv,
|
|
46
|
+
agentPassEnv: agents.config.agentPassEnv ?? {},
|
|
47
|
+
agentSignatures: agents.config.agentSignatures ?? [],
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
readPassLists();
|
|
51
|
+
registerTools(server, {
|
|
52
|
+
logger: stderrLogger,
|
|
53
|
+
untrustedFraming: config.untrustedFraming,
|
|
54
|
+
readPassLists,
|
|
55
|
+
// Audit actor (design §4.5): identify the calling MCP client (Claude
|
|
56
|
+
// Code, Qoder, Cursor…) from the initialize handshake. Resolved per call,
|
|
57
|
+
// because clientInfo does not exist until after the handshake completes.
|
|
58
|
+
actor: () => {
|
|
59
|
+
const info = server.server.getClientVersion();
|
|
60
|
+
return info !== undefined ? `mcp:${info.name}` : 'mcp';
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
await server.connect(new StdioServerTransport());
|
|
64
|
+
}
|
|
65
|
+
main().catch((error) => {
|
|
66
|
+
console.error(`shellpuppet-mcp failed to start: ${error instanceof Error ? error.message : String(error)}`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,YAAY,GAAW;IAC3B,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS;IACtB,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IACjF,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,4BAA4B,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IACzF,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,0BAA0B,OAAO,E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AAE;SACrD,CAAC;IACJ,CAAC,CAAC;IACF,aAAa,EAAE,CAAC;IAChB,aAAa,CAAC,MAAM,EAAE;QACpB,MAAM,EAAE,YAAY;QACpB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,aAAa;QACb,qEAAqE;QACrE,0EAA0E;QAC1E,yEAAyE;QACzE,KAAK,EAAE,GAAG,EAAE;YACV,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC9C,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QACzD,CAAC;KACF,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,OAAO,CAAC,KAAK,CACX,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC7F,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `terminal_*` MCP tools (design §3): a thin shell over the daemon HTTP
|
|
3
|
+
* API. Small and semantic on purpose.
|
|
4
|
+
*
|
|
5
|
+
* Two design requirements are baked into every relevant tool:
|
|
6
|
+
*
|
|
7
|
+
* Under §3.1, the behavioural warnings drawn from real failures live in the
|
|
8
|
+
* tool descriptions themselves: first paint ≠ ready, the echo trap, `escape`
|
|
9
|
+
* as the focus reset, generous timeouts for agent CLIs.
|
|
10
|
+
*
|
|
11
|
+
* Under §4.4, screen content is UNTRUSTED DATA. Everything read back from a
|
|
12
|
+
* terminal (snapshot, wait, find) is wrapped in explicit delimiters with a
|
|
13
|
+
* one-line reminder, because models attend to what they read far more reliably
|
|
14
|
+
* than to schema text they saw once. Toggleable via config, on by default.
|
|
15
|
+
*/
|
|
16
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
17
|
+
import type { ClientOptions } from '../client/http.js';
|
|
18
|
+
import type { AgentSignature } from '../core/reasoning.js';
|
|
19
|
+
export interface McpToolOptions extends ClientOptions {
|
|
20
|
+
/** §4.4 framing toggle: config `mcp.untrustedFraming`, default true. */
|
|
21
|
+
untrustedFraming?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Config `mcp.passEnv`: the variables `terminal_start` may pass from this
|
|
24
|
+
* server's environment into a session (§4.6). Empty or absent passes none.
|
|
25
|
+
*/
|
|
26
|
+
passEnv?: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* Config `agents.passEnv`: the variables each agent's sessions receive from
|
|
29
|
+
* this server's environment, by agent name (§4.6).
|
|
30
|
+
*/
|
|
31
|
+
agentPassEnv?: Readonly<Record<string, readonly string[]>>;
|
|
32
|
+
/** Config `agents.signatures`, so a start is recognised as the agent the daemon will see. */
|
|
33
|
+
agentSignatures?: readonly AgentSignature[];
|
|
34
|
+
/**
|
|
35
|
+
* Reads the three lists above afresh from config. Called at every
|
|
36
|
+
* `terminal_start`, so a change to config applies to the next session
|
|
37
|
+
* started with no restart. Absent, the lists given above are used as they
|
|
38
|
+
* are.
|
|
39
|
+
*/
|
|
40
|
+
readPassLists?: () => PassLists;
|
|
41
|
+
/** Where passed values are read from: this process's environment unless a test says otherwise. */
|
|
42
|
+
environment?: NodeJS.ProcessEnv;
|
|
43
|
+
}
|
|
44
|
+
type Body = Record<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* How the human reaches a session that has just started. When the daemon
|
|
47
|
+
* opened a viewer window there is no link to pass on, and none was minted, so
|
|
48
|
+
* the agent has nothing to paste into a transcript. When nothing opened, the
|
|
49
|
+
* one-use URL in the payload is the human's way in and has to reach them.
|
|
50
|
+
*/
|
|
51
|
+
export declare function viewerLine(payload: Body): string;
|
|
52
|
+
/** The lists `terminal_start` passes variables by (§4.6). */
|
|
53
|
+
export interface PassLists {
|
|
54
|
+
passEnv: readonly string[];
|
|
55
|
+
agentPassEnv: Readonly<Record<string, readonly string[]>>;
|
|
56
|
+
agentSignatures: readonly AgentSignature[];
|
|
57
|
+
}
|
|
58
|
+
export declare function registerTools(server: McpServer, options?: McpToolOptions): void;
|
|
59
|
+
export {};
|