@eigenpal/cli 0.20.70 → 0.20.72

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/dist/cli.js CHANGED
@@ -57033,6 +57033,17 @@ var init_grammar = __esm(() => {
57033
57033
  });
57034
57034
 
57035
57035
  // ../types/src/git-source/manifests.ts
57036
+ function utf8Length(value) {
57037
+ let bytes = 0;
57038
+ for (const character of value) {
57039
+ const code = character.codePointAt(0);
57040
+ bytes += code <= 127 ? 1 : code <= 2047 ? 2 : code <= 65535 ? 3 : 4;
57041
+ }
57042
+ return bytes;
57043
+ }
57044
+ function safePath(value) {
57045
+ return value.length <= 512 && /^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/.test(value) && !value.split("/").some((part) => [".", "..", ".git", ".eigenpal", "node_modules", "eigenpal_modules"].includes(part));
57046
+ }
57036
57047
  function workspaceDependencyNameToPackagePath(name) {
57037
57048
  const parsedName = WorkspaceDependencyNameSchema.parse(name);
57038
57049
  return dottedPackageNameToPath(DottedPackageNameSchema.parse(parsedName.slice("workspace:".length)));
@@ -57040,9 +57051,6 @@ function workspaceDependencyNameToPackagePath(name) {
57040
57051
  function hasFile(files, file) {
57041
57052
  return files.includes(file);
57042
57053
  }
57043
- function hasMatchingFile(files, predicate) {
57044
- return files.some((file) => !file.startsWith("../") && !file.startsWith("/") && predicate(file));
57045
- }
57046
57054
  function validateSourcePackageRequiredFiles({
57047
57055
  packagePath,
57048
57056
  files
@@ -57050,7 +57058,7 @@ function validateSourcePackageRequiredFiles({
57050
57058
  const parsedPath = SourcePackagePathSchema.parse(packagePath);
57051
57059
  const [root, resourceKind] = parsedPath.split("/");
57052
57060
  const issues = [];
57053
- if (root === "agents" && !hasFile(files, "AGENT.md")) {
57061
+ if (root === "agents" && !hasFile(files, "agent.ts") && !hasFile(files, "AGENT.md")) {
57054
57062
  issues.push({
57055
57063
  code: "missing-required-file",
57056
57064
  path: "AGENT.md",
@@ -57064,44 +57072,23 @@ function validateSourcePackageRequiredFiles({
57064
57072
  message: "Shared evaluator packages must include evaluator.yaml"
57065
57073
  });
57066
57074
  }
57067
- if (root !== "resources") {
57068
- return issues;
57069
- }
57070
- if (resourceKind === "skills") {
57071
- if (!hasFile(files, "SKILL.md")) {
57075
+ if (root === "resources") {
57076
+ if (!["skills", "rules", "knowledge", "templates"].includes(resourceKind))
57072
57077
  issues.push({
57073
57078
  code: "missing-required-file",
57074
- path: "SKILL.md",
57075
- message: "Shared skill packages must include SKILL.md"
57079
+ path: "resource.ts",
57080
+ message: "Unknown shared resource kind"
57076
57081
  });
57077
- }
57078
- return issues;
57079
- }
57080
- if (resourceKind === "templates") {
57081
- if (!hasMatchingFile(files, (file) => SOURCE_TEMPLATE_FILE_PATTERN.test(file))) {
57082
- issues.push({
57083
- code: "missing-content-file",
57084
- message: "Template packages must include at least one .docx or .xlsx file"
57085
- });
57086
- }
57087
- return issues;
57088
- }
57089
- if (resourceKind === "rules" || resourceKind === "knowledge") {
57090
- if (!hasMatchingFile(files, (file) => file.toLowerCase().endsWith(".md"))) {
57082
+ if (!hasFile(files, "resource.ts"))
57091
57083
  issues.push({
57092
- code: "missing-content-file",
57093
- message: `${resourceKind === "rules" ? "Rule" : "Knowledge"} packages must include at least one markdown file`
57084
+ code: "missing-required-file",
57085
+ path: "resource.ts",
57086
+ message: "Shared resources must export their TypeScript definition from resource.ts"
57094
57087
  });
57095
- }
57096
- return issues;
57097
57088
  }
57098
- issues.push({
57099
- code: "unsupported-resource-kind",
57100
- message: `Unsupported resource package kind: ${resourceKind ?? "(missing)"}`
57101
- });
57102
57089
  return issues;
57103
57090
  }
57104
- var SOURCE_MANIFEST_FILENAME = "eigenpal.yaml", UNSUPPORTED_SOURCE_MANIFEST_FILENAME = "eigenpal.yml", SourceManifestSchemaVersionSchema, SourceManifestFilenameSchema, LocalAgentResourceDirectorySchema, WorkspaceDependencyNameSchema, WorkspaceDependencyVersionSchema, ScoreInUnitIntervalSchema, LocalEvaluatorReferenceSchema, SharedEvaluatorReferenceSchema, EvaluatorCompositionItemBaseSchema, LocalEvaluatorCompositionItemSchema, SharedEvaluatorCompositionItemSchema, EvaluatorCompositionItemSchema, EvaluatorCompositionSchema, DependencyMapSchema, TriggerConfigSchema, CommonPackageManifestFields, RootSourceManifestSchema, AgentPackageManifestSchema, WorkflowPackageManifestSchema, SharedResourcePackageManifestSchema, EvaluatorPackageManifestSchema, EvaluatorDefinitionSchema, SourcePackageManifestSchema, SOURCE_TEMPLATE_FILE_PATTERN;
57091
+ var SOURCE_MANIFEST_FILENAME = "eigenpal.yaml", UNSUPPORTED_SOURCE_MANIFEST_FILENAME = "eigenpal.yml", SourceManifestSchemaVersionSchema, SourceManifestFilenameSchema, LocalAgentResourceDirectorySchema, WorkspaceDependencyNameSchema, WorkspaceDependencyVersionSchema, ScoreInUnitIntervalSchema, LocalEvaluatorReferenceSchema, SharedEvaluatorReferenceSchema, EvaluatorCompositionItemBaseSchema, LocalEvaluatorCompositionItemSchema, SharedEvaluatorCompositionItemSchema, EvaluatorCompositionItemSchema, EvaluatorCompositionSchema, DependencyMapSchema, TriggerConfigSchema, CommonPackageManifestFields, RootSourceManifestSchema, agentFilesystemOptionsSchema, AgentPackageManifestSchema, WorkflowPackageManifestSchema, SharedResourcePackageManifestSchema, EvaluatorPackageManifestSchema, EvaluatorDefinitionSchema, SourcePackageManifestSchema;
57105
57092
  var init_manifests = __esm(() => {
57106
57093
  init_zod();
57107
57094
  init_evaluator_config();
@@ -57218,13 +57205,53 @@ var init_manifests = __esm(() => {
57218
57205
  schemaVersion: SourceManifestSchemaVersionSchema,
57219
57206
  eigenpalVersion: string2().min(1)
57220
57207
  }).strict();
57208
+ agentFilesystemOptionsSchema = strictObject({
57209
+ cwd: string2().max(512).refine((value) => value === "." || safePath(value), "Use a repository-relative directory without traversal").nullable().optional(),
57210
+ files: record(string2().refine(safePath, "Use a safe relative file path"), string2()).optional(),
57211
+ packages: strictObject({
57212
+ python: record(string2().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]*$/), string2().regex(/^[0-9]+(?:\.[0-9]+){1,3}$/)).optional(),
57213
+ npm: record(string2().regex(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/), string2().regex(/^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/)).optional()
57214
+ }).optional()
57215
+ }).superRefine((value, context) => {
57216
+ const files = Object.entries(value.files ?? {});
57217
+ if (files.length > 100 || files.reduce((total, [path, text]) => total + utf8Length(path + text), 0) > 256 * 1024)
57218
+ context.addIssue({
57219
+ code: "custom",
57220
+ message: "Workspace files allow at most 100 files and 256 KiB total"
57221
+ });
57222
+ if (Object.keys(value.packages?.python ?? {}).length + Object.keys(value.packages?.npm ?? {}).length > 32)
57223
+ context.addIssue({
57224
+ code: "custom",
57225
+ message: "Workspace allows at most 32 additional packages"
57226
+ });
57227
+ });
57221
57228
  AgentPackageManifestSchema = object({
57222
57229
  ...CommonPackageManifestFields,
57223
57230
  model: string2().optional(),
57231
+ instructions: string2().min(1).max(128 * 1024).optional(),
57232
+ filesystem: boolean2().optional(),
57233
+ workspace: agentFilesystemOptionsSchema.optional(),
57234
+ guards: array(discriminatedUnion("kind", [
57235
+ strictObject({ kind: literal("turns"), value: number2().int().positive().safe() }),
57236
+ strictObject({ kind: literal("timeMs"), value: number2().int().positive().safe() }),
57237
+ strictObject({ kind: literal("credits"), value: number2().positive().finite() })
57238
+ ])).max(32).optional(),
57224
57239
  triggers: TriggerConfigSchema.optional(),
57225
57240
  dependencies: DependencyMapSchema.optional(),
57226
57241
  evaluators: EvaluatorCompositionSchema.optional()
57227
57242
  }).strict().superRefine((manifest, ctx) => {
57243
+ if (manifest.workspace?.cwd === null && Object.keys(manifest.dependencies ?? {}).length)
57244
+ ctx.addIssue({
57245
+ code: "custom",
57246
+ path: ["dependencies"],
57247
+ message: "Shared file dependencies require a repository working directory; use files with cwd: null"
57248
+ });
57249
+ if (manifest.workspace !== undefined && manifest.filesystem !== true)
57250
+ ctx.addIssue({
57251
+ code: "custom",
57252
+ path: ["workspace"],
57253
+ message: "Workspace requires filesystem capability"
57254
+ });
57228
57255
  for (const dependencyName of Object.keys(manifest.dependencies ?? {})) {
57229
57256
  const nameResult = WorkspaceDependencyNameSchema.safeParse(dependencyName);
57230
57257
  if (!nameResult.success) {
@@ -57272,21 +57299,146 @@ var init_manifests = __esm(() => {
57272
57299
  SharedResourcePackageManifestSchema,
57273
57300
  EvaluatorPackageManifestSchema
57274
57301
  ]);
57275
- SOURCE_TEMPLATE_FILE_PATTERN = /\.(?:docx|xlsx)$/i;
57302
+ });
57303
+
57304
+ // ../types/src/git-source/resources.ts
57305
+ var filePath, AgentResourceSchema, name, AgentResourcesSchema;
57306
+ var init_resources = __esm(() => {
57307
+ init_zod();
57308
+ filePath = string2().max(256).refine((value) => !value.startsWith("/") && !value.includes("\\") && !Array.from(value).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) && value.split("/").every((part) => !!part && ![".", "..", ".git", ".eigenpal", "eigenpal_modules", "node_modules"].includes(part)));
57309
+ AgentResourceSchema = strictObject({
57310
+ kind: _enum(["knowledge", "rule", "template", "skill"]),
57311
+ name: string2().min(1).max(200),
57312
+ description: string2().max(2000).optional(),
57313
+ content: string2().min(1).max(128 * 1024).refine((value) => !!value.trim()),
57314
+ entry: filePath.optional(),
57315
+ files: record(filePath, union([
57316
+ string2().max(256 * 1024),
57317
+ strictObject({
57318
+ encoding: literal("utf8"),
57319
+ content: string2().max(256 * 1024),
57320
+ executable: boolean2().optional()
57321
+ }),
57322
+ strictObject({
57323
+ executable: boolean2().optional(),
57324
+ encoding: literal("base64"),
57325
+ content: string2().max(512 * 1024).regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)
57326
+ })
57327
+ ])).refine((files) => Object.keys(files).length <= 64).optional()
57328
+ }).superRefine((resource, ctx) => {
57329
+ if (resource.kind === "skill" && Object.hasOwn(resource.files ?? {}, "SKILL.md"))
57330
+ ctx.addIssue({
57331
+ code: "custom",
57332
+ path: ["files"],
57333
+ message: "Resource files cannot override their content entry"
57334
+ });
57335
+ });
57336
+ name = string2().regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/).refine((value) => !["__proto__", "prototype", "constructor"].includes(value));
57337
+ AgentResourcesSchema = record(name, AgentResourceSchema).refine((resources) => Object.keys(resources).length <= 32).refine((resources) => JSON.stringify(resources).length <= 1024 * 1024);
57276
57338
  });
57277
57339
 
57278
57340
  // ../types/src/git-source/agent-definition.ts
57279
- var CompiledAgentDataSchema, CompiledAgentSnapshotSchema;
57341
+ var compiledExactOptions, evaluatorName, CompiledAgentEvaluationSchema, CompiledAgentDataSchema, CompiledAgentSnapshotSchema;
57280
57342
  var init_agent_definition = __esm(() => {
57281
57343
  init_zod();
57344
+ init_evaluator_config();
57282
57345
  init_manifests();
57346
+ init_resources();
57347
+ compiledExactOptions = strictObject({
57348
+ rules: record(string2(), strictObject({
57349
+ ignore: literal(true).optional(),
57350
+ order: _enum(["ordered", "unordered"]).optional(),
57351
+ items: _enum(["at-least", "at-most", "exactly"]).optional(),
57352
+ matchBy: union([string2(), array(string2())]).optional(),
57353
+ allowExtraFields: boolean2().optional(),
57354
+ numericTolerance: number2().finite().nonnegative().optional()
57355
+ })).optional(),
57356
+ paths: array(string2()).optional(),
57357
+ unorderedPaths: array(string2()).optional(),
57358
+ numericTolerance: number2().finite().nonnegative().optional(),
57359
+ allowExtraFields: boolean2().optional()
57360
+ }).superRefine((value, ctx) => {
57361
+ const result = ExactDiffConfigSchema.safeParse(value);
57362
+ if (!result.success)
57363
+ for (const issue of result.error.issues)
57364
+ ctx.addIssue({ code: "custom", path: issue.path, message: issue.message });
57365
+ });
57366
+ evaluatorName = string2().regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/).refine((name) => !["constructor", "prototype", "__proto__"].includes(name));
57367
+ CompiledAgentEvaluationSchema = strictObject({
57368
+ evaluators: record(evaluatorName, discriminatedUnion("kind", [
57369
+ strictObject({ kind: literal("custom") }),
57370
+ strictObject({
57371
+ kind: literal("exact-diff"),
57372
+ options: compiledExactOptions.optional()
57373
+ }),
57374
+ strictObject({
57375
+ kind: literal("llm-judge"),
57376
+ prompt: string2().min(10).max(128 * 1024),
57377
+ model: string2().min(1).optional()
57378
+ })
57379
+ ])).refine((values) => Object.keys(values).length > 0 && Object.keys(values).length <= 32, "Define between 1 and 32 evaluators"),
57380
+ pass: discriminatedUnion("kind", [
57381
+ strictObject({ kind: literal("callback") }),
57382
+ strictObject({
57383
+ kind: literal("weighted"),
57384
+ weights: record(evaluatorName, number2().finite().nonnegative()),
57385
+ threshold: number2().finite().min(0).max(1)
57386
+ })
57387
+ ])
57388
+ }).superRefine((evaluation, ctx) => {
57389
+ if (evaluation.pass.kind === "weighted") {
57390
+ const entries = Object.entries(evaluation.pass.weights);
57391
+ if (!entries.length || !Number.isFinite(entries.reduce((total, [, weight]) => total + weight, 0)) || entries.reduce((total, [, weight]) => total + weight, 0) <= 0)
57392
+ ctx.addIssue({
57393
+ code: "custom",
57394
+ path: ["pass", "weights"],
57395
+ message: "Weights must have a finite positive total"
57396
+ });
57397
+ if (entries.some(([name]) => !Object.hasOwn(evaluation.evaluators, name)))
57398
+ ctx.addIssue({
57399
+ code: "custom",
57400
+ path: ["pass", "weights"],
57401
+ message: "Weight references an undefined evaluator"
57402
+ });
57403
+ }
57404
+ });
57283
57405
  CompiledAgentDataSchema = strictObject({
57284
57406
  schemaVersion: literal(1),
57285
57407
  kind: literal("agent"),
57286
57408
  manifest: unknown().refine((value) => AgentPackageManifestSchema.safeParse(value).success, "Invalid agent manifest"),
57409
+ instructions: string2().min(1).max(128 * 1024).refine((v) => v.trim().length > 0).optional(),
57410
+ resources: AgentResourcesSchema.optional(),
57411
+ evaluation: CompiledAgentEvaluationSchema.optional(),
57412
+ tools: record(string2().regex(/^[a-zA-Z][a-zA-Z0-9_]{0,63}$/).refine((name) => ![
57413
+ "__proto__",
57414
+ "constructor",
57415
+ "prototype",
57416
+ "finish",
57417
+ "read",
57418
+ "write",
57419
+ "edit",
57420
+ "bash",
57421
+ "grep",
57422
+ "find",
57423
+ "ls",
57424
+ "request_human_review",
57425
+ "report_step_progress",
57426
+ "web_search",
57427
+ "fetch_url",
57428
+ "write_workflow_output_json",
57429
+ "write_workflow_output_file"
57430
+ ].includes(name)), strictObject({
57431
+ description: string2().min(1),
57432
+ inputSchema: record(string2(), unknown()),
57433
+ outputSchema: record(string2(), unknown())
57434
+ })).refine((v) => Object.keys(v).length <= 21).optional(),
57435
+ executable: strictObject({
57436
+ code: string2().max(2 * 1024 * 1024),
57437
+ sha256: string2().regex(/^[a-f0-9]{64}$/)
57438
+ }).optional(),
57287
57439
  inputSchema: record(string2(), unknown()).optional(),
57288
57440
  outputSchema: record(string2(), unknown()).optional()
57289
- });
57441
+ }).refine((definition) => !Object.values(definition.resources ?? {}).some((resource) => resource.kind === "skill") || definition.manifest.filesystem === true, "Skills require .withFilesystem()");
57290
57442
  CompiledAgentSnapshotSchema = strictObject({
57291
57443
  definition: CompiledAgentDataSchema,
57292
57444
  sourceSha256: string2().regex(/^[a-f0-9]{64}$/),
@@ -57378,6 +57530,79 @@ var init_secrets = __esm(() => {
57378
57530
  }).strict();
57379
57531
  });
57380
57532
 
57533
+ // ../types/src/git-source/definition-imports.ts
57534
+ import { posix } from "node:path";
57535
+ function definitionImports(source) {
57536
+ const ast = import_parser7.parse(source, { sourceType: "module", plugins: ["typescript"] });
57537
+ return ast.program.body.flatMap((node) => node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration" ? node.source ? [node.source.value] : [] : []);
57538
+ }
57539
+ function definitionImportCandidates(importer, specifier) {
57540
+ if (!specifier.startsWith("./") && !specifier.startsWith("../"))
57541
+ return [];
57542
+ const name = posix.normalize(posix.join(posix.dirname(importer), specifier));
57543
+ if (name.startsWith("../") || name.startsWith("/") || name.includes("\\"))
57544
+ throw new Error("Import escapes the source project");
57545
+ return [
57546
+ name,
57547
+ `${name}.ts`,
57548
+ `${name}.js`,
57549
+ ...name.endsWith(".js") ? [name.slice(0, -3) + ".ts"] : []
57550
+ ];
57551
+ }
57552
+ function resourceDefinitionSource(source) {
57553
+ const entry = posix.join(posix.dirname(source.entry), "agent.ts");
57554
+ if (Object.hasOwn(source.files, entry))
57555
+ throw new Error("Resource packages cannot contain agent.ts");
57556
+ return {
57557
+ entry,
57558
+ files: {
57559
+ ...source.files,
57560
+ [entry]: `import resource from './resource.ts';import {createAgent} from '@eigenpal/automations';
57561
+ const agent=createAgent({name:resource.name,...(resource.description?{description:resource.description}:{}),resources:resource.kind==='skill'?{}:{resource}});
57562
+ export default agent.withFilesystem(resource.kind==='skill'?{skills:{resource}}:{});`
57563
+ }
57564
+ };
57565
+ }
57566
+ function definitionAssetImports(source) {
57567
+ const ast = import_parser7.parse(source, { sourceType: "module", plugins: ["typescript"] });
57568
+ const imports = new Map;
57569
+ for (const node of ast.program.body)
57570
+ if (node.type === "ImportDeclaration") {
57571
+ const mode = node.attributes?.find((attribute) => (attribute.key.type === "Identifier" ? attribute.key.name : attribute.key.value) === "type")?.value.value;
57572
+ if (mode === "text" || mode === "bytes")
57573
+ imports.set(node.source.value, mode);
57574
+ }
57575
+ return imports;
57576
+ }
57577
+ function sourceFileText(file) {
57578
+ return typeof file === "string" ? file : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Buffer.from(file.content, "base64"));
57579
+ }
57580
+ function isResourceAssetPath(path) {
57581
+ return !path.split("/").some((part) => part.startsWith(".") || [
57582
+ "node_modules",
57583
+ "eigenpal_modules",
57584
+ "resource.ts",
57585
+ "package.json",
57586
+ "bun.lock",
57587
+ "package-lock.json",
57588
+ "secrets.enc.yaml",
57589
+ "secrets.yaml",
57590
+ "secrets.yml",
57591
+ "secrets.json",
57592
+ "credentials.json",
57593
+ "id_rsa",
57594
+ "id_ed25519",
57595
+ "id_ecdsa"
57596
+ ].includes(part)) && !/\.(pem|key|p12|pfx)$/i.test(path);
57597
+ }
57598
+ function resourceDirectory(path) {
57599
+ return path.endsWith("/resource.ts") ? path.slice(0, -"/resource.ts".length) : undefined;
57600
+ }
57601
+ var import_parser7;
57602
+ var init_definition_imports = __esm(() => {
57603
+ import_parser7 = __toESM(require_lib(), 1);
57604
+ });
57605
+
57381
57606
  // ../types/src/git-source/index.ts
57382
57607
  var init_git_source = __esm(() => {
57383
57608
  init_grammar();
@@ -57385,6 +57610,10 @@ var init_git_source = __esm(() => {
57385
57610
  init_manifests();
57386
57611
  init_secrets();
57387
57612
  init_agent_definition();
57613
+ init_definition_imports();
57614
+ init_definition_imports();
57615
+ init_definition_imports();
57616
+ init_definition_imports();
57388
57617
  });
57389
57618
 
57390
57619
  // ../types/src/automation/triggers.ts
@@ -208247,7 +208476,7 @@ function toPutBody(body) {
208247
208476
  // package.json
208248
208477
  var package_default = {
208249
208478
  name: "@eigenpal/cli",
208250
- version: "0.20.70",
208479
+ version: "0.20.72",
208251
208480
  description: "Eigenpal CLI — author and run document workflows from your terminal. Agent-ready.",
208252
208481
  keywords: [
208253
208482
  "eigenpal",
@@ -208690,44 +208919,137 @@ import path6 from "node:path";
208690
208919
 
208691
208920
  // src/commands/git/agent-definition.ts
208692
208921
  init_src();
208693
- import { existsSync as existsSync2, lstatSync, readdirSync, readFileSync as readFileSync2 } from "node:fs";
208922
+ import { existsSync as existsSync2, lstatSync, readFileSync as readFileSync2, readdirSync } from "node:fs";
208694
208923
  import path from "node:path";
208695
- function captureAgentSource(root) {
208696
- for (const name of ["eigenpal.yaml", "eigenpal.yml", "input-schema.json", "output-schema.json"])
208924
+ function captureAgentSource(root, filename = "agent.ts") {
208925
+ for (const name of filename === "resource.ts" ? ["eigenpal.yaml", "eigenpal.yml"] : ["eigenpal.yaml", "eigenpal.yml", "input-schema.json", "output-schema.json"])
208697
208926
  if (existsSync2(path.join(root, name)))
208698
208927
  throw new Error("Define the agent manifest and schemas exclusively in agent.ts");
208699
- const files = {};
208928
+ let project = root;
208929
+ while (!existsSync2(path.join(project, "eigenpal.yaml")) && !existsSync2(path.join(project, ".git")) && path.dirname(project) !== project)
208930
+ project = path.dirname(project);
208931
+ if (path.dirname(project) === project)
208932
+ project = root;
208933
+ const entry = path.relative(project, path.join(root, filename)).split(path.sep).join("/");
208934
+ const scope = path.relative(project, root).split(path.sep).join("/");
208935
+ const files = Object.create(null);
208936
+ const regularFile = (relative) => {
208937
+ const components = relative.split("/");
208938
+ for (let n = 1;n <= components.length; n++)
208939
+ if (lstatSync(path.join(project, ...components.slice(0, n))).isSymbolicLink())
208940
+ throw new Error("Resource imports cannot follow symlinks");
208941
+ const stat = lstatSync(path.join(project, relative));
208942
+ if (!stat.isFile())
208943
+ throw new Error("Definition imports must be regular files");
208944
+ return stat;
208945
+ };
208700
208946
  let bytes = 0;
208701
- const visit = (directory) => {
208702
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
208703
- if ([".git", ".eigenpal", "eigenpal_modules", "node_modules"].includes(entry.name))
208947
+ for (const name of [filename, ...filename === "agent.ts" ? ["AGENT.md"] : []]) {
208948
+ const absolute = path.join(root, name);
208949
+ if (!existsSync2(absolute))
208950
+ continue;
208951
+ const relative = path.posix.join(scope, name);
208952
+ bytes += regularFile(relative).size + Buffer.byteLength(relative);
208953
+ if (bytes > 2 * 1024 * 1024)
208954
+ throw new Error("Agent source exceeds compilation limit");
208955
+ const data = readFileSync2(absolute);
208956
+ if (bytes > 2 * 1024 * 1024)
208957
+ throw new Error("Agent source exceeds compilation limit");
208958
+ files[relative] = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(data);
208959
+ }
208960
+ const queue = [entry];
208961
+ const queued = new Set(queue);
208962
+ for (let i = 0;i < queue.length; i++) {
208963
+ const importer = queue[i];
208964
+ if (!/\.(ts|js)$/.test(importer))
208965
+ continue;
208966
+ const directory = resourceDirectory(importer);
208967
+ if (directory) {
208968
+ const walk = (folder) => {
208969
+ for (const item of readdirSync(path.join(project, directory, folder), {
208970
+ withFileTypes: true
208971
+ })) {
208972
+ const local = path.posix.join(folder, item.name);
208973
+ if (!isResourceAssetPath(local))
208974
+ continue;
208975
+ if (item.isSymbolicLink())
208976
+ throw new Error("Resource directories cannot contain symlinks");
208977
+ if (item.isDirectory()) {
208978
+ walk(local);
208979
+ continue;
208980
+ }
208981
+ const relative = path.posix.join(directory, local);
208982
+ if (Object.hasOwn(files, relative))
208983
+ continue;
208984
+ const stat = regularFile(relative);
208985
+ bytes += Math.ceil(stat.size / 3) * 4 + Buffer.byteLength(relative);
208986
+ if (Object.keys(files).length >= 128 || bytes > 2 * 1024 * 1024)
208987
+ throw new Error("Agent source exceeds compilation limit");
208988
+ files[relative] = {
208989
+ encoding: "base64",
208990
+ content: readFileSync2(path.join(project, relative)).toString("base64"),
208991
+ ...stat.mode & 73 ? { executable: true } : {}
208992
+ };
208993
+ }
208994
+ };
208995
+ walk("");
208996
+ }
208997
+ for (const specifier of definitionImports(sourceFileText(files[importer]))) {
208998
+ const candidates = definitionImportCandidates(importer, specifier);
208999
+ if (!candidates.length)
208704
209000
  continue;
208705
- const absolute = path.join(directory, entry.name);
208706
- const relative = path.relative(root, absolute).split(path.sep).join("/");
208707
- const stat = lstatSync(absolute);
208708
- if (stat.isDirectory()) {
208709
- visit(absolute);
209001
+ const selected = candidates.find((candidate) => existsSync2(path.join(project, candidate)));
209002
+ if (!selected)
209003
+ throw new Error("Definition import not found");
209004
+ const assetMode = definitionAssetImports(sourceFileText(files[importer])).get(specifier);
209005
+ if (Object.hasOwn(files, selected)) {
209006
+ if (!assetMode && !queued.has(selected)) {
209007
+ queued.add(selected);
209008
+ queue.push(selected);
209009
+ }
208710
209010
  continue;
208711
209011
  }
208712
- if (!/\.(ts|js)$/.test(relative))
208713
- continue;
208714
- if (!stat.isFile() || !/^[a-zA-Z0-9_./-]+\.(ts|js)$/.test(relative))
208715
- throw new Error("Agent modules must be regular package-local files");
208716
- bytes += stat.size + Buffer.byteLength(relative);
208717
- if (Object.keys(files).length >= 32 || bytes > 256 * 1024)
208718
- throw new Error("Agent source exceeds the compilation limit");
208719
- files[relative] = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(readFileSync2(absolute));
209012
+ if (!selected.startsWith("resources/") && !(scope === "" || selected.startsWith(scope + "/")))
209013
+ throw new Error("Only this agent and shared resource imports are allowed");
209014
+ const absolute = path.join(project, selected);
209015
+ const size = regularFile(selected).size;
209016
+ bytes += (assetMode === "bytes" ? Math.ceil(size / 3) * 4 : size) + Buffer.byteLength(selected);
209017
+ if (Object.keys(files).length >= 128 || bytes > 2 * 1024 * 1024)
209018
+ throw new Error("Agent source exceeds compilation limit");
209019
+ const data = readFileSync2(absolute);
209020
+ files[selected] = assetMode === "bytes" ? { encoding: "base64", content: data.toString("base64") } : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(data);
209021
+ if (!assetMode) {
209022
+ queued.add(selected);
209023
+ queue.push(selected);
209024
+ }
208720
209025
  }
208721
- };
208722
- visit(root);
208723
- if (!Object.hasOwn(files, "agent.ts"))
209026
+ }
209027
+ if (!Object.hasOwn(files, entry))
208724
209028
  throw new Error("Agent entry must be a regular agent.ts file");
208725
- return { entry: "agent.ts", files };
209029
+ return { entry, files };
208726
209030
  }
208727
209031
  async function compileLocalAgent(root, config) {
208728
209032
  const source = captureAgentSource(root);
208729
209033
  return CompiledAgentSnapshotSchema.parse(await new ApiClient(config ?? resolveConfig({})).post("/v1/source/agent-definition", source));
208730
209034
  }
209035
+ async function compileLocalResource(root, config) {
209036
+ const source = resourceDefinitionSource(captureAgentSource(root, "resource.ts"));
209037
+ const snapshot = CompiledAgentSnapshotSchema.parse(await new ApiClient(config ?? resolveConfig({})).post("/v1/source/agent-definition", source));
209038
+ const resource = snapshot.definition.resources?.resource;
209039
+ if (!resource)
209040
+ throw new Error("Invalid TypeScript resource definition");
209041
+ const kind = source.entry.split("/")[1];
209042
+ const kinds = {
209043
+ skills: "skill",
209044
+ rules: "rule",
209045
+ knowledge: "knowledge",
209046
+ templates: "template"
209047
+ };
209048
+ const expected = kinds[kind];
209049
+ if (expected && resource.kind !== expected)
209050
+ throw new Error("Resource kind does not match its folder");
209051
+ return resource;
209052
+ }
208731
209053
 
208732
209054
  // src/commands/git/init.ts
208733
209055
  init_src();
@@ -209196,7 +209518,7 @@ function isOrganizationSourceGitRoot(gitRoot) {
209196
209518
  function findNearestPackageRoot(startDir, gitRoot) {
209197
209519
  let current = path2.resolve(startDir);
209198
209520
  while (true) {
209199
- if (existsSync3(path2.join(current, "eigenpal.yaml")) || existsSync3(path2.join(current, "agent.ts")))
209521
+ if (existsSync3(path2.join(current, "eigenpal.yaml")) || existsSync3(path2.join(current, "agent.ts")) || existsSync3(path2.join(current, "resource.ts")))
209200
209522
  return current;
209201
209523
  if (gitRoot && current === gitRoot)
209202
209524
  return null;
@@ -209241,7 +209563,7 @@ function writeYamlFile(filePath, value) {
209241
209563
  writeFileSync2(filePath, exports_dist.stringify(value));
209242
209564
  }
209243
209565
  function packageManifestExists(gitRoot, packagePath) {
209244
- return existsSync3(path2.join(gitRoot, packagePath, packagePath.startsWith("agents/") ? "agent.ts" : "eigenpal.yaml"));
209566
+ return existsSync3(path2.join(gitRoot, packagePath, packagePath.startsWith("agents/") ? "agent.ts" : packagePath.startsWith("resources/") ? "resource.ts" : "eigenpal.yaml"));
209245
209567
  }
209246
209568
  function releaseTagExists(gitRoot, packagePath, version) {
209247
209569
  const tag = formatReleaseTag(pathToDottedPackageName(packagePath), version);
@@ -209250,6 +209572,14 @@ function releaseTagExists(gitRoot, packagePath, version) {
209250
209572
  async function readPackageManifest(packageRoot, config) {
209251
209573
  if (resolveGitSourceContext({ dir: packageRoot }).packagePath?.startsWith("agents/"))
209252
209574
  return SourcePackageManifestSchema.parse((await compileLocalAgent(packageRoot, config)).definition.manifest);
209575
+ if (resolveGitSourceContext({ dir: packageRoot }).packagePath?.startsWith("resources/")) {
209576
+ const resource = await compileLocalResource(packageRoot, config);
209577
+ return SourcePackageManifestSchema.parse({
209578
+ schemaVersion: 1,
209579
+ name: resource.name,
209580
+ ...resource.description ? { description: resource.description } : {}
209581
+ });
209582
+ }
209253
209583
  return SourcePackageManifestSchema.parse(readYamlFile(path2.join(packageRoot, "eigenpal.yaml")));
209254
209584
  }
209255
209585
  function requirePackageContext(opts = {}) {
@@ -209312,7 +209642,7 @@ async function validatePackage(dir, config) {
209312
209642
  }
209313
209643
  if (!context.packagePath)
209314
209644
  errors.push("Package must live under agents/, workflows/, resources/, or evaluators/.");
209315
- if (context.packagePath?.startsWith("agents/") && context.packageRoot) {
209645
+ if ((context.packagePath?.startsWith("agents/") || context.packagePath?.startsWith("resources/")) && context.packageRoot) {
209316
209646
  try {
209317
209647
  parsedManifest = await readPackageManifest(context.packageRoot, config);
209318
209648
  } catch (error) {
@@ -209712,11 +210042,12 @@ function packagePathForTemplate(template, name) {
209712
210042
  skill: "resources/skills",
209713
210043
  rule: "resources/rules",
209714
210044
  knowledge: "resources/knowledge",
210045
+ template: "resources/templates",
209715
210046
  evaluator: "evaluators"
209716
210047
  };
209717
210048
  const root = rootByTemplate[template];
209718
210049
  if (!root)
209719
- throw new Error("Template must be agent, workflow, skill, rule, knowledge, or evaluator.");
210050
+ throw new Error("Template must be agent, workflow, skill, rule, knowledge, template, or evaluator.");
209720
210051
  return SourcePackagePathSchema.parse(`${root}/${slug}`);
209721
210052
  }
209722
210053
  function writePackageScaffold(packageRoot, packagePath, name) {
@@ -209727,7 +210058,22 @@ function writePackageScaffold(packageRoot, packagePath, name) {
209727
210058
  writeFileSync3(path3.join(packageRoot, "agent.ts"), `import {createAgent} from '@eigenpal/automations';
209728
210059
  export default createAgent(${JSON.stringify({ name: title || path3.basename(packagePath) }, null, 2)});
209729
210060
  `);
209730
- else
210061
+ else if (root === "resources") {
210062
+ const factory = {
210063
+ skills: "createSkill",
210064
+ rules: "createRule",
210065
+ knowledge: "createKnowledge",
210066
+ templates: "createTemplate"
210067
+ }[resourceKind];
210068
+ const contentFile = resourceKind === "skills" ? "SKILL.md" : resourceKind === "rules" ? "RULE.md" : resourceKind === "templates" ? "template.md" : "README.md";
210069
+ writeFileSync3(path3.join(packageRoot, contentFile), `# ${title}
210070
+
210071
+ Describe this resource here.
210072
+ `);
210073
+ writeFileSync3(path3.join(packageRoot, "resource.ts"), `import {${factory}} from '@eigenpal/automations';
210074
+ export default ${factory}({ name: ${JSON.stringify(title || path3.basename(packagePath))} });
210075
+ `);
210076
+ } else
209731
210077
  writeFileSync3(path3.join(packageRoot, "eigenpal.yaml"), exports_dist.stringify({ schemaVersion: 1, name: title || path3.basename(packagePath) }));
209732
210078
  if (root === "agents")
209733
210079
  writeFileSync3(path3.join(packageRoot, "AGENT.md"), `# ${title}
@@ -209736,16 +210082,6 @@ export default createAgent(${JSON.stringify({ name: title || path3.basename(pack
209736
210082
  if (root === "evaluators") {
209737
210083
  writeFileSync3(path3.join(packageRoot, "evaluator.yaml"), exports_dist.stringify({ schemaVersion: 1, type: "exact-diff", config: {} }));
209738
210084
  }
209739
- if (root === "resources" && resourceKind === "skills") {
209740
- writeFileSync3(path3.join(packageRoot, "SKILL.md"), `# ${title}
209741
-
209742
- `);
209743
- }
209744
- if (root === "resources" && (resourceKind === "rules" || resourceKind === "knowledge")) {
209745
- writeFileSync3(path3.join(packageRoot, "README.md"), `# ${title}
209746
-
209747
- `);
209748
- }
209749
210085
  }
209750
210086
  async function initPackage(name, opts) {
209751
210087
  const startDir = path3.resolve(opts.dir ?? process.cwd());
@@ -209772,26 +210108,51 @@ eigenpalVersion: 1.0.0
209772
210108
  if (existsSync4(packageRoot))
209773
210109
  throw new Error(`Package already exists: ${packagePath}`);
209774
210110
  writePackageScaffold(packageRoot, packagePath, name);
209775
- if (opts.template === "agent") {
210111
+ if (opts.template === "agent" || packagePath.startsWith("resources/")) {
210112
+ const tsconfig = path3.join(gitRoot, "tsconfig.json");
210113
+ if (!existsSync4(tsconfig))
210114
+ writeFileSync3(tsconfig, JSON.stringify({
210115
+ compilerOptions: {
210116
+ target: "ES2022",
210117
+ module: "NodeNext",
210118
+ moduleResolution: "NodeNext",
210119
+ strict: true,
210120
+ noEmit: true,
210121
+ allowImportingTsExtensions: true,
210122
+ skipLibCheck: true,
210123
+ types: []
210124
+ },
210125
+ include: ["agents/**/*.ts", "resources/**/*.ts"],
210126
+ exclude: ["node_modules", "eigenpal_modules"]
210127
+ }, null, 2) + `
210128
+ `);
209776
210129
  const toolchain = { sdkVersion: CLI_VERSION, zodVersion: package_default2.version };
209777
210130
  const file = path3.join(gitRoot, "package.json");
209778
210131
  const current = existsSync4(file) ? JSON.parse(readFileSync5(file, "utf8")) : { private: true, type: "module" };
209779
210132
  const additions = {};
209780
210133
  for (const [name, version] of Object.entries({
209781
210134
  "@eigenpal/automations": toolchain.sdkVersion,
209782
- zod: toolchain.zodVersion
210135
+ zod: toolchain.zodVersion,
210136
+ typescript: "^6.0.3"
209783
210137
  }))
209784
210138
  if (!current.dependencies?.[name] && !current.devDependencies?.[name])
209785
210139
  additions[name] = version;
209786
- if (Object.keys(additions).length > 0)
209787
- writeFileSync3(file, JSON.stringify({ ...current, devDependencies: { ...current.devDependencies, ...additions } }, null, 2) + `
210140
+ if (Object.keys(additions).length > 0 || !current.scripts?.typecheck)
210141
+ writeFileSync3(file, JSON.stringify({
210142
+ ...current,
210143
+ scripts: {
210144
+ ...current.scripts,
210145
+ typecheck: current.scripts?.typecheck ?? "tsc --noEmit"
210146
+ },
210147
+ devDependencies: { ...current.devDependencies, ...additions }
210148
+ }, null, 2) + `
209788
210149
  `);
209789
210150
  }
209790
210151
  success(`Created ${packagePath}.`);
209791
210152
  }
209792
210153
  function parseTemplate(value) {
209793
- if (!["agent", "workflow", "skill", "rule", "knowledge", "evaluator"].includes(value)) {
209794
- throw new InvalidArgumentError2("template must be agent, workflow, skill, rule, knowledge, or evaluator");
210154
+ if (!["agent", "workflow", "skill", "rule", "knowledge", "template", "evaluator"].includes(value)) {
210155
+ throw new InvalidArgumentError2("template must be agent, workflow, skill, rule, knowledge, template, or evaluator");
209795
210156
  }
209796
210157
  return value;
209797
210158
  }
@@ -210237,8 +210598,30 @@ async function resolvePackageGraph(input) {
210237
210598
  const resolved = await resolvePackageRef(input);
210238
210599
  const tempDir = await mkdtemp(path6.join(tmpdir(), "eigenpal-install-resolve-"));
210239
210600
  try {
210240
- const packageRoot = path6.join(tempDir, "package");
210601
+ const typed = /^(agents|resources)\//.test(input.packagePath);
210602
+ const packageRoot = path6.join(tempDir, typed ? input.packagePath : "package");
210241
210603
  const ref = resolved.commit;
210604
+ if (typed) {
210605
+ writeFileSync4(path6.join(tempDir, "eigenpal.yaml"), `schemaVersion: 1
210606
+ eigenpalVersion: 1.0.0
210607
+ `);
210608
+ if (input.gitRoot) {
210609
+ if (gitOutput2(["ls-tree", "--name-only", ref, "--", "resources"], input.gitRoot))
210610
+ archivePackage({
210611
+ gitRoot: input.gitRoot,
210612
+ ref,
210613
+ packagePath: "resources",
210614
+ outDir: path6.join(tempDir, "resources")
210615
+ });
210616
+ } else
210617
+ await tryHostedArchive({
210618
+ config: input.config,
210619
+ repository: input.repository,
210620
+ ref,
210621
+ packagePath: "resources",
210622
+ outDir: path6.join(tempDir, "resources")
210623
+ });
210624
+ }
210242
210625
  if (input.gitRoot) {
210243
210626
  archivePackage({
210244
210627
  gitRoot: input.gitRoot,
@@ -210256,7 +210639,12 @@ async function resolvePackageGraph(input) {
210256
210639
  throw new Error(`Hosted source export unavailable for ${input.packagePath}@${ref}.`);
210257
210640
  }
210258
210641
  const compiledAgent = input.packagePath.startsWith("agents/") ? await compileLocalAgent(packageRoot, input.config) : undefined;
210259
- const manifest = compiledAgent ? compiledAgent.definition.manifest : await readPackageManifest(packageRoot);
210642
+ const resource = input.packagePath.startsWith("resources/") ? await compileLocalResource(packageRoot, input.config) : undefined;
210643
+ const manifest = compiledAgent ? compiledAgent.definition.manifest : resource ? {
210644
+ schemaVersion: 1,
210645
+ name: resource.name,
210646
+ ...resource.description ? { description: resource.description } : {}
210647
+ } : await readPackageManifest(packageRoot, input.config);
210260
210648
  const dependencies = "dependencies" in manifest ? Object.entries(manifest.dependencies ?? {}) : [];
210261
210649
  const resolvedDependencies = [];
210262
210650
  for (const [dependencyName, version] of dependencies)
@@ -210628,6 +211016,15 @@ async function sync(target, opts) {
210628
211016
  }
210629
211017
  await syncLatestAutomation(new ApiClient(resolveConfig(opts)), packagePath);
210630
211018
  }
211019
+ function localPackageInputHash(context, dependencies = []) {
211020
+ const typed = /^(agents|resources)\//.test(context.packagePath);
211021
+ return sourceLockfileInputHash({
211022
+ packagePath: context.packagePath,
211023
+ ...typed ? {
211024
+ source: captureAgentSource(context.packageRoot, context.packagePath.startsWith("resources/") ? "resource.ts" : "agent.ts")
211025
+ } : { dependencies }
211026
+ });
211027
+ }
210631
211028
  async function install(packageRef, opts) {
210632
211029
  const config = resolveConfig(opts);
210633
211030
  const context = resolveGitSourceContext();
@@ -210676,9 +211073,8 @@ async function install(packageRef, opts) {
210676
211073
  if (!context.packageRoot || !context.packagePath) {
210677
211074
  throw new Error("Run eigenpal agents install --frozen-lockfile inside a source package or pass a package ref.");
210678
211075
  }
210679
- const manifest = await readPackageManifest(context.packageRoot, config);
210680
- const dependencies = "dependencies" in manifest ? Object.entries(manifest.dependencies ?? {}) : [];
210681
- const inputHash = sourceLockfileInputHash({ packagePath: context.packagePath, dependencies });
211076
+ const dependencies = /^(agents|resources)\//.test(context.packagePath) ? [] : Object.entries((await readPackageManifest(context.packageRoot, config)).dependencies ?? {});
211077
+ const inputHash = localPackageInputHash({ packagePath: context.packagePath, packageRoot: context.packageRoot }, dependencies);
210682
211078
  const existing = readLockfile(lockfilePath);
210683
211079
  if (existing.inputHash !== inputHash) {
210684
211080
  throw new Error(`Existing lockfile ${lockfilePath} does not match current package inputs.`);
@@ -210740,9 +211136,8 @@ async function install(packageRef, opts) {
210740
211136
  if (!context.gitRoot) {
210741
211137
  throw new Error("Run eigenpal agents install inside an organization source repository.");
210742
211138
  }
210743
- const manifest = await readPackageManifest(context.packageRoot, config);
210744
- const dependencies = "dependencies" in manifest ? Object.entries(manifest.dependencies ?? {}) : [];
210745
- const inputHash = sourceLockfileInputHash({ packagePath: context.packagePath, dependencies });
211139
+ const dependencies = /^(agents|resources)\//.test(context.packagePath) ? [] : Object.entries((await readPackageManifest(context.packageRoot, config)).dependencies ?? {});
211140
+ const inputHash = localPackageInputHash({ packagePath: context.packagePath, packageRoot: context.packageRoot }, dependencies);
210746
211141
  const intendedLockfile = opts.lockfile ?? path6.join(context.packageRoot, ".eigenpal", INSTALL_LOCKFILE_NAME);
210747
211142
  if (existsSync6(intendedLockfile)) {
210748
211143
  const existing = readLockfile(intendedLockfile);
@@ -210752,7 +211147,11 @@ async function install(packageRef, opts) {
210752
211147
  await installFromLock(intendedLockfile, context.packageRoot, false);
210753
211148
  return;
210754
211149
  }
211150
+ const compiledAgent = context.packagePath.startsWith("agents/") ? await compileLocalAgent(context.packageRoot, config) : undefined;
211151
+ if (context.packagePath.startsWith("resources/"))
211152
+ await compileLocalResource(context.packageRoot, config);
210755
211153
  const root = {
211154
+ ...compiledAgent ? { compiledAgent } : {},
210756
211155
  packagePath: context.packagePath,
210757
211156
  requestedRef: "main",
210758
211157
  resolvedRef: "main",
@@ -212296,8 +212695,6 @@ async function validateAgentProject(root) {
212296
212695
  }
212297
212696
  if (!existsSync8(path8.join(root, "agent.ts")))
212298
212697
  errors.push("Missing agent.ts");
212299
- if (!existsSync8(path8.join(root, "AGENT.md")))
212300
- warnings.push("Missing AGENT.md");
212301
212698
  if (!existsSync8(path8.join(root, DATASET_DIR)))
212302
212699
  warnings.push(`Missing ${DATASET_DIR}/`);
212303
212700
  return { valid: errors.length === 0, errors, warnings };
@@ -241881,8 +242278,11 @@ function toNumberOrNull(value) {
241881
242278
  function runOutput(run) {
241882
242279
  return run.output !== undefined ? run.output : run.result?.output;
241883
242280
  }
241884
- async function fetchHasEvaluators(client, workflowId) {
241885
- const cfg = await client.get(`/v1/automations/${workflowId}/evaluators`);
242281
+ async function fetchHasEvaluators(client, workflowId, sourceRef) {
242282
+ const query = sourceRef ? `?sourceRef=${encodeURIComponent(sourceRef)}` : "";
242283
+ const cfg = await client.get(`/v1/automations/${workflowId}/evaluators${query}`);
242284
+ if (cfg.automationType === "agent")
242285
+ return Boolean(cfg.evaluation && Object.keys(cfg.evaluation.evaluators).length);
241886
242286
  return Array.isArray(cfg.config?.evaluators) && cfg.config.evaluators.length > 0;
241887
242287
  }
241888
242288
  async function resolveExample(client, workflowId, name) {
@@ -241929,6 +242329,10 @@ async function pollEvalRollup(client, runId) {
241929
242329
  }
241930
242330
  }
241931
242331
  async function fetchEvalRows(client, workflowId, batchId, runId) {
242332
+ if (!batchId) {
242333
+ const detail = await client.get(`/v1/runs/${encodeURIComponent(runId)}/scores`);
242334
+ return detail.scores;
242335
+ }
241932
242336
  const detail = await client.get(`/v1/automations/${workflowId}/experiments/${batchId}`);
241933
242337
  return detail.resultsByRun?.[runId] ?? [];
241934
242338
  }
@@ -241945,7 +242349,7 @@ function toArtifactPayload(run, runId) {
241945
242349
  }
241946
242350
  async function runWorkflowExamplesWithEval(client, dir, workflowIdOrSlug, workflowId, exampleNames, options = {}) {
241947
242351
  const hasEvaluators = await fetchHasEvaluators(client, workflowId);
241948
- const mode = hasEvaluators ? "evaluators" : "diff";
242352
+ let mode = hasEvaluators ? "evaluators" : "diff";
241949
242353
  if (!options.quiet) {
241950
242354
  info(`Running ${ui.bold(`"${workflowIdOrSlug}"`)} ${ui.dim(`(${workflowId}, ${exampleNames.length} example(s))`)}`);
241951
242355
  dim(hasEvaluators ? "Server example run; grading with configured evaluators." : "Server example run; no evaluators configured, grading by structural diff vs expected.");
@@ -241979,7 +242383,10 @@ async function runWorkflowExamplesWithEval(client, dir, workflowIdOrSlug, workfl
241979
242383
  runError: runOk ? undefined : run.error ?? status ?? "unknown",
241980
242384
  mode: "none"
241981
242385
  };
241982
- if (runOk && hasEvaluators && started.batchId) {
242386
+ const commit = run.source?.git?.commitSha;
242387
+ const runHasEvaluators = runOk && commit ? await fetchHasEvaluators(client, workflowId, commit) : hasEvaluators;
242388
+ if (runOk && runHasEvaluators) {
242389
+ mode = "evaluators";
241983
242390
  const rollup = await pollEvalRollup(client, runId);
241984
242391
  if (rollup) {
241985
242392
  const rows = await fetchEvalRows(client, workflowId, started.batchId, runId);
@@ -241994,10 +242401,20 @@ async function runWorkflowExamplesWithEval(client, dir, workflowIdOrSlug, workfl
241994
242401
  error: r.error ?? null
241995
242402
  }));
241996
242403
  } else {
241997
- if (!options.quiet) {
241998
- warn(` ${name}: no evaluator score after ${EVAL_GRACE_MS / 1000}s; grading by diff.`);
241999
- }
242000
- gradeByDiff(result, example.expected, runOutput(run));
242404
+ result.mode = "evaluators";
242405
+ result.score = null;
242406
+ result.passed = false;
242407
+ result.evaluators = [
242408
+ {
242409
+ name: "evaluation",
242410
+ score: null,
242411
+ passed: false,
242412
+ weight: null,
242413
+ error: "Evaluation did not finish within the grace period"
242414
+ }
242415
+ ];
242416
+ if (!options.quiet)
242417
+ warn(` ${name}: evaluator decision did not arrive; marking evaluation failed.`);
242001
242418
  }
242002
242419
  } else if (runOk) {
242003
242420
  gradeByDiff(result, example.expected, runOutput(run));
@@ -242202,7 +242619,10 @@ async function runExample(agentId, opts) {
242202
242619
  const status = payload.execution?.status;
242203
242620
  let wait = { kind: "no-evaluators" };
242204
242621
  if (status === "completed") {
242205
- wait = await waitForExampleEvalRollup(client, agentId, runId);
242622
+ const source = objectOrNull2(objectOrNull2(payload)?.source);
242623
+ const sourceGit = objectOrNull2(source?.git);
242624
+ const pinnedRef = typeof sourceGit?.commitSha === "string" ? sourceGit.commitSha : opts.sourceRef;
242625
+ wait = await waitForExampleEvalRollup(client, agentId, runId, pinnedRef);
242206
242626
  if (wait.kind === "landed") {
242207
242627
  payload = await client.get(`/v1/runs/${encodeURIComponent(runId)}?expand=usage,execution`);
242208
242628
  }
@@ -242222,7 +242642,12 @@ async function runExample(agentId, opts) {
242222
242642
  error2(`--fail-on-mismatch: no evaluator verdict landed within ${EVAL_GRACE_MS / 1000}s; refusing to report success without a verdict.`);
242223
242643
  process.exitCode = 2;
242224
242644
  } else if (wait.kind === "no-evaluators") {
242225
- warn("--fail-on-mismatch cannot gate this run: no evaluators are configured.");
242645
+ const message = "No evaluators configured; --fail-on-mismatch cannot gate this run.";
242646
+ if (opts.json)
242647
+ process.stderr.write(`${message}
242648
+ `);
242649
+ else
242650
+ warn(message);
242226
242651
  }
242227
242652
  }
242228
242653
  return;
@@ -242237,10 +242662,10 @@ async function runExample(agentId, opts) {
242237
242662
  return printJson2(payload);
242238
242663
  success(`Run ${runId ?? ""} queued for example ${opts.example}`);
242239
242664
  }
242240
- async function waitForExampleEvalRollup(client, agentId, runId) {
242665
+ async function waitForExampleEvalRollup(client, agentId, runId, sourceRef) {
242241
242666
  let hasEvaluators = true;
242242
242667
  try {
242243
- hasEvaluators = await fetchHasEvaluators(client, agentAutomationId(agentId));
242668
+ hasEvaluators = await fetchHasEvaluators(client, agentAutomationId(agentId), sourceRef);
242244
242669
  } catch {}
242245
242670
  if (!hasEvaluators) {
242246
242671
  warn("No evaluators configured for this automation; run not graded.");