@trama-dev/runtime 0.4.0 → 0.6.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.
Files changed (56) hide show
  1. package/README.md +4 -3
  2. package/dist/abort.d.ts +12 -0
  3. package/dist/abort.js +31 -0
  4. package/dist/agent-backend.d.ts +127 -7
  5. package/dist/agent-backend.js +38 -19
  6. package/dist/agent-host.d.ts +50 -0
  7. package/dist/agent-host.js +97 -0
  8. package/dist/agent-hosts.d.ts +14 -0
  9. package/dist/agent-hosts.js +321 -0
  10. package/dist/agent.d.ts +26 -3
  11. package/dist/agent.js +165 -43
  12. package/dist/bridge-client.d.ts +6 -0
  13. package/dist/bridge-client.js +69 -16
  14. package/dist/budget.d.ts +52 -0
  15. package/dist/budget.js +118 -0
  16. package/dist/child-process.d.ts +18 -0
  17. package/dist/child-process.js +38 -9
  18. package/dist/client.d.ts +2 -1
  19. package/dist/client.js +9 -19
  20. package/dist/context.d.ts +36 -7
  21. package/dist/context.js +83 -92
  22. package/dist/errors.d.ts +2 -0
  23. package/dist/errors.js +2 -0
  24. package/dist/index.d.ts +7 -2
  25. package/dist/index.js +254 -88
  26. package/dist/ipc-server.d.ts +14 -5
  27. package/dist/ipc-server.js +174 -144
  28. package/dist/journal-view.d.ts +2 -0
  29. package/dist/journal-view.js +52 -7
  30. package/dist/journal.d.ts +27 -9
  31. package/dist/journal.js +216 -79
  32. package/dist/meta.d.ts +18 -0
  33. package/dist/meta.js +29 -0
  34. package/dist/model-relay.d.ts +130 -0
  35. package/dist/model-relay.js +339 -0
  36. package/dist/path-guard.d.ts +128 -19
  37. package/dist/path-guard.js +384 -68
  38. package/dist/pi-adapter.d.ts +35 -9
  39. package/dist/pi-adapter.js +865 -66
  40. package/dist/replace-file.d.ts +31 -0
  41. package/dist/replace-file.js +75 -0
  42. package/dist/runner-types.d.ts +35 -0
  43. package/dist/runner.d.ts +202 -30
  44. package/dist/runner.js +949 -273
  45. package/dist/serializable.d.ts +10 -4
  46. package/dist/serializable.js +56 -31
  47. package/dist/stopping.d.ts +37 -3
  48. package/dist/stopping.js +167 -21
  49. package/dist/tools.d.ts +2 -1
  50. package/dist/tools.js +90 -21
  51. package/dist/tree.d.ts +241 -0
  52. package/dist/tree.js +1431 -0
  53. package/dist/types.d.ts +106 -15
  54. package/dist/workspace.d.ts +7 -0
  55. package/dist/workspace.js +93 -104
  56. package/package.json +1 -1
