@andpipes/cli 0.1.0 → 0.1.1

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/bin.cjs CHANGED
@@ -6897,6 +6897,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
6897
6897
  // src/commands/init.ts
6898
6898
  var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
6899
6899
  var PROJECT_SLUG_RE2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
6900
+ var MAX_BOOTSTRAP_CONTRACT_BYTES = 1024 * 1024;
6900
6901
  var PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "suspended", "archived"]);
6901
6902
  var PROJECT_KEYS = [
6902
6903
  "id",
@@ -6919,7 +6920,20 @@ var MANIFEST_KEYS2 = [
6919
6920
  "template_application_commitment"
6920
6921
  ];
6921
6922
  var DEFAULT_INIT_MESSAGES = import_localization7.CLI_MESSAGES.ja.init;
6922
- function assertTemplateInitOptionShape(options) {
6923
+ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES) {
6924
+ if (options.openapi !== void 0 && options.project === void 0) {
6925
+ throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
6926
+ }
6927
+ if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
6928
+ throw new UsageError(messages.optionRequires("--base-url / --service-name", "--openapi"));
6929
+ }
6930
+ if (options.openapi !== void 0 && (options.template !== void 0 || options.contract !== void 0 || options.create === true || options.name !== void 0 || options.slug !== void 0 || options.connector !== void 0 || options.createConnector === true)) {
6931
+ throw new UsageError(
6932
+ messages.incompatibleOptions(
6933
+ "--openapi / --template / --contract / --create / --name / --slug / --connector / --create-connector"
6934
+ )
6935
+ );
6936
+ }
6923
6937
  if (options.template === void 0 && (options.connector !== void 0 || options.createConnector === true)) {
6924
6938
  throw new UsageError("--connector/--create-connector\u306F--template\u3068\u540C\u6642\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
6925
6939
  }
@@ -6935,9 +6949,83 @@ function assertTemplateInitOptionShape(options) {
6935
6949
  throw new UsageError("--template\u306F--contract/--name/--slug/--create\u3068\u4F75\u7528\u3067\u304D\u307E\u305B\u3093");
6936
6950
  }
6937
6951
  }
6952
+ async function materializeOpenApiInit(options, anchor, runtime, messages) {
6953
+ if (options.openapi === void 0) return { options, anchor };
6954
+ const contractPath = "tool-contract.json";
6955
+ prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6956
+ const source = withAnchoredLocalRoot(
6957
+ anchor.root,
6958
+ anchor.rootIdentity,
6959
+ () => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
6960
+ maxBytes: import_tool_contract7.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
6961
+ root: anchor.root
6962
+ })
6963
+ );
6964
+ let imported;
6965
+ try {
6966
+ imported = (0, import_tool_contract7.importOpenApi)(source.text, {
6967
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
6968
+ ...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
6969
+ ...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
6970
+ });
6971
+ } catch (error) {
6972
+ if (error instanceof import_tool_contract7.OpenApiImportError) {
6973
+ throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
6974
+ }
6975
+ throw error;
6976
+ }
6977
+ const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
6978
+ if (blocked.length > 0) {
6979
+ throw new UsageError(
6980
+ `OpenAPI\u751F\u6210\u7D50\u679C\u304Cpublish gate\u3092\u901A\u904E\u3057\u307E\u305B\u3093: ${blocked.map((operation) => operation.toolName).join(", ")}`
6981
+ );
6982
+ }
6983
+ const contracts = imported.operations.map((operation) => operation.contract);
6984
+ const contractText = `${JSON.stringify(contracts.length === 1 ? contracts[0] : { tools: contracts })}
6985
+ `;
6986
+ let createdEntryNlinkDelta = 0;
6987
+ try {
6988
+ createdEntryNlinkDelta = writePrivateFileNoReplace(
6989
+ contractPath,
6990
+ anchor.root,
6991
+ contractText,
6992
+ MAX_BOOTSTRAP_CONTRACT_BYTES,
6993
+ { expectedRootIdentity: anchor.rootIdentity }
6994
+ );
6995
+ } catch (error) {
6996
+ if (!(error instanceof LocalFilePolicyError)) throw error;
6997
+ try {
6998
+ assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "OpenAPI contract fallback");
6999
+ const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
7000
+ maxBytes: MAX_BOOTSTRAP_CONTRACT_BYTES,
7001
+ root: anchor.root,
7002
+ directChildOnly: true
7003
+ });
7004
+ if (existing.text !== contractText) throw error;
7005
+ } catch {
7006
+ throw error;
7007
+ }
7008
+ }
7009
+ const refreshedAnchor = captureLocalRootOrThrow(runtime, anchor.root, messages);
7010
+ if (refreshedAnchor.root !== anchor.root || refreshedAnchor.rootIdentity.dev !== anchor.rootIdentity.dev || refreshedAnchor.rootIdentity.ino !== anchor.rootIdentity.ino || refreshedAnchor.rootIdentity.uid !== anchor.rootIdentity.uid || refreshedAnchor.rootIdentity.mode !== anchor.rootIdentity.mode || refreshedAnchor.rootIdentity.nlink !== anchor.rootIdentity.nlink + createdEntryNlinkDelta) {
7011
+ throw new InitCommandError(
7012
+ "AP_POLICY_DENIED",
7013
+ "local_file_changed",
7014
+ messages.failure("local_file_changed")
7015
+ );
7016
+ }
7017
+ return {
7018
+ options: {
7019
+ project: options.project,
7020
+ contract: contractPath,
7021
+ profile: options.profile
7022
+ },
7023
+ anchor: refreshedAnchor
7024
+ };
7025
+ }
6938
7026
  async function materializeTemplateInit(options, anchor, runtime, messages) {
6939
7027
  if (options.template === void 0) return { options, anchor };
6940
- assertTemplateInitOptionShape(options);
7028
+ assertTemplateInitOptionShape(options, messages);
6941
7029
  const contractPath = "tool-contract.json";
6942
7030
  const initialPlan = prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6943
7031
  const loadArtifact = () => withAnchoredLocalRoot(
@@ -7374,6 +7462,7 @@ function manifestRecoveryError(error, projectId, messages) {
7374
7462
  }
7375
7463
  function throwLocalizedLocalError(error, messages) {
7376
7464
  if (error instanceof InitLocalUsageError) {
7465
+ if (error.reason === "contract_required") throw new UsageError(messages.contractRequired);
7377
7466
  throw new UsageError(messages.failure(error.reason));
7378
7467
  }
7379
7468
  if (error instanceof UsageError) {
@@ -7433,7 +7522,7 @@ function assertIdempotencyKey(value, messages) {
7433
7522
  return canonical;
7434
7523
  }
7435
7524
  async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_INIT_MESSAGES) {
7436
- assertTemplateInitOptionShape(options);
7525
+ assertTemplateInitOptionShape(options, messages);
7437
7526
  if (options.template !== void 0 && options.project === void 0) {
7438
7527
  throw new UsageError("init --template\u306B\u306Fexport\u5143\u3068\u540C\u3058--project <uuid>\u304C\u5FC5\u9808\u3067\u3059");
7439
7528
  }
@@ -7449,6 +7538,10 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7449
7538
  const materialized = await materializeTemplateInit(options, rootAnchor, runtime, messages);
7450
7539
  rootAnchor = materialized.anchor;
7451
7540
  mode = normalizeInitOptions(materialized.options, messages);
7541
+ } else if (options.openapi !== void 0) {
7542
+ const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
7543
+ rootAnchor = materialized.anchor;
7544
+ mode = normalizeInitOptions(materialized.options, messages);
7452
7545
  }
7453
7546
  if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
7454
7547
  let actionMode;
@@ -7474,6 +7567,9 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7474
7567
  actionMode = mode;
7475
7568
  }
7476
7569
  let plan = prepareLocalOrThrow(runtime, rootAnchor, actionMode.contract, messages);
7570
+ if (plan.toolContractCommitment === null) {
7571
+ throw new UsageError(messages.contractRequired);
7572
+ }
7477
7573
  if (actionMode.kind === "create") {
7478
7574
  assertCreateManifestAbsent(plan, messages);
7479
7575
  if (!actionMode.yes) {
@@ -7548,7 +7644,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7548
7644
  }
7549
7645
  function registerInit(program, writer, cwd, createClient, description2 = "Project\u3092\u660E\u793A\u9078\u629E\u307E\u305F\u306F\u4F5C\u6210\u3057\u3001\u5B89\u5168\u306Alocal manifest\u3078bind\u3057\u307E\u3059", runtime = void 0, messages = DEFAULT_INIT_MESSAGES) {
7550
7646
  const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
7551
- program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option(
7647
+ program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option("--openapi <file>", messages.openApiOption).option("--base-url <https-url>", messages.openApiBaseUrlOption).option("--service-name <name>", messages.openApiServiceNameOption).option(
7552
7648
  "--create-connector",
7553
7649
  "Create the template connector through the existing Admin API policy boundary",
7554
7650
  false
package/dist/bin.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  ConfirmationRequiredError,
4
4
  maskSecrets,
5
5
  runCli
6
- } from "./chunk-IVWMNYBA.js";
6
+ } from "./chunk-QPRR3KCS.js";
7
7
  import "./chunk-7LSHSW4Q.js";
8
8
 
9
9
  // src/bin.ts
@@ -5501,7 +5501,10 @@ import { createInterface } from "readline/promises";
5501
5501
  import { CLI_MESSAGES as CLI_MESSAGES6 } from "@andpipes/localization";
5502
5502
  import {
5503
5503
  canonicalizePublicationJson,
5504
- EXTERNAL_SAAS_TEMPLATE_MAX_BYTES
5504
+ EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
5505
+ importOpenApi,
5506
+ OPENAPI_IMPORT_MAX_SOURCE_BYTES,
5507
+ OpenApiImportError
5505
5508
  } from "@andpipes/tool-contract";
5506
5509
 
5507
5510
  // src/lib/init-manifest.ts
@@ -6375,6 +6378,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
6375
6378
  // src/commands/init.ts
6376
6379
  var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
6377
6380
  var PROJECT_SLUG_RE2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
6381
+ var MAX_BOOTSTRAP_CONTRACT_BYTES = 1024 * 1024;
6378
6382
  var PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "suspended", "archived"]);
6379
6383
  var PROJECT_KEYS = [
6380
6384
  "id",
@@ -6397,7 +6401,20 @@ var MANIFEST_KEYS2 = [
6397
6401
  "template_application_commitment"
6398
6402
  ];
6399
6403
  var DEFAULT_INIT_MESSAGES = CLI_MESSAGES6.ja.init;
6400
- function assertTemplateInitOptionShape(options) {
6404
+ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES) {
6405
+ if (options.openapi !== void 0 && options.project === void 0) {
6406
+ throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
6407
+ }
6408
+ if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
6409
+ throw new UsageError(messages.optionRequires("--base-url / --service-name", "--openapi"));
6410
+ }
6411
+ if (options.openapi !== void 0 && (options.template !== void 0 || options.contract !== void 0 || options.create === true || options.name !== void 0 || options.slug !== void 0 || options.connector !== void 0 || options.createConnector === true)) {
6412
+ throw new UsageError(
6413
+ messages.incompatibleOptions(
6414
+ "--openapi / --template / --contract / --create / --name / --slug / --connector / --create-connector"
6415
+ )
6416
+ );
6417
+ }
6401
6418
  if (options.template === void 0 && (options.connector !== void 0 || options.createConnector === true)) {
6402
6419
  throw new UsageError("--connector/--create-connector\u306F--template\u3068\u540C\u6642\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
6403
6420
  }
@@ -6413,9 +6430,83 @@ function assertTemplateInitOptionShape(options) {
6413
6430
  throw new UsageError("--template\u306F--contract/--name/--slug/--create\u3068\u4F75\u7528\u3067\u304D\u307E\u305B\u3093");
6414
6431
  }
6415
6432
  }
6433
+ async function materializeOpenApiInit(options, anchor, runtime, messages) {
6434
+ if (options.openapi === void 0) return { options, anchor };
6435
+ const contractPath = "tool-contract.json";
6436
+ prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6437
+ const source = withAnchoredLocalRoot(
6438
+ anchor.root,
6439
+ anchor.rootIdentity,
6440
+ () => readBoundedLocalFileSnapshot(resolve3(anchor.root, options.openapi), {
6441
+ maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES,
6442
+ root: anchor.root
6443
+ })
6444
+ );
6445
+ let imported;
6446
+ try {
6447
+ imported = importOpenApi(source.text, {
6448
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
6449
+ ...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
6450
+ ...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
6451
+ });
6452
+ } catch (error) {
6453
+ if (error instanceof OpenApiImportError) {
6454
+ throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
6455
+ }
6456
+ throw error;
6457
+ }
6458
+ const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
6459
+ if (blocked.length > 0) {
6460
+ throw new UsageError(
6461
+ `OpenAPI\u751F\u6210\u7D50\u679C\u304Cpublish gate\u3092\u901A\u904E\u3057\u307E\u305B\u3093: ${blocked.map((operation) => operation.toolName).join(", ")}`
6462
+ );
6463
+ }
6464
+ const contracts = imported.operations.map((operation) => operation.contract);
6465
+ const contractText = `${JSON.stringify(contracts.length === 1 ? contracts[0] : { tools: contracts })}
6466
+ `;
6467
+ let createdEntryNlinkDelta = 0;
6468
+ try {
6469
+ createdEntryNlinkDelta = writePrivateFileNoReplace(
6470
+ contractPath,
6471
+ anchor.root,
6472
+ contractText,
6473
+ MAX_BOOTSTRAP_CONTRACT_BYTES,
6474
+ { expectedRootIdentity: anchor.rootIdentity }
6475
+ );
6476
+ } catch (error) {
6477
+ if (!(error instanceof LocalFilePolicyError)) throw error;
6478
+ try {
6479
+ assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "OpenAPI contract fallback");
6480
+ const existing = readBoundedLocalFileSnapshot(resolve3(anchor.root, contractPath), {
6481
+ maxBytes: MAX_BOOTSTRAP_CONTRACT_BYTES,
6482
+ root: anchor.root,
6483
+ directChildOnly: true
6484
+ });
6485
+ if (existing.text !== contractText) throw error;
6486
+ } catch {
6487
+ throw error;
6488
+ }
6489
+ }
6490
+ const refreshedAnchor = captureLocalRootOrThrow(runtime, anchor.root, messages);
6491
+ if (refreshedAnchor.root !== anchor.root || refreshedAnchor.rootIdentity.dev !== anchor.rootIdentity.dev || refreshedAnchor.rootIdentity.ino !== anchor.rootIdentity.ino || refreshedAnchor.rootIdentity.uid !== anchor.rootIdentity.uid || refreshedAnchor.rootIdentity.mode !== anchor.rootIdentity.mode || refreshedAnchor.rootIdentity.nlink !== anchor.rootIdentity.nlink + createdEntryNlinkDelta) {
6492
+ throw new InitCommandError(
6493
+ "AP_POLICY_DENIED",
6494
+ "local_file_changed",
6495
+ messages.failure("local_file_changed")
6496
+ );
6497
+ }
6498
+ return {
6499
+ options: {
6500
+ project: options.project,
6501
+ contract: contractPath,
6502
+ profile: options.profile
6503
+ },
6504
+ anchor: refreshedAnchor
6505
+ };
6506
+ }
6416
6507
  async function materializeTemplateInit(options, anchor, runtime, messages) {
6417
6508
  if (options.template === void 0) return { options, anchor };
6418
- assertTemplateInitOptionShape(options);
6509
+ assertTemplateInitOptionShape(options, messages);
6419
6510
  const contractPath = "tool-contract.json";
6420
6511
  const initialPlan = prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6421
6512
  const loadArtifact = () => withAnchoredLocalRoot(
@@ -6852,6 +6943,7 @@ function manifestRecoveryError(error, projectId, messages) {
6852
6943
  }
6853
6944
  function throwLocalizedLocalError(error, messages) {
6854
6945
  if (error instanceof InitLocalUsageError) {
6946
+ if (error.reason === "contract_required") throw new UsageError(messages.contractRequired);
6855
6947
  throw new UsageError(messages.failure(error.reason));
6856
6948
  }
6857
6949
  if (error instanceof UsageError) {
@@ -6911,7 +7003,7 @@ function assertIdempotencyKey(value, messages) {
6911
7003
  return canonical;
6912
7004
  }
6913
7005
  async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_INIT_MESSAGES) {
6914
- assertTemplateInitOptionShape(options);
7006
+ assertTemplateInitOptionShape(options, messages);
6915
7007
  if (options.template !== void 0 && options.project === void 0) {
6916
7008
  throw new UsageError("init --template\u306B\u306Fexport\u5143\u3068\u540C\u3058--project <uuid>\u304C\u5FC5\u9808\u3067\u3059");
6917
7009
  }
@@ -6927,6 +7019,10 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
6927
7019
  const materialized = await materializeTemplateInit(options, rootAnchor, runtime, messages);
6928
7020
  rootAnchor = materialized.anchor;
6929
7021
  mode = normalizeInitOptions(materialized.options, messages);
7022
+ } else if (options.openapi !== void 0) {
7023
+ const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
7024
+ rootAnchor = materialized.anchor;
7025
+ mode = normalizeInitOptions(materialized.options, messages);
6930
7026
  }
6931
7027
  if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
6932
7028
  let actionMode;
@@ -6952,6 +7048,9 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
6952
7048
  actionMode = mode;
6953
7049
  }
6954
7050
  let plan = prepareLocalOrThrow(runtime, rootAnchor, actionMode.contract, messages);
7051
+ if (plan.toolContractCommitment === null) {
7052
+ throw new UsageError(messages.contractRequired);
7053
+ }
6955
7054
  if (actionMode.kind === "create") {
6956
7055
  assertCreateManifestAbsent(plan, messages);
6957
7056
  if (!actionMode.yes) {
@@ -7026,7 +7125,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7026
7125
  }
7027
7126
  function registerInit(program, writer, cwd, createClient, description2 = "Project\u3092\u660E\u793A\u9078\u629E\u307E\u305F\u306F\u4F5C\u6210\u3057\u3001\u5B89\u5168\u306Alocal manifest\u3078bind\u3057\u307E\u3059", runtime = void 0, messages = DEFAULT_INIT_MESSAGES) {
7028
7127
  const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
7029
- program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option(
7128
+ program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option("--openapi <file>", messages.openApiOption).option("--base-url <https-url>", messages.openApiBaseUrlOption).option("--service-name <name>", messages.openApiServiceNameOption).option(
7030
7129
  "--create-connector",
7031
7130
  "Create the template connector through the existing Admin API policy boundary",
7032
7131
  false
@@ -7258,7 +7357,7 @@ function registerOauth(program, writer, locale = DEFAULT_LOCALE7) {
7258
7357
  // src/commands/openapi.ts
7259
7358
  import { randomUUID as randomUUID6 } from "crypto";
7260
7359
  import { resolve as resolve4 } from "path";
7261
- import { OPENAPI_IMPORT_MAX_SOURCE_BYTES } from "@andpipes/tool-contract";
7360
+ import { OPENAPI_IMPORT_MAX_SOURCE_BYTES as OPENAPI_IMPORT_MAX_SOURCE_BYTES2 } from "@andpipes/tool-contract";
7262
7361
  function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
7263
7362
  return { createClient, idempotencyKey: randomUUID6 };
7264
7363
  }
@@ -7309,7 +7408,7 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
7309
7408
  throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
7310
7409
  }
7311
7410
  const snapshot = readBoundedLocalFileSnapshot(resolve4(cwd, normalized.file), {
7312
- maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES,
7411
+ maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES2,
7313
7412
  root: cwd
7314
7413
  });
7315
7414
  const request = {
package/dist/index.cjs CHANGED
@@ -7043,6 +7043,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
7043
7043
  // src/commands/init.ts
7044
7044
  var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
7045
7045
  var PROJECT_SLUG_RE2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
7046
+ var MAX_BOOTSTRAP_CONTRACT_BYTES = 1024 * 1024;
7046
7047
  var PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "suspended", "archived"]);
7047
7048
  var PROJECT_KEYS = [
7048
7049
  "id",
@@ -7065,7 +7066,20 @@ var MANIFEST_KEYS2 = [
7065
7066
  "template_application_commitment"
7066
7067
  ];
7067
7068
  var DEFAULT_INIT_MESSAGES = import_localization7.CLI_MESSAGES.ja.init;
7068
- function assertTemplateInitOptionShape(options) {
7069
+ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES) {
7070
+ if (options.openapi !== void 0 && options.project === void 0) {
7071
+ throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
7072
+ }
7073
+ if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
7074
+ throw new UsageError(messages.optionRequires("--base-url / --service-name", "--openapi"));
7075
+ }
7076
+ if (options.openapi !== void 0 && (options.template !== void 0 || options.contract !== void 0 || options.create === true || options.name !== void 0 || options.slug !== void 0 || options.connector !== void 0 || options.createConnector === true)) {
7077
+ throw new UsageError(
7078
+ messages.incompatibleOptions(
7079
+ "--openapi / --template / --contract / --create / --name / --slug / --connector / --create-connector"
7080
+ )
7081
+ );
7082
+ }
7069
7083
  if (options.template === void 0 && (options.connector !== void 0 || options.createConnector === true)) {
7070
7084
  throw new UsageError("--connector/--create-connector\u306F--template\u3068\u540C\u6642\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
7071
7085
  }
@@ -7081,9 +7095,83 @@ function assertTemplateInitOptionShape(options) {
7081
7095
  throw new UsageError("--template\u306F--contract/--name/--slug/--create\u3068\u4F75\u7528\u3067\u304D\u307E\u305B\u3093");
7082
7096
  }
7083
7097
  }
7098
+ async function materializeOpenApiInit(options, anchor, runtime, messages) {
7099
+ if (options.openapi === void 0) return { options, anchor };
7100
+ const contractPath = "tool-contract.json";
7101
+ prepareLocalOrThrow(runtime, anchor, contractPath, messages);
7102
+ const source = withAnchoredLocalRoot(
7103
+ anchor.root,
7104
+ anchor.rootIdentity,
7105
+ () => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
7106
+ maxBytes: import_tool_contract7.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
7107
+ root: anchor.root
7108
+ })
7109
+ );
7110
+ let imported;
7111
+ try {
7112
+ imported = (0, import_tool_contract7.importOpenApi)(source.text, {
7113
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
7114
+ ...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
7115
+ ...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
7116
+ });
7117
+ } catch (error) {
7118
+ if (error instanceof import_tool_contract7.OpenApiImportError) {
7119
+ throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
7120
+ }
7121
+ throw error;
7122
+ }
7123
+ const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
7124
+ if (blocked.length > 0) {
7125
+ throw new UsageError(
7126
+ `OpenAPI\u751F\u6210\u7D50\u679C\u304Cpublish gate\u3092\u901A\u904E\u3057\u307E\u305B\u3093: ${blocked.map((operation) => operation.toolName).join(", ")}`
7127
+ );
7128
+ }
7129
+ const contracts = imported.operations.map((operation) => operation.contract);
7130
+ const contractText = `${JSON.stringify(contracts.length === 1 ? contracts[0] : { tools: contracts })}
7131
+ `;
7132
+ let createdEntryNlinkDelta = 0;
7133
+ try {
7134
+ createdEntryNlinkDelta = writePrivateFileNoReplace(
7135
+ contractPath,
7136
+ anchor.root,
7137
+ contractText,
7138
+ MAX_BOOTSTRAP_CONTRACT_BYTES,
7139
+ { expectedRootIdentity: anchor.rootIdentity }
7140
+ );
7141
+ } catch (error) {
7142
+ if (!(error instanceof LocalFilePolicyError)) throw error;
7143
+ try {
7144
+ assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "OpenAPI contract fallback");
7145
+ const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
7146
+ maxBytes: MAX_BOOTSTRAP_CONTRACT_BYTES,
7147
+ root: anchor.root,
7148
+ directChildOnly: true
7149
+ });
7150
+ if (existing.text !== contractText) throw error;
7151
+ } catch {
7152
+ throw error;
7153
+ }
7154
+ }
7155
+ const refreshedAnchor = captureLocalRootOrThrow(runtime, anchor.root, messages);
7156
+ if (refreshedAnchor.root !== anchor.root || refreshedAnchor.rootIdentity.dev !== anchor.rootIdentity.dev || refreshedAnchor.rootIdentity.ino !== anchor.rootIdentity.ino || refreshedAnchor.rootIdentity.uid !== anchor.rootIdentity.uid || refreshedAnchor.rootIdentity.mode !== anchor.rootIdentity.mode || refreshedAnchor.rootIdentity.nlink !== anchor.rootIdentity.nlink + createdEntryNlinkDelta) {
7157
+ throw new InitCommandError(
7158
+ "AP_POLICY_DENIED",
7159
+ "local_file_changed",
7160
+ messages.failure("local_file_changed")
7161
+ );
7162
+ }
7163
+ return {
7164
+ options: {
7165
+ project: options.project,
7166
+ contract: contractPath,
7167
+ profile: options.profile
7168
+ },
7169
+ anchor: refreshedAnchor
7170
+ };
7171
+ }
7084
7172
  async function materializeTemplateInit(options, anchor, runtime, messages) {
7085
7173
  if (options.template === void 0) return { options, anchor };
7086
- assertTemplateInitOptionShape(options);
7174
+ assertTemplateInitOptionShape(options, messages);
7087
7175
  const contractPath = "tool-contract.json";
7088
7176
  const initialPlan = prepareLocalOrThrow(runtime, anchor, contractPath, messages);
7089
7177
  const loadArtifact = () => withAnchoredLocalRoot(
@@ -7520,6 +7608,7 @@ function manifestRecoveryError(error, projectId, messages) {
7520
7608
  }
7521
7609
  function throwLocalizedLocalError(error, messages) {
7522
7610
  if (error instanceof InitLocalUsageError) {
7611
+ if (error.reason === "contract_required") throw new UsageError(messages.contractRequired);
7523
7612
  throw new UsageError(messages.failure(error.reason));
7524
7613
  }
7525
7614
  if (error instanceof UsageError) {
@@ -7579,7 +7668,7 @@ function assertIdempotencyKey(value, messages) {
7579
7668
  return canonical;
7580
7669
  }
7581
7670
  async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_INIT_MESSAGES) {
7582
- assertTemplateInitOptionShape(options);
7671
+ assertTemplateInitOptionShape(options, messages);
7583
7672
  if (options.template !== void 0 && options.project === void 0) {
7584
7673
  throw new UsageError("init --template\u306B\u306Fexport\u5143\u3068\u540C\u3058--project <uuid>\u304C\u5FC5\u9808\u3067\u3059");
7585
7674
  }
@@ -7595,6 +7684,10 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7595
7684
  const materialized = await materializeTemplateInit(options, rootAnchor, runtime, messages);
7596
7685
  rootAnchor = materialized.anchor;
7597
7686
  mode = normalizeInitOptions(materialized.options, messages);
7687
+ } else if (options.openapi !== void 0) {
7688
+ const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
7689
+ rootAnchor = materialized.anchor;
7690
+ mode = normalizeInitOptions(materialized.options, messages);
7598
7691
  }
7599
7692
  if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
7600
7693
  let actionMode;
@@ -7620,6 +7713,9 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7620
7713
  actionMode = mode;
7621
7714
  }
7622
7715
  let plan = prepareLocalOrThrow(runtime, rootAnchor, actionMode.contract, messages);
7716
+ if (plan.toolContractCommitment === null) {
7717
+ throw new UsageError(messages.contractRequired);
7718
+ }
7623
7719
  if (actionMode.kind === "create") {
7624
7720
  assertCreateManifestAbsent(plan, messages);
7625
7721
  if (!actionMode.yes) {
@@ -7694,7 +7790,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7694
7790
  }
7695
7791
  function registerInit(program, writer, cwd, createClient, description2 = "Project\u3092\u660E\u793A\u9078\u629E\u307E\u305F\u306F\u4F5C\u6210\u3057\u3001\u5B89\u5168\u306Alocal manifest\u3078bind\u3057\u307E\u3059", runtime = void 0, messages = DEFAULT_INIT_MESSAGES) {
7696
7792
  const commandRuntime = runtime ?? createInitCommandRuntime(createClient, messages);
7697
- program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option(
7793
+ program.command("init").description(description2).option("--project <project-uuid>", messages.projectOption).option("--create", messages.createOption).option("--name <name>", messages.nameOption).option("--slug <slug>", messages.slugOption).option("--contract <root-file>", messages.contractOption).option("--template <export-file>", "External SaaS template export artifact").option("--openapi <file>", messages.openApiOption).option("--base-url <https-url>", messages.openApiBaseUrlOption).option("--service-name <name>", messages.openApiServiceNameOption).option(
7698
7794
  "--create-connector",
7699
7795
  "Create the template connector through the existing Admin API policy boundary",
7700
7796
  false
package/dist/index.d.cts CHANGED
@@ -383,9 +383,9 @@ declare class InitManifestConflictError extends Error {
383
383
  constructor(message?: string);
384
384
  }
385
385
  declare class InitLocalUsageError extends UsageError {
386
- readonly reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "manifest_invalid";
386
+ readonly reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "contract_required" | "manifest_invalid";
387
387
  readonly code: "AP_INPUT_INVALID";
388
- constructor(reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "manifest_invalid");
388
+ constructor(reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "contract_required" | "manifest_invalid");
389
389
  }
390
390
  /** command開始時のcwd realpath + directory identityを副作用なしで固定する。 */
391
391
  declare const captureInitRoot: (cwd: string) => InitRootAnchor;
@@ -463,6 +463,9 @@ interface InitCommandOptions {
463
463
  readonly slug?: string;
464
464
  readonly contract?: string;
465
465
  readonly template?: string;
466
+ readonly openapi?: string;
467
+ readonly baseUrl?: string;
468
+ readonly serviceName?: string;
466
469
  readonly connector?: string;
467
470
  readonly createConnector?: boolean;
468
471
  readonly profile?: string;
package/dist/index.d.ts CHANGED
@@ -383,9 +383,9 @@ declare class InitManifestConflictError extends Error {
383
383
  constructor(message?: string);
384
384
  }
385
385
  declare class InitLocalUsageError extends UsageError {
386
- readonly reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "manifest_invalid";
386
+ readonly reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "contract_required" | "manifest_invalid";
387
387
  readonly code: "AP_INPUT_INVALID";
388
- constructor(reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "manifest_invalid");
388
+ constructor(reason: "contract_path_invalid" | "contract_candidates_ambiguous" | "contract_required" | "manifest_invalid");
389
389
  }
390
390
  /** command開始時のcwd realpath + directory identityを副作用なしで固定する。 */
391
391
  declare const captureInitRoot: (cwd: string) => InitRootAnchor;
@@ -463,6 +463,9 @@ interface InitCommandOptions {
463
463
  readonly slug?: string;
464
464
  readonly contract?: string;
465
465
  readonly template?: string;
466
+ readonly openapi?: string;
467
+ readonly baseUrl?: string;
468
+ readonly serviceName?: string;
466
469
  readonly connector?: string;
467
470
  readonly createConnector?: boolean;
468
471
  readonly profile?: string;
package/dist/index.js CHANGED
@@ -96,7 +96,7 @@ import {
96
96
  validateContract,
97
97
  validateOAuthMetadata,
98
98
  writeInitManifestNoReplace
99
- } from "./chunk-IVWMNYBA.js";
99
+ } from "./chunk-QPRR3KCS.js";
100
100
  import "./chunk-7LSHSW4Q.js";
101
101
  export {
102
102
  ADMIN_API_MAX_GET_ATTEMPTS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andpipes/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "andpipe CLI — Brand MCP Gateway / OAuth Broker / Tool Contract Platform の init / dev / validate / publish を提供する公式 CLI",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "commander": "^14.0.0",
43
- "@andpipes/tool-contract": "0.1.0",
44
- "@andpipes/localization": "0.1.0",
43
+ "@andpipes/localization": "0.1.1",
44
+ "@andpipes/tool-contract": "0.1.1",
45
45
  "@andpipes/mcp-adapter": "0.0.0"
46
46
  },
47
47
  "devDependencies": {