@trama-dev/runtime 0.6.0 → 0.7.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 (57) hide show
  1. package/dist/agent-backend.d.ts +51 -0
  2. package/dist/agent-backend.js +4 -0
  3. package/dist/agent-host.d.ts +46 -7
  4. package/dist/agent-host.js +59 -19
  5. package/dist/agent-hosts.js +122 -56
  6. package/dist/agent.d.ts +16 -5
  7. package/dist/agent.js +22 -64
  8. package/dist/bridge-client.d.ts +6 -2
  9. package/dist/bridge-client.js +6 -1
  10. package/dist/client.d.ts +2 -2
  11. package/dist/client.js +126 -2
  12. package/dist/context.js +3 -2
  13. package/dist/history.d.ts +9 -0
  14. package/dist/history.js +98 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +70 -41
  17. package/dist/ipc-server.d.ts +2 -3
  18. package/dist/ipc-server.js +93 -37
  19. package/dist/journal-view.js +19 -9
  20. package/dist/journal.d.ts +10 -4
  21. package/dist/journal.js +28 -6
  22. package/dist/merge-deeds.d.ts +22 -0
  23. package/dist/merge-deeds.js +201 -0
  24. package/dist/merge-doing.d.ts +9 -0
  25. package/dist/merge-doing.js +410 -0
  26. package/dist/merge-settle.d.ts +14 -0
  27. package/dist/merge-settle.js +166 -0
  28. package/dist/merge-shared.d.ts +64 -0
  29. package/dist/merge-shared.js +159 -0
  30. package/dist/merge.d.ts +150 -0
  31. package/dist/merge.js +209 -0
  32. package/dist/model-relay.d.ts +63 -5
  33. package/dist/model-relay.js +206 -23
  34. package/dist/own-tools.d.ts +60 -0
  35. package/dist/own-tools.js +209 -0
  36. package/dist/path-guard.js +8 -6
  37. package/dist/pi-adapter.d.ts +22 -0
  38. package/dist/pi-adapter.js +294 -72
  39. package/dist/project.d.ts +31 -0
  40. package/dist/project.js +253 -0
  41. package/dist/replace-file.d.ts +13 -2
  42. package/dist/replace-file.js +23 -6
  43. package/dist/runner-backend.d.ts +43 -0
  44. package/dist/runner-backend.js +125 -0
  45. package/dist/runner-types.d.ts +8 -0
  46. package/dist/runner.d.ts +8 -123
  47. package/dist/runner.js +57 -453
  48. package/dist/schema.d.ts +38 -0
  49. package/dist/schema.js +104 -0
  50. package/dist/stopping.js +2 -3
  51. package/dist/tools.js +31 -7
  52. package/dist/tree.d.ts +33 -149
  53. package/dist/tree.js +43 -1077
  54. package/dist/types.d.ts +54 -2
  55. package/dist/workspace.d.ts +20 -0
  56. package/dist/workspace.js +76 -12
  57. package/package.json +2 -2