@@ -0,0 +1,339 @@
1
+ // Asking a model for a session that is in another process.
2
+ //
3
+ // A call that has extensions is served by pi in a process of its own (see
4
+ // agent-host.ts), and what an extension is free to do there it can do to what
5
+ // that process says of itself: what the call used, among it. So where it can
6
+ // be, the model is asked by a process no extension is in — the runner, or a
7
+ // process of the runner's that was started with the variables of the run —
8
+ // and the session is handed the reply as it comes. What the reply used is
9
+ // then read where it was asked for, and is nobody's word.
10
+ //
11
+ // Where it can be: the model has to be the same to both, and the request one
12
+ // that is made of plain data. A session whose model the other side has not
13
+ // got as the session has it, or whose request an extension has a hand in,
14
+ // asks its model itself, as it always did — and what it used is what its
15
+ // process says. This is not a wall: pi does not hold an extension to it.
16
+ //
17
+ // Three things are here: the one that asks (createModelRelay), and the two
18
+ // ends of a channel between it and a session (relayClient, relayServer).
19
+ import { createRequire } from "module";
20
+ import { pathToFileURL } from "url";
21
+ import { onAbort } from "./abort.js";
22
+ import { messageOf } from "./errors.js";
23
+ const loadPi = () => import("@earendil-works/pi-coding-agent");
24
+ /** The options of a request that are data, and mean something to a provider. (The rest is pi's agent's own, and functions.) */
25
+ const DATA_OPTIONS = [
26
+ "temperature", "samplingParams", "maxTokens", "transport", "cacheRetention", "sessionId", "disableContinuation",
27
+ "websocketConnectTimeoutMs", "metadata", "toolChoice", "reasoning", "thinkingBudgets", "env", "headers", "identity",
28
+ "timeoutMs", "maxRetries", "maxRetryDelayMs",
29
+ ];
30
+ /**
31
+ * Of the options a session asks with, those that go with a relayed request —
32
+ * or undefined where one is there that cannot go, and would be missed: a key
33
+ * of the asker's own, a way of its own to reach the provider, a reply that is
34
+ * to be fetched later.
35
+ */
36
+ export function dataOf(options = {}) {
37
+ if (["apiKey", "fetch", "telemetry", "deferred"].some(key => options[key] !== undefined))
38
+ return undefined;
39
+ return Object.fromEntries(DATA_OPTIONS.filter(key => options[key] !== undefined).map(key => [key, options[key]]));
40
+ }
41
+ /** What the reply an event is the last of used — undefined of any other event. */
42
+ export function usageAtEnd(event) {
43
+ const reply = event.type === "done" ? event.message : event.type === "error" ? event.error : undefined;
44
+ return reply?.usage;
45
+ }
46
+ /**
47
+ * The event that ends a reply the model was not asked for: as pi makes the
48
+ * reply of a request that was cancelled before it was sent. (Said as one that
49
+ * was cancelled, whyever it was: pi reads the words of a reply that failed —
50
+ * for a number that looks like a server's, to try again; for a limit, to sum
51
+ * the conversation up — and a request that is not to be made is neither.)
52
+ */
53
+ export function notAsked(model, why, as = "aborted") {
54
+ return {
55
+ type: "error",
56
+ reason: as,
57
+ error: {
58
+ role: "assistant", content: [], api: model.api, provider: model.provider, model: model.id,
59
+ usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
60
+ stopReason: as, errorMessage: why, timestamp: Date.now(),
61
+ },
62
+ };
63
+ }
64
+ // --- An event without the reply so far, and with it again ---
65
+ // Every event of a reply but the last carries `partial`: the whole reply so
66
+ // far. Sent as they are, a reply's events grow with the square of its length.
67
+ // And `partial` is one object that pi goes on changing: read a moment late,
68
+ // it holds what later events bring. So an event is sent with what it adds —
69
+ // text and thinking as their delta, anything else as the one block it is of
70
+ // (see `leaner`) — and the reply so far is put together again where it is
71
+ // wanted.
72
+ const wordsOf = (type) => type.startsWith("text_") ? "text" : type.startsWith("thinking_") ? "thinking" : undefined;
73
+ /** How much of a tool call's arguments is sent whole with every piece of them, before it is sent whole only as it grows by half again. */
74
+ const SMALL = 8 * 1024;
75
+ /**
76
+ * Makes of a reply's events the events as they are sent: without the reply
77
+ * so far. (One for each reply: it keeps how much of each tool call has been
78
+ * sent.) What an event adds is sent with it — but a tool call's arguments,
79
+ * which pi puts together from their pieces in its own way for each kind of
80
+ * provider, can only be sent whole: so they are, with every piece while they
81
+ * are short, and after that each time they have grown by half — and whole at
82
+ * their end. Whoever is shown a long tool call as it comes is shown its
83
+ * arguments as they were a little while before.
84
+ */
85
+ export function leaner() {
86
+ const grown = new Map(), sent = new Map();
87
+ return (event) => {
88
+ if (event.type === "done" || event.type === "error")
89
+ return event;
90
+ const { partial, ...rest } = event;
91
+ const { content, ...top } = partial;
92
+ if (event.type === "start")
93
+ return { ...rest, top };
94
+ const at = rest.contentIndex, kind = wordsOf(event.type);
95
+ if (!kind) {
96
+ const now = (grown.get(at) ?? 0) + (typeof rest.delta === "string" ? rest.delta.length : 0);
97
+ grown.set(at, now);
98
+ const whole = !event.type.endsWith("_delta") || now <= SMALL || now >= (sent.get(at) ?? 0) * 1.5;
99
+ if (!whole)
100
+ return { ...rest, top };
101
+ sent.set(at, now);
102
+ return { ...rest, top, block: content[at] };
103
+ }
104
+ if (event.type.endsWith("_delta"))
105
+ return { ...rest, top };
106
+ // (Its beginning and its end: the block without its words, which are had from the deltas, or from `content`.)
107
+ const { [kind]: _words, ...around } = content[at] ?? {};
108
+ return { ...rest, top, around };
109
+ };
110
+ }
111
+ /** An event that was sent without the reply so far (see `leaner`), with it. */
112
+ export function whole(event, state) {
113
+ if (event.type === "done" || event.type === "error")
114
+ return event;
115
+ const { top, block, around, ...rest } = event;
116
+ const partial = state.partial = { ...state.partial, ...top, content: [...(state.partial?.content ?? [])] };
117
+ if (event.type === "start")
118
+ return { ...rest, partial };
119
+ const at = rest.contentIndex, was = partial.content[at] ?? {};
120
+ const kind = wordsOf(event.type);
121
+ if (!kind)
122
+ partial.content[at] = block ?? was;
123
+ else if (event.type.endsWith("_start"))
124
+ partial.content[at] = { ...around, [kind]: "" };
125
+ else if (event.type.endsWith("_delta"))
126
+ partial.content[at] = { ...was, [kind]: String(was[kind] ?? "") + String(rest.delta ?? "") };
127
+ else
128
+ partial.content[at] = { ...was, ...around, [kind]: rest.content };
129
+ return { ...rest, partial };
130
+ }
131
+ // --- The one that asks ---
132
+ /** What pi keeps for a session where its model is asked, let go of. (pi's own, had by its file: it is no part of what pi exports.) */
133
+ async function letGoOf(sessions) {
134
+ try {
135
+ const kept = createRequire(import.meta.resolve("@earendil-works/pi-coding-agent")).resolve("@earendil-works/pi-ai/compat");
136
+ const { cleanupSessionResources } = await import(pathToFileURL(kept).href);
137
+ for (const session of sessions)
138
+ cleanupSessionResources?.(session);
139
+ }
140
+ catch { /* what cannot be let go of is left: it is bounded where it is kept */ }
141
+ }
142
+ /**
143
+ * A relay that asks with this process's own pi: the models it finds, and the
144
+ * keys it has for their providers. Its events are sent ones (see `leaner`).
145
+ * `close` when whoever it asks for is done: what is still being asked is
146
+ * asked no further, and what was kept for it is let go of.
147
+ */
148
+ export function createModelRelay() {
149
+ let models;
150
+ const asking = new Set();
151
+ const sessions = new Set();
152
+ return {
153
+ async ask(request, signal) {
154
+ let reply;
155
+ const stop = new AbortController();
156
+ try {
157
+ const found = await (models ??= loadPi().then(pi => pi.ModelRuntime.create()));
158
+ const { provider, id } = request.model;
159
+ const own = found.getModel(provider, id);
160
+ // The same model, to the letter, with a key to ask it by — and a provider nobody has had a hand in.
161
+ if (!own || JSON.stringify(own) !== JSON.stringify(request.model) || !found.hasConfiguredAuth(provider))
162
+ return undefined;
163
+ // (What goes with a request is held to here as where it was sent from: whoever sent it may not be who should have.)
164
+ const options = dataOf(request.options);
165
+ if (!options)
166
+ return undefined;
167
+ if (typeof options.sessionId === "string")
168
+ sessions.add(options.sessionId);
169
+ reply = found.streamSimple(own, request.context, { ...options, signal: stop.signal });
170
+ }
171
+ catch {
172
+ // (A pi that cannot be had here is not one to ask by: whoever asked asks itself.)
173
+ models = undefined;
174
+ return undefined;
175
+ }
176
+ const off = onAbort(signal, () => stop.abort());
177
+ asking.add(stop);
178
+ const lean = leaner();
179
+ return (async function* () {
180
+ try {
181
+ for await (const event of reply)
182
+ yield lean(event);
183
+ }
184
+ catch (err) {
185
+ yield notAsked(request.model, `The model could not be asked: ${messageOf(err)}`, "error");
186
+ }
187
+ finally {
188
+ off();
189
+ asking.delete(stop);
190
+ }
191
+ })();
192
+ },
193
+ async close() {
194
+ for (const stop of asking)
195
+ stop.abort();
196
+ await letGoOf(sessions);
197
+ sessions.clear();
198
+ },
199
+ };
200
+ }
201
+ /**
202
+ * The asking end: a relay that is reached by messages. `heard` is to be told
203
+ * what the other end answers; `close` when the other end is gone — whatever
204
+ * is still waited for then ends as a request that failed, saying so (nobody
205
+ * cancelled it), and nothing more is asked by it.
206
+ */
207
+ export function relayClient(send) {
208
+ const waiting = new Map();
209
+ let ids = 0, closed = false;
210
+ return {
211
+ relay: {
212
+ ask: (request, signal) => new Promise((resolve) => {
213
+ if (closed)
214
+ return resolve(undefined);
215
+ // (Cancelled before it was asked: nothing is sent.)
216
+ if (signal?.aborted)
217
+ return resolve((async function* () { yield notAsked(request.model, "Aborted"); })());
218
+ const id = ++ids;
219
+ const events = [];
220
+ let wake = () => { }, begun = false;
221
+ const off = onAbort(signal, () => send({ relayAbort: id }));
222
+ const reply = async function* () {
223
+ try {
224
+ for (;;) {
225
+ const event = events.shift();
226
+ if (!event)
227
+ await new Promise((next) => { wake = next; });
228
+ else {
229
+ yield event;
230
+ if (event.type === "done" || event.type === "error")
231
+ return;
232
+ }
233
+ }
234
+ }
235
+ finally {
236
+ off();
237
+ waiting.delete(id);
238
+ }
239
+ };
240
+ const add = (event) => {
241
+ events.push(event);
242
+ wake();
243
+ if (!begun)
244
+ resolve(reply());
245
+ begun = true;
246
+ };
247
+ waiting.set(id, {
248
+ heard(answer) {
249
+ if ("event" in answer)
250
+ return add(answer.event);
251
+ // (Not one the other end can serve: nothing was asked.)
252
+ off();
253
+ waiting.delete(id);
254
+ if (!begun)
255
+ resolve(undefined);
256
+ },
257
+ end: () => add(notAsked(request.model, "The process that was asking the model ended before the reply had come.", "error")),
258
+ });
259
+ try {
260
+ send({ relay: { id, request } });
261
+ }
262
+ catch {
263
+ // (A request that cannot be put on the channel — something in it is not data — is one nobody served.)
264
+ off();
265
+ waiting.delete(id);
266
+ resolve(undefined);
267
+ }
268
+ }),
269
+ },
270
+ heard(answer) {
271
+ waiting.get(answer.id)?.heard(answer);
272
+ },
273
+ close() {
274
+ closed = true;
275
+ for (const request of [...waiting.values()])
276
+ request.end();
277
+ },
278
+ };
279
+ }
280
+ /**
281
+ * The answering end: serves, by `relay`, the requests that `heard` is told
282
+ * of. `refuse`: whether a request is not to be made at all (it then ends as
283
+ * one that was cancelled) — asked before each, and waited for; `replied`:
284
+ * told what each reply used, as its last event passes. `close`: what is
285
+ * still being asked is asked no further.
286
+ */
287
+ export function relayServer(relay, send, on = {}) {
288
+ const asking = new Map();
289
+ const serve = async (id, request, stop) => {
290
+ try {
291
+ if (await on.refuse?.(request))
292
+ return send({ relayed: { id, event: notAsked(request.model, "The call is to ask no more.") } });
293
+ const events = await relay.ask(request, stop.signal);
294
+ if (!events)
295
+ return send({ relayed: { id, not: true } });
296
+ for await (const event of events) {
297
+ const usage = usageAtEnd(event);
298
+ if (usage)
299
+ on.replied?.(usage);
300
+ send({ relayed: { id, event } });
301
+ }
302
+ }
303
+ catch (err) {
304
+ send({ relayed: { id, event: notAsked(request.model, `The model could not be asked: ${messageOf(err)}`, "error") } });
305
+ }
306
+ finally {
307
+ asking.delete(id);
308
+ }
309
+ };
310
+ return {
311
+ heard(message) {
312
+ if ("relayAbort" in message)
313
+ return asking.get(message.relayAbort)?.abort();
314
+ const { id, request } = message.relay;
315
+ const stop = new AbortController();
316
+ asking.set(id, stop);
317
+ void serve(id, request, stop);
318
+ },
319
+ close() {
320
+ for (const stop of asking.values())
321
+ stop.abort();
322
+ },
323
+ };
324
+ }
325
+ /** A relay whose events are sent ones, as one whose events are pi's own: each with the reply so far. */
326
+ export function withRepliesWhole(relay) {
327
+ return {
328
+ async ask(request, signal) {
329
+ const events = await relay.ask(request, signal);
330
+ if (!events)
331
+ return undefined;
332
+ return (async function* () {
333
+ const state = {};
334
+ for await (const event of events)
335
+ yield whole(event, state);
336
+ })();
337
+ },
338
+ };
339
+ }
@@ -1,27 +1,136 @@
1
+ import { type BigIntStats } from "fs";
1
2
  /**
2
- * Keep file access inside a bounded root directory (a project directory or a
3
- * session workspace) — rejecting escapes via ".." segments or symlinks.
4
- *
5
- * Not a security sandbox — just a footgun guard against malicious shared
6
- * projects where files like state.json or .gitignore are symlinks pointing
7
- * outside the project directory.
3
+ * A byte buffer as UTF-8 text — undefined if its bytes are not valid UTF-8.
4
+ * Leading BOM bytes are preserved as text rather than stripped.
5
+ */
6
+ export declare function utf8Text(raw: Buffer): string | undefined;
7
+ /**
8
+ * What a link says, as text — undefined if it says nothing a path can be made
9
+ * of: a name that is not valid UTF-8, or nothing at all (macOS lets a link to
10
+ * nothing be made, and then refuses every use of it).
8
11
  */
