shellpuppet 0.0.1 → 0.2.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.
Files changed (137) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +31 -0
  3. package/README.md +499 -8
  4. package/dist/cli/desktopShortcut.d.ts +22 -0
  5. package/dist/cli/desktopShortcut.js +157 -0
  6. package/dist/cli/desktopShortcut.js.map +1 -0
  7. package/dist/cli/index.d.ts +13 -0
  8. package/dist/cli/index.js +846 -0
  9. package/dist/cli/index.js.map +1 -0
  10. package/dist/client/http.d.ts +143 -0
  11. package/dist/client/http.js +581 -0
  12. package/dist/client/http.js.map +1 -0
  13. package/dist/core/dialogs.d.ts +96 -0
  14. package/dist/core/dialogs.js +226 -0
  15. package/dist/core/dialogs.js.map +1 -0
  16. package/dist/core/echo.d.ts +71 -0
  17. package/dist/core/echo.js +249 -0
  18. package/dist/core/echo.js.map +1 -0
  19. package/dist/core/find.d.ts +34 -0
  20. package/dist/core/find.js +41 -0
  21. package/dist/core/find.js.map +1 -0
  22. package/dist/core/keys.d.ts +22 -0
  23. package/dist/core/keys.js +80 -0
  24. package/dist/core/keys.js.map +1 -0
  25. package/dist/core/manager.d.ts +96 -0
  26. package/dist/core/manager.js +271 -0
  27. package/dist/core/manager.js.map +1 -0
  28. package/dist/core/nativePty.d.ts +73 -0
  29. package/dist/core/nativePty.js +161 -0
  30. package/dist/core/nativePty.js.map +1 -0
  31. package/dist/core/policy.d.ts +61 -0
  32. package/dist/core/policy.js +143 -0
  33. package/dist/core/policy.js.map +1 -0
  34. package/dist/core/promptDetector.d.ts +109 -0
  35. package/dist/core/promptDetector.js +897 -0
  36. package/dist/core/promptDetector.js.map +1 -0
  37. package/dist/core/reasoning.d.ts +265 -0
  38. package/dist/core/reasoning.js +933 -0
  39. package/dist/core/reasoning.js.map +1 -0
  40. package/dist/core/regexBudget.d.ts +64 -0
  41. package/dist/core/regexBudget.js +103 -0
  42. package/dist/core/regexBudget.js.map +1 -0
  43. package/dist/core/renderer.d.ts +127 -0
  44. package/dist/core/renderer.js +316 -0
  45. package/dist/core/renderer.js.map +1 -0
  46. package/dist/core/selection.d.ts +6 -0
  47. package/dist/core/selection.js +48 -0
  48. package/dist/core/selection.js.map +1 -0
  49. package/dist/core/session.d.ts +565 -0
  50. package/dist/core/session.js +1450 -0
  51. package/dist/core/session.js.map +1 -0
  52. package/dist/core/types.d.ts +316 -0
  53. package/dist/core/types.js +71 -0
  54. package/dist/core/types.js.map +1 -0
  55. package/dist/core/waiter.d.ts +94 -0
  56. package/dist/core/waiter.js +310 -0
  57. package/dist/core/waiter.js.map +1 -0
  58. package/dist/core/windowsConsoleHost.d.ts +147 -0
  59. package/dist/core/windowsConsoleHost.js +588 -0
  60. package/dist/core/windowsConsoleHost.js.map +1 -0
  61. package/dist/core/windowsPtyStart.d.ts +161 -0
  62. package/dist/core/windowsPtyStart.js +236 -0
  63. package/dist/core/windowsPtyStart.js.map +1 -0
  64. package/dist/daemon/audit.d.ts +23 -0
  65. package/dist/daemon/audit.js +51 -0
  66. package/dist/daemon/audit.js.map +1 -0
  67. package/dist/daemon/auth.d.ts +197 -0
  68. package/dist/daemon/auth.js +366 -0
  69. package/dist/daemon/auth.js.map +1 -0
  70. package/dist/daemon/config.d.ts +119 -0
  71. package/dist/daemon/config.js +568 -0
  72. package/dist/daemon/config.js.map +1 -0
  73. package/dist/daemon/folderPicker.d.ts +27 -0
  74. package/dist/daemon/folderPicker.js +115 -0
  75. package/dist/daemon/folderPicker.js.map +1 -0
  76. package/dist/daemon/index.d.ts +7 -0
  77. package/dist/daemon/index.js +88 -0
  78. package/dist/daemon/index.js.map +1 -0
  79. package/dist/daemon/launchProfiles.d.ts +155 -0
  80. package/dist/daemon/launchProfiles.js +554 -0
  81. package/dist/daemon/launchProfiles.js.map +1 -0
  82. package/dist/daemon/liveness.d.ts +36 -0
  83. package/dist/daemon/liveness.js +71 -0
  84. package/dist/daemon/liveness.js.map +1 -0
  85. package/dist/daemon/logger.d.ts +7 -0
  86. package/dist/daemon/logger.js +29 -0
  87. package/dist/daemon/logger.js.map +1 -0
  88. package/dist/daemon/meta.d.ts +9 -0
  89. package/dist/daemon/meta.js +24 -0
  90. package/dist/daemon/meta.js.map +1 -0
  91. package/dist/daemon/paths.d.ts +85 -0
  92. package/dist/daemon/paths.js +154 -0
  93. package/dist/daemon/paths.js.map +1 -0
  94. package/dist/daemon/screenshot.d.ts +144 -0
  95. package/dist/daemon/screenshot.js +402 -0
  96. package/dist/daemon/screenshot.js.map +1 -0
  97. package/dist/daemon/server.d.ts +453 -0
  98. package/dist/daemon/server.js +3954 -0
  99. package/dist/daemon/server.js.map +1 -0
  100. package/dist/daemon/sessionFeed.d.ts +48 -0
  101. package/dist/daemon/sessionFeed.js +101 -0
  102. package/dist/daemon/sessionFeed.js.map +1 -0
  103. package/dist/daemon/terminalReports.d.ts +38 -0
  104. package/dist/daemon/terminalReports.js +84 -0
  105. package/dist/daemon/terminalReports.js.map +1 -0
  106. package/dist/daemon/viewerLauncher.d.ts +226 -0
  107. package/dist/daemon/viewerLauncher.js +562 -0
  108. package/dist/daemon/viewerLauncher.js.map +1 -0
  109. package/dist/daemon/viewerSync.d.ts +38 -0
  110. package/dist/daemon/viewerSync.js +83 -0
  111. package/dist/daemon/viewerSync.js.map +1 -0
  112. package/dist/mcp/config.d.ts +50 -0
  113. package/dist/mcp/config.js +95 -0
  114. package/dist/mcp/config.js.map +1 -0
  115. package/dist/mcp/index.d.ts +10 -0
  116. package/dist/mcp/index.js +78 -0
  117. package/dist/mcp/index.js.map +1 -0
  118. package/dist/mcp/tools.d.ts +66 -0
  119. package/dist/mcp/tools.js +638 -0
  120. package/dist/mcp/tools.js.map +1 -0
  121. package/dist/viewer/dashboard-folders.js +20 -0
  122. package/dist/viewer/dashboard-layout.js +52 -0
  123. package/dist/viewer/dashboard.css +67 -0
  124. package/dist/viewer/dashboard.html +44 -0
  125. package/dist/viewer/dashboard.js +1518 -0
  126. package/dist/viewer/icon-16.png +0 -0
  127. package/dist/viewer/icon-180.png +0 -0
  128. package/dist/viewer/icon-32.png +0 -0
  129. package/dist/viewer/icon-512.png +0 -0
  130. package/dist/viewer/icon.ico +0 -0
  131. package/dist/viewer/icon.svg +66 -0
  132. package/dist/viewer/index.html +61 -0
  133. package/dist/viewer/pane.js +736 -0
  134. package/dist/viewer/viewer.css +95 -0
  135. package/dist/viewer/viewer.js +84 -0
  136. package/package.json +66 -7
  137. package/index.js +0 -4
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The gate that keeps one viewer socket's byte stream in order across
3
+ * snapshots (design §5).
4
+ *
5
+ * A snapshot of the daemon's renderer is taken asynchronously: it resolves
6
+ * once every byte queued before the request has been parsed, and includes
7
+ * nothing queued after it (`ScreenRenderer.serialize`). Bytes that arrive
8
+ * while it is pending are NOT in it and must reach the viewer
9
+ * AFTER it; bytes that arrived before the request ARE in it and were already
10
+ * forwarded live, so they must not go out again. This class is that
11
+ * bookkeeping, with the socket and the snapshot injected so it can be tested
12
+ * without either.
13
+ *
14
+ * No I/O of its own and no logging.
15
+ */
16
+ export class ViewerSync {
17
+ send;
18
+ snapshot;
19
+ /** Arrival counter: every delivered chunk takes the next value. */
20
+ seq = 0;
21
+ /** Chunks held back while a snapshot is pending, with their arrival order. */
22
+ held = [];
23
+ /** The arrival counter at each pending snapshot request, oldest first. */
24
+ pending = [];
25
+ closed = false;
26
+ constructor(send, snapshot) {
27
+ this.send = send;
28
+ this.snapshot = snapshot;
29
+ }
30
+ /** Live bytes from the session, in arrival order. */
31
+ deliver(bytes) {
32
+ if (this.closed)
33
+ return;
34
+ const seq = this.seq++;
35
+ if (this.pending.length === 0) {
36
+ this.send(bytes);
37
+ return;
38
+ }
39
+ this.held.push({ seq, bytes });
40
+ }
41
+ /**
42
+ * Send a fresh snapshot, then everything that arrived after it was taken.
43
+ * Requests may overlap (a window being dragged): each snapshot goes out
44
+ * once, and no chunk goes out twice or not at all.
45
+ */
46
+ resync() {
47
+ if (this.closed)
48
+ return;
49
+ // Everything delivered before this point is in the snapshot about to be
50
+ // taken: the session writes a chunk to its renderer before it notifies
51
+ // listeners, and the snapshot's marker joins the renderer's queue now.
52
+ const mark = this.seq;
53
+ this.pending.push(mark);
54
+ this.snapshot().then((state) => this.complete(mark, state), () => this.complete(mark, null));
55
+ }
56
+ complete(mark, state) {
57
+ if (this.closed)
58
+ return;
59
+ // Snapshots resolve in request order: the renderer's write queue is FIFO.
60
+ this.pending.shift();
61
+ if (state !== null) {
62
+ this.send(state);
63
+ // Chunks that arrived before this snapshot was requested are inside it.
64
+ // Only a snapshot that WENT OUT accounts for them: one that failed
65
+ // covers nothing, and pruning on its mark would lose every chunk between
66
+ // the previous request and this one. Those are released live instead,
67
+ // in order.
68
+ this.held = this.held.filter((entry) => entry.seq >= mark);
69
+ }
70
+ if (this.pending.length === 0) {
71
+ const release = this.held;
72
+ this.held = [];
73
+ for (const entry of release)
74
+ this.send(entry.bytes);
75
+ }
76
+ }
77
+ /** Nothing goes out after this, including a snapshot that resolves late. */
78
+ close() {
79
+ this.closed = true;
80
+ this.held = [];
81
+ }
82
+ }
83
+ //# sourceMappingURL=viewerSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewerSync.js","sourceRoot":"","sources":["../../src/daemon/viewerSync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,UAAU;IAUF;IACA;IAVnB,mEAAmE;IAC3D,GAAG,GAAG,CAAC,CAAC;IAChB,8EAA8E;IACtE,IAAI,GAAqC,EAAE,CAAC;IACpD,0EAA0E;IACzD,OAAO,GAAa,EAAE,CAAC;IAChC,MAAM,GAAG,KAAK,CAAC;IAEvB,YACmB,IAA6B,EAC7B,QAA+B;QAD/B,SAAI,GAAJ,IAAI,CAAyB;QAC7B,aAAQ,GAAR,QAAQ,CAAuB;IAC/C,CAAC;IAEJ,qDAAqD;IACrD,OAAO,CAAC,KAAa;QACnB,IAAI,IAA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CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;YAC1B,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;YACf,KAAK,MAAM,KAAK,IAAI,OAAO;gBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The MCP adapter's own section of `config.json` (the daemon parses the
3
+ * rest, the variable lists included): the framing toggle at launch. Also the
4
+ * rules by which the MCP server and the CLI apply those lists at every start.
5
+ * Problems are reported through the logger, which the adapter points at
6
+ * stderr: stdout belongs to the MCP protocol.
7
+ */
8
+ import type { Logger } from '../core/types.js';
9
+ export interface McpConfig {
10
+ /** §4.4 framing toggle: `{ "mcp": { "untrustedFraming": false } }` disables. */
11
+ untrustedFraming: boolean;
12
+ }
13
+ /** The `mcp` section of a parsed config, with defaults for what is absent. */
14
+ export declare function parseMcpConfig(parsed: unknown): McpConfig;
15
+ /**
16
+ * Resolve requested variable names against the human's list (§4.6), for the
17
+ * MCP server's `envNames` and the CLI's `--env-name` alike. Names off the
18
+ * list refuse the start; listed names not set in `environment` are reported,
19
+ * by name, and not passed. On Windows names compare in any case, as Windows
20
+ * reads them.
21
+ */
22
+ export declare function resolvePassedEnv(requested: readonly string[], allowed: readonly string[], environment: NodeJS.ProcessEnv): {
23
+ env: Record<string, string>;
24
+ absent: string[];
25
+ refused: string[];
26
+ };
27
+ /**
28
+ * The variables a start passes for the agent its session runs as
29
+ * (`agents.passEnv`, §4.6), with what a caller may add by name. For an agent
30
+ * session the agent's list is the whole answer: its names pass without being
31
+ * asked for, and a requested name off that list refuses the start. A session
32
+ * that runs as no agent passes only requested names on `adHoc`
33
+ * (config `envNames`). Names, never values, go into the notes and the refusal.
34
+ */
35
+ export declare function planPassedEnv(input: {
36
+ agent: string | null;
37
+ requested: readonly string[];
38
+ agentLists: Readonly<Record<string, readonly string[]>>;
39
+ adHoc: readonly string[];
40
+ environment: NodeJS.ProcessEnv;
41
+ /** Where the values come from, for the notes: "this MCP server's environment". */
42
+ source: string;
43
+ }): {
44
+ env: Record<string, string>;
45
+ notes: string[];
46
+ refusedForAgent: string[];
47
+ refused: string[];
48
+ };
49
+ /** Read the `mcp` section of `<home>/config.json`; no file or no section means the defaults. */
50
+ export declare function readMcpConfig(home: string, logger: Logger): McpConfig;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The MCP adapter's own section of `config.json` (the daemon parses the
3
+ * rest, the variable lists included): the framing toggle at launch. Also the
4
+ * rules by which the MCP server and the CLI apply those lists at every start.
5
+ * Problems are reported through the logger, which the adapter points at
6
+ * stderr: stdout belongs to the MCP protocol.
7
+ */
8
+ import * as fs from 'node:fs';
9
+ import { configPath } from '../daemon/paths.js';
10
+ const DEFAULTS = { untrustedFraming: true };
11
+ /** The `mcp` section of a parsed config, with defaults for what is absent. */
12
+ export function parseMcpConfig(parsed) {
13
+ const mcp = typeof parsed === 'object' && parsed !== null
14
+ ? parsed.mcp
15
+ : undefined;
16
+ if (mcp === undefined || mcp === null)
17
+ return { ...DEFAULTS };
18
+ return { untrustedFraming: mcp.untrustedFraming !== false };
19
+ }
20
+ /**
21
+ * Resolve requested variable names against the human's list (§4.6), for the
22
+ * MCP server's `envNames` and the CLI's `--env-name` alike. Names off the
23
+ * list refuse the start; listed names not set in `environment` are reported,
24
+ * by name, and not passed. On Windows names compare in any case, as Windows
25
+ * reads them.
26
+ */
27
+ export function resolvePassedEnv(requested, allowed, environment) {
28
+ const fold = (name) => (process.platform === 'win32' ? name.toUpperCase() : name);
29
+ const allowedSet = new Set(allowed.map(fold));
30
+ const lookup = new Map();
31
+ for (const [name, value] of Object.entries(environment)) {
32
+ if (value !== undefined)
33
+ lookup.set(fold(name), value);
34
+ }
35
+ const env = {};
36
+ const absent = [];
37
+ const refused = [];
38
+ for (const name of requested) {
39
+ if (!allowedSet.has(fold(name)))
40
+ refused.push(name);
41
+ else if (lookup.has(fold(name)))
42
+ env[name] = lookup.get(fold(name));
43
+ else
44
+ absent.push(name);
45
+ }
46
+ return { env, absent, refused };
47
+ }
48
+ /**
49
+ * The variables a start passes for the agent its session runs as
50
+ * (`agents.passEnv`, §4.6), with what a caller may add by name. For an agent
51
+ * session the agent's list is the whole answer: its names pass without being
52
+ * asked for, and a requested name off that list refuses the start. A session
53
+ * that runs as no agent passes only requested names on `adHoc`
54
+ * (config `envNames`). Names, never values, go into the notes and the refusal.
55
+ */
56
+ export function planPassedEnv(input) {
57
+ const { agent, requested, environment, source } = input;
58
+ if (agent === null) {
59
+ const { env, absent, refused } = resolvePassedEnv(requested, input.adHoc, environment);
60
+ const notes = [];
61
+ if (Object.keys(env).length > 0)
62
+ notes.push(`Passed from ${source}: ${Object.keys(env).join(', ')}.`);
63
+ if (absent.length > 0)
64
+ notes.push(`Not set in ${source}, so not passed: ${absent.join(', ')}.`);
65
+ return { env, notes, refusedForAgent: [], refused };
66
+ }
67
+ // An own entry only: an agent named `constructor` or `__proto__` has no list.
68
+ const list = Object.prototype.hasOwnProperty.call(input.agentLists, agent) ? (input.agentLists[agent] ?? []) : [];
69
+ const refusedForAgent = resolvePassedEnv(requested, list, environment).refused;
70
+ const { env, absent } = resolvePassedEnv(list, list, environment);
71
+ const notes = [];
72
+ if (Object.keys(env).length > 0)
73
+ notes.push(`Passed for ${agent} from ${source}: ${Object.keys(env).join(', ')}.`);
74
+ if (absent.length > 0)
75
+ notes.push(`Listed for ${agent} but not set in ${source}, so not passed: ${absent.join(', ')}.`);
76
+ return { env, notes, refusedForAgent, refused: [] };
77
+ }
78
+ /** Read the `mcp` section of `<home>/config.json`; no file or no section means the defaults. */
79
+ export function readMcpConfig(home, logger) {
80
+ let raw;
81
+ try {
82
+ raw = fs.readFileSync(configPath(home), 'utf8');
83
+ }
84
+ catch {
85
+ return { ...DEFAULTS };
86
+ }
87
+ try {
88
+ return parseMcpConfig(JSON.parse(raw));
89
+ }
90
+ catch {
91
+ logger.warn('config.json could not be parsed: using the MCP defaults');
92
+ return { ...DEFAULTS };
93
+ }
94
+ }
95
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/mcp/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQhD,MAAM,QAAQ,GAAc,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;AAEvD,8EAA8E;AAC9E,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,MAAM,GAAG,GACP,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAC3C,CAAC,CAAE,MAAmD,CAAC,GAAG;QAC1D,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC9D,OAAO,EAAE,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAA4B,EAC5B,OAA0B,EAC1B,WAA8B;IAE9B,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClG,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC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,CAAC,GAAG,CAAC,CAAC;IACxH,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACtD,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,MAAc;IACxD,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,GAAG,QAAQ,EAAE,CAAC;IACzB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;QACvE,OAAO,EAAE,GAAG,QAAQ,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
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
+ export {};
@@ -0,0 +1,78 @@
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 { isEnvNamesProblem, 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
+ instructions: 'Important: A session whose model is a Claude model should ALWAYS pass hideReasoning: true ' +
28
+ 'on every call that reads a screen: terminal_snapshot, terminal_wait, terminal_find, ' +
29
+ 'terminal_screenshot, terminal_list, and use --hide-reasoning with their CLI equivalents. ' +
30
+ 'Claude models\' safety checks can flag another model\'s reasoning read off a screen as an ' +
31
+ 'attempt to extract reasoning and stop the session. Leaving the reasoning out avoids that; ' +
32
+ 'terminal_result gives the agent\'s answer. With the flag, a Claude model can use every ' +
33
+ 'ShellPuppet tool freely. Other models can leave the flag off when they need the full screen.',
34
+ });
35
+ const home = shellpuppetHome();
36
+ const config = readMcpConfig(home, stderrLogger);
37
+ // The variable lists are read afresh at every terminal_start, so a change
38
+ // to config applies to the next session with no restart. The lists are the
39
+ // daemon's to parse; their problems are reported once each.
40
+ const reported = new Set();
41
+ const reportOnce = (problem) => {
42
+ if (reported.has(problem))
43
+ return;
44
+ reported.add(problem);
45
+ stderrLogger.warn(problem);
46
+ };
47
+ const readPassLists = () => {
48
+ const parsed = readDaemonConfig(home);
49
+ for (const problem of parsed.problems) {
50
+ if (problem.startsWith('agents') || isEnvNamesProblem(problem))
51
+ reportOnce(problem);
52
+ }
53
+ return {
54
+ envNames: parsed.config.envNames ?? [],
55
+ agentPassEnv: parsed.config.agentPassEnv ?? {},
56
+ agentSignatures: parsed.config.agentSignatures ?? [],
57
+ };
58
+ };
59
+ readPassLists();
60
+ registerTools(server, {
61
+ logger: stderrLogger,
62
+ untrustedFraming: config.untrustedFraming,
63
+ readPassLists,
64
+ // Audit actor (design §4.5): identify the calling MCP client (Claude
65
+ // Code, Qoder, Cursor…) from the initialize handshake. Resolved per call,
66
+ // because clientInfo does not exist until after the handshake completes.
67
+ actor: () => {
68
+ const info = server.server.getClientVersion();
69
+ return info !== undefined ? `mcp:${info.name}` : 'mcp';
70
+ },
71
+ });
72
+ await server.connect(new StdioServerTransport());
73
+ }
74
+ main().catch((error) => {
75
+ console.error(`shellpuppet-mcp failed to start: ${error instanceof Error ? error.message : String(error)}`);
76
+ process.exit(1);
77
+ });
78
+ //# 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,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,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,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,IAAI,iBAAiB,CAAC,OAAO,CAAC;gBAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QACtF,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE;YACtC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE;YAC9C,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,eAAe,IAAI,EAAE;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,66 @@
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
+ /**
20
+ * Wrap untrusted terminal text in the frame every MCP result uses (design
21
+ * §4.4). Both boundary lines carry a nonce drawn fresh for this result, so the
22
+ * content cannot print the real closing line. A content line shaped like a
23
+ * boundary is prefixed with a backslash, so it cannot pass for one, even to a
24
+ * reader that does not compare nonces. Exported for its tests.
25
+ */
26
+ export declare function frameUntrusted(screen: string, nonce?: string): string;
27
+ export interface McpToolOptions extends ClientOptions {
28
+ /** §4.4 framing toggle: config `mcp.untrustedFraming`, default true. */
29
+ untrustedFraming?: boolean;
30
+ /**
31
+ * Config `envNames`: the variables `terminal_start` may pass from this
32
+ * server's environment into a session (§4.6). Empty or absent passes none.
33
+ */
34
+ envNames?: readonly string[];
35
+ /**
36
+ * Config `agents.passEnv`: the variables each agent's sessions receive from
37
+ * this server's environment, by agent name (§4.6).
38
+ */
39
+ agentPassEnv?: Readonly<Record<string, readonly string[]>>;
40
+ /** Config `agents.signatures`, so a start is recognised as the agent the daemon will see. */
41
+ agentSignatures?: readonly AgentSignature[];
42
+ /**
43
+ * Reads the three lists above afresh from config. Called at every
44
+ * `terminal_start`, so a change to config applies to the next session
45
+ * started with no restart. Absent, the lists given above are used as they
46
+ * are.
47
+ */
48
+ readPassLists?: () => PassLists;
49
+ /** Where passed values are read from: this process's environment unless a test says otherwise. */
50
+ environment?: NodeJS.ProcessEnv;
51
+ }
52
+ type Body = Record<string, unknown>;
53
+ /**
54
+ * How the human reaches a session that has just started. A dashboard or
55
+ * viewer window needs no link in the transcript. If no window is connected
56
+ * or opening, the one-use viewer URL is the human's way in.
57
+ */
58
+ export declare function viewerLine(payload: Body): string;
59
+ /** The lists `terminal_start` passes variables by (§4.6). */
60
+ export interface PassLists {
61
+ envNames: readonly string[];
62
+ agentPassEnv: Readonly<Record<string, readonly string[]>>;
63
+ agentSignatures: readonly AgentSignature[];
64
+ }
65
+ export declare function registerTools(server: McpServer, options?: McpToolOptions): void;
66
+ export {};