@@ -0,0 +1,38 @@
1
+ declare const PRIMITIVES: readonly ["string", "number", "boolean"];
2
+ type SchemaPrimitive = (typeof PRIMITIVES)[number];
3
+ /** What a schema says a value is to be: a primitive by its name, an object by its fields, a list by the one shape all its items have. */
4
+ export type Shape = SchemaPrimitive | {
5
+ fields: Array<[string, Shape]>;
6
+ } | {
7
+ items: Shape;
8
+ };
9
+ /** Where a value is in an answer, in words: null for the answer itself, and under that each field by its name. */
10
+ type Where = string | null;
11
+ /**
12
+ * Read the caller's schema declaration, up front: what the value at `where`
13
+ * is to be. In words — "string", "number", "boolean", where what follows a
14
+ * ":" describes the value to the model and is not read here — or an object
15
+ * of such, or a list of one element: the shape of every item.
16
+ */
17
+ export declare function shapeOf(declared: unknown, where?: Where): Shape;
18
+ /**
19
+ * What a tool is called with, declared as a typed answer's shape is: the
20
+ * fields of an object. `schema` says it as JSON Schema, which is how a model
21
+ * is told; `held` holds what a tool is about to be called with to it, as a
22
+ * typed answer is held to its shape — returning the declared fields and no
23
+ * others, or throwing what is wrong. (A schema that is not one is an error,
24
+ * as it is of an answer.)
25
+ */
26
+ export declare function argumentsOf(declared: unknown): {
27
+ schema: Record<string, unknown>;
28
+ held(args: unknown): unknown;
29
+ };
30
+ /** Whether a shape has a list anywhere in it. */
31
+ export declare const hasList: (shape: Shape) => boolean;
32
+ /**
33
+ * Shape validation and projection: verifies that the value at `where` is of
34
+ * the shape declared — every field there, every item of a list — and returns
35
+ * it holding the declared fields and no others.
36
+ */
37
+ export declare function conform(value: unknown, shape: Shape, where?: Where): unknown;
38
+ export {};
package/dist/schema.js ADDED
@@ -0,0 +1,104 @@
1
+ // The shapes a program declares: of a typed answer (`agent.generate`), and of
2
+ // what a tool of its own is called with. One way of writing them — a kind in
3
+ // a word, an object by its fields, a list by the shape of its items — read
4
+ // once into a shape, which a value is then held to.
5
+ import { isJsonObject } from "./serializable.js";
6
+ const PRIMITIVES = ["string", "number", "boolean"];
7
+ const isPrimitive = (named) => PRIMITIVES.includes(named);
8
+ /** How the two shapes that are not named in a word are written, for whoever named them in one. */
9
+ const HOW_WRITTEN = `a list is written as the shape of its items, in brackets: ["string"]; an object as its fields: { name: "string" }`;
10
+ const fieldOf = (where, key) => (where === null ? key : `${where}.${key}`);
11
+ /** A value's kind as a schema names it in a word — and what follows a ":" there: words for the model, of what the value is. */
12
+ function worded(word) {
13
+ const [kind, ...words] = word.split(":");
14
+ return { kind: kind.trim(), description: words.join(":").trim() };
15
+ }
16
+ /**
17
+ * Read the caller's schema declaration, up front: what the value at `where`
18
+ * is to be. In words — "string", "number", "boolean", where what follows a
19
+ * ":" describes the value to the model and is not read here — or an object
20
+ * of such, or a list of one element: the shape of every item.
21
+ */
22
+ export function shapeOf(declared, where = null) {
23
+ if (Array.isArray(declared)) {
24
+ if (declared.length !== 1) {
25
+ throw new Error(`Schema validation failed: the list at "${where}" is written with ${declared.length} elements — it takes one, the shape of every item`);
26
+ }
27
+ return { items: shapeOf(declared[0], `${where}[]`) };
28
+ }
29
+ if (isJsonObject(declared)) {
30
+ return { fields: Object.entries(declared).map(([key, value]) => [key, shapeOf(value, fieldOf(where, key))]) };
31
+ }
32
+ // (Anything else says nothing that is supported — and is said back as JSON would write it, which is no word for a kind.)
33
+ const named = typeof declared === "string" ? worded(declared).kind : JSON.stringify(declared);
34
+ if (!isPrimitive(named)) {
35
+ throw new Error(`Schema validation failed: unsupported schema type "${named}" for key "${where}" (${HOW_WRITTEN})`);
36
+ }
37
+ return named;
38
+ }
39
+ /** A schema as JSON Schema says it: every field there, and no other; what follows a ":" in a field's word describes it. */
40
+ function asJsonSchema(declared) {
41
+ if (Array.isArray(declared))
42
+ return { type: "array", items: asJsonSchema(declared[0]) };
43
+ if (isJsonObject(declared)) {
44
+ return {
45
+ type: "object",
46
+ properties: Object.fromEntries(Object.entries(declared).map(([key, value]) => [key, asJsonSchema(value)])),
47
+ required: Object.keys(declared),
48
+ additionalProperties: false,
49
+ };
50
+ }
51
+ const { kind, description } = worded(String(declared));
52
+ return { type: kind, ...(description && { description }) };
53
+ }
54
+ /**
55
+ * What a tool is called with, declared as a typed answer's shape is: the
56
+ * fields of an object. `schema` says it as JSON Schema, which is how a model
57
+ * is told; `held` holds what a tool is about to be called with to it, as a
58
+ * typed answer is held to its shape — returning the declared fields and no
59
+ * others, or throwing what is wrong. (A schema that is not one is an error,
60
+ * as it is of an answer.)
61
+ */
62
+ export function argumentsOf(declared) {
63
+ if (!isJsonObject(declared))
64
+ throw new Error("Schema validation failed: a tool's parameters are an object of the fields it is called with");
65
+ const shape = shapeOf(declared);
66
+ return {
67
+ schema: asJsonSchema(declared),
68
+ held(args) {
69
+ if (!isJsonObject(args))
70
+ throw new Error("Schema validation failed: the arguments are not an object");
71
+ return conform(args, shape);
72
+ },
73
+ };
74
+ }
75
+ /** Whether a shape has a list anywhere in it. */
76
+ export const hasList = (shape) => typeof shape !== "string" && ("items" in shape || shape.fields.some(([, field]) => hasList(field)));
77
+ /** What a value is, said as a reply is told of it. */
78
+ const said = (value) => value === null ? "null" : Array.isArray(value) ? "a list" : typeof value === "number" ? String(value) : typeof value;
79
+ /**
80
+ * Shape validation and projection: verifies that the value at `where` is of
81
+ * the shape declared — every field there, every item of a list — and returns
82
+ * it holding the declared fields and no others.
83
+ */
84
+ export function conform(value, shape, where = null) {
85
+ const mismatch = (expected) => new Error(`Schema validation failed: ${where}: expected ${expected}, got ${said(value)}`);
86
+ if (typeof shape === "string") {
87
+ if (typeof value !== shape || (shape === "number" && !Number.isFinite(value)))
88
+ throw mismatch(shape);
89
+ return value;
90
+ }
91
+ if ("items" in shape) {
92
+ if (!Array.isArray(value))
93
+ throw mismatch("a list");
94
+ return value.map((item, index) => conform(item, shape.items, `${where}[${index}]`));
95
+ }
96
+ if (!isJsonObject(value))
97
+ throw where === null ? new Error("Schema validation failed: response is not an object") : mismatch("an object");
98
+ return Object.fromEntries(shape.fields.map(([key, field]) => {
99
+ // (A field is the reply's own: what every object has by birth is not something a reply said.)
100
+ if (!Object.hasOwn(value, key))
101
+ throw new Error(`Schema validation failed: missing key: ${fieldOf(where, key)}`);
102
+ return [key, conform(value[key], field, fieldOf(where, key))];
103
+ }));
104
+ }
package/dist/stopping.js CHANGED
@@ -185,7 +185,6 @@ const processes = () => {
185
185
  }