9
- /** True if `path` is `root` itself or lies underneath it. Both must already be normalized. */
10
- export declare function isInside(path: string, root: string): boolean;
12
+ export declare function linkText(link: string): string | undefined;
11
13
  /**
12
- * Resolve `relativePath` against `rootDir` and verify the logical path
13
- * stays within the root. Returns the resolved absolute path.
14
- * Catches ".." traversal only — use guardPath to also catch symlink escapes.
14
+ * The real (symlink-resolved) location of a root directory, whether or not it
15
+ * exists yet. A root is named by whoever runs the program, not by the
16
+ * program, and is read as the rest of Node reads a directory it is given.
15
17
  */
16
- export declare function resolveBounded(rootDir: string, relativePath: string): string;
17
- /** The real (symlink-resolved) location of a root directory, or its normalized path if it doesn't exist yet. */
18
18
  export declare function realRootOf(rootDir: string): string;
19
+ export declare const identityIn: (stat: BigIntStats) => string;
20
+ /**
21
+ * What tells one file or directory from every other — undefined if nothing is
22
+ * there to be told apart. Two paths with one identity are one place, however
23
+ * each is spelled; a link is itself, not what it points at.
24
+ *
25
+ * This is how the runtime asks whether two paths are the same. Their text
26
+ * cannot say: a file system that takes "Data" and "data" for one name has
27
+ * many names for every directory.
28
+ *
29
+ * Undefined says that nothing is there, and only that. What is there and may
30
+ * not be looked at is not nothing: it throws.
31
+ */
32
+ export declare function identityOf(path: string): string | undefined;
33
+ /** What the words of a link come to, read by one who means to keep a copy of the root they are in. */
34
+ export interface Lead {
35
+ /** The place they name. A link of the root that they end at is the place: what it names in turn is its own affair. */
36
+ to: string;
37
+ /**
38
+ * Whether the way there is in the root at one point and out of it at
39
+ * another: it steps out over the root's top, or into it from outside. If it
40
+ * does neither, the same words name the same place in any copy of the
41
+ * root, wherever the copy is.
42
+ */
43
+ strays: boolean;
44
+ /**
45
+ * What the words go on to say once they have come to the root from outside
46
+ * it (see `sinceRoot`) — provided they have not stepped out of it over its
47
+ * top again since. That much is said of the root, and says the same of a
48
+ * copy of it, wherever its links lead. Undefined if they never come to the
49
+ * root so, or step out of it afterwards: such a way, if it strays, ends
50
+ * outside the root.
51
+ */
52
+ home: string | undefined;
53
+ }
54
+ /**
55
+ * A reader of the links in `root` (named without links), for one who means
56
+ * to keep a copy of the root.
57
+ *
58
+ * It reads as a copy of the root would have to be read. A link of the root
59
+ * that a way passes through is not followed step by step but taken for the
60
+ * place it names: a copy has that link too, saying whatever it must to name
61
+ * the same place there, and how it says so is no part of the way. A link
62
+ * outside the root is nobody's copy, and is followed like any other step —
63
+ * to the end, also where the words end at it: what matters of it is where it
64
+ * leads.
65
+ *
66
+ * Whether a place is in the root is asked of the place (see underRoot), not
67
+ * read off its name: a way that has left the root may come back to it by any
68
+ * of the names the file system has for it.
69
+ */
70
+ export declare function linksOf(root: string): {
71
+ /**
72
+ * Where words lead, for a link that is in `dir`. Throws if the way cannot
73
+ * be followed: then what they name cannot be told, which is not the same
74
+ * as its being outside.
75
+ */
76
+ names(dir: string, text: string): Lead;
77
+ /**
78
+ * What the same words go on to say once they have come to the root from
79
+ * outside it — a slash first, if any more is said — or undefined if they
80
+ * never do. Where they come to it more than once, it is the last time that
81
+ * counts. (Coming to it is a step into it from outside. A link of the root
82
+ * that names the root is a step within it.) Whatever they say from there
83
+ * on, and wherever that leads, it is said of the root: to one who takes a
84
+ * copy for the root itself, it is the copy's name that the words before it
85
+ * come to. Told as far as the way can be followed: one that cannot be
86
+ * followed to its end has still come as far as it has.
87
+ */
88
+ sinceRoot(dir: string, text: string): string | undefined;
89
+ };
90
+ /**
91
+ * The places under a root that make a path lead where it does: every place
92
+ * the way comes to there — each name it steps to, each link it follows, each
93
+ * directory it goes through (also one it leaves again with ".."), and the
94
+ * place it ends at. With any of them another thing, or gone, the path leads
95
+ * somewhere else, or nowhere. Told as far as the way can be followed, each
96
+ * as the way names it — which need not be how its directory lists it.
97
+ */
98
+ export declare function wayTo(rootDir: string, path: string): string[];
99
+ /**
100
+ * Where a project is — which is a directory that is there. Nothing in the
101
+ * runtime makes one for a project that is gone: what it makes for a project,
102
+ * it makes in it. (Making the directories on the way to a file would make a
103
+ * project of that file, at the path of one that somebody has moved away.)
104
+ */
105
+ export declare function projectAt(projectDir: string): string;
106
+ /**
107
+ * A question to ask later: whether what is at a project's path is still the
108
+ * directory that is there now. A project is known by what it is, and what is
109
+ * done over some time — generate a program, ask for a fix, try it, install it,
110
+ * write it down — is done to the project it was started on: not to another
111
+ * directory that somebody has put at the path meanwhile. (Gone is not another:
112
+ * what is to be done where no project is, each step says for itself.)
113
+ */
114
+ export declare function sameProjectAs(projectDir: string): () => void;
115
+ /**
116
+ * Make a directory under a root, with those on the way to it — in the root,
117
+ * which must be there: no root is made for the sake of what goes into it.
118
+ * This is for a root that is something in itself — a project, which
119
+ * somebody may have moved away since it was named: making the directory
120
+ * anew at its path would make another, and put into it what was meant for
121
+ * the first. (A workspace is nothing but its path, and is made as needed,
122
+ * with the way to it.)
123
+ * `dir` is a place the guard has passed.
124
+ */
125
+ export declare function makeDirsIn(rootDir: string, dir: string): void;
19
126
  /**
20
- * The guard for reading or writing a path under a bounded root.
21
- * Checks both the logical path (".." segments) and symlink resolution,
22
- * and returns the resolved absolute path.
127
+ * The guard for reading or writing a path under a bounded root: where the
128
+ * path leads, every link on the way followed — refused unless that is inside
129
+ * the root, and a file, a directory, or nothing yet. What comes back has no
130
+ * link left in it, so using it goes where this looked.
23
131
  *
24
- * For paths that don't exist yet, checks the nearest existing ancestor —
25
- * so a caller can safely mkdir and write afterwards.
132
+ * A path that does not exist yet is followed as far as it does, so a caller
133
+ * can safely mkdir and write afterwards: a write lands on what a link points
134
+ * at, not on a link on the way.
26
135
  */
27
- export declare function guardPath(rootDir: string, relativePath: string): string;
136
+ export declare function guardPath(rootDir: string, path: string): string;