@nylorun/harness 0.8.0-beta.1 → 0.11.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 (51) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +5 -38
  3. package/dist/build/assemble.js +1 -0
  4. package/dist/build/bind-tool.js +4 -3
  5. package/dist/build/builder.js +26 -0
  6. package/dist/build/helpers.d.ts +2 -2
  7. package/dist/build/manifest.js +12 -1
  8. package/dist/build/schema.d.ts +11 -16
  9. package/dist/build/schema.js +141 -22
  10. package/dist/errors.d.ts +1 -1
  11. package/dist/index.d.ts +8 -5
  12. package/dist/index.js +2 -0
  13. package/dist/model/adapters.d.ts +160 -0
  14. package/dist/model/adapters.js +545 -0
  15. package/dist/{model-normalize.d.ts → model/normalize.d.ts} +2 -2
  16. package/dist/{model-normalize.js → model/normalize.js} +35 -4
  17. package/dist/model/prepared.d.ts +16 -0
  18. package/dist/model/prepared.js +11 -0
  19. package/dist/session/event-log.d.ts +4 -3
  20. package/dist/session/input-queue.d.ts +7 -4
  21. package/dist/session/input-queue.js +12 -0
  22. package/dist/session/output-contract.d.ts +6 -0
  23. package/dist/session/output-contract.js +12 -0
  24. package/dist/session/scheduler.js +1 -1
  25. package/dist/session/seed.js +79 -5
  26. package/dist/session/session.d.ts +8 -5
  27. package/dist/session/session.js +38 -2
  28. package/dist/session/state.d.ts +1 -1
  29. package/dist/session/submission-stream.d.ts +5 -4
  30. package/dist/step/context-draft.js +1 -7
  31. package/dist/step/model-configuration.js +6 -20
  32. package/dist/step/project.js +25 -3
  33. package/dist/step/resolve.d.ts +1 -0
  34. package/dist/step/resolve.js +1 -0
  35. package/dist/step/run.d.ts +1 -0
  36. package/dist/step/run.js +25 -4
  37. package/dist/step/seal.d.ts +4 -2
  38. package/dist/step/seal.js +64 -13
  39. package/dist/step/step-context.js +1 -1
  40. package/dist/turn/plan-runner.js +38 -3
  41. package/dist/turn/runner.d.ts +6 -4
  42. package/dist/turn/runner.js +6 -4
  43. package/dist/types/manifest.d.ts +5 -4
  44. package/dist/types/middleware.d.ts +10 -1
  45. package/dist/types/model.d.ts +21 -13
  46. package/dist/types/session.d.ts +34 -13
  47. package/dist/types/shared.d.ts +16 -3
  48. package/dist/types/tool.d.ts +54 -17
  49. package/package.json +15 -12
  50. package/dist/utils/digest.d.ts +0 -1
  51. package/dist/utils/digest.js +0 -14
@@ -1,29 +1,61 @@
1
- import type { ZodObject, output } from "zod";
1
+ import type { ZodType } from "zod";
2
2
  import type { DeferredOutcome, JsonObject, JsonValue } from "./shared.js";
