@memoryblock/tools 0.1.0-beta
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 +21 -0
- package/dist/base.d.ts +17 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +12 -0
- package/dist/base.js.map +1 -0
- package/dist/core/channels.d.ts +9 -0
- package/dist/core/channels.d.ts.map +1 -0
- package/dist/core/channels.js +39 -0
- package/dist/core/channels.js.map +1 -0
- package/dist/core/identity.d.ts +5 -0
- package/dist/core/identity.d.ts.map +1 -0
- package/dist/core/identity.js +108 -0
- package/dist/core/identity.js.map +1 -0
- package/dist/dev/index.d.ts +7 -0
- package/dist/dev/index.d.ts.map +1 -0
- package/dist/dev/index.js +113 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/fs/index.d.ts +11 -0
- package/dist/fs/index.d.ts.map +1 -0
- package/dist/fs/index.js +240 -0
- package/dist/fs/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +33 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +96 -0
- package/dist/registry.js.map +1 -0
- package/dist/sandbox.d.ts +33 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +136 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/shell/index.d.ts +8 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +85 -0
- package/dist/shell/index.js.map +1 -0
- package/package.json +17 -0
- package/src/base.ts +24 -0
- package/src/core/channels.ts +47 -0
- package/src/core/identity.ts +125 -0
- package/src/dev/index.ts +119 -0
- package/src/fs/index.ts +272 -0
- package/src/index.ts +31 -0
- package/src/registry.ts +108 -0
- package/src/sandbox.ts +169 -0
- package/src/shell/index.ts +96 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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+1,14 @@
|
|
|
1
|
+
export { ToolRegistry } from './registry.js';
|
|
2
|
+
export type { Tool } from './base.js';
|
|
3
|
+
export { createSchema } from './base.js';
|
|
4
|
+
export { fsTools } from './fs/index.js';
|
|
5
|
+
export { shellTools, isSafeCommand } from './shell/index.js';
|
|
6
|
+
export { devTools } from './dev/index.js';
|
|
7
|
+
export { identityTools } from './core/identity.js';
|
|
8
|
+
export { channelTools } from './core/channels.js';
|
|
9
|
+
import { ToolRegistry } from './registry.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create a ToolRegistry pre-loaded with all built-in tools.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createDefaultRegistry(): ToolRegistry;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAO7C;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,YAAY,CAWpD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { ToolRegistry } from './registry.js';
|
|
2
|
+
export { createSchema } from './base.js';
|
|
3
|
+
export { fsTools } from './fs/index.js';
|
|
4
|
+
export { shellTools, isSafeCommand } from './shell/index.js';
|
|
5
|
+
export { devTools } from './dev/index.js';
|
|
6
|
+
export { identityTools } from './core/identity.js';
|
|
7
|
+
export { channelTools } from './core/channels.js';
|
|
8
|
+
import { ToolRegistry } from './registry.js';
|
|
9
|
+
import { fsTools } from './fs/index.js';
|
|
10
|
+
import { shellTools } from './shell/index.js';
|
|
11
|
+
import { devTools } from './dev/index.js';
|
|
12
|
+
import { identityTools } from './core/identity.js';
|
|
13
|
+
import { channelTools } from './core/channels.js';
|
|
14
|
+
/**
|
|
15
|
+
* Create a ToolRegistry pre-loaded with all built-in tools.
|
|
16
|
+
*/
|
|
17
|
+
export function createDefaultRegistry() {
|
|
18
|
+
const registry = new ToolRegistry();
|
|
19
|
+
// Core built-in tools
|
|
20
|
+
for (const tool of fsTools)
|
|
21
|
+
registry.register(tool);
|
|
22
|
+
for (const tool of shellTools)
|
|
23
|
+
registry.register(tool);
|
|
24
|
+
for (const tool of devTools)
|
|
25
|
+
registry.register(tool);
|
|
26
|
+
for (const tool of identityTools)
|
|
27
|
+
registry.register(tool);
|
|
28
|
+
for (const tool of channelTools)
|
|
29
|
+
registry.register(tool);
|
|
30
|
+
return registry;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACjC,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IAEpC,sBAAsB;IACtB,KAAK,MAAM,IAAI,IAAI,OAAO;QAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACpD,KAAK,MAAM,IAAI,IAAI,UAAU;QAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvD,KAAK,MAAM,IAAI,IAAI,QAAQ;QAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,aAAa;QAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1D,KAAK,MAAM,IAAI,IAAI,YAAY;QAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEzD,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ToolDefinition, ToolContext, ToolExecutionResult } from 'memoryblock';
|
|
2
|
+
import type { Tool } from './base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Central tool registry. Manages built-in tools and dynamically loaded plugin tools.
|
|
5
|
+
* Implements the LIST_TOOLS_AVAILABLE discovery pattern for token optimization.
|
|
6
|
+
* All execution passes through ToolSandbox for permission enforcement.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ToolRegistry {
|
|
9
|
+
private tools;
|
|
10
|
+
/** Register a tool. */
|
|
11
|
+
register(tool: Tool): void;
|
|
12
|
+
/** Check if a tool exists. */
|
|
13
|
+
has(name: string): boolean;
|
|
14
|
+
/** Get all tool definitions (for LIST_TOOLS_AVAILABLE). */
|
|
15
|
+
listTools(): ToolDefinition[];
|
|
16
|
+
/**
|
|
17
|
+
* Get the LIST_TOOLS_AVAILABLE meta-tool definition.
|
|
18
|
+
* This is the only tool exposed to the LLM on first contact.
|
|
19
|
+
*/
|
|
20
|
+
getDiscoveryTool(): ToolDefinition;
|
|
21
|
+
/**
|
|
22
|
+
* Execute a tool by name.
|
|
23
|
+
* All calls pass through ToolSandbox BEFORE execution.
|
|
24
|
+
* Implements graceful degradation — never throws.
|
|
25
|
+
*/
|
|
26
|
+
execute(name: string, params: Record<string, unknown>, context: ToolContext): Promise<ToolExecutionResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Load plugin tools from a dynamic import path.
|
|
29
|
+
* Uses try/catch for graceful degradation — never crashes if plugin is missing.
|
|
30
|
+
*/
|
|
31
|
+
loadPlugin(pluginPath: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGtC;;;;GAIG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,KAAK,CAA2B;IAExC,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAI1B,8BAA8B;IAC9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,2DAA2D;IAC3D,SAAS,IAAI,cAAc,EAAE;IAI7B;;;OAGG;IACH,gBAAgB,IAAI,cAAc;IASlC;;;;OAIG;IACG,OAAO,CACT,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,WAAW,GACrB,OAAO,CAAC,mBAAmB,CAAC;IAsC/B;;;OAGG;IACG,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAetD"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { log } from 'memoryblock';
|
|
2
|
+
import { ToolSandbox } from './sandbox.js';
|
|
3
|
+
/**
|
|
4
|
+
* Central tool registry. Manages built-in tools and dynamically loaded plugin tools.
|
|
5
|
+
* Implements the LIST_TOOLS_AVAILABLE discovery pattern for token optimization.
|
|
6
|
+
* All execution passes through ToolSandbox for permission enforcement.
|
|
7
|
+
*/
|
|
8
|
+
export class ToolRegistry {
|
|
9
|
+
tools = new Map();
|
|
10
|
+
/** Register a tool. */
|
|
11
|
+
register(tool) {
|
|
12
|
+
this.tools.set(tool.definition.name, tool);
|
|
13
|
+
}
|
|
14
|
+
/** Check if a tool exists. */
|
|
15
|
+
has(name) {
|
|
16
|
+
return this.tools.has(name);
|
|
17
|
+
}
|
|
18
|
+
/** Get all tool definitions (for LIST_TOOLS_AVAILABLE). */
|
|
19
|
+
listTools() {
|
|
20
|
+
return Array.from(this.tools.values()).map((t) => t.definition);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the LIST_TOOLS_AVAILABLE meta-tool definition.
|
|
24
|
+
* This is the only tool exposed to the LLM on first contact.
|
|
25
|
+
*/
|
|
26
|
+
getDiscoveryTool() {
|
|
27
|
+
return {
|
|
28
|
+
name: 'list_tools_available',
|
|
29
|
+
description: 'Discover all tools available to you. Call this first to see your capabilities.',
|
|
30
|
+
parameters: { type: 'object', properties: {}, required: [], additionalProperties: false },
|
|
31
|
+
requiresApproval: false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Execute a tool by name.
|
|
36
|
+
* All calls pass through ToolSandbox BEFORE execution.
|
|
37
|
+
* Implements graceful degradation — never throws.
|
|
38
|
+
*/
|
|
39
|
+
async execute(name, params, context) {
|
|
40
|
+
// Handle the meta-tool
|
|
41
|
+
if (name === 'list_tools_available') {
|
|
42
|
+
const tools = this.listTools();
|
|
43
|
+
const listing = tools.map((t) => `- **${t.name}**: ${t.description}`).join('\n');
|
|
44
|
+
return {
|
|
45
|
+
content: `You have ${tools.length} tools available:\n\n${listing}\n\nCall any tool by name with the required parameters.`,
|
|
46
|
+
isError: false,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const tool = this.tools.get(name);
|
|
50
|
+
if (!tool) {
|
|
51
|
+
// Graceful degradation — never crash
|
|
52
|
+
return {
|
|
53
|
+
content: `Tool "${name}" not found. Use list_tools_available to see available tools.`,
|
|
54
|
+
isError: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// ===== SANDBOX GATE =====
|
|
58
|
+
// Validate BEFORE execution. If denied, the tool never runs.
|
|
59
|
+
const denied = ToolSandbox.validate(name, params, context);
|
|
60
|
+
if (denied) {
|
|
61
|
+
return denied;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return await tool.execute(params, context);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
68
|
+
return {
|
|
69
|
+
content: `Tool "${name}" failed: ${message}`,
|
|
70
|
+
isError: true,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Load plugin tools from a dynamic import path.
|
|
76
|
+
* Uses try/catch for graceful degradation — never crashes if plugin is missing.
|
|
77
|
+
*/
|
|
78
|
+
async loadPlugin(pluginPath) {
|
|
79
|
+
try {
|
|
80
|
+
const mod = await import(pluginPath);
|
|
81
|
+
if (mod.tools && Array.isArray(mod.tools)) {
|
|
82
|
+
for (const tool of mod.tools) {
|
|
83
|
+
this.register(tool);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (mod.default && typeof mod.default === 'object' && 'definition' in mod.default) {
|
|
87
|
+
this.register(mod.default);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
92
|
+
log.warn(`Failed to load plugin "${pluginPath}": ${message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACb,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IAExC,uBAAuB;IACvB,QAAQ,CAAC,IAAU;QACf,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,8BAA8B;IAC9B,GAAG,CAAC,IAAY;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,2DAA2D;IAC3D,SAAS;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACpE,CAAC;IAED;;;OAGG;IACH,gBAAgB;QACZ,OAAO;YACH,IAAI,EAAE,sBAAsB;YAC5B,WAAW,EAAE,gFAAgF;YAC7F,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EA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AC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO;gBACH,OAAO,EAAE,SAAS,IAAI,aAAa,OAAO,EAAE;gBAC5C,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAC,UAAkB;QAC/B,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;YACrC,IAAI,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAe,EAAE,CAAC;oBACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBACxB,CAAC;YACL,CAAC;iBAAM,IAAI,GAAG,CAAC,OAAO,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,YAAY,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;gBACvF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAe,CAAC,CAAC;YACvC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,GAAG,CAAC,IAAI,CAAC,0BAA0B,UAAU,MAAM,OAAO,EAAE,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolSandbox — central enforcement layer for tool execution.
|
|
3
|
+
*
|
|
4
|
+
* Every tool.execute() call passes through this gate.
|
|
5
|
+
* It intercepts params, scans for file paths, validates them against
|
|
6
|
+
* the block's permission scope, and blocks disallowed operations.
|
|
7
|
+
*
|
|
8
|
+
* This class is designed as a drop-in replaceable module. Any future
|
|
9
|
+
* enforcement backend can substitute this class as long as it exposes
|
|
10
|
+
* the same static validate() and validateCommand() interface.
|
|
11
|
+
*/
|
|
12
|
+
import type { ToolContext, ToolExecutionResult } from 'memoryblock';
|
|
13
|
+
export declare class ToolSandbox {
|
|
14
|
+
/**
|
|
15
|
+
* Validate a tool call BEFORE execution.
|
|
16
|
+
* Returns null if allowed, or an error ToolExecutionResult if denied.
|
|
17
|
+
*/
|
|
18
|
+
static validate(toolName: string, params: Record<string, unknown>, context: ToolContext): ToolExecutionResult | null;
|
|
19
|
+
/**
|
|
20
|
+
* Scan params for file path values and validate against scope.
|
|
21
|
+
*/
|
|
22
|
+
private static scanPaths;
|
|
23
|
+
/**
|
|
24
|
+
* Check if any string param references a sensitive file.
|
|
25
|
+
*/
|
|
26
|
+
private static scanSensitive;
|
|
27
|
+
/**
|
|
28
|
+
* Scan a shell command string for path traversal attempts.
|
|
29
|
+
* Returns an error message if the command looks like it's escaping scope.
|
|
30
|
+
*/
|
|
31
|
+
static validateCommand(command: string, context: ToolContext): string | null;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AAmBvF,qBAAa,WAAW;IAEpB;;;OAGG;IACH,MAAM,CAAC,QAAQ,CACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,WAAW,GACrB,mBAAmB,GAAG,IAAI;IA+B7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAsCxB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAa5B;;;OAGG;IACH,MAAM,CAAC,eAAe,CAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,WAAW,GACrB,MAAM,GAAG,IAAI;CA+BnB"}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolSandbox — central enforcement layer for tool execution.
|
|
3
|
+
*
|
|
4
|
+
* Every tool.execute() call passes through this gate.
|
|
5
|
+
* It intercepts params, scans for file paths, validates them against
|
|
6
|
+
* the block's permission scope, and blocks disallowed operations.
|
|
7
|
+
*
|
|
8
|
+
* This class is designed as a drop-in replaceable module. Any future
|
|
9
|
+
* enforcement backend can substitute this class as long as it exposes
|
|
10
|
+
* the same static validate() and validateCommand() interface.
|
|
11
|
+
*/
|
|
12
|
+
import { resolve, relative, isAbsolute } from 'node:path';
|
|
13
|
+
// Patterns that look like file paths in tool params
|
|
14
|
+
const PATH_PARAM_NAMES = ['path', 'file', 'filePath', 'directory', 'dir', 'target', 'source', 'destination'];
|
|
15
|
+
// Sensitive files that should never be accessible regardless of scope
|
|
16
|
+
const SENSITIVE_PATTERNS = [
|
|
17
|
+
'auth.json',
|
|
18
|
+
'.env',
|
|
19
|
+
'.memoryblock/auth.json',
|
|
20
|
+
'id_rsa',
|
|
21
|
+
'id_ed25519',
|
|
22
|
+
'.ssh/config',
|
|
23
|
+
'.aws/credentials',
|
|
24
|
+
];
|
|
25
|
+
// Shell tools that need special handling
|
|
26
|
+
const SHELL_TOOL_NAMES = ['execute_command', 'run_lint', 'run_build', 'run_test'];
|
|
27
|
+
export class ToolSandbox {
|
|
28
|
+
/**
|
|
29
|
+
* Validate a tool call BEFORE execution.
|
|
30
|
+
* Returns null if allowed, or an error ToolExecutionResult if denied.
|
|
31
|
+
*/
|
|
32
|
+
static validate(toolName, params, context) {
|
|
33
|
+
const perms = context.permissions || { scope: 'block', allowShell: false, allowNetwork: true, maxTimeout: 120_000 };
|
|
34
|
+
// 1. Shell access check
|
|
35
|
+
if (SHELL_TOOL_NAMES.includes(toolName)) {
|
|
36
|
+
if (!perms.allowShell && perms.scope !== 'system') {
|
|
37
|
+
return {
|
|
38
|
+
content: `Denied: "${toolName}" requires shell access. Current scope: "${perms.scope}". Run \`mblk permissions ${context.blockName} --allow-shell\` to grant access.`,
|
|
39
|
+
isError: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// 2. Scan all params for file paths and validate
|
|
44
|
+
const pathViolation = ToolSandbox.scanPaths(params, context, perms);
|
|
45
|
+
if (pathViolation) {
|
|
46
|
+
return { content: pathViolation, isError: true };
|
|
47
|
+
}
|
|
48
|
+
// 3. Check for sensitive file access in any string param
|
|
49
|
+
const sensitiveHit = ToolSandbox.scanSensitive(params);
|
|
50
|
+
if (sensitiveHit) {
|
|
51
|
+
return {
|
|
52
|
+
content: `Denied: access to "${sensitiveHit}" is blocked for security.`,
|
|
53
|
+
isError: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return null; // Allowed
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Scan params for file path values and validate against scope.
|
|
60
|
+
*/
|
|
61
|
+
static scanPaths(params, context, perms) {
|
|
62
|
+
if (perms.scope === 'system')
|
|
63
|
+
return null; // No path restrictions
|
|
64
|
+
for (const [key, value] of Object.entries(params)) {
|
|
65
|
+
if (typeof value !== 'string')
|
|
66
|
+
continue;
|
|
67
|
+
// Check named path params
|
|
68
|
+
const isPathParam = PATH_PARAM_NAMES.some(p => key.toLowerCase().includes(p.toLowerCase()));
|
|
69
|
+
// Also check any string that looks like an absolute path
|
|
70
|
+
const looksLikePath = isPathParam || value.startsWith('/') || value.startsWith('~');
|
|
71
|
+
if (!looksLikePath)
|
|
72
|
+
continue;
|
|
73
|
+
const resolved = isAbsolute(value)
|
|
74
|
+
? value
|
|
75
|
+
: resolve(context.workingDir || context.blockPath, value);
|
|
76
|
+
const allowedRoot = perms.scope === 'workspace' && context.workspacePath
|
|
77
|
+
? context.workspacePath
|
|
78
|
+
: context.blockPath;
|
|
79
|
+
const rel = relative(allowedRoot, resolved);
|
|
80
|
+
if (rel.startsWith('..') || isAbsolute(rel)) {
|
|
81
|
+
const label = perms.scope === 'workspace' ? 'workspace' : 'block directory';
|
|
82
|
+
return `Denied: "${key}" points to "${value}" which is outside the ${label}. Scope: "${perms.scope}".`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if any string param references a sensitive file.
|
|
89
|
+
*/
|
|
90
|
+
static scanSensitive(params) {
|
|
91
|
+
for (const value of Object.values(params)) {
|
|
92
|
+
if (typeof value !== 'string')
|
|
93
|
+
continue;
|
|
94
|
+
const normalized = value.replace(/\\/g, '/');
|
|
95
|
+
for (const pattern of SENSITIVE_PATTERNS) {
|
|
96
|
+
if (normalized.endsWith(pattern) || normalized.includes(`/${pattern}`)) {
|
|
97
|
+
return pattern;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Scan a shell command string for path traversal attempts.
|
|
105
|
+
* Returns an error message if the command looks like it's escaping scope.
|
|
106
|
+
*/
|
|
107
|
+
static validateCommand(command, context) {
|
|
108
|
+
const perms = context.permissions || { scope: 'block', allowShell: false, allowNetwork: true, maxTimeout: 120_000 };
|
|
109
|
+
if (perms.scope === 'system')
|
|
110
|
+
return null;
|
|
111
|
+
// Check for common escape patterns in shell commands
|
|
112
|
+
const escapePatterns = [
|
|
113
|
+
/\bcd\s+\//, // cd /absolute
|
|
114
|
+
/\bcat\s+\//, // cat /etc/passwd
|
|
115
|
+
/\bls\s+\//, // ls / (outside block)
|
|
116
|
+
/>\s*\//, // redirect to absolute path
|
|
117
|
+
/\|\s*tee\s+\//, // pipe to absolute path
|
|
118
|
+
];
|
|
119
|
+
// Only flag these in block scope — workspace/system allow broader access
|
|
120
|
+
if (perms.scope === 'block') {
|
|
121
|
+
for (const pattern of escapePatterns) {
|
|
122
|
+
if (pattern.test(command)) {
|
|
123
|
+
return `Denied: command appears to access paths outside the block directory. Scope: "block".`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Check for sensitive file access in any scope
|
|
128
|
+
for (const sensitive of SENSITIVE_PATTERNS) {
|
|
129
|
+
if (command.includes(sensitive)) {
|
|
130
|
+
return `Denied: command references sensitive file "${sensitive}".`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG1D,oDAAoD;AACpD,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAE7G,sEAAsE;AACtE,MAAM,kBAAkB,GAAG;IACvB,WAAW;IACX,MAAM;IACN,wBAAwB;IACxB,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,kBAAkB;CACrB,CAAC;AAEF,yCAAyC;AACzC,MAAM,gBAAgB,GAAG,CAAC,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAElF,MAAM,OAAO,WAAW;IAEpB;;;OAGG;IACH,MAAM,CAAC,QAAQ,CACX,QAAgB,EAChB,MAA+B,EAC/B,OAAoB;QAEpB,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,IA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O,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Tool } from '../base.js';
|
|
2
|
+
declare function isSafeCommand(command: string): boolean;
|
|
3
|
+
export declare const executeCommandTool: Tool;
|
|
4
|
+
/** Check if a command is safe (export for use in approval logic). */
|
|
5
|
+
export { isSafeCommand };
|
|
6
|
+
/** All built-in shell tools. */
|
|
7
|
+
export declare const shellTools: Tool[];
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shell/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAgBvC,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAG/C;AAGD,eAAO,MAAM,kBAAkB,EAAE,IAgEhC,CAAC;AAEF,qEAAqE;AACrE,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAE,IAAI,EAAyB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { createSchema } from '../base.js';
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
const DEFAULT_TIMEOUT = 120_000; // 2 minutes
|
|
6
|
+
const MAX_OUTPUT = 50_000;
|
|
7
|
+
// Commands that are safe to auto-execute without approval
|
|
8
|
+
const SAFE_PREFIXES = [
|
|
9
|
+
'ls', 'cat', 'head', 'tail', 'wc', 'find', 'grep', 'which', 'echo', 'pwd',
|
|
10
|
+
'node --version', 'bun --version', 'pnpm --version', 'npm --version',
|
|
11
|
+
'git status', 'git log', 'git diff', 'git branch',
|
|
12
|
+
'tsc --noEmit', 'npx eslint', 'pnpm lint', 'npm run lint',
|
|
13
|
+
'pnpm build', 'npm run build', 'pnpm test', 'npm test',
|
|
14
|
+
];
|
|
15
|
+
function isSafeCommand(command) {
|
|
16
|
+
const trimmed = command.trim();
|
|
17
|
+
return SAFE_PREFIXES.some((prefix) => trimmed.startsWith(prefix));
|
|
18
|
+
}
|
|
19
|
+
// ===== execute_command =====
|
|
20
|
+
export const executeCommandTool = {
|
|
21
|
+
definition: {
|
|
22
|
+
name: 'execute_command',
|
|
23
|
+
description: 'Run shell command (Safe cmds run auto).',
|
|
24
|
+
parameters: createSchema({
|
|
25
|
+
command: { type: 'string', description: 'Command.' },
|
|
26
|
+
timeout: { type: 'string', description: 'Timeout (ms).' },
|
|
27
|
+
}, ['command']),
|
|
28
|
+
// Dynamic approval: overridden at dispatch time based on command safety
|
|
29
|
+
requiresApproval: true,
|
|
30
|
+
},
|
|
31
|
+
async execute(params, context) {
|
|
32
|
+
const command = params.command;
|
|
33
|
+
const scope = context.permissions?.scope || 'block';
|
|
34
|
+
// Permission check: shell access must be explicitly granted
|
|
35
|
+
if (!context.permissions?.allowShell && scope !== 'system') {
|
|
36
|
+
return {
|
|
37
|
+
content: `Shell access denied. Current permission scope: "${scope}". Set allowShell: true or scope: "system" via \`mblk permissions ${context.blockName} --allow-shell\`.`,
|
|
38
|
+
isError: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const timeout = context.permissions?.maxTimeout
|
|
42
|
+
|| (params.timeout ? parseInt(params.timeout, 10) : DEFAULT_TIMEOUT);
|
|
43
|
+
// Determine cwd based on scope
|
|
44
|
+
let cwd = context.workingDir || context.blockPath;
|
|
45
|
+
if (scope === 'block') {
|
|
46
|
+
cwd = context.blockPath;
|
|
47
|
+
}
|
|
48
|
+
else if (scope === 'workspace' && context.workspacePath) {
|
|
49
|
+
// Allow commands within workspace, but default cwd to block
|
|
50
|
+
cwd = context.workingDir || context.blockPath;
|
|
51
|
+
}
|
|
52
|
+
// scope === 'system' — use whatever workingDir is set
|
|
53
|
+
try {
|
|
54
|
+
const { stdout, stderr } = await execFileAsync('/bin/sh', ['-c', command], {
|
|
55
|
+
cwd,
|
|
56
|
+
timeout,
|
|
57
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
58
|
+
env: { ...process.env, HOME: process.env.HOME },
|
|
59
|
+
});
|
|
60
|
+
let output = '';
|
|
61
|
+
if (stdout)
|
|
62
|
+
output += stdout;
|
|
63
|
+
if (stderr)
|
|
64
|
+
output += (output ? '\n--- stderr ---\n' : '') + stderr;
|
|
65
|
+
if (output.length > MAX_OUTPUT) {
|
|
66
|
+
output = output.slice(0, MAX_OUTPUT) + `\n...(truncated, ${output.length} total chars)`;
|
|
67
|
+
}
|
|
68
|
+
return { content: output || '(no output)', isError: false };
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
const error = err;
|
|
72
|
+
let message = error.message;
|
|
73
|
+
if (error.stdout)
|
|
74
|
+
message += `\nstdout: ${error.stdout.slice(0, 5000)}`;
|
|
75
|
+
if (error.stderr)
|
|
76
|
+
message += `\nstderr: ${error.stderr.slice(0, 5000)}`;
|
|
77
|
+
return { content: `Command failed: ${message}`, isError: true };
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
/** Check if a command is safe (export for use in approval logic). */
|
|
82
|
+
export { isSafeCommand };
|
|
83
|
+
/** All built-in shell tools. */
|
|
84
|
+
export const shellTools = [executeCommandTool];
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shell/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC1C,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC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AE,CAAC,GAAG,MAAM,CAAC;YAEpE,IAAI,MAAM,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;gBAC7B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,oBAAoB,MAAM,CAAC,MAAM,eAAe,CAAC;YAC5F,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAChE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,KAAK,GAAG,GAAkE,CAAC;YACjF,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;YAC5B,IAAI,KAAK,CAAC,MAAM;gBAAE,OAAO,IAAI,aAAa,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;YACxE,IAAI,KAAK,CAAC,MAAM;gBAAE,OAAO,IAAI,aAAa,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;YACxE,OAAO,EAAE,OAAO,EAAE,mBAAmB,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACpE,CAAC;IACL,CAAC;CACJ,CAAC;AAEF,qEAAqE;AACrE,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,gCAAgC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAW,CAAC,kBAAkB,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@memoryblock/tools",
|
|
3
|
+
"version": "0.1.0-beta",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"memoryblock": "0.1.0-beta"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/base.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ToolDefinition, ToolContext, ToolExecutionResult } from 'memoryblock';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base Tool interface. All built-in and plugin tools must implement this.
|
|
5
|
+
*/
|
|
6
|
+
export interface Tool {
|
|
7
|
+
readonly definition: ToolDefinition;
|
|
8
|
+
execute(params: Record<string, unknown>, context: ToolContext): Promise<ToolExecutionResult>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Helper to create a JSON Schema object for tool parameters.
|
|
13
|
+
*/
|
|
14
|
+
export function createSchema(
|
|
15
|
+
properties: Record<string, { type: string; description: string; enum?: string[] }>,
|
|
16
|
+
required: string[] = [],
|
|
17
|
+
): Record<string, unknown> {
|
|
18
|
+
return {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties,
|
|
21
|
+
required,
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ToolExecutionResult, ToolContext } from 'memoryblock';
|
|
2
|
+
import type { Tool } from '../base.js';
|
|
3
|
+
import { createSchema } from '../base.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* send_channel_message tool allows the monitor to proactively dispatch
|
|
7
|
+
* a message to a specific bound channel (e.g. Telegram or CLI), rather
|
|
8
|
+
* than just passively replying to the channel that initiated the turn.
|
|
9
|
+
*/
|
|
10
|
+
export const dispatchMessageTool: Tool = {
|
|
11
|
+
definition: {
|
|
12
|
+
name: 'send_channel_message',
|
|
13
|
+
description: 'Send a message proactively to a specific active channel (e.g., "telegram" or "cli"). Use this if the founder asks you to send them a message somewhere else.',
|
|
14
|
+
parameters: createSchema(
|
|
15
|
+
{
|
|
16
|
+
channel: { type: 'string', description: 'The exact name of the target channel (e.g., "telegram", "cli").' },
|
|
17
|
+
content: { type: 'string', description: 'The message content to send.' },
|
|
18
|
+
},
|
|
19
|
+
['channel', 'content'],
|
|
20
|
+
),
|
|
21
|
+
requiresApproval: false,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
async execute(params: Record<string, unknown>, context: ToolContext): Promise<ToolExecutionResult> {
|
|
25
|
+
const target = params.channel as string;
|
|
26
|
+
const content = params.content as string;
|
|
27
|
+
|
|
28
|
+
if (!context.dispatchMessage) {
|
|
29
|
+
return { content: 'Message dispatching is not supported in the current execution context.', isError: true };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
await context.dispatchMessage(target, content);
|
|
34
|
+
return {
|
|
35
|
+
content: `Message successfully dispatched proactively to channel: ${target}`,
|
|
36
|
+
isError: false,
|
|
37
|
+
};
|
|
38
|
+
} catch (err) {
|
|
39
|
+
return {
|
|
40
|
+
content: `Failed to dispatch message to channel '${target}': ${(err as Error).message}`,
|
|
41
|
+
isError: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const channelTools = [dispatchMessageTool];
|