@notation/factory 0.2.0 → 0.5.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/contracts/runner.ts +32 -1
- package/deployer/index.ts +12 -5
- package/deployer/sdk.gen.ts +1 -1
- package/implementations/outpost-secret.ts +35 -0
- package/index.ts +3 -1
- package/lib/repos.test.ts +17 -0
- package/lib/repos.ts +19 -0
- package/package.json +1 -1
- package/resources/random-key.ts +43 -0
- package/resources/router-sync.ts +27 -11
- package/router/admin.ts +100 -0
- package/router/channel.ts +73 -14
- package/router/deliveries.ts +126 -0
- package/router/handle.test.ts +615 -20
- package/router/handle.ts +541 -121
- package/router/index.ts +25 -38
- package/router/run.ts +45 -5
- package/router/sync.ts +22 -0
- package/runner/index.ts +369 -80
- package/runner/runner.test.ts +485 -78
package/contracts/runner.ts
CHANGED
|
@@ -11,10 +11,18 @@ import type { Run } from "../router/run.ts";
|
|
|
11
11
|
export type RunContext = {
|
|
12
12
|
/** The run's worktree. */
|
|
13
13
|
cwd: string;
|
|
14
|
+
/**
|
|
15
|
+
* The conversation's messages that the agent hasn't seen, which the
|
|
16
|
+
* runner reads when the run starts. The runner writes it to the CLI's
|
|
17
|
+
* stdin, since a whole thread can be longer than one argument may be.
|
|
18
|
+
*/
|
|
19
|
+
prompt: string;
|
|
14
20
|
/** The runner's system prompt, followed by the agent's own. */
|
|
15
21
|
systemPrompt: string;
|
|
16
22
|
/** The runner's state directory, `/data`. */
|
|
17
23
|
dataDir: string;
|
|
24
|
+
/** The agent's config directory, which the CLI reads in place of `~/<configDir>`. */
|
|
25
|
+
configDir: string;
|
|
18
26
|
};
|
|
19
27
|
|
|
20
28
|
/** What a runtime's CLI said at the end of a run. */
|
|
@@ -26,14 +34,37 @@ export type RuntimeRunner = {
|
|
|
26
34
|
command: string;
|
|
27
35
|
/** The CLI's name, for errors. */
|
|
28
36
|
name: string;
|
|
29
|
-
/**
|
|
37
|
+
/** The CLI's config directory, relative to the home, such as `.claude`. */
|
|
38
|
+
configDir: string;
|
|
39
|
+
/**
|
|
40
|
+
* The environment that has the CLI read `dir` as its config directory.
|
|
41
|
+
* The runner gives each agent a directory of its own. Without it, the
|
|
42
|
+
* agents of the runtime share `~/<configDir>`.
|
|
43
|
+
*/
|
|
44
|
+
configEnv?(dir: string): Record<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* Files that the CLI reads from the home, but from its config directory
|
|
47
|
+
* once `configEnv` moves it, such as Claude Code's `.claude.json`. The
|
|
48
|
+
* runner writes `~/<file>` to the agent's config directory.
|
|
49
|
+
*/
|
|
50
|
+
homeFiles?: string[];
|
|
51
|
+
/** Where the CLI keeps its sessions' transcripts, relative to its config directory, in a directory per working directory. */
|
|
30
52
|
transcripts: string;
|
|
31
53
|
/** The CLI's arguments for a run. */
|
|
32
54
|
args(run: Run, context: RunContext): Promise<string[]>;
|
|
55
|
+
/** What the runner writes to the CLI's stdin. Without it, the runner writes the prompt. */
|
|
56
|
+
input?(context: RunContext): string;
|
|
33
57
|
/** The arguments that resume a session. */
|
|
34
58
|
resume(sessionId: string): string[];
|
|
35
59
|
/** Reads the CLI's output. Returns undefined if it isn't the CLI's output. */
|
|
36
60
|
parse(stdout: string): RuntimeOutput | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Reads one line of the CLI's output while it runs, and returns the text
|
|
63
|
+
* of the agent's message on that line, if it has one. The runner posts
|
|
64
|
+
* each message in place of the last, until the final reply replaces
|
|
65
|
+
* them. Without it, the runner posts only the final reply.
|
|
66
|
+
*/
|
|
67
|
+
message?(line: string): string | undefined;
|
|
37
68
|
/** Extra environment for the CLI. */
|
|
38
69
|
env?: Record<string, string>;
|
|
39
70
|
};
|
package/deployer/index.ts
CHANGED
|
@@ -22,9 +22,16 @@ export interface DeployerContext {
|
|
|
22
22
|
/**
|
|
23
23
|
* Stores the repo's outpost config, where the router reads it, and the
|
|
24
24
|
* `.factory/` files it was evaluated from. `ref` is the commit they were
|
|
25
|
-
* read at
|
|
25
|
+
* read at, and `executables` are the paths of the files that are
|
|
26
|
+
* executable. Resolves to the containers whose images started building.
|
|
26
27
|
*/
|
|
27
|
-
putOutpost(
|
|
28
|
+
putOutpost(
|
|
29
|
+
repo: string,
|
|
30
|
+
outpost: OutpostConfig,
|
|
31
|
+
files: Record<string, string>,
|
|
32
|
+
ref: string,
|
|
33
|
+
executables?: string[],
|
|
34
|
+
): Promise<string[]>;
|
|
28
35
|
/** The `.factory/` files of the repo's outpost. */
|
|
29
36
|
getFiles(repo: string): Promise<Record<string, string> | undefined>;
|
|
30
37
|
deleteOutpost(repo: string): Promise<void>;
|
|
@@ -136,7 +143,7 @@ const message = (error: unknown) => (error instanceof Error ? error.message : St
|
|
|
136
143
|
*/
|
|
137
144
|
export const deploy = async (
|
|
138
145
|
repo: string,
|
|
139
|
-
{ ref, files }: SourceFiles,
|
|
146
|
+
{ ref, files, executables }: SourceFiles,
|
|
140
147
|
context: DeployerContext,
|
|
141
148
|
): Promise<FactoryStatus> => {
|
|
142
149
|
if (!("infra.ts" in files)) {
|
|
@@ -144,8 +151,8 @@ export const deploy = async (
|
|
|
144
151
|
return { state: "failed", ref, error: `There's no ${FACTORY_DIR}/infra.ts.`, at: new Date().toISOString() };
|
|
145
152
|
}
|
|
146
153
|
try {
|
|
147
|
-
const
|
|
148
|
-
return { state: "deployed", ref, at: new Date().toISOString(), ...(
|
|
154
|
+
const builds = await context.putOutpost(repo, await evaluateOutpost(repo, files, context), files, ref, executables);
|
|
155
|
+
return { state: "deployed", ref, at: new Date().toISOString(), ...(builds.length && { builds }) };
|
|
149
156
|
} catch (error) {
|
|
150
157
|
return { state: "failed", ref, error: message(error), at: new Date().toISOString() };
|
|
151
158
|
}
|