@agent-api/sdk 1.1.4 → 1.2.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/CHANGELOG.md +17 -5
- package/README.md +29 -16
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- 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/tools.d.ts +17 -17
- package/dist/local/tools.js +46 -46
- package/dist/local-skills.js +13 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/resources/auth.d.ts +3 -1
- package/dist/resources/auth.js +18 -0
- package/dist/types/auth.d.ts +3 -0
- package/dist/types/responses.d.ts +4 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist-cjs/client.js +1 -0
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/local/context.js +10 -10
- package/dist-cjs/local/core.js +15 -15
- package/dist-cjs/local/tools.js +51 -51
- package/dist-cjs/local-skills.js +13 -1
- package/dist-cjs/node.js +5 -5
- package/dist-cjs/resources/auth.js +19 -0
- package/dist-cjs/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
# Changelog — @agent-api/sdk
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added browser-session refresh helpers for long-running CLI and desktop integrations: `client.auth.refreshBrowserSession()` and `browserAuthSessionExpiresWithin()`.
|
|
8
|
+
- Added unified local skill tool-call handling for both local skill and function-call response items.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Renamed local SDK concepts from workspace to workdir to avoid confusion with platform identity workspaces.
|
|
13
|
+
- Extended response input types so tool-call continuations can carry function-call metadata consistently.
|
|
14
|
+
|
|
3
15
|
## 1.1.2
|
|
4
16
|
|
|
5
17
|
### Added
|
|
6
18
|
|
|
7
|
-
- Added a model-facing `
|
|
8
|
-
- Added approval-aware dispatch for mutating local
|
|
19
|
+
- Added a model-facing `local_workdir` driver/tool primitive for local workdir operations.
|
|
20
|
+
- Added approval-aware dispatch for mutating local workdir actions.
|
|
9
21
|
|
|
10
22
|
### Changed
|
|
11
23
|
|
|
12
|
-
- Replaced fragmented local
|
|
24
|
+
- Replaced fragmented local workdir tool presentation with an action-based adapter over the low-level local APIs.
|
|
13
25
|
|
|
14
26
|
## 1.1.1
|
|
15
27
|
|
|
@@ -27,9 +39,9 @@
|
|
|
27
39
|
- Cross-platform app directory resolution for data, config, cache, logs, and temp files.
|
|
28
40
|
- Root-scoped local file stores with path traversal protection, atomic writes, JSON helpers, recursive listing, and local skill discovery.
|
|
29
41
|
- Local workdir operations for entry search, file delivery, line-range reads and edits, literal grep, and directory summaries.
|
|
30
|
-
- `
|
|
42
|
+
- `LocalWorkdir` and `LocalWorkdirManager` for project roots, default ignore rules, patch previews, snapshots, diffs, and file-watch handles.
|
|
31
43
|
- Typed local errors, `.gitignore` loading, sensitivity classification for likely secret paths, and multi-file line-edit plans with conflict detection and rollback.
|
|
32
|
-
- `createLocalContextPackage()` for bounded, secret-aware local
|
|
44
|
+
- `createLocalContextPackage()` for bounded, secret-aware local workdir manifests that app integrations can hand to agent workflows.
|
|
33
45
|
|
|
34
46
|
### Changed
|
|
35
47
|
|
package/README.md
CHANGED
|
@@ -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, and local workdir tool support.
|
|
48
48
|
- `@agent-api/sdk/node`: Node aggregate entry for local helpers such as `localSkillFromDirectory()` plus `NodeAgentAPI`.
|
|
49
49
|
|
|
50
50
|
```
|
|
@@ -68,7 +68,7 @@ src/
|
|
|
68
68
|
| `client.tools` | `list` |
|
|
69
69
|
| `client.volumes` | `list`, `create`, `retrieve`, `update`, `delete`, `listEntries`, `searchEntries`, `readFile`, `writeFile`, `deletePath`, `reconcileUsage`, `createDirectory`, `downloadArchive`, `summarize`, `readLines`, `patchLines`, `grep` |
|
|
70
70
|
| `client.skills` | `list`, `create`, `discover`, `focus`, `createDev`, `updateFile`, `retrieve`, `update`, `archive`, `delete`, `diff`, `acceptDev`, `discardDev`, `exportArchive`, `importArchive`, `listFiles`, `readFile`, `writeFile`, `deleteFile` |
|
|
71
|
-
| `client.auth` | `startDeviceAuth`, `pollDeviceAuth`, `waitForDeviceAuth` |
|
|
71
|
+
| `client.auth` | `startDeviceAuth`, `pollDeviceAuth`, `waitForDeviceAuth`, `refreshBrowserSession` |
|
|
72
72
|
|
|
73
73
|
`NodeAgentAPI` from `@agent-api/sdk/node` extends `client.skills` with Node-only `pushDirectory` and `pullDirectory`.
|
|
74
74
|
|
|
@@ -90,6 +90,19 @@ console.log(session.access_token);
|
|
|
90
90
|
|
|
91
91
|
The SDK returns URLs and polling helpers only. Opening the browser belongs to the CLI, Electron, Tauri, or native host app.
|
|
92
92
|
|
|
93
|
+
Long-running local apps can keep browser sessions fresh explicitly:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { browserAuthSessionExpiresWithin } from "@agent-api/sdk";
|
|
97
|
+
|
|
98
|
+
if (browserAuthSessionExpiresWithin(session, 5 * 60_000)) {
|
|
99
|
+
session = await client.auth.refreshBrowserSession({
|
|
100
|
+
refresh_token: session.refresh_token,
|
|
101
|
+
});
|
|
102
|
+
// Persist the refreshed session in your app's secure profile store.
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
93
106
|
## Durable Volumes
|
|
94
107
|
|
|
95
108
|
```typescript
|
|
@@ -101,7 +114,7 @@ const binary = await client.volumes.readFile(volume.volume_id, "assets/logo.png"
|
|
|
101
114
|
|
|
102
115
|
const response = await client.agent.create({
|
|
103
116
|
preset: "pro-search",
|
|
104
|
-
input: "Use the attached
|
|
117
|
+
input: "Use the attached agent volume.",
|
|
105
118
|
volume_id: volume.volume_id,
|
|
106
119
|
});
|
|
107
120
|
```
|
|
@@ -112,10 +125,10 @@ const response = await client.agent.create({
|
|
|
112
125
|
|
|
113
126
|
```typescript
|
|
114
127
|
import { resolvePresetTools } from "@agent-api/sdk";
|
|
115
|
-
import {
|
|
128
|
+
import { createLocalWorkdirToolRegistry, LocalWorkdir } from "@agent-api/sdk/local";
|
|
116
129
|
|
|
117
|
-
const
|
|
118
|
-
const registry =
|
|
130
|
+
const workdir = new LocalWorkdir("/path/to/project", { trusted: true });
|
|
131
|
+
const registry = createLocalWorkdirToolRegistry(workdir);
|
|
119
132
|
|
|
120
133
|
const { tools } = await resolvePresetTools(client, {
|
|
121
134
|
preset: "pro-search",
|
|
@@ -175,7 +188,7 @@ The runtime provides:
|
|
|
175
188
|
- Root-scoped file stores with path traversal protection.
|
|
176
189
|
- Atomic text/JSON writes, byte reads/writes, recursive listing, copy, remove, and stat helpers.
|
|
177
190
|
- Local workdir operations inspired by platform volumes: `listEntries`, `searchEntries`, `readFile`, `writeFile`, `deletePath`, `createDirectory`, `readLines`, `patchLines`, `grep`, and `summarize`.
|
|
178
|
-
- First-class local
|
|
191
|
+
- First-class local workdirs with default ignore rules, scoped workbench operations, patch previews, snapshots, diffs, file-watch handles, and budgeted context packaging.
|
|
179
192
|
- Typed local errors, `.gitignore` loading, sensitivity classification, and multi-file edit plans with rollback on failure.
|
|
180
193
|
- JSON config helpers for typed app settings.
|
|
181
194
|
- Local skill discovery built on `localSkillFromDirectory()`.
|
|
@@ -183,24 +196,24 @@ The runtime provides:
|
|
|
183
196
|
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.
|
|
184
197
|
|
|
185
198
|
```typescript
|
|
186
|
-
const
|
|
199
|
+
const workdir = local.data.child("workdirs/demo");
|
|
187
200
|
|
|
188
|
-
await
|
|
201
|
+
await workdir.writeText("src/index.ts", "console.log('hello');\n");
|
|
189
202
|
|
|
190
|
-
const matches = await
|
|
191
|
-
const lines = await
|
|
192
|
-
await
|
|
203
|
+
const matches = await workdir.grep({ pattern: "hello", path: "src" });
|
|
204
|
+
const lines = await workdir.readLines("src/index.ts", { startLine: 1, endLine: 20 });
|
|
205
|
+
await workdir.patchLines("src/index.ts", {
|
|
193
206
|
startLine: 1,
|
|
194
207
|
replacement: "console.log('patched');",
|
|
195
208
|
});
|
|
196
209
|
|
|
197
|
-
const summary = await
|
|
210
|
+
const summary = await workdir.summarize();
|
|
198
211
|
```
|
|
199
212
|
|
|
200
|
-
For project/
|
|
213
|
+
For project/workdir roots, prefer `local.workdir()` so SDK defaults protect common generated directories such as `.git`, `node_modules`, `dist`, and build caches.
|
|
201
214
|
|
|
202
215
|
```typescript
|
|
203
|
-
const project = local.
|
|
216
|
+
const project = local.workdir("/path/to/project", {
|
|
204
217
|
name: "my-project",
|
|
205
218
|
trusted: true,
|
|
206
219
|
ignore: ["vendor", /^tmp\//],
|
|
@@ -223,7 +236,7 @@ const diff = project.diff(before, after);
|
|
|
223
236
|
const sensitivity = project.classifyPath(".env");
|
|
224
237
|
```
|
|
225
238
|
|
|
226
|
-
Use `createLocalContextPackage()` when a local app needs to prepare bounded
|
|
239
|
+
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.
|
|
227
240
|
|
|
228
241
|
```typescript
|
|
229
242
|
import { createLocalContextPackage } from "@agent-api/sdk/local";
|
package/dist/client.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class AgentAPI {
|
|
|
31
31
|
protected createSkillsResource(): SkillsResource;
|
|
32
32
|
startDeviceAuth: (...args: Parameters<AuthResource["startDeviceAuth"]>) => Promise<import("./index.js").DeviceAuthStart>;
|
|
33
33
|
pollDeviceAuth: (...args: Parameters<AuthResource["pollDeviceAuth"]>) => Promise<import("./index.js").DeviceAuthPollResult>;
|
|
34
|
+
refreshBrowserSession: (...args: Parameters<AuthResource["refreshBrowserSession"]>) => Promise<import("./index.js").AuthSession>;
|
|
34
35
|
waitForDeviceAuth: (...args: Parameters<AuthResource["waitForDeviceAuth"]>) => Promise<import("./index.js").ApprovedDeviceAuth>;
|
|
35
36
|
}
|
|
36
37
|
export { VERSION };
|
package/dist/client.js
CHANGED
|
@@ -62,6 +62,7 @@ export class AgentAPI {
|
|
|
62
62
|
}
|
|
63
63
|
startDeviceAuth = (...args) => this.auth.startDeviceAuth(...args);
|
|
64
64
|
pollDeviceAuth = (...args) => this.auth.pollDeviceAuth(...args);
|
|
65
|
+
refreshBrowserSession = (...args) => this.auth.refreshBrowserSession(...args);
|
|
65
66
|
waitForDeviceAuth = (...args) => this.auth.waitForDeviceAuth(...args);
|
|
66
67
|
}
|
|
67
68
|
export { VERSION };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers
|
|
|
7
7
|
export type { LocalFunctionHandler, LocalFunctionHandlers } from "./local-functions.js";
|
|
8
8
|
export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
|
|
9
9
|
export type { PresetToolCatalogClient, ResolvePresetToolsOptions, ResolvePresetToolsResult, UnknownPresetToolBehavior, } from "./preset-tools.js";
|
|
10
|
-
export { AuthResource, DeviceAuthFlowError } from "./resources/auth.js";
|
|
10
|
+
export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { APIError, APIConnectionError, APIStatusError, AuthenticationError, BadR
|
|
|
4
4
|
export * from "./types/index.js";
|
|
5
5
|
export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers, } from "./local-functions.js";
|
|
6
6
|
export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
|
|
7
|
-
export { AuthResource, DeviceAuthFlowError } from "./resources/auth.js";
|
|
7
|
+
export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
|
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/tools.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import type { FunctionTool } from "../types/tools.js";
|
|
2
|
-
import type {
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export interface
|
|
6
|
-
accessMode?:
|
|
2
|
+
import type { LocalWorkdir } from "./core.js";
|
|
3
|
+
export type LocalWorkdirAccessMode = "approval" | "full";
|
|
4
|
+
export type LocalWorkdirAction = "summarize" | "list" | "search" | "grep" | "read" | "read_lines" | "context" | "snapshot" | "classify_path" | "preview_edits" | "apply_edits" | "write" | "mkdir" | "delete";
|
|
5
|
+
export interface LocalWorkdirToolRegistryOptions {
|
|
6
|
+
accessMode?: LocalWorkdirAccessMode;
|
|
7
7
|
toolName?: string;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
10
|
-
readonly
|
|
11
|
-
readonly accessMode:
|
|
9
|
+
export interface LocalWorkdirToolRegistry {
|
|
10
|
+
readonly workdir: LocalWorkdir;
|
|
11
|
+
readonly accessMode: LocalWorkdirAccessMode;
|
|
12
12
|
readonly toolName: string;
|
|
13
13
|
definitions(): FunctionTool[];
|
|
14
14
|
handlers(): Record<string, (args: Record<string, unknown>) => Promise<Record<string, unknown>>>;
|
|
15
15
|
execute(name: string, args: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
16
16
|
requiresApproval(name: string, args?: Record<string, unknown>): boolean;
|
|
17
17
|
}
|
|
18
|
-
export interface
|
|
19
|
-
accessMode?:
|
|
18
|
+
export interface LocalWorkdirDriverOptions {
|
|
19
|
+
accessMode?: LocalWorkdirAccessMode;
|
|
20
20
|
}
|
|
21
|
-
export declare class
|
|
22
|
-
readonly
|
|
23
|
-
readonly accessMode:
|
|
24
|
-
constructor(
|
|
21
|
+
export declare class LocalWorkdirDriver {
|
|
22
|
+
readonly workdir: LocalWorkdir;
|
|
23
|
+
readonly accessMode: LocalWorkdirAccessMode;
|
|
24
|
+
constructor(workdir: LocalWorkdir, options?: LocalWorkdirDriverOptions);
|
|
25
25
|
dispatch(args: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
26
26
|
requiresApproval(args: Record<string, unknown>): boolean;
|
|
27
27
|
private dispatchApplyEdits;
|
|
@@ -29,6 +29,6 @@ export declare class LocalWorkspaceDriver {
|
|
|
29
29
|
private dispatchMkdir;
|
|
30
30
|
private dispatchDelete;
|
|
31
31
|
}
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function
|
|
32
|
+
export declare function createLocalWorkdirToolRegistry(workdir: LocalWorkdir, options?: LocalWorkdirToolRegistryOptions): LocalWorkdirToolRegistry;
|
|
33
|
+
export declare function localWorkdirToolDefinition(name?: string): FunctionTool;
|
|
34
|
+
export declare function localWorkdirToolInstructions(): string;
|