@agent-api/sdk 1.1.5 → 1.2.1
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/CHANGELOG.md +13 -6
- package/README.md +21 -17
- package/dist/local/context.d.ts +4 -4
- package/dist/local/context.js +10 -10
- package/dist/local/core.d.ts +30 -30
- package/dist/local/core.js +12 -12
- package/dist/local/index.d.ts +1 -0
- package/dist/local/index.js +1 -0
- package/dist/local/shell.d.ts +82 -0
- package/dist/local/shell.js +318 -0
- package/dist/local/tools.d.ts +17 -17
- package/dist/local/tools.js +46 -46
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist-cjs/local/context.js +10 -10
- package/dist-cjs/local/core.js +15 -15
- package/dist-cjs/local/index.js +1 -0
- package/dist-cjs/local/shell.js +329 -0
- package/dist-cjs/local/tools.js +51 -51
- package/dist-cjs/node.js +11 -6
- package/dist-cjs/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Changelog — @agent-api/sdk
|
|
2
2
|
|
|
3
|
-
## 1.1
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added a model-facing `local_shell` tool primitive with approval/full-access modes, bounded host command execution, timeout handling, execution-environment context, and a pluggable command-runner boundary for future isolation backends.
|
|
8
|
+
|
|
9
|
+
## 1.2.0
|
|
4
10
|
|
|
5
11
|
### Added
|
|
6
12
|
|
|
@@ -9,18 +15,19 @@
|
|
|
9
15
|
|
|
10
16
|
### Changed
|
|
11
17
|
|
|
18
|
+
- Renamed local SDK concepts from workspace to workdir to avoid confusion with platform identity workspaces.
|
|
12
19
|
- Extended response input types so tool-call continuations can carry function-call metadata consistently.
|
|
13
20
|
|
|
14
21
|
## 1.1.2
|
|
15
22
|
|
|
16
23
|
### Added
|
|
17
24
|
|
|
18
|
-
- Added a model-facing `
|
|
19
|
-
- Added approval-aware dispatch for mutating local
|
|
25
|
+
- Added a model-facing `local_workdir` driver/tool primitive for local workdir operations.
|
|
26
|
+
- Added approval-aware dispatch for mutating local workdir actions.
|
|
20
27
|
|
|
21
28
|
### Changed
|
|
22
29
|
|
|
23
|
-
- Replaced fragmented local
|
|
30
|
+
- Replaced fragmented local workdir tool presentation with an action-based adapter over the low-level local APIs.
|
|
24
31
|
|
|
25
32
|
## 1.1.1
|
|
26
33
|
|
|
@@ -38,9 +45,9 @@
|
|
|
38
45
|
- Cross-platform app directory resolution for data, config, cache, logs, and temp files.
|
|
39
46
|
- Root-scoped local file stores with path traversal protection, atomic writes, JSON helpers, recursive listing, and local skill discovery.
|
|
40
47
|
- Local workdir operations for entry search, file delivery, line-range reads and edits, literal grep, and directory summaries.
|
|
41
|
-
- `
|
|
48
|
+
- `LocalWorkdir` and `LocalWorkdirManager` for project roots, default ignore rules, patch previews, snapshots, diffs, and file-watch handles.
|
|
42
49
|
- Typed local errors, `.gitignore` loading, sensitivity classification for likely secret paths, and multi-file line-edit plans with conflict detection and rollback.
|
|
43
|
-
- `createLocalContextPackage()` for bounded, secret-aware local
|
|
50
|
+
- `createLocalContextPackage()` for bounded, secret-aware local workdir manifests that app integrations can hand to agent workflows.
|
|
44
51
|
|
|
45
52
|
### Changed
|
|
46
53
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Production JavaScript/TypeScript SDK for the Managed Agent API.
|
|
4
4
|
|
|
5
|
-
**Published on npm:** [`@agent-api/sdk`](https://www.npmjs.com/package/@agent-api/sdk) (v1.1
|
|
5
|
+
**Published on npm:** [`@agent-api/sdk`](https://www.npmjs.com/package/@agent-api/sdk) (v1.2.1)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -44,7 +44,7 @@ Public package entrypoints:
|
|
|
44
44
|
|
|
45
45
|
- `@agent-api/sdk`: browser-safe REST client, public types, auth, responses, models, presets, tools, volumes, and skills HTTP APIs.
|
|
46
46
|
- `@agent-api/sdk/browser`: explicit alias of the browser-safe REST client entry.
|
|
47
|
-
- `@agent-api/sdk/local`: Node-only local runtime,
|
|
47
|
+
- `@agent-api/sdk/local`: Node-only local runtime, workdir, context, local workdir tools, and local shell tools.
|
|
48
48
|
- `@agent-api/sdk/node`: Node aggregate entry for local helpers such as `localSkillFromDirectory()` plus `NodeAgentAPI`.
|
|
49
49
|
|
|
50
50
|
```
|
|
@@ -114,7 +114,7 @@ const binary = await client.volumes.readFile(volume.volume_id, "assets/logo.png"
|
|
|
114
114
|
|
|
115
115
|
const response = await client.agent.create({
|
|
116
116
|
preset: "pro-search",
|
|
117
|
-
input: "Use the attached
|
|
117
|
+
input: "Use the attached agent volume.",
|
|
118
118
|
volume_id: volume.volume_id,
|
|
119
119
|
});
|
|
120
120
|
```
|
|
@@ -125,14 +125,15 @@ const response = await client.agent.create({
|
|
|
125
125
|
|
|
126
126
|
```typescript
|
|
127
127
|
import { resolvePresetTools } from "@agent-api/sdk";
|
|
128
|
-
import {
|
|
128
|
+
import { createLocalShellToolRegistry, createLocalWorkdirToolRegistry, LocalWorkdir } from "@agent-api/sdk/local";
|
|
129
129
|
|
|
130
|
-
const
|
|
131
|
-
const
|
|
130
|
+
const workdir = new LocalWorkdir("/path/to/project", { trusted: true });
|
|
131
|
+
const workdirRegistry = createLocalWorkdirToolRegistry(workdir);
|
|
132
|
+
const shellRegistry = createLocalShellToolRegistry({ workdir });
|
|
132
133
|
|
|
133
134
|
const { tools } = await resolvePresetTools(client, {
|
|
134
135
|
preset: "pro-search",
|
|
135
|
-
tools:
|
|
136
|
+
tools: [...workdirRegistry.definitions(), ...shellRegistry.definitions()],
|
|
136
137
|
});
|
|
137
138
|
|
|
138
139
|
const response = await client.agent.create({
|
|
@@ -188,32 +189,35 @@ The runtime provides:
|
|
|
188
189
|
- Root-scoped file stores with path traversal protection.
|
|
189
190
|
- Atomic text/JSON writes, byte reads/writes, recursive listing, copy, remove, and stat helpers.
|
|
190
191
|
- Local workdir operations inspired by platform volumes: `listEntries`, `searchEntries`, `readFile`, `writeFile`, `deletePath`, `createDirectory`, `readLines`, `patchLines`, `grep`, and `summarize`.
|
|
191
|
-
- First-class local
|
|
192
|
+
- First-class local workdirs with default ignore rules, scoped workbench operations, patch previews, snapshots, diffs, file-watch handles, and budgeted context packaging.
|
|
193
|
+
- Model-facing local tools for workdir operations (`local_workdir`) and command execution (`local_shell`) with approval/full-access dispatch conventions.
|
|
192
194
|
- Typed local errors, `.gitignore` loading, sensitivity classification, and multi-file edit plans with rollback on failure.
|
|
193
195
|
- JSON config helpers for typed app settings.
|
|
194
196
|
- Local skill discovery built on `localSkillFromDirectory()`.
|
|
195
197
|
|
|
196
198
|
Keep UI and OS interaction policy in your host framework. Electron, Tauri, Qt, or native apps should call this layer from their trusted local process and expose only the capabilities their UI needs.
|
|
197
199
|
|
|
200
|
+
`local_shell` executes commands through a pluggable command runner. The default `HostLocalShellRunner` runs on the user's local machine, bounds captured output, enforces a timeout, and confines relative `workdir` overrides under the configured cwd. It is not a security sandbox; use approval mode unless your application intentionally grants full local command access.
|
|
201
|
+
|
|
198
202
|
```typescript
|
|
199
|
-
const
|
|
203
|
+
const workdir = local.data.child("workdirs/demo");
|
|
200
204
|
|
|
201
|
-
await
|
|
205
|
+
await workdir.writeText("src/index.ts", "console.log('hello');\n");
|
|
202
206
|
|
|
203
|
-
const matches = await
|
|
204
|
-
const lines = await
|
|
205
|
-
await
|
|
207
|
+
const matches = await workdir.grep({ pattern: "hello", path: "src" });
|
|
208
|
+
const lines = await workdir.readLines("src/index.ts", { startLine: 1, endLine: 20 });
|
|
209
|
+
await workdir.patchLines("src/index.ts", {
|
|
206
210
|
startLine: 1,
|
|
207
211
|
replacement: "console.log('patched');",
|
|
208
212
|
});
|
|
209
213
|
|
|
210
|
-
const summary = await
|
|
214
|
+
const summary = await workdir.summarize();
|
|
211
215
|
```
|
|
212
216
|
|
|
213
|
-
For project/
|
|
217
|
+
For project/workdir roots, prefer `local.workdir()` so SDK defaults protect common generated directories such as `.git`, `node_modules`, `dist`, and build caches.
|
|
214
218
|
|
|
215
219
|
```typescript
|
|
216
|
-
const project = local.
|
|
220
|
+
const project = local.workdir("/path/to/project", {
|
|
217
221
|
name: "my-project",
|
|
218
222
|
trusted: true,
|
|
219
223
|
ignore: ["vendor", /^tmp\//],
|
|
@@ -236,7 +240,7 @@ const diff = project.diff(before, after);
|
|
|
236
240
|
const sensitivity = project.classifyPath(".env");
|
|
237
241
|
```
|
|
238
242
|
|
|
239
|
-
Use `createLocalContextPackage()` when a local app needs to prepare bounded
|
|
243
|
+
Use `createLocalContextPackage()` when a local app needs to prepare bounded workdir context for an agent request. The package includes a manifest, selected file previews, optional search matches, hashes, sensitivity labels, and secret-aware omission by default.
|
|
240
244
|
|
|
241
245
|
```typescript
|
|
242
246
|
import { createLocalContextPackage } from "@agent-api/sdk/local";
|
package/dist/local/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LocalFileDeliver, type LocalGrepResponse, type LocalPathSensitivity, type LocalPathSensitivityInfo, type LocalSummary, type
|
|
1
|
+
import { type LocalFileDeliver, type LocalGrepResponse, type LocalPathSensitivity, type LocalPathSensitivityInfo, type LocalSummary, type LocalWorkdir, type LocalWorkdirSnapshotFile } from "./core.js";
|
|
2
2
|
export interface LocalContextPackageParams {
|
|
3
3
|
path?: string;
|
|
4
4
|
include?: string[];
|
|
@@ -30,7 +30,7 @@ export interface LocalContextFile {
|
|
|
30
30
|
export interface LocalContextManifest {
|
|
31
31
|
object: "local_context_manifest";
|
|
32
32
|
root: string;
|
|
33
|
-
|
|
33
|
+
workdir_name: string;
|
|
34
34
|
generated_at_unix: number;
|
|
35
35
|
base_path: string;
|
|
36
36
|
file_count: number;
|
|
@@ -41,9 +41,9 @@ export interface LocalContextManifest {
|
|
|
41
41
|
summary?: LocalSummary;
|
|
42
42
|
search?: LocalGrepResponse;
|
|
43
43
|
}
|
|
44
|
-
export declare function createLocalContextPackage(
|
|
44
|
+
export declare function createLocalContextPackage(workdir: LocalWorkdir, params?: LocalContextPackageParams): Promise<LocalContextManifest>;
|
|
45
45
|
export declare function summarizeLocalContextSensitivity(files: Array<Pick<LocalContextFile, "path" | "sensitivity" | "sensitivity_reason">>): {
|
|
46
46
|
highest: LocalPathSensitivity;
|
|
47
47
|
files: LocalPathSensitivityInfo[];
|
|
48
48
|
};
|
|
49
|
-
export type LocalContextSnapshotFile =
|
|
49
|
+
export type LocalContextSnapshotFile = LocalWorkdirSnapshotFile;
|
package/dist/local/context.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { classifyLocalPathSensitivity, } from "./core.js";
|
|
4
|
-
export async function createLocalContextPackage(
|
|
4
|
+
export async function createLocalContextPackage(workdir, params = {}) {
|
|
5
5
|
const basePath = params.path ?? ".";
|
|
6
6
|
const maxFiles = positiveInt(params.maxFiles, 80);
|
|
7
7
|
const maxBytes = positiveInt(params.maxBytes, 256 * 1024);
|
|
@@ -12,7 +12,7 @@ export async function createLocalContextPackage(workspace, params = {}) {
|
|
|
12
12
|
const includeSummary = params.includeSummary ?? true;
|
|
13
13
|
const includeSearch = Boolean(params.includeSearch && params.query?.trim());
|
|
14
14
|
const includeSecrets = params.includeSecrets ?? false;
|
|
15
|
-
const stats = await
|
|
15
|
+
const stats = await workdir.list(basePath, { recursive: true });
|
|
16
16
|
const fileStats = stats
|
|
17
17
|
.filter((item) => item.type === "file")
|
|
18
18
|
.filter((item) => matchesPathFilters(item.path, params.include, params.exclude))
|
|
@@ -49,7 +49,7 @@ export async function createLocalContextPackage(workspace, params = {}) {
|
|
|
49
49
|
truncated = true;
|
|
50
50
|
continue;
|
|
51
51
|
}
|
|
52
|
-
const delivered = await
|
|
52
|
+
const delivered = await workdir.readFile(item.path, { maxBytes: readBudget });
|
|
53
53
|
includedBytes += delivered.encoding === "text"
|
|
54
54
|
? Buffer.byteLength(delivered.content ?? "", "utf8")
|
|
55
55
|
: Buffer.byteLength(delivered.content_base64 ?? "", "base64");
|
|
@@ -64,7 +64,7 @@ export async function createLocalContextPackage(workspace, params = {}) {
|
|
|
64
64
|
packaged.content_base64 = delivered.content_base64;
|
|
65
65
|
}
|
|
66
66
|
if (includeHashes) {
|
|
67
|
-
packaged.sha256 = await sha256File(
|
|
67
|
+
packaged.sha256 = await sha256File(workdir, item.path);
|
|
68
68
|
}
|
|
69
69
|
if (delivered.truncated) {
|
|
70
70
|
truncated = true;
|
|
@@ -72,7 +72,7 @@ export async function createLocalContextPackage(workspace, params = {}) {
|
|
|
72
72
|
files.push(packaged);
|
|
73
73
|
}
|
|
74
74
|
const summary = includeSummary
|
|
75
|
-
? await
|
|
75
|
+
? await workdir.summarize({
|
|
76
76
|
path: basePath,
|
|
77
77
|
maxFiles,
|
|
78
78
|
previewBytes,
|
|
@@ -80,7 +80,7 @@ export async function createLocalContextPackage(workspace, params = {}) {
|
|
|
80
80
|
})
|
|
81
81
|
: undefined;
|
|
82
82
|
const search = includeSearch
|
|
83
|
-
? await
|
|
83
|
+
? await workdir.grep({
|
|
84
84
|
pattern: params.query,
|
|
85
85
|
path: basePath,
|
|
86
86
|
limit: maxFiles,
|
|
@@ -90,8 +90,8 @@ export async function createLocalContextPackage(workspace, params = {}) {
|
|
|
90
90
|
: undefined;
|
|
91
91
|
return {
|
|
92
92
|
object: "local_context_manifest",
|
|
93
|
-
root:
|
|
94
|
-
|
|
93
|
+
root: workdir.root,
|
|
94
|
+
workdir_name: workdir.name,
|
|
95
95
|
generated_at_unix: Math.floor(Date.now() / 1000),
|
|
96
96
|
base_path: basePath,
|
|
97
97
|
file_count: fileStats.length,
|
|
@@ -148,7 +148,7 @@ function positiveInt(value, fallback) {
|
|
|
148
148
|
const parsed = Number(value);
|
|
149
149
|
return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : fallback;
|
|
150
150
|
}
|
|
151
|
-
async function sha256File(
|
|
152
|
-
const fullPath =
|
|
151
|
+
async function sha256File(workdir, relativePath) {
|
|
152
|
+
const fullPath = workdir.files.resolvePath(relativePath);
|
|
153
153
|
return createHash("sha256").update(await readFile(fullPath)).digest("hex");
|
|
154
154
|
}
|
package/dist/local/core.d.ts
CHANGED
|
@@ -174,7 +174,7 @@ export interface LocalSummary {
|
|
|
174
174
|
generated_at_unix: number;
|
|
175
175
|
scan_truncated: boolean;
|
|
176
176
|
}
|
|
177
|
-
export interface
|
|
177
|
+
export interface LocalWorkdirOptions {
|
|
178
178
|
name?: string;
|
|
179
179
|
metadata?: Record<string, unknown>;
|
|
180
180
|
trusted?: boolean;
|
|
@@ -182,31 +182,31 @@ export interface LocalWorkspaceOptions {
|
|
|
182
182
|
gitignore?: boolean;
|
|
183
183
|
maxFileBytes?: number;
|
|
184
184
|
}
|
|
185
|
-
export interface
|
|
185
|
+
export interface LocalWorkdirSnapshotParams {
|
|
186
186
|
path?: string;
|
|
187
187
|
hash?: boolean;
|
|
188
188
|
maxBytesPerFile?: number;
|
|
189
189
|
}
|
|
190
|
-
export interface
|
|
190
|
+
export interface LocalWorkdirSnapshotFile {
|
|
191
191
|
path: string;
|
|
192
192
|
size: number;
|
|
193
193
|
modified_at_unix?: number;
|
|
194
194
|
sha256?: string;
|
|
195
195
|
}
|
|
196
|
-
export interface
|
|
196
|
+
export interface LocalWorkdirSnapshot {
|
|
197
197
|
root: string;
|
|
198
198
|
name: string;
|
|
199
199
|
generated_at_unix: number;
|
|
200
|
-
files:
|
|
200
|
+
files: LocalWorkdirSnapshotFile[];
|
|
201
201
|
}
|
|
202
|
-
export interface
|
|
203
|
-
added:
|
|
202
|
+
export interface LocalWorkdirDiff {
|
|
203
|
+
added: LocalWorkdirSnapshotFile[];
|
|
204
204
|
modified: Array<{
|
|
205
|
-
before:
|
|
206
|
-
after:
|
|
205
|
+
before: LocalWorkdirSnapshotFile;
|
|
206
|
+
after: LocalWorkdirSnapshotFile;
|
|
207
207
|
}>;
|
|
208
|
-
deleted:
|
|
209
|
-
unchanged:
|
|
208
|
+
deleted: LocalWorkdirSnapshotFile[];
|
|
209
|
+
unchanged: LocalWorkdirSnapshotFile[];
|
|
210
210
|
}
|
|
211
211
|
export interface LocalLinePatchPreview {
|
|
212
212
|
path: string;
|
|
@@ -216,18 +216,18 @@ export interface LocalLinePatchPreview {
|
|
|
216
216
|
before: string[];
|
|
217
217
|
after: string[];
|
|
218
218
|
}
|
|
219
|
-
export interface
|
|
219
|
+
export interface LocalWorkdirLineEdit {
|
|
220
220
|
path: string;
|
|
221
221
|
startLine: number;
|
|
222
222
|
endLine?: number;
|
|
223
223
|
replacement?: string;
|
|
224
224
|
expectedSha256?: string;
|
|
225
225
|
}
|
|
226
|
-
export interface
|
|
227
|
-
edits:
|
|
226
|
+
export interface LocalWorkdirEditPlan {
|
|
227
|
+
edits: LocalWorkdirLineEdit[];
|
|
228
228
|
previews: LocalLinePatchPreview[];
|
|
229
229
|
}
|
|
230
|
-
export interface
|
|
230
|
+
export interface LocalWorkdirEditResult {
|
|
231
231
|
applied: LocalFileLinesPatch[];
|
|
232
232
|
backups: Array<{
|
|
233
233
|
path: string;
|
|
@@ -240,11 +240,11 @@ export interface LocalPathSensitivityInfo {
|
|
|
240
240
|
sensitivity: LocalPathSensitivity;
|
|
241
241
|
reason?: string;
|
|
242
242
|
}
|
|
243
|
-
export interface
|
|
243
|
+
export interface LocalWorkdirWatchEvent {
|
|
244
244
|
type: "change" | "rename";
|
|
245
245
|
path: string;
|
|
246
246
|
}
|
|
247
|
-
export interface
|
|
247
|
+
export interface LocalWorkdirWatcher {
|
|
248
248
|
close(): void;
|
|
249
249
|
}
|
|
250
250
|
export interface LocalSkillDiscoveryOptions extends LocalSkillDirectoryOptions {
|
|
@@ -262,8 +262,8 @@ export interface LocalRuntime {
|
|
|
262
262
|
temp: LocalFileStore;
|
|
263
263
|
config: LocalConfigStore;
|
|
264
264
|
skills: LocalSkillStore;
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
workdirs: LocalWorkdirManager;
|
|
266
|
+
workdir(root: string, options?: LocalWorkdirOptions): LocalWorkdir;
|
|
267
267
|
ensure(): Promise<void>;
|
|
268
268
|
}
|
|
269
269
|
export declare function createLocalRuntime(options: LocalRuntimeOptions): LocalRuntime;
|
|
@@ -322,10 +322,10 @@ export declare class LocalConfigStore {
|
|
|
322
322
|
delete(name: string, key: string): Promise<string>;
|
|
323
323
|
private readRecord;
|
|
324
324
|
}
|
|
325
|
-
export declare class
|
|
326
|
-
open(root: string, options?:
|
|
325
|
+
export declare class LocalWorkdirManager {
|
|
326
|
+
open(root: string, options?: LocalWorkdirOptions): LocalWorkdir;
|
|
327
327
|
}
|
|
328
|
-
export declare class
|
|
328
|
+
export declare class LocalWorkdir {
|
|
329
329
|
readonly root: string;
|
|
330
330
|
readonly name: string;
|
|
331
331
|
readonly metadata: Record<string, unknown>;
|
|
@@ -334,10 +334,10 @@ export declare class LocalWorkspace {
|
|
|
334
334
|
readonly ignore: LocalIgnoreRule[];
|
|
335
335
|
readonly gitignore: boolean;
|
|
336
336
|
readonly maxFileBytes: number;
|
|
337
|
-
constructor(root: string, options?:
|
|
337
|
+
constructor(root: string, options?: LocalWorkdirOptions);
|
|
338
338
|
ensure(): Promise<void>;
|
|
339
339
|
loadIgnoreFiles(files?: string[]): Promise<LocalIgnoreRule[]>;
|
|
340
|
-
child(relativePath: string, options?:
|
|
340
|
+
child(relativePath: string, options?: LocalWorkdirOptions): LocalWorkdir;
|
|
341
341
|
resolvePath(relativePath?: string): string;
|
|
342
342
|
list(relativePath?: string, options?: LocalListOptions): Promise<LocalFileStat[]>;
|
|
343
343
|
listEntries(relativePath?: string, options?: LocalListOptions): Promise<LocalEntryList>;
|
|
@@ -358,16 +358,16 @@ export declare class LocalWorkspace {
|
|
|
358
358
|
readLines(relativePath: string, params: LocalReadLinesParams): Promise<LocalFileLines>;
|
|
359
359
|
previewPatchLines(relativePath: string, params: LocalPatchLinesParams): Promise<LocalLinePatchPreview>;
|
|
360
360
|
patchLines(relativePath: string, params: LocalPatchLinesParams): Promise<LocalFileLinesPatch>;
|
|
361
|
-
previewEdits(edits:
|
|
362
|
-
applyEdits(edits:
|
|
361
|
+
previewEdits(edits: LocalWorkdirLineEdit[]): Promise<LocalWorkdirEditPlan>;
|
|
362
|
+
applyEdits(edits: LocalWorkdirLineEdit[]): Promise<LocalWorkdirEditResult>;
|
|
363
363
|
classifyPath(relativePath: string): LocalPathSensitivityInfo;
|
|
364
364
|
grep(params: LocalGrepParams): Promise<LocalGrepResponse>;
|
|
365
365
|
summarize(params?: LocalSummarizeParams): Promise<LocalSummary>;
|
|
366
|
-
snapshot(params?:
|
|
367
|
-
diff(before:
|
|
368
|
-
watch(onEvent: (event:
|
|
366
|
+
snapshot(params?: LocalWorkdirSnapshotParams): Promise<LocalWorkdirSnapshot>;
|
|
367
|
+
diff(before: LocalWorkdirSnapshot, after: LocalWorkdirSnapshot): LocalWorkdirDiff;
|
|
368
|
+
watch(onEvent: (event: LocalWorkdirWatchEvent) => void, options?: {
|
|
369
369
|
recursive?: boolean;
|
|
370
|
-
}):
|
|
370
|
+
}): LocalWorkdirWatcher;
|
|
371
371
|
private scopedListOptions;
|
|
372
372
|
private mergeIgnore;
|
|
373
373
|
private assertAllowed;
|
package/dist/local/core.js
CHANGED
|
@@ -22,7 +22,7 @@ export class LocalPathError extends LocalError {
|
|
|
22
22
|
}
|
|
23
23
|
export class LocalIgnoredPathError extends LocalError {
|
|
24
24
|
constructor(path) {
|
|
25
|
-
super("local_ignored_path", `local
|
|
25
|
+
super("local_ignored_path", `local workdir path is ignored: ${path}`, { path });
|
|
26
26
|
this.name = "LocalIgnoredPathError";
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -62,9 +62,9 @@ export function createLocalRuntime(options) {
|
|
|
62
62
|
temp,
|
|
63
63
|
config: new LocalConfigStore(configFiles),
|
|
64
64
|
skills: new LocalSkillStore(data.child("skills")),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return new
|
|
65
|
+
workdirs: new LocalWorkdirManager(),
|
|
66
|
+
workdir(root, workdirOptions = {}) {
|
|
67
|
+
return new LocalWorkdir(root, workdirOptions);
|
|
68
68
|
},
|
|
69
69
|
async ensure() {
|
|
70
70
|
await Promise.all([data.ensure(), cache.ensure(), logs.ensure(), temp.ensure(), configFiles.ensure()]);
|
|
@@ -456,12 +456,12 @@ export class LocalConfigStore {
|
|
|
456
456
|
return value;
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
|
-
export class
|
|
459
|
+
export class LocalWorkdirManager {
|
|
460
460
|
open(root, options = {}) {
|
|
461
|
-
return new
|
|
461
|
+
return new LocalWorkdir(root, options);
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
export class
|
|
464
|
+
export class LocalWorkdir {
|
|
465
465
|
root;
|
|
466
466
|
name;
|
|
467
467
|
metadata;
|
|
@@ -472,11 +472,11 @@ export class LocalWorkspace {
|
|
|
472
472
|
maxFileBytes;
|
|
473
473
|
constructor(root, options = {}) {
|
|
474
474
|
this.root = path.resolve(root);
|
|
475
|
-
this.name = options.name?.trim() || path.basename(this.root) || "
|
|
475
|
+
this.name = options.name?.trim() || path.basename(this.root) || "workdir";
|
|
476
476
|
this.metadata = { ...(options.metadata ?? {}) };
|
|
477
477
|
this.trusted = options.trusted ?? false;
|
|
478
|
-
this.files = new LocalFileStore(this.root, { label: "
|
|
479
|
-
this.ignore = [...
|
|
478
|
+
this.files = new LocalFileStore(this.root, { label: "workdir" });
|
|
479
|
+
this.ignore = [...defaultWorkdirIgnoreRules(), ...(options.ignore ?? [])];
|
|
480
480
|
this.gitignore = options.gitignore ?? true;
|
|
481
481
|
this.maxFileBytes = positiveInt(options.maxFileBytes, 10 * 1024 * 1024);
|
|
482
482
|
}
|
|
@@ -503,7 +503,7 @@ export class LocalWorkspace {
|
|
|
503
503
|
return loaded;
|
|
504
504
|
}
|
|
505
505
|
child(relativePath, options = {}) {
|
|
506
|
-
return new
|
|
506
|
+
return new LocalWorkdir(this.files.resolvePath(relativePath), {
|
|
507
507
|
name: options.name,
|
|
508
508
|
metadata: options.metadata ?? this.metadata,
|
|
509
509
|
trusted: options.trusted ?? this.trusted,
|
|
@@ -884,7 +884,7 @@ function ignored(relativePath, ignore) {
|
|
|
884
884
|
function ignoredDirectoryName(name) {
|
|
885
885
|
return name === ".git" || name === "node_modules" || name === "__pycache__";
|
|
886
886
|
}
|
|
887
|
-
function
|
|
887
|
+
function defaultWorkdirIgnoreRules() {
|
|
888
888
|
return [
|
|
889
889
|
".git",
|
|
890
890
|
"node_modules",
|
package/dist/local/index.d.ts
CHANGED
package/dist/local/index.js
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { FunctionTool } from "../types/tools.js";
|
|
2
|
+
import type { LocalWorkdir } from "./core.js";
|
|
3
|
+
export type LocalShellAccessMode = "approval" | "full";
|
|
4
|
+
export interface LocalShellRequest {
|
|
5
|
+
command: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
workdir?: string;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
env?: Record<string, string | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export interface LocalShellContext {
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
export interface LocalShellResult {
|
|
15
|
+
ok: boolean;
|
|
16
|
+
command: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
cwd: string;
|
|
19
|
+
exit_code: number | null;
|
|
20
|
+
signal: NodeJS.Signals | null;
|
|
21
|
+
stdout: string;
|
|
22
|
+
stderr: string;
|
|
23
|
+
output: string;
|
|
24
|
+
duration_ms: number;
|
|
25
|
+
timed_out: boolean;
|
|
26
|
+
truncated: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface LocalCommandRunner {
|
|
29
|
+
run(request: LocalShellRequest, context?: LocalShellContext): Promise<LocalShellResult>;
|
|
30
|
+
}
|
|
31
|
+
export interface HostLocalShellRunnerOptions {
|
|
32
|
+
cwd?: string;
|
|
33
|
+
shell?: string | boolean;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
maxOutputBytes?: number;
|
|
36
|
+
env?: NodeJS.ProcessEnv;
|
|
37
|
+
}
|
|
38
|
+
export declare class HostLocalShellRunner implements LocalCommandRunner {
|
|
39
|
+
readonly cwd: string;
|
|
40
|
+
readonly shell: string | boolean;
|
|
41
|
+
readonly timeoutMs: number;
|
|
42
|
+
readonly maxOutputBytes: number;
|
|
43
|
+
readonly env: NodeJS.ProcessEnv;
|
|
44
|
+
constructor(options?: HostLocalShellRunnerOptions);
|
|
45
|
+
run(request: LocalShellRequest, context?: LocalShellContext): Promise<LocalShellResult>;
|
|
46
|
+
}
|
|
47
|
+
export interface LocalShellToolRegistryOptions {
|
|
48
|
+
accessMode?: LocalShellAccessMode;
|
|
49
|
+
toolName?: string;
|
|
50
|
+
runner?: LocalCommandRunner;
|
|
51
|
+
cwd?: string;
|
|
52
|
+
workdir?: LocalWorkdir;
|
|
53
|
+
shell?: string | boolean;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
maxOutputBytes?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface LocalShellToolPresentationOptions {
|
|
58
|
+
accessMode?: LocalShellAccessMode;
|
|
59
|
+
cwd?: string;
|
|
60
|
+
shell?: string | boolean;
|
|
61
|
+
platform?: NodeJS.Platform;
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
maxOutputBytes?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface LocalShellToolRegistry {
|
|
66
|
+
readonly accessMode: LocalShellAccessMode;
|
|
67
|
+
readonly toolName: string;
|
|
68
|
+
definitions(): FunctionTool[];
|
|
69
|
+
handlers(): Record<string, (args: Record<string, unknown>) => Promise<Record<string, unknown>>>;
|
|
70
|
+
execute(name: string, args: Record<string, unknown>, context?: LocalShellContext): Promise<Record<string, unknown>>;
|
|
71
|
+
requiresApproval(name: string, args?: Record<string, unknown>): boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare class LocalShellDriver {
|
|
74
|
+
readonly accessMode: LocalShellAccessMode;
|
|
75
|
+
readonly runner: LocalCommandRunner;
|
|
76
|
+
constructor(options?: LocalShellToolRegistryOptions);
|
|
77
|
+
dispatch(args: Record<string, unknown>, context?: LocalShellContext): Promise<Record<string, unknown>>;
|
|
78
|
+
requiresApproval(): boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare function createLocalShellToolRegistry(options?: LocalShellToolRegistryOptions): LocalShellToolRegistry;
|
|
81
|
+
export declare function localShellToolDefinition(name?: string, options?: LocalShellToolPresentationOptions): FunctionTool;
|
|
82
|
+
export declare function localShellToolInstructions(options?: LocalShellToolPresentationOptions): string;
|