@nylorun/core 0.0.0-bootstrap → 0.2.0-beta

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +192 -0
  3. package/README.md +16 -0
  4. package/dist/compatibility.d.ts +3 -0
  5. package/dist/compatibility.js +3 -0
  6. package/dist/contracts.d.ts +330 -0
  7. package/dist/contracts.js +366 -0
  8. package/dist/define.d.ts +32 -0
  9. package/dist/define.js +15 -0
  10. package/dist/definition/assemble.d.ts +29 -0
  11. package/dist/definition/assemble.js +120 -0
  12. package/dist/definition/bind-agent.d.ts +8 -0
  13. package/dist/definition/bind-agent.js +62 -0
  14. package/dist/definition/bind-tool.d.ts +4 -0
  15. package/dist/definition/bind-tool.js +25 -0
  16. package/dist/definition/binding.d.ts +15 -0
  17. package/dist/definition/binding.js +9 -0
  18. package/dist/definition/bound.d.ts +34 -0
  19. package/dist/definition/bound.js +1 -0
  20. package/dist/definition/builder.d.ts +66 -0
  21. package/dist/definition/builder.js +218 -0
  22. package/dist/definition/declaration.d.ts +10 -0
  23. package/dist/definition/declaration.js +93 -0
  24. package/dist/definition/from.d.ts +13 -0
  25. package/dist/definition/from.js +294 -0
  26. package/dist/definition/helpers.d.ts +23 -0
  27. package/dist/definition/helpers.js +33 -0
  28. package/dist/definition/implementations.d.ts +16 -0
  29. package/dist/definition/implementations.js +3 -0
  30. package/dist/definition/manifest.d.ts +13 -0
  31. package/dist/definition/manifest.js +60 -0
  32. package/dist/definition/output-contract.d.ts +6 -0
  33. package/dist/definition/output-contract.js +12 -0
  34. package/dist/definition/schema-json.d.ts +3 -0
  35. package/dist/definition/schema-json.js +22 -0
  36. package/dist/definition/schema.d.ts +16 -0
  37. package/dist/definition/schema.js +284 -0
  38. package/dist/definition/skill-tools.d.ts +3 -0
  39. package/dist/definition/skill-tools.js +56 -0
  40. package/dist/definition/tool-error.d.ts +9 -0
  41. package/dist/definition/tool-error.js +20 -0
  42. package/dist/errors.d.ts +17 -0
  43. package/dist/errors.js +22 -0
  44. package/dist/index.d.ts +10 -0
  45. package/dist/index.js +1 -0
  46. package/dist/types/agent.d.ts +10 -0
  47. package/dist/types/agent.js +1 -0
  48. package/dist/types/dynamics.d.ts +53 -0
  49. package/dist/types/dynamics.js +1 -0
  50. package/dist/types/manifest.d.ts +57 -0
  51. package/dist/types/manifest.js +1 -0
  52. package/dist/types/middleware.d.ts +92 -0
  53. package/dist/types/middleware.js +1 -0
  54. package/dist/types/model.d.ts +184 -0
  55. package/dist/types/model.js +1 -0
  56. package/dist/types/observe.d.ts +180 -0
  57. package/dist/types/observe.js +1 -0
  58. package/dist/types/shared.d.ts +25 -0
  59. package/dist/types/shared.js +1 -0
  60. package/dist/types/tool.d.ts +194 -0
  61. package/dist/types/tool.js +1 -0
  62. package/dist/types/transcript.d.ts +65 -0
  63. package/dist/types/transcript.js +1 -0
  64. package/dist/utils/canonical.d.ts +1 -0
  65. package/dist/utils/canonical.js +10 -0
  66. package/dist/utils/hash.d.ts +3 -0
  67. package/dist/utils/hash.js +7 -0
  68. package/dist/utils/immutable.d.ts +6 -0
  69. package/dist/utils/immutable.js +76 -0
  70. package/package.json +57 -7
  71. package/index.js +0 -1
  72. package/publish.out +0 -0
