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,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,CAA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C,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5C,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,iCAAiC,IAAI,CAAC,MAAM,EAAE;QACtD,IAAI,EAAE,IAAI,CAAC,MAAM;KAClB,CAAC,CAAC,CAAC;IACJ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAEnC,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAEzD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACvF,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC;IACrC,OAAO;QACL,OAAO,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,75 @@
|
|
|
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 dialog drawn with its choices as one row of buttons (OpenCode, MiMo Code)
|
|
32
|
+
* fits none of these shapes and is recognised by its signature instead
|
|
33
|
+
* (`dialogs.ts`), which config can extend.
|
|
34
|
+
*/
|
|
35
|
+
export interface DetectedPrompt {
|
|
36
|
+
/** Best-effort headline for the prompt (e.g. "Permission Required"). */
|
|
37
|
+
question: string;
|
|
38
|
+
/** The visible options, in screen order, markers stripped. */
|
|
39
|
+
options: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Stable identity for the prompt as currently drawn: the same prompt
|
|
42
|
+
* redrawn (cursor blink, spinner elsewhere) keeps its signature, so a
|
|
43
|
+
* stall timer can accumulate across scans without resetting.
|
|
44
|
+
*/
|
|
45
|
+
signature: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decide whether the screen is showing a prompt that waits on a human.
|
|
49
|
+
* Returns null when the screen looks busy or shows no prompt shape.
|
|
50
|
+
*/
|
|
51
|
+
export declare function detectPrompt(screen: string): DetectedPrompt | null;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the prompt on screen is the one the caller has ALREADY ANSWERED.
|
|
54
|
+
* A supervision loop is wait-for-prompt → answer → wait, and the second wait
|
|
55
|
+
* can look before the program has repainted; it must not return the
|
|
56
|
+
* question just answered as a new one.
|
|
57
|
+
*
|
|
58
|
+
* The guard remembers the prompt showing when input was last written and
|
|
59
|
+
* treats it as stale until an observation has seen the screen without it, or
|
|
60
|
+
* with a different prompt. An observation is a wait tick, a snapshot or the
|
|
61
|
+
* daemon's stall scan. So a prompt with the SAME text drawn later is
|
|
62
|
+
* new only once the earlier one was seen to go; a program that ignored the
|
|
63
|
+
* input keeps showing a stale prompt, and the wait says so rather than
|
|
64
|
+
* guessing.
|
|
65
|
+
*/
|
|
66
|
+
export declare class StalePromptGuard {
|
|
67
|
+
private signatureAtInput;
|
|
68
|
+
private cleared;
|
|
69
|
+
/** Input is being written; `screen` is what the program showed at that moment. */
|
|
70
|
+
noteInput(screen: string): void;
|
|
71
|
+
/** A look at the screen found this prompt (or none, when null). */
|
|
72
|
+
observe(signature: string | null): void;
|
|
73
|
+
/** True while `signature` is the answered prompt, not yet seen to go away. */
|
|
74
|
+
isStale(signature: string): boolean;
|
|
75
|
+
}
|