@trama-dev/runtime 0.6.1 → 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.
- package/dist/agent-backend.d.ts +51 -0
- package/dist/agent-backend.js +4 -0
- package/dist/agent-host.d.ts +46 -7
- package/dist/agent-host.js +59 -19
- package/dist/agent-hosts.js +122 -56
- package/dist/agent.d.ts +16 -5
- package/dist/agent.js +22 -64
- package/dist/bridge-client.d.ts +6 -2
- package/dist/bridge-client.js +6 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +126 -2
- package/dist/context.js +3 -2
- package/dist/history.d.ts +9 -0
- package/dist/history.js +98 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +70 -41
- package/dist/ipc-server.d.ts +2 -3
- package/dist/ipc-server.js +93 -37
- package/dist/journal-view.js +19 -9
- package/dist/journal.d.ts +10 -4
- package/dist/journal.js +28 -6
- package/dist/merge-deeds.d.ts +22 -0
- package/dist/merge-deeds.js +201 -0
- package/dist/merge-doing.d.ts +9 -0
- package/dist/merge-doing.js +410 -0
- package/dist/merge-settle.d.ts +14 -0
- package/dist/merge-settle.js +166 -0
- package/dist/merge-shared.d.ts +64 -0
- package/dist/merge-shared.js +159 -0
- package/dist/merge.d.ts +150 -0
- package/dist/merge.js +209 -0
- package/dist/model-relay.js +35 -5
- package/dist/own-tools.d.ts +60 -0
- package/dist/own-tools.js +209 -0
- package/dist/path-guard.js +8 -6
- package/dist/pi-adapter.d.ts +22 -0
- package/dist/pi-adapter.js +147 -46
- package/dist/project.d.ts +31 -0
- package/dist/project.js +253 -0
- package/dist/replace-file.d.ts +13 -2
- package/dist/replace-file.js +23 -6
- package/dist/runner-backend.d.ts +43 -0
- package/dist/runner-backend.js +125 -0
- package/dist/runner-types.d.ts +8 -0
- package/dist/runner.d.ts +8 -123
- package/dist/runner.js +57 -453
- package/dist/schema.d.ts +38 -0
- package/dist/schema.js +104 -0
- package/dist/stopping.js +2 -3
- package/dist/tools.js +31 -7
- package/dist/tree.d.ts +33 -149
- package/dist/tree.js +43 -1077
- package/dist/types.d.ts +54 -2
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.js +76 -12
- package/package.json +2 -2
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,55 @@ export interface Ctx {
|
|
|
54
54
|
}
|
|
55
55
|
/** How much a model is to think before it answers. */
|
|
56
56
|
export type Thinking = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
57
|
+
/**
|
|
58
|
+
* A tool of the program's own, for the agent of one call: a function of the
|
|
59
|
+
* program's, which the model can call by name. It is run where the program
|
|
60
|
+
* runs — it has the program's variables, and can do what the program can.
|
|
61
|
+
*/
|
|
62
|
+
export interface AgentTool {
|
|
63
|
+
/** As the model calls it: letters, digits, "_" and "-". Not the name of another tool the agent has. */
|
|
64
|
+
name: string;
|
|
65
|
+
/** What it is for. This, and what its parameters are called, is all the model is told of it. */
|
|
66
|
+
description: string;
|
|
67
|
+
/**
|
|
68
|
+
* What it is called with, written as the shape of a typed answer is (see
|
|
69
|
+
* `Schema`): `{ id: "string: the order's id", lines: ["number"] }`. The
|
|
70
|
+
* model's call is held to it before `run` is called: every field there,
|
|
71
|
+
* each of its kind, and no other. Without it, the tool is called with `{}`.
|
|
72
|
+
*/
|
|
73
|
+
parameters?: Schema;
|
|
74
|
+
/**
|
|
75
|
+
* It may run while another tool does. Without it, the tools a model calls
|
|
76
|
+
* in one reply are run one after the other, in the order it called them —
|
|
77
|
+
* the agent's own among them, where one of the program's is called beside.
|
|
78
|
+
*/
|
|
79
|
+
parallel?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* What it returns is the end of the agent's work, and the answer of the
|
|
82
|
+
* call: the model is not asked again. For a call whose answer is to be
|
|
83
|
+
* something the model hands over, held to a shape, rather than its last
|
|
84
|
+
* words — `{ name: "verdict", ends: true, parameters: { ok: "boolean" }, … }`.
|
|
85
|
+
* Not where it throws: the model then reads why, and may call it again.
|
|
86
|
+
* (And not where the model called, in the same reply, a tool that ends
|
|
87
|
+
* nothing: it is then asked again, as after any tool.)
|
|
88
|
+
*/
|
|
89
|
+
ends?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Called each time the model calls the tool, with its arguments. What it
|
|
92
|
+
* returns is the model's to read: a string as it is, anything else as
|
|
93
|
+
* JSON says it (nothing at all as "Done."). Bytes — a Buffer, a
|
|
94
|
+
* Uint8Array — are an image for the model to see: PNG, JPEG, GIF or WebP,
|
|
95
|
+
* told by how they begin; a list with bytes in it is each of those as an
|
|
96
|
+
* image, and the rest as words. What it throws is the model's
|
|
97
|
+
* to read too, as the tool's failure — and not the failure of the call,
|
|
98
|
+
* which goes on. `signal` says when the call it is run for is to go no
|
|
99
|
+
* further (it was cancelled, or its budget is spent): what it returns
|
|
100
|
+
* after that is nobody's.
|
|
101
|
+
*/
|
|
102
|
+
run(args: any, context: {
|
|
103
|
+
signal: AbortSignal;
|
|
104
|
+
}): unknown;
|
|
105
|
+
}
|
|
57
106
|
/**
|
|
58
107
|
* What a call may say about how it is served. Each is honoured or the call
|
|
59
108
|
* fails: nothing asked for here is quietly left out. (But by an extension
|
|
@@ -71,9 +120,12 @@ export interface AgentOptions {
|
|
|
71
120
|
* the answer is then made from the prompt alone, and nothing is read, run
|
|
72
121
|
* or written. Without it the agent has its own choice of them (read, bash,
|
|
73
122
|
* edit, write); pi has more than it chooses (grep, find, ls). A name the
|
|
74
|
-
* agent has no tool for is an error.
|
|
123
|
+
* agent has no tool for is an error. A tool of the program's own is given
|
|
124
|
+
* as itself (see `AgentTool`), beside the names — and is then the agent's
|
|
125
|
+
* like any: a call that names tools of its own and nothing else has those
|
|
126
|
+
* and no other.
|
|
75
127
|
*/
|
|
76
|
-
tools?: string
|
|
128
|
+
tools?: Array<string | AgentTool>;
|
|
77
129
|
/**
|
|
78
130
|
* The skills the agent has for this call: `true` for all that pi finds
|
|
79
131
|
* for the user and for the project (its `.pi/skills` among them; of two
|
package/dist/workspace.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import type { Workspace } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read a simple glob pattern for matching relative paths: `*` is any run of
|
|
4
|
+
* characters within a segment, `?` one of them, `**` any run of characters
|
|
5
|
+
* at all, and `**` with its slash any number of whole segments, none included
|
|
6
|
+
* (so `**` + `/*.md` matches at the root too). Every other character is itself.
|
|
7
|
+
*
|
|
8
|
+
* The pattern is taken apart at its operators, and each piece between them
|
|
9
|
+
* is itself, character for character — there is no text a pattern could
|
|
10
|
+
* hold that is mistaken for an operator.
|
|
11
|
+
*
|
|
12
|
+
* A path is held against it step by step, and no step is taken twice: where
|
|
13
|
+
* the pattern is at a given place and the path at a given place, whether the
|
|
14
|
+
* rest matches is found once. (A pattern handed to the system's own matcher
|
|
15
|
+
* of expressions is tried every way round instead, and one that says "any
|
|
16
|
+
* segments" a dozen times is not done with a path of some depth in any time
|
|
17
|
+
* a caller would wait — which, here, is everyone the runner serves.)
|
|
18
|
+
*/
|
|
19
|
+
export declare function compileGlob(pattern: string): {
|
|
20
|
+
test(path: string): boolean;
|
|
21
|
+
};
|
|
2
22
|
/**
|
|
3
23
|
* Make sure a workspace directory exists where `workspaceDir` leads, and
|
|
4
24
|
* return its resolved path. Unlike a project, a workspace is nothing but its
|
package/dist/workspace.js
CHANGED
|
@@ -5,20 +5,83 @@ import { guardPath, realRootOf } from "./path-guard.js";
|
|
|
5
5
|
import { isStagedName, stageFile } from "./replace-file.js";
|
|
6
6
|
const OBSERVE_POLL_MS = 250;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Read a simple glob pattern for matching relative paths: `*` is any run of
|
|
9
|
+
* characters within a segment, `?` one of them, `**` any run of characters
|
|
10
10
|
* at all, and `**` with its slash any number of whole segments, none included
|
|
11
11
|
* (so `**` + `/*.md` matches at the root too). Every other character is itself.
|
|
12
12
|
*
|
|
13
|
-
* The pattern is taken apart at its operators and each piece between them
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* The pattern is taken apart at its operators, and each piece between them
|
|
14
|
+
* is itself, character for character — there is no text a pattern could
|
|
15
|
+
* hold that is mistaken for an operator.
|
|
16
|
+
*
|
|
17
|
+
* A path is held against it step by step, and no step is taken twice: where
|
|
18
|
+
* the pattern is at a given place and the path at a given place, whether the
|
|
19
|
+
* rest matches is found once. (A pattern handed to the system's own matcher
|
|
20
|
+
* of expressions is tried every way round instead, and one that says "any
|
|
21
|
+
* segments" a dozen times is not done with a path of some depth in any time
|
|
22
|
+
* a caller would wait — which, here, is everyone the runner serves.)
|
|
16
23
|
*/
|
|
17
|
-
function compileGlob(pattern) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
export function compileGlob(pattern) {
|
|
25
|
+
const steps = [];
|
|
26
|
+
pattern.split("**/").forEach((part, whole) => {
|
|
27
|
+
if (whole > 0)
|
|
28
|
+
steps.push("whole segments");
|
|
29
|
+
part.split("**").forEach((within, any) => {
|
|
30
|
+
if (any > 0)
|
|
31
|
+
steps.push("anything");
|
|
32
|
+
within.split("?").forEach((run, one) => {
|
|
33
|
+
if (one > 0)
|
|
34
|
+
steps.push("one of a segment");
|
|
35
|
+
run.split("*").forEach((text, some) => {
|
|
36
|
+
if (some > 0)
|
|
37
|
+
steps.push("some of a segment");
|
|
38
|
+
// (Unit by unit, as text is counted: one `?` is one of them, as it was to the matcher before this.)
|
|
39
|
+
for (let at = 0; at < text.length; at += 1)
|
|
40
|
+
steps.push({ one: text[at] });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
test(characters) {
|
|
47
|
+
/** Whether the rest matches, from a step of the pattern and a place in the path: found once. */
|
|
48
|
+
const found = new Map();
|
|
49
|
+
const rest = (step, at) => {
|
|
50
|
+
if (step === steps.length)
|
|
51
|
+
return at === characters.length;
|
|
52
|
+
const key = step * (characters.length + 1) + at;
|
|
53
|
+
const known = found.get(key);
|
|
54
|
+
if (known !== undefined)
|
|
55
|
+
return known;
|
|
56
|
+
const is = steps[step];
|
|
57
|
+
let matches = false;
|
|
58
|
+
if (typeof is === "object")
|
|
59
|
+
matches = characters[at] === is.one && rest(step + 1, at + 1);
|
|
60
|
+
else if (is === "one of a segment")
|
|
61
|
+
matches = at < characters.length && characters[at] !== "/" && rest(step + 1, at + 1);
|
|
62
|
+
else if (is === "some of a segment") {
|
|
63
|
+
for (let to = at; !matches; to += 1) {
|
|
64
|
+
matches = rest(step + 1, to);
|
|
65
|
+
if (to >= characters.length || characters[to] === "/")
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (is === "anything") {
|
|
70
|
+
for (let to = at; to <= characters.length && !matches; to += 1)
|
|
71
|
+
matches = rest(step + 1, to);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// None — or what ends in a slash and has something before it.
|
|
75
|
+
matches = rest(step + 1, at);
|
|
76
|
+
for (let to = at + 2; to <= characters.length && !matches; to += 1)
|
|
77
|
+
matches = characters[to - 1] === "/" && rest(step + 1, to);
|
|
78
|
+
}
|
|
79
|
+
found.set(key, matches);
|
|
80
|
+
return matches;
|
|
81
|
+
};
|
|
82
|
+
return rest(0, 0);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
22
85
|
}
|
|
23
86
|
/**
|
|
24
87
|
* A pattern with no glob operators names exactly one artifact.
|
|
@@ -78,6 +141,7 @@ function listFiles(dir, root, found, byLink = false) {
|
|
|
78
141
|
}
|
|
79
142
|
}
|
|
80
143
|
}
|
|
144
|
+
const observeAborted = () => new Error("workspace.observe() aborted");
|
|
81
145
|
/** Resolve after `ms`, or reject as soon as `signal` aborts. */
|
|
82
146
|
function sleep(ms, signal) {
|
|
83
147
|
return new Promise((resolve, reject) => {
|
|
@@ -87,7 +151,7 @@ function sleep(ms, signal) {
|
|
|
87
151
|
}, ms);
|
|
88
152
|
const offAbort = onAbort(signal, () => {
|
|
89
153
|
clearTimeout(timer);
|
|
90
|
-
reject(
|
|
154
|
+
reject(observeAborted());
|
|
91
155
|
});
|
|
92
156
|
});
|
|
93
157
|
}
|
|
@@ -180,7 +244,7 @@ export function createWorkspace(workspaceDir, signal) {
|
|
|
180
244
|
const startTime = performance.now();
|
|
181
245
|
while (true) {
|
|
182
246
|
if (signal?.aborted)
|
|
183
|
-
throw
|
|
247
|
+
throw observeAborted();
|
|
184
248
|
if (single && isDirectory()) {
|
|
185
249
|
throw Object.assign(new Error(`EISDIR: illegal operation on a directory, read '${pattern}'`), { code: "EISDIR" });
|
|
186
250
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trama-dev/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"node": ">=22.19.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
40
|
+
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
41
41
|
"tsx": "4.23.15"
|
|
42
42
|
}
|
|
43
43
|
}
|