poe-code 3.0.332 → 3.0.334

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "3.0.332",
3
+ "version": "3.0.334",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -64,7 +64,7 @@ function parseRunConfigData(filePath, document) {
64
64
  if (prompt === undefined) {
65
65
  throw new Error(`Missing "prompt" field in "${filePath}".`);
66
66
  }
67
- if (typeof prompt !== "string" || prompt.length === 0) {
67
+ if (typeof prompt !== "string" || prompt.trim().length === 0) {
68
68
  throw new Error(`"prompt" must be a non-empty string in "${filePath}".`);
69
69
  }
70
70
  return { prompt };
@@ -96,7 +96,7 @@ export const experimentDocumentSchema = {
96
96
  minimum: 0
97
97
  }
98
98
  },
99
- required: ["kind", "version", "baseline"],
99
+ required: [],
100
100
  additionalProperties: false
101
101
  };
102
102
  export function parseExperimentFrontmatter(content) {
@@ -132,6 +132,7 @@ export function parseExperimentFrontmatterData(value) {
132
132
  const parsed = isRecord(value) ? value : undefined;
133
133
  validateFrontmatterFields(parsed);
134
134
  validateDocumentKind(parsed ? getOwnEntry(parsed, "kind") : undefined);
135
+ validateDocumentVersion(parsed ? getOwnEntry(parsed, "version") : undefined);
135
136
  const agent = parseAgent(parsed ? getOwnEntry(parsed, "agent") : undefined);
136
137
  const extendsValue = parseBoolean(parsed ? getOwnEntry(parsed, "extends") : undefined);
137
138
  const metric = parseMetric(parsed ? getOwnEntry(parsed, "metric") : undefined);
@@ -166,71 +167,72 @@ function serializeFrontmatter(frontmatter) {
166
167
  };
167
168
  }
168
169
  function parseMetric(value) {
170
+ if (value === undefined) {
171
+ return undefined;
172
+ }
169
173
  if (Array.isArray(value)) {
170
- const metrics = value
171
- .map((item) => parseMetricDefinition(item))
172
- .filter((item) => item !== undefined);
173
- return metrics.length === value.length ? metrics : undefined;
174
+ return value.map((item, index) => parseMetricDefinition(item, `metric[${index}]`));
174
175
  }
175
- return parseMetricDefinition(value);
176
+ return parseMetricDefinition(value, "metric");
176
177
  }
177
- function parseMetricDefinition(value) {
178
- const parsed = isRecord(value) ? value : undefined;
179
- const name = parseString(parsed ? getOwnEntry(parsed, "name") : undefined);
180
- const script = parseString(parsed ? getOwnEntry(parsed, "script") : undefined);
181
- const direction = parseMetricDirection(parsed ? getOwnEntry(parsed, "direction") : undefined);
182
- if (name === undefined || script === undefined || direction === undefined) {
183
- return undefined;
178
+ function parseMetricDefinition(value, label) {
179
+ if (!isRecord(value)) {
180
+ throw new Error(`${label} must be an object.`);
181
+ }
182
+ const name = parseRequiredString(getOwnEntry(value, "name"), `${label}.name`);
183
+ const script = parseRequiredString(getOwnEntry(value, "script"), `${label}.script`);
184
+ const direction = parseRequiredMetricDirection(getOwnEntry(value, "direction"), `${label}.direction`);
185
+ const deltaValue = getOwnEntry(value, "delta");
186
+ if (deltaValue !== undefined &&
187
+ (typeof deltaValue !== "number" || !Number.isFinite(deltaValue) || deltaValue < 0)) {
188
+ throw new Error(`${label}.delta must be a non-negative number.`);
184
189
  }
185
- const deltaValue = parsed ? getOwnEntry(parsed, "delta") : undefined;
186
- const delta = typeof deltaValue === "number" && Number.isFinite(deltaValue) && deltaValue >= 0
187
- ? deltaValue
188
- : undefined;
189
190
  return {
190
191
  name,
191
192
  script,
192
193
  direction,
193
- ...(delta !== undefined ? { delta } : {})
194
+ ...(deltaValue !== undefined ? { delta: deltaValue } : {})
194
195
  };
195
196
  }
196
- function parseMetricDirection(value) {
197
- return value === "minimize" || value === "maximize" || value === "stable" ? value : undefined;
197
+ function parseRequiredMetricDirection(value, label) {
198
+ if (value === "minimize" || value === "maximize" || value === "stable") {
199
+ return value;
200
+ }
201
+ throw new Error(`${label} must be one of "minimize", "maximize", or "stable".`);
198
202
  }
199
203
  function parseBaseline(value) {
200
204
  if (value === null || value === undefined) {
201
205
  return null;
202
206
  }
203
207
  if (!isRecord(value)) {
204
- return null;
208
+ throw new Error("baseline must be null or an object.");
205
209
  }
206
- const baselineEntries = Object.entries(value)
207
- .map(([key, entryValue]) => {
210
+ const baselineEntries = Object.entries(value).map(([key, entryValue]) => {
208
211
  if (typeof entryValue !== "number" || !Number.isFinite(entryValue)) {
209
- return undefined;
212
+ throw new Error(`baseline.${key} must be a finite number.`);
210
213
  }
211
214
  return [key, entryValue];
212
- })
213
- .filter((entry) => entry !== undefined);
214
- return baselineEntries.length === Object.keys(value).length
215
- ? Object.fromEntries(baselineEntries)
216
- : null;
215
+ });
216
+ return Object.fromEntries(baselineEntries);
217
217
  }
218
218
  function parseAgent(value) {
219
+ if (value === undefined) {
220
+ return undefined;
221
+ }
219
222
  if (typeof value === "string") {
220
- return parseString(value);
223
+ return parseRequiredString(value, "agent");
221
224
  }
222
225
  if (!Array.isArray(value)) {
223
- return undefined;
226
+ throw new Error("agent must be a non-empty string or an array of non-empty strings.");
227
+ }
228
+ if (value.length === 0) {
229
+ throw new Error("agent must contain at least one agent.");
224
230
  }
225
231
  const agents = [];
226
- for (const item of value) {
227
- const parsed = parseString(item);
228
- if (parsed === undefined) {
229
- return undefined;
230
- }
231
- agents.push(parsed);
232
+ for (const [index, item] of value.entries()) {
233
+ agents.push(parseRequiredString(item, `agent[${index}]`));
232
234
  }
233
- return agents.length > 0 ? agents : undefined;
235
+ return agents;
234
236
  }
235
237
  function parseString(value) {
236
238
  if (typeof value !== "string") {
@@ -239,6 +241,13 @@ function parseString(value) {
239
241
  const trimmed = value.trim();
240
242
  return trimmed.length > 0 ? trimmed : undefined;
241
243
  }
244
+ function parseRequiredString(value, label) {
245
+ const parsed = parseString(value);
246
+ if (parsed === undefined) {
247
+ throw new Error(`${label} must be a non-empty string.`);
248
+ }
249
+ return parsed;
250
+ }
242
251
  function parseOptionalNonNegativeInteger(value, label) {
243
252
  if (value === undefined) {
244
253
  return undefined;
@@ -262,6 +271,11 @@ function validateDocumentKind(value) {
262
271
  throw new Error("Experiment document kind must be 'experiment'.");
263
272
  }
264
273
  }
274
+ function validateDocumentVersion(value) {
275
+ if (value !== undefined && value !== 1) {
276
+ throw new Error("Experiment document version must be 1.");
277
+ }
278
+ }
265
279
  function validateFrontmatterFields(value) {
266
280
  if (value === undefined) {
267
281
  return;