disk 1.9.0 → 1.11.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/dist/cli.mjs +27 -7
- package/dist/{disk-MmfqVyPo.d.cts → disk-BmBSYT8h.d.cts} +51 -3
- package/dist/{disk-MmfqVyPo.d.mts → disk-BmBSYT8h.d.mts} +51 -3
- package/dist/index.cjs +126 -8
- package/dist/index.d.cts +24 -5
- package/dist/index.d.mts +24 -5
- package/dist/index.mjs +1 -1
- package/dist/internal/tools.cjs +2 -2
- package/dist/internal/tools.d.cts +1 -1
- package/dist/internal/tools.d.mts +1 -1
- package/dist/internal/tools.mjs +2 -2
- package/dist/sandbox-cli.mjs +2 -46
- package/dist/{common-Dl6NSqjY.mjs → sandbox-options-VBQ-AsOP.mjs} +46 -2
- package/dist/{src-vpVe_Scb.mjs → src-BbjR-spO.mjs} +126 -8
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as deleteApiKey, k as ArchilApiError, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-
|
|
3
|
-
import { a as
|
|
2
|
+
import { a as deleteApiKey, k as ArchilApiError, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-BbjR-spO.mjs";
|
|
3
|
+
import { a as addGlobalOptions, c as resolveProgramCredentials, l as renderTable, o as addProfileCommands, s as isProfileCommand, t as optionalInteger } from "./sandbox-options-VBQ-AsOP.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
//#region bin/cli.ts
|
|
@@ -173,8 +173,14 @@ program.command("exec <id|name> <command...>").description("Run a command in a c
|
|
|
173
173
|
fail(err);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
|
-
program.command("grep <pattern> <target>").description("Constant-time parallel server-side grep across a disk. <target> is <id|name>[/<path>] — the path after the first '/' is the directory to search (defaults to the disk root). Accepts a disk id or name.").option("--no-recursive", "Search only the given directory, not its subdirectories (recursive is the default)").option("--max-duration <seconds>", "Wall-clock deadline for the whole search"
|
|
176
|
+
program.command("grep <pattern> <target>").description("Constant-time parallel server-side grep across a disk. <target> is <id|name>[/<path>] — the path after the first '/' is the directory to search (defaults to the disk root). Accepts a disk id or name.").option("--no-recursive", "Search only the given directory, not its subdirectories (recursive is the default)").option("--max-duration <seconds>", "Wall-clock deadline for the whole search").option("--concurrency <n>", "Max parallel grep workers (clamped to fleet capacity)").option("--max-results <n>", "Stop once this many matches are collected").option("-i, --ignore-case", "Match case-insensitively").option("-U, --multiline", "Let matches span lines").option("-g, --glob <glob>", "Include files matching the glob, or exclude with a leading ! (repeatable)", (value, previous) => [...previous, value], []).option("-t, --type <type>", "Only search files of this type, e.g. py (repeatable)", (value, previous) => [...previous, value], []).option("-T, --type-not <type>", "Skip files of this type (repeatable)", (value, previous) => [...previous, value], []).option("-A, --after-context <n>", "Lines of context after each match (max 10)").option("-B, --before-context <n>", "Lines of context before each match (max 10)").option("-C, --context <n>", "Lines of context before and after each match (max 10)").option("-o, --output <format>", "Output format: text | json", "text").action(async (pattern, target, opts) => {
|
|
177
177
|
try {
|
|
178
|
+
const context = optionalInteger(opts.context, "Context", 0, 10);
|
|
179
|
+
const contextBefore = optionalInteger(opts.beforeContext, "Before context", 0, 10) ?? context;
|
|
180
|
+
const contextAfter = optionalInteger(opts.afterContext, "After context", 0, 10) ?? context;
|
|
181
|
+
const maxDurationSeconds = optionalInteger(opts.maxDuration, "Max duration", 1, 30);
|
|
182
|
+
const concurrency = optionalInteger(opts.concurrency, "Concurrency", 1, 100);
|
|
183
|
+
const maxResults = optionalInteger(opts.maxResults, "Max results", 1, 1e4);
|
|
178
184
|
const slash = target.indexOf("/");
|
|
179
185
|
const idOrName = slash === -1 ? target : target.slice(0, slash);
|
|
180
186
|
const directory = slash === -1 ? "" : target.slice(slash + 1);
|
|
@@ -182,13 +188,27 @@ program.command("grep <pattern> <target>").description("Constant-time parallel s
|
|
|
182
188
|
directory,
|
|
183
189
|
pattern,
|
|
184
190
|
recursive: opts.recursive !== false,
|
|
185
|
-
maxDurationSeconds
|
|
186
|
-
concurrency
|
|
187
|
-
maxResults
|
|
191
|
+
maxDurationSeconds,
|
|
192
|
+
concurrency,
|
|
193
|
+
maxResults,
|
|
194
|
+
ignoreCase: opts.ignoreCase,
|
|
195
|
+
multiline: opts.multiline,
|
|
196
|
+
globs: opts.glob,
|
|
197
|
+
types: opts.type,
|
|
198
|
+
typesNot: opts.typeNot,
|
|
199
|
+
contextBefore,
|
|
200
|
+
contextAfter
|
|
188
201
|
});
|
|
189
202
|
if (opts.output === "json") console.log(JSON.stringify(res, null, 2));
|
|
190
203
|
else {
|
|
191
|
-
|
|
204
|
+
if (res.groups) res.groups.forEach((g, i) => {
|
|
205
|
+
if (i > 0) console.log("--");
|
|
206
|
+
for (const l of g.lines) {
|
|
207
|
+
const sep = l.match ? ":" : "-";
|
|
208
|
+
console.log(`${g.file}${sep}${l.line}${sep}${l.text}`);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
else for (const m of res.matches) m.text.split("\n").forEach((text, k) => console.log(`${m.file}:${m.line + k}:${text}`));
|
|
192
212
|
console.error(`${res.matches.length} match${res.matches.length === 1 ? "" : "es"} · ${res.filesScanned} files scanned · ${res.containersDispatched} containers · ${res.durationMs}ms · ${res.stoppedReason}`);
|
|
193
213
|
if (res.stoppedReason !== "completed") console.error(`warning: search did not complete (${res.stoppedReason}); results may be partial`);
|
|
194
214
|
}
|
|
@@ -65,12 +65,15 @@ type Branch = components["schemas"]["BranchResponse"];
|
|
|
65
65
|
type DiskUser = components["schemas"]["DiskUser"];
|
|
66
66
|
type TokenUser = components["schemas"]["TokenUser"];
|
|
67
67
|
type AwsStsUser = components["schemas"]["AwsStsUser"];
|
|
68
|
+
type S3User = components["schemas"]["S3User"];
|
|
68
69
|
type CreateApiTokenRequest = components["schemas"]["CreateApiTokenRequest"];
|
|
69
70
|
type ApiTokenResponse = components["schemas"]["ApiTokenResponse"];
|
|
70
71
|
type ExecDiskResult = components["schemas"]["ExecDiskResult"];
|
|
71
72
|
type ExecRequest = components["schemas"]["ExecRequest"];
|
|
72
73
|
type GrepDiskResult = components["schemas"]["GrepDiskResult"];
|
|
73
74
|
type GrepMatch = components["schemas"]["GrepMatch"];
|
|
75
|
+
type GrepGroup = components["schemas"]["GrepGroup"];
|
|
76
|
+
type GrepGroupLine = components["schemas"]["GrepGroupLine"];
|
|
74
77
|
type GrepStoppedReason = components["schemas"]["GrepStoppedReason"];
|
|
75
78
|
type DiskStatus = DiskResponse["status"];
|
|
76
79
|
//#endregion
|
|
@@ -104,7 +107,10 @@ interface GrepOptions {
|
|
|
104
107
|
* string or "/" means the disk root.
|
|
105
108
|
*/
|
|
106
109
|
directory: string;
|
|
107
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Regular expression in ripgrep syntax. A newline separates alternative
|
|
112
|
+
* patterns, except with `multiline`, where it matches a line break.
|
|
113
|
+
*/
|
|
108
114
|
pattern: string;
|
|
109
115
|
/** Walk subdirectories breadth-first. Defaults to false. */
|
|
110
116
|
recursive?: boolean;
|
|
@@ -123,6 +129,36 @@ interface GrepOptions {
|
|
|
123
129
|
* lexicographically first N. Defaults to 1000.
|
|
124
130
|
*/
|
|
125
131
|
maxResults?: number;
|
|
132
|
+
/** Match the pattern case-insensitively (`rg -i`). Defaults to false. */
|
|
133
|
+
ignoreCase?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Let a match span lines (`rg -U`): `\n` in the pattern matches a line
|
|
136
|
+
* break, and `.` matches one only after `(?s)`. Files with Windows line
|
|
137
|
+
* endings need `\r?\n`. Matches on adjacent lines come back as one match
|
|
138
|
+
* with `endLine` set, and count once toward `maxResults`. Defaults to false.
|
|
139
|
+
*/
|
|
140
|
+
multiline?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Path globs with ripgrep's `-g` rules, matched against paths relative to
|
|
143
|
+
* `directory`. A leading `!` excludes. If any non-`!` glob is given, files
|
|
144
|
+
* that match no glob are skipped. A file a glob matches is searched or
|
|
145
|
+
* skipped regardless of `types` and `typesNot`.
|
|
146
|
+
*/
|
|
147
|
+
globs?: string[];
|
|
148
|
+
/** Only search files of these ripgrep types (for example `py`, `ts`). */
|
|
149
|
+
types?: string[];
|
|
150
|
+
/** Skip files of these ripgrep types. Takes precedence over `types`. */
|
|
151
|
+
typesNot?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Lines of context to return before each match (`rg -B`), 0 to 10. When
|
|
154
|
+
* either context field is set, the result includes `groups`.
|
|
155
|
+
*/
|
|
156
|
+
contextBefore?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Lines of context to return after each match (`rg -A`), 0 to 10. When
|
|
159
|
+
* either context field is set, the result includes `groups`.
|
|
160
|
+
*/
|
|
161
|
+
contextAfter?: number;
|
|
126
162
|
}
|
|
127
163
|
interface ShareUrlOptions {
|
|
128
164
|
/**
|
|
@@ -424,12 +460,24 @@ declare class Disk implements FileSystem {
|
|
|
424
460
|
constructor(data: DiskResponse, client: ApiClient, archilRegion: string, s3BaseUrl?: string);
|
|
425
461
|
toJSON(): DiskResponse;
|
|
426
462
|
addUser(user: DiskUser): Promise<AuthorizedUser>;
|
|
427
|
-
removeUser(userType: "token" | "awssts", identifier: string): Promise<void>;
|
|
463
|
+
removeUser(userType: "token" | "awssts" | "s3", identifier: string): Promise<void>;
|
|
428
464
|
createToken(nickname: string): Promise<AuthorizedUser & {
|
|
429
465
|
token: string;
|
|
430
466
|
identifier: string;
|
|
431
467
|
}>;
|
|
432
468
|
removeTokenUser(identifier: string): Promise<void>;
|
|
469
|
+
/**
|
|
470
|
+
* Create an S3 access key pair for this disk's S3 API. The secret key is
|
|
471
|
+
* returned only here. The keys reach the whole disk, read-write unless
|
|
472
|
+
* `readOnly` is set, so keep them server-side and give browsers presigned
|
|
473
|
+
* URLs instead.
|
|
474
|
+
*/
|
|
475
|
+
createS3Credentials(options?: Omit<S3User, "type">): Promise<AuthorizedUser & {
|
|
476
|
+
s3AccessKeyId: string;
|
|
477
|
+
s3SecretKey: string;
|
|
478
|
+
identifier: string;
|
|
479
|
+
}>;
|
|
480
|
+
removeS3Credentials(accessKeyId: string): Promise<void>;
|
|
433
481
|
/**
|
|
434
482
|
* List all delegations currently held on this disk. A delegation grants a
|
|
435
483
|
* client exclusive write access to an inode; it has no ID of its own and is
|
|
@@ -746,4 +794,4 @@ declare class DiskMultipart {
|
|
|
746
794
|
*/
|
|
747
795
|
declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
|
|
748
796
|
//#endregion
|
|
749
|
-
export {
|
|
797
|
+
export { MountResponse as $, effectiveUploadPartSize as A, DiskMetrics as B, PosixCreateAttrs as C, ShareUrlOptions as D, S3Object as E, Branch as F, ExecRequest as G, DiskStatus as H, ConnectedClient as I, GrepGroupLine as J, GCSMount as K, CreateApiTokenRequest as L, AuthorizedUser as M, AwsStsUser as N, ShareUrlResult as O, AzureBlobMount as P, MountConfigResponse as Q, CreateDiskRequest as R, PartListing as S, PutObjectResult as T, DiskUser as U, DiskResponse as V, ExecDiskResult as W, GrepStoppedReason as X, GrepMatch as Y, MountConfig as Z, MultipartUpload as _, DeleteObjectsOptions as a, TokenUser as at, ObjectMetadata as b, DiskMultipart as c, ArchilTlsOptions as ct, GrepResult as d, R2Mount as et, ListMultipartUploadsOptions as f, MountOptions as g, ListPartsOptions as h, DeleteObjectsError as i, S3User as it, ApiTokenResponse as j, UploadPart as k, ExecResult as l, ListObjectsResult as m, CompletedMultipartUpload as n, S3CompatibleMount as nt, DeleteObjectsResult as o, FileSystem as ot, ListObjectsOptions as p, GrepGroup as q, CreateBranchOptions as r, S3Mount as rt, Disk as s, ApiClient as st, AppendObjectOptions as t, RootAttrs as tt, GrepOptions as u, MultipartUploadListing as v, PutObjectOptions as w, PartInfo as x, MultipartUploadSummary as y, Delegation as z };
|
|
@@ -65,12 +65,15 @@ type Branch = components["schemas"]["BranchResponse"];
|
|
|
65
65
|
type DiskUser = components["schemas"]["DiskUser"];
|
|
66
66
|
type TokenUser = components["schemas"]["TokenUser"];
|
|
67
67
|
type AwsStsUser = components["schemas"]["AwsStsUser"];
|
|
68
|
+
type S3User = components["schemas"]["S3User"];
|
|
68
69
|
type CreateApiTokenRequest = components["schemas"]["CreateApiTokenRequest"];
|
|
69
70
|
type ApiTokenResponse = components["schemas"]["ApiTokenResponse"];
|
|
70
71
|
type ExecDiskResult = components["schemas"]["ExecDiskResult"];
|
|
71
72
|
type ExecRequest = components["schemas"]["ExecRequest"];
|
|
72
73
|
type GrepDiskResult = components["schemas"]["GrepDiskResult"];
|
|
73
74
|
type GrepMatch = components["schemas"]["GrepMatch"];
|
|
75
|
+
type GrepGroup = components["schemas"]["GrepGroup"];
|
|
76
|
+
type GrepGroupLine = components["schemas"]["GrepGroupLine"];
|
|
74
77
|
type GrepStoppedReason = components["schemas"]["GrepStoppedReason"];
|
|
75
78
|
type DiskStatus = DiskResponse["status"];
|
|
76
79
|
//#endregion
|
|
@@ -104,7 +107,10 @@ interface GrepOptions {
|
|
|
104
107
|
* string or "/" means the disk root.
|
|
105
108
|
*/
|
|
106
109
|
directory: string;
|
|
107
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Regular expression in ripgrep syntax. A newline separates alternative
|
|
112
|
+
* patterns, except with `multiline`, where it matches a line break.
|
|
113
|
+
*/
|
|
108
114
|
pattern: string;
|
|
109
115
|
/** Walk subdirectories breadth-first. Defaults to false. */
|
|
110
116
|
recursive?: boolean;
|
|
@@ -123,6 +129,36 @@ interface GrepOptions {
|
|
|
123
129
|
* lexicographically first N. Defaults to 1000.
|
|
124
130
|
*/
|
|
125
131
|
maxResults?: number;
|
|
132
|
+
/** Match the pattern case-insensitively (`rg -i`). Defaults to false. */
|
|
133
|
+
ignoreCase?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Let a match span lines (`rg -U`): `\n` in the pattern matches a line
|
|
136
|
+
* break, and `.` matches one only after `(?s)`. Files with Windows line
|
|
137
|
+
* endings need `\r?\n`. Matches on adjacent lines come back as one match
|
|
138
|
+
* with `endLine` set, and count once toward `maxResults`. Defaults to false.
|
|
139
|
+
*/
|
|
140
|
+
multiline?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Path globs with ripgrep's `-g` rules, matched against paths relative to
|
|
143
|
+
* `directory`. A leading `!` excludes. If any non-`!` glob is given, files
|
|
144
|
+
* that match no glob are skipped. A file a glob matches is searched or
|
|
145
|
+
* skipped regardless of `types` and `typesNot`.
|
|
146
|
+
*/
|
|
147
|
+
globs?: string[];
|
|
148
|
+
/** Only search files of these ripgrep types (for example `py`, `ts`). */
|
|
149
|
+
types?: string[];
|
|
150
|
+
/** Skip files of these ripgrep types. Takes precedence over `types`. */
|
|
151
|
+
typesNot?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Lines of context to return before each match (`rg -B`), 0 to 10. When
|
|
154
|
+
* either context field is set, the result includes `groups`.
|
|
155
|
+
*/
|
|
156
|
+
contextBefore?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Lines of context to return after each match (`rg -A`), 0 to 10. When
|
|
159
|
+
* either context field is set, the result includes `groups`.
|
|
160
|
+
*/
|
|
161
|
+
contextAfter?: number;
|
|
126
162
|
}
|
|
127
163
|
interface ShareUrlOptions {
|
|
128
164
|
/**
|
|
@@ -424,12 +460,24 @@ declare class Disk implements FileSystem {
|
|
|
424
460
|
constructor(data: DiskResponse, client: ApiClient, archilRegion: string, s3BaseUrl?: string);
|
|
425
461
|
toJSON(): DiskResponse;
|
|
426
462
|
addUser(user: DiskUser): Promise<AuthorizedUser>;
|
|
427
|
-
removeUser(userType: "token" | "awssts", identifier: string): Promise<void>;
|
|
463
|
+
removeUser(userType: "token" | "awssts" | "s3", identifier: string): Promise<void>;
|
|
428
464
|
createToken(nickname: string): Promise<AuthorizedUser & {
|
|
429
465
|
token: string;
|
|
430
466
|
identifier: string;
|
|
431
467
|
}>;
|
|
432
468
|
removeTokenUser(identifier: string): Promise<void>;
|
|
469
|
+
/**
|
|
470
|
+
* Create an S3 access key pair for this disk's S3 API. The secret key is
|
|
471
|
+
* returned only here. The keys reach the whole disk, read-write unless
|
|
472
|
+
* `readOnly` is set, so keep them server-side and give browsers presigned
|
|
473
|
+
* URLs instead.
|
|
474
|
+
*/
|
|
475
|
+
createS3Credentials(options?: Omit<S3User, "type">): Promise<AuthorizedUser & {
|
|
476
|
+
s3AccessKeyId: string;
|
|
477
|
+
s3SecretKey: string;
|
|
478
|
+
identifier: string;
|
|
479
|
+
}>;
|
|
480
|
+
removeS3Credentials(accessKeyId: string): Promise<void>;
|
|
433
481
|
/**
|
|
434
482
|
* List all delegations currently held on this disk. A delegation grants a
|
|
435
483
|
* client exclusive write access to an inode; it has no ID of its own and is
|
|
@@ -746,4 +794,4 @@ declare class DiskMultipart {
|
|
|
746
794
|
*/
|
|
747
795
|
declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
|
|
748
796
|
//#endregion
|
|
749
|
-
export {
|
|
797
|
+
export { MountResponse as $, effectiveUploadPartSize as A, DiskMetrics as B, PosixCreateAttrs as C, ShareUrlOptions as D, S3Object as E, Branch as F, ExecRequest as G, DiskStatus as H, ConnectedClient as I, GrepGroupLine as J, GCSMount as K, CreateApiTokenRequest as L, AuthorizedUser as M, AwsStsUser as N, ShareUrlResult as O, AzureBlobMount as P, MountConfigResponse as Q, CreateDiskRequest as R, PartListing as S, PutObjectResult as T, DiskUser as U, DiskResponse as V, ExecDiskResult as W, GrepStoppedReason as X, GrepMatch as Y, MountConfig as Z, MultipartUpload as _, DeleteObjectsOptions as a, TokenUser as at, ObjectMetadata as b, DiskMultipart as c, ArchilTlsOptions as ct, GrepResult as d, R2Mount as et, ListMultipartUploadsOptions as f, MountOptions as g, ListPartsOptions as h, DeleteObjectsError as i, S3User as it, ApiTokenResponse as j, UploadPart as k, ExecResult as l, ListObjectsResult as m, CompletedMultipartUpload as n, S3CompatibleMount as nt, DeleteObjectsResult as o, FileSystem as ot, ListObjectsOptions as p, GrepGroup as q, CreateBranchOptions as r, S3Mount as rt, Disk as s, ApiClient as st, AppendObjectOptions as t, RootAttrs as tt, GrepOptions as u, MultipartUploadListing as v, PutObjectOptions as w, PartInfo as x, MultipartUploadSummary as y, Delegation as z };
|
package/dist/index.cjs
CHANGED
|
@@ -163,7 +163,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
163
163
|
}
|
|
164
164
|
//#endregion
|
|
165
165
|
//#region src/version.ts
|
|
166
|
-
const VERSION = "1.
|
|
166
|
+
const VERSION = "1.11.0";
|
|
167
167
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/client.ts
|
|
@@ -465,6 +465,23 @@ var Disk = class {
|
|
|
465
465
|
await this.removeUser("token", identifier);
|
|
466
466
|
}
|
|
467
467
|
/**
|
|
468
|
+
* Create an S3 access key pair for this disk's S3 API. The secret key is
|
|
469
|
+
* returned only here. The keys reach the whole disk, read-write unless
|
|
470
|
+
* `readOnly` is set, so keep them server-side and give browsers presigned
|
|
471
|
+
* URLs instead.
|
|
472
|
+
*/
|
|
473
|
+
async createS3Credentials(options = {}) {
|
|
474
|
+
const user = await this.addUser({
|
|
475
|
+
...options,
|
|
476
|
+
type: "s3"
|
|
477
|
+
});
|
|
478
|
+
if (!user.s3AccessKeyId || !user.s3SecretKey || !user.identifier) throw new Error("Server did not return generated S3 credentials");
|
|
479
|
+
return user;
|
|
480
|
+
}
|
|
481
|
+
async removeS3Credentials(accessKeyId) {
|
|
482
|
+
await this.removeUser("s3", accessKeyId);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
468
485
|
* List all delegations currently held on this disk. A delegation grants a
|
|
469
486
|
* client exclusive write access to an inode; it has no ID of its own and is
|
|
470
487
|
* identified by the (clientId, inodeId) pair — pass those to
|
|
@@ -581,7 +598,14 @@ var Disk = class {
|
|
|
581
598
|
recursive: opts.recursive ?? false,
|
|
582
599
|
maxDurationSeconds: opts.maxDurationSeconds ?? 30,
|
|
583
600
|
concurrency: opts.concurrency ?? 50,
|
|
584
|
-
maxResults: opts.maxResults ?? 1e3
|
|
601
|
+
maxResults: opts.maxResults ?? 1e3,
|
|
602
|
+
ignoreCase: opts.ignoreCase,
|
|
603
|
+
multiline: opts.multiline,
|
|
604
|
+
globs: opts.globs,
|
|
605
|
+
types: opts.types,
|
|
606
|
+
typesNot: opts.typesNot,
|
|
607
|
+
contextBefore: opts.contextBefore ?? 0,
|
|
608
|
+
contextAfter: opts.contextAfter ?? 0
|
|
585
609
|
}
|
|
586
610
|
}), "transient"));
|
|
587
611
|
}
|
|
@@ -2368,6 +2392,30 @@ var Tokens = class {
|
|
|
2368
2392
|
function isExecMountSpec$1(m) {
|
|
2369
2393
|
return typeof m === "object" && m !== null && "disk" in m;
|
|
2370
2394
|
}
|
|
2395
|
+
/** Keep groups up to the one holding the `maxResults`-th match, and end that
|
|
2396
|
+
* group after up to `after` more lines, which become context so the groups
|
|
2397
|
+
* hold exactly the kept matches. With multiline, a run of matching lines is
|
|
2398
|
+
* one match. Mirrors the controlplane's truncation of a single disk's groups. */
|
|
2399
|
+
function truncateGroups(groups, maxResults, after, multiline) {
|
|
2400
|
+
let seen = 0;
|
|
2401
|
+
for (let i = 0; i < groups.length; i++) {
|
|
2402
|
+
const lines = groups[i].lines;
|
|
2403
|
+
for (let j = 0; j < lines.length; j++) {
|
|
2404
|
+
if (lines[j].match && !(multiline && j > 0 && lines[j - 1].match)) seen++;
|
|
2405
|
+
if (seen === maxResults && !(multiline && j + 1 < lines.length && lines[j + 1].match)) {
|
|
2406
|
+
const kept = lines.slice(0, Math.min(j + 1 + after, lines.length)).map((l, k) => k > j ? {
|
|
2407
|
+
...l,
|
|
2408
|
+
match: false
|
|
2409
|
+
} : l);
|
|
2410
|
+
return [...groups.slice(0, i), {
|
|
2411
|
+
...groups[i],
|
|
2412
|
+
lines: kept
|
|
2413
|
+
}];
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
return groups;
|
|
2418
|
+
}
|
|
2371
2419
|
/**
|
|
2372
2420
|
* A key-routed filesystem spanning several Archil disks. Each disk is mounted
|
|
2373
2421
|
* under a name and addressed as the first segment of a key (`<name>/...`);
|
|
@@ -2464,6 +2512,46 @@ var Workspace = class {
|
|
|
2464
2512
|
rel: this.diskKey(entry, segs.slice(1).join("/"))
|
|
2465
2513
|
}];
|
|
2466
2514
|
}
|
|
2515
|
+
/** Route grep globs written against the workspace root to the mounts they
|
|
2516
|
+
* can match. A glob that starts with a mount's name goes to that mount without
|
|
2517
|
+
* the name. One with no `/`, or that starts with `**` + `/` with or without a
|
|
2518
|
+
* leading `/`, goes to every mount as written, and also applies to a mount it
|
|
2519
|
+
* names exactly, like `!cache` or `**` + `/logs/**`. Mount names are matched
|
|
2520
|
+
* literally, so `!l*` doesn't skip a `logs` mount. Leaves out a mount whose
|
|
2521
|
+
* directory an exclude names, or that no include reaches, and throws for any
|
|
2522
|
+
* other glob with a `/`. */
|
|
2523
|
+
rootGlobs(globs) {
|
|
2524
|
+
const routed = new Map([...this.mounts.keys()].map((name) => [name, []]));
|
|
2525
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
2526
|
+
for (const glob of globs) {
|
|
2527
|
+
const exclude = glob.startsWith("!");
|
|
2528
|
+
let body = exclude ? glob.slice(1) : glob;
|
|
2529
|
+
const dirOnly = body.endsWith("/");
|
|
2530
|
+
if (dirOnly) body = body.slice(0, -1);
|
|
2531
|
+
const anchored = body.startsWith("/");
|
|
2532
|
+
if (anchored) body = body.slice(1);
|
|
2533
|
+
const everywhere = !anchored && !body.includes("/") || body === "**" || body.startsWith("**/");
|
|
2534
|
+
if (everywhere) for (const mountGlobs of routed.values()) mountGlobs.push(glob);
|
|
2535
|
+
const path = everywhere && body.startsWith("**/") ? body.slice(3) : body;
|
|
2536
|
+
const slash = path.indexOf("/");
|
|
2537
|
+
const name = slash < 0 ? path : path.slice(0, slash);
|
|
2538
|
+
const rest = slash < 0 ? "" : path.slice(slash + 1);
|
|
2539
|
+
const mountGlobs = routed.get(name);
|
|
2540
|
+
if (!mountGlobs) {
|
|
2541
|
+
if (everywhere) continue;
|
|
2542
|
+
throw new Error(`At the workspace root, a glob with a '/' must start with a mount name (${this.diskNames().map((n) => `${n}/`).join(", ")}) or '**/'; got '${glob}'. To search below one mount, set directory to it.`);
|
|
2543
|
+
}
|
|
2544
|
+
if (rest === "") {
|
|
2545
|
+
if (exclude) excluded.add(name);
|
|
2546
|
+
else excluded.delete(name);
|
|
2547
|
+
continue;
|
|
2548
|
+
}
|
|
2549
|
+
mountGlobs.push(`${exclude ? "!" : ""}${rest.includes("/") ? rest : `/${rest}`}${dirOnly ? "/" : ""}`);
|
|
2550
|
+
}
|
|
2551
|
+
const hasInclude = globs.some((glob) => !glob.startsWith("!"));
|
|
2552
|
+
for (const [name, mountGlobs] of routed) if (excluded.has(name) || hasInclude && mountGlobs.every((glob) => glob.startsWith("!"))) routed.delete(name);
|
|
2553
|
+
return routed;
|
|
2554
|
+
}
|
|
2467
2555
|
/** Map a workspace-relative key to the disk's key, applying the mount's subdirectory. */
|
|
2468
2556
|
diskKey(entry, rel) {
|
|
2469
2557
|
const trimmed = rel.replace(/^\/+/, "");
|
|
@@ -2534,13 +2622,38 @@ var Workspace = class {
|
|
|
2534
2622
|
keyCount
|
|
2535
2623
|
};
|
|
2536
2624
|
}
|
|
2625
|
+
/**
|
|
2626
|
+
* Grep the disks `directory` covers in parallel and merge their results. At
|
|
2627
|
+
* the workspace root, a glob with a `/` must start with a mount name, like
|
|
2628
|
+
* `data/src/**`, which applies to that mount only, or with `**` + `/`. A glob
|
|
2629
|
+
* with no `/`, like `*.ts`, or one starting with `**` + `/` with or without a
|
|
2630
|
+
* leading `/`, applies inside every mount, and also to a mount it names
|
|
2631
|
+
* exactly, so `!cache` skips the cache mount. Mount names are matched
|
|
2632
|
+
* literally, not as patterns: `!l*` applies inside every mount, but doesn't
|
|
2633
|
+
* skip a mount named `logs`.
|
|
2634
|
+
*/
|
|
2537
2635
|
async grep(opts) {
|
|
2538
|
-
const
|
|
2539
|
-
const
|
|
2636
|
+
const directory = opts.directory ?? "";
|
|
2637
|
+
const rootGlobs = require_paths.toSegments(directory).length === 0 && opts.globs?.length ? this.rootGlobs(opts.globs) : void 0;
|
|
2638
|
+
const covered = this.covered(directory).flatMap((c) => {
|
|
2639
|
+
if (rootGlobs === void 0) return [{
|
|
2640
|
+
...c,
|
|
2641
|
+
globs: opts.globs
|
|
2642
|
+
}];
|
|
2643
|
+
const globs = rootGlobs.get(c.name);
|
|
2644
|
+
return globs === void 0 ? [] : [{
|
|
2645
|
+
...c,
|
|
2646
|
+
globs
|
|
2647
|
+
}];
|
|
2648
|
+
});
|
|
2649
|
+
const results = await Promise.allSettled(covered.map(({ entry, rel, globs }) => entry.disk.grep({
|
|
2540
2650
|
...opts,
|
|
2541
|
-
directory: rel
|
|
2651
|
+
directory: rel,
|
|
2652
|
+
globs
|
|
2542
2653
|
})));
|
|
2654
|
+
for (const settled of results) if (settled.status === "rejected" && settled.reason instanceof ArchilApiError && settled.reason.status === 400) throw settled.reason;
|
|
2543
2655
|
const matches = [];
|
|
2656
|
+
const groups = [];
|
|
2544
2657
|
let filesScanned = 0;
|
|
2545
2658
|
let containersDispatched = 0;
|
|
2546
2659
|
let computeSecondsUsed = 0;
|
|
@@ -2563,9 +2676,12 @@ var Workspace = class {
|
|
|
2563
2676
|
grepMs = Math.max(grepMs, r.grepMs ?? 0);
|
|
2564
2677
|
reasons.add(r.stoppedReason);
|
|
2565
2678
|
for (const m of r.matches) matches.push({
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2679
|
+
...m,
|
|
2680
|
+
file: this.abs(name, entry, m.file)
|
|
2681
|
+
});
|
|
2682
|
+
for (const g of r.groups ?? []) groups.push({
|
|
2683
|
+
...g,
|
|
2684
|
+
file: this.abs(name, entry, g.file)
|
|
2569
2685
|
});
|
|
2570
2686
|
});
|
|
2571
2687
|
const cap = opts.maxResults ?? 1e3;
|
|
@@ -2577,8 +2693,10 @@ var Workspace = class {
|
|
|
2577
2693
|
"max_results"
|
|
2578
2694
|
];
|
|
2579
2695
|
const stoppedReason = [...reasons].every((x) => x === "completed") ? "completed" : priority.find((x) => reasons.has(x)) ?? "completed";
|
|
2696
|
+
const withGroups = (opts.contextBefore ?? 0) > 0 || (opts.contextAfter ?? 0) > 0;
|
|
2580
2697
|
return {
|
|
2581
2698
|
matches: matches.slice(0, cap),
|
|
2699
|
+
...withGroups && { groups: matches.length > cap ? truncateGroups(groups, cap, opts.contextAfter ?? 0, opts.multiline ?? false) : groups },
|
|
2582
2700
|
stoppedReason,
|
|
2583
2701
|
filesScanned,
|
|
2584
2702
|
containersDispatched,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as MountResponse, A as effectiveUploadPartSize, B as DiskMetrics, C as PosixCreateAttrs, D as ShareUrlOptions, E as S3Object, F as Branch, G as ExecRequest, H as DiskStatus, I as ConnectedClient, J as GrepGroupLine, K as GCSMount, L as CreateApiTokenRequest, M as AuthorizedUser, N as AwsStsUser, O as ShareUrlResult, P as AzureBlobMount, Q as MountConfigResponse, R as CreateDiskRequest, S as PartListing, T as PutObjectResult, U as DiskUser, V as DiskResponse, W as ExecDiskResult, X as GrepStoppedReason, Y as GrepMatch, Z as MountConfig, _ as MultipartUpload, a as DeleteObjectsOptions, at as TokenUser, b as ObjectMetadata, c as DiskMultipart, ct as ArchilTlsOptions, d as GrepResult, et as R2Mount, f as ListMultipartUploadsOptions, g as MountOptions, h as ListPartsOptions, i as DeleteObjectsError, it as S3User, j as ApiTokenResponse, k as UploadPart, l as ExecResult, m as ListObjectsResult, n as CompletedMultipartUpload, nt as S3CompatibleMount, o as DeleteObjectsResult, ot as FileSystem, p as ListObjectsOptions, q as GrepGroup, r as CreateBranchOptions, rt as S3Mount, s as Disk, st as ApiClient, t as AppendObjectOptions, tt as RootAttrs, u as GrepOptions, v as MultipartUploadListing, w as PutObjectOptions, x as PartInfo, y as MultipartUploadSummary, z as Delegation } from "./disk-BmBSYT8h.cjs";
|
|
2
2
|
import { components } from "@archildata/api-types";
|
|
3
3
|
|
|
4
4
|
//#region src/disks.d.ts
|
|
@@ -560,6 +560,15 @@ declare class Workspace implements FileSystem {
|
|
|
560
560
|
private route;
|
|
561
561
|
/** Mounts touched by a key prefix; an empty prefix fans out to all of them. */
|
|
562
562
|
private covered;
|
|
563
|
+
/** Route grep globs written against the workspace root to the mounts they
|
|
564
|
+
* can match. A glob that starts with a mount's name goes to that mount without
|
|
565
|
+
* the name. One with no `/`, or that starts with `**` + `/` with or without a
|
|
566
|
+
* leading `/`, goes to every mount as written, and also applies to a mount it
|
|
567
|
+
* names exactly, like `!cache` or `**` + `/logs/**`. Mount names are matched
|
|
568
|
+
* literally, so `!l*` doesn't skip a `logs` mount. Leaves out a mount whose
|
|
569
|
+
* directory an exclude names, or that no include reaches, and throws for any
|
|
570
|
+
* other glob with a `/`. */
|
|
571
|
+
private rootGlobs;
|
|
563
572
|
/** Map a workspace-relative key to the disk's key, applying the mount's subdirectory. */
|
|
564
573
|
private diskKey;
|
|
565
574
|
/** Map a disk key back to its workspace key (`<name>/...`), stripping the mount subdirectory. */
|
|
@@ -568,6 +577,16 @@ declare class Workspace implements FileSystem {
|
|
|
568
577
|
putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
|
|
569
578
|
deleteObject(key: string): Promise<void>;
|
|
570
579
|
listObjects(prefix?: string, opts?: ListObjectsOptions): Promise<ListObjectsResult>;
|
|
580
|
+
/**
|
|
581
|
+
* Grep the disks `directory` covers in parallel and merge their results. At
|
|
582
|
+
* the workspace root, a glob with a `/` must start with a mount name, like
|
|
583
|
+
* `data/src/**`, which applies to that mount only, or with `**` + `/`. A glob
|
|
584
|
+
* with no `/`, like `*.ts`, or one starting with `**` + `/` with or without a
|
|
585
|
+
* leading `/`, applies inside every mount, and also to a mount it names
|
|
586
|
+
* exactly, so `!cache` skips the cache mount. Mount names are matched
|
|
587
|
+
* literally, not as patterns: `!l*` applies inside every mount, but doesn't
|
|
588
|
+
* skip a mount named `logs`.
|
|
589
|
+
*/
|
|
571
590
|
grep(opts: GrepOptions): Promise<GrepResult>;
|
|
572
591
|
exec(command: string): Promise<ExecResult>;
|
|
573
592
|
}
|
|
@@ -611,9 +630,9 @@ interface ExecMountSpec {
|
|
|
611
630
|
*/
|
|
612
631
|
readOnly?: boolean;
|
|
613
632
|
/**
|
|
614
|
-
* When true, mount the disk in conditional mode,
|
|
615
|
-
*
|
|
616
|
-
*
|
|
633
|
+
* When true, mount the disk in conditional mode, which lets this mount
|
|
634
|
+
* write without a delegation checkout. This enables concurrent writes from
|
|
635
|
+
* multiple clients to the same disk.
|
|
617
636
|
* Defaults to false.
|
|
618
637
|
*/
|
|
619
638
|
conditional?: boolean;
|
|
@@ -756,4 +775,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
|
|
|
756
775
|
*/
|
|
757
776
|
declare function workspace(mounts: Record<string, ExecMount>): Workspace;
|
|
758
777
|
//#endregion
|
|
759
|
-
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type Branch, type BuildImageOptions, type BuildImageRequest, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateBranchOptions, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type Image, ImageBuildError, type ImageFailureReason, type ImageStatus, Images, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RegistryAuth, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxMount, type SandboxMountSpec, type SandboxNetwork, type SandboxNetworkAction, SandboxPauseError, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStartOptions, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
|
778
|
+
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type Branch, type BuildImageOptions, type BuildImageRequest, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateBranchOptions, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepGroup, type GrepGroupLine, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type Image, ImageBuildError, type ImageFailureReason, type ImageStatus, Images, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RegistryAuth, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, type S3User, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxMount, type SandboxMountSpec, type SandboxNetwork, type SandboxNetworkAction, SandboxPauseError, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStartOptions, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as MountResponse, A as effectiveUploadPartSize, B as DiskMetrics, C as PosixCreateAttrs, D as ShareUrlOptions, E as S3Object, F as Branch, G as ExecRequest, H as DiskStatus, I as ConnectedClient, J as GrepGroupLine, K as GCSMount, L as CreateApiTokenRequest, M as AuthorizedUser, N as AwsStsUser, O as ShareUrlResult, P as AzureBlobMount, Q as MountConfigResponse, R as CreateDiskRequest, S as PartListing, T as PutObjectResult, U as DiskUser, V as DiskResponse, W as ExecDiskResult, X as GrepStoppedReason, Y as GrepMatch, Z as MountConfig, _ as MultipartUpload, a as DeleteObjectsOptions, at as TokenUser, b as ObjectMetadata, c as DiskMultipart, ct as ArchilTlsOptions, d as GrepResult, et as R2Mount, f as ListMultipartUploadsOptions, g as MountOptions, h as ListPartsOptions, i as DeleteObjectsError, it as S3User, j as ApiTokenResponse, k as UploadPart, l as ExecResult, m as ListObjectsResult, n as CompletedMultipartUpload, nt as S3CompatibleMount, o as DeleteObjectsResult, ot as FileSystem, p as ListObjectsOptions, q as GrepGroup, r as CreateBranchOptions, rt as S3Mount, s as Disk, st as ApiClient, t as AppendObjectOptions, tt as RootAttrs, u as GrepOptions, v as MultipartUploadListing, w as PutObjectOptions, x as PartInfo, y as MultipartUploadSummary, z as Delegation } from "./disk-BmBSYT8h.mjs";
|
|
2
2
|
import { components } from "@archildata/api-types";
|
|
3
3
|
|
|
4
4
|
//#region src/disks.d.ts
|
|
@@ -560,6 +560,15 @@ declare class Workspace implements FileSystem {
|
|
|
560
560
|
private route;
|
|
561
561
|
/** Mounts touched by a key prefix; an empty prefix fans out to all of them. */
|
|
562
562
|
private covered;
|
|
563
|
+
/** Route grep globs written against the workspace root to the mounts they
|
|
564
|
+
* can match. A glob that starts with a mount's name goes to that mount without
|
|
565
|
+
* the name. One with no `/`, or that starts with `**` + `/` with or without a
|
|
566
|
+
* leading `/`, goes to every mount as written, and also applies to a mount it
|
|
567
|
+
* names exactly, like `!cache` or `**` + `/logs/**`. Mount names are matched
|
|
568
|
+
* literally, so `!l*` doesn't skip a `logs` mount. Leaves out a mount whose
|
|
569
|
+
* directory an exclude names, or that no include reaches, and throws for any
|
|
570
|
+
* other glob with a `/`. */
|
|
571
|
+
private rootGlobs;
|
|
563
572
|
/** Map a workspace-relative key to the disk's key, applying the mount's subdirectory. */
|
|
564
573
|
private diskKey;
|
|
565
574
|
/** Map a disk key back to its workspace key (`<name>/...`), stripping the mount subdirectory. */
|
|
@@ -568,6 +577,16 @@ declare class Workspace implements FileSystem {
|
|
|
568
577
|
putObject(key: string, body: string | Uint8Array | ArrayBuffer, options?: string | PutObjectOptions): Promise<PutObjectResult>;
|
|
569
578
|
deleteObject(key: string): Promise<void>;
|
|
570
579
|
listObjects(prefix?: string, opts?: ListObjectsOptions): Promise<ListObjectsResult>;
|
|
580
|
+
/**
|
|
581
|
+
* Grep the disks `directory` covers in parallel and merge their results. At
|
|
582
|
+
* the workspace root, a glob with a `/` must start with a mount name, like
|
|
583
|
+
* `data/src/**`, which applies to that mount only, or with `**` + `/`. A glob
|
|
584
|
+
* with no `/`, like `*.ts`, or one starting with `**` + `/` with or without a
|
|
585
|
+
* leading `/`, applies inside every mount, and also to a mount it names
|
|
586
|
+
* exactly, so `!cache` skips the cache mount. Mount names are matched
|
|
587
|
+
* literally, not as patterns: `!l*` applies inside every mount, but doesn't
|
|
588
|
+
* skip a mount named `logs`.
|
|
589
|
+
*/
|
|
571
590
|
grep(opts: GrepOptions): Promise<GrepResult>;
|
|
572
591
|
exec(command: string): Promise<ExecResult>;
|
|
573
592
|
}
|
|
@@ -611,9 +630,9 @@ interface ExecMountSpec {
|
|
|
611
630
|
*/
|
|
612
631
|
readOnly?: boolean;
|
|
613
632
|
/**
|
|
614
|
-
* When true, mount the disk in conditional mode,
|
|
615
|
-
*
|
|
616
|
-
*
|
|
633
|
+
* When true, mount the disk in conditional mode, which lets this mount
|
|
634
|
+
* write without a delegation checkout. This enables concurrent writes from
|
|
635
|
+
* multiple clients to the same disk.
|
|
617
636
|
* Defaults to false.
|
|
618
637
|
*/
|
|
619
638
|
conditional?: boolean;
|
|
@@ -756,4 +775,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
|
|
|
756
775
|
*/
|
|
757
776
|
declare function workspace(mounts: Record<string, ExecMount>): Workspace;
|
|
758
777
|
//#endregion
|
|
759
|
-
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type Branch, type BuildImageOptions, type BuildImageRequest, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateBranchOptions, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type Image, ImageBuildError, type ImageFailureReason, type ImageStatus, Images, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RegistryAuth, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxMount, type SandboxMountSpec, type SandboxNetwork, type SandboxNetworkAction, SandboxPauseError, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStartOptions, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
|
778
|
+
export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type Branch, type BuildImageOptions, type BuildImageRequest, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateBranchOptions, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepGroup, type GrepGroupLine, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type Image, ImageBuildError, type ImageFailureReason, type ImageStatus, Images, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RegistryAuth, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, type S3User, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxMount, type SandboxMountSpec, type SandboxNetwork, type SandboxNetworkAction, SandboxPauseError, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStartOptions, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as ArchilError, C as Disk, D as VERSION, E as USER_AGENT, M as ImageBuildError, N as SandboxFileTransferError, P as SandboxPauseError, S as Disks, T as effectiveUploadPartSize, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as ArchilS3Error, k as ArchilApiError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as DiskMultipart, x as Images, y as SandboxProcess } from "./src-
|
|
1
|
+
import { A as ArchilError, C as Disk, D as VERSION, E as USER_AGENT, M as ImageBuildError, N as SandboxFileTransferError, P as SandboxPauseError, S as Disks, T as effectiveUploadPartSize, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as ArchilS3Error, k as ArchilApiError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as DiskMultipart, x as Images, y as SandboxProcess } from "./src-BbjR-spO.mjs";
|
|
2
2
|
export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, ImageBuildError, Images, Sandbox, SandboxFileTransferError, SandboxFiles, SandboxPauseError, SandboxProcess, SandboxProcesses, Sandboxes, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
|
package/dist/internal/tools.cjs
CHANGED
|
@@ -250,9 +250,9 @@ const SPECS = [
|
|
|
250
250
|
}),
|
|
251
251
|
defineSpec({
|
|
252
252
|
name: "grep",
|
|
253
|
-
description: "Search file contents for
|
|
253
|
+
description: "Search file contents for a regular expression and return matching lines as path:line: text. Searches recursively by default.",
|
|
254
254
|
schema: zod.z.object({
|
|
255
|
-
pattern: zod.z.string().describe("
|
|
255
|
+
pattern: zod.z.string().describe("Regex in ripgrep (Rust) syntax, without lookaround or backreferences."),
|
|
256
256
|
path: zod.z.string().optional().describe("Directory to search (optional)."),
|
|
257
257
|
recursive: zod.z.boolean().optional().describe("Search subdirectories (default true)."),
|
|
258
258
|
maxResults: zod.z.number().int().optional().describe("Cap on matches (default 200).")
|
package/dist/internal/tools.mjs
CHANGED
|
@@ -249,9 +249,9 @@ const SPECS = [
|
|
|
249
249
|
}),
|
|
250
250
|
defineSpec({
|
|
251
251
|
name: "grep",
|
|
252
|
-
description: "Search file contents for
|
|
252
|
+
description: "Search file contents for a regular expression and return matching lines as path:line: text. Searches recursively by default.",
|
|
253
253
|
schema: z.object({
|
|
254
|
-
pattern: z.string().describe("
|
|
254
|
+
pattern: z.string().describe("Regex in ripgrep (Rust) syntax, without lookaround or backreferences."),
|
|
255
255
|
path: z.string().optional().describe("Directory to search (optional)."),
|
|
256
256
|
recursive: z.boolean().optional().describe("Search subdirectories (default true)."),
|
|
257
257
|
maxResults: z.number().int().optional().describe("Cap on matches (default 200).")
|
package/dist/sandbox-cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { k as ArchilApiError, p as Archil } from "./src-
|
|
3
|
-
import { a as
|
|
2
|
+
import { k as ArchilApiError, p as Archil } from "./src-BbjR-spO.mjs";
|
|
3
|
+
import { a as addGlobalOptions, c as resolveProgramCredentials, i as validateSandboxName, l as renderTable, n as parseCreateSandboxOptions, o as addProfileCommands, r as parseRunOptions, s as isProfileCommand } from "./sandbox-options-VBQ-AsOP.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { spinner } from "@clack/prompts";
|
|
@@ -64,50 +64,6 @@ function formatSandbox(sandbox, format) {
|
|
|
64
64
|
return renderTable(rows.filter(([, value]) => value !== ""));
|
|
65
65
|
}
|
|
66
66
|
//#endregion
|
|
67
|
-
//#region src/cli/sandbox-options.ts
|
|
68
|
-
function validateSandboxName(name) {
|
|
69
|
-
if (name === void 0) return void 0;
|
|
70
|
-
const value = name.trim();
|
|
71
|
-
if (!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(value)) throw new Error("Name must be 1–63 lowercase letters, numbers, or hyphens and cannot start or end with a hyphen");
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
|
-
function optionalInteger(value, label, min, max) {
|
|
75
|
-
if (value === void 0) return void 0;
|
|
76
|
-
const parsed = Number(value);
|
|
77
|
-
if (!Number.isInteger(parsed) || parsed < min || parsed > max) throw new Error(`${label} must be an integer from ${min} to ${max}`);
|
|
78
|
-
return parsed;
|
|
79
|
-
}
|
|
80
|
-
function parseEnvironment(entries) {
|
|
81
|
-
if (entries.length === 0) return void 0;
|
|
82
|
-
const environment = {};
|
|
83
|
-
for (const entry of entries) {
|
|
84
|
-
const separator = entry.indexOf("=");
|
|
85
|
-
if (separator <= 0) throw new Error(`Invalid environment entry '${entry}'; use NAME=value`);
|
|
86
|
-
const name = entry.slice(0, separator);
|
|
87
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid environment variable name '${name}'`);
|
|
88
|
-
environment[name] = entry.slice(separator + 1);
|
|
89
|
-
}
|
|
90
|
-
return environment;
|
|
91
|
-
}
|
|
92
|
-
function parseCreateSandboxOptions(name, options) {
|
|
93
|
-
return {
|
|
94
|
-
name: validateSandboxName(name),
|
|
95
|
-
vcpuCount: optionalInteger(options.vcpuCount, "CPU count", 1, 32),
|
|
96
|
-
memSizeMiB: optionalInteger(options.memSizeMib, "Memory", 256, 65536),
|
|
97
|
-
baseImage: options.baseImage,
|
|
98
|
-
maxTtlSeconds: optionalInteger(options.maxTtlSeconds, "Max TTL", 1, 2147483647),
|
|
99
|
-
idleTtlSeconds: optionalInteger(options.idleTtlSeconds, "Idle TTL", 0, 86400),
|
|
100
|
-
maxConcurrentExecs: optionalInteger(options.maxConcurrentProcesses, "Max concurrent processes", 1, 1024),
|
|
101
|
-
env: parseEnvironment(options.env)
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function parseRunOptions(options) {
|
|
105
|
-
return {
|
|
106
|
-
env: parseEnvironment(options.env),
|
|
107
|
-
timeoutSeconds: optionalInteger(options.timeout, "Timeout", 1, 2147483647)
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
67
|
//#region src/cli/sandbox-shell.ts
|
|
112
68
|
async function runSandboxShell(options) {
|
|
113
69
|
const stdin = options.stdin ?? process.stdin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as REGION_URLS, p as Archil } from "./src-
|
|
1
|
+
import { O as REGION_URLS, p as Archil } from "./src-BbjR-spO.mjs";
|
|
2
2
|
import { Option } from "commander";
|
|
3
3
|
import { isCancel, password, spinner } from "@clack/prompts";
|
|
4
4
|
import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
|
|
@@ -303,4 +303,48 @@ function addProfileCommands(program, validateCredential = validateCredentialAndR
|
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
//#endregion
|
|
306
|
-
|
|
306
|
+
//#region src/cli/sandbox-options.ts
|
|
307
|
+
function validateSandboxName(name) {
|
|
308
|
+
if (name === void 0) return void 0;
|
|
309
|
+
const value = name.trim();
|
|
310
|
+
if (!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(value)) throw new Error("Name must be 1–63 lowercase letters, numbers, or hyphens and cannot start or end with a hyphen");
|
|
311
|
+
return value;
|
|
312
|
+
}
|
|
313
|
+
function optionalInteger(value, label, min, max) {
|
|
314
|
+
if (value === void 0) return void 0;
|
|
315
|
+
const parsed = Number(value);
|
|
316
|
+
if (!Number.isInteger(parsed) || parsed < min || parsed > max) throw new Error(`${label} must be an integer from ${min} to ${max}`);
|
|
317
|
+
return parsed;
|
|
318
|
+
}
|
|
319
|
+
function parseEnvironment(entries) {
|
|
320
|
+
if (entries.length === 0) return void 0;
|
|
321
|
+
const environment = {};
|
|
322
|
+
for (const entry of entries) {
|
|
323
|
+
const separator = entry.indexOf("=");
|
|
324
|
+
if (separator <= 0) throw new Error(`Invalid environment entry '${entry}'; use NAME=value`);
|
|
325
|
+
const name = entry.slice(0, separator);
|
|
326
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid environment variable name '${name}'`);
|
|
327
|
+
environment[name] = entry.slice(separator + 1);
|
|
328
|
+
}
|
|
329
|
+
return environment;
|
|
330
|
+
}
|
|
331
|
+
function parseCreateSandboxOptions(name, options) {
|
|
332
|
+
return {
|
|
333
|
+
name: validateSandboxName(name),
|
|
334
|
+
vcpuCount: optionalInteger(options.vcpuCount, "CPU count", 1, 32),
|
|
335
|
+
memSizeMiB: optionalInteger(options.memSizeMib, "Memory", 256, 65536),
|
|
336
|
+
baseImage: options.baseImage,
|
|
337
|
+
maxTtlSeconds: optionalInteger(options.maxTtlSeconds, "Max TTL", 1, 2147483647),
|
|
338
|
+
idleTtlSeconds: optionalInteger(options.idleTtlSeconds, "Idle TTL", 0, 86400),
|
|
339
|
+
maxConcurrentExecs: optionalInteger(options.maxConcurrentProcesses, "Max concurrent processes", 1, 1024),
|
|
340
|
+
env: parseEnvironment(options.env)
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function parseRunOptions(options) {
|
|
344
|
+
return {
|
|
345
|
+
env: parseEnvironment(options.env),
|
|
346
|
+
timeoutSeconds: optionalInteger(options.timeout, "Timeout", 1, 2147483647)
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
export { addGlobalOptions as a, resolveProgramCredentials as c, validateSandboxName as i, renderTable as l, parseCreateSandboxOptions as n, addProfileCommands as o, parseRunOptions as r, isProfileCommand as s, optionalInteger as t };
|
|
@@ -140,7 +140,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
140
140
|
}
|
|
141
141
|
//#endregion
|
|
142
142
|
//#region src/version.ts
|
|
143
|
-
const VERSION = "1.
|
|
143
|
+
const VERSION = "1.11.0";
|
|
144
144
|
const USER_AGENT = `archil-js/${VERSION}`;
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region src/client.ts
|
|
@@ -442,6 +442,23 @@ var Disk = class {
|
|
|
442
442
|
await this.removeUser("token", identifier);
|
|
443
443
|
}
|
|
444
444
|
/**
|
|
445
|
+
* Create an S3 access key pair for this disk's S3 API. The secret key is
|
|
446
|
+
* returned only here. The keys reach the whole disk, read-write unless
|
|
447
|
+
* `readOnly` is set, so keep them server-side and give browsers presigned
|
|
448
|
+
* URLs instead.
|
|
449
|
+
*/
|
|
450
|
+
async createS3Credentials(options = {}) {
|
|
451
|
+
const user = await this.addUser({
|
|
452
|
+
...options,
|
|
453
|
+
type: "s3"
|
|
454
|
+
});
|
|
455
|
+
if (!user.s3AccessKeyId || !user.s3SecretKey || !user.identifier) throw new Error("Server did not return generated S3 credentials");
|
|
456
|
+
return user;
|
|
457
|
+
}
|
|
458
|
+
async removeS3Credentials(accessKeyId) {
|
|
459
|
+
await this.removeUser("s3", accessKeyId);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
445
462
|
* List all delegations currently held on this disk. A delegation grants a
|
|
446
463
|
* client exclusive write access to an inode; it has no ID of its own and is
|
|
447
464
|
* identified by the (clientId, inodeId) pair — pass those to
|
|
@@ -558,7 +575,14 @@ var Disk = class {
|
|
|
558
575
|
recursive: opts.recursive ?? false,
|
|
559
576
|
maxDurationSeconds: opts.maxDurationSeconds ?? 30,
|
|
560
577
|
concurrency: opts.concurrency ?? 50,
|
|
561
|
-
maxResults: opts.maxResults ?? 1e3
|
|
578
|
+
maxResults: opts.maxResults ?? 1e3,
|
|
579
|
+
ignoreCase: opts.ignoreCase,
|
|
580
|
+
multiline: opts.multiline,
|
|
581
|
+
globs: opts.globs,
|
|
582
|
+
types: opts.types,
|
|
583
|
+
typesNot: opts.typesNot,
|
|
584
|
+
contextBefore: opts.contextBefore ?? 0,
|
|
585
|
+
contextAfter: opts.contextAfter ?? 0
|
|
562
586
|
}
|
|
563
587
|
}), "transient"));
|
|
564
588
|
}
|
|
@@ -2345,6 +2369,30 @@ var Tokens = class {
|
|
|
2345
2369
|
function isExecMountSpec$1(m) {
|
|
2346
2370
|
return typeof m === "object" && m !== null && "disk" in m;
|
|
2347
2371
|
}
|
|
2372
|
+
/** Keep groups up to the one holding the `maxResults`-th match, and end that
|
|
2373
|
+
* group after up to `after` more lines, which become context so the groups
|
|
2374
|
+
* hold exactly the kept matches. With multiline, a run of matching lines is
|
|
2375
|
+
* one match. Mirrors the controlplane's truncation of a single disk's groups. */
|
|
2376
|
+
function truncateGroups(groups, maxResults, after, multiline) {
|
|
2377
|
+
let seen = 0;
|
|
2378
|
+
for (let i = 0; i < groups.length; i++) {
|
|
2379
|
+
const lines = groups[i].lines;
|
|
2380
|
+
for (let j = 0; j < lines.length; j++) {
|
|
2381
|
+
if (lines[j].match && !(multiline && j > 0 && lines[j - 1].match)) seen++;
|
|
2382
|
+
if (seen === maxResults && !(multiline && j + 1 < lines.length && lines[j + 1].match)) {
|
|
2383
|
+
const kept = lines.slice(0, Math.min(j + 1 + after, lines.length)).map((l, k) => k > j ? {
|
|
2384
|
+
...l,
|
|
2385
|
+
match: false
|
|
2386
|
+
} : l);
|
|
2387
|
+
return [...groups.slice(0, i), {
|
|
2388
|
+
...groups[i],
|
|
2389
|
+
lines: kept
|
|
2390
|
+
}];
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
return groups;
|
|
2395
|
+
}
|
|
2348
2396
|
/**
|
|
2349
2397
|
* A key-routed filesystem spanning several Archil disks. Each disk is mounted
|
|
2350
2398
|
* under a name and addressed as the first segment of a key (`<name>/...`);
|
|
@@ -2441,6 +2489,46 @@ var Workspace = class {
|
|
|
2441
2489
|
rel: this.diskKey(entry, segs.slice(1).join("/"))
|
|
2442
2490
|
}];
|
|
2443
2491
|
}
|
|
2492
|
+
/** Route grep globs written against the workspace root to the mounts they
|
|
2493
|
+
* can match. A glob that starts with a mount's name goes to that mount without
|
|
2494
|
+
* the name. One with no `/`, or that starts with `**` + `/` with or without a
|
|
2495
|
+
* leading `/`, goes to every mount as written, and also applies to a mount it
|
|
2496
|
+
* names exactly, like `!cache` or `**` + `/logs/**`. Mount names are matched
|
|
2497
|
+
* literally, so `!l*` doesn't skip a `logs` mount. Leaves out a mount whose
|
|
2498
|
+
* directory an exclude names, or that no include reaches, and throws for any
|
|
2499
|
+
* other glob with a `/`. */
|
|
2500
|
+
rootGlobs(globs) {
|
|
2501
|
+
const routed = new Map([...this.mounts.keys()].map((name) => [name, []]));
|
|
2502
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
2503
|
+
for (const glob of globs) {
|
|
2504
|
+
const exclude = glob.startsWith("!");
|
|
2505
|
+
let body = exclude ? glob.slice(1) : glob;
|
|
2506
|
+
const dirOnly = body.endsWith("/");
|
|
2507
|
+
if (dirOnly) body = body.slice(0, -1);
|
|
2508
|
+
const anchored = body.startsWith("/");
|
|
2509
|
+
if (anchored) body = body.slice(1);
|
|
2510
|
+
const everywhere = !anchored && !body.includes("/") || body === "**" || body.startsWith("**/");
|
|
2511
|
+
if (everywhere) for (const mountGlobs of routed.values()) mountGlobs.push(glob);
|
|
2512
|
+
const path = everywhere && body.startsWith("**/") ? body.slice(3) : body;
|
|
2513
|
+
const slash = path.indexOf("/");
|
|
2514
|
+
const name = slash < 0 ? path : path.slice(0, slash);
|
|
2515
|
+
const rest = slash < 0 ? "" : path.slice(slash + 1);
|
|
2516
|
+
const mountGlobs = routed.get(name);
|
|
2517
|
+
if (!mountGlobs) {
|
|
2518
|
+
if (everywhere) continue;
|
|
2519
|
+
throw new Error(`At the workspace root, a glob with a '/' must start with a mount name (${this.diskNames().map((n) => `${n}/`).join(", ")}) or '**/'; got '${glob}'. To search below one mount, set directory to it.`);
|
|
2520
|
+
}
|
|
2521
|
+
if (rest === "") {
|
|
2522
|
+
if (exclude) excluded.add(name);
|
|
2523
|
+
else excluded.delete(name);
|
|
2524
|
+
continue;
|
|
2525
|
+
}
|
|
2526
|
+
mountGlobs.push(`${exclude ? "!" : ""}${rest.includes("/") ? rest : `/${rest}`}${dirOnly ? "/" : ""}`);
|
|
2527
|
+
}
|
|
2528
|
+
const hasInclude = globs.some((glob) => !glob.startsWith("!"));
|
|
2529
|
+
for (const [name, mountGlobs] of routed) if (excluded.has(name) || hasInclude && mountGlobs.every((glob) => glob.startsWith("!"))) routed.delete(name);
|
|
2530
|
+
return routed;
|
|
2531
|
+
}
|
|
2444
2532
|
/** Map a workspace-relative key to the disk's key, applying the mount's subdirectory. */
|
|
2445
2533
|
diskKey(entry, rel) {
|
|
2446
2534
|
const trimmed = rel.replace(/^\/+/, "");
|
|
@@ -2511,13 +2599,38 @@ var Workspace = class {
|
|
|
2511
2599
|
keyCount
|
|
2512
2600
|
};
|
|
2513
2601
|
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Grep the disks `directory` covers in parallel and merge their results. At
|
|
2604
|
+
* the workspace root, a glob with a `/` must start with a mount name, like
|
|
2605
|
+
* `data/src/**`, which applies to that mount only, or with `**` + `/`. A glob
|
|
2606
|
+
* with no `/`, like `*.ts`, or one starting with `**` + `/` with or without a
|
|
2607
|
+
* leading `/`, applies inside every mount, and also to a mount it names
|
|
2608
|
+
* exactly, so `!cache` skips the cache mount. Mount names are matched
|
|
2609
|
+
* literally, not as patterns: `!l*` applies inside every mount, but doesn't
|
|
2610
|
+
* skip a mount named `logs`.
|
|
2611
|
+
*/
|
|
2514
2612
|
async grep(opts) {
|
|
2515
|
-
const
|
|
2516
|
-
const
|
|
2613
|
+
const directory = opts.directory ?? "";
|
|
2614
|
+
const rootGlobs = toSegments(directory).length === 0 && opts.globs?.length ? this.rootGlobs(opts.globs) : void 0;
|
|
2615
|
+
const covered = this.covered(directory).flatMap((c) => {
|
|
2616
|
+
if (rootGlobs === void 0) return [{
|
|
2617
|
+
...c,
|
|
2618
|
+
globs: opts.globs
|
|
2619
|
+
}];
|
|
2620
|
+
const globs = rootGlobs.get(c.name);
|
|
2621
|
+
return globs === void 0 ? [] : [{
|
|
2622
|
+
...c,
|
|
2623
|
+
globs
|
|
2624
|
+
}];
|
|
2625
|
+
});
|
|
2626
|
+
const results = await Promise.allSettled(covered.map(({ entry, rel, globs }) => entry.disk.grep({
|
|
2517
2627
|
...opts,
|
|
2518
|
-
directory: rel
|
|
2628
|
+
directory: rel,
|
|
2629
|
+
globs
|
|
2519
2630
|
})));
|
|
2631
|
+
for (const settled of results) if (settled.status === "rejected" && settled.reason instanceof ArchilApiError && settled.reason.status === 400) throw settled.reason;
|
|
2520
2632
|
const matches = [];
|
|
2633
|
+
const groups = [];
|
|
2521
2634
|
let filesScanned = 0;
|
|
2522
2635
|
let containersDispatched = 0;
|
|
2523
2636
|
let computeSecondsUsed = 0;
|
|
@@ -2540,9 +2653,12 @@ var Workspace = class {
|
|
|
2540
2653
|
grepMs = Math.max(grepMs, r.grepMs ?? 0);
|
|
2541
2654
|
reasons.add(r.stoppedReason);
|
|
2542
2655
|
for (const m of r.matches) matches.push({
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2656
|
+
...m,
|
|
2657
|
+
file: this.abs(name, entry, m.file)
|
|
2658
|
+
});
|
|
2659
|
+
for (const g of r.groups ?? []) groups.push({
|
|
2660
|
+
...g,
|
|
2661
|
+
file: this.abs(name, entry, g.file)
|
|
2546
2662
|
});
|
|
2547
2663
|
});
|
|
2548
2664
|
const cap = opts.maxResults ?? 1e3;
|
|
@@ -2554,8 +2670,10 @@ var Workspace = class {
|
|
|
2554
2670
|
"max_results"
|
|
2555
2671
|
];
|
|
2556
2672
|
const stoppedReason = [...reasons].every((x) => x === "completed") ? "completed" : priority.find((x) => reasons.has(x)) ?? "completed";
|
|
2673
|
+
const withGroups = (opts.contextBefore ?? 0) > 0 || (opts.contextAfter ?? 0) > 0;
|
|
2557
2674
|
return {
|
|
2558
2675
|
matches: matches.slice(0, cap),
|
|
2676
|
+
...withGroups && { groups: matches.length > cap ? truncateGroups(groups, cap, opts.contextAfter ?? 0, opts.multiline ?? false) : groups },
|
|
2559
2677
|
stoppedReason,
|
|
2560
2678
|
filesScanned,
|
|
2561
2679
|
containersDispatched,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "disk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Pure-JS client and CLIs for Archil disks and sandboxes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"archil",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"LICENSE"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@archildata/api-types": "^0.0.
|
|
43
|
+
"@archildata/api-types": "^0.0.78",
|
|
44
44
|
"@clack/prompts": "^1.7.0",
|
|
45
45
|
"commander": "^14.0.3",
|
|
46
46
|
"fast-xml-parser": "^5.7.0",
|