@peasant-labs/schema 0.1.0-rc10

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 (37) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +66 -0
  3. package/dist/fixtures/quality.d.ts +81 -0
  4. package/dist/fixtures/quality.js +36 -0
  5. package/dist/fixtures/timeline.d.ts +53 -0
  6. package/dist/fixtures/timeline.js +2 -0
  7. package/dist/fixtures.d.ts +2 -0
  8. package/dist/fixtures.js +2 -0
  9. package/dist/index.d.ts +8 -0
  10. package/dist/index.js +36 -0
  11. package/dist/internal/generated/contract/zod.gen.d.ts +3441 -0
  12. package/dist/internal/generated/contract/zod.gen.js +1623 -0
  13. package/dist/internal/generated/enums.gen.d.ts +406 -0
  14. package/dist/internal/generated/enums.gen.js +445 -0
  15. package/dist/internal/generated/local-api.d.ts +1047 -0
  16. package/dist/internal/generated/local-api.js +1 -0
  17. package/dist/internal/generated/public-contract.gen.d.ts +2 -0
  18. package/dist/internal/generated/public-contract.gen.js +2 -0
  19. package/dist/internal/generated/quality-fixtures.gen.d.ts +2 -0
  20. package/dist/internal/generated/quality-fixtures.gen.js +367 -0
  21. package/dist/internal/generated/testcase.gen.d.ts +17 -0
  22. package/dist/internal/generated/testcase.gen.js +20 -0
  23. package/dist/internal/generated/timeline-fixtures.gen.d.ts +2 -0
  24. package/dist/internal/generated/timeline-fixtures.gen.js +1554 -0
  25. package/dist/internal/generated/versions.gen.d.ts +4 -0
  26. package/dist/internal/generated/versions.gen.js +5 -0
  27. package/dist/internal/generated/village-api.d.ts +652 -0
  28. package/dist/internal/generated/village-api.js +1 -0
  29. package/dist/local-api.d.ts +4 -0
  30. package/dist/local-api.js +1 -0
  31. package/dist/testcase.d.ts +32 -0
  32. package/dist/testcase.js +144 -0
  33. package/dist/types.d.ts +2 -0
  34. package/dist/types.js +2 -0
  35. package/dist/village-api.d.ts +4 -0
  36. package/dist/village-api.js +1 -0
  37. package/package.json +75 -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,66 @@
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
+ The generated root Zod schemas enforce the wire's structural shape and selected
26
+ generator-owned local cross-field invariants, including association evidence and
27
+ annotation target rules. The Go `Validate` methods remain authoritative at the
28
+ trust boundary for payload-context and cross-object relationships. TypeScript
29
+ consumer adapters remain responsible for any post-parse semantic handling.
30
+
31
+ `ProjectHash` is a nominal string identity matching Go's validated newtype.
32
+ Construct values with `newProjectHash`, narrow unknown wire values with
33
+ `isProjectHash`, or assert a trust boundary with `validateProjectHash`.
34
+
35
+ This package is published to npm as `@peasant-labs/schema`. The committed
36
+ `package.json` in this directory stays `0.0.0-development` + `private: true` as
37
+ a local safety; the schema module's release pipeline stamps the real version
38
+ from the module release tag (not an individual OpenAPI document version) and
39
+ publishes at release time, so every published version corresponds to a tagged
40
+ schema module release. An `-rcN` tag publishes under the npm dist-tag `next`; a
41
+ final `vX.Y.Z` publishes under `latest`.
42
+
43
+ ```ts
44
+ import {
45
+ Role,
46
+ isRole,
47
+ newProjectHash,
48
+ zSessionDetailPayload,
49
+ type SessionDetailPayload,
50
+ } from "@peasant-labs/schema";
51
+ import { loadCorpus } from "@peasant-labs/schema/testcase";
52
+ import { loadQualityFixtures, qualitySessions } from "@peasant-labs/schema/fixtures/quality";
53
+ import { loadTimelineFixtures } from "@peasant-labs/schema/fixtures/timeline";
54
+ import type { operations as LocalOperations } from "@peasant-labs/schema/local-api";
55
+
56
+ const detail: SessionDetailPayload = zSessionDetailPayload.parse(input);
57
+ type SessionDetailResponse = LocalOperations["getSession"]["responses"][200]["content"]["application/json"];
58
+ const fixtures = loadQualityFixtures();
59
+ const timeline = loadTimelineFixtures();
60
+ qualitySessions(fixtures);
61
+ timeline.cases.length;
62
+ isRole(Role.User);
63
+ newProjectHash("a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2");
64
+ const response: SessionDetailResponse = detail;
65
+ void response;
66
+ ```
@@ -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,53 @@
1
+ import type { CommitRef, RewrittenCommit, SessionAssociation, 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 interface TimelineFixtureEvidenceObservation {
7
+ kind: string;
8
+ recordedCommitHash?: string;
9
+ touchedFilePath?: string;
10
+ branchName?: string;
11
+ windowStartMs?: number;
12
+ windowEndMs?: number;
13
+ }
14
+ export type TimelineFixtureAssociationInput = Omit<SessionAssociation, "conclusion" | "confidence" | "evidence"> & {
15
+ conclusion: string;
16
+ confidence: string;
17
+ evidence: TimelineFixtureEvidenceObservation[] | null;
18
+ };
19
+ export type TimelineFixtureCommitInput = Omit<CommitRef, "sessionIds" | "associations"> & {
20
+ sessionIds: SessionID[] | null;
21
+ associations: TimelineFixtureAssociationInput[] | null;
22
+ };
23
+ export type TimelineFixtureRepairKind = "set_session_binding_true" | "replace_successor_association";
24
+ export interface TimelineFixtureSetSessionBindingRepair {
25
+ kind: "set_session_binding_true";
26
+ sessionId: SessionID;
27
+ postMutationValid: boolean;
28
+ }
29
+ export interface TimelineFixtureReplaceSuccessorAssociationRepair {
30
+ kind: "replace_successor_association";
31
+ ghostHash: string;
32
+ successorHash: string;
33
+ associationId: SessionAssociation["id"];
34
+ postMutationValid: boolean;
35
+ }
36
+ export type TimelineFixtureRepair = TimelineFixtureSetSessionBindingRepair | TimelineFixtureReplaceSuccessorAssociationRepair;
37
+ export interface TimelineFixtureInput {
38
+ sessions: TimelineFixtureSessionInput[];
39
+ commits: TimelineFixtureCommitInput[];
40
+ rewrittenCommits?: RewrittenCommit[];
41
+ }
42
+ export interface TimelineFixtureExpected {
43
+ errorContains?: string;
44
+ repair?: TimelineFixtureRepair;
45
+ }
46
+ export type TimelineFixtureCase = Case<TimelineFixtureInput, TimelineFixtureExpected> & {
47
+ family: string;
48
+ };
49
+ export interface TimelineFixtureCorpus {
50
+ cases: TimelineFixtureCase[];
51
+ successorAssociationMirrorCases: TimelineFixtureCase[];
52
+ }
53
+ export declare function loadTimelineFixtures(): TimelineFixtureCorpus;
@@ -0,0 +1,2 @@
1
+ import { canonicalTimelineFixtures } from "../internal/generated/timeline-fixtures.gen.js";
2
+ export function loadTimelineFixtures() { return structuredClone(canonicalTimelineFixtures); }
@@ -0,0 +1,2 @@
1
+ export * from "./fixtures/quality.js";
2
+ export * from "./fixtures/timeline.js";
@@ -0,0 +1,2 @@
1
+ export * from "./fixtures/quality.js";
2
+ export * from "./fixtures/timeline.js";
@@ -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
+ }