@autohq/cli 0.1.677 → 0.1.678

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.
@@ -33217,7 +33217,7 @@ function bootstrapAdditionalData(input) {
33217
33217
  // package.json
33218
33218
  var package_default = {
33219
33219
  name: "@autohq/cli",
33220
- version: "0.1.677",
33220
+ version: "0.1.678",
33221
33221
  license: "SEE LICENSE IN README.md",
33222
33222
  publishConfig: {
33223
33223
  access: "public"
package/dist/index.js CHANGED
@@ -23403,6 +23403,21 @@ var init_validation_diagnostics = __esm({
23403
23403
  message: "The Auto authoring file could not be parsed as YAML or JSON.",
23404
23404
  owner: "schemas/project-apply-files"
23405
23405
  },
23406
+ "auto.validation.schema_version.invalid": {
23407
+ severity: "error",
23408
+ message: "The authored schema version must be a positive integer.",
23409
+ owner: "schemas/project-apply-files"
23410
+ },
23411
+ "auto.validation.schema_version.unsupported": {
23412
+ severity: "error",
23413
+ message: "This Auto release does not support the authored schema version.",
23414
+ owner: "schemas/project-apply-files"
23415
+ },
23416
+ "auto.validation.authoring.unknown_field": {
23417
+ severity: "error",
23418
+ message: "The versioned authoring document contains an unknown field.",
23419
+ owner: "schemas/project-apply-files"
23420
+ },
23406
23421
  "auto.validation.schema.invalid": {
23407
23422
  severity: "error",
23408
23423
  message: "The Auto resource does not match its schema.",
@@ -23429,7 +23444,8 @@ var init_validation_diagnostics = __esm({
23429
23444
  location: external_exports.object({
23430
23445
  file: external_exports.string().min(1),
23431
23446
  line: external_exports.number().int().positive().optional(),
23432
- column: external_exports.number().int().positive().optional()
23447
+ column: external_exports.number().int().positive().optional(),
23448
+ documentIndex: external_exports.number().int().nonnegative().optional()
23433
23449
  }).optional(),
23434
23450
  remediation: external_exports.object({
23435
23451
  summary: external_exports.string().min(1),
@@ -104535,7 +104551,7 @@ var init_package = __esm({
104535
104551
  "package.json"() {
104536
104552
  package_default = {
104537
104553
  name: "@autohq/cli",
104538
- version: "0.1.677",
104554
+ version: "0.1.678",
104539
104555
  license: "SEE LICENSE IN README.md",
104540
104556
  publishConfig: {
104541
104557
  access: "public"
@@ -105539,17 +105555,140 @@ var init_agent_tool_connect = __esm({
105539
105555
  }
105540
105556
  });
105541
105557
 
105558
+ // ../../packages/schemas/src/project-apply-files/schema-version.ts
105559
+ function selectAuthoredSchemaDocument(input) {
105560
+ if (!isRecord4(input.document) || !Object.hasOwn(input.document, "schemaVersion")) {
105561
+ return {
105562
+ dialect: LEGACY_AUTHORED_SCHEMA_DIALECT,
105563
+ value: input.document
105564
+ };
105565
+ }
105566
+ const version2 = input.document.schemaVersion;
105567
+ if (typeof version2 !== "number" || !isPositiveInteger(version2)) {
105568
+ throw malformedSchemaVersionError(input);
105569
+ }
105570
+ if (version2 > CURRENT_AUTHORED_SCHEMA_VERSION) {
105571
+ throw unsupportedSchemaVersionError(input, version2);
105572
+ }
105573
+ const { schemaVersion: _controlField, ...body } = input.document;
105574
+ return {
105575
+ dialect: CURRENT_AUTHORED_SCHEMA_DIALECT,
105576
+ value: migrateAuthoredSchemaDocument({
105577
+ document: body,
105578
+ fromVersion: version2,
105579
+ toVersion: CURRENT_AUTHORED_SCHEMA_VERSION,
105580
+ migrations: AUTHORED_SCHEMA_MIGRATIONS
105581
+ })
105582
+ };
105583
+ }
105584
+ function isAuthoredSchemaVersionError(error51) {
105585
+ if (!(error51 instanceof AutoValidationDiagnosticError)) {
105586
+ return false;
105587
+ }
105588
+ return error51.diagnostic.code === "auto.validation.schema_version.invalid" || error51.diagnostic.code === "auto.validation.schema_version.unsupported";
105589
+ }
105590
+ function migrateAuthoredSchemaDocument(input) {
105591
+ if (!isPositiveInteger(input.fromVersion) || !isPositiveInteger(input.toVersion)) {
105592
+ throw new Error(
105593
+ "Authored schema migration endpoints must be positive integers"
105594
+ );
105595
+ }
105596
+ if (input.fromVersion > input.toVersion) {
105597
+ throw new Error(
105598
+ `Authored schema migrations cannot move backward from ${input.fromVersion} to ${input.toVersion}`
105599
+ );
105600
+ }
105601
+ let document = structuredClone(input.document);
105602
+ for (let version2 = input.fromVersion; version2 < input.toVersion; version2 += 1) {
105603
+ const edges = input.migrations.filter(
105604
+ (edge) => edge.fromVersion === version2
105605
+ );
105606
+ if (edges.length !== 1 || edges[0]?.toVersion !== version2 + 1) {
105607
+ throw new Error(
105608
+ `Authored schema migration chain requires exactly one ${version2} -> ${version2 + 1} edge`
105609
+ );
105610
+ }
105611
+ document = edges[0].migrate(structuredClone(document));
105612
+ }
105613
+ return document;
105614
+ }
105615
+ function malformedSchemaVersionError(input) {
105616
+ return new AutoValidationDiagnosticError(
105617
+ `Invalid schemaVersion in ${documentLabel(input)}: expected a positive integer`,
105618
+ autoValidationDiagnostic({
105619
+ code: "auto.validation.schema_version.invalid",
105620
+ path: ["schemaVersion"],
105621
+ location: diagnosticLocation(input),
105622
+ remediation: {
105623
+ summary: `Set schemaVersion to ${CURRENT_AUTHORED_SCHEMA_VERSION}, or remove it to retain the legacy dialect.`
105624
+ }
105625
+ })
105626
+ );
105627
+ }
105628
+ function unsupportedSchemaVersionError(input, version2) {
105629
+ return new AutoValidationDiagnosticError(
105630
+ `Unsupported schemaVersion ${version2} in ${documentLabel(input)}: this Auto release supports through ${CURRENT_AUTHORED_SCHEMA_VERSION}`,
105631
+ autoValidationDiagnostic({
105632
+ code: "auto.validation.schema_version.unsupported",
105633
+ path: ["schemaVersion"],
105634
+ location: diagnosticLocation(input),
105635
+ remediation: {
105636
+ summary: "Upgrade Auto to a release that supports this authored schema version, then validate again."
105637
+ }
105638
+ })
105639
+ );
105640
+ }
105641
+ function documentLabel(input) {
105642
+ return `${input.location.file} document ${input.documentIndex + 1}`;
105643
+ }
105644
+ function diagnosticLocation(input) {
105645
+ return {
105646
+ ...input.topLevelLocations.schemaVersion ?? input.location,
105647
+ documentIndex: input.documentIndex
105648
+ };
105649
+ }
105650
+ function isRecord4(value) {
105651
+ return typeof value === "object" && value !== null && !Array.isArray(value);
105652
+ }
105653
+ function isPositiveInteger(value) {
105654
+ return Number.isInteger(value) && value > 0;
105655
+ }
105656
+ var CURRENT_AUTHORED_SCHEMA_VERSION, LEGACY_AUTHORED_SCHEMA_DIALECT, AUTHORED_SCHEMA_MIGRATIONS, CURRENT_AUTHORED_SCHEMA_DIALECT;
105657
+ var init_schema_version = __esm({
105658
+ "../../packages/schemas/src/project-apply-files/schema-version.ts"() {
105659
+ "use strict";
105660
+ init_validation_diagnostics();
105661
+ CURRENT_AUTHORED_SCHEMA_VERSION = 1;
105662
+ LEGACY_AUTHORED_SCHEMA_DIALECT = Object.freeze({
105663
+ kind: "legacy"
105664
+ });
105665
+ AUTHORED_SCHEMA_MIGRATIONS = Object.freeze([]);
105666
+ CURRENT_AUTHORED_SCHEMA_DIALECT = Object.freeze({
105667
+ kind: "versioned",
105668
+ version: CURRENT_AUTHORED_SCHEMA_VERSION
105669
+ });
105670
+ }
105671
+ });
105672
+
105542
105673
  // ../../packages/schemas/src/project-apply-files/source.ts
105543
- import { parseAllDocuments as parseYamlDocuments2 } from "yaml";
105544
- function readDocumentsFromSource(file2) {
105674
+ import {
105675
+ LineCounter,
105676
+ isMap,
105677
+ parseAllDocuments as parseYamlDocuments2
105678
+ } from "yaml";
105679
+ function readSourceDocuments(file2) {
105545
105680
  const source = Buffer.from(file2.contentBase64, "base64").toString("utf8");
105681
+ const lineCounter = new LineCounter();
105682
+ let parsedDocuments;
105546
105683
  try {
105547
- const parsedDocuments = parseYamlDocuments2(source);
105684
+ parsedDocuments = parseYamlDocuments2(source, {
105685
+ keepSourceTokens: true,
105686
+ lineCounter
105687
+ });
105548
105688
  const parseError = parsedDocuments.flatMap((document) => document.errors).at(0);
105549
105689
  if (parseError) {
105550
105690
  throw parseError;
105551
105691
  }
105552
- return parsedDocuments.filter((document) => document.contents !== null).map((document) => document.toJSON());
105553
105692
  } catch {
105554
105693
  throw new AutoValidationDiagnosticError(
105555
105694
  `Invalid apply file ${file2.path}: YAML or JSON could not be parsed`,
@@ -105562,6 +105701,55 @@ function readDocumentsFromSource(file2) {
105562
105701
  })
105563
105702
  );
105564
105703
  }
105704
+ return parsedDocuments.flatMap((document, documentIndex) => {
105705
+ if (document.contents === null) {
105706
+ return [];
105707
+ }
105708
+ const value = sourceDocumentValue(document, file2.path);
105709
+ const location = sourceNodeLocation(
105710
+ document.contents,
105711
+ file2.path,
105712
+ lineCounter
105713
+ );
105714
+ const topLevelLocations = topLevelSourceLocations(
105715
+ document.contents,
105716
+ file2.path,
105717
+ lineCounter
105718
+ );
105719
+ const selected = selectAuthoredSchemaDocument({
105720
+ document: value,
105721
+ documentIndex,
105722
+ location,
105723
+ topLevelLocations
105724
+ });
105725
+ return [
105726
+ {
105727
+ ...selected,
105728
+ documentIndex,
105729
+ location,
105730
+ topLevelLocations
105731
+ }
105732
+ ];
105733
+ });
105734
+ }
105735
+ function sourceDocumentValue(document, file2) {
105736
+ try {
105737
+ return document.toJSON();
105738
+ } catch {
105739
+ throw invalidSourceSyntaxError(file2);
105740
+ }
105741
+ }
105742
+ function invalidSourceSyntaxError(file2) {
105743
+ return new AutoValidationDiagnosticError(
105744
+ `Invalid apply file ${file2}: YAML or JSON could not be parsed`,
105745
+ autoValidationDiagnostic({
105746
+ code: "auto.validation.parse.yaml_invalid",
105747
+ location: { file: file2 },
105748
+ remediation: {
105749
+ summary: "Fix the YAML or JSON syntax in this file, then validate again."
105750
+ }
105751
+ })
105752
+ );
105565
105753
  }
105566
105754
  function primaryApplyDirectory() {
105567
105755
  return APPLY_DIRECTORIES[RESOURCE_KIND_AGENT];
@@ -105583,15 +105771,39 @@ function sourceFileIndex(files) {
105583
105771
  function isAbsoluteSourcePath(path2) {
105584
105772
  return path2.startsWith("/");
105585
105773
  }
105586
- function isRecord4(value) {
105774
+ function isRecord5(value) {
105587
105775
  return typeof value === "object" && value !== null && !Array.isArray(value);
105588
105776
  }
105777
+ function topLevelSourceLocations(node, file2, lineCounter) {
105778
+ if (!isMap(node)) {
105779
+ return {};
105780
+ }
105781
+ return Object.fromEntries(
105782
+ node.items.flatMap((pair) => {
105783
+ const key = pair.key?.toJSON?.();
105784
+ if (typeof key !== "string") {
105785
+ return [];
105786
+ }
105787
+ return [[key, sourceNodeLocation(pair.key, file2, lineCounter)]];
105788
+ })
105789
+ );
105790
+ }
105791
+ function sourceNodeLocation(node, file2, lineCounter) {
105792
+ const range = node?.range;
105793
+ const position = lineCounter.linePos(range?.[0] ?? 0);
105794
+ return {
105795
+ file: normalizeSourcePath(file2),
105796
+ line: position.line,
105797
+ column: position.col
105798
+ };
105799
+ }
105589
105800
  var APPLY_DIRECTORIES, PROJECT_APPLY_RESOURCE_DIRECTORIES;
105590
105801
  var init_source = __esm({
105591
105802
  "../../packages/schemas/src/project-apply-files/source.ts"() {
105592
105803
  "use strict";
105593
105804
  init_agents();
105594
105805
  init_validation_diagnostics();
105806
+ init_schema_version();
105595
105807
  APPLY_DIRECTORIES = {
105596
105808
  [RESOURCE_KIND_AGENT]: "agents"
105597
105809
  };
@@ -105608,7 +105820,7 @@ function readSingleDocument2(path2, fileIndex) {
105608
105820
  if (!file2) {
105609
105821
  throw new Error(`Agent import not found: ${path2}`);
105610
105822
  }
105611
- const documents = readDocumentsFromSource(file2);
105823
+ const documents = readSourceDocuments(file2);
105612
105824
  if (documents.length !== 1) {
105613
105825
  throw new Error(
105614
105826
  `Agent authoring file ${file2.path} must contain exactly one document`
@@ -105662,7 +105874,7 @@ function resolveTemplateImportPath(importPath, fileIndex) {
105662
105874
  return key;
105663
105875
  }
105664
105876
  function removalDirectives2(document, path2) {
105665
- const raw = isRecord4(document.remove) ? document.remove : {};
105877
+ const raw = isRecord5(document.remove) ? document.remove : {};
105666
105878
  const directives = [];
105667
105879
  for (const [target, value] of Object.entries(raw)) {
105668
105880
  const names = stringList2(value, `remove.${target}`);
@@ -105690,16 +105902,16 @@ var init_agent_document_merge = __esm({
105690
105902
  });
105691
105903
 
105692
105904
  // ../../packages/schemas/src/project-apply-files/source-locations.ts
105693
- import { LineCounter, isMap, isSeq, parseAllDocuments as parseAllDocuments3 } from "yaml";
105905
+ import { LineCounter as LineCounter2, isMap as isMap2, isSeq, parseAllDocuments as parseAllDocuments3 } from "yaml";
105694
105906
  function readProjectConfigSourceLocations(file2) {
105695
- const locations = readYamlLocations(file2, "spec");
105907
+ const locations = readYamlLocations(file2, "spec", 0);
105696
105908
  return Object.values(locations).map((location) => ({
105697
105909
  ...location,
105698
105910
  kind: RESOURCE_KIND_CONFIG,
105699
105911
  name: PROJECT_CONFIG_RESOURCE_NAME
105700
105912
  }));
105701
105913
  }
105702
- function readAgentDraftSourceLocations(path2, fileIndex) {
105914
+ function readAgentDraftSourceLocations(path2, fileIndex, documentIndex) {
105703
105915
  const normalizedPath = normalizeSourcePath(path2);
105704
105916
  if (normalizedPath.startsWith("packages/")) {
105705
105917
  return {};
@@ -105708,30 +105920,39 @@ function readAgentDraftSourceLocations(path2, fileIndex) {
105708
105920
  if (!file2) {
105709
105921
  return {};
105710
105922
  }
105711
- return readYamlLocations(file2, "");
105923
+ return readYamlLocations(file2, "", documentIndex);
105712
105924
  }
105713
- function readYamlLocations(file2, rootPath) {
105925
+ function readYamlLocations(file2, rootPath, documentIndex) {
105714
105926
  const source = Buffer.from(file2.contentBase64, "base64").toString("utf8");
105715
- const lineCounter = new LineCounter();
105927
+ const lineCounter = new LineCounter2();
105716
105928
  const documents = parseAllDocuments3(source, {
105717
105929
  keepSourceTokens: true,
105718
105930
  lineCounter
105719
105931
  });
105720
- if (documents.length !== 1 || documents[0]?.errors.length) {
105932
+ const document = documents[documentIndex];
105933
+ if (!document || document.errors.length > 0) {
105721
105934
  return {};
105722
105935
  }
105723
105936
  const locations = {};
105724
- collectNodeLocations(documents[0]?.contents, rootPath, locations, {
105937
+ collectNodeLocations(document.contents, rootPath, locations, {
105725
105938
  file: normalizeSourcePath(file2.path),
105726
105939
  lineCounter
105727
105940
  });
105728
105941
  return locations;
105729
105942
  }
105730
105943
  function collectNodeLocations(node, path2, locations, context) {
105731
- if (isMap(node)) {
105944
+ if (isMap2(node)) {
105732
105945
  for (const pair of node.items) {
105733
105946
  const key = String(pair.key?.toJSON());
105734
- if (["import", "imports", "remove", "variables"].includes(key)) {
105947
+ if ([
105948
+ "import",
105949
+ "imports",
105950
+ "remove",
105951
+ "schemaVersion",
105952
+ "templateVariables",
105953
+ "variables",
105954
+ "when"
105955
+ ].includes(key)) {
105735
105956
  continue;
105736
105957
  }
105737
105958
  const childPath = propertyPath(path2, key);
@@ -105807,7 +106028,7 @@ function mergeValues3(base, override) {
105807
106028
  if (override === void 0) {
105808
106029
  return base;
105809
106030
  }
105810
- if (isRecord4(base) && isRecord4(override)) {
106031
+ if (isRecord5(base) && isRecord5(override)) {
105811
106032
  const merged = { ...base };
105812
106033
  for (const [key, value] of Object.entries(override)) {
105813
106034
  merged[key] = mergeValues3(merged[key], value);
@@ -105827,7 +106048,7 @@ function sortJson(value) {
105827
106048
  if (Array.isArray(value)) {
105828
106049
  return value.map(sortJson);
105829
106050
  }
105830
- if (isRecord4(value)) {
106051
+ if (isRecord5(value)) {
105831
106052
  return Object.fromEntries(
105832
106053
  Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, nested]) => [key, sortJson(nested)])
105833
106054
  );
@@ -105843,6 +106064,7 @@ var init_helpers = __esm({
105843
106064
  "import",
105844
106065
  "imports",
105845
106066
  "remove",
106067
+ "schemaVersion",
105846
106068
  "templateVariables",
105847
106069
  "variables",
105848
106070
  "when"
@@ -105865,7 +106087,7 @@ function fileBackedStringField() {
105865
106087
  };
105866
106088
  }
105867
106089
  function rejectDirectiveObject(value, input) {
105868
- if (isRecord4(value) && "append" in value) {
106090
+ if (isRecord5(value) && "append" in value) {
105869
106091
  throw new Error(
105870
106092
  `Invalid agent authoring file ${input.path}: ${input.field} does not support directive objects; append is supported on ${APPEND_CAPABLE_FIELDS}`
105871
106093
  );
@@ -105873,7 +106095,7 @@ function rejectDirectiveObject(value, input) {
105873
106095
  return value;
105874
106096
  }
105875
106097
  function resolveFileBackedString2(value, input) {
105876
- if (!isRecord4(value)) {
106098
+ if (!isRecord5(value)) {
105877
106099
  return value;
105878
106100
  }
105879
106101
  if ("file" in value && !("append" in value)) {
@@ -105971,11 +106193,11 @@ function rejectUnresolvedAppendDirective(value) {
105971
106193
  );
105972
106194
  }
105973
106195
  function appendDirectiveFromMarker(value) {
105974
- if (!isRecord4(value)) {
106196
+ if (!isRecord5(value)) {
105975
106197
  return void 0;
105976
106198
  }
105977
106199
  const marker = value[APPEND_DIRECTIVE_MARKER_KEY];
105978
- if (!isRecord4(marker)) {
106200
+ if (!isRecord5(marker)) {
105979
106201
  return void 0;
105980
106202
  }
105981
106203
  return marker;
@@ -105997,7 +106219,7 @@ function inlineEnvironmentField() {
105997
106219
  target: "spec",
105998
106220
  merge: (base, override) => mergeValues3(base, override),
105999
106221
  compile: (value, context) => {
106000
- if (!isRecord4(value)) {
106222
+ if (!isRecord5(value)) {
106001
106223
  return { resources: [], value };
106002
106224
  }
106003
106225
  const resource = inlineEnvironmentResource2(value, context.path);
@@ -106010,7 +106232,7 @@ function inlineIdentityField() {
106010
106232
  target: "spec",
106011
106233
  merge: (base, override) => mergeValues3(base, override),
106012
106234
  compile: (value, context) => {
106013
- if (!isRecord4(value)) {
106235
+ if (!isRecord5(value)) {
106014
106236
  return { resources: [], value };
106015
106237
  }
106016
106238
  const resource = inlineIdentityResource2(
@@ -106023,7 +106245,7 @@ function inlineIdentityField() {
106023
106245
  };
106024
106246
  }
106025
106247
  function assertAgentAuthoringDocument(document, path2) {
106026
- if (!isRecord4(document) || !("kind" in document)) {
106248
+ if (!isRecord5(document) || !("kind" in document)) {
106027
106249
  return;
106028
106250
  }
106029
106251
  if (document.kind === "session") {
@@ -106201,7 +106423,7 @@ function triggersField() {
106201
106423
  };
106202
106424
  }
106203
106425
  function mountItemKey(item) {
106204
- if (!isRecord4(item)) {
106426
+ if (!isRecord5(item)) {
106205
106427
  return void 0;
106206
106428
  }
106207
106429
  if (typeof item.name === "string") {
@@ -106213,7 +106435,7 @@ function mountItemKey(item) {
106213
106435
  return void 0;
106214
106436
  }
106215
106437
  function triggerItemKey(item) {
106216
- if (!isRecord4(item)) {
106438
+ if (!isRecord5(item)) {
106217
106439
  return void 0;
106218
106440
  }
106219
106441
  if (typeof item.name === "string") {
@@ -106266,7 +106488,7 @@ function removeAuthoringTriggerNames(value) {
106266
106488
  return value;
106267
106489
  }
106268
106490
  return value.map((trigger) => {
106269
- if (!isRecord4(trigger) || !("name" in trigger)) {
106491
+ if (!isRecord5(trigger) || !("name" in trigger)) {
106270
106492
  return trigger;
106271
106493
  }
106272
106494
  const next = { ...trigger };
@@ -106288,7 +106510,7 @@ function namedMapField() {
106288
106510
  target: "spec",
106289
106511
  merge: (base, override) => mergeValues3(base, override),
106290
106512
  remove: (value, names) => {
106291
- if (!isRecord4(value)) {
106513
+ if (!isRecord5(value)) {
106292
106514
  return value;
106293
106515
  }
106294
106516
  const next = { ...value };
@@ -106329,12 +106551,21 @@ var init_scalar = __esm({
106329
106551
  });
106330
106552
 
106331
106553
  // ../../packages/schemas/src/project-apply-files/agent-fields/index.ts
106332
- function parseAgentDraft(document, path2, fileIndex) {
106554
+ function parseAgentDraft(sourceDocument, path2, fileIndex) {
106555
+ const document = sourceDocument.value;
106556
+ if (!isRecord5(document)) {
106557
+ throw new Error(`Invalid agent authoring file ${path2}: expected object`);
106558
+ }
106333
106559
  assertAgentAuthoringDocument(document, path2);
106560
+ assertKnownAgentAuthoringFields(document, sourceDocument, path2);
106334
106561
  const sanitized = sanitizedAgentDocument2(document);
106335
106562
  assertNoLegacyEnvelopeFields(sanitized, path2);
106336
106563
  const draft = emptyAgentDraft();
106337
- draft.sourceLocations = readAgentDraftSourceLocations(path2, fileIndex);
106564
+ draft.sourceLocations = readAgentDraftSourceLocations(
106565
+ path2,
106566
+ fileIndex,
106567
+ sourceDocument.documentIndex
106568
+ );
106338
106569
  for (const [key, value] of Object.entries(sanitized)) {
106339
106570
  if (value === void 0) {
106340
106571
  continue;
@@ -106394,7 +106625,7 @@ function mergeSourceLocations(base, override) {
106394
106625
  continue;
106395
106626
  }
106396
106627
  const prefix = `${target}.${key}`;
106397
- if (!isRecord4(value)) {
106628
+ if (!isRecord5(value)) {
106398
106629
  merged = Object.fromEntries(
106399
106630
  Object.entries(merged).filter(
106400
106631
  ([path2]) => path2 !== prefix && !path2.startsWith(`${prefix}.`)
@@ -106470,10 +106701,36 @@ function supportedRemovalTargets() {
106470
106701
  (key) => AGENT_FIELDS[key]?.remove
106471
106702
  );
106472
106703
  }
106704
+ function assertKnownAgentAuthoringFields(document, sourceDocument, path2) {
106705
+ if (sourceDocument.dialect.kind === "legacy") {
106706
+ return;
106707
+ }
106708
+ const unknownField = Object.keys(document).find(
106709
+ (key) => !AGENT_FIELDS[key] && !CONTROL_FIELDS.has(key)
106710
+ );
106711
+ if (!unknownField) {
106712
+ return;
106713
+ }
106714
+ throw new AutoValidationDiagnosticError(
106715
+ `Invalid agent authoring file ${path2}: unknown field "${unknownField}" for schemaVersion ${sourceDocument.dialect.version}`,
106716
+ autoValidationDiagnostic({
106717
+ code: "auto.validation.authoring.unknown_field",
106718
+ path: [unknownField],
106719
+ location: {
106720
+ ...sourceDocument.topLevelLocations[unknownField] ?? sourceDocument.location,
106721
+ documentIndex: sourceDocument.documentIndex
106722
+ },
106723
+ remediation: {
106724
+ summary: `Remove "${unknownField}" or replace it with a supported Agent authoring field.`
106725
+ }
106726
+ })
106727
+ );
106728
+ }
106473
106729
  var AGENT_FIELDS;
106474
106730
  var init_agent_fields = __esm({
106475
106731
  "../../packages/schemas/src/project-apply-files/agent-fields/index.ts"() {
106476
106732
  "use strict";
106733
+ init_validation_diagnostics();
106477
106734
  init_source();
106478
106735
  init_source_locations();
106479
106736
  init_file_backed_string();
@@ -106522,7 +106779,7 @@ function readVariableScope(document, path2) {
106522
106779
  if (declared === void 0) {
106523
106780
  return /* @__PURE__ */ new Map();
106524
106781
  }
106525
- if (!isRecord4(declared)) {
106782
+ if (!isRecord5(declared)) {
106526
106783
  throw new Error(
106527
106784
  `Invalid variables in ${path2}: variables must be a map of name to value`
106528
106785
  );
@@ -106611,7 +106868,7 @@ function substituteValue(value, scope, site) {
106611
106868
  if (Array.isArray(value)) {
106612
106869
  return value.map((item) => substituteValue(item, scope, site));
106613
106870
  }
106614
- if (isRecord4(value)) {
106871
+ if (isRecord5(value)) {
106615
106872
  return Object.fromEntries(
106616
106873
  Object.entries(value).map(([key, nested]) => [
106617
106874
  key,
@@ -106648,7 +106905,7 @@ function availableNames(scope) {
106648
106905
  }
106649
106906
  function readVariableCondition(value, path2) {
106650
106907
  if (value === void 0) return void 0;
106651
- if (!isRecord4(value) || typeof value.variable !== "string" || value.variable.length === 0 || Object.keys(value).some((key) => key !== "variable")) {
106908
+ if (!isRecord5(value) || typeof value.variable !== "string" || value.variable.length === 0 || Object.keys(value).some((key) => key !== "variable")) {
106652
106909
  throw new Error(
106653
106910
  `Invalid when in ${path2}: expected exactly { variable: <optional variable name> }`
106654
106911
  );
@@ -106673,7 +106930,7 @@ function collectOptionalVariableReferences(value, optional2, found) {
106673
106930
  }
106674
106931
  return;
106675
106932
  }
106676
- if (isRecord4(value)) {
106933
+ if (isRecord5(value)) {
106677
106934
  for (const [key, nested] of Object.entries(value)) {
106678
106935
  if (key !== "templateVariables" && key !== "when") {
106679
106936
  collectOptionalVariableReferences(nested, optional2, found);
@@ -106694,7 +106951,7 @@ var init_template_variables = __esm({
106694
106951
 
106695
106952
  // ../../packages/schemas/src/project-apply-files/agent-authoring.ts
106696
106953
  function readApplyDocument(path2, document, fileIndex, contextVariables) {
106697
- assertAgentAuthoringDocument(document, path2);
106954
+ assertAgentAuthoringDocument(document.value, path2);
106698
106955
  const result = compileAgentDocumentValue(
106699
106956
  document,
106700
106957
  path2,
@@ -106725,7 +106982,8 @@ function readApplyDocument(path2, document, fileIndex, contextVariables) {
106725
106982
  sourcePath: normalizeSourcePath(path2),
106726
106983
  draftLocations: result.sourceLocations,
106727
106984
  authoredTriggers: result.authoredTriggers,
106728
- generatedLocation
106985
+ generatedLocation,
106986
+ documentLocation: document.location
106729
106987
  })
106730
106988
  };
106731
106989
  });
@@ -106739,7 +106997,7 @@ function sourceLocationsForCompiledResource(input) {
106739
106997
  return [
106740
106998
  {
106741
106999
  file: input.sourcePath,
106742
- line: 1,
107000
+ line: input.documentLocation.line,
106743
107001
  kind: input.resource.kind,
106744
107002
  name: input.resource.metadata.name,
106745
107003
  path: "$"
@@ -106774,7 +107032,7 @@ function projectCompiledTriggerSourceLocations(locations, authoredTriggers) {
106774
107032
  );
106775
107033
  let compiledIndex = 0;
106776
107034
  for (const [authoredIndex, trigger] of authoredTriggers.entries()) {
106777
- if (!isRecord4(trigger)) {
107035
+ if (!isRecord5(trigger)) {
106778
107036
  continue;
106779
107037
  }
106780
107038
  const events = authoredTriggerEvents(trigger);
@@ -106835,14 +107093,15 @@ function authoredTriggerDisplayName(trigger, events) {
106835
107093
  }
106836
107094
  return "trigger";
106837
107095
  }
106838
- function validateAgentFragmentDocument(document, path2, context) {
107096
+ function validateAgentFragmentDocument(sourceDocument, path2, context) {
106839
107097
  const normalizedPath = normalizeSourcePath(path2);
106840
107098
  if (context.stack.includes(normalizedPath)) {
106841
107099
  throw new Error(
106842
107100
  `Agent import cycle detected: ${[...context.stack, normalizedPath].join(" -> ")}`
106843
107101
  );
106844
107102
  }
106845
- if (!isRecord4(document)) {
107103
+ const document = sourceDocument.value;
107104
+ if (!isRecord5(document)) {
106846
107105
  throw new Error(`Invalid agent fragment file ${path2}: expected object`);
106847
107106
  }
106848
107107
  const variableContract = readTemplateVariableContract(
@@ -106877,7 +107136,7 @@ function validateAgentFragmentDocument(document, path2, context) {
106877
107136
  for (const removal of removalDirectives2(document, normalizedPath)) {
106878
107137
  assertSupportedAgentRemovalTarget(removal.target);
106879
107138
  }
106880
- parseAgentDraft(document, normalizedPath, context.fileIndex);
107139
+ parseAgentDraft(sourceDocument, normalizedPath, context.fileIndex);
106881
107140
  }
106882
107141
  function dedupeGeneratedResources(records) {
106883
107142
  const recordsByKey = /* @__PURE__ */ new Map();
@@ -106907,16 +107166,16 @@ function conflictingGeneratedResourceMessage(key, existing, record3) {
106907
107166
  const location = existing.sourcePath === record3.sourcePath ? `defined more than once in "${existing.sourcePath}" with different content` : `defined differently in "${existing.sourcePath}" and "${record3.sourcePath}"`;
106908
107167
  return `Conflicting generated resource "${key}" from agent authoring: ${location}. Inline generated resources must be identical when they share a name.`;
106909
107168
  }
106910
- function compileAgentDocumentValue(document, path2, fileIndex, contextVariables) {
107169
+ function compileAgentDocumentValue(sourceDocument, path2, fileIndex, contextVariables) {
106911
107170
  const templateVariableKinds = /* @__PURE__ */ new Map();
106912
107171
  collectTemplateVariableContracts(
106913
- document,
107172
+ sourceDocument,
106914
107173
  path2,
106915
107174
  fileIndex,
106916
107175
  [],
106917
107176
  templateVariableKinds
106918
107177
  );
106919
- const draft = compileAgentDocument2(document, path2, {
107178
+ const draft = compileAgentDocument2(sourceDocument, path2, {
106920
107179
  fileIndex,
106921
107180
  stack: [],
106922
107181
  templateVariableKinds,
@@ -106924,21 +107183,22 @@ function compileAgentDocumentValue(document, path2, fileIndex, contextVariables)
106924
107183
  ...contextVariables && Object.keys(contextVariables).length > 0 ? { contextVariables: new Map(Object.entries(contextVariables)) } : {}
106925
107184
  });
106926
107185
  const authoredTriggers = structuredClone(draft.spec.triggers);
106927
- const removals = isRecord4(document) ? removalDirectives2(document, normalizeSourcePath(path2)) : [];
107186
+ const removals = isRecord5(sourceDocument.value) ? removalDirectives2(sourceDocument.value, normalizeSourcePath(path2)) : [];
106928
107187
  return {
106929
107188
  ...compileAgentDraftResources(draft, path2, removals),
106930
107189
  sourceLocations: draft.sourceLocations,
106931
107190
  authoredTriggers
106932
107191
  };
106933
107192
  }
106934
- function collectTemplateVariableContracts(document, path2, fileIndex, stack, declarations) {
107193
+ function collectTemplateVariableContracts(sourceDocument, path2, fileIndex, stack, declarations) {
106935
107194
  const normalizedPath = normalizeSourcePath(path2);
106936
107195
  if (stack.includes(normalizedPath)) {
106937
107196
  throw new Error(
106938
107197
  `Agent import cycle detected: ${[...stack, normalizedPath].join(" -> ")}`
106939
107198
  );
106940
107199
  }
106941
- if (!isRecord4(document)) {
107200
+ const document = sourceDocument.value;
107201
+ if (!isRecord5(document)) {
106942
107202
  throw new Error(`Invalid agent authoring file ${path2}: expected object`);
106943
107203
  }
106944
107204
  registerTemplateVariableContract(
@@ -106961,14 +107221,15 @@ function collectTemplateVariableContracts(document, path2, fileIndex, stack, dec
106961
107221
  );
106962
107222
  }
106963
107223
  }
106964
- function compileAgentDocument2(document, path2, context) {
107224
+ function compileAgentDocument2(sourceDocument, path2, context) {
106965
107225
  const normalizedPath = normalizeSourcePath(path2);
106966
107226
  if (context.stack.includes(normalizedPath)) {
106967
107227
  throw new Error(
106968
107228
  `Agent import cycle detected: ${[...context.stack, normalizedPath].join(" -> ")}`
106969
107229
  );
106970
107230
  }
106971
- if (!isRecord4(document)) {
107231
+ const document = sourceDocument.value;
107232
+ if (!isRecord5(document)) {
106972
107233
  throw new Error(`Invalid agent authoring file ${path2}: expected object`);
106973
107234
  }
106974
107235
  const variableContract = readTemplateVariableContract(
@@ -107009,13 +107270,13 @@ function compileAgentDocument2(document, path2, context) {
107009
107270
  context.fileIndex
107010
107271
  );
107011
107272
  const rawImportedDocument = readSingleDocument2(imported, context.fileIndex);
107012
- if (!isRecord4(rawImportedDocument)) {
107273
+ if (!isRecord5(rawImportedDocument.value)) {
107013
107274
  throw new Error(
107014
107275
  `Invalid agent authoring file ${imported}: expected object`
107015
107276
  );
107016
107277
  }
107017
107278
  const importedContract = readTemplateVariableContract(
107018
- rawImportedDocument,
107279
+ rawImportedDocument.value,
107019
107280
  imported
107020
107281
  );
107021
107282
  registerTemplateVariableContract(
@@ -107029,20 +107290,19 @@ function compileAgentDocument2(document, path2, context) {
107029
107290
  imported
107030
107291
  );
107031
107292
  if (!includeConditionalTemplateDocument({
107032
- document: rawImportedDocument,
107293
+ document: rawImportedDocument.value,
107033
107294
  declarations: context.templateVariableKinds,
107034
107295
  variables,
107035
107296
  path: imported
107036
107297
  })) {
107037
107298
  continue;
107038
107299
  }
107039
- const importedDocument = substituteVariables(
107040
- rawImportedDocument,
107041
- variables,
107042
- {
107300
+ const importedDocument = {
107301
+ ...rawImportedDocument,
107302
+ value: substituteVariables(rawImportedDocument.value, variables, {
107043
107303
  importPath
107044
- }
107045
- );
107304
+ })
107305
+ };
107046
107306
  merged = mergeAgentDrafts(
107047
107307
  merged,
107048
107308
  compileAgentDocument2(importedDocument, imported, {
@@ -107058,7 +107318,7 @@ function compileAgentDocument2(document, path2, context) {
107058
107318
  }
107059
107319
  return mergeAgentDrafts(
107060
107320
  merged,
107061
- parseAgentDraft(document, normalizedPath, context.fileIndex)
107321
+ parseAgentDraft(sourceDocument, normalizedPath, context.fileIndex)
107062
107322
  );
107063
107323
  }
107064
107324
  var init_agent_authoring = __esm({
@@ -107336,10 +107596,13 @@ function collectInjectableTemplateReferences(files) {
107336
107596
  function hasBuiltInDefaultAgentDocument(files) {
107337
107597
  return files.some((file2) => {
107338
107598
  try {
107339
- return readDocumentsFromSource(file2).some(
107340
- (document) => isRecord4(document) && document.name === BUILT_IN_DEFAULT_AGENT_NAME
107599
+ return readSourceDocuments(file2).some(
107600
+ ({ value }) => isRecord5(value) && value.name === BUILT_IN_DEFAULT_AGENT_NAME
107341
107601
  );
107342
- } catch {
107602
+ } catch (error51) {
107603
+ if (isAuthoredSchemaVersionError(error51)) {
107604
+ throw error51;
107605
+ }
107343
107606
  return false;
107344
107607
  }
107345
107608
  });
@@ -107347,8 +107610,8 @@ function hasBuiltInDefaultAgentDocument(files) {
107347
107610
  function templateImportsInFile(file2) {
107348
107611
  try {
107349
107612
  const specifiers = [];
107350
- for (const document of readDocumentsFromSource(file2)) {
107351
- if (!isRecord4(document)) {
107613
+ for (const { value: document } of readSourceDocuments(file2)) {
107614
+ if (!isRecord5(document)) {
107352
107615
  continue;
107353
107616
  }
107354
107617
  for (const importPath of importPaths2(document)) {
@@ -107358,7 +107621,10 @@ function templateImportsInFile(file2) {
107358
107621
  }
107359
107622
  }
107360
107623
  return specifiers;
107361
- } catch {
107624
+ } catch (error51) {
107625
+ if (isAuthoredSchemaVersionError(error51)) {
107626
+ throw error51;
107627
+ }
107362
107628
  return [];
107363
107629
  }
107364
107630
  }
@@ -107368,6 +107634,7 @@ var init_template_injection = __esm({
107368
107634
  init_default_agent();
107369
107635
  init_templates();
107370
107636
  init_agent_document_merge();
107637
+ init_schema_version();
107371
107638
  init_source();
107372
107639
  }
107373
107640
  });
@@ -107376,6 +107643,7 @@ var init_template_injection = __esm({
107376
107643
  function readProjectApplyDirectorySource(input) {
107377
107644
  const resourceRoot = normalizeSourcePath(input.resourceRoot ?? "");
107378
107645
  const displayResourceRoot2 = input.displayResourceRoot ?? (resourceRoot || ".auto");
107646
+ assertSupportedSourceSchemaVersions(input.files);
107379
107647
  const files = injectManagedTemplateFiles({
107380
107648
  files: input.files,
107381
107649
  registry: defaultTemplateRegistry
@@ -107447,7 +107715,7 @@ function readProjectApplyFileSource(input) {
107447
107715
  }
107448
107716
  function readProjectApplyDocumentSourceFile(file2, options = {}) {
107449
107717
  const fileIndex = options.fileIndex ?? sourceFileIndex([file2]);
107450
- const documents = readDocumentsFromSource(file2);
107718
+ const documents = readSourceDocuments(file2);
107451
107719
  if (documents.length === 0) {
107452
107720
  throw new AutoValidationDiagnosticError(
107453
107721
  `Invalid apply file: ${file2.path} is empty`,
@@ -107461,7 +107729,9 @@ function readProjectApplyDocumentSourceFile(file2, options = {}) {
107461
107729
  );
107462
107730
  }
107463
107731
  if (documents.length === 1) {
107464
- const system = ProjectApplySystemConfigSchema.safeParse(documents[0]);
107732
+ const system = ProjectApplySystemConfigSchema.safeParse(
107733
+ documents[0]?.value
107734
+ );
107465
107735
  if (system.success) {
107466
107736
  return ProjectApplyRequestSchema.parse(system.data.spec);
107467
107737
  }
@@ -107498,13 +107768,13 @@ function readProjectConfigResource(files, resourceRoot) {
107498
107768
  );
107499
107769
  }
107500
107770
  const file2 = configFiles[0];
107501
- const documents = readDocumentsFromSource(file2);
107771
+ const documents = readSourceDocuments(file2);
107502
107772
  if (documents.length > 1) {
107503
107773
  throw new Error(
107504
107774
  `Invalid project config ${file2.path}: expected a single document`
107505
107775
  );
107506
107776
  }
107507
- const parsed = ProjectConfigSpecSchema.safeParse(documents[0] ?? {});
107777
+ const parsed = ProjectConfigSpecSchema.safeParse(documents[0]?.value ?? {});
107508
107778
  if (!parsed.success) {
107509
107779
  throw new AutoValidationDiagnosticError(
107510
107780
  `Invalid project config ${file2.path}: ${parsed.error.message}`,
@@ -107520,6 +107790,20 @@ function readProjectConfigResource(files, resourceRoot) {
107520
107790
  spec: parsed.data
107521
107791
  };
107522
107792
  }
107793
+ function assertSupportedSourceSchemaVersions(files) {
107794
+ for (const file2 of files) {
107795
+ if (!/\.(json|ya?ml)$/i.test(normalizeSourcePath(file2.path))) {
107796
+ continue;
107797
+ }
107798
+ try {
107799
+ readSourceDocuments(file2);
107800
+ } catch (error51) {
107801
+ if (isAuthoredSchemaVersionError(error51)) {
107802
+ throw error51;
107803
+ }
107804
+ }
107805
+ }
107806
+ }
107523
107807
  function assertNoLegacySessionSourceFiles(files, resourceRoot, displayResourceRoot2) {
107524
107808
  const legacyFiles = files.filter(
107525
107809
  (file2) => isResourceFileUnderDirectory(
@@ -107570,7 +107854,7 @@ function assertValidFragmentSourceFiles(files, resourceRoot, fileIndex) {
107570
107854
  );
107571
107855
  for (const file2 of fragments) {
107572
107856
  try {
107573
- const documents = readDocumentsFromSource(file2);
107857
+ const documents = readSourceDocuments(file2);
107574
107858
  if (documents.length !== 1) {
107575
107859
  throw new Error(
107576
107860
  `Agent authoring file ${file2.path} must contain exactly one document`
@@ -107583,6 +107867,9 @@ function assertValidFragmentSourceFiles(files, resourceRoot, fileIndex) {
107583
107867
  variables: /* @__PURE__ */ new Map()
107584
107868
  });
107585
107869
  } catch (error51) {
107870
+ if (isAuthoredSchemaVersionError(error51) || error51 instanceof AutoValidationDiagnosticError && error51.diagnostic.code === "auto.validation.authoring.unknown_field") {
107871
+ throw error51;
107872
+ }
107586
107873
  throw new Error(
107587
107874
  `Invalid fragment file ${file2.path}: ${error51 instanceof Error ? error51.message : String(error51)}`
107588
107875
  );
@@ -107602,6 +107889,7 @@ var init_project_apply_files = __esm({
107602
107889
  init_agent_authoring();
107603
107890
  init_apply_result();
107604
107891
  init_assets();
107892
+ init_schema_version();
107605
107893
  init_source();
107606
107894
  init_source_locations();
107607
107895
  init_template_injection();
@@ -130144,7 +130432,7 @@ async function selectRepository(context, github, explicitRepo) {
130144
130432
  const selection = github.grant.providerResourceSelection;
130145
130433
  if (selection.kind === "selected") {
130146
130434
  const repos = selection.resources.map(
130147
- (resource) => isRecord5(resource) && typeof resource.fullName === "string" ? resource.fullName : void 0
130435
+ (resource) => isRecord6(resource) && typeof resource.fullName === "string" ? resource.fullName : void 0
130148
130436
  ).filter(isDefined);
130149
130437
  if (repos.length === 1) {
130150
130438
  context.writeOutput(`Using GitHub repository ${repos[0]}.`);
@@ -130474,7 +130762,7 @@ function slackWorkspaceUrl(slack) {
130474
130762
  function organizationLabel(organization) {
130475
130763
  return `${organization.organizationName} (${organization.organizationSlug})`;
130476
130764
  }
130477
- function isRecord5(value) {
130765
+ function isRecord6(value) {
130478
130766
  return typeof value === "object" && value !== null && !Array.isArray(value);
130479
130767
  }
130480
130768
  function isDefined(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autohq/cli",
3
- "version": "0.1.677",
3
+ "version": "0.1.678",
4
4
  "license": "SEE LICENSE IN README.md",
5
5
  "publishConfig": {
6
6
  "access": "public"