@peasant-labs/schema 0.1.0-rc6
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/LICENSE +13 -0
- package/README.md +56 -0
- package/dist/fixtures/quality.d.ts +81 -0
- package/dist/fixtures/quality.js +36 -0
- package/dist/fixtures/timeline.d.ts +22 -0
- package/dist/fixtures/timeline.js +2 -0
- package/dist/fixtures.d.ts +2 -0
- package/dist/fixtures.js +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +36 -0
- package/dist/internal/generated/contract/zod.gen.d.ts +2740 -0
- package/dist/internal/generated/contract/zod.gen.js +1196 -0
- package/dist/internal/generated/enums.gen.d.ts +318 -0
- package/dist/internal/generated/enums.gen.js +348 -0
- package/dist/internal/generated/local-api.d.ts +946 -0
- package/dist/internal/generated/local-api.js +1 -0
- package/dist/internal/generated/public-contract.gen.d.ts +2 -0
- package/dist/internal/generated/public-contract.gen.js +2 -0
- package/dist/internal/generated/quality-fixtures.gen.d.ts +2 -0
- package/dist/internal/generated/quality-fixtures.gen.js +367 -0
- package/dist/internal/generated/testcase.gen.d.ts +17 -0
- package/dist/internal/generated/testcase.gen.js +20 -0
- package/dist/internal/generated/timeline-fixtures.gen.d.ts +2 -0
- package/dist/internal/generated/timeline-fixtures.gen.js +542 -0
- package/dist/internal/generated/versions.gen.d.ts +4 -0
- package/dist/internal/generated/versions.gen.js +5 -0
- package/dist/internal/generated/village-api.d.ts +585 -0
- package/dist/internal/generated/village-api.js +1 -0
- package/dist/local-api.d.ts +4 -0
- package/dist/local-api.js +1 -0
- package/dist/testcase.d.ts +32 -0
- package/dist/testcase.js +144 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- package/dist/village-api.d.ts +4 -0
- package/dist/village-api.js +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Peasant Labs
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @peasant-labs/schema
|
|
2
|
+
|
|
3
|
+
Use this package when a TypeScript application needs typed, always-in-sync
|
|
4
|
+
access to the peasant-labs wire contract: the same domain types, closed-set
|
|
5
|
+
enums, and runtime validation Go services already produce and enforce,
|
|
6
|
+
optionally with type-only Local/Village operation contracts for API-aware
|
|
7
|
+
tooling.
|
|
8
|
+
|
|
9
|
+
TypeScript bindings for the canonical `github.com/peasant-labs/schema` wire
|
|
10
|
+
contract. The package is a contract-only leaf: it contains data definitions,
|
|
11
|
+
runtime Zod schemas, Go-shaped closed-set values and guards, version constants,
|
|
12
|
+
and schema-owned fixture helpers. It does not contain HTTP or WebSocket clients.
|
|
13
|
+
Consumers that need endpoint typing can import type-only OpenAPI `paths` and
|
|
14
|
+
`operations` namespaces from `@peasant-labs/schema/local-api` and
|
|
15
|
+
`@peasant-labs/schema/village-api`; these exports do not contain a transport.
|
|
16
|
+
|
|
17
|
+
The Go contract and its generated Types OpenAPI document are authoritative.
|
|
18
|
+
Hey API's Zod plugin derives both the TypeScript definitions and runtime schemas
|
|
19
|
+
from that document. `openapi-typescript` derives the Local and Village operation
|
|
20
|
+
contracts from their OpenAPI documents. A small generated facade exposes the
|
|
21
|
+
same closed-set shape as Go (`Role.User`, `AllRoles`, `isRole`) without
|
|
22
|
+
maintaining a handwritten second contract. The retired `@peasant-labs/types`
|
|
23
|
+
package must not receive new wire definitions.
|
|
24
|
+
|
|
25
|
+
`ProjectHash` is a nominal string identity matching Go's validated newtype.
|
|
26
|
+
Construct values with `newProjectHash`, narrow unknown wire values with
|
|
27
|
+
`isProjectHash`, or assert a trust boundary with `validateProjectHash`.
|
|
28
|
+
|
|
29
|
+
This package is not published yet. Its development version is
|
|
30
|
+
`0.0.0-development`; a published package version will follow the schema module
|
|
31
|
+
release tag, not an individual OpenAPI document version.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import {
|
|
35
|
+
Role,
|
|
36
|
+
isRole,
|
|
37
|
+
newProjectHash,
|
|
38
|
+
zSessionDetailPayload,
|
|
39
|
+
type SessionDetailPayload,
|
|
40
|
+
} from "@peasant-labs/schema";
|
|
41
|
+
import { loadCorpus } from "@peasant-labs/schema/testcase";
|
|
42
|
+
import { loadQualityFixtures, qualitySessions } from "@peasant-labs/schema/fixtures/quality";
|
|
43
|
+
import { loadTimelineFixtures } from "@peasant-labs/schema/fixtures/timeline";
|
|
44
|
+
import type { operations as LocalOperations } from "@peasant-labs/schema/local-api";
|
|
45
|
+
|
|
46
|
+
const detail: SessionDetailPayload = zSessionDetailPayload.parse(input);
|
|
47
|
+
type SessionDetailResponse = LocalOperations["getSession"]["responses"][200]["content"]["application/json"];
|
|
48
|
+
const fixtures = loadQualityFixtures();
|
|
49
|
+
const timeline = loadTimelineFixtures();
|
|
50
|
+
qualitySessions(fixtures);
|
|
51
|
+
timeline.cases.length;
|
|
52
|
+
isRole(Role.User);
|
|
53
|
+
newProjectHash("a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2");
|
|
54
|
+
const response: SessionDetailResponse = detail;
|
|
55
|
+
void response;
|
|
56
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { QualitySession } from "../index.js";
|
|
2
|
+
export declare const QualityFixtureName: Readonly<{
|
|
3
|
+
readonly ResolvedTypical: "resolved_typical";
|
|
4
|
+
readonly ResolvedHighTokens: "resolved_high_tokens";
|
|
5
|
+
readonly PartialMedium: "partial_medium";
|
|
6
|
+
readonly FailedComplex: "failed_complex";
|
|
7
|
+
readonly ResolvedMinimal: "resolved_minimal";
|
|
8
|
+
}>;
|
|
9
|
+
export type QualityFixtureName = (typeof QualityFixtureName)[keyof typeof QualityFixtureName];
|
|
10
|
+
export declare const AllQualityFixtureNames: readonly QualityFixtureName[];
|
|
11
|
+
export declare const QualityFixtureSetName: Readonly<{
|
|
12
|
+
readonly ProjectMix: "project_mix";
|
|
13
|
+
}>;
|
|
14
|
+
export type QualityFixtureSetName = (typeof QualityFixtureSetName)[keyof typeof QualityFixtureSetName];
|
|
15
|
+
export declare const AllQualityFixtureSetNames: readonly QualityFixtureSetName[];
|
|
16
|
+
export interface QualityStringVariation {
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
export interface QualityRatioVariation {
|
|
20
|
+
name: string;
|
|
21
|
+
inputRatio: number;
|
|
22
|
+
}
|
|
23
|
+
export interface QualityMetricVariation {
|
|
24
|
+
name: string;
|
|
25
|
+
value: number;
|
|
26
|
+
}
|
|
27
|
+
export interface QualityMetricVariations {
|
|
28
|
+
retryLoops: QualityMetricVariation[];
|
|
29
|
+
signalDensity: QualityMetricVariation[];
|
|
30
|
+
specQualityScore: QualityMetricVariation[];
|
|
31
|
+
filesTouched: QualityMetricVariation[];
|
|
32
|
+
linesChanged: QualityMetricVariation[];
|
|
33
|
+
}
|
|
34
|
+
export interface QualityVariations {
|
|
35
|
+
outcomes: QualityStringVariation[];
|
|
36
|
+
projects: QualityStringVariation[];
|
|
37
|
+
scopes: QualityStringVariation[];
|
|
38
|
+
taskTitles: QualityStringVariation[];
|
|
39
|
+
tokenRatios: QualityRatioVariation[];
|
|
40
|
+
metrics: QualityMetricVariations;
|
|
41
|
+
}
|
|
42
|
+
export interface QualitySessionFixture {
|
|
43
|
+
name: QualityFixtureName;
|
|
44
|
+
id: string;
|
|
45
|
+
date: string;
|
|
46
|
+
project: string;
|
|
47
|
+
scope: string;
|
|
48
|
+
title: string;
|
|
49
|
+
totalTokens: number;
|
|
50
|
+
inputTokens: number;
|
|
51
|
+
outputTokens: number;
|
|
52
|
+
turnCount: number;
|
|
53
|
+
toolCalls: number;
|
|
54
|
+
outcome: string;
|
|
55
|
+
filesTouched: number;
|
|
56
|
+
linesChanged: number;
|
|
57
|
+
durationMinutes: number;
|
|
58
|
+
retryLoops: number;
|
|
59
|
+
retryTokensWasted: number;
|
|
60
|
+
withinSessionReverts: number;
|
|
61
|
+
signalDensity: number;
|
|
62
|
+
specQualityScore: number;
|
|
63
|
+
explorationRatio: number;
|
|
64
|
+
scopeBreadth: number;
|
|
65
|
+
discoveryTurns: number;
|
|
66
|
+
}
|
|
67
|
+
export interface QualityFixtureSet {
|
|
68
|
+
name: QualityFixtureSetName;
|
|
69
|
+
cases: QualityFixtureName[];
|
|
70
|
+
}
|
|
71
|
+
export interface QualityFixtures {
|
|
72
|
+
sessions: QualitySessionFixture[];
|
|
73
|
+
sets: QualityFixtureSet[];
|
|
74
|
+
variations: QualityVariations;
|
|
75
|
+
}
|
|
76
|
+
export declare function loadQualityFixtures(): QualityFixtures;
|
|
77
|
+
export declare function sessionByName(fixtures: QualityFixtures, name: QualityFixtureName): QualitySessionFixture | undefined;
|
|
78
|
+
export declare function setByName(fixtures: QualityFixtures, name: QualityFixtureSetName): QualityFixtureSet | undefined;
|
|
79
|
+
export declare function toQualitySession(fixture: QualitySessionFixture): QualitySession;
|
|
80
|
+
export declare function qualitySessions(fixtures: QualityFixtures): QualitySession[];
|
|
81
|
+
export declare function qualitySessionsForSet(fixtures: QualityFixtures, name: QualityFixtureSetName): QualitySession[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { canonicalQualityFixtures } from "../internal/generated/quality-fixtures.gen.js";
|
|
2
|
+
export const QualityFixtureName = Object.freeze({
|
|
3
|
+
ResolvedTypical: "resolved_typical",
|
|
4
|
+
ResolvedHighTokens: "resolved_high_tokens",
|
|
5
|
+
PartialMedium: "partial_medium",
|
|
6
|
+
FailedComplex: "failed_complex",
|
|
7
|
+
ResolvedMinimal: "resolved_minimal",
|
|
8
|
+
});
|
|
9
|
+
export const AllQualityFixtureNames = Object.freeze(Object.values(QualityFixtureName));
|
|
10
|
+
export const QualityFixtureSetName = Object.freeze({ ProjectMix: "project_mix" });
|
|
11
|
+
export const AllQualityFixtureSetNames = Object.freeze(Object.values(QualityFixtureSetName));
|
|
12
|
+
export function loadQualityFixtures() { return structuredClone(canonicalQualityFixtures); }
|
|
13
|
+
export function sessionByName(fixtures, name) {
|
|
14
|
+
const fixture = fixtures.sessions.find((candidate) => candidate.name === name);
|
|
15
|
+
return fixture === undefined ? undefined : structuredClone(fixture);
|
|
16
|
+
}
|
|
17
|
+
export function setByName(fixtures, name) {
|
|
18
|
+
const fixture = fixtures.sets.find((candidate) => candidate.name === name);
|
|
19
|
+
return fixture === undefined ? undefined : structuredClone(fixture);
|
|
20
|
+
}
|
|
21
|
+
export function toQualitySession(fixture) {
|
|
22
|
+
const { name: _name, ...session } = fixture;
|
|
23
|
+
return structuredClone(session);
|
|
24
|
+
}
|
|
25
|
+
export function qualitySessions(fixtures) { return fixtures.sessions.map(toQualitySession); }
|
|
26
|
+
export function qualitySessionsForSet(fixtures, name) {
|
|
27
|
+
const fixtureSet = setByName(fixtures, name);
|
|
28
|
+
if (fixtureSet === undefined)
|
|
29
|
+
throw new Error(`unknown quality fixture set ${JSON.stringify(name)}`);
|
|
30
|
+
return fixtureSet.cases.map((caseName) => {
|
|
31
|
+
const fixture = sessionByName(fixtures, caseName);
|
|
32
|
+
if (fixture === undefined)
|
|
33
|
+
throw new Error(`quality fixture set ${JSON.stringify(name)} references unknown case ${JSON.stringify(caseName)}`);
|
|
34
|
+
return toQualitySession(fixture);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CommitRef, SessionID, TimelineSessionRef } from "../index.js";
|
|
2
|
+
import type { Case } from "../testcase.js";
|
|
3
|
+
export type TimelineFixtureSessionInput = Omit<TimelineSessionRef, "harness"> & {
|
|
4
|
+
harness: string;
|
|
5
|
+
};
|
|
6
|
+
export type TimelineFixtureCommitInput = Omit<CommitRef, "sessionIds"> & {
|
|
7
|
+
sessionIds: SessionID[] | null;
|
|
8
|
+
};
|
|
9
|
+
export interface TimelineFixtureInput {
|
|
10
|
+
sessions: TimelineFixtureSessionInput[];
|
|
11
|
+
commits: TimelineFixtureCommitInput[];
|
|
12
|
+
}
|
|
13
|
+
export interface TimelineFixtureExpected {
|
|
14
|
+
errorContains?: string;
|
|
15
|
+
}
|
|
16
|
+
export type TimelineFixtureCase = Case<TimelineFixtureInput, TimelineFixtureExpected> & {
|
|
17
|
+
family: string;
|
|
18
|
+
};
|
|
19
|
+
export interface TimelineFixtureCorpus {
|
|
20
|
+
cases: TimelineFixtureCase[];
|
|
21
|
+
}
|
|
22
|
+
export declare function loadTimelineFixtures(): TimelineFixtureCorpus;
|
package/dist/fixtures.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./internal/generated/public-contract.gen.js";
|
|
2
|
+
export * from "./internal/generated/enums.gen.js";
|
|
3
|
+
export * from "./internal/generated/versions.gen.js";
|
|
4
|
+
import { type ProjectHash } from "./internal/generated/contract/zod.gen.js";
|
|
5
|
+
export declare function isProjectHash(value: unknown): value is ProjectHash;
|
|
6
|
+
export declare function validateProjectHash(value: unknown): asserts value is ProjectHash;
|
|
7
|
+
export declare function newProjectHash(raw: string): ProjectHash;
|
|
8
|
+
export type PushContractVersion = import("./internal/generated/contract/zod.gen.js").ContractVersion;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from "./internal/generated/public-contract.gen.js";
|
|
2
|
+
export * from "./internal/generated/enums.gen.js";
|
|
3
|
+
export * from "./internal/generated/versions.gen.js";
|
|
4
|
+
import { zProjectHash } from "./internal/generated/contract/zod.gen.js";
|
|
5
|
+
function assertProjectHash(value, operation) {
|
|
6
|
+
if (!isProjectHash(value)) {
|
|
7
|
+
const rendered = renderProjectHashInput(value);
|
|
8
|
+
throw new TypeError("ProjectHash validation failed for " + rendered + " at @peasant-labs/schema ProjectHash during " + operation + ": the value is not a 64-character lowercase hexadecimal string; callers cannot use it as a canonical project identity; pass the lowercase SHA-256 hex digest of the project origin URL or local path.");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function renderProjectHashInput(value) {
|
|
12
|
+
try {
|
|
13
|
+
const json = JSON.stringify(value);
|
|
14
|
+
if (json !== undefined)
|
|
15
|
+
return json;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Fall through to String for values whose JSON hooks throw.
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return String(value);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return "<unrenderable value>";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function isProjectHash(value) {
|
|
28
|
+
return zProjectHash.safeParse(value).success;
|
|
29
|
+
}
|
|
30
|
+
export function validateProjectHash(value) {
|
|
31
|
+
assertProjectHash(value, "validateProjectHash");
|
|
32
|
+
}
|
|
33
|
+
export function newProjectHash(raw) {
|
|
34
|
+
assertProjectHash(raw, "newProjectHash");
|
|
35
|
+
return raw;
|
|
36
|
+
}
|