@framers/agentos-ext-local-file-search 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 +98 -0
- package/README.md +73 -0
- package/dist/LocalFileSearchTool.d.ts +46 -0
- package/dist/LocalFileSearchTool.d.ts.map +1 -0
- package/dist/LocalFileSearchTool.js +175 -0
- package/dist/LocalFileSearchTool.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/manifest.json +25 -0
- package/package.json +45 -0
- package/src/LocalFileSearchTool.ts +172 -0
- package/src/index.ts +31 -0
- package/src/types.ts +64 -0
- package/test/LocalFileSearchTool.spec.ts +83 -0
- package/tsconfig.json +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License.
|
|
30
|
+
|
|
31
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License.
|
|
34
|
+
|
|
35
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
36
|
+
|
|
37
|
+
4. Redistribution.
|
|
38
|
+
|
|
39
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
40
|
+
|
|
41
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
42
|
+
|
|
43
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
44
|
+
|
|
45
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
46
|
+
|
|
47
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
48
|
+
|
|
49
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
50
|
+
|
|
51
|
+
5. Submission of Contributions.
|
|
52
|
+
|
|
53
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
54
|
+
|
|
55
|
+
6. Trademarks.
|
|
56
|
+
|
|
57
|
+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
58
|
+
|
|
59
|
+
7. Disclaimer of Warranty.
|
|
60
|
+
|
|
61
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
+
|
|
63
|
+
8. Limitation of Liability.
|
|
64
|
+
|
|
65
|
+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
66
|
+
|
|
67
|
+
9. Accepting Warranty or Additional Liability.
|
|
68
|
+
|
|
69
|
+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
70
|
+
|
|
71
|
+
END OF TERMS AND CONDITIONS
|
|
72
|
+
|
|
73
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
74
|
+
|
|
75
|
+
To apply the Apache License to your work, attach the following
|
|
76
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
77
|
+
replaced with your own identifying information. (Don't include
|
|
78
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
79
|
+
comment syntax for the file format. We also recommend that a
|
|
80
|
+
file or class name and description of purpose be included on the
|
|
81
|
+
same "printed page" as the copyright notice for easier
|
|
82
|
+
identification within third-party archives.
|
|
83
|
+
|
|
84
|
+
Copyright (c) 2025 Framers
|
|
85
|
+
|
|
86
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
87
|
+
you may not use this file except in compliance with the License.
|
|
88
|
+
You may obtain a copy of the License at
|
|
89
|
+
|
|
90
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
91
|
+
|
|
92
|
+
Unless required by applicable law or agreed to in writing, software
|
|
93
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
94
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
95
|
+
See the License for the specific language governing permissions and
|
|
96
|
+
limitations under the License.
|
|
97
|
+
|
|
98
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Local File Search
|
|
2
|
+
|
|
3
|
+
Search for files on the local filesystem by fuzzy name matching.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @framers/agentos-ext-local-file-search
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createExtensionPack } from '@framers/agentos-ext-local-file-search';
|
|
15
|
+
|
|
16
|
+
const pack = createExtensionPack({
|
|
17
|
+
config: {
|
|
18
|
+
denylist: ['/proc', '/sys', 'node_modules', '.git', '.ssh', '*.key'],
|
|
19
|
+
maxResults: 10,
|
|
20
|
+
maxDepth: 10,
|
|
21
|
+
timeoutMs: 10000,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Tool: `local_file_search`
|
|
27
|
+
|
|
28
|
+
| Parameter | Type | Required | Description |
|
|
29
|
+
|-----------|------|----------|-------------|
|
|
30
|
+
| `query` | string | Yes | Filename or partial filename to search for |
|
|
31
|
+
| `directory` | string | No | Specific directory to search (defaults to full filesystem) |
|
|
32
|
+
|
|
33
|
+
### Example
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
User: "Find pic.png in my Downloads folder"
|
|
37
|
+
Tool call: local_file_search({ query: "pic.png", directory: "/Users/me/Downloads" })
|
|
38
|
+
Result: [{ path: "/Users/me/Downloads/pic.png", size: 2100000, mimeType: "image/png" }]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Relevance Ranking
|
|
42
|
+
|
|
43
|
+
Results are ranked by match quality:
|
|
44
|
+
|
|
45
|
+
| Match Type | Score | Example |
|
|
46
|
+
|-----------|-------|---------|
|
|
47
|
+
| Exact match | 1.0 | `pic.png` matches `pic.png` |
|
|
48
|
+
| Without extension | 0.95 | `pic` matches `pic.png` |
|
|
49
|
+
| Starts with | 0.8 | `pic` matches `picture.jpg` |
|
|
50
|
+
| Contains | 0.6 | `report` matches `quarterly-report.pdf` |
|
|
51
|
+
| Fuzzy (Levenshtein ≤ 3) | 0.06-0.30 | `rprt` matches `report` |
|
|
52
|
+
|
|
53
|
+
## Denylist
|
|
54
|
+
|
|
55
|
+
The denylist filters both directories and files:
|
|
56
|
+
|
|
57
|
+
- **Directory patterns**: `/proc`, `/sys`, `node_modules`, `.git`, `.ssh`
|
|
58
|
+
- **Glob patterns**: `*.key`, `*.pem`, `*.secret`
|
|
59
|
+
|
|
60
|
+
Configurable via `agent.config.json`:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"fileSearch": {
|
|
65
|
+
"denylist": ["/proc", "/sys", "node_modules", ".git", ".ssh", "*.key"],
|
|
66
|
+
"maxResults": 10
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Local File Search — find files on the host filesystem by fuzzy name matching.
|
|
3
|
+
*
|
|
4
|
+
* Searches the full filesystem (or a specified directory) with a configurable denylist
|
|
5
|
+
* to exclude sensitive paths. Results are ranked by relevance: exact > startsWith > contains > fuzzy.
|
|
6
|
+
*
|
|
7
|
+
* @module agentos-ext-local-file-search/LocalFileSearchTool
|
|
8
|
+
*/
|
|
9
|
+
import type { FileSearchConfig, LocalFileSearchInput, LocalFileSearchOutput } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* ITool implementation for local filesystem search.
|
|
12
|
+
* Walks directories recursively, matches files by name, and ranks by relevance.
|
|
13
|
+
*/
|
|
14
|
+
export declare class LocalFileSearchTool {
|
|
15
|
+
readonly id = "local_file_search";
|
|
16
|
+
readonly name = "local_file_search";
|
|
17
|
+
readonly displayName = "Local File Search";
|
|
18
|
+
readonly description = "Search for files on the local filesystem by name. Returns matching files sorted by relevance.";
|
|
19
|
+
readonly parameters: {
|
|
20
|
+
type: "object";
|
|
21
|
+
properties: {
|
|
22
|
+
query: {
|
|
23
|
+
type: string;
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
directory: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
required: string[];
|
|
32
|
+
};
|
|
33
|
+
private config;
|
|
34
|
+
constructor(config?: Partial<FileSearchConfig>);
|
|
35
|
+
/** Execute the file search. */
|
|
36
|
+
execute(input: LocalFileSearchInput): Promise<LocalFileSearchOutput>;
|
|
37
|
+
/** Score how well a filename matches the query. 0 = no match. */
|
|
38
|
+
private scoreRelevance;
|
|
39
|
+
/** Check if a directory name or path is in the denylist. */
|
|
40
|
+
private isDeniedDir;
|
|
41
|
+
/** Check if a filename matches a glob-style denylist pattern (e.g., *.key). */
|
|
42
|
+
private isDeniedFile;
|
|
43
|
+
/** Simple Levenshtein distance for fuzzy matching. */
|
|
44
|
+
private levenshtein;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=LocalFileSearchTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalFileSearchTool.d.ts","sourceRoot":"","sources":["../src/LocalFileSearchTool.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACV,gBAAgB,EAEhB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAmBpB;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,EAAE,uBAAuB;IAClC,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,WAAW,uBAAuB;IAC3C,QAAQ,CAAC,WAAW,mGAAmG;IACvH,QAAQ,CAAC,UAAU;;;;;;;;;;;;;MAOjB;IAEF,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAI9C,+BAA+B;IACzB,OAAO,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAyD1E,iEAAiE;IACjE,OAAO,CAAC,cAAc;IAgBtB,4DAA4D;IAC5D,OAAO,CAAC,WAAW;IAUnB,+EAA+E;IAC/E,OAAO,CAAC,YAAY;IASpB,sDAAsD;IACtD,OAAO,CAAC,WAAW;CAcpB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Local File Search — find files on the host filesystem by fuzzy name matching.
|
|
4
|
+
*
|
|
5
|
+
* Searches the full filesystem (or a specified directory) with a configurable denylist
|
|
6
|
+
* to exclude sensitive paths. Results are ranked by relevance: exact > startsWith > contains > fuzzy.
|
|
7
|
+
*
|
|
8
|
+
* @module agentos-ext-local-file-search/LocalFileSearchTool
|
|
9
|
+
*/
|
|
10
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
11
|
+
import { join, basename, extname } from 'node:path';
|
|
12
|
+
import { DEFAULT_FILE_SEARCH_CONFIG } from './types.js';
|
|
13
|
+
/** MIME type map for common file extensions. */
|
|
14
|
+
const MIME_MAP = {
|
|
15
|
+
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
16
|
+
'.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml',
|
|
17
|
+
'.mp4': 'video/mp4', '.mov': 'video/quicktime', '.webm': 'video/webm',
|
|
18
|
+
'.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg',
|
|
19
|
+
'.pdf': 'application/pdf', '.zip': 'application/zip',
|
|
20
|
+
'.txt': 'text/plain', '.json': 'application/json',
|
|
21
|
+
'.csv': 'text/csv', '.md': 'text/markdown',
|
|
22
|
+
'.doc': 'application/msword',
|
|
23
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
24
|
+
'.xls': 'application/vnd.ms-excel',
|
|
25
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
26
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* ITool implementation for local filesystem search.
|
|
30
|
+
* Walks directories recursively, matches files by name, and ranks by relevance.
|
|
31
|
+
*/
|
|
32
|
+
export class LocalFileSearchTool {
|
|
33
|
+
id = 'local_file_search';
|
|
34
|
+
name = 'local_file_search';
|
|
35
|
+
displayName = 'Local File Search';
|
|
36
|
+
description = 'Search for files on the local filesystem by name. Returns matching files sorted by relevance.';
|
|
37
|
+
parameters = {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
query: { type: 'string', description: 'Filename or partial filename to search for' },
|
|
41
|
+
directory: { type: 'string', description: 'Specific directory to search (overrides default scope)' },
|
|
42
|
+
},
|
|
43
|
+
required: ['query'],
|
|
44
|
+
};
|
|
45
|
+
config;
|
|
46
|
+
constructor(config) {
|
|
47
|
+
this.config = { ...DEFAULT_FILE_SEARCH_CONFIG, ...config };
|
|
48
|
+
}
|
|
49
|
+
/** Execute the file search. */
|
|
50
|
+
async execute(input) {
|
|
51
|
+
const query = input.query.toLowerCase();
|
|
52
|
+
const rootDir = input.directory ?? '/';
|
|
53
|
+
const matches = [];
|
|
54
|
+
let directoriesScanned = 0;
|
|
55
|
+
let timedOut = false;
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
const walk = async (dir, depth) => {
|
|
58
|
+
if (depth > this.config.maxDepth)
|
|
59
|
+
return;
|
|
60
|
+
if (Date.now() - startTime > this.config.timeoutMs) {
|
|
61
|
+
timedOut = true;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (this.isDeniedDir(dir))
|
|
65
|
+
return;
|
|
66
|
+
directoriesScanned++;
|
|
67
|
+
let entries;
|
|
68
|
+
try {
|
|
69
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return;
|
|
73
|
+
} // permission denied, etc.
|
|
74
|
+
for (const entry of entries) {
|
|
75
|
+
if (timedOut)
|
|
76
|
+
return;
|
|
77
|
+
const fullPath = join(dir, entry.name);
|
|
78
|
+
if (entry.isDirectory()) {
|
|
79
|
+
if (!this.isDeniedDir(entry.name) && !this.isDeniedDir(fullPath)) {
|
|
80
|
+
await walk(fullPath, depth + 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (entry.isFile()) {
|
|
84
|
+
if (this.isDeniedFile(entry.name))
|
|
85
|
+
continue;
|
|
86
|
+
const relevance = this.scoreRelevance(entry.name.toLowerCase(), query);
|
|
87
|
+
if (relevance > 0) {
|
|
88
|
+
try {
|
|
89
|
+
const fileStat = await stat(fullPath);
|
|
90
|
+
matches.push({
|
|
91
|
+
path: fullPath,
|
|
92
|
+
name: entry.name,
|
|
93
|
+
size: fileStat.size,
|
|
94
|
+
modified: fileStat.mtime.toISOString(),
|
|
95
|
+
mimeType: MIME_MAP[extname(entry.name).toLowerCase()] ?? 'application/octet-stream',
|
|
96
|
+
relevance,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch { /* stat failed — skip */ }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
await walk(rootDir, 0);
|
|
105
|
+
matches.sort((a, b) => b.relevance - a.relevance);
|
|
106
|
+
return {
|
|
107
|
+
matches: matches.slice(0, this.config.maxResults),
|
|
108
|
+
directoriesScanned,
|
|
109
|
+
timedOut,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Score how well a filename matches the query. 0 = no match. */
|
|
113
|
+
scoreRelevance(filename, query) {
|
|
114
|
+
const nameNoExt = filename.replace(/\.[^.]+$/, '');
|
|
115
|
+
if (filename === query)
|
|
116
|
+
return 1.0; // exact match
|
|
117
|
+
if (nameNoExt === query)
|
|
118
|
+
return 0.95; // match without extension
|
|
119
|
+
if (filename.startsWith(query))
|
|
120
|
+
return 0.8; // starts with
|
|
121
|
+
if (nameNoExt.startsWith(query))
|
|
122
|
+
return 0.75;
|
|
123
|
+
if (filename.includes(query))
|
|
124
|
+
return 0.6; // contains
|
|
125
|
+
if (nameNoExt.includes(query))
|
|
126
|
+
return 0.55;
|
|
127
|
+
// Levenshtein for fuzzy (only if query is close in length)
|
|
128
|
+
if (Math.abs(nameNoExt.length - query.length) <= 3) {
|
|
129
|
+
const dist = this.levenshtein(nameNoExt, query);
|
|
130
|
+
if (dist <= 3)
|
|
131
|
+
return 0.3 - (dist * 0.08);
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
/** Check if a directory name or path is in the denylist. */
|
|
136
|
+
isDeniedDir(nameOrPath) {
|
|
137
|
+
const base = basename(nameOrPath);
|
|
138
|
+
return this.config.denylist.some(pattern => {
|
|
139
|
+
if (pattern.startsWith('*'))
|
|
140
|
+
return false; // glob patterns are for files only
|
|
141
|
+
if (pattern.startsWith('/'))
|
|
142
|
+
return nameOrPath.startsWith(pattern);
|
|
143
|
+
if (pattern.startsWith('.'))
|
|
144
|
+
return base === pattern;
|
|
145
|
+
return base === pattern;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/** Check if a filename matches a glob-style denylist pattern (e.g., *.key). */
|
|
149
|
+
isDeniedFile(filename) {
|
|
150
|
+
return this.config.denylist.some(pattern => {
|
|
151
|
+
if (pattern.startsWith('*.')) {
|
|
152
|
+
return filename.endsWith(pattern.slice(1));
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/** Simple Levenshtein distance for fuzzy matching. */
|
|
158
|
+
levenshtein(a, b) {
|
|
159
|
+
const m = a.length, n = b.length;
|
|
160
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
161
|
+
for (let i = 0; i <= m; i++)
|
|
162
|
+
dp[i][0] = i;
|
|
163
|
+
for (let j = 0; j <= n; j++)
|
|
164
|
+
dp[0][j] = j;
|
|
165
|
+
for (let i = 1; i <= m; i++) {
|
|
166
|
+
for (let j = 1; j <= n; j++) {
|
|
167
|
+
dp[i][j] = a[i - 1] === b[j - 1]
|
|
168
|
+
? dp[i - 1][j - 1]
|
|
169
|
+
: 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return dp[m][n];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=LocalFileSearchTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalFileSearchTool.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CAAC,EAAE;YAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5B,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;oBAC9B,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;oBAClB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Extension pack factory for the local-file-search tool.
|
|
3
|
+
* @module agentos-ext-local-file-search
|
|
4
|
+
*/
|
|
5
|
+
import { LocalFileSearchTool } from './LocalFileSearchTool.js';
|
|
6
|
+
import type { FileSearchConfig } from './types.js';
|
|
7
|
+
export { LocalFileSearchTool } from './LocalFileSearchTool.js';
|
|
8
|
+
export type { FileSearchConfig, FileMatch, LocalFileSearchInput, LocalFileSearchOutput } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create the local-file-search extension pack.
|
|
11
|
+
* @param ctx - Extension context with optional configuration.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createExtensionPack(ctx?: {
|
|
14
|
+
config?: Partial<FileSearchConfig>;
|
|
15
|
+
}): {
|
|
16
|
+
name: string;
|
|
17
|
+
version: string;
|
|
18
|
+
descriptors: {
|
|
19
|
+
id: string;
|
|
20
|
+
kind: "tool";
|
|
21
|
+
priority: number;
|
|
22
|
+
payload: LocalFileSearchTool;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE3G;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAAE;;;;;;;;;EAc/E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Extension pack factory for the local-file-search tool.
|
|
4
|
+
* @module agentos-ext-local-file-search
|
|
5
|
+
*/
|
|
6
|
+
import { LocalFileSearchTool } from './LocalFileSearchTool.js';
|
|
7
|
+
export { LocalFileSearchTool } from './LocalFileSearchTool.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create the local-file-search extension pack.
|
|
10
|
+
* @param ctx - Extension context with optional configuration.
|
|
11
|
+
*/
|
|
12
|
+
export function createExtensionPack(ctx) {
|
|
13
|
+
const tool = new LocalFileSearchTool(ctx?.config);
|
|
14
|
+
return {
|
|
15
|
+
name: '@framers/agentos-ext-local-file-search',
|
|
16
|
+
version: '0.1.0',
|
|
17
|
+
descriptors: [
|
|
18
|
+
{
|
|
19
|
+
id: 'local_file_search',
|
|
20
|
+
kind: 'tool',
|
|
21
|
+
priority: 50,
|
|
22
|
+
payload: tool,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAA4C;IAC9E,MAAM,IAAI,GAAG,IAAI,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAClD,OAAO;QACL,IAAI,EAAE,wCAAwC;QAC9C,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE;YACX;gBACE,EAAE,EAAE,mBAAmB;gBACvB,IAAI,EAAE,MAAe;gBACrB,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,IAAI;aACd;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Types for the local-file-search extension tool.
|
|
3
|
+
* @module agentos-ext-local-file-search/types
|
|
4
|
+
*/
|
|
5
|
+
/** Configuration for file search scope and behavior. */
|
|
6
|
+
export interface FileSearchConfig {
|
|
7
|
+
/** Directories and glob patterns to exclude from search. */
|
|
8
|
+
denylist: string[];
|
|
9
|
+
/** Maximum number of results to return. */
|
|
10
|
+
maxResults: number;
|
|
11
|
+
/** Maximum directory depth to traverse. */
|
|
12
|
+
maxDepth: number;
|
|
13
|
+
/** Timeout in milliseconds — returns best results found so far. */
|
|
14
|
+
timeoutMs: number;
|
|
15
|
+
}
|
|
16
|
+
/** A single file match result. */
|
|
17
|
+
export interface FileMatch {
|
|
18
|
+
/** Absolute path to the file. */
|
|
19
|
+
path: string;
|
|
20
|
+
/** File name (basename). */
|
|
21
|
+
name: string;
|
|
22
|
+
/** File size in bytes. */
|
|
23
|
+
size: number;
|
|
24
|
+
/** ISO 8601 last modified timestamp. */
|
|
25
|
+
modified: string;
|
|
26
|
+
/** Detected MIME type based on extension. */
|
|
27
|
+
mimeType: string;
|
|
28
|
+
/** Relevance score (higher is better). */
|
|
29
|
+
relevance: number;
|
|
30
|
+
}
|
|
31
|
+
/** Input schema for the local_file_search tool. */
|
|
32
|
+
export interface LocalFileSearchInput {
|
|
33
|
+
/** Filename or partial filename to search for. */
|
|
34
|
+
query: string;
|
|
35
|
+
/** Specific directory to search (overrides full filesystem scan). */
|
|
36
|
+
directory?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Output schema for the local_file_search tool. */
|
|
39
|
+
export interface LocalFileSearchOutput {
|
|
40
|
+
/** Array of matching files sorted by relevance. */
|
|
41
|
+
matches: FileMatch[];
|
|
42
|
+
/** Number of directories scanned. */
|
|
43
|
+
directoriesScanned: number;
|
|
44
|
+
/** Whether the search timed out before completing. */
|
|
45
|
+
timedOut: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Default file search configuration. */
|
|
48
|
+
export declare const DEFAULT_FILE_SEARCH_CONFIG: FileSearchConfig;
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,kCAAkC;AAClC,MAAM,WAAW,SAAS;IACxB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,mDAAmD;AACnD,MAAM,WAAW,oBAAoB;IACnC,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oDAAoD;AACpD,MAAM,WAAW,qBAAqB;IACpC,mDAAmD;IACnD,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,qCAAqC;IACrC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,yCAAyC;AACzC,eAAO,MAAM,0BAA0B,EAAE,gBAUxC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Types for the local-file-search extension tool.
|
|
4
|
+
* @module agentos-ext-local-file-search/types
|
|
5
|
+
*/
|
|
6
|
+
/** Default file search configuration. */
|
|
7
|
+
export const DEFAULT_FILE_SEARCH_CONFIG = {
|
|
8
|
+
denylist: [
|
|
9
|
+
'/proc', '/sys', '/dev',
|
|
10
|
+
'node_modules', '.git', '.env',
|
|
11
|
+
'.ssh', '.gnupg', '.aws',
|
|
12
|
+
'*.key', '*.pem', '*.secret',
|
|
13
|
+
],
|
|
14
|
+
maxResults: 10,
|
|
15
|
+
maxDepth: 10,
|
|
16
|
+
timeoutMs: 10_000,
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;GAGG;AAgDH,yCAAyC;AACzC,MAAM,CAAC,MAAM,0BAA0B,GAAqB;IAC1D,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,EAAE,MAAM;QACvB,cAAc,EAAE,MAAM,EAAE,MAAM;QAC9B,MAAM,EAAE,QAAQ,EAAE,MAAM;QACxB,OAAO,EAAE,OAAO,EAAE,UAAU;KAC7B;IACD,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,MAAM;CAClB,CAAC"}
|
package/manifest.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
|
|
3
|
+
"id": "com.framers.tools.local-file-search",
|
|
4
|
+
"name": "Local File Search",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"description": "Search for files on the local filesystem by fuzzy name matching. Supports denylist filtering and relevance-ranked results.",
|
|
7
|
+
"author": { "name": "Manic Agency LLC", "url": "https://manic.agency" },
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": ["file", "search", "filesystem", "local", "find"],
|
|
10
|
+
"agentosVersion": "^2.0.0",
|
|
11
|
+
"categories": ["tool", "productivity"],
|
|
12
|
+
"platforms": [],
|
|
13
|
+
"sdk": "none",
|
|
14
|
+
"extensions": [
|
|
15
|
+
{
|
|
16
|
+
"kind": "tool",
|
|
17
|
+
"id": "local_file_search",
|
|
18
|
+
"displayName": "Local File Search",
|
|
19
|
+
"description": "Find files on the host filesystem by name",
|
|
20
|
+
"entry": "./dist/LocalFileSearchTool.js"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"requiredSecrets": [],
|
|
24
|
+
"features": ["file-search", "fuzzy-matching"]
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@framers/agentos-ext-local-file-search",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Search for files on the local filesystem by fuzzy name matching",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./manifest.json": "./manifest.json",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@framers/agentos": "^0.5.2"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"agentos",
|
|
21
|
+
"extension",
|
|
22
|
+
"tool",
|
|
23
|
+
"file-search",
|
|
24
|
+
"filesystem"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/framersai/agentos-extensions.git",
|
|
33
|
+
"directory": "registry/curated/tools/local-file-search"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/framersai/agentos-extensions/tree/master/registry/curated/tools/local-file-search#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/framersai/agentos-extensions/issues"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"dev": "tsc --watch",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"clean": "rimraf dist"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Local File Search — find files on the host filesystem by fuzzy name matching.
|
|
4
|
+
*
|
|
5
|
+
* Searches the full filesystem (or a specified directory) with a configurable denylist
|
|
6
|
+
* to exclude sensitive paths. Results are ranked by relevance: exact > startsWith > contains > fuzzy.
|
|
7
|
+
*
|
|
8
|
+
* @module agentos-ext-local-file-search/LocalFileSearchTool
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
12
|
+
import { join, basename, extname } from 'node:path';
|
|
13
|
+
import type {
|
|
14
|
+
FileSearchConfig,
|
|
15
|
+
FileMatch,
|
|
16
|
+
LocalFileSearchInput,
|
|
17
|
+
LocalFileSearchOutput,
|
|
18
|
+
} from './types.js';
|
|
19
|
+
import { DEFAULT_FILE_SEARCH_CONFIG } from './types.js';
|
|
20
|
+
|
|
21
|
+
/** MIME type map for common file extensions. */
|
|
22
|
+
const MIME_MAP: Record<string, string> = {
|
|
23
|
+
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
24
|
+
'.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml',
|
|
25
|
+
'.mp4': 'video/mp4', '.mov': 'video/quicktime', '.webm': 'video/webm',
|
|
26
|
+
'.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg',
|
|
27
|
+
'.pdf': 'application/pdf', '.zip': 'application/zip',
|
|
28
|
+
'.txt': 'text/plain', '.json': 'application/json',
|
|
29
|
+
'.csv': 'text/csv', '.md': 'text/markdown',
|
|
30
|
+
'.doc': 'application/msword',
|
|
31
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
32
|
+
'.xls': 'application/vnd.ms-excel',
|
|
33
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
34
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* ITool implementation for local filesystem search.
|
|
39
|
+
* Walks directories recursively, matches files by name, and ranks by relevance.
|
|
40
|
+
*/
|
|
41
|
+
export class LocalFileSearchTool {
|
|
42
|
+
readonly id = 'local_file_search';
|
|
43
|
+
readonly name = 'local_file_search';
|
|
44
|
+
readonly displayName = 'Local File Search';
|
|
45
|
+
readonly description = 'Search for files on the local filesystem by name. Returns matching files sorted by relevance.';
|
|
46
|
+
readonly parameters = {
|
|
47
|
+
type: 'object' as const,
|
|
48
|
+
properties: {
|
|
49
|
+
query: { type: 'string', description: 'Filename or partial filename to search for' },
|
|
50
|
+
directory: { type: 'string', description: 'Specific directory to search (overrides default scope)' },
|
|
51
|
+
},
|
|
52
|
+
required: ['query'],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
private config: FileSearchConfig;
|
|
56
|
+
|
|
57
|
+
constructor(config?: Partial<FileSearchConfig>) {
|
|
58
|
+
this.config = { ...DEFAULT_FILE_SEARCH_CONFIG, ...config };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Execute the file search. */
|
|
62
|
+
async execute(input: LocalFileSearchInput): Promise<LocalFileSearchOutput> {
|
|
63
|
+
const query = input.query.toLowerCase();
|
|
64
|
+
const rootDir = input.directory ?? '/';
|
|
65
|
+
const matches: FileMatch[] = [];
|
|
66
|
+
let directoriesScanned = 0;
|
|
67
|
+
let timedOut = false;
|
|
68
|
+
const startTime = Date.now();
|
|
69
|
+
|
|
70
|
+
const walk = async (dir: string, depth: number): Promise<void> => {
|
|
71
|
+
if (depth > this.config.maxDepth) return;
|
|
72
|
+
if (Date.now() - startTime > this.config.timeoutMs) { timedOut = true; return; }
|
|
73
|
+
if (this.isDeniedDir(dir)) return;
|
|
74
|
+
|
|
75
|
+
directoriesScanned++;
|
|
76
|
+
let entries;
|
|
77
|
+
try {
|
|
78
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
79
|
+
} catch { return; } // permission denied, etc.
|
|
80
|
+
|
|
81
|
+
for (const entry of entries) {
|
|
82
|
+
if (timedOut) return;
|
|
83
|
+
const fullPath = join(dir, entry.name);
|
|
84
|
+
|
|
85
|
+
if (entry.isDirectory()) {
|
|
86
|
+
if (!this.isDeniedDir(entry.name) && !this.isDeniedDir(fullPath)) {
|
|
87
|
+
await walk(fullPath, depth + 1);
|
|
88
|
+
}
|
|
89
|
+
} else if (entry.isFile()) {
|
|
90
|
+
if (this.isDeniedFile(entry.name)) continue;
|
|
91
|
+
const relevance = this.scoreRelevance(entry.name.toLowerCase(), query);
|
|
92
|
+
if (relevance > 0) {
|
|
93
|
+
try {
|
|
94
|
+
const fileStat = await stat(fullPath);
|
|
95
|
+
matches.push({
|
|
96
|
+
path: fullPath,
|
|
97
|
+
name: entry.name,
|
|
98
|
+
size: fileStat.size,
|
|
99
|
+
modified: fileStat.mtime.toISOString(),
|
|
100
|
+
mimeType: MIME_MAP[extname(entry.name).toLowerCase()] ?? 'application/octet-stream',
|
|
101
|
+
relevance,
|
|
102
|
+
});
|
|
103
|
+
} catch { /* stat failed — skip */ }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
await walk(rootDir, 0);
|
|
110
|
+
|
|
111
|
+
matches.sort((a, b) => b.relevance - a.relevance);
|
|
112
|
+
return {
|
|
113
|
+
matches: matches.slice(0, this.config.maxResults),
|
|
114
|
+
directoriesScanned,
|
|
115
|
+
timedOut,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Score how well a filename matches the query. 0 = no match. */
|
|
120
|
+
private scoreRelevance(filename: string, query: string): number {
|
|
121
|
+
const nameNoExt = filename.replace(/\.[^.]+$/, '');
|
|
122
|
+
if (filename === query) return 1.0; // exact match
|
|
123
|
+
if (nameNoExt === query) return 0.95; // match without extension
|
|
124
|
+
if (filename.startsWith(query)) return 0.8; // starts with
|
|
125
|
+
if (nameNoExt.startsWith(query)) return 0.75;
|
|
126
|
+
if (filename.includes(query)) return 0.6; // contains
|
|
127
|
+
if (nameNoExt.includes(query)) return 0.55;
|
|
128
|
+
// Levenshtein for fuzzy (only if query is close in length)
|
|
129
|
+
if (Math.abs(nameNoExt.length - query.length) <= 3) {
|
|
130
|
+
const dist = this.levenshtein(nameNoExt, query);
|
|
131
|
+
if (dist <= 3) return 0.3 - (dist * 0.08);
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Check if a directory name or path is in the denylist. */
|
|
137
|
+
private isDeniedDir(nameOrPath: string): boolean {
|
|
138
|
+
const base = basename(nameOrPath);
|
|
139
|
+
return this.config.denylist.some(pattern => {
|
|
140
|
+
if (pattern.startsWith('*')) return false; // glob patterns are for files only
|
|
141
|
+
if (pattern.startsWith('/')) return nameOrPath.startsWith(pattern);
|
|
142
|
+
if (pattern.startsWith('.')) return base === pattern;
|
|
143
|
+
return base === pattern;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Check if a filename matches a glob-style denylist pattern (e.g., *.key). */
|
|
148
|
+
private isDeniedFile(filename: string): boolean {
|
|
149
|
+
return this.config.denylist.some(pattern => {
|
|
150
|
+
if (pattern.startsWith('*.')) {
|
|
151
|
+
return filename.endsWith(pattern.slice(1));
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Simple Levenshtein distance for fuzzy matching. */
|
|
158
|
+
private levenshtein(a: string, b: string): number {
|
|
159
|
+
const m = a.length, n = b.length;
|
|
160
|
+
const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
161
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
162
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
163
|
+
for (let i = 1; i <= m; i++) {
|
|
164
|
+
for (let j = 1; j <= n; j++) {
|
|
165
|
+
dp[i][j] = a[i - 1] === b[j - 1]
|
|
166
|
+
? dp[i - 1][j - 1]
|
|
167
|
+
: 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return dp[m][n];
|
|
171
|
+
}
|
|
172
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Extension pack factory for the local-file-search tool.
|
|
4
|
+
* @module agentos-ext-local-file-search
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { LocalFileSearchTool } from './LocalFileSearchTool.js';
|
|
8
|
+
import type { FileSearchConfig } from './types.js';
|
|
9
|
+
|
|
10
|
+
export { LocalFileSearchTool } from './LocalFileSearchTool.js';
|
|
11
|
+
export type { FileSearchConfig, FileMatch, LocalFileSearchInput, LocalFileSearchOutput } from './types.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create the local-file-search extension pack.
|
|
15
|
+
* @param ctx - Extension context with optional configuration.
|
|
16
|
+
*/
|
|
17
|
+
export function createExtensionPack(ctx?: { config?: Partial<FileSearchConfig> }) {
|
|
18
|
+
const tool = new LocalFileSearchTool(ctx?.config);
|
|
19
|
+
return {
|
|
20
|
+
name: '@framers/agentos-ext-local-file-search',
|
|
21
|
+
version: '0.1.0',
|
|
22
|
+
descriptors: [
|
|
23
|
+
{
|
|
24
|
+
id: 'local_file_search',
|
|
25
|
+
kind: 'tool' as const,
|
|
26
|
+
priority: 50,
|
|
27
|
+
payload: tool,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Types for the local-file-search extension tool.
|
|
4
|
+
* @module agentos-ext-local-file-search/types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Configuration for file search scope and behavior. */
|
|
8
|
+
export interface FileSearchConfig {
|
|
9
|
+
/** Directories and glob patterns to exclude from search. */
|
|
10
|
+
denylist: string[];
|
|
11
|
+
/** Maximum number of results to return. */
|
|
12
|
+
maxResults: number;
|
|
13
|
+
/** Maximum directory depth to traverse. */
|
|
14
|
+
maxDepth: number;
|
|
15
|
+
/** Timeout in milliseconds — returns best results found so far. */
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A single file match result. */
|
|
20
|
+
export interface FileMatch {
|
|
21
|
+
/** Absolute path to the file. */
|
|
22
|
+
path: string;
|
|
23
|
+
/** File name (basename). */
|
|
24
|
+
name: string;
|
|
25
|
+
/** File size in bytes. */
|
|
26
|
+
size: number;
|
|
27
|
+
/** ISO 8601 last modified timestamp. */
|
|
28
|
+
modified: string;
|
|
29
|
+
/** Detected MIME type based on extension. */
|
|
30
|
+
mimeType: string;
|
|
31
|
+
/** Relevance score (higher is better). */
|
|
32
|
+
relevance: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Input schema for the local_file_search tool. */
|
|
36
|
+
export interface LocalFileSearchInput {
|
|
37
|
+
/** Filename or partial filename to search for. */
|
|
38
|
+
query: string;
|
|
39
|
+
/** Specific directory to search (overrides full filesystem scan). */
|
|
40
|
+
directory?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Output schema for the local_file_search tool. */
|
|
44
|
+
export interface LocalFileSearchOutput {
|
|
45
|
+
/** Array of matching files sorted by relevance. */
|
|
46
|
+
matches: FileMatch[];
|
|
47
|
+
/** Number of directories scanned. */
|
|
48
|
+
directoriesScanned: number;
|
|
49
|
+
/** Whether the search timed out before completing. */
|
|
50
|
+
timedOut: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Default file search configuration. */
|
|
54
|
+
export const DEFAULT_FILE_SEARCH_CONFIG: FileSearchConfig = {
|
|
55
|
+
denylist: [
|
|
56
|
+
'/proc', '/sys', '/dev',
|
|
57
|
+
'node_modules', '.git', '.env',
|
|
58
|
+
'.ssh', '.gnupg', '.aws',
|
|
59
|
+
'*.key', '*.pem', '*.secret',
|
|
60
|
+
],
|
|
61
|
+
maxResults: 10,
|
|
62
|
+
maxDepth: 10,
|
|
63
|
+
timeoutMs: 10_000,
|
|
64
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
3
|
+
import { mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { LocalFileSearchTool } from '../src/LocalFileSearchTool.js';
|
|
7
|
+
|
|
8
|
+
const TEST_DIR = join(tmpdir(), 'lfs-test-' + Date.now());
|
|
9
|
+
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
mkdirSync(join(TEST_DIR, 'docs'), { recursive: true });
|
|
12
|
+
mkdirSync(join(TEST_DIR, 'pics'), { recursive: true });
|
|
13
|
+
mkdirSync(join(TEST_DIR, 'node_modules', 'pkg'), { recursive: true });
|
|
14
|
+
mkdirSync(join(TEST_DIR, '.ssh'), { recursive: true });
|
|
15
|
+
writeFileSync(join(TEST_DIR, 'docs', 'report.pdf'), 'fake pdf');
|
|
16
|
+
writeFileSync(join(TEST_DIR, 'docs', 'notes.txt'), 'some notes');
|
|
17
|
+
writeFileSync(join(TEST_DIR, 'pics', 'photo.png'), 'fake png');
|
|
18
|
+
writeFileSync(join(TEST_DIR, 'pics', 'sunset.jpg'), 'fake jpg');
|
|
19
|
+
writeFileSync(join(TEST_DIR, 'node_modules', 'pkg', 'index.js'), 'module');
|
|
20
|
+
writeFileSync(join(TEST_DIR, '.ssh', 'id_rsa.key'), 'secret');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterAll(() => {
|
|
24
|
+
rmSync(TEST_DIR, { recursive: true, force: true });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('LocalFileSearchTool', () => {
|
|
28
|
+
const tool = new LocalFileSearchTool({
|
|
29
|
+
denylist: ['node_modules', '.ssh', '*.key'],
|
|
30
|
+
maxResults: 10,
|
|
31
|
+
maxDepth: 5,
|
|
32
|
+
timeoutMs: 5000,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('finds files by exact name', async () => {
|
|
36
|
+
const result = await tool.execute({ query: 'report.pdf', directory: TEST_DIR });
|
|
37
|
+
expect(result.matches.length).toBeGreaterThanOrEqual(1);
|
|
38
|
+
expect(result.matches[0].name).toBe('report.pdf');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('finds files by partial name', async () => {
|
|
42
|
+
const result = await tool.execute({ query: 'photo', directory: TEST_DIR });
|
|
43
|
+
expect(result.matches.some(m => m.name === 'photo.png')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('respects denylist — skips node_modules', async () => {
|
|
47
|
+
const result = await tool.execute({ query: 'index.js', directory: TEST_DIR });
|
|
48
|
+
expect(result.matches.length).toBe(0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('respects denylist — skips .ssh', async () => {
|
|
52
|
+
const result = await tool.execute({ query: 'id_rsa', directory: TEST_DIR });
|
|
53
|
+
expect(result.matches.length).toBe(0);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('respects glob denylist — skips *.key files', async () => {
|
|
57
|
+
const result = await tool.execute({ query: 'id_rsa.key', directory: TEST_DIR });
|
|
58
|
+
expect(result.matches.length).toBe(0);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('ranks exact matches higher than partial', async () => {
|
|
62
|
+
const result = await tool.execute({ query: 'notes.txt', directory: TEST_DIR });
|
|
63
|
+
expect(result.matches[0].name).toBe('notes.txt');
|
|
64
|
+
expect(result.matches[0].relevance).toBeGreaterThan(0.8);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns size and mimeType', async () => {
|
|
68
|
+
const result = await tool.execute({ query: 'photo.png', directory: TEST_DIR });
|
|
69
|
+
expect(result.matches[0].size).toBeGreaterThan(0);
|
|
70
|
+
expect(result.matches[0].mimeType).toBe('image/png');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('limits results to maxResults', async () => {
|
|
74
|
+
const smallTool = new LocalFileSearchTool({
|
|
75
|
+
denylist: ['node_modules', '.ssh', '*.key'],
|
|
76
|
+
maxResults: 1,
|
|
77
|
+
maxDepth: 5,
|
|
78
|
+
timeoutMs: 5000,
|
|
79
|
+
});
|
|
80
|
+
const result = await smallTool.execute({ query: '.', directory: TEST_DIR });
|
|
81
|
+
expect(result.matches.length).toBeLessThanOrEqual(1);
|
|
82
|
+
});
|
|
83
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"],
|
|
16
|
+
"exclude": ["dist", "test", "node_modules"]
|
|
17
|
+
}
|