@trama-dev/runtime 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-backend.d.ts +127 -1
- package/dist/agent-backend.js +41 -2
- package/dist/agent-host.d.ts +50 -0
- package/dist/agent-host.js +97 -0
- package/dist/agent-hosts.d.ts +14 -0
- package/dist/agent-hosts.js +321 -0
- package/dist/agent.d.ts +10 -2
- package/dist/agent.js +85 -36
- package/dist/bridge-client.d.ts +6 -0
- package/dist/bridge-client.js +31 -8
- package/dist/budget.d.ts +52 -0
- package/dist/budget.js +118 -0
- package/dist/child-process.d.ts +18 -0
- package/dist/child-process.js +29 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +4 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +191 -56
- package/dist/ipc-server.d.ts +11 -2
- package/dist/ipc-server.js +104 -41
- package/dist/journal-view.d.ts +2 -0
- package/dist/journal-view.js +41 -4
- package/dist/journal.d.ts +12 -4
- package/dist/journal.js +7 -2
- package/dist/model-relay.d.ts +188 -0
- package/dist/model-relay.js +492 -0
- package/dist/pi-adapter.d.ts +34 -9
- package/dist/pi-adapter.js +978 -47
- package/dist/runner-types.d.ts +35 -0
- package/dist/runner.d.ts +190 -4
- package/dist/runner.js +652 -189
- package/dist/stopping.d.ts +33 -2
- package/dist/stopping.js +119 -11
- package/dist/tools.d.ts +2 -1
- package/dist/tools.js +52 -13
- package/dist/tree.d.ts +9 -2
- package/dist/tree.js +25 -3
- package/dist/types.d.ts +100 -12
- package/package.json +1 -1
package/dist/runner-types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Budget } from "./budget.js";
|
|
2
|
+
export type { Budget };
|
|
1
3
|
export interface ProgramResult {
|
|
2
4
|
status: "done" | "yielded" | "failed";
|
|
3
5
|
/** Yield reason, or error summary for failed. */
|
|
@@ -25,6 +27,25 @@ export interface RunOptions {
|
|
|
25
27
|
workspaceDir?: string;
|
|
26
28
|
/** A name for this run — a participant's, say. Its output is shown under it. */
|
|
27
29
|
label?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Variables for the run, over the runner's own: its program has them, and
|
|
32
|
+
* so do the shell commands it runs, its agents, and the runs it asks for,
|
|
33
|
+
* each of which may be given more. (An agent has them by being served in a
|
|
34
|
+
* process of its own, started with them: which pi it finds, and which key
|
|
35
|
+
* for a provider, are then the run's.) One given as undefined is one not
|
|
36
|
+
* given. The journal has their names, not what they hold.
|
|
37
|
+
*/
|
|
38
|
+
env?: Record<string, string | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* What the run may use of a model, in all: its program's agent calls, the
|
|
41
|
+
* requests for a fix, and everything the runs it asks for use. Once it is
|
|
42
|
+
* spent, a call that asks a model is refused, one that is under way is
|
|
43
|
+
* stopped where it would ask its model again, and no repair is tried. A
|
|
44
|
+
* run a program asks for is held to the budget of the run that asked as
|
|
45
|
+
* well: it can be given less, never more. Without it, a run nobody's
|
|
46
|
+
* program asked for has the config's `budget`, if that has one.
|
|
47
|
+
*/
|
|
48
|
+
budget?: Budget;
|
|
28
49
|
/**
|
|
29
50
|
* Stops the run: its program is stopped, no repair is attempted, and the
|
|
30
51
|
* run ends as failed. A fix that was being tried leaves no trace.
|
|
@@ -39,4 +60,18 @@ export interface TramaConfig extends ModelConfig {
|
|
|
39
60
|
defaultMaxIterations: number;
|
|
40
61
|
/** How many runs of a project keep their journal. 0 records nothing. */
|
|
41
62
|
journalRuns: number;
|
|
63
|
+
/**
|
|
64
|
+
* What becomes of what the agent that writes or fixes a program changes in
|
|
65
|
+
* the project beside the program — a package it installs, a file it puts
|
|
66
|
+
* right. "keep": it reaches the project with a program that then works,
|
|
67
|
+
* and only with one. "discard": none of it does; the program is all that
|
|
68
|
+
* is taken from the agent.
|
|
69
|
+
*/
|
|
70
|
+
agentChanges: "keep" | "discard";
|
|
71
|
+
/**
|
|
72
|
+
* What a run may use of a model (see RunOptions) where it is not given a
|
|
73
|
+
* budget of its own — and what a `create` or an `update` may: writing the
|
|
74
|
+
* program and validating it, together. Without it, nothing is capped.
|
|
75
|
+
*/
|
|
76
|
+
budget?: Budget;
|
|
42
77
|
}
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { RunOptions, TramaConfig, ProgramResult } from "./runner-types.js";
|
|
2
|
-
import type { AgentBackend } from "./agent-backend.js";
|
|
2
|
+
import type { AgentBackend, AgentUsage } from "./agent-backend.js";
|
|
3
|
+
import { type Budget, type Meter } from "./budget.js";
|
|
4
|
+
import { type Tree, type Unmerged } from "./tree.js";
|
|
3
5
|
/**
|
|
4
6
|
* Everything a project directory needs around program.ts before it can run:
|
|
5
7
|
* history/ and logs/, an ESM package.json, .gitignore entries, and links to the
|
|
@@ -19,15 +21,114 @@ export declare function loadProjectConfig(projectDir: string, meta?: import("./m
|
|
|
19
21
|
/**
|
|
20
22
|
* What does the LLM work for a project. The only place that picks a backend:
|
|
21
23
|
* everything else is handed one and does not know which it is.
|
|
24
|
+
*
|
|
25
|
+
* It is also where what is asked of a model is counted, and held to a
|
|
26
|
+
* budget (`meter`): every call passes here, whoever makes it. A call that
|
|
27
|
+
* comes when the budget is spent is refused; one under way is stopped where
|
|
28
|
+
* its agent would ask the model again — what the model was asked before
|
|
29
|
+
* that is used, and what it was answering is let finish. `spent` is told
|
|
30
|
+
* why, the first time either happens.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createBackend(config: TramaConfig, meter?: Meter, spent?: (why: string) => void, env?: Record<string, string>): Backend;
|
|
33
|
+
/**
|
|
34
|
+
* Say that a budget is spent, once for the budget — whoever comes up against
|
|
35
|
+
* it first: the run's own backend, or the backend of a project being made
|
|
36
|
+
* for the run's program, of which there may be many.
|
|
22
37
|
*/
|
|
23
|
-
export declare
|
|
38
|
+
export declare const saysOnce: (meter: Meter, say: (why: string) => void) => (why: string) => void;
|
|
39
|
+
/** A backend as the runner holds it: one whose cancelled calls are answered at once, and can be waited for apart. */
|
|
40
|
+
export interface Backend extends AgentBackend {
|
|
41
|
+
/** Why nothing more may be asked of it — the budget it counts in is spent — or nothing, while something may. */
|
|
42
|
+
spent?(): string | undefined;
|
|
43
|
+
/** Why a call of it was first refused or stopped for the budget, if one was — whatever the count has come to since. */
|
|
44
|
+
refused?(): string | undefined;
|
|
45
|
+
/** Whether what its calls use is held to anything: then what a call it cut off used is to be waited for, recorded or not. */
|
|
46
|
+
counts?(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* End what the backend kept to serve calls with — a process of its own for
|
|
49
|
+
* those that have extensions. Whatever it served is over: a run, a
|
|
50
|
+
* validation. (Asked again after this, it starts anew.)
|
|
51
|
+
*/
|
|
52
|
+
close?(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves when the backend has let go of the calls that were cancelled so
|
|
55
|
+
* far: whoever cancelled one went on at once, and the backend still had to
|
|
56
|
+
* stop what it was doing, and to say what the call had used. They are
|
|
57
|
+
* waited for no longer than anything asked to stop is.
|
|
58
|
+
*/
|
|
59
|
+
letGo(): Promise<void>;
|
|
60
|
+
}
|
|
24
61
|
export declare function loadState(projectDir: string): Record<string, unknown>;
|
|
25
62
|
/** Save the current program.ts as the next version of the project, and record why. */
|
|
26
63
|
export declare function copyToHistory(projectDir: string, reason: string, detail?: string): void;
|
|
27
64
|
/** Run fn in a temp directory, clean up afterwards regardless of outcome — including this process being stopped. */
|
|
28
65
|
export declare function withTempDir<T>(prefix: string, fn: (dir: string) => Promise<T>): Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Have what is beside a project be beside a copy of it: for each name in the
|
|
68
|
+
* directory the project is in, a link of that name, to it, in the directory
|
|
69
|
+
* the copy is in. So ".." leads from the copy to what it leads to from the
|
|
70
|
+
* project — a file beside it that its program reads, a module it imports
|
|
71
|
+
* from there, a project beside it that it runs.
|
|
72
|
+
*
|
|
73
|
+
* What is come to that way is the real thing, not a copy: what is done to it
|
|
74
|
+
* is done. (So is what it comes to in turn — and from a directory beside the
|
|
75
|
+
* project, ".." is the directory the project is in: by its name from there,
|
|
76
|
+
* the project itself, and not the copy.) One step up is all there is: what
|
|
77
|
+
* the directory the project is in is itself beside is not beside the copy.
|
|
78
|
+
* And it is as much as can be found out: a directory that may not be listed
|
|
79
|
+
* has nothing told of it, and a name the copy's own directory will not have
|
|
80
|
+
* beside the copy is left out — the project's own, which is the copy's
|
|
81
|
+
* there, before any.
|
|
82
|
+
*
|
|
83
|
+
* Returns the names put there, and the directory they are names in. A name
|
|
84
|
+
* is not the thing: one that is made beside the copy, or taken away there,
|
|
85
|
+
* is made or taken away in a directory that goes with the copy, and not
|
|
86
|
+
* beside the project (see strandedBeside).
|
|
87
|
+
*/
|
|
88
|
+
interface Beside {
|
|
89
|
+
among: string;
|
|
90
|
+
names: string[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Make, in `privateDir`, a copy of a project — to try a program in, or for an
|
|
94
|
+
* agent to look at and work in: what the project is and holds (see copyTree),
|
|
95
|
+
* with `program` as its program.ts where one is given. Returns where the
|
|
96
|
+
* copy is, what the project was when it was copied, and the names put beside
|
|
97
|
+
* the copy for what is beside the project.
|
|
98
|
+
*
|
|
99
|
+
* The copy allows what the project allows, to everybody: so it is made in a
|
|
100
|
+
* directory that is this runner's alone, and is nobody else's to come to. It
|
|
101
|
+
* has the project's name there, and what is beside the project beside it (see
|
|
102
|
+
* standAmong) — nothing else is to be in that directory. Where what is
|
|
103
|
+
* copied is itself a copy of a project — as where a candidate is validated
|
|
104
|
+
* in the project as an agent prepared it — `among` names the project: what
|
|
105
|
+
* is beside the copy is what is beside that, and nothing an agent made
|
|
106
|
+
* beside its own.
|
|
107
|
+
*
|
|
108
|
+
* The project's journals are not carried over: they are the record of its
|
|
109
|
+
* runs, not part of what a run works on, and a copy is where a run is tried.
|
|
110
|
+
*
|
|
111
|
+
* In everything else the copy is as the project is, so that what a program
|
|
112
|
+
* can do in the one it can do in the other: what a run did in a copy is
|
|
113
|
+
* merged back into the project, and must not have been possible only there.
|
|
114
|
+
* The one exception is the program: the one to be tried, in the place of
|
|
115
|
+
* the project's. It allows what the project's allows — and its owner to
|
|
116
|
+
* replace it — and is put there whatever the directory it goes in allows:
|
|
117
|
+
* a copy is where programs are tried and replaced, and whether the project's
|
|
118
|
+
* own may be is said of the project, where one is to take its place (see
|
|
119
|
+
* whyNotReplaceable). A project with a directory where its program should be
|
|
120
|
+
* has no place for one, and is not copied to try one in.
|
|
121
|
+
*/
|
|
122
|
+
export declare function copyProjectWith(projectDir: string, privateDir: string, program?: string, among?: string): {
|
|
123
|
+
copy: string;
|
|
124
|
+
held: Tree;
|
|
125
|
+
beside: Beside;
|
|
126
|
+
};
|
|
127
|
+
/** A line as it is shown for a run: under the run's name, if it has one. */
|
|
128
|
+
export declare const tagged: (label: string | undefined, line: string) => string;
|
|
29
129
|
/** The instructions a request for a fix is made under. (Exported so the tests' stand-in LLM can tell one from any other call.) */
|
|
30
130
|
export declare const REPAIR_SYSTEM_PROMPT = "You are a TypeScript repair tool.";
|
|
131
|
+
export declare const shownPaths: (paths: string[]) => string;
|
|
31
132
|
/**
|
|
32
133
|
* Validate a candidate program.ts for a project without touching what the
|
|
33
134
|
* project holds: run it (with repair) in a throwaway copy. The one thing left
|
|
@@ -35,21 +136,80 @@ export declare const REPAIR_SYSTEM_PROMPT = "You are a TypeScript repair tool.";
|
|
|
35
136
|
* the candidate itself, or a repaired version of it, with the failure that was
|
|
36
137
|
* repaired. Throws if it cannot be made to run.
|
|
37
138
|
*
|
|
139
|
+
* `as` names a directory that is the project as it is to be once the
|
|
140
|
+
* program is in it — the copy the agent that wrote the program worked in,
|
|
141
|
+
* with what it made there (see Prepared). The copy the program is run in is
|
|
142
|
+
* then a copy of that, which is no more touched than the project is, and it
|
|
143
|
+
* stands among what the project stands among.
|
|
144
|
+
*
|
|
145
|
+
* A repair made here is of the program alone (see requestRepair): the copy a
|
|
146
|
+
* candidate runs in goes whole, with whatever was done in it.
|
|
147
|
+
*
|
|
148
|
+
* Where the agent left its copy so that no copy can be made of it — a file
|
|
149
|
+
* nobody may read, say — the candidate is validated in the project as it is,
|
|
150
|
+
* as it would be were nothing of the agent's kept: and `alone` says why,
|
|
151
|
+
* for then nothing of the agent's is to be kept. (A caller that knows of such
|
|
152
|
+
* a reason beforehand gives it as `alone`, with no `as`.) That is said when
|
|
153
|
+
* it is found, whatever then comes of the candidate.
|
|
154
|
+
*
|
|
38
155
|
* Only the project's own files are shielded. What the program does beyond
|
|
39
156
|
* them — network calls, shell commands, agent calls — is real. A run it asks
|
|
40
157
|
* its runner for is not started: the validation ends where it asks for the
|
|
41
158
|
* first.
|
|
42
159
|
*/
|
|
43
|
-
export declare function validateProgram(projectDir: string, backend:
|
|
160
|
+
export declare function validateProgram(projectDir: string, backend: Backend, candidate: string, options: {
|
|
44
161
|
timeout: number;
|
|
45
162
|
maxRepairAttempts: number;
|
|
46
163
|
maxIterations: number;
|
|
47
164
|
journalRuns?: number;
|
|
48
165
|
signal?: AbortSignal;
|
|
166
|
+
as?: string;
|
|
167
|
+
alone?: string;
|
|
168
|
+
budget?: Budget;
|
|
169
|
+
wrote?: AgentUsage[];
|
|
170
|
+
/** Where a run's program asked for the project to be made or changed: the run's name and variables are the validation's, and the two journals point at each other. */
|
|
171
|
+
label?: string;
|
|
172
|
+
env?: Record<string, string>;
|
|
173
|
+
askedFor?: Pick<AskedFor, "parent" | "started">;
|
|
49
174
|
}): Promise<{
|
|
50
175
|
source: string;
|
|
51
176
|
repairedError?: string;
|
|
177
|
+
alone?: string;
|
|
52
178
|
}>;
|
|
179
|
+
/**
|
|
180
|
+
* A copy of a project for the agent that writes its program to work in: to
|
|
181
|
+
* look at what the program is to work with, and to make what the program
|
|
182
|
+
* needs beside it — a package installed, a module, a file. `keep` carries
|
|
183
|
+
* what the agent made there into the project, and returns what did not
|
|
184
|
+
* arrive, with the paths it made or changed: it is for when the program has
|
|
185
|
+
* been found to work in a copy of this one, and is in the project.
|
|
186
|
+
*
|
|
187
|
+
* The program is no part of that: it is what the agent answers with,
|
|
188
|
+
* validated and installed as that, and what the agent left at program.ts —
|
|
189
|
+
* the name, each link it led through, and the file it led to — stays in its
|
|
190
|
+
* copy. So that the answer is validated where it will be installed, `ready`
|
|
191
|
+
* has the name program.ts be, in the copy, what it was before the agent
|
|
192
|
+
* worked: a link the agent put there is taken away, and one it took away is
|
|
193
|
+
* put back. Where the way from the name is then still not what it was — a
|
|
194
|
+
* link further along made to lead elsewhere, a directory on it replaced —
|
|
195
|
+
* the copy is no place to validate the answer in, and `ready` says so.
|
|
196
|
+
*/
|
|
197
|
+
export interface Prepared {
|
|
198
|
+
/** Where the copy is. */
|
|
199
|
+
copy: string;
|
|
200
|
+
/**
|
|
201
|
+
* Make the copy what a candidate can be validated in a copy of (see above).
|
|
202
|
+
* Throws if it cannot be: what is at the copy's path is no longer the copy
|
|
203
|
+
* (moved away, say, with a link left in its place), or program.ts does not
|
|
204
|
+
* lead there where it led.
|
|
205
|
+
*/
|
|
206
|
+
ready(): void;
|
|
207
|
+
keep(): {
|
|
208
|
+
changed: string[];
|
|
209
|
+
unmerged: Unmerged[];
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
export declare function prepareProject(projectDir: string, privateDir: string): Prepared;
|
|
53
213
|
/**
|
|
54
214
|
* Why a project's program cannot be given a successor — or null if it can.
|
|
55
215
|
*
|
|
@@ -72,6 +232,30 @@ export declare function installValidatedProgram(projectDir: string, validated: {
|
|
|
72
232
|
source: string;
|
|
73
233
|
repairedError?: string;
|
|
74
234
|
}, reason: "create" | "update", prompt: string): void;
|
|
235
|
+
/** A project a program asks its runner to make, or to change (see createProject and updateProject). */
|
|
236
|
+
export interface MakeRequest {
|
|
237
|
+
kind: "create" | "update";
|
|
238
|
+
name: string;
|
|
239
|
+
prompt: string;
|
|
240
|
+
model?: string;
|
|
241
|
+
args?: Record<string, unknown>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* What a project is made or changed under where a run's program asked for
|
|
245
|
+
* it: that run's — stopped with it, counted in its budget, shown under its
|
|
246
|
+
* name, validated with its variables, and on record beside its journal.
|
|
247
|
+
*/
|
|
248
|
+
export interface AskedToMake extends Pick<AskedFor, "parent" | "started" | "above"> {
|
|
249
|
+
signal: AbortSignal;
|
|
250
|
+
label?: string;
|
|
251
|
+
env?: Record<string, string>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* How a project is made or changed for a program that asks its runner to.
|
|
255
|
+
* The runner is handed it by what starts runs (the runner surface): it is
|
|
256
|
+
* that which knows how a program is written, and it stands on this.
|
|
257
|
+
*/
|
|
258
|
+
export type Making = (request: MakeRequest, asked: AskedToMake) => Promise<void>;
|
|
75
259
|
/** What a run is told when a program asked for it, rather than a person or a host. */
|
|
76
260
|
interface AskedFor {
|
|
77
261
|
/** How many runs deep it is: one more than the run that asked. */
|
|
@@ -84,6 +268,8 @@ interface AskedFor {
|
|
|
84
268
|
};
|
|
85
269
|
/** Called once this run has a journal of its own. */
|
|
86
270
|
started(run: string, journal: string): void;
|
|
271
|
+
/** The count of what the run that asked uses of a model: what this one uses is counted there too, and held to it. */
|
|
272
|
+
above?: Meter;
|
|
87
273
|
}
|
|
88
274
|
/**
|
|
89
275
|
* Run a project, in this process: this is what a runner does.
|
|
@@ -92,5 +278,5 @@ interface AskedFor {
|
|
|
92
278
|
* call). One runner carries the whole tree of runs, so it is also where the
|
|
93
279
|
* tree is kept from growing without bound.
|
|
94
280
|
*/
|
|
95
|
-
export declare function runProgram(options: RunOptions, askedFor?: AskedFor): Promise<ProgramResult>;
|
|
281
|
+
export declare function runProgram(options: RunOptions, askedFor?: AskedFor, making?: Making): Promise<ProgramResult>;
|
|
96
282
|
export {};
|