@@ -0,0 +1,284 @@
1
+ import { z } from "zod";
2
+ import { HarnessError } from "../errors.js";
3
+ import { copyJsonObject } from "../utils/immutable.js";
4
+ const preparedSchemas = new WeakMap();
5
+ /** Creates a portable, explicitly validated schema source from raw JSON Schema. */
6
+ export function defineSchema(value) {
7
+ if (!value ||
8
+ typeof value !== "object" ||
9
+ typeof value.validate !== "function")
10
+ throw new HarnessError("tool.invalid-schema", "Tool schema must provide validate()");
11
+ return Object.freeze({
12
+ jsonSchema: copyJsonObject(value.jsonSchema, "tool schema jsonSchema"),
13
+ validate: value.validate.bind(value),
14
+ });
15
+ }
16
+ /** Eagerly prepares a definition authored through Harness's tool() helper. */
17
+ export function prepareTool(definition) {
18
+ const normalized = normalizeToolDefinition(definition);
19
+ normalizedSchemasFor(normalized);
20
+ return normalized;
21
+ }
22
+ /** Resolves `input`/`output`/`run` aliases onto the legacy field names. */
23
+ export function normalizeToolDefinition(definition) {
24
+ const alreadyCanonical = definition.inputSchema !== undefined &&
25
+ typeof definition.execute === "function" &&
26
+ definition.input === undefined &&
27
+ definition.output === undefined &&
28
+ definition.run === undefined;
29
+ if (alreadyCanonical)
30
+ return definition;
31
+ const inputSchema = definition.inputSchema ?? definition.input;
32
+ const outputSchema = definition.outputSchema ?? definition.output;
33
+ const execute = definition.execute ?? definition.run;
34
+ if (!inputSchema)
35
+ throw new HarnessError("tool.invalid-schema", `Tool '${definition.name}' must provide input or inputSchema`);
36
+ if (typeof execute !== "function")
37
+ throw new HarnessError("tool.invalid", `Tool '${definition.name}' must provide run() or execute()`);
38
+ return {
39
+ name: definition.name,
40
+ ...(definition.description === undefined
41
+ ? {}
42
+ : { description: definition.description }),
43
+ inputSchema,
44
+ ...(outputSchema === undefined ? {} : { outputSchema }),
45
+ execute,
46
+ ...(definition.approval === undefined
47
+ ? {}
48
+ : { approval: definition.approval }),
49
+ ...(definition.effects === undefined
50
+ ? {}
51
+ : { effects: definition.effects }),
52
+ };
53
+ }
54
+ /** Returns cached normalized contracts, preparing raw definitions on first bind. */
55
+ export function normalizedSchemasFor(definition) {
56
+ const cached = preparedSchemas.get(definition);
57
+ if (cached)
58
+ return cached;
59
+ const prepared = normalizeToolDefinition(definition);
60
+ const cachedPrepared = prepared !== definition ? preparedSchemas.get(prepared) : undefined;
61
+ if (cachedPrepared) {
62
+ preparedSchemas.set(definition, cachedPrepared);
63
+ return cachedPrepared;
64
+ }
65
+ if (!prepared.inputSchema)
66
+ throw new HarnessError("tool.invalid-schema", `Tool '${prepared.name}' is missing inputSchema`);
67
+ const normalized = Object.freeze({
68
+ inputSchema: normalizeSchema(prepared.inputSchema, "input"),
69
+ ...(prepared.outputSchema === undefined
70
+ ? {}
71
+ : { outputSchema: normalizeSchema(prepared.outputSchema, "output") }),
72
+ });
73
+ preparedSchemas.set(prepared, normalized);
74
+ if (definition !== prepared)
75
+ preparedSchemas.set(definition, normalized);
76
+ return normalized;
77
+ }
78
+ /** Converts an accepted tool schema source into Harness's immutable runtime representation. */
79
+ export function normalizeSchema(source, role) {
80
+ const normalized = isZodSchema(source)
81
+ ? normalizeZodSchema(source, role)
82
+ : isStandardSchema(source)
83
+ ? normalizeStandardSchema(source, role)
84
+ : isToolSchema(source)
85
+ ? normalizeExplicitSchema(source)
86
+ : undefined;
87
+ if (!normalized)
88
+ throw new HarnessError("tool.invalid-schema", "Tool schema must be a Zod schema, synchronous Standard Schema with JSON Schema conversion, or defineSchema() contract");
89
+ if (role === "input" && normalized.jsonSchema.type !== "object")
90
+ throw new HarnessError("tool.invalid-schema", "Tool inputSchema JSON Schema root type must be object");
91
+ return normalized;
92
+ }
93
+ function normalizeZodSchema(source, role) {
94
+ // Classic parse/JSON Schema helpers are typed on ZodType; concrete schemas
95
+ // are $ZodType-compatible but may not assign to ZodType under zod 4.6+.
96
+ const classic = source;
97
+ if (hasDeclaredAsyncWork(classic))
98
+ throw new HarnessError("tool.invalid-schema", "Tool schema must validate synchronously");
99
+ let jsonSchema;
100
+ try {
101
+ jsonSchema = copyJsonObject(z.toJSONSchema(classic, { target: "draft-07" }), `tool.${role}Schema.jsonSchema`);
102
+ }
103
+ catch (error) {
104
+ throw new HarnessError("tool.invalid-schema", `Tool ${role}Schema must convert to JSON Schema: ${message(error)}`, { cause: error });
105
+ }
106
+ return Object.freeze({
107
+ jsonSchema,
108
+ validate(value) {
109
+ try {
110
+ const result = classic.safeParse(value);
111
+ if (result.success)
112
+ return { ok: true, value: result.data };
113
+ return {
114
+ ok: false,
115
+ issues: Object.freeze(result.error.issues.map((entry) => issue(entry.path.filter(isPathSegment), entry.code, entry.message))),
116
+ };
117
+ }
118
+ catch (error) {
119
+ return {
120
+ ok: false,
121
+ issues: [issue([], "schema_error", synchronousIssue(error))],
122
+ };
123
+ }
124
+ },
125
+ });
126
+ }
127
+ function normalizeStandardSchema(source, role) {
128
+ let jsonSchema;
129
+ try {
130
+ jsonSchema = copyJsonObject(role === "input"
131
+ ? source["~standard"].jsonSchema.input()
132
+ : source["~standard"].jsonSchema.output(), `tool.${role}Schema.jsonSchema`);
133
+ }
134
+ catch (error) {
135
+ throw new HarnessError("tool.invalid-schema", `Tool ${role}Schema must convert to JSON Schema: ${message(error)}`, { cause: error });
136
+ }
137
+ return Object.freeze({
138
+ jsonSchema,
139
+ validate(value) {
140
+ try {
141
+ const result = source["~standard"].validate(value);
142
+ if (isPromiseLike(result))
143
+ return {
144
+ ok: false,
145
+ issues: [
146
+ issue([], "async_validation", "Schema validation must be synchronous"),
147
+ ],
148
+ };
149
+ if (result &&
150
+ typeof result === "object" &&
151
+ "issues" in result &&
152
+ result.issues)
153
+ return {
154
+ ok: false,
155
+ issues: Object.freeze(result.issues.map(standardIssue)),
156
+ };
157
+ if (result && typeof result === "object" && "value" in result)
158
+ return { ok: true, value: result.value };
159
+ return {
160
+ ok: false,
161
+ issues: [
162
+ issue([], "schema_error", "Standard Schema returned an invalid result"),
163
+ ],
164
+ };
165
+ }
166
+ catch (error) {
167
+ return {
168
+ ok: false,
169
+ issues: [issue([], "schema_error", synchronousIssue(error))],
170
+ };
171
+ }
172
+ },
173
+ });
174
+ }
175
+ function normalizeExplicitSchema(source) {
176
+ return Object.freeze({
177
+ jsonSchema: copyJsonObject(source.jsonSchema, "tool schema jsonSchema"),
178
+ validate(value) {
179
+ try {
180
+ const result = source.validate(value);
181
+ if (isPromiseLike(result))
182
+ return {
183
+ ok: false,
184
+ issues: [
185
+ issue([], "async_validation", "Schema validation must be synchronous"),
186
+ ],
187
+ };
188
+ if (!result ||
189
+ typeof result !== "object" ||
190
+ typeof result.ok !== "boolean")
191
+ return {
192
+ ok: false,
193
+ issues: [
194
+ issue([], "schema_error", "Tool schema returned an invalid result"),
195
+ ],
196
+ };
197
+ if (result.ok)
198
+ return { ok: true, value: result.value };
199
+ return {
200
+ ok: false,
201
+ issues: Object.freeze(result.issues.map(normalizeIssue)),
202
+ };
203
+ }
204
+ catch (error) {
205
+ return {
206
+ ok: false,
207
+ issues: [issue([], "schema_error", synchronousIssue(error))],
208
+ };
209
+ }
210
+ },
211
+ });
212
+ }
213
+ function isZodSchema(value) {
214
+ return value instanceof z.ZodType;
215
+ }
216
+ function isStandardSchema(value) {
217
+ if (!value || typeof value !== "object" || !("~standard" in value))
218
+ return false;
219
+ const standard = value["~standard"];
220
+ if (!standard || typeof standard !== "object")
221
+ return false;
222
+ const record = standard;
223
+ if (typeof record.validate !== "function" ||
224
+ !record.jsonSchema ||
225
+ typeof record.jsonSchema !== "object")
226
+ return false;
227
+ const jsonSchema = record.jsonSchema;
228
+ return (typeof jsonSchema.input === "function" &&
229
+ typeof jsonSchema.output === "function");
230
+ }
231
+ function isToolSchema(value) {
232
+ return (!!value &&
233
+ typeof value === "object" &&
234
+ "jsonSchema" in value &&
235
+ "validate" in value &&
236
+ typeof value.validate === "function");
237
+ }
238
+ /** Zod exposes declared checks in its stable v4 definition graph; reject async checks before a run. */
239
+ function hasDeclaredAsyncWork(schema) {
240
+ return visitDefinition(schema._zod?.def, new Set());
241
+ }
242
+ function visitDefinition(value, seen) {
243
+ if (typeof value === "function")
244
+ return value.constructor.name === "AsyncFunction";
245
+ if (!value || typeof value !== "object")
246
+ return false;
247
+ if (seen.has(value))
248
+ return false;
249
+ seen.add(value);
250
+ const nestedDefinition = value._zod?.def;
251
+ if (nestedDefinition !== undefined && nestedDefinition !== value)
252
+ return visitDefinition(nestedDefinition, seen);
253
+ for (const item of Object.values(value)) {
254
+ if (visitDefinition(item, seen))
255
+ return true;
256
+ }
257
+ return false;
258
+ }
259
+ function standardIssue(value) {
260
+ return issue(value.path?.filter(isPathSegment) ?? [], value.code ?? "invalid", value.message ?? "Invalid value");
261
+ }
262
+ function normalizeIssue(value) {
263
+ return issue(value.path?.filter(isPathSegment) ?? [], value.code ?? "invalid", value.message ?? "Invalid value");
264
+ }
265
+ function issue(path, code, text) {
266
+ return Object.freeze({ path: Object.freeze([...path]), code, message: text });
267
+ }
268
+ function isPathSegment(value) {
269
+ return typeof value === "string" || typeof value === "number";
270
+ }
271
+ function isPromiseLike(value) {
272
+ return (!!value &&
273
+ typeof value === "object" &&
274
+ typeof value.then === "function");
275
+ }
276
+ function synchronousIssue(error) {
277
+ const reason = message(error);
278
+ return reason.includes("Promise during synchronous parse")
279
+ ? "Schema validation must be synchronous"
280
+ : reason;
281
+ }
282
+ function message(error) {
283
+ return error instanceof Error ? error.message : String(error);
284
+ }
@@ -0,0 +1,3 @@
1
+ import type { SkillRecord } from "../types/middleware.js";
2
+ import type { ToolDefinition } from "../types/tool.js";
3
+ export declare function createSkillTools(skills: ReadonlyMap<string, SkillRecord>): readonly ToolDefinition[];
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { tool } from "./helpers.js";
3
+ const USAGE = "Load the full instructions for a named skill. Call this before following a skill.";
4
+ export function createSkillTools(skills) {
5
+ const names = [...skills.keys()].sort();
6
+ const nameSchema = names.length === 1
7
+ ? z.literal(names[0])
8
+ : z.enum(names);
9
+ const definitions = [
10
+ tool({
11
+ name: "load_skill",
12
+ description: USAGE,
13
+ inputSchema: z.object({ name: nameSchema }),
14
+ effects: "read",
15
+ async execute(args) {
16
+ const name = args.name;
17
+ const skill = skills.get(name);
18
+ if (!skill)
19
+ return { unknown: name, available: names };
20
+ const loaded = {
21
+ name: skill.name,
22
+ content: skill.instructions,
23
+ };
24
+ const resources = Object.keys(skill.resources ?? {}).sort();
25
+ if (resources.length === 0)
26
+ return loaded;
27
+ return { ...loaded, resources };
28
+ },
29
+ }),
30
+ ];
31
+ const hasResources = [...skills.values()].some((skill) => skill.resources !== undefined && Object.keys(skill.resources).length > 0);
32
+ if (hasResources) {
33
+ definitions.push(tool({
34
+ name: "read_skill_resource",
35
+ description: "Read one text resource from a skill after load_skill.",
36
+ inputSchema: z.object({
37
+ name: nameSchema,
38
+ path: z.string().min(1),
39
+ }),
40
+ effects: "read",
41
+ async execute(args) {
42
+ const { name, path } = args;
43
+ const skill = skills.get(name);
44
+ const content = skill?.resources?.[path];
45
+ if (!skill || content === undefined)
46
+ return {
47
+ kind: "failed",
48
+ code: "skill.unknown_resource",
49
+ message: `Skill '${name}' has no resource '${path}'.`,
50
+ };
51
+ return { kind: "completed", output: { name, path, content } };
52
+ },
53
+ }));
54
+ }
55
+ return definitions;
56
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Thrown from a tool `run` / `execute` to produce a failed tool result.
3
+ * Prefer this over returning `{ kind: "failed" }` in new code.
4
+ */
5
+ export declare class ToolError extends Error {
6
+ readonly code: string;
7
+ constructor(code: string, message: string);
8
+ }
9
+ export declare function isToolError(error: unknown): error is ToolError;
@@ -0,0 +1,20 @@
1
+ const errorBrand = Symbol.for("@nylorun/core/ToolError");
2
+ /**
3
+ * Thrown from a tool `run` / `execute` to produce a failed tool result.
4
+ * Prefer this over returning `{ kind: "failed" }` in new code.
5
+ */
6
+ export class ToolError extends Error {
7
+ code;
8
+ constructor(code, message) {
9
+ super(message);
10
+ this.name = "ToolError";
11
+ Object.defineProperty(this, errorBrand, { value: true });
12
+ this.code = code;
13
+ }
14
+ }
15
+ export function isToolError(error) {
16
+ return (error instanceof ToolError ||
17
+ (typeof error === "object" &&
18
+ error !== null &&
19
+ error[errorBrand] === true));
20
+ }
@@ -0,0 +1,17 @@
1
+ /** Machine-readable error raised by Harness-owned code. */
2
+ export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "middleware.next-after-return" | "middleware.next-called-twice" | "middleware.request-mutators-revoked" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema" | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
3
+ export type HarnessErrorDetails = Readonly<Record<string, string | number | boolean>>;
4
+ export interface HarnessErrorOptions {
5
+ readonly cause?: unknown;
6
+ readonly details?: HarnessErrorDetails;
7
+ }
8
+ /**
9
+ * The sole error shape produced by Harness itself. Message text is explanatory;
10
+ * callers must branch on `code`.
11
+ */
12
+ export declare class HarnessError extends Error {
13
+ readonly code: HarnessErrorCode;
14
+ readonly details: HarnessErrorDetails;
15
+ constructor(code: HarnessErrorCode, message: string, options?: HarnessErrorOptions);
16
+ }
17
+ export declare function isHarnessError(error: unknown): error is HarnessError;
package/dist/errors.js ADDED
@@ -0,0 +1,22 @@
1
+ const errorBrand = Symbol.for("@nylorun/core/HarnessError");
2
+ /**
3
+ * The sole error shape produced by Harness itself. Message text is explanatory;
4
+ * callers must branch on `code`.
5
+ */
6
+ export class HarnessError extends Error {
7
+ code;
8
+ details;
9
+ constructor(code, message, options = {}) {
10
+ super(message, options.cause === undefined ? undefined : { cause: options.cause });
11
+ this.name = "HarnessError";
12
+ Object.defineProperty(this, errorBrand, { value: true });
13
+ this.code = code;
14
+ this.details = Object.freeze({ ...(options.details ?? {}) });
15
+ }
16
+ }
17
+ export function isHarnessError(error) {
18
+ return (error instanceof HarnessError ||
19
+ (typeof error === "object" &&
20
+ error !== null &&
21
+ error[errorBrand] === true));
22
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./contracts.js";
2
+ export type * from "./types/dynamics.js";
3
+ export type * from "./types/middleware.js";
4
+ export type * from "./types/tool.js";
5
+ export type * from "./types/agent.js";
6
+ export type * from "./types/observe.js";
7
+ export type * from "./types/model.js";
8
+ export type * from "./types/shared.js";
9
+ export type * from "./types/manifest.js";
10
+ export type * from "./types/transcript.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./contracts.js";
@@ -0,0 +1,10 @@
1
+ import type { AgentBinding } from "../definition/binding.js";
2
+ import type { AgentManifest } from "./manifest.js";
3
+ /** An agent definition composed with Agent(...).use(...). Optional `.build()` is a no-op facade. */
4
+ export interface BuiltAgent<Info = unknown, Output = string> {
5
+ readonly id: string;
6
+ readonly name?: string;
7
+ readonly manifest: AgentManifest;
8
+ toJSON(): AgentManifest;
9
+ getBinding(): AgentBinding;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ import type { JsonValue } from "./shared.js";
2
+ import type { PromptItem } from "./model.js";
3
+ import type { MessageInput } from "./transcript.js";
4
+ /** Closed-world patch applied before a model call. No `model` — Runtime owns resolution. */
5
+ export type Patch = {
6
+ /** Switch capabilities declared in the manifest. */
7
+ readonly capabilities?: Readonly<Record<string, boolean>>;
8
+ /** Switch tools by name. */
9
+ readonly tools?: Readonly<Record<string, boolean>>;
10
+ /** Extra instructions for this model call only. */
11
+ readonly instructions?: readonly string[];
12
+ /** Write session state keys (merged into durable session state). */
13
+ readonly state?: Readonly<Record<string, JsonValue>>;
14
+ /** Refuse this model call; message returned to the host. */
15
+ readonly block?: string;
16
+ /**
17
+ * Capability-level shorthand: toggle only this capability.
18
+ * Normalized to `capabilities: { [id]: active }` at bind time.
19
+ */
20
+ readonly active?: boolean;
21
+ };
22
+ /** Decision applied after a model response, before tools/text take effect. */
23
+ export type Decision = {
24
+ readonly text?: string;
25
+ readonly deny?: readonly {
26
+ readonly id: string;
27
+ readonly reason: string;
28
+ }[];
29
+ readonly approve?: readonly {
30
+ readonly id: string;
31
+ readonly prompt: string;
32
+ }[];
33
+ readonly retry?: string;
34
+ readonly block?: string;
35
+ };
36
+ export type BeforeModelCallFn<Info = unknown> = (args: {
37
+ readonly input?: MessageInput | string;
38
+ readonly info?: Info;
39
+ readonly state: Readonly<Record<string, JsonValue>>;
40
+ readonly messages: readonly PromptItem[];
41
+ readonly step: number;
42
+ }) => Patch | Promise<Patch>;
43
+ export type AfterModelCallFn<Info = unknown> = (args: {
44
+ readonly text?: string;
45
+ readonly toolCalls: readonly {
46
+ readonly id: string;
47
+ readonly name: string;
48
+ readonly args: JsonValue;
49
+ }[];
50
+ }, ctx: {
51
+ readonly info?: Info;
52
+ readonly state: Readonly<Record<string, JsonValue>>;
53
+ }) => Decision | Promise<Decision>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { JsonObject } from "./shared.js";
2
+ /** Published manifest schema version (no top-level model — Runtime-owned). */
3
+ export type ManifestSchemaVersion = 3;
4
+ export interface ToolManifest {
5
+ readonly name: string;
6
+ readonly description?: string;
7
+ readonly inputSchema: JsonObject;
8
+ readonly outputSchema?: JsonObject;
9
+ }
10
+ export interface SkillManifest {
11
+ readonly name: string;
12
+ readonly description: string;
13
+ }
14
+ export type McpServerManifest = {
15
+ readonly name: string;
16
+ readonly type: "stdio";
17
+ readonly command: string;
18
+ readonly args?: readonly string[];
19
+ readonly env?: Readonly<Record<string, string>>;
20
+ readonly cwd?: string;
21
+ } | {
22
+ readonly name: string;
23
+ readonly type: "streamable-http";
24
+ readonly url: string;
25
+ readonly headers?: Readonly<Record<string, string>>;
26
+ } | {
27
+ readonly name: string;
28
+ readonly type: "sse";
29
+ readonly url: string;
30
+ readonly headers?: Readonly<Record<string, string>>;
31
+ };
32
+ export interface CapabilityManifest {
33
+ readonly id: string;
34
+ readonly type: "agent" | "agent-plugin";
35
+ readonly name?: string;
36
+ readonly description?: string;
37
+ readonly metadata?: JsonObject;
38
+ readonly instructions?: readonly string[];
39
+ readonly skills?: Readonly<Record<string, SkillManifest>>;
40
+ readonly tools?: readonly ToolManifest[];
41
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
42
+ readonly beforeModelCall?: boolean;
43
+ readonly afterModelCall?: boolean;
44
+ }
45
+ /** Reserved. Empty until later fields are defined. Omit `runtime` while it has no fields. */
46
+ export interface RuntimeManifest {
47
+ }
48
+ export interface AgentManifest {
49
+ readonly manifestSchemaVersion: ManifestSchemaVersion;
50
+ readonly id: string;
51
+ readonly name?: string;
52
+ readonly description?: string;
53
+ readonly metadata?: JsonObject;
54
+ readonly outputSchema?: JsonObject;
55
+ readonly capabilities: readonly CapabilityManifest[];
56
+ readonly runtime?: RuntimeManifest;
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
2
+ import type { InputEvent, TranscriptEntry } from "./transcript.js";
3
+ import type { McpServerManifest, SkillManifest } from "./manifest.js";
4
+ /** Skill files held on the developer binding. Not a manifest field. */
5
+ export interface SkillRecord {
6
+ readonly name: string;
7
+ readonly description: string;
8
+ readonly instructions: string;
9
+ readonly resources?: Readonly<Record<string, string>>;
10
+ }
11
+ import type { ContextItem, JsonObject, Tripwire } from "./shared.js";
12
+ import type { AfterModelCallFn, BeforeModelCallFn } from "./dynamics.js";
13
+ import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
14
+ interface StepRequestBase {
15
+ /** Opaque identity of the execution that owns this Step. */
16
+ readonly executionId: string;
17
+ /** Opaque identity of the Turn that owns this Step. */
18
+ readonly turnId: string;
19
+ /** Opaque identity of this Model Step. */
20
+ readonly stepId: string;
21
+ readonly turnNumber: number;
22
+ readonly stepNumber: number;
23
+ readonly arrivals: readonly InputEvent[];
24
+ readonly toolResults: readonly ToolResult[];
25
+ readonly transcript: readonly TranscriptEntry[];
26
+ readonly context: {
27
+ set(slot: string, items: readonly ContextItem[], options?: ContextMutationOptions): void;
28
+ };
29
+ readonly configuration: {
30
+ readonly instructions: {
31
+ set(slot: string, items: readonly string[], options?: ModelConfigurationMutationOptions): void;
32
+ };
33
+ readonly tools: {
34
+ set(slot: string, tools: readonly ToolDefinition[], options?: ModelConfigurationMutationOptions): void;
35
+ };
36
+ readonly model: {
37
+ select(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
38
+ replace(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
39
+ clear(options?: Omit<ModelConfigurationMutationOptions, "order">): void;
40
+ };
41
+ };
42
+ tripwire(error: Tripwire): StepResponse;
43
+ }
44
+ export type StepRequest<Info = unknown> = StepRequestBase & {
45
+ readonly info?: Info;
46
+ };
47
+ export interface StepResponse {
48
+ candidate(): Readonly<ModelCandidate> | undefined;
49
+ toolCalls(): readonly ModelToolCall[];
50
+ replace(candidate: ModelCandidate): void;
51
+ deny(callId: string, reason: string): void;
52
+ requireInteraction(callId: string, interaction: Interaction): void;
53
+ tripwire(error: Tripwire): StepResponse;
54
+ }
55
+ export type StepMiddleware<Info = unknown> = (request: StepRequest<Info>, next: () => Promise<StepResponse>) => Promise<StepResponse>;
56
+ export type CapabilityItems<Item> = readonly Item[] | Readonly<{
57
+ readonly slot: string;
58
+ readonly items: readonly Item[];
59
+ }>;
60
+ export interface CapabilityDeclaration<Info = unknown> {
61
+ readonly id: string;
62
+ readonly type?: "agent" | "agent-plugin";
63
+ readonly name?: string;
64
+ readonly description?: string;
65
+ readonly metadata?: JsonObject;
66
+ readonly tools?: CapabilityItems<ToolDefinition<any, Info, any>>;
67
+ readonly instructions?: CapabilityItems<string>;
68
+ readonly skills?: Readonly<Record<string, SkillManifest>>;
69
+ /** File contents for load_skill. Omitted from the manifest. */
70
+ readonly skillRecords?: Readonly<Record<string, SkillRecord>>;
71
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
72
+ /** Resolved package directory. Not projected into the manifest. */
73
+ readonly pluginRoot?: string;
74
+ /**
75
+ * @deprecated Model resolution is Runtime-owned. Not projected into the harness manifest.
76
+ * Kept for local middleware composition through 1.0.
77
+ */
78
+ readonly model?: ModelDirective;
79
+ /** @deprecated Prefer beforeModelCall / afterModelCall. Kept through 1.0. */
80
+ readonly middleware?: StepMiddleware<Info>;
81
+ readonly beforeModelCall?: BeforeModelCallFn<Info>;
82
+ readonly afterModelCall?: AfterModelCallFn<Info>;
83
+ }
84
+ export interface MiddlewareContributions {
85
+ readonly instructions?: readonly string[];
86
+ readonly tools?: readonly {
87
+ readonly name: string;
88
+ readonly description?: string;
89
+ }[];
90
+ readonly model?: Pick<ModelDirective, "id" | "controls">;
91
+ }
92
+ export {};
@@ -0,0 +1 @@
1
+ export {};