@hardlydifficult/agent-tools 1.0.0 → 1.0.2
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/README.md +136 -0
- package/package.json +9 -1
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @hardlydifficult/agent-tools
|
|
2
|
+
|
|
3
|
+
A utility package providing configuration-driven limits, path parsing for GitHub-style file references, and error-handling helpers for safe, predictable agent tool execution.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @hardlydifficult/agent-tools
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
parsePath,
|
|
16
|
+
MAX_READ_BYTES,
|
|
17
|
+
executeWithErrorHandling,
|
|
18
|
+
toArray,
|
|
19
|
+
} from "@hardlydifficult/agent-tools";
|
|
20
|
+
|
|
21
|
+
// Parse a GitHub-style path with line range
|
|
22
|
+
const result = parsePath("src/index.ts#L10-L20");
|
|
23
|
+
// { filePath: "src/index.ts", startLine: 10, endLine: 20 }
|
|
24
|
+
|
|
25
|
+
// Normalize inputs to arrays
|
|
26
|
+
const items = toArray("single"); // ["single"]
|
|
27
|
+
const itemsArray = toArray(["a", "b"]); // ["a", "b"]
|
|
28
|
+
|
|
29
|
+
// Safely handle async operations with error messages
|
|
30
|
+
const safeRead = await executeWithErrorHandling(
|
|
31
|
+
() => Promise.resolve("data"),
|
|
32
|
+
"read_file failed"
|
|
33
|
+
);
|
|
34
|
+
// "data"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Path Parsing
|
|
38
|
+
|
|
39
|
+
Parses GitHub-style file paths with optional line ranges into structured objects.
|
|
40
|
+
|
|
41
|
+
### `parsePath(path: string): ParsedPath`
|
|
42
|
+
|
|
43
|
+
Parses paths like `file.ts`, `file.ts#L10`, or `file.ts#L10-L20`.
|
|
44
|
+
|
|
45
|
+
**Parameters:**
|
|
46
|
+
|
|
47
|
+
| Name | Type | Description |
|
|
48
|
+
|------|------|-------------|
|
|
49
|
+
| `path` | `string` | GitHub-style file path with optional `#L...` line range |
|
|
50
|
+
|
|
51
|
+
**Returns:**
|
|
52
|
+
|
|
53
|
+
| Name | Type | Description |
|
|
54
|
+
|------|------|-------------|
|
|
55
|
+
| `filePath` | `string` | The path to the file |
|
|
56
|
+
| `startLine?` | `number` | Starting line (1-indexed) |
|
|
57
|
+
| `endLine?` | `number` | Ending line (inclusive) |
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { parsePath } from "@hardlydifficult/agent-tools";
|
|
61
|
+
|
|
62
|
+
parsePath("src/index.ts"); // { filePath: "src/index.ts" }
|
|
63
|
+
parsePath("src/index.ts#L5"); // { filePath: "src/index.ts", startLine: 5, endLine: 5 }
|
|
64
|
+
parsePath("src/index.ts#L5-L15"); // { filePath: "src/index.ts", startLine: 5, endLine: 15 }
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration Constants
|
|
68
|
+
|
|
69
|
+
Configuration values used to enforce safe limits in agent tool operations.
|
|
70
|
+
|
|
71
|
+
| Constant | Type | Default | Description |
|
|
72
|
+
|----------|------|---------|-------------|
|
|
73
|
+
| `MAX_READ_BYTES` | `number` | `100_000` | Max bytes to return from read operations before truncation |
|
|
74
|
+
| `MAX_GREP_FILE_SIZE` | `number` | `102_400` | Max file size (bytes) to scan during content search |
|
|
75
|
+
| `MAX_SEARCH_RESULTS` | `number` | `100` | Max total matches returned by search operations |
|
|
76
|
+
| `MAX_CONTEXT_LINES` | `number` | `3` | Lines of context to show around each edit in write output |
|
|
77
|
+
| `VERIFY_TIMEOUT` | `number` | `120_000` | Timeout (ms) for verify tool commands |
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import {
|
|
81
|
+
MAX_READ_BYTES,
|
|
82
|
+
MAX_GREP_FILE_SIZE,
|
|
83
|
+
} from "@hardlydifficult/agent-tools";
|
|
84
|
+
|
|
85
|
+
// Max readable file size
|
|
86
|
+
console.log(MAX_READ_BYTES); // 100000
|
|
87
|
+
|
|
88
|
+
// Skip scanning files larger than this
|
|
89
|
+
console.log(MAX_GREP_FILE_SIZE); // 102400
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Utility Helpers
|
|
93
|
+
|
|
94
|
+
Support functions for input normalization, error handling, and result formatting.
|
|
95
|
+
|
|
96
|
+
### `toArray<T>(input: T | T[]): T[]`
|
|
97
|
+
|
|
98
|
+
Normalizes a value (single item or array) into an array.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { toArray } from "@hardlydifficult/agent-tools";
|
|
102
|
+
|
|
103
|
+
toArray("single"); // ["single"]
|
|
104
|
+
toArray(["a", "b"]); // ["a", "b"]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `executeWithErrorHandling<T>(operation: () => Promise<T>, errorPrefix: string): Promise<T \| string>`
|
|
108
|
+
|
|
109
|
+
Wraps async operations in try-catch and returns either the result or an error string.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { executeWithErrorHandling } from "@hardlydifficult/agent-tools";
|
|
113
|
+
|
|
114
|
+
const result = await executeWithErrorHandling(
|
|
115
|
+
() => Promise.resolve("success"),
|
|
116
|
+
"Operation failed"
|
|
117
|
+
);
|
|
118
|
+
// "success"
|
|
119
|
+
|
|
120
|
+
const errorResult = await executeWithErrorHandling(
|
|
121
|
+
() => Promise.reject(new Error("Boom")),
|
|
122
|
+
"Operation failed"
|
|
123
|
+
);
|
|
124
|
+
// "Operation failed: Boom"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### `formatArrayResult(items: string[], emptyMessage: string): string`
|
|
128
|
+
|
|
129
|
+
Formats array results: joins items with newlines or returns a custom message if empty.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { formatArrayResult } from "@hardlydifficult/agent-tools";
|
|
133
|
+
|
|
134
|
+
formatArrayResult(["a", "b"], "No items"); // "a\nb"
|
|
135
|
+
formatArrayResult([], "No items"); // "No items"
|
|
136
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardlydifficult/agent-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,5 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
29
|
}
|