@rarebit-one/harness-kernel 0.11.0 → 0.12.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/README.md +66 -0
- package/dist/engines/acp.d.ts.map +1 -1
- package/dist/engines/acp.js +34 -19
- package/dist/engines/acp.js.map +1 -1
- package/dist/engines/claudeCode.d.ts +23 -1
- package/dist/engines/claudeCode.d.ts.map +1 -1
- package/dist/engines/claudeCode.js +49 -18
- package/dist/engines/claudeCode.js.map +1 -1
- package/dist/engines/claudeCodeDriver.d.ts +9 -1
- package/dist/engines/claudeCodeDriver.d.ts.map +1 -1
- package/dist/engines/claudeCodeDriver.js +30 -0
- package/dist/engines/claudeCodeDriver.js.map +1 -1
- package/dist/engines/codex.d.ts +7 -1
- package/dist/engines/codex.d.ts.map +1 -1
- package/dist/engines/codex.js +31 -19
- package/dist/engines/codex.js.map +1 -1
- package/dist/engines/codexDriver.d.ts +1 -1
- package/dist/engines/codexDriver.d.ts.map +1 -1
- package/dist/engines/codexDriver.js +6 -0
- package/dist/engines/codexDriver.js.map +1 -1
- package/dist/engines/environment.d.ts +121 -0
- package/dist/engines/environment.d.ts.map +1 -0
- package/dist/engines/environment.js +318 -0
- package/dist/engines/environment.js.map +1 -0
- package/dist/engines/gateway.d.ts +99 -0
- package/dist/engines/gateway.d.ts.map +1 -0
- package/dist/engines/gateway.js +181 -0
- package/dist/engines/gateway.js.map +1 -0
- package/dist/engines/harnessPrompt.d.ts +15 -0
- package/dist/engines/harnessPrompt.d.ts.map +1 -0
- package/dist/engines/harnessPrompt.js +33 -0
- package/dist/engines/harnessPrompt.js.map +1 -0
- package/dist/engines/native.d.ts +15 -0
- package/dist/engines/native.d.ts.map +1 -1
- package/dist/engines/native.js +74 -5
- package/dist/engines/native.js.map +1 -1
- package/dist/engines/types.d.ts +45 -2
- package/dist/engines/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.d.ts +3 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +4 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/index.d.ts +10 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +3 -3
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openai.d.ts +3 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +4 -2
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter.d.ts +3 -1
- package/dist/providers/openrouter.d.ts.map +1 -1
- package/dist/providers/openrouter.js +4 -2
- package/dist/providers/openrouter.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { RunSpec } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A credential gateway: a host-side service that holds the run's real provider
|
|
4
|
+
* keys and injects them on the way out, so the run itself only ever holds a
|
|
5
|
+
* short-lived, attempt-bound run token.
|
|
6
|
+
*
|
|
7
|
+
* The mechanism is base-URL redirection, never interception: every supported
|
|
8
|
+
* harness and adapter honours a provider base URL, so a run is pointed at
|
|
9
|
+
* `<route>` with the run token in place of the API key, and the gateway swaps
|
|
10
|
+
* in the real key (and enforces its own budget) before forwarding. No CA, no
|
|
11
|
+
* TLS termination inside the sandbox.
|
|
12
|
+
*
|
|
13
|
+
* When a spec carries one, no engine puts a raw provider credential — the
|
|
14
|
+
* run's BYO keys or the host's own env keys — anywhere a harness can read it.
|
|
15
|
+
*/
|
|
16
|
+
export interface RunGateway {
|
|
17
|
+
/** The gateway's base URL; a provider's default route is `<baseUrl>/p/<provider>`. */
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
/** The attempt-bound token the gateway authenticates the run with. The only credential the run holds. */
|
|
20
|
+
runToken: string;
|
|
21
|
+
/** Per-provider base URLs, overriding the default route. */
|
|
22
|
+
routes?: Partial<Record<GatewayProvider, string>>;
|
|
23
|
+
}
|
|
24
|
+
export declare const GATEWAY_PROVIDERS: readonly ["anthropic", "openai", "openrouter"];
|
|
25
|
+
export type GatewayProvider = (typeof GATEWAY_PROVIDERS)[number];
|
|
26
|
+
/**
|
|
27
|
+
* Host env prefixes a harness must NOT inherit while a gateway is in use: a
|
|
28
|
+
* host `ANTHROPIC_BASE_URL` would route around the gateway, and a header or
|
|
29
|
+
* config var under these prefixes can carry a credential whose name the
|
|
30
|
+
* deny-list cannot spot (`ANTHROPIC_CUSTOM_HEADERS`).
|
|
31
|
+
*/
|
|
32
|
+
export declare const GATEWAY_SHADOWED_PREFIXES: readonly ["ANTHROPIC_", "OPENAI_", "OPENROUTER_"];
|
|
33
|
+
/** The base URL a provider is reached through. */
|
|
34
|
+
export declare function gatewayRoute(gateway: RunGateway, provider: GatewayProvider): string;
|
|
35
|
+
/**
|
|
36
|
+
* The env that points a harness at the gateway for each of `providers`: the
|
|
37
|
+
* route as its base URL and the run token as its key. This is what a harness
|
|
38
|
+
* gets INSTEAD of a credential.
|
|
39
|
+
*/
|
|
40
|
+
export declare function gatewayEnv(gateway: RunGateway, providers?: readonly GatewayProvider[]): Record<string, string>;
|
|
41
|
+
/**
|
|
42
|
+
* Drop the prefixes a gateway shadows from a harness's inherit list. A prefix
|
|
43
|
+
* overlapping one in either direction goes: `"ANTHROPIC_BASE"` sits inside a
|
|
44
|
+
* shadowed prefix, and a broader `"ANTHROPIC"` or `"A"` would match every
|
|
45
|
+
* shadowed var (and the host's `ANTHROPIC_CUSTOM_HEADERS`) just as well.
|
|
46
|
+
*/
|
|
47
|
+
export declare function withoutShadowed(prefixes: readonly string[]): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Why the spec's gateway cannot be used, or `undefined` when it can (or there
|
|
50
|
+
* is none). A malformed gateway is refused rather than ignored: ignoring it
|
|
51
|
+
* would fall back to raw credentials, which is the thing it exists to stop.
|
|
52
|
+
*/
|
|
53
|
+
export declare function gatewayProblem(spec: Pick<RunSpec, "gateway">): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The refusal a microVM lane relies on: a run the caller placed on `vm`
|
|
56
|
+
* isolation must not carry raw model credentials into the
|
|
57
|
+
* guest. It reaches models through a gateway or not at all.
|
|
58
|
+
*
|
|
59
|
+
* "Raw" is any non-empty `provider.credentials` slot, and any of `hostKeys`
|
|
60
|
+
* (the env keys this engine would otherwise fall back to) set on the host. The
|
|
61
|
+
* reason names the slots, never their values. A gateway exempts only what it
|
|
62
|
+
* replaces: the routed providers' slots and host keys, for which the engine
|
|
63
|
+
* sends the run token instead. Anything else it does not route (the local
|
|
64
|
+
* provider's key, say) is still raw, and still refused.
|
|
65
|
+
*/
|
|
66
|
+
export declare function refuseRawCredentialsInVm(engine: string, spec: Pick<RunSpec, "isolation" | "gateway" | "provider">, hostKeys?: readonly string[], env?: NodeJS.ProcessEnv): {
|
|
67
|
+
ok: false;
|
|
68
|
+
reason: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* The other half of the microVM rule: credentials the guest would hold in the
|
|
72
|
+
* clear that are NOT model keys. A gateway cannot inject these, so they are
|
|
73
|
+
* "exposed" — the run's `secrets` (they become the agent's env), and any
|
|
74
|
+
* connector credential the harness would carry itself (a bearer `auth.token`,
|
|
75
|
+
* or `headers` / `env` values a caller's connector shape adds).
|
|
76
|
+
*
|
|
77
|
+
* Under `vm` they are refused unless the spec says
|
|
78
|
+
* `exposedCredentials: "allowed"`, which only the caller's policy may set
|
|
79
|
+
* (the owner has not decided when exposed credentials are acceptable in a
|
|
80
|
+
* microVM, so the default is refuse). A connector whose token IS the
|
|
81
|
+
* gateway's run token is not exposed: that is a connector routed through the
|
|
82
|
+
* gateway, which injects the real credential host-side. The reason names
|
|
83
|
+
* secrets and connectors, never values.
|
|
84
|
+
*/
|
|
85
|
+
export declare function refuseExposedCredentialsInVm(engine: string, spec: Pick<RunSpec, "isolation" | "gateway" | "secrets" | "connectors" | "exposedCredentials">): {
|
|
86
|
+
ok: false;
|
|
87
|
+
reason: string;
|
|
88
|
+
} | undefined;
|
|
89
|
+
/** Every credential refusal a `vm` run gets: raw model keys first, then exposed credentials. */
|
|
90
|
+
export declare function refuseCredentialsInVm(engine: string, spec: Pick<RunSpec, "isolation" | "gateway" | "provider" | "secrets" | "connectors" | "exposedCredentials">, hostKeys?: readonly string[], env?: NodeJS.ProcessEnv): {
|
|
91
|
+
ok: false;
|
|
92
|
+
reason: string;
|
|
93
|
+
} | undefined;
|
|
94
|
+
/** The refusal for a spec whose gateway is unusable, in `supports()` shape. */
|
|
95
|
+
export declare function refuseBadGateway(engine: string, spec: Pick<RunSpec, "gateway">): {
|
|
96
|
+
ok: false;
|
|
97
|
+
reason: string;
|
|
98
|
+
} | undefined;
|
|
99
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/engines/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,UAAU;IACzB,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAA;IACf,yGAAyG;IACzG,QAAQ,EAAE,MAAM,CAAA;IAChB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAA;CAClD;AAED,eAAO,MAAM,iBAAiB,gDAAiD,CAAA;AAC/E,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAShE;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,mDAAoD,CAAA;AAE1F,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,GAAG,MAAM,CAEnF;AASD;;;;GAIG;AACH,wBAAgB,UAA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,GAAG,SAAS,CAK3C;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAC7B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAK3C"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
export const GATEWAY_PROVIDERS = ["anthropic", "openai", "openrouter"];
|
|
2
|
+
/** The env var each provider's harness reads its base URL and key from. */
|
|
3
|
+
const PROVIDER_ENV = {
|
|
4
|
+
anthropic: { baseUrl: "ANTHROPIC_BASE_URL", key: "ANTHROPIC_API_KEY" },
|
|
5
|
+
openai: { baseUrl: "OPENAI_BASE_URL", key: "OPENAI_API_KEY" },
|
|
6
|
+
openrouter: { baseUrl: "OPENROUTER_BASE_URL", key: "OPENROUTER_API_KEY" },
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Host env prefixes a harness must NOT inherit while a gateway is in use: a
|
|
10
|
+
* host `ANTHROPIC_BASE_URL` would route around the gateway, and a header or
|
|
11
|
+
* config var under these prefixes can carry a credential whose name the
|
|
12
|
+
* deny-list cannot spot (`ANTHROPIC_CUSTOM_HEADERS`).
|
|
13
|
+
*/
|
|
14
|
+
export const GATEWAY_SHADOWED_PREFIXES = ["ANTHROPIC_", "OPENAI_", "OPENROUTER_"];
|
|
15
|
+
/** The base URL a provider is reached through. */
|
|
16
|
+
export function gatewayRoute(gateway, provider) {
|
|
17
|
+
return gateway.routes?.[provider] ?? `${withoutTrailingSlashes(gateway.baseUrl)}/p/${provider}`;
|
|
18
|
+
}
|
|
19
|
+
// A loop, not `/\/+$/`: that regex backtracks polynomially on a run of slashes.
|
|
20
|
+
function withoutTrailingSlashes(url) {
|
|
21
|
+
let end = url.length;
|
|
22
|
+
while (end > 0 && url[end - 1] === "/")
|
|
23
|
+
end--;
|
|
24
|
+
return url.slice(0, end);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The env that points a harness at the gateway for each of `providers`: the
|
|
28
|
+
* route as its base URL and the run token as its key. This is what a harness
|
|
29
|
+
* gets INSTEAD of a credential.
|
|
30
|
+
*/
|
|
31
|
+
export function gatewayEnv(gateway, providers = GATEWAY_PROVIDERS) {
|
|
32
|
+
const env = {};
|
|
33
|
+
for (const provider of providers) {
|
|
34
|
+
env[PROVIDER_ENV[provider].baseUrl] = gatewayRoute(gateway, provider);
|
|
35
|
+
env[PROVIDER_ENV[provider].key] = gateway.runToken;
|
|
36
|
+
}
|
|
37
|
+
return env;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Drop the prefixes a gateway shadows from a harness's inherit list. A prefix
|
|
41
|
+
* overlapping one in either direction goes: `"ANTHROPIC_BASE"` sits inside a
|
|
42
|
+
* shadowed prefix, and a broader `"ANTHROPIC"` or `"A"` would match every
|
|
43
|
+
* shadowed var (and the host's `ANTHROPIC_CUSTOM_HEADERS`) just as well.
|
|
44
|
+
*/
|
|
45
|
+
export function withoutShadowed(prefixes) {
|
|
46
|
+
return prefixes.filter((p) => !GATEWAY_SHADOWED_PREFIXES.some((s) => p.startsWith(s) || s.startsWith(p)));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Why the spec's gateway cannot be used, or `undefined` when it can (or there
|
|
50
|
+
* is none). A malformed gateway is refused rather than ignored: ignoring it
|
|
51
|
+
* would fall back to raw credentials, which is the thing it exists to stop.
|
|
52
|
+
*/
|
|
53
|
+
export function gatewayProblem(spec) {
|
|
54
|
+
const gateway = spec.gateway;
|
|
55
|
+
if (gateway === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (typeof gateway.runToken !== "string" || gateway.runToken === "") {
|
|
58
|
+
return "gateway has no run token";
|
|
59
|
+
}
|
|
60
|
+
const urls = [
|
|
61
|
+
["baseUrl", gateway.baseUrl],
|
|
62
|
+
...Object.entries(gateway.routes ?? {}).map(([p, url]) => [
|
|
63
|
+
`routes.${p}`,
|
|
64
|
+
url,
|
|
65
|
+
]),
|
|
66
|
+
];
|
|
67
|
+
for (const [field, url] of urls) {
|
|
68
|
+
if (typeof url !== "string" || !/^https?:\/\/[^/\s]+/.test(url)) {
|
|
69
|
+
return `gateway ${field} is not an http(s) URL`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const provider of Object.keys(gateway.routes ?? {})) {
|
|
73
|
+
if (!GATEWAY_PROVIDERS.includes(provider)) {
|
|
74
|
+
return `gateway routes a provider this kernel does not know: ${provider}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The refusal a microVM lane relies on: a run the caller placed on `vm`
|
|
81
|
+
* isolation must not carry raw model credentials into the
|
|
82
|
+
* guest. It reaches models through a gateway or not at all.
|
|
83
|
+
*
|
|
84
|
+
* "Raw" is any non-empty `provider.credentials` slot, and any of `hostKeys`
|
|
85
|
+
* (the env keys this engine would otherwise fall back to) set on the host. The
|
|
86
|
+
* reason names the slots, never their values. A gateway exempts only what it
|
|
87
|
+
* replaces: the routed providers' slots and host keys, for which the engine
|
|
88
|
+
* sends the run token instead. Anything else it does not route (the local
|
|
89
|
+
* provider's key, say) is still raw, and still refused.
|
|
90
|
+
*/
|
|
91
|
+
export function refuseRawCredentialsInVm(engine, spec, hostKeys = [], env = process.env) {
|
|
92
|
+
if (spec.isolation !== "vm")
|
|
93
|
+
return undefined;
|
|
94
|
+
const routed = spec.gateway !== undefined;
|
|
95
|
+
// CODEX_API_KEY is codex's alias for OPENAI_API_KEY; its engine sets it to
|
|
96
|
+
// the run token under a gateway too. No other engine passes it as a host key.
|
|
97
|
+
const routedKeys = [
|
|
98
|
+
...GATEWAY_PROVIDERS.map((p) => PROVIDER_ENV[p].key),
|
|
99
|
+
"CODEX_API_KEY",
|
|
100
|
+
];
|
|
101
|
+
const raw = [
|
|
102
|
+
...Object.entries(spec.provider.credentials ?? {})
|
|
103
|
+
.filter(([, value]) => typeof value === "string" && value !== "")
|
|
104
|
+
.filter(([slot]) => !(routed && GATEWAY_PROVIDERS.includes(slot)))
|
|
105
|
+
.map(([slot]) => `provider.credentials.${slot}`),
|
|
106
|
+
...hostKeys
|
|
107
|
+
.filter((key) => Boolean(env[key]) && !(routed && routedKeys.includes(key)))
|
|
108
|
+
.map((key) => `host ${key}`),
|
|
109
|
+
];
|
|
110
|
+
if (raw.length === 0)
|
|
111
|
+
return undefined;
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
reason: `${engine} engine refuses a vm run holding raw model credentials (${raw.join(", ")}); ` +
|
|
115
|
+
"route it through a credential gateway (RunSpec.gateway) instead",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The other half of the microVM rule: credentials the guest would hold in the
|
|
120
|
+
* clear that are NOT model keys. A gateway cannot inject these, so they are
|
|
121
|
+
* "exposed" — the run's `secrets` (they become the agent's env), and any
|
|
122
|
+
* connector credential the harness would carry itself (a bearer `auth.token`,
|
|
123
|
+
* or `headers` / `env` values a caller's connector shape adds).
|
|
124
|
+
*
|
|
125
|
+
* Under `vm` they are refused unless the spec says
|
|
126
|
+
* `exposedCredentials: "allowed"`, which only the caller's policy may set
|
|
127
|
+
* (the owner has not decided when exposed credentials are acceptable in a
|
|
128
|
+
* microVM, so the default is refuse). A connector whose token IS the
|
|
129
|
+
* gateway's run token is not exposed: that is a connector routed through the
|
|
130
|
+
* gateway, which injects the real credential host-side. The reason names
|
|
131
|
+
* secrets and connectors, never values.
|
|
132
|
+
*/
|
|
133
|
+
export function refuseExposedCredentialsInVm(engine, spec) {
|
|
134
|
+
if (spec.isolation !== "vm" || spec.exposedCredentials === "allowed")
|
|
135
|
+
return undefined;
|
|
136
|
+
const runToken = spec.gateway?.runToken;
|
|
137
|
+
const exposed = [
|
|
138
|
+
...Object.entries(spec.secrets ?? {})
|
|
139
|
+
.filter(([, value]) => typeof value === "string" && value !== "")
|
|
140
|
+
.map(([name]) => `secret ${name}`),
|
|
141
|
+
...(spec.connectors ?? []).flatMap((connector) => {
|
|
142
|
+
const found = [];
|
|
143
|
+
const token = connector.auth?.token;
|
|
144
|
+
if (typeof token === "string" && token !== "" && token !== runToken) {
|
|
145
|
+
found.push(`connector ${connector.name} auth.token`);
|
|
146
|
+
}
|
|
147
|
+
// Not part of ConnectorConfig, but a caller's connector may carry them,
|
|
148
|
+
// and whatever is there reaches the harness.
|
|
149
|
+
const extra = connector;
|
|
150
|
+
for (const field of ["headers", "env"]) {
|
|
151
|
+
const values = extra[field];
|
|
152
|
+
if (values &&
|
|
153
|
+
typeof values === "object" &&
|
|
154
|
+
Object.values(values).some((v) => v !== "" && v != null)) {
|
|
155
|
+
found.push(`connector ${connector.name} ${field}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return found;
|
|
159
|
+
}),
|
|
160
|
+
];
|
|
161
|
+
if (exposed.length === 0)
|
|
162
|
+
return undefined;
|
|
163
|
+
return {
|
|
164
|
+
ok: false,
|
|
165
|
+
reason: `${engine} engine refuses a vm run holding exposed credentials (${exposed.join(", ")}); ` +
|
|
166
|
+
'they reach the guest in the clear, so they need exposedCredentials: "allowed" from policy',
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** Every credential refusal a `vm` run gets: raw model keys first, then exposed credentials. */
|
|
170
|
+
export function refuseCredentialsInVm(engine, spec, hostKeys = [], env = process.env) {
|
|
171
|
+
return (refuseRawCredentialsInVm(engine, spec, hostKeys, env) ??
|
|
172
|
+
refuseExposedCredentialsInVm(engine, spec));
|
|
173
|
+
}
|
|
174
|
+
/** The refusal for a spec whose gateway is unusable, in `supports()` shape. */
|
|
175
|
+
export function refuseBadGateway(engine, spec) {
|
|
176
|
+
const problem = gatewayProblem(spec);
|
|
177
|
+
return problem
|
|
178
|
+
? { ok: false, reason: `${engine} engine cannot use this run's gateway: ${problem}` }
|
|
179
|
+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AE,QAAQ,EAAE,GAAG,CAAC;QACrD,4BAA4B,CAAC,MAAM,EAAE,IAAI,CAAC,CAC3C,CAAA;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,IAA8B;IAE9B,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,OAAO;QACZ,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,0CAA0C,OAAO,EAAE,EAAE;QACrF,CAAC,CAAC,SAAS,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RunSpec } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The task prompt an out-of-process harness (Claude Code, codex, an ACP agent)
|
|
4
|
+
* is handed: the workflow prompt, the run's inputs, the caller's pre-assembled
|
|
5
|
+
* context when there is any, and a closing instruction.
|
|
6
|
+
*
|
|
7
|
+
* These harnesses explore the working tree with their own tools, but that is no
|
|
8
|
+
* reason to drop `spec.context`: it can carry material that is not on disk at
|
|
9
|
+
* all (curated notes, assembled memory), which is exactly what the native loop
|
|
10
|
+
* bakes into its own prompt. An empty context adds nothing, so a run without one
|
|
11
|
+
* gets the prompt it always had. `instructions` is for a harness with no
|
|
12
|
+
* system-prompt slot of its own; absent, it adds nothing either.
|
|
13
|
+
*/
|
|
14
|
+
export declare function harnessPrompt(spec: RunSpec, instructions?: string): string;
|
|
15
|
+
//# sourceMappingURL=harnessPrompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harnessPrompt.d.ts","sourceRoot":"","sources":["../../src/engines/harnessPrompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAmB1E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The task prompt an out-of-process harness (Claude Code, codex, an ACP agent)
|
|
3
|
+
* is handed: the workflow prompt, the run's inputs, the caller's pre-assembled
|
|
4
|
+
* context when there is any, and a closing instruction.
|
|
5
|
+
*
|
|
6
|
+
* These harnesses explore the working tree with their own tools, but that is no
|
|
7
|
+
* reason to drop `spec.context`: it can carry material that is not on disk at
|
|
8
|
+
* all (curated notes, assembled memory), which is exactly what the native loop
|
|
9
|
+
* bakes into its own prompt. An empty context adds nothing, so a run without one
|
|
10
|
+
* gets the prompt it always had. `instructions` is for a harness with no
|
|
11
|
+
* system-prompt slot of its own; absent, it adds nothing either.
|
|
12
|
+
*/
|
|
13
|
+
export function harnessPrompt(spec, instructions) {
|
|
14
|
+
const inputs = JSON.stringify(spec.inputs ?? {}, null, 2);
|
|
15
|
+
const context = spec.context?.trim() ? ["## Workspace context", spec.context, ""] : [];
|
|
16
|
+
// For a harness with no system-prompt slot: instructions lead the prompt.
|
|
17
|
+
const preamble = instructions ? ["## Instructions", instructions, ""] : [];
|
|
18
|
+
return [
|
|
19
|
+
...preamble,
|
|
20
|
+
spec.workflow.prompt ?? `Execute the "${spec.workflow.name ?? spec.workflowPath}" workflow.`,
|
|
21
|
+
"",
|
|
22
|
+
"## Inputs",
|
|
23
|
+
"```json",
|
|
24
|
+
inputs,
|
|
25
|
+
"```",
|
|
26
|
+
"",
|
|
27
|
+
...context,
|
|
28
|
+
"You are running as an autonomous workflow. The current working directory is the",
|
|
29
|
+
"workspace — inspect and edit its files directly with your tools. When finished,",
|
|
30
|
+
"reply with the workflow's output as Markdown.",
|
|
31
|
+
].join("\n");
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=harnessPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harnessPrompt.js","sourceRoot":"","sources":["../../src/engines/harnessPrompt.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,IAAa,EAAE,YAAqB;IAChE,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACzD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,sBAAsB,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACtF,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,OAAO;QACL,GAAG,QAAQ;QACX,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,gBAAgB,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,aAAa;QAC5F,EAAE;QACF,WAAW;QACX,SAAS;QACT,MAAM;QACN,KAAK;QACL,EAAE;QACF,GAAG,OAAO;QACV,iFAAiF;QACjF,iFAAiF;QACjF,+CAA+C;KAChD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
package/dist/engines/native.d.ts
CHANGED
|
@@ -65,4 +65,19 @@ export declare class NativeEngine implements AgentEngine {
|
|
|
65
65
|
*/
|
|
66
66
|
private buildContext;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The provider selection the run resolves against. With a gateway, every
|
|
70
|
+
* cloud adapter is pointed at its gateway route and keyed with the run token,
|
|
71
|
+
* replacing the run's BYO keys — and, because a key is now always present, the
|
|
72
|
+
* host's env keys are never reached either. The `local` provider is not
|
|
73
|
+
* routed: private inference never leaves the host anyway.
|
|
74
|
+
*
|
|
75
|
+
* Because the run token keys every cloud adapter, a run with no preference
|
|
76
|
+
* would always resolve to the first one in order. So the preference is pinned
|
|
77
|
+
* to the provider the run would have resolved without the gateway (its BYO
|
|
78
|
+
* key, else the host's), keeping an OpenAI-only run on OpenAI. When none
|
|
79
|
+
* would resolve, the run token is not handed out, and the selection fails
|
|
80
|
+
* exactly as it would have without the gateway.
|
|
81
|
+
*/
|
|
82
|
+
export declare function providerSelection(spec: RunSpec, env?: NodeJS.ProcessEnv): RunSpec["provider"];
|
|
68
83
|
//# sourceMappingURL=native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/engines/native.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1F,OAAO,EAA6B,KAAK,IAAI,EAAE,MAAM,YAAY,CAAA;AAMjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/engines/native.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1F,OAAO,EAA6B,KAAK,IAAI,EAAE,MAAM,YAAY,CAAA;AAMjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AASlG;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE,CAAA;AAE9D,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAA;IACpC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ;AAED;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,WAAW;IAC9C,QAAQ,CAAC,IAAI,YAAW;IAExB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmB;IAC/C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IACpD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAM;gBAEf,OAAO,GAAE,mBAAwB;IAM7C;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa;IAajC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;YA+BrD,OAAO;IAwGrB;;;;;OAKG;YACW,YAAY;CAY3B;AAeD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAAC,UAAU,CAAC,CAyBrB"}
|
package/dist/engines/native.js
CHANGED
|
@@ -7,6 +7,8 @@ import { providerAvailability, selectProvider } from "../providers/index.js";
|
|
|
7
7
|
import { secretsToEnv } from "../secrets.js";
|
|
8
8
|
import { primitiveTools, connectorTools } from "../tools/registry.js";
|
|
9
9
|
import { PrivateRunError, privateRunChannels } from "../private.js";
|
|
10
|
+
import { environmentInstructions } from "./environment.js";
|
|
11
|
+
import { GATEWAY_PROVIDERS, gatewayRoute, refuseBadGateway, refuseCredentialsInVm, } from "./gateway.js";
|
|
10
12
|
/**
|
|
11
13
|
* The in-process native engine: the provider-neutral tool-use loop over the
|
|
12
14
|
* general-purpose primitives (run_code, read_file, list_files, http_fetch) plus
|
|
@@ -39,9 +41,16 @@ export class NativeEngine {
|
|
|
39
41
|
supports(spec) {
|
|
40
42
|
if (!spec)
|
|
41
43
|
return { ok: true };
|
|
44
|
+
// Before the private branch: a private run is held to local inference, but
|
|
45
|
+
// a vm run must still carry no raw or exposed credentials, and a
|
|
46
|
+
// malformed gateway is refused whatever the run is.
|
|
47
|
+
const refusal = refuseBadGateway("native", spec) ?? refuseCredentialsInVm("native", spec, HOST_MODEL_KEYS);
|
|
48
|
+
if (refusal)
|
|
49
|
+
return refusal;
|
|
42
50
|
if (spec.private)
|
|
43
51
|
return privateProviderSupport(spec);
|
|
44
|
-
|
|
52
|
+
const selection = providerSelection(spec);
|
|
53
|
+
return providerAvailability(selection.preferred, selection);
|
|
45
54
|
}
|
|
46
55
|
async run(spec, ctx) {
|
|
47
56
|
if (!spec.private)
|
|
@@ -86,7 +95,8 @@ export class NativeEngine {
|
|
|
86
95
|
// The whole selection, not a hand-picked subset: `supports()` judged the
|
|
87
96
|
// run on `spec.provider` (including `allowMockFallback`), so `run()` must
|
|
88
97
|
// resolve it from the same object or the two can disagree.
|
|
89
|
-
const
|
|
98
|
+
const selection = providerSelection(spec);
|
|
99
|
+
const provider = selectProvider(selection.preferred, selection);
|
|
90
100
|
// Belt and braces for the private path: whatever selection did, a private
|
|
91
101
|
// run proceeds on the local provider or not at all.
|
|
92
102
|
if (spec.private && provider.name !== "local") {
|
|
@@ -136,7 +146,11 @@ export class NativeEngine {
|
|
|
136
146
|
const model = asChatModel(provider);
|
|
137
147
|
const result = await runWithEvents(this.loop, {
|
|
138
148
|
model,
|
|
139
|
-
system: buildSystemPrompt(spec.workflow, spec.workspaceId, spec.workflowPath
|
|
149
|
+
system: buildSystemPrompt(spec.workflow, spec.workspaceId, spec.workflowPath,
|
|
150
|
+
// The loop has no AGENTS.md discovery and no skills tool, so both
|
|
151
|
+
// ride in the system prompt; the skill files themselves are on
|
|
152
|
+
// disk for read_file.
|
|
153
|
+
environmentInstructions(spec, { agentsMd: true, skillsIndex: true })),
|
|
140
154
|
messages: [{ role: "user", text: buildUserPrompt(spec.workflow, context, spec.inputs) }],
|
|
141
155
|
tools,
|
|
142
156
|
limits: resolveLoopLimits(spec.limits),
|
|
@@ -186,6 +200,55 @@ export class NativeEngine {
|
|
|
186
200
|
return spec.context ? `${spec.context}\n\n${assembled}` : assembled;
|
|
187
201
|
}
|
|
188
202
|
}
|
|
203
|
+
/** The host env keys the cloud adapters fall back to, in `selectProvider`'s order. */
|
|
204
|
+
const CLOUD_ENV_KEYS = {
|
|
205
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
206
|
+
openai: "OPENAI_API_KEY",
|
|
207
|
+
openrouter: "OPENROUTER_API_KEY",
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Every host env key a native run can end up holding: the cloud fallbacks and
|
|
211
|
+
* the local provider's optional key, which `selectProvider` also reads.
|
|
212
|
+
*/
|
|
213
|
+
const HOST_MODEL_KEYS = [...Object.values(CLOUD_ENV_KEYS), "LOCAL_MODEL_API_KEY"];
|
|
214
|
+
/**
|
|
215
|
+
* The provider selection the run resolves against. With a gateway, every
|
|
216
|
+
* cloud adapter is pointed at its gateway route and keyed with the run token,
|
|
217
|
+
* replacing the run's BYO keys — and, because a key is now always present, the
|
|
218
|
+
* host's env keys are never reached either. The `local` provider is not
|
|
219
|
+
* routed: private inference never leaves the host anyway.
|
|
220
|
+
*
|
|
221
|
+
* Because the run token keys every cloud adapter, a run with no preference
|
|
222
|
+
* would always resolve to the first one in order. So the preference is pinned
|
|
223
|
+
* to the provider the run would have resolved without the gateway (its BYO
|
|
224
|
+
* key, else the host's), keeping an OpenAI-only run on OpenAI. When none
|
|
225
|
+
* would resolve, the run token is not handed out, and the selection fails
|
|
226
|
+
* exactly as it would have without the gateway.
|
|
227
|
+
*/
|
|
228
|
+
export function providerSelection(spec, env = process.env) {
|
|
229
|
+
const gateway = spec.gateway;
|
|
230
|
+
if (!gateway)
|
|
231
|
+
return spec.provider;
|
|
232
|
+
const baseURLs = Object.fromEntries(GATEWAY_PROVIDERS.map((p) => [p, gatewayRoute(gateway, p)]));
|
|
233
|
+
const local = spec.provider.credentials?.local;
|
|
234
|
+
const localOnly = local !== undefined ? { local } : {};
|
|
235
|
+
let preferred = spec.provider.preferred;
|
|
236
|
+
if (typeof preferred !== "string" || preferred.trim() === "") {
|
|
237
|
+
const configured = GATEWAY_PROVIDERS.find((p) => spec.provider.credentials?.[p] ?? env[CLOUD_ENV_KEYS[p]]);
|
|
238
|
+
// Nothing would resolve, so every cloud slot is absent or deliberately
|
|
239
|
+
// empty; keep them as sent, since an empty slot is what stops the host key.
|
|
240
|
+
if (!configured)
|
|
241
|
+
return { ...spec.provider, baseURLs };
|
|
242
|
+
preferred = configured;
|
|
243
|
+
}
|
|
244
|
+
const token = gateway.runToken;
|
|
245
|
+
return {
|
|
246
|
+
...spec.provider,
|
|
247
|
+
preferred,
|
|
248
|
+
credentials: { anthropic: token, openai: token, openrouter: token, ...localOnly },
|
|
249
|
+
baseURLs,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
189
252
|
/**
|
|
190
253
|
* Whether a private run can be held to local inference on this host. Only an
|
|
191
254
|
* explicit `preferred: "local"` with `LOCAL_MODEL_BASE_URL` set qualifies; every
|
|
@@ -233,8 +296,13 @@ function untilAborted(work, signal) {
|
|
|
233
296
|
work.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
234
297
|
});
|
|
235
298
|
}
|
|
236
|
-
|
|
237
|
-
|
|
299
|
+
/**
|
|
300
|
+
* The loop's system prompt. `instructions` (the run's environment, when it has
|
|
301
|
+
* one) goes last, after the kernel's own framing, so a run without one gets
|
|
302
|
+
* exactly the prompt it always had.
|
|
303
|
+
*/
|
|
304
|
+
function buildSystemPrompt(workflow, workspaceId, workflowPath, instructions) {
|
|
305
|
+
const base = [
|
|
238
306
|
"You are an autonomous workflow executing in an isolated workspace sandbox.",
|
|
239
307
|
`Workspace: ${workspaceId}`,
|
|
240
308
|
`Workflow: ${workflow.name ?? workflowPath}`,
|
|
@@ -244,6 +312,7 @@ function buildSystemPrompt(workflow, workspaceId, workflowPath) {
|
|
|
244
312
|
"than doing it yourself. When finished, reply with the workflow's output as",
|
|
245
313
|
"Markdown and no further tool calls.",
|
|
246
314
|
].join("\n");
|
|
315
|
+
return instructions ? `${base}\n\n${instructions}` : base;
|
|
247
316
|
}
|
|
248
317
|
function buildUserPrompt(workflow, context, inputs) {
|
|
249
318
|
const inputsJson = JSON.stringify(inputs ?? {}, null, 2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../src/engines/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAwB,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAa,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../src/engines/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAwB,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAa,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,cAAc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AAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
package/dist/engines/types.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { ProviderOptions } from "../providers/options.js";
|
|
|
4
4
|
import type { FinishReason } from "../providers/types.js";
|
|
5
5
|
import type { ConnectorConfig, Permissions, WorkflowDefinition } from "../types.js";
|
|
6
6
|
import type { Isolation } from "./isolation.js";
|
|
7
|
+
import type { EnvironmentFile, RunInstructions, RunSkill, RunSource } from "./environment.js";
|
|
8
|
+
import type { RunGateway } from "./gateway.js";
|
|
7
9
|
/**
|
|
8
10
|
* The provider-neutral, harness-neutral description of one workflow run, handed
|
|
9
11
|
* to an {@link AgentEngine}. It carries the *materials* (a prepared on-disk
|
|
@@ -24,8 +26,10 @@ export interface RunSpec {
|
|
|
24
26
|
workflow: WorkflowDefinition;
|
|
25
27
|
/** The run's structured inputs (context_bundle.inputs). */
|
|
26
28
|
inputs: Record<string, unknown>;
|
|
27
|
-
/** Pre-assembled curated context text.
|
|
28
|
-
* prompt
|
|
29
|
+
/** Pre-assembled curated context text. Every engine puts it in the task
|
|
30
|
+
* prompt — the native loop always, an out-of-process harness (Claude Code,
|
|
31
|
+
* codex, ACP) whenever it is non-empty — since it may carry material that is
|
|
32
|
+
* not on disk for the harness to find. */
|
|
29
33
|
context: string;
|
|
30
34
|
/** Absolute path to the prepared sandbox working tree (the engine edits here). */
|
|
31
35
|
workdir: string;
|
|
@@ -71,6 +75,45 @@ export interface RunSpec {
|
|
|
71
75
|
* nothing. The returned `EngineResult.text` is still the caller's to place.
|
|
72
76
|
*/
|
|
73
77
|
private?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Instructions on top of the harness's own defaults (see `environment.ts`).
|
|
80
|
+
* `system` reaches every engine through its system-prompt slot or nearest
|
|
81
|
+
* equivalent; `agentsMd` is the workdir root's `AGENTS.md`, which the caller
|
|
82
|
+
* materializes and an engine whose harness does not read `AGENTS.md` also
|
|
83
|
+
* puts in its prompt. Absent changes nothing.
|
|
84
|
+
*/
|
|
85
|
+
instructions?: RunInstructions;
|
|
86
|
+
/** Nested `AGENTS.md` files, materialized by the caller. Absent changes nothing. */
|
|
87
|
+
agentFiles?: EnvironmentFile[];
|
|
88
|
+
/**
|
|
89
|
+
* Agent Skills, materialized by the caller under `.agents/skills/<name>/`.
|
|
90
|
+
* Claude Code also gets them as a local plugin; every other engine is told
|
|
91
|
+
* where they are. Absent changes nothing.
|
|
92
|
+
*/
|
|
93
|
+
skills?: RunSkill[];
|
|
94
|
+
/**
|
|
95
|
+
* Run inputs that are not workspace content (inline files today), written by
|
|
96
|
+
* the caller before setup and removed before the change set is computed.
|
|
97
|
+
* Absent changes nothing.
|
|
98
|
+
*/
|
|
99
|
+
sources?: RunSource[];
|
|
100
|
+
/**
|
|
101
|
+
* A credential gateway for the run's model calls (see `gateway.ts`). When
|
|
102
|
+
* present, every engine reaches its provider through the gateway's route
|
|
103
|
+
* with `runToken` as the key, and no raw credential — `provider.credentials`
|
|
104
|
+
* or the host's env keys — reaches a harness. A malformed gateway is
|
|
105
|
+
* refused in `supports()`, never ignored. Absent changes nothing, except
|
|
106
|
+
* that a `vm` run holding raw credentials is refused.
|
|
107
|
+
*/
|
|
108
|
+
gateway?: RunGateway;
|
|
109
|
+
/**
|
|
110
|
+
* Whether a `vm` run may hold exposed credentials — `secrets`, or a
|
|
111
|
+
* connector credential the harness carries itself — which reach the guest
|
|
112
|
+
* in the clear because no gateway can inject them. Absent (or anything but
|
|
113
|
+
* `"allowed"`) refuses such a run; only the caller's policy should set it,
|
|
114
|
+
* never a workflow author. Ignored below `vm`.
|
|
115
|
+
*/
|
|
116
|
+
exposedCredentials?: "allowed" | "refused";
|
|
74
117
|
}
|
|
75
118
|
export interface EngineContext {
|
|
76
119
|
/** Append a timestamped line to the run's logs. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/engines/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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