@onyx-robotics/agent 0.1.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.
@@ -0,0 +1,152 @@
1
+ import {
2
+ gitShaSchema,
3
+ researchExperimentStatusSchema,
4
+ researchMetricDirectionSchema,
5
+ } from "./research"
6
+ import { z } from "zod"
7
+
8
+ const nameSchema = z
9
+ .string()
10
+ .trim()
11
+ .min(1)
12
+ .max(120)
13
+ .regex(/^[a-z0-9][a-z0-9-]*$/)
14
+
15
+ const metricsSchema = z.record(z.string().min(1), z.number().finite())
16
+ const metadataSchema = z.record(z.string(), z.unknown())
17
+
18
+ const checksSchema = z.object({
19
+ status: z.enum(["passed", "failed", "timed_out"]),
20
+ durationMs: z.number().int().nonnegative().nullable().optional(),
21
+ outputSummary: z.string().trim().max(4000).nullable().optional(),
22
+ })
23
+
24
+ export const localResearchSyncMetadataSchema = z.object({
25
+ projectId: z.uuid().optional(),
26
+ branchId: z.uuid().optional(),
27
+ experimentId: z.uuid().optional(),
28
+ syncedAt: z.iso.datetime().optional(),
29
+ })
30
+
31
+ export const localResearchBranchStartedRecordSchema = z.object({
32
+ schemaVersion: z.literal(1),
33
+ type: z.literal("branch_started"),
34
+ createdAt: z.iso.datetime(),
35
+ name: nameSchema,
36
+ description: z.string().trim().max(2000).nullable().optional(),
37
+ gitBranchName: z.string().trim().min(1).max(240),
38
+ projectPath: z.string().trim().max(240).optional(),
39
+ baseCommitSha: gitShaSchema.nullable().optional(),
40
+ metricName: z.string().trim().min(1).max(120),
41
+ metricUnit: z.string().trim().max(80).nullable().optional(),
42
+ metricDirection: researchMetricDirectionSchema,
43
+ sync: localResearchSyncMetadataSchema.optional(),
44
+ })
45
+
46
+ export const localResearchExperimentLoggedRecordSchema = z.object({
47
+ schemaVersion: z.literal(1),
48
+ type: z.literal("experiment_logged"),
49
+ createdAt: z.iso.datetime(),
50
+ runRef: z.string().trim().min(1).max(240),
51
+ branchName: nameSchema,
52
+ name: z.string().trim().min(1).max(160),
53
+ description: z.string().trim().max(2000).nullable().optional(),
54
+ gitBranchName: z.string().trim().min(1).max(240),
55
+ projectPath: z.string().trim().max(240).optional(),
56
+ commitSha: gitShaSchema,
57
+ status: researchExperimentStatusSchema,
58
+ primaryMetricName: z.string().trim().min(1).max(120),
59
+ primaryMetricValue: z.number().finite().nullable(),
60
+ metrics: metricsSchema.default({}),
61
+ agentNotes: metadataSchema.default({}),
62
+ checks: checksSchema.nullable().optional(),
63
+ durationMs: z.number().int().nonnegative().nullable().optional(),
64
+ startedAt: z.iso.datetime().nullable().optional(),
65
+ completedAt: z.iso.datetime().nullable().optional(),
66
+ outputSummary: z.string().trim().max(4000).nullable().optional(),
67
+ sync: localResearchSyncMetadataSchema.optional(),
68
+ })
69
+
70
+ export const localResearchRecordSchema = z.union([
71
+ localResearchBranchStartedRecordSchema,
72
+ localResearchExperimentLoggedRecordSchema,
73
+ ])
74
+
75
+ export const localResearchJsonlSchema = z.array(localResearchRecordSchema)
76
+
77
+ /**
78
+ * One experiment in `.git/onyx/history.jsonl` — the permanent, offline-
79
+ * searchable cache of the project's research history. Unlike the outbox,
80
+ * entries are never deleted on flush: `onyx exp log` appends provisional
81
+ * records (`source: "local"`) and `onyx sync` rewrites the file to the
82
+ * canonical API state (`source: "api"`), keeping still-pending local records.
83
+ * The Onyx app remains the source of truth; this is a cache keyed by runRef.
84
+ */
85
+ export const localResearchHistoryRecordSchema = z.object({
86
+ schemaVersion: z.literal(1),
87
+ source: z.enum(["local", "api"]),
88
+ branchName: nameSchema,
89
+ gitBranchName: z.string().trim().min(1).max(240).optional(),
90
+ runRef: z.string().trim().min(1).max(240),
91
+ commitSha: gitShaSchema,
92
+ status: researchExperimentStatusSchema,
93
+ name: z.string().trim().min(1).max(160),
94
+ description: z.string().trim().max(2000).nullable().optional(),
95
+ primaryMetricName: z.string().trim().min(1).max(120),
96
+ primaryMetricValue: z.number().finite().nullable(),
97
+ metrics: metricsSchema.default({}),
98
+ agentNotes: metadataSchema.default({}),
99
+ checks: checksSchema.nullable().optional(),
100
+ durationMs: z.number().int().nonnegative().nullable().optional(),
101
+ outputSummary: z.string().trim().max(4000).nullable().optional(),
102
+ startedAt: z.iso.datetime().nullable().optional(),
103
+ completedAt: z.iso.datetime().nullable().optional(),
104
+ createdAt: z.iso.datetime(),
105
+ // Server-assigned fields, present when source === "api".
106
+ experimentId: z.uuid().optional(),
107
+ branchId: z.uuid().optional(),
108
+ sequenceNumber: z.number().int().positive().optional(),
109
+ })
110
+
111
+ export const localResearchEventTypeSchema = z.enum([
112
+ "branch_created",
113
+ "exp_run_started",
114
+ "eval_finished",
115
+ "checks_finished",
116
+ "run_finished",
117
+ "exp_logged",
118
+ "flush_finished",
119
+ "pushed",
120
+ ])
121
+
122
+ /**
123
+ * One line in `.git/onyx/events.jsonl` — a best-effort local activity feed
124
+ * emitted by CLI commands so `onyx listen` can show what a running agent
125
+ * session is doing. Never authoritative; periodically truncated.
126
+ */
127
+ export const localResearchEventSchema = z.object({
128
+ schemaVersion: z.literal(1),
129
+ ts: z.iso.datetime(),
130
+ type: localResearchEventTypeSchema,
131
+ branchName: z.string().trim().max(240).optional(),
132
+ commitSha: gitShaSchema.optional(),
133
+ message: z.string().max(1000).optional(),
134
+ })
135
+
136
+ export type LocalResearchSyncMetadata = z.infer<
137
+ typeof localResearchSyncMetadataSchema
138
+ >
139
+ export type LocalResearchBranchStartedRecord = z.infer<
140
+ typeof localResearchBranchStartedRecordSchema
141
+ >
142
+ export type LocalResearchExperimentLoggedRecord = z.infer<
143
+ typeof localResearchExperimentLoggedRecordSchema
144
+ >
145
+ export type LocalResearchRecord = z.infer<typeof localResearchRecordSchema>
146
+ export type LocalResearchHistoryRecord = z.infer<
147
+ typeof localResearchHistoryRecordSchema
148
+ >
149
+ export type LocalResearchEventType = z.infer<
150
+ typeof localResearchEventTypeSchema
151
+ >
152
+ export type LocalResearchEvent = z.infer<typeof localResearchEventSchema>
@@ -0,0 +1,75 @@
1
+ import { z } from "zod"
2
+
3
+ const metadataSchema = z.record(z.string(), z.unknown())
4
+
5
+ export const gitShaSchema = z
6
+ .string()
7
+ .trim()
8
+ .regex(/^[0-9a-fA-F]{7,64}$/, "must be a hex git SHA (7-64 hex chars)")
9
+
10
+ export const researchMetricDirectionSchema = z.enum(["maximize", "minimize"])
11
+
12
+ export const researchExperimentStatusSchema = z.enum([
13
+ "queued",
14
+ "running",
15
+ "succeeded",
16
+ "failed",
17
+ "checks_failed",
18
+ "accepted",
19
+ "rejected",
20
+ ])
21
+
22
+ export const createResearchBranchRequestSchema = z.object({
23
+ parentBranchId: z.uuid().optional(),
24
+ name: z
25
+ .string()
26
+ .trim()
27
+ .min(1)
28
+ .max(120)
29
+ .regex(/^[a-z0-9][a-z0-9-]*$/),
30
+ description: z.string().trim().max(2000).optional(),
31
+ gitBranchName: z.string().trim().min(1).max(240).optional(),
32
+ baseCommitSha: gitShaSchema.optional(),
33
+ currentHeadCommitSha: gitShaSchema.optional(),
34
+ metricName: z.string().trim().min(1).max(120),
35
+ metricUnit: z.string().trim().max(80).optional(),
36
+ metricDirection: researchMetricDirectionSchema.default("maximize"),
37
+ })
38
+
39
+ export const createResearchExperimentRequestSchema = z.object({
40
+ name: z.string().trim().min(1).max(160),
41
+ description: z.string().trim().max(2000).optional(),
42
+ runRef: z.string().trim().min(1).max(240).optional(),
43
+ commitSha: gitShaSchema,
44
+ status: researchExperimentStatusSchema.default("succeeded"),
45
+ primaryMetricName: z.string().trim().min(1).max(120).optional(),
46
+ primaryMetricValue: z.number().finite().optional(),
47
+ secondaryMetrics: metadataSchema.default({}),
48
+ artifactRefs: metadataSchema.default({}),
49
+ agentNotes: metadataSchema.default({}),
50
+ checks: z
51
+ .object({
52
+ status: z.enum(["passed", "failed", "timed_out"]),
53
+ durationMs: z.number().int().nonnegative().nullable().optional(),
54
+ outputSummary: z.string().trim().max(4000).nullable().optional(),
55
+ })
56
+ .nullable()
57
+ .optional(),
58
+ durationMs: z.number().int().nonnegative().optional(),
59
+ outputSummary: z.string().trim().max(4000).optional(),
60
+ startedAt: z.iso.datetime().optional(),
61
+ completedAt: z.iso.datetime().optional(),
62
+ })
63
+
64
+ export type ResearchMetricDirection = z.infer<
65
+ typeof researchMetricDirectionSchema
66
+ >
67
+ export type ResearchExperimentStatus = z.infer<
68
+ typeof researchExperimentStatusSchema
69
+ >
70
+ export type CreateResearchBranchRequest = z.infer<
71
+ typeof createResearchBranchRequestSchema
72
+ >
73
+ export type CreateResearchExperimentRequest = z.infer<
74
+ typeof createResearchExperimentRequestSchema
75
+ >