@clemrig/factory 0.1.0 → 0.2.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/README.md +6 -17
- package/dist/app/doctor.d.ts +2 -4
- package/dist/app/doctor.js +6 -4
- package/dist/app/doctor.js.map +1 -1
- package/dist/app/factory.d.ts +2 -0
- package/dist/app/factory.js +13 -2
- package/dist/app/factory.js.map +1 -1
- package/dist/app/init.d.ts +1 -5
- package/dist/app/init.js +1 -13
- package/dist/app/init.js.map +1 -1
- package/dist/app/options.d.ts +17 -0
- package/dist/app/options.js +78 -0
- package/dist/app/options.js.map +1 -0
- package/dist/app/run.d.ts +4 -20
- package/dist/app/run.js +22 -93
- package/dist/app/run.js.map +1 -1
- package/dist/app/runs.d.ts +4 -32
- package/dist/app/runs.js +9 -61
- package/dist/app/runs.js.map +1 -1
- package/dist/cli/application.d.ts +1 -1
- package/dist/cli/application.js +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/doctor.d.ts +1 -1
- package/dist/cli/doctor.js +1 -1
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/help.d.ts +1 -1
- package/dist/cli/help.js +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +1 -1
- package/dist/cli/launcher.d.ts +1 -1
- package/dist/cli/launcher.js +4 -4
- package/dist/cli/launcher.js.map +1 -1
- package/dist/cli/reporter.d.ts +1 -1
- package/dist/cli/reporter.js +1 -2
- package/dist/cli/reporter.js.map +1 -1
- package/dist/cli/run.d.ts +1 -5
- package/dist/cli/run.js +24 -11
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/ui.d.ts +1 -1
- package/dist/cli/ui.js +10 -3
- package/dist/cli/ui.js.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/system/factory.d.ts +1 -1
- package/dist/system/factory.js +1 -1
- package/dist/system/factory.js.map +1 -1
- package/dist/system/npm.d.ts +5 -0
- package/dist/system/npm.js +14 -0
- package/dist/system/npm.js.map +1 -0
- package/dist/system/templates.d.ts +1 -1
- package/dist/system/templates.js +1 -1
- package/package.json +7 -17
- package/dist/engine/metrics.d.ts +0 -45
- package/dist/engine/metrics.js +0 -60
- package/dist/engine/metrics.js.map +0 -1
- package/dist/engine/primitives.d.ts +0 -34
- package/dist/engine/primitives.js +0 -81
- package/dist/engine/primitives.js.map +0 -1
- package/dist/engine/profiles.d.ts +0 -53
- package/dist/engine/profiles.js +0 -117
- package/dist/engine/profiles.js.map +0 -1
- package/dist/engine/runner.d.ts +0 -13
- package/dist/engine/runner.js +0 -157
- package/dist/engine/runner.js.map +0 -1
- package/dist/engine/types.d.ts +0 -194
- package/dist/engine/types.js +0 -2
- package/dist/engine/types.js.map +0 -1
- package/dist/engine/workflow.d.ts +0 -18
- package/dist/engine/workflow.js +0 -196
- package/dist/engine/workflow.js.map +0 -1
- package/dist/system/process.d.ts +0 -21
- package/dist/system/process.js +0 -238
- package/dist/system/process.js.map +0 -1
- package/dist/system/runtimes/adapter.d.ts +0 -90
- package/dist/system/runtimes/adapter.js +0 -20
- package/dist/system/runtimes/adapter.js.map +0 -1
- package/dist/system/runtimes/agent-runtime.d.ts +0 -45
- package/dist/system/runtimes/agent-runtime.js +0 -184
- package/dist/system/runtimes/agent-runtime.js.map +0 -1
- package/dist/system/runtimes/claude-code.d.ts +0 -10
- package/dist/system/runtimes/claude-code.js +0 -383
- package/dist/system/runtimes/claude-code.js.map +0 -1
- package/dist/system/runtimes/inspect.d.ts +0 -25
- package/dist/system/runtimes/inspect.js +0 -129
- package/dist/system/runtimes/inspect.js.map +0 -1
- package/dist/system/runtimes/pi.d.ts +0 -7
- package/dist/system/runtimes/pi.js +0 -235
- package/dist/system/runtimes/pi.js.map +0 -1
- package/dist/system/runtimes/protocol.d.ts +0 -9
- package/dist/system/runtimes/protocol.js +0 -38
- package/dist/system/runtimes/protocol.js.map +0 -1
- package/dist/system/runtimes/registry.d.ts +0 -5
- package/dist/system/runtimes/registry.js +0 -5
- package/dist/system/runtimes/registry.js.map +0 -1
- package/dist/system/store.d.ts +0 -20
- package/dist/system/store.js +0 -126
- package/dist/system/store.js.map +0 -1
- package/dist/ui/server.d.ts +0 -8
- package/dist/ui/server.js +0 -111
- package/dist/ui/server.js.map +0 -1
- package/dist/ui/static/dashboard.js +0 -266
- package/dist/ui/static/follow.js +0 -67
- package/dist/ui/static/index.html +0 -20
- package/dist/ui/static/style.css +0 -166
- package/dist/ui/static/timeline.js +0 -180
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export const END = null;
|
|
3
|
-
/** A correction route, taken at most `max` times per run. */
|
|
4
|
-
export function retry(to, max) {
|
|
5
|
-
return { to, max };
|
|
6
|
-
}
|
|
7
|
-
/** Binds a stage to its routes; every declared outcome must be routed. */
|
|
8
|
-
export function node(stage, on) {
|
|
9
|
-
return { stage, on };
|
|
10
|
-
}
|
|
11
|
-
/** Selects explicit agent context from the run input and workflow data. */
|
|
12
|
-
export function pick(...keys) {
|
|
13
|
-
return ({ state }) => Object.fromEntries(keys.flatMap((key) => {
|
|
14
|
-
const value = key === "input" ? state.input : state.data[key];
|
|
15
|
-
return value === undefined ? [] : [[key, value]];
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
/** AGENT primitive: one structured request; its untrusted output waits for a gate. */
|
|
19
|
-
export function agent(options) {
|
|
20
|
-
const { profile, prompt, session } = options;
|
|
21
|
-
return {
|
|
22
|
-
kind: "AGENT",
|
|
23
|
-
outcomes: ["ok"],
|
|
24
|
-
agent: {
|
|
25
|
-
profile,
|
|
26
|
-
...(prompt === undefined ? {} : { prompt }),
|
|
27
|
-
...(session === undefined ? {} : { session }),
|
|
28
|
-
},
|
|
29
|
-
async run(context) {
|
|
30
|
-
const { state } = context;
|
|
31
|
-
const output = await context.agent.execute({
|
|
32
|
-
profile,
|
|
33
|
-
prompt: prompt ?? state.stage,
|
|
34
|
-
session: typeof session === "function"
|
|
35
|
-
? session(state)
|
|
36
|
-
: (session ?? state.stage),
|
|
37
|
-
context: {
|
|
38
|
-
...(await options.context(context)),
|
|
39
|
-
...(state.feedback === undefined ? {} : { feedback: state.feedback }),
|
|
40
|
-
},
|
|
41
|
-
schema: z.toJSONSchema(options.schema),
|
|
42
|
-
});
|
|
43
|
-
return { outcome: "ok", output };
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/** CODE primitive: deterministic work with named outcomes. */
|
|
48
|
-
export function code(outcomes, run) {
|
|
49
|
-
return { kind: "CODE", outcomes, run };
|
|
50
|
-
}
|
|
51
|
-
/** CODE primitive with a single successful outcome. */
|
|
52
|
-
export function step(run) {
|
|
53
|
-
return code(["ok"], async (context) => {
|
|
54
|
-
const data = await run(context);
|
|
55
|
-
return { outcome: "ok", ...(data ? { data } : {}) };
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
/** GATE primitive: decides acceptance or correction from saved facts. */
|
|
59
|
-
export function gate(outcomes, run) {
|
|
60
|
-
return { kind: "GATE", outcomes, run };
|
|
61
|
-
}
|
|
62
|
-
/** GATE over the last agent output: schema, then business invariants; failures are corrections. */
|
|
63
|
-
export function schemaGate(options) {
|
|
64
|
-
return gate(["ok", "invalid"], async (context) => {
|
|
65
|
-
const parsed = options.schema.safeParse(context.state.output);
|
|
66
|
-
if (!parsed.success)
|
|
67
|
-
return {
|
|
68
|
-
outcome: "invalid",
|
|
69
|
-
reason: `Invalid structured output:\n${z.prettifyError(parsed.error)}`,
|
|
70
|
-
};
|
|
71
|
-
const checked = await options.check?.(parsed.data, context);
|
|
72
|
-
if (typeof checked === "string")
|
|
73
|
-
return { outcome: "invalid", reason: checked };
|
|
74
|
-
return {
|
|
75
|
-
outcome: "ok",
|
|
76
|
-
reason: `Structured output and invariants valid: ${options.into}`,
|
|
77
|
-
data: { ...(checked?.data ?? {}), [options.into]: parsed.data },
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=primitives.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/engine/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC;AAExB,6DAA6D;AAC7D,MAAM,UAAU,KAAK,CAAC,EAAU,EAAE,GAAW;IAC3C,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;AACrB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,IAAI,CAClB,KAAe,EACf,EAAmB;IAEnB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAkB,CAAC;AACvC,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,IAAI,CAClB,GAAG,IAAc;IAEjB,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CACnB,MAAM,CAAC,WAAW,CAChB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9D,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CACH,CAAC;AACN,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,KAAK,CACnB,OAGC;IAED,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC7C,OAAO;QACL,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,CAAC,IAAI,CAAC;QAChB,KAAK,EAAE;YACL,OAAO;Y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C,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE;SAChE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/** An agent stage's runtime, settings and access, declared in full by its workflow. */
|
|
3
|
-
export declare const profileSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
4
|
-
runtime: z.ZodLiteral<"pi">;
|
|
5
|
-
access: z.ZodDefault<z.ZodEnum<{
|
|
6
|
-
read: "read";
|
|
7
|
-
write: "write";
|
|
8
|
-
}>>;
|
|
9
|
-
provider: z.ZodString;
|
|
10
|
-
model: z.ZodString;
|
|
11
|
-
thinking: z.ZodEnum<{
|
|
12
|
-
high: "high";
|
|
13
|
-
low: "low";
|
|
14
|
-
max: "max";
|
|
15
|
-
medium: "medium";
|
|
16
|
-
minimal: "minimal";
|
|
17
|
-
off: "off";
|
|
18
|
-
xhigh: "xhigh";
|
|
19
|
-
}>;
|
|
20
|
-
tools: z.ZodArray<z.ZodString>;
|
|
21
|
-
skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
22
|
-
extensions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
23
|
-
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
24
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
25
|
-
runtime: z.ZodLiteral<"claude-code">;
|
|
26
|
-
access: z.ZodDefault<z.ZodEnum<{
|
|
27
|
-
read: "read";
|
|
28
|
-
write: "write";
|
|
29
|
-
}>>;
|
|
30
|
-
model: z.ZodString;
|
|
31
|
-
thinking: z.ZodEnum<{
|
|
32
|
-
high: "high";
|
|
33
|
-
low: "low";
|
|
34
|
-
max: "max";
|
|
35
|
-
medium: "medium";
|
|
36
|
-
xhigh: "xhigh";
|
|
37
|
-
}>;
|
|
38
|
-
tools: z.ZodArray<z.ZodString>;
|
|
39
|
-
mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
40
|
-
command: z.ZodString;
|
|
41
|
-
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
42
|
-
}, z.core.$strict>>>;
|
|
43
|
-
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
44
|
-
}, z.core.$strict>], "runtime">;
|
|
45
|
-
/** A profile as a workflow declares it. */
|
|
46
|
-
export type AgentProfile = z.input<typeof profileSchema>;
|
|
47
|
-
/** A profile with its defaults applied. */
|
|
48
|
-
export type ResolvedProfile = z.output<typeof profileSchema>;
|
|
49
|
-
export type Runtime = ResolvedProfile["runtime"];
|
|
50
|
-
/** Each runtime's name as the operator reads it. */
|
|
51
|
-
export declare const runtimeLabels: Record<Runtime, string>;
|
|
52
|
-
/** The profile with its defaults applied; an invalid profile is refused with its problems. */
|
|
53
|
-
export declare function resolveProfile(profile: AgentProfile): ResolvedProfile;
|
package/dist/engine/profiles.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/** Pi native tools; any other tool name must come from an explicitly trusted extension. */
|
|
3
|
-
const piBuiltinTools = new Set([
|
|
4
|
-
"read",
|
|
5
|
-
"bash",
|
|
6
|
-
"powershell",
|
|
7
|
-
"edit",
|
|
8
|
-
"write",
|
|
9
|
-
"grep",
|
|
10
|
-
"find",
|
|
11
|
-
"ls",
|
|
12
|
-
]);
|
|
13
|
-
/** Pi native tools that can change the repository or run commands. */
|
|
14
|
-
const piWriteTools = new Set(["bash", "powershell", "edit", "write"]);
|
|
15
|
-
/**
|
|
16
|
-
* The only Claude Code tools a read-only profile may use. Its native set grows with
|
|
17
|
-
* each version (worktrees, monitors, schedules…), so anything else is refused.
|
|
18
|
-
*/
|
|
19
|
-
const claudeCodeReadTools = new Set([
|
|
20
|
-
"Read",
|
|
21
|
-
"Grep",
|
|
22
|
-
"Glob",
|
|
23
|
-
"WebFetch",
|
|
24
|
-
"WebSearch",
|
|
25
|
-
]);
|
|
26
|
-
const timeoutMs = z.number().int().min(1000).max(7_200_000).default(900_000);
|
|
27
|
-
/** `read` by default; `write` allows tools that change the repository or run commands. */
|
|
28
|
-
const access = z.enum(["read", "write"]).default("read");
|
|
29
|
-
const piProfileSchema = z
|
|
30
|
-
.strictObject({
|
|
31
|
-
runtime: z.literal("pi"),
|
|
32
|
-
access,
|
|
33
|
-
// No default: a profile names the provider whose connection it uses.
|
|
34
|
-
provider: z.string().min(1),
|
|
35
|
-
model: z.string().min(1),
|
|
36
|
-
thinking: z.enum([
|
|
37
|
-
"off",
|
|
38
|
-
"minimal",
|
|
39
|
-
"low",
|
|
40
|
-
"medium",
|
|
41
|
-
"high",
|
|
42
|
-
"xhigh",
|
|
43
|
-
"max",
|
|
44
|
-
]),
|
|
45
|
-
// Exact names only: Pi allowlist patterns could accidentally grant mutation tools.
|
|
46
|
-
tools: z.array(z.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/)),
|
|
47
|
-
skills: z.array(z.string().min(1)).default([]),
|
|
48
|
-
extensions: z.array(z.string().min(1)).default([]),
|
|
49
|
-
timeoutMs,
|
|
50
|
-
})
|
|
51
|
-
.refine((profile) => profile.extensions.length > 0 ||
|
|
52
|
-
profile.tools.every((tool) => piBuiltinTools.has(tool)), {
|
|
53
|
-
path: ["tools"],
|
|
54
|
-
message: "Custom tools require explicitly trusted extensions",
|
|
55
|
-
});
|
|
56
|
-
const mcpTool = /^mcp__([a-zA-Z0-9][a-zA-Z0-9-]*)__[a-zA-Z0-9_-]+$/;
|
|
57
|
-
/** The server a Claude Code MCP tool name (`mcp__<server>__<tool>`) belongs to. */
|
|
58
|
-
function mcpToolServer(tool) {
|
|
59
|
-
return mcpTool.exec(tool)?.[1];
|
|
60
|
-
}
|
|
61
|
-
const claudeCodeProfileSchema = z
|
|
62
|
-
.strictObject({
|
|
63
|
-
runtime: z.literal("claude-code"),
|
|
64
|
-
access,
|
|
65
|
-
model: z.string().min(1),
|
|
66
|
-
/** Claude Code effort levels. */
|
|
67
|
-
thinking: z.enum(["low", "medium", "high", "xhigh", "max"]),
|
|
68
|
-
// Exact names only: rules such as Bash(git *) or "default" would change the tool set.
|
|
69
|
-
tools: z.array(z
|
|
70
|
-
.string()
|
|
71
|
-
.refine((tool) => /^[A-Z][a-zA-Z0-9]*$/.test(tool) || mcpTool.test(tool))),
|
|
72
|
-
// Without "_": `mcp__<server>__<tool>` names must split one way only.
|
|
73
|
-
mcpServers: z
|
|
74
|
-
.record(z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9-]*$/),
|
|
75
|
-
// No env: servers inherit the factory's environment, so secrets stay in .env.
|
|
76
|
-
z.strictObject({
|
|
77
|
-
command: z.string().min(1),
|
|
78
|
-
args: z.array(z.string()).default([]),
|
|
79
|
-
}))
|
|
80
|
-
.default({}),
|
|
81
|
-
timeoutMs,
|
|
82
|
-
})
|
|
83
|
-
.refine((profile) => profile.tools.every((tool) => {
|
|
84
|
-
const server = mcpToolServer(tool);
|
|
85
|
-
return (server === undefined || Object.hasOwn(profile.mcpServers, server));
|
|
86
|
-
}), { path: ["tools"], message: "MCP tools require a declared server" });
|
|
87
|
-
/** Tools a read-only profile must not have; tools of a declared MCP server are trusted like Pi extension tools. */
|
|
88
|
-
function writeTools(profile) {
|
|
89
|
-
return profile.tools.filter((tool) => profile.runtime === "pi"
|
|
90
|
-
? piWriteTools.has(tool)
|
|
91
|
-
: !claudeCodeReadTools.has(tool) && mcpToolServer(tool) === undefined);
|
|
92
|
-
}
|
|
93
|
-
/** An agent stage's runtime, settings and access, declared in full by its workflow. */
|
|
94
|
-
export const profileSchema = z
|
|
95
|
-
.discriminatedUnion("runtime", [piProfileSchema, claudeCodeProfileSchema])
|
|
96
|
-
.superRefine((profile, context) => {
|
|
97
|
-
const refused = profile.access === "read" ? writeTools(profile) : [];
|
|
98
|
-
if (refused.length)
|
|
99
|
-
context.addIssue({
|
|
100
|
-
code: "custom",
|
|
101
|
-
path: ["tools"],
|
|
102
|
-
message: `read-only profile must not include ${refused.join(", ")}; set access: "write" to allow it`,
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
/** Each runtime's name as the operator reads it. */
|
|
106
|
-
export const runtimeLabels = {
|
|
107
|
-
"claude-code": "Claude Code",
|
|
108
|
-
pi: "Pi",
|
|
109
|
-
};
|
|
110
|
-
/** The profile with its defaults applied; an invalid profile is refused with its problems. */
|
|
111
|
-
export function resolveProfile(profile) {
|
|
112
|
-
const parsed = profileSchema.safeParse(profile);
|
|
113
|
-
if (!parsed.success)
|
|
114
|
-
throw new Error(`Invalid agent profile:\n${z.prettifyError(parsed.error)}`);
|
|
115
|
-
return parsed.data;
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=profiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/engine/profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2FAA2F;AAC3F,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,MAAM;IACN,MAAM;IACN,YAAY;IACZ,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,IAAI;CACL,CAAC,CAAC;AACH,sEAAsE;AACtE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACtE;;;GAGG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU;IACV,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAE7E,0FAA0F;AAC1F,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,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,OAAqB;IAClD,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,OAAO;QACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
package/dist/engine/runner.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AgentPort, RunEvent, RunState, RunStore, Workflow } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Deterministic graph runner. Stages report outcomes; the graph routes them.
|
|
4
|
-
* Each retry edge is taken at most its maximum; an aborted run stops before its
|
|
5
|
-
* next stage, or fails instead of completing.
|
|
6
|
-
*/
|
|
7
|
-
export declare function executeWorkflow(workflow: Pick<Workflow, "nodes">, state: RunState, runtime: {
|
|
8
|
-
agent: AgentPort;
|
|
9
|
-
dir: string;
|
|
10
|
-
}, store: RunStore, options?: {
|
|
11
|
-
onEvent?: (event: RunEvent) => void;
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
}): Promise<RunState>;
|
package/dist/engine/runner.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The journal of one stage run: its messages and its agent's activity. Writes
|
|
3
|
-
* keep their call order and are awaited before the stage is routed; the first
|
|
4
|
-
* write failure fails the stage.
|
|
5
|
-
*/
|
|
6
|
-
function stageJournal(write, stage, kind) {
|
|
7
|
-
let pending = Promise.resolve();
|
|
8
|
-
let failure;
|
|
9
|
-
let closed = false;
|
|
10
|
-
const append = (event) => {
|
|
11
|
-
if (closed)
|
|
12
|
-
throw new Error(`Stage ${stage} logged after it ended`);
|
|
13
|
-
pending = pending
|
|
14
|
-
.then(() => write(event))
|
|
15
|
-
.catch((error) => {
|
|
16
|
-
failure ??= { error };
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
log(message, data) {
|
|
21
|
-
append({ type: "log", stage, kind, message, ...(data ? { data } : {}) });
|
|
22
|
-
},
|
|
23
|
-
activity(activity) {
|
|
24
|
-
append({ type: "agent", stage, kind, activity });
|
|
25
|
-
},
|
|
26
|
-
async flush() {
|
|
27
|
-
closed = true;
|
|
28
|
-
await pending;
|
|
29
|
-
if (failure)
|
|
30
|
-
throw failure.error;
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function errorMessage(error) {
|
|
35
|
-
return error instanceof Error ? error.message : String(error);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Deterministic graph runner. Stages report outcomes; the graph routes them.
|
|
39
|
-
* Each retry edge is taken at most its maximum; an aborted run stops before its
|
|
40
|
-
* next stage, or fails instead of completing.
|
|
41
|
-
*/
|
|
42
|
-
export async function executeWorkflow(workflow, state, runtime, store, options = {}) {
|
|
43
|
-
const emit = async (event) => {
|
|
44
|
-
const full = {
|
|
45
|
-
...event,
|
|
46
|
-
runId: state.id,
|
|
47
|
-
at: new Date().toISOString(),
|
|
48
|
-
};
|
|
49
|
-
await store.event(full);
|
|
50
|
-
options.onEvent?.(full);
|
|
51
|
-
};
|
|
52
|
-
while (state.status === "running") {
|
|
53
|
-
const node = workflow.nodes[state.stage];
|
|
54
|
-
if (!node)
|
|
55
|
-
throw new Error(`Unknown stage: ${state.stage}`);
|
|
56
|
-
const current = state.stage;
|
|
57
|
-
const kind = node.stage.kind;
|
|
58
|
-
let outcome = {};
|
|
59
|
-
const journal = stageJournal(emit, current, kind);
|
|
60
|
-
try {
|
|
61
|
-
if (options.signal?.aborted)
|
|
62
|
-
throw options.signal.reason ?? new Error("Run aborted");
|
|
63
|
-
await emit({ type: "stage", stage: current, kind, status: "started" });
|
|
64
|
-
const context = {
|
|
65
|
-
state,
|
|
66
|
-
dir: runtime.dir,
|
|
67
|
-
agent: {
|
|
68
|
-
execute: (request) => runtime.agent.execute(request, journal.activity),
|
|
69
|
-
},
|
|
70
|
-
log: journal.log,
|
|
71
|
-
};
|
|
72
|
-
const result = await node.stage.run(context);
|
|
73
|
-
await journal.flush();
|
|
74
|
-
if (!node.stage.outcomes.includes(result.outcome) ||
|
|
75
|
-
!Object.hasOwn(node.on, result.outcome))
|
|
76
|
-
throw new Error(`Stage ${current} returned unrouted outcome ${result.outcome}`);
|
|
77
|
-
const edge = node.on[result.outcome] ?? null;
|
|
78
|
-
const correction = typeof edge === "object" && edge !== null ? edge : undefined;
|
|
79
|
-
const next = correction ? correction.to : edge;
|
|
80
|
-
if (next !== null && !workflow.nodes[next])
|
|
81
|
-
throw new Error(`Unknown route: ${next}`);
|
|
82
|
-
const decision = kind === "GATE" || correction || result.reason
|
|
83
|
-
? {
|
|
84
|
-
verdict: correction ? "correction" : "accepted",
|
|
85
|
-
reason: result.reason ?? result.outcome,
|
|
86
|
-
destination: next,
|
|
87
|
-
}
|
|
88
|
-
: undefined;
|
|
89
|
-
outcome = {
|
|
90
|
-
...(decision ? { decision } : {}),
|
|
91
|
-
...(result.detail ? { detail: result.detail } : {}),
|
|
92
|
-
};
|
|
93
|
-
let retry;
|
|
94
|
-
if (correction) {
|
|
95
|
-
const key = `${current}.${result.outcome}`;
|
|
96
|
-
state.retries ??= {};
|
|
97
|
-
const count = (state.retries[key] ?? 0) + 1;
|
|
98
|
-
state.retries[key] = count;
|
|
99
|
-
retry = { key, count, max: correction.max };
|
|
100
|
-
outcome.retry = retry;
|
|
101
|
-
}
|
|
102
|
-
Object.assign(state.data, result.data);
|
|
103
|
-
if (Object.hasOwn(result, "output"))
|
|
104
|
-
state.output = result.output;
|
|
105
|
-
if (correction)
|
|
106
|
-
state.feedback = result.feedback ?? result.reason;
|
|
107
|
-
else if (kind === "GATE") {
|
|
108
|
-
delete state.feedback;
|
|
109
|
-
delete state.output;
|
|
110
|
-
}
|
|
111
|
-
if (retry && retry.count > retry.max)
|
|
112
|
-
throw new Error(`Retry ${retry.key} → ${next} exceeded its maximum of ${retry.max}`);
|
|
113
|
-
// The end of the run is a stage boundary too: an interrupted run never completes.
|
|
114
|
-
if (next === null && options.signal?.aborted)
|
|
115
|
-
throw options.signal.reason ?? new Error("Run aborted");
|
|
116
|
-
if (next === null)
|
|
117
|
-
state.status = "completed";
|
|
118
|
-
else
|
|
119
|
-
state.stage = next;
|
|
120
|
-
state.updatedAt = new Date().toISOString();
|
|
121
|
-
// The event first: a reader that sees the run ended has every event.
|
|
122
|
-
await emit({
|
|
123
|
-
type: "stage",
|
|
124
|
-
stage: current,
|
|
125
|
-
kind,
|
|
126
|
-
status: state.status === "running" ? "passed" : state.status,
|
|
127
|
-
...outcome,
|
|
128
|
-
});
|
|
129
|
-
await store.save(state);
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
// The stage's own failure takes precedence over a journal write failure.
|
|
133
|
-
await journal.flush().catch(() => undefined);
|
|
134
|
-
state.status = "failed";
|
|
135
|
-
state.error = errorMessage(error);
|
|
136
|
-
state.updatedAt = new Date().toISOString();
|
|
137
|
-
try {
|
|
138
|
-
await emit({
|
|
139
|
-
type: "stage",
|
|
140
|
-
stage: current,
|
|
141
|
-
kind,
|
|
142
|
-
status: "failed",
|
|
143
|
-
...outcome,
|
|
144
|
-
detail: outcome.detail
|
|
145
|
-
? `${outcome.detail}\n${state.error}`
|
|
146
|
-
: state.error,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
finally {
|
|
150
|
-
// The failed state is kept even if its event cannot be written.
|
|
151
|
-
await store.save(state);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return state;
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=runner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/engine/runner.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,SAAS,YAAY,CACnB,KAA0E,EAC1E,KAAa,E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AO;oBACb,KAAK,EAAE,OAAO;oBACd,IAAI;oBACJ,MAAM,EAAE,QAAQ;oBAChB,GAAG,OAAO;oBACV,MAAM,EAAE,OAAO,CAAC,MAAM;wBACpB,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,EAAE;wBACrC,CAAC,CAAC,KAAK,CAAC,KAAK;iBAChB,CAAC,CAAC;YACL,CAAC;oBAAS,CAAC;gBACT,gEAAgE;gBAChE,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/engine/types.d.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
import type { AgentUsage, RunMetrics, TokenCounts } from "./metrics.js";
|
|
3
|
-
import type { AgentProfile, ResolvedProfile, Runtime } from "./profiles.js";
|
|
4
|
-
export type StageKind = "AGENT" | "CODE" | "GATE";
|
|
5
|
-
/** What an agent stage asks of the agent runtime. */
|
|
6
|
-
export interface AgentRequest {
|
|
7
|
-
/** The stage's profile as declared; the runtime validates it and applies its defaults. */
|
|
8
|
-
profile: AgentProfile;
|
|
9
|
-
/** Name of the prompt file the runtime appends to its system prompt. */
|
|
10
|
-
prompt: string;
|
|
11
|
-
/** The run-local conversation the request continues. */
|
|
12
|
-
session: string;
|
|
13
|
-
context: unknown;
|
|
14
|
-
schema: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
/** Adds a message to the run journal: events.jsonl, terminal and --json. */
|
|
17
|
-
export type Log = (message: string, data?: Record<string, unknown>) => void;
|
|
18
|
-
/** What an agent call does, as its runtime reports it; never the messages themselves. */
|
|
19
|
-
export type AgentActivity = {
|
|
20
|
-
kind: "call";
|
|
21
|
-
status: "started";
|
|
22
|
-
runtime: Runtime;
|
|
23
|
-
model: string;
|
|
24
|
-
session: string;
|
|
25
|
-
} | {
|
|
26
|
-
kind: "call";
|
|
27
|
-
status: "completed" | "failed";
|
|
28
|
-
runtime: Runtime;
|
|
29
|
-
/** As the runtime announced it at the end of the call: the call's own, or its session's total. */
|
|
30
|
-
usage?: AgentUsage;
|
|
31
|
-
scope?: "call" | "session";
|
|
32
|
-
} | {
|
|
33
|
-
kind: "tool";
|
|
34
|
-
id: string;
|
|
35
|
-
name: string;
|
|
36
|
-
status: "started";
|
|
37
|
-
} | {
|
|
38
|
-
kind: "tool";
|
|
39
|
-
id: string;
|
|
40
|
-
name: string;
|
|
41
|
-
status: "completed" | "failed";
|
|
42
|
-
durationMs: number;
|
|
43
|
-
} | {
|
|
44
|
-
kind: "response";
|
|
45
|
-
tokens: TokenCounts;
|
|
46
|
-
costUsd?: number;
|
|
47
|
-
/** Reported while the call runs and replaced by the figures announced at its end. */
|
|
48
|
-
provisional: boolean;
|
|
49
|
-
} | {
|
|
50
|
-
kind: "warning";
|
|
51
|
-
message: string;
|
|
52
|
-
};
|
|
53
|
-
/** Records an agent call's activity under the calling stage. */
|
|
54
|
-
export type RecordActivity = (activity: AgentActivity) => void;
|
|
55
|
-
/** Agent execution managed by the core runtime; `record` journals its activity under the calling stage. */
|
|
56
|
-
export interface AgentPort {
|
|
57
|
-
execute(request: AgentRequest, record?: RecordActivity): Promise<unknown>;
|
|
58
|
-
}
|
|
59
|
-
export interface RunState {
|
|
60
|
-
/** 4 since workflows declare their inputs, agent profiles and retry maximums. */
|
|
61
|
-
version: 4;
|
|
62
|
-
id: string;
|
|
63
|
-
workflow: string;
|
|
64
|
-
/** Options validated by the workflow's input object. */
|
|
65
|
-
input: Record<string, unknown>;
|
|
66
|
-
stage: string;
|
|
67
|
-
status: "running" | "completed" | "failed";
|
|
68
|
-
/** Validated values written by the workflow's stages. */
|
|
69
|
-
data: Record<string, unknown>;
|
|
70
|
-
/** Owned by the engine: untrusted output of the last agent, cleared when a gate accepts. */
|
|
71
|
-
output?: unknown;
|
|
72
|
-
/** Owned by the engine: correction routed by the last retry edge, cleared when a gate accepts. */
|
|
73
|
-
feedback?: unknown;
|
|
74
|
-
/** Corrections taken per retry edge, keyed `<stage>.<outcome>`. */
|
|
75
|
-
retries?: Record<string, number>;
|
|
76
|
-
error?: string;
|
|
77
|
-
createdAt: string;
|
|
78
|
-
updatedAt: string;
|
|
79
|
-
metrics?: RunMetrics;
|
|
80
|
-
/** Each runtime the run used, with its version and connection, as checked before it started. */
|
|
81
|
-
runtimes?: Partial<Record<Runtime, string>>;
|
|
82
|
-
}
|
|
83
|
-
export interface WorkflowDecision {
|
|
84
|
-
verdict: "accepted" | "correction";
|
|
85
|
-
reason: string;
|
|
86
|
-
destination: string | null;
|
|
87
|
-
}
|
|
88
|
-
/** What a stage receives: its run, the agent runtime, the run journal and the repository. */
|
|
89
|
-
export interface StageContext {
|
|
90
|
-
state: Readonly<RunState>;
|
|
91
|
-
agent: AgentPort;
|
|
92
|
-
log: Log;
|
|
93
|
-
/** The repository the workflow works in: the directory that contains `.factory/`. */
|
|
94
|
-
dir: string;
|
|
95
|
-
}
|
|
96
|
-
/** A stage reports a named outcome; the workflow graph decides where it leads. */
|
|
97
|
-
export interface StageResult<O extends string = string> {
|
|
98
|
-
outcome: O;
|
|
99
|
-
/** Why this outcome was chosen; becomes the decision reason. */
|
|
100
|
-
reason?: string;
|
|
101
|
-
/** Correction carried by a retry edge to the next stage; defaults to the reason. */
|
|
102
|
-
feedback?: unknown;
|
|
103
|
-
/** Validated values merged into the run's data. */
|
|
104
|
-
data?: Record<string, unknown>;
|
|
105
|
-
/** Untrusted agent output, kept for the next gate. */
|
|
106
|
-
output?: unknown;
|
|
107
|
-
detail?: string;
|
|
108
|
-
}
|
|
109
|
-
/** What an agent stage declares, checked by `defineWorkflow`. */
|
|
110
|
-
export interface AgentDeclaration {
|
|
111
|
-
profile: AgentProfile;
|
|
112
|
-
/** Prompt file `prompts/<prompt>.md`; defaults to the stage name. */
|
|
113
|
-
prompt?: string;
|
|
114
|
-
/** Conversation name; defaults to the stage name. */
|
|
115
|
-
session?: string | ((state: Readonly<RunState>) => string);
|
|
116
|
-
}
|
|
117
|
-
export interface Stage<O extends string = string> {
|
|
118
|
-
kind: StageKind;
|
|
119
|
-
outcomes: readonly O[];
|
|
120
|
-
agent?: AgentDeclaration;
|
|
121
|
-
run: (context: StageContext) => Promise<StageResult<O>>;
|
|
122
|
-
}
|
|
123
|
-
/** A correction route, taken at most `max` times per run. */
|
|
124
|
-
export interface RetryEdge {
|
|
125
|
-
to: string;
|
|
126
|
-
max: number;
|
|
127
|
-
}
|
|
128
|
-
/** Next stage name, END (null) or a bounded correction route. */
|
|
129
|
-
export type Edge = string | null | RetryEdge;
|
|
130
|
-
export interface WorkflowNode<O extends string = string> {
|
|
131
|
-
stage: Stage<O>;
|
|
132
|
-
on: Record<O, Edge>;
|
|
133
|
-
}
|
|
134
|
-
/** What a workflow author writes: inputs, graph and an optional rendering. */
|
|
135
|
-
export interface WorkflowDefinition {
|
|
136
|
-
/** Also names the workflow's folder, which holds its `prompts/`. */
|
|
137
|
-
name: string;
|
|
138
|
-
/** Each field becomes a `--<name>` option of `factory run`. */
|
|
139
|
-
input?: z.ZodObject;
|
|
140
|
-
initial: string;
|
|
141
|
-
nodes: Record<string, WorkflowNode>;
|
|
142
|
-
/** Fails a run once its agents' announced cost exceeds it; `--max-cost-usd` replaces it for a run. */
|
|
143
|
-
maxCostUsd?: number;
|
|
144
|
-
/** Result lines; by default the run's validated data as JSON. */
|
|
145
|
-
presentResult?(state: Readonly<RunState>): string[];
|
|
146
|
-
}
|
|
147
|
-
/** An agent stage as `defineWorkflow` resolves it. */
|
|
148
|
-
export interface AgentStage {
|
|
149
|
-
profile: ResolvedProfile;
|
|
150
|
-
prompt: string;
|
|
151
|
-
}
|
|
152
|
-
/** A workflow validated by `defineWorkflow`. */
|
|
153
|
-
export interface Workflow extends WorkflowDefinition {
|
|
154
|
-
/** Agent stages by stage name. */
|
|
155
|
-
agents: Record<string, AgentStage>;
|
|
156
|
-
presentResult(state: Readonly<RunState>): string[];
|
|
157
|
-
}
|
|
158
|
-
export interface RetryContext {
|
|
159
|
-
/** The retry edge, `<stage>.<outcome>`. */
|
|
160
|
-
key: string;
|
|
161
|
-
count: number;
|
|
162
|
-
max: number;
|
|
163
|
-
}
|
|
164
|
-
interface EventBase {
|
|
165
|
-
runId: string;
|
|
166
|
-
stage: string;
|
|
167
|
-
kind: StageKind;
|
|
168
|
-
at: string;
|
|
169
|
-
}
|
|
170
|
-
/** Recorded by the engine when a stage starts and when it ends. */
|
|
171
|
-
export interface StageEvent extends EventBase {
|
|
172
|
-
type: "stage";
|
|
173
|
-
status: "started" | "passed" | "failed" | "completed";
|
|
174
|
-
retry?: RetryContext;
|
|
175
|
-
decision?: WorkflowDecision;
|
|
176
|
-
detail?: string;
|
|
177
|
-
}
|
|
178
|
-
/** Recorded by a stage, or by the agent runtime on its behalf, while it runs. */
|
|
179
|
-
export interface LogEvent extends EventBase {
|
|
180
|
-
type: "log";
|
|
181
|
-
message: string;
|
|
182
|
-
data?: Record<string, unknown>;
|
|
183
|
-
}
|
|
184
|
-
/** Recorded by the agent runtime for the calling stage while it runs. */
|
|
185
|
-
export interface AgentEvent extends EventBase {
|
|
186
|
-
type: "agent";
|
|
187
|
-
activity: AgentActivity;
|
|
188
|
-
}
|
|
189
|
-
export type RunEvent = StageEvent | LogEvent | AgentEvent;
|
|
190
|
-
export interface RunStore {
|
|
191
|
-
save(state: RunState): Promise<void>;
|
|
192
|
-
event(event: RunEvent): Promise<void>;
|
|
193
|
-
}
|
|
194
|
-
export {};
|
package/dist/engine/types.js
DELETED
package/dist/engine/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/engine/types.ts"],"names":[],"mappings":""}
|