186
186
  };
187
187
  const alive = (pgid) => signalGroup(pgid, 0);
188
- const signal = signalGroup;
189
188
 
190
189
  let unread = "";
191
190
  process.stdin.setEncoding("utf8");
@@ -212,7 +211,7 @@ const takeOver = () => {
212
211
  const rows = led.length > 0 ? processes() : [];
213
212
  const below = led.flatMap((pid) => groupsAmong(rows, pid, process.pid));
214
213
  let left = [...new Set([...lists.g, ...below])].filter(alive);
215
- for (const pgid of left) { if (!lists.asked.has(pgid)) signal(pgid, "SIGTERM"); }
214
+ for (const pgid of left) { if (!lists.asked.has(pgid)) signalGroup(pgid, "SIGTERM"); }
216
215
  let deadline = performance.now() + grace;
217
216
  let killed = false;
218
217
  const check = () => {
@@ -221,7 +220,7 @@ const takeOver = () => {
221
220
  if (left.length === 0) return finish();
222
221
  if (performance.now() < deadline) return;
223
222
  if (killed) return finish();
224
- for (const pgid of left) signal(pgid, "SIGKILL");
223
+ for (const pgid of left) signalGroup(pgid, "SIGKILL");
225
224
  killed = true;
226
225
  deadline = performance.now() + settle;
227
226
  };
package/dist/tools.js CHANGED
@@ -8,6 +8,22 @@ import { signalGroup, stopGroups, stopWithThisProcess } from "./stopping.js";
8
8
  const MAX_FETCH_BODY = 10 * 1024 * 1024; // 10 MB
9
9
  const DEFAULT_SHELL_TIMEOUT = 30_000;
10
10
  const GROUP_SWEEP_MS = 250;
11
+ /**
12
+ * What a command's shell is started with, in place of the command: it waits
13
+ * to be told that it may go — on a channel of its own, which is closed
14
+ * before anything of the command's runs — and then becomes the shell the
15
+ * command is run by, as that shell would have been started: the same
16
+ * process, with the command and nothing else.
17
+ *
18
+ * A command is in a group of its own, which is stopped with its run — by
19
+ * the runner, or, should the runner die, by whoever watches for that. Both
20
+ * know of the group once it is listed, and it can only be listed once it is
21
+ * there: a command that was at its work before that would, in a runner that
22
+ * died in between, be nobody's to stop. So it is held until it is listed.
23
+ * Where its runner is gone before that, the channel ends with nothing said,
24
+ * and nothing of the command is run.
25
+ */
26
+ const HELD = 'read -r go <&3 || exit 1; exec 3<&-; exec "$1" -c "$2" "$0"';
11
27
  /**
12
28
  * The shell a command is run by: the `sh` that `path` — the runner's own
13
29
  * PATH — leads to from where the command runs. Not the one a PATH given for
@@ -121,12 +137,13 @@ export function createTools(projectDir, signal, env) {
121
137
  const notStarted = (why) => ({ exitCode: 1, stdout: "", stderr: messageOf(why).replace(`spawn ${shell} `, "spawn sh ") });
122
138
  let child;
123
139
  try {
124
- child = spawn(shell, ["-c", command], {
140
+ child = spawn(shell, ["-c", HELD, "sh", shell, command], {
125
141
  cwd,
126
142
  env,
127
143
  argv0: "sh",
128
144
  // Nothing is ever sent to a command: one that reads its input finds it at an end, rather than waiting.
129
- stdio: ["ignore", "pipe", "pipe"],
145
+ // (The fourth is how it is told that it may go: see HELD.)
146
+ stdio: ["ignore", "pipe", "pipe", "pipe"],
130
147
  detached: true,
131
148
  });
132
149
  }
@@ -138,6 +155,10 @@ export function createTools(projectDir, signal, env) {
138
155
  if (pgid) {
139
156
  groups.set(pgid, { shellExited: false, forget: stopWithThisProcess(pgid) });
140
157
  }
158
+ // Listed: now it may go. (A shell that could not be started has nobody to be told.)
159
+ const go = child.stdio[3];
160
+ go?.on("error", () => { });
161
+ go?.end("\n");
141
162
  try {
142
163
  const exit = await superviseChild(child, { timeout: options.timeout ?? DEFAULT_SHELL_TIMEOUT });
143
164
  if (pgid)
@@ -165,18 +186,23 @@ export function createTools(projectDir, signal, env) {
165
186
  const reader = response.body.getReader();
166
187
  const decoder = new TextDecoder("utf-8");
167
188
  let text = "";
189
+ // How much may still be taken, of what was sent: the limit is on that, and not on how many characters it comes to.
190
+ let room = MAX_FETCH_BODY;
168
191
  let truncated = false;
169
192
  try {
170
193
  for (;;) {
171
194
  const { done, value } = await reader.read();
172
195
  if (done)
173
196
  break;
174
- text += decoder.decode(value, { stream: true });
175
- if (text.length > MAX_FETCH_BODY) {
197
+ if (value.byteLength > room) {
198
+ // (What a character is cut in the middle of is left out with the rest: the decoder keeps it for what never comes.)
199
+ text += decoder.decode(value.subarray(0, room), { stream: true });
176
200
  truncated = true;
177
201
  await reader.cancel();
178
202
  break;
179
203
  }
204
+ text += decoder.decode(value, { stream: true });
205
+ room -= value.byteLength;
180
206
  }
181
207
  if (!truncated)
182
208
  text += decoder.decode();
@@ -184,9 +210,7 @@ export function createTools(projectDir, signal, env) {
184
210
  finally {
185
211
  reader.releaseLock();
186
212
  }
187
- body = truncated
188
- ? text.slice(0, MAX_FETCH_BODY) + "\n[trama] response body truncated at 10MB"
189
- : text;
213
+ body = truncated ? text + "\n[trama] response body truncated at 10MB" : text;
190
214
  }
191
215
  else {
192
216
  body = ""; // (an answer that has no body: to a HEAD, say)
package/dist/tree.d.ts CHANGED
@@ -32,10 +32,43 @@ export type Entry =
32
32
  * under it ("/" between the names) — a directory before what is in it.
33
33
  */
34
34
  export type Tree = Map<string, Entry>;
35
+ /** The path of the directory a tree is of. It is in no directory of the tree, and every other path is under it. */
36
+ export declare const ITSELF = ".";
37
+ /** The order in which a path comes before every path under it. (As text "." comes after "-x", which is under it.) */
38
+ export declare const inOrder: (a: string, b: string) => -1 | 0 | 1;
35
39
  /** What is at a path — the path itself, not what a link there leads to. Undefined if nothing is. */
36
40
  export declare function entryAt(path: string): Entry | undefined;
41
+ /** Put one more thing under a key that may have several. */
42
+ export declare function addTo<K, V>(map: Map<K, V[]>, key: K, value: V): void;
43
+ /** Which file, directory or link an entry is — undefined of what is none. */
44
+ export declare const idOf: (entry: Entry | undefined) => string | undefined;
45
+ /**
46
+ * Whether two entries are the same thing, unchanged. Nothing is the same as
47
+ * nothing. A directory is the same if it allows the same — what it holds is
48
+ * other paths. What is not content is never taken for the same: nothing is
49
+ * known of it that could be compared.
50
+ */
51
+ export declare function same(a: Entry | undefined, b: Entry | undefined): boolean;
37
52
  /** The paths at which two readings of a directory differ, a path before every path under it. */
38
53
  export declare function differences(before: Tree, after: Tree): string[];
54
+ /** The names in a directory. One that is not text cannot be told from another, or looked up again: it throws. */
55
+ export declare function namesIn(dir: string): string[];
56
+ export declare const gone: (err: unknown) => boolean;
57
+ /** Whether a refusal says that there is no such place: nothing is there, or the system takes no such name. */
58
+ export declare const noSuchPlace: (err: unknown) => boolean;
59
+ /**
60
+ * Go through a directory and everything under it, a directory before what it
61
+ * holds. `visit` is given each path, what is there, and where that is; if it
62
+ * returns false the entry is left out, and not gone into.
63
+ *
64
+ * Whatever goes wrong, the walk throws — with one exception, which is not
65
+ * something going wrong: a directory may be in use while it is read, and what
66
+ * has gone by the time it is come to is not there. (A directory that goes
67
+ * after it was looked at is one with nothing in it.)
68
+ */
69
+ export declare function walk(root: string, visit: (path: string, entry: Entry, at: string) => boolean | void): void;
70
+ /** Whether two files hold the same bytes. Read a piece at a time: a file may be larger than can be held at once. */
71
+ export declare function sameBytes(one: string, other: string): boolean;
39
72
  /**
40
73
  * What a directory is and holds. The directory must be there, and all of it
41
74
  * readable — or, with `opening`, to be made so: a directory that may not be
@@ -90,152 +123,3 @@ export declare function copyTree(fromDir: string, toDir: string, leaveOut?: (at:
90
123
  * links.
91
124
  */
92
125
  export declare function pathAsListed(dir: string, place: string): string | undefined;
93
- /** Something a run did in a copy that did not reach the real directory, and why. */
94
- export interface Unmerged {
95
- path: string;
96
- why: string;
97
- }
98
- /**
99
- * Carry what a run did to a copy back into the directory it is a copy of.
100
- *
101
- * @param stagedDir - the copy, as the run left it
102
- * @param realDir - the directory it was copied from
103
- * @param before - the copy as it was before the run (readTree)
104
- * @param seed - the real directory as it was when the copy was made (copyTree)
105
- * @param together - things that are one thing to the caller: each list the
106
- * `id`s (see Entry) of the files, links and directories that are one
107
- *
108
- * What the run did is where the copy differs from what it was: a file, a
109
- * directory or a link made, removed, changed, or put where something of
110
- * another kind was; permissions changed — those of the directory itself
111
- * among them, which is a directory like any in it: only that it is neither
112
- * made nor removed. Each difference is carried over on
113
- * one condition: the place in the real directory is still as it was when the
114
- * copy was made — and so is the directory it is in. If not, somebody else —
115
- * the user, another run of the same project — has been there since, and
116
- * theirs is kept. A place that already holds what the run left needs nothing
117
- * done, whoever made it so.
118
- *
119
- * There is no path this leaves out. Where the caller has itself put
120
- * something into the real directory since the copy was made, it says so in
121
- * `seed`: the place is then as the seed has it, and what the run did there is
122
- * carried over like anything else.
123
- *
124
- * All of that is found out before anything is done. What cannot arrive is
125
- * then left alone, with everything under it; and a directory the run removed,
126
- * or put something else in the place of, goes only if all that is in it goes
127
- * — if anything in it stays, or it holds something the run never saw, the
128
- * directory stays whole. What the run moved — a file, a link, a directory —
129
- * goes from where it was only if it arrives where the run moved it: what it
130
- * holds is not to be in neither place. (What was moved is known by its `id`,
131
- * see Entry. What the run copied and then removed is a new file, and is not
132
- * known to be the old one's.) And what the caller says is one thing — a
133
- * link, say, with the file that makes it lead somewhere: the things in one
134
- * list of `together`, each known by what it is, at every path where the copy
135
- * had it before the run or has it now — arrives together or not at all: if
136
- * one of those paths is left alone, nothing is done at any of them. A part
137
- * the run left as it was has nothing to arrive, but the rest leans on it: if
138
- * it is not, in the project, as it was when the copy was made, that is told
139
- * of it, and the rest does not arrive. (So that all this holds where the
140
- * system refuses in the doing, what is done at such a path is only what can
141
- * be taken back: a file there is not written into but has the new one put in
142
- * its place, and what is to go from there is moved aside first, as what is
143
- * taken the place of is. A directory among them that stays a directory is
144
- * not left alone with the rest — what else the run did in it could not be
145
- * taken for undone with it — but what it was to be left allowing does not
146
- * arrive either, and that is told of it. And a part the run left as it was,
147
- * and that is not so in the project, is told of besides, as that: nothing
148
- * under it is left alone for it — and nothing is told of it where nothing is
149
- * held back for it.) So what is returned as not arrived is as it
150
- * was, at that path and under it. That holds where the system refuses, in
151
- * the doing, what had been found possible — see how it is done, below — as
152
- * long as it does not also refuse to put back what was moved aside; then
153
- * the report says where that is.
154
- *
155
- * Some things are told of besides, which are not that. What was moved aside
156
- * to go, or made ready and not needed, and which the system will not have
157
- * removed, is told of at the name it is left under — a path that is none of
158
- * the run's. A directory the run removed which the system will not remove,
159
- * or not with all that was in it, holds what is left, as it would had the
160
- * run removed it there, and is told of so. A directory or a file that could
161
- * not be given, at the end, what it is to allow is told of for that: what
162
- * it holds has arrived, unless that is told of itself. A file that could not
163
- * be written into, and had a new one put in its place, is told of for that.
164
- * (If the system will not have the new one put there either, the file did
165
- * not arrive, and the report says that what it held may be damaged, and
166
- * where what it was to hold is.)
167
- *
168
- * Finding out is looking, and a directory that is closed cannot be looked
169
- * into. One of the real directory's — or the directory itself — is opened
170
- * for it, as it is for what is then done in it, and one of the copy's is
171
- * opened to be read: both are this merge's to open. Each is left, at the end,
172
- * allowing what the run left it allowing — or, if that did not arrive, what
173
- * it allowed. (One that somebody else gave other permissions since the copy
174
- * was made is theirs, and is not opened: nothing is made or removed in it.)
175
- *
176
- * A path is a name, and the real directory has the last word on its names:
177
- * its file system may take "Notes.txt" and "notes.txt" for one. A path of
178
- * the tree whose place holds something, though the directory does not list
179
- * the name as the tree spells it, is such a second spelling — the run
180
- * spelled a name anew, or made one beside another on a file system that
181
- * tells them apart. To a tree that is one entry removed and another made; in
182
- * the real directory the two are one place, and removing the one would
183
- * remove the other. Neither is touched: nothing is done to what is there
184
- * under any name the run changed, and each is told of as not arrived. (What
185
- * is there is known by what it is. All the names of a file that has several
186
- * are therefore left, where one would have done.) If what is there is a
187
- * directory, nothing is done in it either: a path through it is a path
188
- * through the other, and what the run left under the two names is in one
189
- * place. And two names the run made where nothing was, which the directory
190
- * turns out to take for one when the second is put there: neither is put.
191
- * (That can only be seen in the putting. If the first was not put, for a
192
- * reason of its own, the second is — and what is told of the first is then
193
- * true of the name as the run spelled it, not as the directory takes it.)
194
- * The same is asked of the way to a path: a directory on it that the real
195
- * one no longer lists as the tree spells it — somebody spelled it anew — is
196
- * not the tree's directory any more, and nothing is done in it.
197
- *
198
- * What is to be done is done so that nothing is lost by its being done in
199
- * part. A file or a link that is to be where something is, is made beside
200
- * the place first. Then what the run made is made, a directory before what
201
- * goes in it. What is in the place of it is not removed but moved aside,
202
- * under a name of its own beside the place, and what was made beside the
203
- * place is moved in. (Only a directory that stays a directory, and a file
204
- * the run wrote into that can be written into, stay and are changed where
205
- * they are. A file that is written into has what it is to hold made beside
206
- * it first all the same: if the system will not have the writing — which it
207
- * may have begun — that takes its place.) Where the system will not have a thing done, that
208
- * thing is left alone like what was found impossible beforehand, with what
209
- * follows from it — and what follows may be that something already done is
210
- * not to stand: what the run moved from there did not arrive where it went.
211
- * Then what was put there is removed again, and what was moved aside comes
212
- * back. Only when all that is settled does what was moved aside go for good,
213
- * and what the run removed, where it is. (A runner that is stopped in the
214
- * middle leaves what it had moved aside, or made ready, where it is: under
215
- * names that begin with .trama-tmp-.) It is where the run ended that is
216
- * carried over, not the steps by which it got there.
217
- *
218
- * A file the run wrote into is written into, if it may be, and stays the
219
- * file it is — as does one that holds what the run left already, and has
220
- * only what it allows changed. Where the run put another file in the place,
221
- * or the file may not be written into, or the system will not have it
222
- * written into after all, a new one is put in its place — and then a second
223
- * name of the old file is none of the new one, and holds whatever the
224
- * writing left. A link is written as the run wrote it
225
- * — the run took its copy for the directory itself — unless its way comes to
226
- * the copy from outside: by the copy's full path, or out of the copy and
227
- * back in by its name. What such a link says from there on is said of the
228
- * real directory, wherever that leads from there. So a link the copy
229
- * was given in other words than the directory's own (see copyTree), if the
230
- * run moved it, is merged in those words: it names what the run found it to
231
- * name, which is not always what the directory's own words would name from
232
- * the new place. And a link the run made that climbs out of its directory
233
- * with ".." and does not come back says the same in the real directory, and
234
- * names from there what it names from there.
235
- *
236
- * Nothing is thrown. What could not be carried over is returned, each path
237
- * with the reason, so that a run whose work did not all arrive is not passed
238
- * off as one whose work did. Under a path that did not arrive, what was not
239
- * looked at for that reason is not listed: it is as it was, with the path.
240
- */
241
- export declare function mergeTree(stagedDir: string, realDir: string, before: Tree, seed: Tree, together?: string[][]): Unmerged[];