@johannes.latzel/llm-chat-shell 0.1.1 → 0.3.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/config.d.ts +10 -5
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +36 -10
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/permission.d.ts +43 -24
- package/dist/lib/permission.d.ts.map +1 -1
- package/dist/lib/permission.js +92 -249
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/redirect-parser.d.ts +19 -0
- package/dist/lib/redirect-parser.d.ts.map +1 -0
- package/dist/lib/redirect-parser.js +302 -0
- package/dist/lib/redirect-parser.js.map +1 -0
- package/dist/lib/types.d.ts +43 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +16 -0
- package/dist/lib/types.js.map +1 -1
- package/dist/tools/shell-command-tool.d.ts +14 -5
- package/dist/tools/shell-command-tool.d.ts.map +1 -1
- package/dist/tools/shell-command-tool.js +79 -37
- package/dist/tools/shell-command-tool.js.map +1 -1
- package/dist/tools/shell-permissions-tool.d.ts.map +1 -1
- package/dist/tools/shell-permissions-tool.js +9 -2
- package/dist/tools/shell-permissions-tool.js.map +1 -1
- package/package.json +10 -9
|
@@ -1,71 +1,98 @@
|
|
|
1
1
|
import { Tool, ToolParameters, ToolParameterProperty, ResultStatus } from '@johannes.latzel/llm-chat';
|
|
2
2
|
import { workspaceForPath } from '../lib/permission.js';
|
|
3
3
|
import { PermissionAction, PermissionDenyReason } from '../lib/types.js';
|
|
4
|
+
/** Prefix of the notice reporting an auto-created session id. */
|
|
5
|
+
const SESSION_NOTICE = '[shell_command] new session: ';
|
|
6
|
+
/** Opening delimiter wrapping command output when a session was auto-created. */
|
|
7
|
+
const OUTPUT_BEGIN = '[shell_command] --- begin output ---';
|
|
8
|
+
/** Closing delimiter wrapping command output when a session was auto-created. */
|
|
9
|
+
const OUTPUT_END = '[shell_command] --- end output ---';
|
|
4
10
|
/**
|
|
5
11
|
* Tool that executes a shell command in a persistent session.
|
|
6
12
|
* Checks command permissions before execution. With `background=true` the
|
|
7
13
|
* command is submitted as a queued job and the tool returns a job ID
|
|
8
14
|
* immediately; poll `shell_job_status` for its progress and results.
|
|
15
|
+
*
|
|
16
|
+
* When `sessionId` is omitted or empty, a new session is created in the
|
|
17
|
+
* current workspace once the command is allowed, and its id is reported in a
|
|
18
|
+
* delimited notice ahead of the output. A non-empty id that is unknown or
|
|
19
|
+
* tombstoned keeps its descriptive error and never spawns a session.
|
|
9
20
|
*/
|
|
10
21
|
export class ShellCommandTool extends Tool {
|
|
11
22
|
sessionManager;
|
|
12
23
|
permissionSystem;
|
|
13
24
|
workspace;
|
|
14
25
|
constructor(sessionManager, permissionSystem, workspace) {
|
|
15
|
-
super('shell_command', 'Executes a shell command in a persistent session. Supports pipes (|), logical operators (&&, ||), and redirects.
|
|
26
|
+
super('shell_command', 'Executes a shell command in a persistent session. Supports pipes (|), logical operators (&&, ||), and redirects. ' +
|
|
27
|
+
'When sessionId is omitted or empty, a new session is created in the current workspace and its id is returned in the result. ' +
|
|
16
28
|
'Set background=true to submit the command as a queued job and return immediately with a job ID; poll shell_job_status / shell_jobs for results. ' +
|
|
17
29
|
'Set timeout to override the max idle time (no output) in ms; larger values are capped by the server config. ' +
|
|
18
30
|
'Set useCurrentWorkspace=true to run the command in the current workspace and permanently rebind the session to it.', new ToolParameters({
|
|
19
31
|
command: ToolParameterProperty.string('The shell command to execute.'),
|
|
20
|
-
sessionId: ToolParameterProperty.string('The session ID from shell_create.'),
|
|
32
|
+
sessionId: ToolParameterProperty.string('The session ID from shell_create. When omitted or empty, a new session is created in the current workspace and its id is returned in the result.'),
|
|
21
33
|
useCurrentWorkspace: ToolParameterProperty.boolean('When true, run the command in the current workspace and permanently bind this session to that workspace.'),
|
|
22
34
|
background: ToolParameterProperty.boolean('When true, submit the command as a background job, return immediately with a jobId, and continue with other work. Poll shell_job_status for the result.'),
|
|
23
35
|
timeout: ToolParameterProperty.integer('Max idle time in ms (no stdout/stderr output) before the command is killed. Defaults to the configured foreground or background timeout; larger values are capped by the server config.')
|
|
24
|
-
}, ['command'
|
|
36
|
+
}, ['command']));
|
|
25
37
|
this.sessionManager = sessionManager;
|
|
26
38
|
this.permissionSystem = permissionSystem;
|
|
27
39
|
this.workspace = workspace;
|
|
28
40
|
}
|
|
29
41
|
async onExecute(args) {
|
|
30
|
-
this.validateRequiredParams(args, ['command'
|
|
42
|
+
this.validateRequiredParams(args, ['command']);
|
|
31
43
|
const command = args['command'];
|
|
32
|
-
const
|
|
44
|
+
const rawSessionId = args['sessionId'];
|
|
45
|
+
const providedId = typeof rawSessionId === 'string' ? rawSessionId.trim() : '';
|
|
33
46
|
const useCurrentWorkspace = args['useCurrentWorkspace'] === true;
|
|
34
47
|
const background = args['background'] === true;
|
|
35
48
|
const timeout = this.parseTimeout(args['timeout']);
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
const
|
|
49
|
+
// Resolve the cwd and permission root. A non-empty unknown id throws here,
|
|
50
|
+
// before anything is created; an absent id resolves to the current workspace.
|
|
51
|
+
const target = await this.resolveTarget(providedId, useCurrentWorkspace);
|
|
52
|
+
// Check permissions against the effective workspace root before creating a session
|
|
53
|
+
const permission = this.permissionSystem.check(command, target.workspaceRoot);
|
|
39
54
|
if (permission.action === PermissionAction.Deny) {
|
|
40
|
-
const deniedSubs = this.getDeniedSubcommands(permission,
|
|
55
|
+
const deniedSubs = this.getDeniedSubcommands(permission, target.workspaceRoot);
|
|
41
56
|
const message = deniedSubs.length > 0
|
|
42
57
|
? `Permission denied for: ${deniedSubs.join(', ')}`
|
|
43
58
|
: 'Permission denied';
|
|
44
59
|
const reason = permission.denyReason === PermissionDenyReason.WriteAccess
|
|
45
|
-
? ` (requires write access to ${
|
|
60
|
+
? ` (requires write access to ${target.workspaceRoot})`
|
|
46
61
|
: '';
|
|
47
62
|
return { result: message + reason, status: ResultStatus.Error };
|
|
48
63
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
// The command is allowed: create the session now, or rebind an existing one.
|
|
65
|
+
let sessionId = providedId;
|
|
66
|
+
let createdId;
|
|
67
|
+
if (target.create) {
|
|
68
|
+
sessionId = await this.sessionManager.createSession(target.cwd);
|
|
69
|
+
createdId = sessionId;
|
|
70
|
+
}
|
|
71
|
+
else if (useCurrentWorkspace) {
|
|
72
|
+
await this.sessionManager.rebindSession(sessionId, target.workspaceRoot, target.cwd);
|
|
52
73
|
}
|
|
53
74
|
if (background) {
|
|
54
|
-
const job = await this.sessionManager.submitCommand(sessionId,
|
|
55
|
-
cwd:
|
|
75
|
+
const job = await this.sessionManager.submitCommand(sessionId, command, {
|
|
76
|
+
cwd: target.cwd,
|
|
56
77
|
...(timeout !== undefined ? { timeout } : {})
|
|
57
78
|
});
|
|
58
|
-
return {
|
|
79
|
+
return {
|
|
80
|
+
result: this.formatJobSubmitted(job, createdId),
|
|
81
|
+
status: ResultStatus.Success
|
|
82
|
+
};
|
|
59
83
|
}
|
|
60
84
|
// Execute command (blocks until the shell gets to it, running queued jobs first)
|
|
61
|
-
const result = await this.sessionManager.executeCommand(sessionId,
|
|
62
|
-
cwd:
|
|
85
|
+
const result = await this.sessionManager.executeCommand(sessionId, command, {
|
|
86
|
+
cwd: target.cwd,
|
|
63
87
|
...(timeout !== undefined ? { timeout } : {})
|
|
64
88
|
});
|
|
65
89
|
// Format output
|
|
66
90
|
const output = this.formatOutput(result);
|
|
67
91
|
const status = result.exitCode === 0 ? ResultStatus.Success : ResultStatus.Error;
|
|
68
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
result: createdId !== undefined ? this.withSessionNotice(createdId, output) : output,
|
|
94
|
+
status
|
|
95
|
+
};
|
|
69
96
|
}
|
|
70
97
|
/** Only finite, positive numbers are honored; anything else falls back to the default. */
|
|
71
98
|
parseTimeout(value) {
|
|
@@ -75,40 +102,55 @@ export class ShellCommandTool extends Tool {
|
|
|
75
102
|
return value;
|
|
76
103
|
}
|
|
77
104
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
105
|
+
* Resolve the cwd and workspace root a command targets. When no usable id
|
|
106
|
+
* was given, the command runs in the current workspace and a session is
|
|
107
|
+
* created; an explicit id keeps its bound cwd/root unless
|
|
108
|
+
* `useCurrentWorkspace` moves it to the current workspace.
|
|
82
109
|
*/
|
|
83
|
-
async
|
|
110
|
+
async resolveTarget(providedId, useCurrentWorkspace) {
|
|
111
|
+
if (providedId.length === 0) {
|
|
112
|
+
return {
|
|
113
|
+
create: true,
|
|
114
|
+
cwd: this.workspace.currentPath,
|
|
115
|
+
workspaceRoot: this.currentWorkspaceRoot()
|
|
116
|
+
};
|
|
117
|
+
}
|
|
84
118
|
if (!useCurrentWorkspace) {
|
|
85
119
|
return {
|
|
86
|
-
|
|
87
|
-
cwd: await this.sessionManager.getSessionCwd(
|
|
88
|
-
workspaceRoot: await this.sessionManager.getSessionWorkspaceRoot(
|
|
120
|
+
create: false,
|
|
121
|
+
cwd: await this.sessionManager.getSessionCwd(providedId),
|
|
122
|
+
workspaceRoot: await this.sessionManager.getSessionWorkspaceRoot(providedId)
|
|
89
123
|
};
|
|
90
124
|
}
|
|
91
|
-
const roots = this.workspace.getAccesses().map((a) => a.path);
|
|
92
|
-
const workspaceRoot = workspaceForPath(this.workspace.currentPath, roots);
|
|
93
125
|
return {
|
|
94
|
-
|
|
126
|
+
create: false,
|
|
95
127
|
cwd: this.workspace.currentPath,
|
|
96
|
-
workspaceRoot
|
|
128
|
+
workspaceRoot: this.currentWorkspaceRoot()
|
|
97
129
|
};
|
|
98
130
|
}
|
|
131
|
+
/** Deepest workspace access root containing the current workspace path. */
|
|
132
|
+
currentWorkspaceRoot() {
|
|
133
|
+
const roots = this.workspace.getAccesses().map((a) => a.path);
|
|
134
|
+
return workspaceForPath(this.workspace.currentPath, roots);
|
|
135
|
+
}
|
|
99
136
|
getDeniedSubcommands(permission, workspaceRoot) {
|
|
100
|
-
// Re-check each
|
|
137
|
+
// Re-check each raw fragment (core + redirects) to find which are denied
|
|
101
138
|
const denied = [];
|
|
102
|
-
for (const
|
|
103
|
-
const check = this.permissionSystem.check(
|
|
139
|
+
for (const fragment of permission.fragments) {
|
|
140
|
+
const check = this.permissionSystem.check(fragment.raw, workspaceRoot);
|
|
104
141
|
if (check.action === PermissionAction.Deny) {
|
|
105
|
-
denied.push(
|
|
142
|
+
denied.push(fragment.raw);
|
|
106
143
|
}
|
|
107
144
|
}
|
|
108
145
|
return denied;
|
|
109
146
|
}
|
|
110
|
-
|
|
111
|
-
|
|
147
|
+
/** Wrap output with the created-session notice and delimiters the model can spot. */
|
|
148
|
+
withSessionNotice(sessionId, output) {
|
|
149
|
+
return `${SESSION_NOTICE}${sessionId}\n${OUTPUT_BEGIN}\n${output}\n${OUTPUT_END}`;
|
|
150
|
+
}
|
|
151
|
+
formatJobSubmitted(job, createdId) {
|
|
152
|
+
const message = `Background job ${job.id} submitted (status: ${job.status}, queue position ${job.position}). Poll shell_job_status with this jobId for results.`;
|
|
153
|
+
return createdId !== undefined ? `${SESSION_NOTICE}${createdId}\n${message}` : message;
|
|
112
154
|
}
|
|
113
155
|
formatOutput(result) {
|
|
114
156
|
const parts = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-command-tool.js","sourceRoot":"","sources":["../../src/tools/shell-command-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,cAAc,EACd,qBAAqB,EACrB,YAAY,EAEf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAGH,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"shell-command-tool.js","s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MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"shell-permissions-tool.d.ts","sourceRoot":"","sources":["../../src/tools/shell-permissions-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EAGJ,KAAK,iBAAiB,EACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI3D;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,IAAI;IAEtC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;gBADT,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,SAAS;cAUhB,SAAS,IAAI,OAAO,CAAC,iBAAiB,CAAC;CA4B1D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Tool, ToolParameters, ResultStatus } from '@johannes.latzel/llm-chat';
|
|
2
2
|
import { workspaceForPath } from '../lib/permission.js';
|
|
3
|
+
import { PermissionType } from '../lib/types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Tool that returns the current workspace and the permission rules / default
|
|
5
6
|
* action that apply to it. Lets the LLM understand what commands are allowed or
|
|
@@ -28,8 +29,14 @@ export class ShellPermissionsTool extends Tool {
|
|
|
28
29
|
parts.push('Rules:');
|
|
29
30
|
for (let i = 0; i < perms.permissionRules.length; i++) {
|
|
30
31
|
const rule = perms.permissionRules[i];
|
|
31
|
-
const
|
|
32
|
-
|
|
32
|
+
const descriptors = [];
|
|
33
|
+
if (rule.access !== undefined)
|
|
34
|
+
descriptors.push(rule.access);
|
|
35
|
+
if ((rule.type ?? perms.defaultType) === PermissionType.Redirect) {
|
|
36
|
+
descriptors.push('redirect');
|
|
37
|
+
}
|
|
38
|
+
const suffix = descriptors.length > 0 ? ` (${descriptors.join(', ')})` : '';
|
|
39
|
+
parts.push(`${i + 1}. ${rule.pattern} → ${rule.action}${suffix}`);
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
return { result: parts.join('\n'), status: ResultStatus.Success };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-permissions-tool.js","sourceRoot":"","sources":["../../src/tools/shell-permissions-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,cAAc,EACd,YAAY,EAEf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"shell-permissions-tool.js","sourceRoot":"","sources":["../../src/tools/shell-permissions-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,cAAc,EACd,YAAY,EAEf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,IAAI;IAE9B;IACA;IAFZ,YACY,MAA0B,EAC1B,SAAoB;QAE5B,KAAK,CACD,mBAAmB,EACnB,oGAAoG;YAChG,yFAAyF,EAC7F,IAAI,cAAc,CAAC,EAAE,CAAC,CACzB,CAAC;QARM,WAAM,GAAN,MAAM,CAAoB;QAC1B,cAAS,GAAT,SAAS,CAAW;IAQhC,CAAC;IAES,KAAK,CAAC,SAAS;QACrB,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,gBAAgB,CAA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AC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;YACtE,CAAC;QACL,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC;IACtE,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johannes.latzel/llm-chat-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Tightly controlled shell tool for llm-chat with permission system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prebuild": "rm -rf dist/",
|
|
45
45
|
"prepack": "npm run build",
|
|
46
46
|
"build": "tsc -p tsconfig.build.json",
|
|
47
|
-
"verify": "tsc --noEmit && eslint . --max-warnings 0 && npm run check:lines && vitest run --coverage",
|
|
47
|
+
"verify": "tsc --noEmit && eslint . --max-warnings 0 && npm run check:lines && npm run check:mkdocs && vitest run --coverage",
|
|
48
48
|
"lint": "eslint . --max-warnings 0",
|
|
49
49
|
"format": "prettier --write 'docs/**/*.md' 'src/**/*.ts' 'tests/**/*.ts'",
|
|
50
50
|
"docs": "docker run --rm -it -p 8000:8000 -v $PWD:/docs squidfunk/mkdocs-material",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"clean:install": "rm -rf node_modules dist/ package-lock.json && npm cache clean --force && npm install && npm run verify",
|
|
55
55
|
"prepare": "husky",
|
|
56
56
|
"audit": "npm audit --audit-level=high",
|
|
57
|
-
"check:lines": "check-line-limits"
|
|
57
|
+
"check:lines": "check-line-limits",
|
|
58
|
+
"check:mkdocs": "check-mkdocs"
|
|
58
59
|
},
|
|
59
60
|
"lint-staged": {
|
|
60
61
|
"src/**/*.ts": [
|
|
@@ -66,16 +67,15 @@
|
|
|
66
67
|
"dependencies": {
|
|
67
68
|
"@johannes.latzel/llm-chat": "^0.7.0",
|
|
68
69
|
"@johannes.latzel/llm-chat-workspace": "^0.2.0",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
70
|
+
"@johannes.latzel/pattern-specific": "^0.1.0",
|
|
71
|
+
"async-mutex": "^0.5.0"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@eslint/js": "^10.0.1",
|
|
74
75
|
"@types/node": "^26.4.0",
|
|
75
|
-
"@types/picomatch": "^4.0.3",
|
|
76
76
|
"@typescript-eslint/eslint-plugin": "^8.68.0",
|
|
77
77
|
"@typescript-eslint/parser": "^8.60.0",
|
|
78
|
-
"@vitest/coverage-v8": "^
|
|
78
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
79
79
|
"eslint": "^10.9.1",
|
|
80
80
|
"eslint-config-prettier": "^10.1.2",
|
|
81
81
|
"eslint-plugin-n": "^18.3.0",
|
|
@@ -83,7 +83,8 @@
|
|
|
83
83
|
"lint-staged": "^17.4.1",
|
|
84
84
|
"prettier": "^3.5.3",
|
|
85
85
|
"typescript": "^6.0.3",
|
|
86
|
-
"vitest": "^
|
|
87
|
-
"@johannes.latzel/check-line-limits": "^1.0.1"
|
|
86
|
+
"vitest": "^5.0.0",
|
|
87
|
+
"@johannes.latzel/check-line-limits": "^1.0.1",
|
|
88
|
+
"@johannes.latzel/check-mkdocs": "^0.1.0"
|
|
88
89
|
}
|
|
89
90
|
}
|