3
- type SchemaValidationSuccess<T> = {
3
+ export interface SchemaIssue {
4
+ readonly path: readonly (string | number)[];
5
+ readonly code: string;
6
+ readonly message: string;
7
+ }
8
+ export type SchemaValidation<T> = {
4
9
  readonly ok: true;
5
10
  readonly value: T;
6
- };
7
- type SchemaValidationFailure = {
11
+ } | {
8
12
  readonly ok: false;
9
- readonly issues: readonly string[];
13
+ readonly issues: readonly SchemaIssue[];
10
14
  };
11
- type SchemaValidation<T> = SchemaValidationSuccess<T> | SchemaValidationFailure;
12
- /** Harness tool parameters are synchronous Zod object schemas. */
13
- export type ToolObjectSchema = ZodObject;
14
- export interface BoundToolSchema<T> {
15
+ /** The portable, locally-enforced schema contract accepted by a Harness tool. */
16
+ export interface ToolSchema<T> {
15
17
  readonly jsonSchema: JsonObject;
16
18
  validate(value: unknown): SchemaValidation<T>;
17
19
  }
18
- export interface ToolDefinition<Parameters extends ToolObjectSchema = ToolObjectSchema, State = never> {
20
+ /** The synchronous Standard Schema subset required to project and validate a tool contract. */
21
+ export interface StandardToolSchema<Input = unknown, Output = unknown> {
22
+ readonly "~standard": {
23
+ readonly validate: (value: Input) => {
24
+ readonly value: Output;
25
+ readonly issues?: undefined;
26
+ } | {
27
+ readonly issues: readonly StandardSchemaIssue[];
28
+ readonly value?: undefined;
29
+ } | Promise<unknown>;
30
+ readonly jsonSchema: {
31
+ readonly input: () => unknown;
32
+ readonly output: () => unknown;
33
+ };
34
+ };
35
+ }
36
+ export interface StandardSchemaIssue {
37
+ readonly message?: string;
38
+ readonly path?: readonly (string | number | symbol)[];
39
+ readonly code?: string;
40
+ }
41
+ export type ToolSchemaSource<T = unknown> = ZodType<T> | StandardToolSchema<any, T> | ToolSchema<T>;
42
+ export type SchemaOutput<Schema> = Schema extends ZodType<infer Value> ? Value : Schema extends StandardToolSchema<any, infer Value> ? Value : Schema extends ToolSchema<infer Value> ? Value : never;
43
+ export type ToolInputSchema = ToolSchemaSource;
44
+ export type ToolOutputSchema = ToolSchemaSource;
45
+ export interface BoundToolSchema<T> extends ToolSchema<T> {
46
+ }
47
+ type OutputFor<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : ToolContent;
48
+ export interface ToolDefinition<InputSchema extends ToolInputSchema = ToolInputSchema, State = never, OutputSchema extends ToolOutputSchema | undefined = undefined> {
19
49
  readonly name: string;
20
50
  readonly description?: string;
21
- readonly parameters: Parameters;
22
- execute(args: output<Parameters>, context: ToolExecutionContext<State>): Promise<ToolOutcome>;
51
+ readonly inputSchema: InputSchema;
52
+ readonly outputSchema?: OutputSchema;
53
+ execute(args: SchemaOutput<InputSchema>, context: ToolExecutionContext<State>): Promise<ToolOutcome<OutputFor<OutputSchema>>>;
23
54
  }
24
- export interface BoundToolDefinition<Parameters extends ToolObjectSchema = ToolObjectSchema, State = never> extends Omit<ToolDefinition<Parameters, State>, "parameters" | "execute"> {
25
- readonly parameters: BoundToolSchema<output<Parameters>>;
26
- readonly execute: ToolDefinition<Parameters, State>["execute"];
55
+ export interface BoundToolDefinition<State = never> extends Omit<ToolDefinition<ToolInputSchema, State, ToolOutputSchema | undefined>, "inputSchema" | "outputSchema" | "execute"> {
56
+ readonly inputSchema: BoundToolSchema<unknown>;
57
+ readonly outputSchema?: BoundToolSchema<unknown>;
58
+ readonly execute: (args: unknown, context: ToolExecutionContext<State>) => Promise<ToolOutcome>;
27
59
  readonly owner: ToolOwner;
28
60
  }
29
61
  export interface ToolOwner {
@@ -64,9 +96,9 @@ export type ToolExecutionContext<State = never> = ToolExecutionContextBase & ([S
64
96
  readonly state: Promise<State>;
65
97
  });
66
98
  export type ToolContent = JsonValue;
67
- export type ToolOutcome = {
99
+ export type ToolOutcome<Output = ToolContent> = {
68
100
  readonly kind: "completed";
69
- readonly output: ToolContent;
101
+ readonly output: Output;
70
102
  } | {
71
103
  readonly kind: "denied";
72
104
  readonly reason: string;
@@ -79,6 +111,10 @@ export type ToolOutcome = {
79
111
  readonly interaction: Interaction;
80
112
  readonly token?: JsonValue;
81
113
  } | DeferredOutcome;
114
+ export interface ToolValidationFailureDetails {
115
+ readonly phase: "input" | "output";
116
+ readonly issues: readonly SchemaIssue[];
117
+ }
82
118
  export type ToolResult = {
83
119
  readonly callId: string;
84
120
  readonly toolName: string;
@@ -95,5 +131,6 @@ export type ToolResult = {
95
131
  readonly kind: "failed";
96
132
  readonly code: string;
97
133
  readonly message: string;
134
+ readonly details?: ToolValidationFailureDetails;
98
135
  };
99
136
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nylorun/harness",
3
- "version": "0.8.0-beta.1",
4
- "description": "A provider-neutral, in-memory agent loop for TypeScript.",
3
+ "version": "0.11.0-beta",
4
+ "description": "Nylorun's TypeScript agent runtime. See github.com/nylorun/harness.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -9,7 +9,7 @@
9
9
  "url": "git+https://github.com/nylorun/harness.git",
10
10
  "directory": "harness"
11
11
  },
12
- "homepage": "https://github.com/nylorun/harness/tree/main/harness#readme",
12
+ "homepage": "https://github.com/nylorun/harness",
13
13
  "bugs": "https://github.com/nylorun/harness/issues",
14
14
  "author": "Nylo",
15
15
  "keywords": [
@@ -27,6 +27,10 @@
27
27
  ".": {
28
28
  "types": "./dist/index.d.ts",
29
29
  "import": "./dist/index.js"
30
+ },
31
+ "./model/adapters": {
32
+ "types": "./dist/model/adapters.d.ts",
33
+ "import": "./dist/model/adapters.js"
30
34
  }
31
35
  },
32
36
  "files": [
@@ -44,26 +48,25 @@
44
48
  "node": "^22.14.0 || ^24.0.0 || >=26.0.0"
45
49
  },
46
50
  "scripts": {
47
- "clean": "node -e \"import('node:fs').then(({rmSync})=>rmSync('dist',{recursive:true,force:true}))\"",
48
- "build": "npm run clean && tsc -p tsconfig.json",
51
+ "build": "npm run clean && node ../scripts/check-typescript-version.mjs && tsc -p tsconfig.json",
52
+ "check": "npm run format:check && npm run build && npm run test:types && npm test && node scripts/check-package.mjs",
53
+ "typecheck": "node ../scripts/check-typescript-version.mjs && tsc -p tsconfig.json --noEmit",
49
54
  "test": "vitest run",
55
+ "test:types": "tsc -p test/types/tsconfig.json",
50
56
  "format": "prettier --write .",
51
57
  "format:check": "prettier --check .",
52
- "test:types": "tsc -p test/types/tsconfig.json",
53
- "check": "npm run format:check && npm run build && npm run test:types && npm test && node scripts/check-package.mjs",
58
+ "clean": "node -e \"import('node:fs').then(({rmSync})=>rmSync('dist',{recursive:true,force:true}))\"",
54
59
  "prepack": "npm run build"
55
60
  },
56
61
  "devDependencies": {
57
62
  "@types/node": "^22.18.0",
63
+ "@typescript/native": "npm:typescript@^7.0.2",
58
64
  "prettier": "^3.9.6",
59
- "typescript": "^5.9.3",
60
- "vitest": "^3.2.4",
65
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
66
+ "vitest": "^4.1.11",
61
67
  "zod": "^4.1.12"
62
68
  },
63
69
  "peerDependencies": {
64
70
  "zod": "^4.1.12"
65
- },
66
- "dependencies": {
67
- "@noble/hashes": "^2.3.0"
68
71
  }
69
72
  }
@@ -1 +0,0 @@
1
- export declare const digest: (value: unknown) => string;
@@ -1,14 +0,0 @@
1
- import { sha256 } from "@noble/hashes/sha2.js";
2
- import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
3
- function canonical(value) {
4
- if (Array.isArray(value))
5
- return `[${value.map(canonical).join(",")}]`;
6
- if (value && typeof value === "object") {
7
- return `{${Object.entries(value)
8
- .sort(([a], [b]) => a.localeCompare(b))
9
- .map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`)
10
- .join(",")}}`;
11
- }
12
- return JSON.stringify(value);
13
- }
14
- export const digest = (value) => bytesToHex(sha256(utf8ToBytes(canonical(value))));