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,73 @@
1
+ /**
2
+ * Loading node-pty, and the ways an npm install can leave it unable to open a
3
+ * terminal.
4
+ *
5
+ * npm 12 runs a dependency's install scripts only when the person installing
6
+ * allows them. node-pty ships prebuilt binaries for Windows and macOS and,
7
+ * since 1.2.0-beta, for mainstream Linux; its install script builds one only
8
+ * where no prebuilt matches (another architecture, or musl in place of
9
+ * glibc). Its loader searches `build/Release`, `build/Debug` and then
10
+ * `prebuilds/<platform>-<arch>`, so an install whose script never ran still
11
+ * loads a prebuilt binary that is there. On macOS the prebuilt `spawn-helper`
12
+ * ships without its execute bit (microsoft/node-pty#850). npm 12 would block
13
+ * an install script that restored it, and every spawn would then fail with
14
+ * "posix_spawnp failed".
15
+ *
16
+ * So node-pty is loaded on the first start rather than when the daemon starts,
17
+ * and the helper's execute bit is checked there. Either failure reaches the
18
+ * person as a start that fails with what to do, instead of a daemon that dies
19
+ * before it answers and a client that can only say it never became healthy.
20
+ * On Windows node-pty loads its native module when a terminal is built, not
21
+ * when it is imported, so a spawn's failure gets the same explanation.
22
+ */
23
+ type NodePty = typeof import('node-pty');
24
+ /**
25
+ * The install that builds node-pty under npm 12. Earlier npm runs the script
26
+ * without the flag; npm 10 and early npm 11 releases ignore it as an unknown
27
+ * option.
28
+ */
29
+ export declare const REINSTALL = "npm install -g --allow-scripts=node-pty shellpuppet";
30
+ /** node-pty cannot open a terminal on this install; the message says what to do. */
31
+ export declare class NativePtyUnavailableError extends Error {
32
+ constructor(message: string);
33
+ }
34
+ /**
35
+ * A loader that keeps node-pty once a load succeeds, and explains a failure. A
36
+ * failed load is not remembered, so a start after a reinstall tries again.
37
+ * `load` is a test seam.
38
+ */
39
+ export declare function nodePtyLoader(load?: () => NodePty): () => NodePty;
40
+ /** The daemon's node-pty. */
41
+ export declare const loadNodePty: () => NodePty;
42
+ /**
43
+ * What a node-pty load failure means for the person who hit it. node-pty's own
44
+ * loader reports a missing module as "Failed to load native module: pty.node,
45
+ * checked: …"; a module built for another Node.js names NODE_MODULE_VERSION,
46
+ * on a later line of the message than the first.
47
+ */
48
+ export declare function explainLoadFailure(error: unknown): string;
49
+ /**
50
+ * A spawn's failure, explained when it is node-pty's native module that would
51
+ * not load (on Windows that happens as a terminal is built). Anything else is
52
+ * returned as it was, so other start failures keep their own handling.
53
+ */
54
+ export declare function explainSpawnFailure(error: unknown): unknown;
55
+ /** The file operations `ensureSpawnHelperExecutable` needs; a test seam. */
56
+ export interface HelperFs {
57
+ /** Whether this native module loads, as node-pty's loader would find. */
58
+ loads(file: string): boolean;
59
+ isExecutable(file: string): boolean;
60
+ makeExecutable(file: string): void;
61
+ }
62
+ /** The real file operations; exported so a test can pair them with a stand-in `loads`. */
63
+ export declare const realHelperFs: HelperFs;
64
+ /**
65
+ * On macOS, make sure node-pty's `spawn-helper` can run before a spawn needs
66
+ * it. node-pty uses the helper beside the native module it loaded. Its loader
67
+ * tries `build/Release`, `build/Debug` and then `prebuilds/<platform>-<arch>`,
68
+ * each first beside its `lib` directory and then inside it, and moves on when
69
+ * a module fails to load. This follows the same order and takes the first
70
+ * module that loads. Anywhere but macOS it does nothing.
71
+ */
72
+ export declare function ensureSpawnHelperExecutable(root?: string, platform?: NodeJS.Platform, arch?: string, ops?: HelperFs): void;
73
+ export {};
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Loading node-pty, and the ways an npm install can leave it unable to open a
3
+ * terminal.
4
+ *
5
+ * npm 12 runs a dependency's install scripts only when the person installing
6
+ * allows them. node-pty ships prebuilt binaries for Windows and macOS and,
7
+ * since 1.2.0-beta, for mainstream Linux; its install script builds one only
8
+ * where no prebuilt matches (another architecture, or musl in place of
9
+ * glibc). Its loader searches `build/Release`, `build/Debug` and then
10
+ * `prebuilds/<platform>-<arch>`, so an install whose script never ran still
11
+ * loads a prebuilt binary that is there. On macOS the prebuilt `spawn-helper`
12
+ * ships without its execute bit (microsoft/node-pty#850). npm 12 would block
13
+ * an install script that restored it, and every spawn would then fail with
14
+ * "posix_spawnp failed".
15
+ *
16
+ * So node-pty is loaded on the first start rather than when the daemon starts,
17
+ * and the helper's execute bit is checked there. Either failure reaches the
18
+ * person as a start that fails with what to do, instead of a daemon that dies
19
+ * before it answers and a client that can only say it never became healthy.
20
+ * On Windows node-pty loads its native module when a terminal is built, not
21
+ * when it is imported, so a spawn's failure gets the same explanation.
22
+ */
23
+ import * as fs from 'node:fs';
24
+ import { createRequire } from 'node:module';
25
+ import * as path from 'node:path';
26
+ const require = createRequire(import.meta.url);
27
+ /**
28
+ * The install that builds node-pty under npm 12. Earlier npm runs the script
29
+ * without the flag; npm 10 and early npm 11 releases ignore it as an unknown
30
+ * option.
31
+ */
32
+ export const REINSTALL = 'npm install -g --allow-scripts=node-pty shellpuppet';
33
+ /** node-pty cannot open a terminal on this install; the message says what to do. */
34
+ export class NativePtyUnavailableError extends Error {
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = 'NativePtyUnavailableError';
38
+ }
39
+ }
40
+ /**
41
+ * A loader that keeps node-pty once a load succeeds, and explains a failure. A
42
+ * failed load is not remembered, so a start after a reinstall tries again.
43
+ * `load` is a test seam.
44
+ */
45
+ export function nodePtyLoader(load = () => require('node-pty')) {
46
+ let loaded;
47
+ return () => {
48
+ if (loaded === undefined) {
49
+ try {
50
+ loaded = load();
51
+ }
52
+ catch (error) {
53
+ throw new NativePtyUnavailableError(explainLoadFailure(error));
54
+ }
55
+ }
56
+ return loaded;
57
+ };
58
+ }
59
+ /** The daemon's node-pty. */
60
+ export const loadNodePty = nodePtyLoader();
61
+ /**
62
+ * What a node-pty load failure means for the person who hit it. node-pty's own
63
+ * loader reports a missing module as "Failed to load native module: pty.node,
64
+ * checked: …"; a module built for another Node.js names NODE_MODULE_VERSION,
65
+ * on a later line of the message than the first.
66
+ */
67
+ export function explainLoadFailure(error) {
68
+ const message = error instanceof Error ? error.message : String(error);
69
+ // Classified whole, shown by its first line: Node appends the whole require
70
+ // stack to a missing module's message, which is noise to the person reading
71
+ // it, but the reason a module would not load can sit on a later line.
72
+ const detail = message.split('\n')[0] ?? '';
73
+ if (/NODE_MODULE_VERSION|compiled against a different Node\.js version/.test(message)) {
74
+ return ('node-pty was built for a different version of Node.js, so ShellPuppet cannot open a terminal. ' +
75
+ `Reinstall ShellPuppet under this Node.js: ${REINSTALL}. (${detail})`);
76
+ }
77
+ // node-pty's loader keeps only its last error, so a module built for
78
+ // another Node.js can look like a missing one here. Say both.
79
+ if (/Failed to load native module|Cannot find module/.test(message)) {
80
+ return ("node-pty's native module is missing, or was built for another version of Node.js, " +
81
+ 'so ShellPuppet cannot open a terminal. ' +
82
+ "npm 12 runs a dependency's install script only when you allow it; reinstall with " +
83
+ `${REINSTALL} (on a machine node-pty ships no prebuilt binary for, that builds it, ` +
84
+ `which needs Python 3, make and a C++ compiler). (${detail})`);
85
+ }
86
+ return `node-pty could not be loaded, so ShellPuppet cannot open a terminal: ${detail}`;
87
+ }
88
+ /**
89
+ * A spawn's failure, explained when it is node-pty's native module that would
90
+ * not load (on Windows that happens as a terminal is built). Anything else is
91
+ * returned as it was, so other start failures keep their own handling.
92
+ */
93
+ export function explainSpawnFailure(error) {
94
+ const message = error instanceof Error ? error.message : String(error);
95
+ return /Failed to load native module/.test(message) ? new NativePtyUnavailableError(explainLoadFailure(error)) : error;
96
+ }
97
+ /** The real file operations; exported so a test can pair them with a stand-in `loads`. */
98
+ export const realHelperFs = {
99
+ loads: (file) => {
100
+ try {
101
+ require(file);
102
+ return true;
103
+ }
104
+ catch {
105
+ return false;
106
+ }
107
+ },
108
+ isExecutable: (file) => {
109
+ try {
110
+ fs.accessSync(file, fs.constants.X_OK);
111
+ return true;
112
+ }
113
+ catch {
114
+ return false;
115
+ }
116
+ },
117
+ makeExecutable: (file) => {
118
+ fs.chmodSync(file, 0o755);
119
+ },
120
+ };
121
+ /** A path as one POSIX shell word, safe to paste: single quotes, with any single quote escaped. */
122
+ function shellQuote(value) {
123
+ return `'${value.replace(/'/g, `'\\''`)}'`;
124
+ }
125
+ /**
126
+ * On macOS, make sure node-pty's `spawn-helper` can run before a spawn needs
127
+ * it. node-pty uses the helper beside the native module it loaded. Its loader
128
+ * tries `build/Release`, `build/Debug` and then `prebuilds/<platform>-<arch>`,
129
+ * each first beside its `lib` directory and then inside it, and moves on when
130
+ * a module fails to load. This follows the same order and takes the first
131
+ * module that loads. Anywhere but macOS it does nothing.
132
+ */
133
+ export function ensureSpawnHelperExecutable(root = path.dirname(require.resolve('node-pty/package.json')), platform = process.platform, arch = process.arch, ops = realHelperFs) {
134
+ if (platform !== 'darwin')
135
+ return;
136
+ for (const dir of ['build/Release', 'build/Debug', `prebuilds/${platform}-${arch}`]) {
137
+ for (const base of [root, path.join(root, 'lib')]) {
138
+ const candidate = path.join(base, dir);
139
+ if (!ops.loads(path.join(candidate, 'pty.node')))
140
+ continue;
141
+ const helper = path.join(candidate, 'spawn-helper');
142
+ if (ops.isExecutable(helper))
143
+ return;
144
+ try {
145
+ ops.makeExecutable(helper);
146
+ }
147
+ catch (error) {
148
+ const code = error.code ?? String(error);
149
+ if (code === 'ENOENT') {
150
+ throw new NativePtyUnavailableError(`node-pty's spawn-helper is missing (${helper}), so ShellPuppet cannot open a terminal. ` +
151
+ `Reinstall ShellPuppet: ${REINSTALL}.`);
152
+ }
153
+ throw new NativePtyUnavailableError(`node-pty's spawn-helper is not executable and ShellPuppet could not make it so (${code}), ` +
154
+ `so it cannot open a terminal. Run: chmod +x -- ${shellQuote(helper)} ` +
155
+ '(with sudo if ShellPuppet was installed as root).');
156
+ }
157
+ return;
158
+ }
159
+ }
160
+ }
161
+ //# sourceMappingURL=nativePty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativePty.js","sourceRoot":"","sources":["../../src/core/nativePty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,qDAAqD,CAAC;AAE/E,oFAAoF;AACpF,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAAsB,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAY;IACtF,IAAI,MAA2B,CAAC;IAChC,OAAO,GAAG,EAAE;QACV,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,EAAE,CAAC;YAClB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,yBAAyB,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,6BAA6B;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,EAAE,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK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,cAAc,CAAC,CAAC;YACpD,IAAI,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC;gBAAE,OAAO;YACrC,IAAI,CAAC;gBACH,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;gBACpE,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;oBACtB,MAAM,IAAI,yBAAyB,CACjC,uCAAuC,MAAM,4CAA4C;wBACvF,0BAA0B,SAAS,GAAG,CACzC,CAAC;gBACJ,CAAC;gBACD,MAAM,IAAI,yBAAyB,CACjC,mFAAmF,IAAI,KAAK;oBAC1F,kDAAkD,UAAU,CAAC,MAAM,CAAC,GAAG;oBACvE,mDAAmD,CACtD,CAAC;YACJ,CAAC;YACD,OAAO;QACT,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Command policy: allow/deny evaluation for `terminal_start` (design §4.3).
3
+ *
4
+ * Two invariants:
5
+ *
6
+ * 1. **Policy evaluates the pre-wrap command.** Callers pass the real command
7
+ * (`goose session`); the daemon applies the Windows `cmd.exe /c` wrapper
8
+ * *after* the policy decision. If policy saw wrapped commands, an allowlist
9
+ * would see `cmd.exe` for everything and be unsatisfiable.
10
+ * 2. **Configuration errors fail closed.** A malformed pattern in an active
11
+ * policy denies every command with a clear reason, rather than silently
12
+ * not matching. A policy that cannot be evaluated as written must not be
13
+ * guessed at.
14
+ *
15
+ * Policy applies to commands only. It deliberately does not filter keystrokes:
16
+ * that is unenforceable theatre once a shell is running, and pretending
17
+ * otherwise would be worse than saying so.
18
+ *
19
+ * Pure evaluation. No I/O: config loading lives daemon-side.
20
+ */
21
+ import type { PolicyConfig, PolicyDecision, PolicyMode } from './types.js';
22
+ interface CompiledRule {
23
+ source: string;
24
+ regex: RegExp;
25
+ }
26
+ export interface CompiledPolicy {
27
+ mode: PolicyMode;
28
+ allow: CompiledRule[];
29
+ deny: CompiledRule[];
30
+ /** Concurrent live sessions allowed; no limit when undefined. */
31
+ maxSessions: number | undefined;
32
+ /** Pattern sources that failed to compile. Non-empty ⇒ active policy denies all. */
33
+ invalidPatterns: string[];
34
+ /**
35
+ * Present ⇒ the policy section itself could not be parsed as written (set
36
+ * by the daemon's config validation, invariant 2). Deny everything,
37
+ * regardless of mode: a bad SHAPE cannot even tell us the intended mode.
38
+ */
39
+ configError?: string;
40
+ }
41
+ /** The exact string patterns are matched against: command + args, space-joined. */
42
+ export declare function commandLine(command: string, args?: string[]): string;
43
+ /**
44
+ * Compile a policy once at config load. Patterns are case-insensitive:
45
+ * Windows commands are case-insensitive in reality (`Goose.exe` ≡ `goose.exe`),
46
+ * and for deny rules matching more broadly is the safe direction.
47
+ */
48
+ export declare function compilePolicy(config?: PolicyConfig): CompiledPolicy;
49
+ /**
50
+ * Decide whether a command may start a session.
51
+ *
52
+ * - `allow-all`: everything passes; the lists are inert.
53
+ * - `denylist`: refused if any deny pattern matches.
54
+ * - `allowlist`: refused unless an allow pattern matches. Deny patterns are
55
+ * still honoured first, so a deny rule can never be silently ignored by a
56
+ * mode switch.
57
+ */
58
+ export declare function evaluateCommand(policy: CompiledPolicy, command: string, args?: string[]): PolicyDecision;
59
+ /** Enforce the concurrent-session cap, when one is configured. There is none by default. */
60
+ export declare function checkSessionCapacity(policy: CompiledPolicy, liveSessionCount: number): PolicyDecision;
61
+ export {};
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Command policy: allow/deny evaluation for `terminal_start` (design §4.3).
3
+ *
4
+ * Two invariants:
5
+ *
6
+ * 1. **Policy evaluates the pre-wrap command.** Callers pass the real command
7
+ * (`goose session`); the daemon applies the Windows `cmd.exe /c` wrapper
8
+ * *after* the policy decision. If policy saw wrapped commands, an allowlist
9
+ * would see `cmd.exe` for everything and be unsatisfiable.
10
+ * 2. **Configuration errors fail closed.** A malformed pattern in an active
11
+ * policy denies every command with a clear reason, rather than silently
12
+ * not matching. A policy that cannot be evaluated as written must not be
13
+ * guessed at.
14
+ *
15
+ * Policy applies to commands only. It deliberately does not filter keystrokes:
16
+ * that is unenforceable theatre once a shell is running, and pretending
17
+ * otherwise would be worse than saying so.
18
+ *
19
+ * Pure evaluation. No I/O: config loading lives daemon-side.
20
+ */
21
+ import { RegexBudgetError, withRegexBudget } from './regexBudget.js';
22
+ /** The exact string patterns are matched against: command + args, space-joined. */
23
+ export function commandLine(command, args = []) {
24
+ return [command, ...args].join(' ');
25
+ }
26
+ /**
27
+ * Compile a policy once at config load. Patterns are case-insensitive:
28
+ * Windows commands are case-insensitive in reality (`Goose.exe` ≡ `goose.exe`),
29
+ * and for deny rules matching more broadly is the safe direction.
30
+ */
31
+ export function compilePolicy(config) {
32
+ const invalidPatterns = [];
33
+ const compile = (sources) => {
34
+ const rules = [];
35
+ for (const source of sources ?? []) {
36
+ try {
37
+ rules.push({ source, regex: new RegExp(source, 'i') });
38
+ }
39
+ catch {
40
+ invalidPatterns.push(source);
41
+ }
42
+ }
43
+ return rules;
44
+ };
45
+ return {
46
+ mode: config?.mode ?? 'allow-all',
47
+ allow: compile(config?.allow),
48
+ deny: compile(config?.deny),
49
+ maxSessions: config?.maxSessions,
50
+ invalidPatterns,
51
+ ...(config?.configError !== undefined ? { configError: config.configError } : {}),
52
+ };
53
+ }
54
+ /**
55
+ * Decide whether a command may start a session.
56
+ *
57
+ * - `allow-all`: everything passes; the lists are inert.
58
+ * - `denylist`: refused if any deny pattern matches.
59
+ * - `allowlist`: refused unless an allow pattern matches. Deny patterns are
60
+ * still honoured first, so a deny rule can never be silently ignored by a
61
+ * mode switch.
62
+ */
63
+ export function evaluateCommand(policy, command, args = []) {
64
+ // Checked BEFORE the allow-all early return: a structurally invalid policy
65
+ // section cannot even tell us the intended mode, so no mode is trusted.
66
+ if (policy.configError !== undefined) {
67
+ return {
68
+ allowed: false,
69
+ reason: `Policy configuration error: ${policy.configError} All commands are ` +
70
+ `refused until the policy in ~/.shellpuppet/config.json is fixed.`,
71
+ };
72
+ }
73
+ if (policy.mode === 'allow-all')
74
+ return { allowed: true };
75
+ if (policy.invalidPatterns.length > 0) {
76
+ return {
77
+ allowed: false,
78
+ reason: `Policy configuration error: invalid pattern(s): ` +
79
+ `${policy.invalidPatterns.join(', ')}. All commands are refused until the ` +
80
+ `policy in ~/.shellpuppet/config.json is fixed.`,
81
+ };
82
+ }
83
+ const line = commandLine(command, args);
84
+ // Every rule gets a budget, and a rule that overruns it refuses the command
85
+ // (`regexBudget.ts`). That is invariant 2 again: a policy that cannot be
86
+ // evaluated as written must not be guessed at, and the alternative is a
87
+ // rule in a config file blocking the whole daemon's event loop for as long
88
+ // as it backtracks. Deny and allow are treated alike, because the safe
89
+ // direction for both is to refuse.
90
+ const decide = (rules, onMatch) => {
91
+ for (const rule of rules) {
92
+ let matched;
93
+ try {
94
+ matched = withRegexBudget(rule.source, () => rule.regex.test(line));
95
+ }
96
+ catch (error) {
97
+ if (error instanceof RegexBudgetError) {
98
+ return {
99
+ allowed: false,
100
+ reason: `Policy configuration error: the rule ${rule.source} did not finish ` +
101
+ `evaluating within its budget, so this command is refused. Each ` +
102
+ `command is judged on its own, but the rule will go on failing on ` +
103
+ `lines like this one until the policy in ~/.shellpuppet/config.json ` +
104
+ `is fixed.`,
105
+ rule: rule.source,
106
+ };
107
+ }
108
+ throw error;
109
+ }
110
+ if (matched)
111
+ return onMatch(rule);
112
+ }
113
+ return null;
114
+ };
115
+ const denied = decide(policy.deny, (rule) => ({
116
+ allowed: false,
117
+ reason: `Command refused by deny rule: ${rule.source}`,
118
+ rule: rule.source,
119
+ }));
120
+ if (denied !== null)
121
+ return denied;
122
+ if (policy.mode === 'denylist')
123
+ return { allowed: true };
124
+ const allowed = decide(policy.allow, (rule) => ({ allowed: true, rule: rule.source }));
125
+ if (allowed !== null)
126
+ return allowed;
127
+ return {
128
+ allowed: false,
129
+ reason: `Command is not on the allowlist: ${line}`,
130
+ };
131
+ }
132
+ /** Enforce the concurrent-session cap, when one is configured. There is none by default. */
133
+ export function checkSessionCapacity(policy, liveSessionCount) {
134
+ if (policy.maxSessions !== undefined && liveSessionCount >= policy.maxSessions) {
135
+ return {
136
+ allowed: false,
137
+ reason: `Session limit reached (${String(policy.maxSessions)} live sessions). ` +
138
+ `Kill a session or raise policy.maxSessions.`,
139
+ };
140
+ }
141
+ return { allowed: true };
142
+ }
143
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/core/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAuBrE,mFAAmF;AACnF,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,OAAiB,EAAE;IAC9D,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,CAAC,OAA6B,EAAkB,EAAE;QAChE,MAAM,KAAK,GAAmB,EAAE,CAAC;QACjC,KAAK,MAAM,MAAM,IAAI,OAAO,IAAI,EAAE,EAAE,CAAC;YACnC,IAAI,CAAC;gBACH,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACzD,CAAC;YAAC,MAAM,CAAC;gBACP,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,OAAO;QACL,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,WAAW;QAC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EAAE,KAAK;QACd,MAAM,EAAE,oCAAoC,IAAI,EAAE;KACnD,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAClC,MAAsB,EACtB,gBAAwB;IAExB,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,IAAI,gBAAgB,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QAC/E,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EACJ,0BAA0B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,mBAAmB;gBACvE,6CAA6C;SAChD,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Permission-prompt detection over rendered screen text. An agent CLI
3
+ * stuck on a permission prompt should raise an alert instead of waiting for
4
+ * the next manual snapshot, because a prompt only serviced when a human or
5
+ * manager happens to look costs tens of idle minutes per prompt.
6
+ *
7
+ * This is a HEURISTIC over untrusted screen content. It decides only whether
8
+ * the screen LOOKS LIKE it is waiting on a human choice; it never decides the
9
+ * answer. False negatives cost what the status quo already costs (a wait for
10
+ * the next snapshot); false positives cost one spurious notification. Both
11
+ * are acceptable, so the patterns favour the shapes real agent CLIs draw.
12
+ *
13
+ * Calibrated against real screens from three CLIs (the fixtures are
14
+ * verbatim): Qoder (`❯` marker, tight option blocks), Codex (`›`/`>` markers,
15
+ * LONG WRAPPED option text between numbered rows and `Press enter to
16
+ * confirm or esc to cancel` footers) and Grok (radio rows `1 (○)` / `2 (•)`
17
+ * inside a `│` box border, NO dot after the number; its folder-trust question
18
+ * puts each option's key after it, `Yes, proceed y`). It also reads
19
+ * pointer-only choosers with unnumbered rows (inquirer.js, and Claude Code's
20
+ * own folder-trust prompt), letter-keyed menus, `(Y)es/(N)o` and bracketed
21
+ * letter lists, and the steps `@clack/prompts` draws for the scaffolding
22
+ * wizards of create-vite, `sv create` and others: a select, a multi-select or
23
+ * a confirm under a `◆` headline, or `▲` while the step shows a validation
24
+ * error. MiMo Code's folder-trust question is a clack select too. Two rules
25
+ * keep out FALSE positives: a numbered findings list an agent printed above
26
+ * its composer, under a line that happens to end in a question mark; and a
27
+ * message Claude Code echoes into its transcript or holds in its composer,
28
+ * whose `❯` and aligned lines look like a pointer chooser under a question
29
+ * from an earlier message.
30
+ *
31
+ * A permission dialog drawn with its choices as one row of buttons
32
+ * (OpenCode, MiMo Code) is recognised by its signature (`dialogs.ts`),
33
+ * which config can extend. Their numbered question menu is recognised by
34
+ * its fixed controls and custom-answer choice here.
35
+ */
36
+ import type { StyledLine } from './renderer.js';
37
+ /** A plain Muse heading can precede the moment its keys become active. */
38
+ export declare const MUSE_MENU_SETTLE_MS = 1500;
39
+ export interface DetectedPrompt {
40
+ /** Best-effort headline for the prompt (e.g. "Permission Required"). */
41
+ question: string;
42
+ /** The visible options, in screen order, markers stripped. */
43
+ options: string[];
44
+ /** Index into `options` when cell styling uniquely selects one row. */
45
+ selectedOption?: number;
46
+ /** Raw screen row for each option, when options occupy separate rows. */
47
+ optionRows?: number[];
48
+ /**
49
+ * Stable identity for the prompt as currently drawn: the same prompt
50
+ * redrawn (cursor blink, spinner elsewhere) keeps its signature, so a
51
+ * stall timer can accumulate across scans without resetting.
52
+ */
53
+ signature: string;
54
+ /**
55
+ * The first and last raw line of the screen the prompt's own drawing
56
+ * occupies: its question when one is found, its options, and what is
57
+ * drawn between them. For Grok's older radio box, whose command is plain
58
+ * bar text above the options, the span also takes that command when a
59
+ * bare bar closes it off from the lines above. A reader that puts parts
60
+ * of a screen aside (`reasoning.ts` hides reasoning) leaves these lines
61
+ * alone: a filter must never hide a question. A wait result does not
62
+ * carry this.
63
+ */
64
+ rows: [number, number];
65
+ /**
66
+ * Why the screen was called live. `question` means the only signal was a
67
+ * question-shaped line with nothing drawn below the options. The reasoning
68
+ * filter leaves such a span unclaimed when every row of it sits inside a
69
+ * reasoning block that began above the question. A wait result does not
70
+ * carry this.
71
+ */
72
+ basis: 'marker' | 'footer' | 'question' | 'frame';
73
+ }
74
+ /**
75
+ * Decide whether the screen is showing a prompt that waits on a human.
76
+ * Returns null when the screen looks busy or shows no prompt shape.
77
+ */
78
+ export declare const SELECTED_OPTION_MARKER = "\u27E6SP:selected\u27E7 ";
79
+ export declare function detectPrompt(screen: string): DetectedPrompt | null;
80
+ /** Tracks the visible menu block, independently of activity above it. */
81
+ export declare class MusePromptSettler {
82
+ private menu;
83
+ private since;
84
+ detect(screen: string, now?: number, styled?: readonly StyledLine[]): DetectedPrompt | null;
85
+ }
86
+ /**
87
+ * Whether the prompt on screen is the one the caller has ALREADY ANSWERED.
88
+ * A supervision loop is wait-for-prompt → answer → wait, and the second wait
89
+ * can look before the program has repainted; it must not return the
90
+ * question just answered as a new one.
91
+ *
92
+ * The guard remembers the prompt showing when input was last written and
93
+ * treats it as stale until an observation has seen the screen without it, or
94
+ * with a different prompt. An observation is a wait tick, a snapshot or the
95
+ * daemon's stall scan. So a prompt with the SAME text drawn later is
96
+ * new only once the earlier one was seen to go; a program that ignored the
97
+ * input keeps showing a stale prompt, and the wait says so rather than
98
+ * guessing.
99
+ */
100
+ export declare class StalePromptGuard {
101
+ private signatureAtInput;
102
+ private cleared;
103
+ /** Input is being written; `screen` is what the program showed at that moment. */
104
+ noteInput(screen: string): void;
105
+ /** A look at the screen found this prompt (or none, when null). */
106
+ observe(signature: string | null): void;
107
+ /** True while `signature` is the answered prompt, not yet seen to go away. */
108
+ isStale(signature: string): boolean;
109
+ }