@andpipes/cli 0.1.0 → 0.1.2

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
@@ -3672,6 +3672,41 @@ async function loginAdminCli(input = {}) {
3672
3672
  }
3673
3673
  }
3674
3674
 
3675
+ // src/lib/open-browser.ts
3676
+ var import_node_child_process = require("child_process");
3677
+ function browserCommandForPlatform(verificationUri, platform = process.platform) {
3678
+ if (platform === "darwin") {
3679
+ return { command: "open", args: [verificationUri] };
3680
+ }
3681
+ if (platform === "win32") {
3682
+ return {
3683
+ command: "rundll32",
3684
+ args: ["url.dll,FileProtocolHandler", verificationUri]
3685
+ };
3686
+ }
3687
+ if (platform === "linux") {
3688
+ return { command: "xdg-open", args: [verificationUri] };
3689
+ }
3690
+ return null;
3691
+ }
3692
+ function openBrowser(verificationUri) {
3693
+ const browserCommand = browserCommandForPlatform(verificationUri);
3694
+ if (!browserCommand) return false;
3695
+ try {
3696
+ const child = (0, import_node_child_process.spawn)(browserCommand.command, [...browserCommand.args], {
3697
+ detached: true,
3698
+ shell: false,
3699
+ stdio: "ignore",
3700
+ windowsHide: true
3701
+ });
3702
+ child.once("error", () => void 0);
3703
+ child.unref();
3704
+ return true;
3705
+ } catch {
3706
+ return false;
3707
+ }
3708
+ }
3709
+
3675
3710
  // src/commands/auth.ts
3676
3711
  function explicitScopes(value) {
3677
3712
  if (value === void 0) return void 0;
@@ -3684,12 +3719,15 @@ function explicitScopes(value) {
3684
3719
  }
3685
3720
  return scopes;
3686
3721
  }
3687
- function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE) {
3722
+ function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE, dependencies = {}) {
3688
3723
  const text = import_localization2.LOCALIZED_TEXT[locale].cli;
3689
3724
  const messages = import_localization2.CLI_MESSAGES[locale];
3690
3725
  program.command("login").description(
3691
3726
  locale === "ja" ? "Web Admin\u627F\u8A8D\u3067Admin CLI\u3078\u30ED\u30B0\u30A4\u30F3" : "Sign in to the Admin CLI through Web Admin approval"
3692
- ).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).action(async (opts) => {
3727
+ ).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).option(
3728
+ "--no-browser",
3729
+ locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u81EA\u52D5\u8D77\u52D5\u305B\u305A\u3001\u627F\u8A8DURL\u3060\u3051\u3092\u8868\u793A" : "Print the approval URL without opening the default browser"
3730
+ ).action(async (opts) => {
3693
3731
  const record = await loginAdminCli({
3694
3732
  profile: opts.profile,
3695
3733
  requestedScopes: explicitScopes(opts.scope),
@@ -3698,6 +3736,12 @@ function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOC
3698
3736
  writer,
3699
3737
  locale === "ja" ? `Web Admin\u3067\u627F\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044: ${verificationUri}` : `Approve this request in Web Admin: ${verificationUri}`
3700
3738
  );
3739
+ if (opts.browser) {
3740
+ try {
3741
+ (dependencies.openBrowser ?? openBrowser)(verificationUri);
3742
+ } catch {
3743
+ }
3744
+ }
3701
3745
  },
3702
3746
  onUserCode: (userCode) => {
3703
3747
  interactive(
@@ -5408,7 +5452,7 @@ function loadDevProject(cwd, runtime = {}) {
5408
5452
  }
5409
5453
 
5410
5454
  // src/lib/dev-tunnel.ts
5411
- var import_node_child_process = require("child_process");
5455
+ var import_node_child_process2 = require("child_process");
5412
5456
  var import_node_fs7 = require("fs");
5413
5457
  var import_node_path7 = require("path");
5414
5458
  var QUICK_TUNNEL_PROVIDER = "cloudflare-quick";
@@ -5475,7 +5519,7 @@ async function terminateKnownProcessGroup(pgid, runtime = defaultProcessGroupRun
5475
5519
  var defaultParentTunnelRuntime = {
5476
5520
  ...defaultProcessGroupRuntime,
5477
5521
  forkSupervisor(modulePath, args, options) {
5478
- return (0, import_node_child_process.fork)(modulePath, [...args], {
5522
+ return (0, import_node_child_process2.fork)(modulePath, [...args], {
5479
5523
  detached: options.detached,
5480
5524
  execArgv: [...options.execArgv],
5481
5525
  stdio: [...options.stdio]
@@ -5569,7 +5613,7 @@ async function startCloudflareQuickTunnel(input, runtime = defaultParentTunnelRu
5569
5613
  }
5570
5614
  var defaultSupervisorRuntime = {
5571
5615
  spawn(file, args, options) {
5572
- return (0, import_node_child_process.spawn)(file, [...args], {
5616
+ return (0, import_node_child_process2.spawn)(file, [...args], {
5573
5617
  shell: options.shell,
5574
5618
  detached: options.detached,
5575
5619
  stdio: [...options.stdio]
@@ -6897,6 +6941,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
6897
6941
  // src/commands/init.ts
6898
6942
  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
6943
  var PROJECT_SLUG_RE2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
6944
+ var MAX_BOOTSTRAP_CONTRACT_BYTES = 1024 * 1024;
6900
6945
  var PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "suspended", "archived"]);
6901
6946
  var PROJECT_KEYS = [
6902
6947
  "id",
@@ -6919,7 +6964,20 @@ var MANIFEST_KEYS2 = [
6919
6964
  "template_application_commitment"
6920
6965
  ];
6921
6966
  var DEFAULT_INIT_MESSAGES = import_localization7.CLI_MESSAGES.ja.init;
6922
- function assertTemplateInitOptionShape(options) {
6967
+ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES) {
6968
+ if (options.openapi !== void 0 && options.project === void 0) {
6969
+ throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
6970
+ }
6971
+ if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
6972
+ throw new UsageError(messages.optionRequires("--base-url / --service-name", "--openapi"));
6973
+ }
6974
+ 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)) {
6975
+ throw new UsageError(
6976
+ messages.incompatibleOptions(
6977
+ "--openapi / --template / --contract / --create / --name / --slug / --connector / --create-connector"
6978
+ )
6979
+ );
6980
+ }
6923
6981
  if (options.template === void 0 && (options.connector !== void 0 || options.createConnector === true)) {
6924
6982
  throw new UsageError("--connector/--create-connector\u306F--template\u3068\u540C\u6642\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
6925
6983
  }
@@ -6935,9 +6993,83 @@ function assertTemplateInitOptionShape(options) {
6935
6993
  throw new UsageError("--template\u306F--contract/--name/--slug/--create\u3068\u4F75\u7528\u3067\u304D\u307E\u305B\u3093");
6936
6994
  }
6937
6995
  }
6996
+ async function materializeOpenApiInit(options, anchor, runtime, messages) {
6997
+ if (options.openapi === void 0) return { options, anchor };
6998
+ const contractPath = "tool-contract.json";
6999
+ prepareLocalOrThrow(runtime, anchor, contractPath, messages);
7000
+ const source = withAnchoredLocalRoot(
7001
+ anchor.root,
7002
+ anchor.rootIdentity,
7003
+ () => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
7004
+ maxBytes: import_tool_contract7.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
7005
+ root: anchor.root
7006
+ })
7007
+ );
7008
+ let imported;
7009
+ try {
7010
+ imported = (0, import_tool_contract7.importOpenApi)(source.text, {
7011
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
7012
+ ...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
7013
+ ...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
7014
+ });
7015
+ } catch (error) {
7016
+ if (error instanceof import_tool_contract7.OpenApiImportError) {
7017
+ throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
7018
+ }
7019
+ throw error;
7020
+ }
7021
+ const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
7022
+ if (blocked.length > 0) {
7023
+ throw new UsageError(
7024
+ `OpenAPI\u751F\u6210\u7D50\u679C\u304Cpublish gate\u3092\u901A\u904E\u3057\u307E\u305B\u3093: ${blocked.map((operation) => operation.toolName).join(", ")}`
7025
+ );
7026
+ }
7027
+ const contracts = imported.operations.map((operation) => operation.contract);
7028
+ const contractText = `${JSON.stringify(contracts.length === 1 ? contracts[0] : { tools: contracts })}
7029
+ `;
7030
+ let createdEntryNlinkDelta = 0;
7031
+ try {
7032
+ createdEntryNlinkDelta = writePrivateFileNoReplace(
7033
+ contractPath,
7034
+ anchor.root,
7035
+ contractText,
7036
+ MAX_BOOTSTRAP_CONTRACT_BYTES,
7037
+ { expectedRootIdentity: anchor.rootIdentity }
7038
+ );
7039
+ } catch (error) {
7040
+ if (!(error instanceof LocalFilePolicyError)) throw error;
7041
+ try {
7042
+ assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "OpenAPI contract fallback");
7043
+ const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
7044
+ maxBytes: MAX_BOOTSTRAP_CONTRACT_BYTES,
7045
+ root: anchor.root,
7046
+ directChildOnly: true
7047
+ });
7048
+ if (existing.text !== contractText) throw error;
7049
+ } catch {
7050
+ throw error;
7051
+ }
7052
+ }
7053
+ const refreshedAnchor = captureLocalRootOrThrow(runtime, anchor.root, messages);
7054
+ 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) {
7055
+ throw new InitCommandError(
7056
+ "AP_POLICY_DENIED",
7057
+ "local_file_changed",
7058
+ messages.failure("local_file_changed")
7059
+ );
7060
+ }
7061
+ return {
7062
+ options: {
7063
+ project: options.project,
7064
+ contract: contractPath,
7065
+ profile: options.profile
7066
+ },
7067
+ anchor: refreshedAnchor
7068
+ };
7069
+ }
6938
7070
  async function materializeTemplateInit(options, anchor, runtime, messages) {
6939
7071
  if (options.template === void 0) return { options, anchor };
6940
- assertTemplateInitOptionShape(options);
7072
+ assertTemplateInitOptionShape(options, messages);
6941
7073
  const contractPath = "tool-contract.json";
6942
7074
  const initialPlan = prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6943
7075
  const loadArtifact = () => withAnchoredLocalRoot(
@@ -7374,6 +7506,7 @@ function manifestRecoveryError(error, projectId, messages) {
7374
7506
  }
7375
7507
  function throwLocalizedLocalError(error, messages) {
7376
7508
  if (error instanceof InitLocalUsageError) {
7509
+ if (error.reason === "contract_required") throw new UsageError(messages.contractRequired);
7377
7510
  throw new UsageError(messages.failure(error.reason));
7378
7511
  }
7379
7512
  if (error instanceof UsageError) {
@@ -7433,7 +7566,7 @@ function assertIdempotencyKey(value, messages) {
7433
7566
  return canonical;
7434
7567
  }
7435
7568
  async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_INIT_MESSAGES) {
7436
- assertTemplateInitOptionShape(options);
7569
+ assertTemplateInitOptionShape(options, messages);
7437
7570
  if (options.template !== void 0 && options.project === void 0) {
7438
7571
  throw new UsageError("init --template\u306B\u306Fexport\u5143\u3068\u540C\u3058--project <uuid>\u304C\u5FC5\u9808\u3067\u3059");
7439
7572
  }
@@ -7449,6 +7582,10 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7449
7582
  const materialized = await materializeTemplateInit(options, rootAnchor, runtime, messages);
7450
7583
  rootAnchor = materialized.anchor;
7451
7584
  mode = normalizeInitOptions(materialized.options, messages);
7585
+ } else if (options.openapi !== void 0) {
7586
+ const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
7587
+ rootAnchor = materialized.anchor;
7588
+ mode = normalizeInitOptions(materialized.options, messages);
7452
7589
  }
7453
7590
  if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
7454
7591
  let actionMode;
@@ -7474,6 +7611,9 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7474
7611
  actionMode = mode;
7475
7612
  }
7476
7613
  let plan = prepareLocalOrThrow(runtime, rootAnchor, actionMode.contract, messages);
7614
+ if (plan.toolContractCommitment === null) {
7615
+ throw new UsageError(messages.contractRequired);
7616
+ }
7477
7617
  if (actionMode.kind === "create") {
7478
7618
  assertCreateManifestAbsent(plan, messages);
7479
7619
  if (!actionMode.yes) {
@@ -7548,7 +7688,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7548
7688
  }
7549
7689
  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
7690
  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(
7691
+ 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
7692
  "--create-connector",
7553
7693
  "Create the template connector through the existing Admin API policy boundary",
7554
7694
  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-ELZTOEAZ.js";
7
7
  import "./chunk-7LSHSW4Q.js";
8
8
 
9
9
  // src/bin.ts
@@ -3757,6 +3757,41 @@ async function loginAdminCli(input = {}) {
3757
3757
  }
3758
3758
  }
3759
3759
 
3760
+ // src/lib/open-browser.ts
3761
+ import { spawn } from "child_process";
3762
+ function browserCommandForPlatform(verificationUri, platform = process.platform) {
3763
+ if (platform === "darwin") {
3764
+ return { command: "open", args: [verificationUri] };
3765
+ }
3766
+ if (platform === "win32") {
3767
+ return {
3768
+ command: "rundll32",
3769
+ args: ["url.dll,FileProtocolHandler", verificationUri]
3770
+ };
3771
+ }
3772
+ if (platform === "linux") {
3773
+ return { command: "xdg-open", args: [verificationUri] };
3774
+ }
3775
+ return null;
3776
+ }
3777
+ function openBrowser(verificationUri) {
3778
+ const browserCommand = browserCommandForPlatform(verificationUri);
3779
+ if (!browserCommand) return false;
3780
+ try {
3781
+ const child = spawn(browserCommand.command, [...browserCommand.args], {
3782
+ detached: true,
3783
+ shell: false,
3784
+ stdio: "ignore",
3785
+ windowsHide: true
3786
+ });
3787
+ child.once("error", () => void 0);
3788
+ child.unref();
3789
+ return true;
3790
+ } catch {
3791
+ return false;
3792
+ }
3793
+ }
3794
+
3760
3795
  // src/commands/auth.ts
3761
3796
  function explicitScopes(value) {
3762
3797
  if (value === void 0) return void 0;
@@ -3769,12 +3804,15 @@ function explicitScopes(value) {
3769
3804
  }
3770
3805
  return scopes;
3771
3806
  }
3772
- function registerAuth(program, writer, locale = DEFAULT_LOCALE2) {
3807
+ function registerAuth(program, writer, locale = DEFAULT_LOCALE2, dependencies = {}) {
3773
3808
  const text = LOCALIZED_TEXT[locale].cli;
3774
3809
  const messages = CLI_MESSAGES[locale];
3775
3810
  program.command("login").description(
3776
3811
  locale === "ja" ? "Web Admin\u627F\u8A8D\u3067Admin CLI\u3078\u30ED\u30B0\u30A4\u30F3" : "Sign in to the Admin CLI through Web Admin approval"
3777
- ).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).action(async (opts) => {
3812
+ ).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).option(
3813
+ "--no-browser",
3814
+ locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u81EA\u52D5\u8D77\u52D5\u305B\u305A\u3001\u627F\u8A8DURL\u3060\u3051\u3092\u8868\u793A" : "Print the approval URL without opening the default browser"
3815
+ ).action(async (opts) => {
3778
3816
  const record = await loginAdminCli({
3779
3817
  profile: opts.profile,
3780
3818
  requestedScopes: explicitScopes(opts.scope),
@@ -3783,6 +3821,12 @@ function registerAuth(program, writer, locale = DEFAULT_LOCALE2) {
3783
3821
  writer,
3784
3822
  locale === "ja" ? `Web Admin\u3067\u627F\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044: ${verificationUri}` : `Approve this request in Web Admin: ${verificationUri}`
3785
3823
  );
3824
+ if (opts.browser) {
3825
+ try {
3826
+ (dependencies.openBrowser ?? openBrowser)(verificationUri);
3827
+ } catch {
3828
+ }
3829
+ }
3786
3830
  },
3787
3831
  onUserCode: (userCode) => {
3788
3832
  interactive(
@@ -5501,7 +5545,10 @@ import { createInterface } from "readline/promises";
5501
5545
  import { CLI_MESSAGES as CLI_MESSAGES6 } from "@andpipes/localization";
5502
5546
  import {
5503
5547
  canonicalizePublicationJson,
5504
- EXTERNAL_SAAS_TEMPLATE_MAX_BYTES
5548
+ EXTERNAL_SAAS_TEMPLATE_MAX_BYTES,
5549
+ importOpenApi,
5550
+ OPENAPI_IMPORT_MAX_SOURCE_BYTES,
5551
+ OpenApiImportError
5505
5552
  } from "@andpipes/tool-contract";
5506
5553
 
5507
5554
  // src/lib/init-manifest.ts
@@ -6375,6 +6422,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
6375
6422
  // src/commands/init.ts
6376
6423
  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
6424
  var PROJECT_SLUG_RE2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
6425
+ var MAX_BOOTSTRAP_CONTRACT_BYTES = 1024 * 1024;
6378
6426
  var PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "suspended", "archived"]);
6379
6427
  var PROJECT_KEYS = [
6380
6428
  "id",
@@ -6397,7 +6445,20 @@ var MANIFEST_KEYS2 = [
6397
6445
  "template_application_commitment"
6398
6446
  ];
6399
6447
  var DEFAULT_INIT_MESSAGES = CLI_MESSAGES6.ja.init;
6400
- function assertTemplateInitOptionShape(options) {
6448
+ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES) {
6449
+ if (options.openapi !== void 0 && options.project === void 0) {
6450
+ throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
6451
+ }
6452
+ if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
6453
+ throw new UsageError(messages.optionRequires("--base-url / --service-name", "--openapi"));
6454
+ }
6455
+ 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)) {
6456
+ throw new UsageError(
6457
+ messages.incompatibleOptions(
6458
+ "--openapi / --template / --contract / --create / --name / --slug / --connector / --create-connector"
6459
+ )
6460
+ );
6461
+ }
6401
6462
  if (options.template === void 0 && (options.connector !== void 0 || options.createConnector === true)) {
6402
6463
  throw new UsageError("--connector/--create-connector\u306F--template\u3068\u540C\u6642\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
6403
6464
  }
@@ -6413,9 +6474,83 @@ function assertTemplateInitOptionShape(options) {
6413
6474
  throw new UsageError("--template\u306F--contract/--name/--slug/--create\u3068\u4F75\u7528\u3067\u304D\u307E\u305B\u3093");
6414
6475
  }
6415
6476
  }
6477
+ async function materializeOpenApiInit(options, anchor, runtime, messages) {
6478
+ if (options.openapi === void 0) return { options, anchor };
6479
+ const contractPath = "tool-contract.json";
6480
+ prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6481
+ const source = withAnchoredLocalRoot(
6482
+ anchor.root,
6483
+ anchor.rootIdentity,
6484
+ () => readBoundedLocalFileSnapshot(resolve3(anchor.root, options.openapi), {
6485
+ maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES,
6486
+ root: anchor.root
6487
+ })
6488
+ );
6489
+ let imported;
6490
+ try {
6491
+ imported = importOpenApi(source.text, {
6492
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
6493
+ ...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
6494
+ ...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
6495
+ });
6496
+ } catch (error) {
6497
+ if (error instanceof OpenApiImportError) {
6498
+ throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
6499
+ }
6500
+ throw error;
6501
+ }
6502
+ const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
6503
+ if (blocked.length > 0) {
6504
+ throw new UsageError(
6505
+ `OpenAPI\u751F\u6210\u7D50\u679C\u304Cpublish gate\u3092\u901A\u904E\u3057\u307E\u305B\u3093: ${blocked.map((operation) => operation.toolName).join(", ")}`
6506
+ );
6507
+ }
6508
+ const contracts = imported.operations.map((operation) => operation.contract);
6509
+ const contractText = `${JSON.stringify(contracts.length === 1 ? contracts[0] : { tools: contracts })}
6510
+ `;
6511
+ let createdEntryNlinkDelta = 0;
6512
+ try {
6513
+ createdEntryNlinkDelta = writePrivateFileNoReplace(
6514
+ contractPath,
6515
+ anchor.root,
6516
+ contractText,
6517
+ MAX_BOOTSTRAP_CONTRACT_BYTES,
6518
+ { expectedRootIdentity: anchor.rootIdentity }
6519
+ );
6520
+ } catch (error) {
6521
+ if (!(error instanceof LocalFilePolicyError)) throw error;
6522
+ try {
6523
+ assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "OpenAPI contract fallback");
6524
+ const existing = readBoundedLocalFileSnapshot(resolve3(anchor.root, contractPath), {
6525
+ maxBytes: MAX_BOOTSTRAP_CONTRACT_BYTES,
6526
+ root: anchor.root,
6527
+ directChildOnly: true
6528
+ });
6529
+ if (existing.text !== contractText) throw error;
6530
+ } catch {
6531
+ throw error;
6532
+ }
6533
+ }
6534
+ const refreshedAnchor = captureLocalRootOrThrow(runtime, anchor.root, messages);
6535
+ 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) {
6536
+ throw new InitCommandError(
6537
+ "AP_POLICY_DENIED",
6538
+ "local_file_changed",
6539
+ messages.failure("local_file_changed")
6540
+ );
6541
+ }
6542
+ return {
6543
+ options: {
6544
+ project: options.project,
6545
+ contract: contractPath,
6546
+ profile: options.profile
6547
+ },
6548
+ anchor: refreshedAnchor
6549
+ };
6550
+ }
6416
6551
  async function materializeTemplateInit(options, anchor, runtime, messages) {
6417
6552
  if (options.template === void 0) return { options, anchor };
6418
- assertTemplateInitOptionShape(options);
6553
+ assertTemplateInitOptionShape(options, messages);
6419
6554
  const contractPath = "tool-contract.json";
6420
6555
  const initialPlan = prepareLocalOrThrow(runtime, anchor, contractPath, messages);
6421
6556
  const loadArtifact = () => withAnchoredLocalRoot(
@@ -6852,6 +6987,7 @@ function manifestRecoveryError(error, projectId, messages) {
6852
6987
  }
6853
6988
  function throwLocalizedLocalError(error, messages) {
6854
6989
  if (error instanceof InitLocalUsageError) {
6990
+ if (error.reason === "contract_required") throw new UsageError(messages.contractRequired);
6855
6991
  throw new UsageError(messages.failure(error.reason));
6856
6992
  }
6857
6993
  if (error instanceof UsageError) {
@@ -6911,7 +7047,7 @@ function assertIdempotencyKey(value, messages) {
6911
7047
  return canonical;
6912
7048
  }
6913
7049
  async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_INIT_MESSAGES) {
6914
- assertTemplateInitOptionShape(options);
7050
+ assertTemplateInitOptionShape(options, messages);
6915
7051
  if (options.template !== void 0 && options.project === void 0) {
6916
7052
  throw new UsageError("init --template\u306B\u306Fexport\u5143\u3068\u540C\u3058--project <uuid>\u304C\u5FC5\u9808\u3067\u3059");
6917
7053
  }
@@ -6927,6 +7063,10 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
6927
7063
  const materialized = await materializeTemplateInit(options, rootAnchor, runtime, messages);
6928
7064
  rootAnchor = materialized.anchor;
6929
7065
  mode = normalizeInitOptions(materialized.options, messages);
7066
+ } else if (options.openapi !== void 0) {
7067
+ const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
7068
+ rootAnchor = materialized.anchor;
7069
+ mode = normalizeInitOptions(materialized.options, messages);
6930
7070
  }
6931
7071
  if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
6932
7072
  let actionMode;
@@ -6952,6 +7092,9 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
6952
7092
  actionMode = mode;
6953
7093
  }
6954
7094
  let plan = prepareLocalOrThrow(runtime, rootAnchor, actionMode.contract, messages);
7095
+ if (plan.toolContractCommitment === null) {
7096
+ throw new UsageError(messages.contractRequired);
7097
+ }
6955
7098
  if (actionMode.kind === "create") {
6956
7099
  assertCreateManifestAbsent(plan, messages);
6957
7100
  if (!actionMode.yes) {
@@ -7026,7 +7169,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7026
7169
  }
7027
7170
  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
7171
  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(
7172
+ 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
7173
  "--create-connector",
7031
7174
  "Create the template connector through the existing Admin API policy boundary",
7032
7175
  false
@@ -7258,7 +7401,7 @@ function registerOauth(program, writer, locale = DEFAULT_LOCALE7) {
7258
7401
  // src/commands/openapi.ts
7259
7402
  import { randomUUID as randomUUID6 } from "crypto";
7260
7403
  import { resolve as resolve4 } from "path";
7261
- import { OPENAPI_IMPORT_MAX_SOURCE_BYTES } from "@andpipes/tool-contract";
7404
+ import { OPENAPI_IMPORT_MAX_SOURCE_BYTES as OPENAPI_IMPORT_MAX_SOURCE_BYTES2 } from "@andpipes/tool-contract";
7262
7405
  function createOpenApiImportRuntime(createClient = (profile) => createAdminApiClient({ profile })) {
7263
7406
  return { createClient, idempotencyKey: randomUUID6 };
7264
7407
  }
@@ -7309,7 +7452,7 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
7309
7452
  throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
7310
7453
  }
7311
7454
  const snapshot = readBoundedLocalFileSnapshot(resolve4(cwd, normalized.file), {
7312
- maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES,
7455
+ maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES2,
7313
7456
  root: cwd
7314
7457
  });
7315
7458
  const request = {
package/dist/index.cjs CHANGED
@@ -3818,6 +3818,41 @@ async function loginAdminCli(input = {}) {
3818
3818
  }
3819
3819
  }
3820
3820
 
3821
+ // src/lib/open-browser.ts
3822
+ var import_node_child_process = require("child_process");
3823
+ function browserCommandForPlatform(verificationUri, platform = process.platform) {
3824
+ if (platform === "darwin") {
3825
+ return { command: "open", args: [verificationUri] };
3826
+ }
3827
+ if (platform === "win32") {
3828
+ return {
3829
+ command: "rundll32",
3830
+ args: ["url.dll,FileProtocolHandler", verificationUri]
3831
+ };
3832
+ }
3833
+ if (platform === "linux") {
3834
+ return { command: "xdg-open", args: [verificationUri] };
3835
+ }
3836
+ return null;
3837
+ }
3838
+ function openBrowser(verificationUri) {
3839
+ const browserCommand = browserCommandForPlatform(verificationUri);
3840
+ if (!browserCommand) return false;
3841
+ try {
3842
+ const child = (0, import_node_child_process.spawn)(browserCommand.command, [...browserCommand.args], {
3843
+ detached: true,
3844
+ shell: false,
3845
+ stdio: "ignore",
3846
+ windowsHide: true
3847
+ });
3848
+ child.once("error", () => void 0);
3849
+ child.unref();
3850
+ return true;
3851
+ } catch {
3852
+ return false;
3853
+ }
3854
+ }
3855
+
3821
3856
  // src/commands/auth.ts
3822
3857
  function explicitScopes(value) {
3823
3858
  if (value === void 0) return void 0;
@@ -3830,12 +3865,15 @@ function explicitScopes(value) {
3830
3865
  }
3831
3866
  return scopes;
3832
3867
  }
3833
- function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE) {
3868
+ function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOCALE, dependencies = {}) {
3834
3869
  const text = import_localization2.LOCALIZED_TEXT[locale].cli;
3835
3870
  const messages = import_localization2.CLI_MESSAGES[locale];
3836
3871
  program.command("login").description(
3837
3872
  locale === "ja" ? "Web Admin\u627F\u8A8D\u3067Admin CLI\u3078\u30ED\u30B0\u30A4\u30F3" : "Sign in to the Admin CLI through Web Admin approval"
3838
- ).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).action(async (opts) => {
3873
+ ).option("--scope <scopes>", "\u8981\u6C42\u3059\u308BAdmin CLI scope\uFF08\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u6A29\u9650\u306F\u3053\u3053\u3067\u660E\u793A\u6307\u5B9A\uFF09").option("--profile <name>", messages.common.profileDestinationOption, DEFAULT_PROFILE_NAME).option(
3874
+ "--no-browser",
3875
+ locale === "ja" ? "\u65E2\u5B9A\u30D6\u30E9\u30A6\u30B6\u3092\u81EA\u52D5\u8D77\u52D5\u305B\u305A\u3001\u627F\u8A8DURL\u3060\u3051\u3092\u8868\u793A" : "Print the approval URL without opening the default browser"
3876
+ ).action(async (opts) => {
3839
3877
  const record = await loginAdminCli({
3840
3878
  profile: opts.profile,
3841
3879
  requestedScopes: explicitScopes(opts.scope),
@@ -3844,6 +3882,12 @@ function registerAuth(program, writer, locale = import_localization2.DEFAULT_LOC
3844
3882
  writer,
3845
3883
  locale === "ja" ? `Web Admin\u3067\u627F\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044: ${verificationUri}` : `Approve this request in Web Admin: ${verificationUri}`
3846
3884
  );
3885
+ if (opts.browser) {
3886
+ try {
3887
+ (dependencies.openBrowser ?? openBrowser)(verificationUri);
3888
+ } catch {
3889
+ }
3890
+ }
3847
3891
  },
3848
3892
  onUserCode: (userCode) => {
3849
3893
  interactive(
@@ -5554,7 +5598,7 @@ function loadDevProject(cwd, runtime = {}) {
5554
5598
  }
5555
5599
 
5556
5600
  // src/lib/dev-tunnel.ts
5557
- var import_node_child_process = require("child_process");
5601
+ var import_node_child_process2 = require("child_process");
5558
5602
  var import_node_fs7 = require("fs");
5559
5603
  var import_node_path7 = require("path");
5560
5604
  var QUICK_TUNNEL_PROVIDER = "cloudflare-quick";
@@ -5621,7 +5665,7 @@ async function terminateKnownProcessGroup(pgid, runtime = defaultProcessGroupRun
5621
5665
  var defaultParentTunnelRuntime = {
5622
5666
  ...defaultProcessGroupRuntime,
5623
5667
  forkSupervisor(modulePath, args, options) {
5624
- return (0, import_node_child_process.fork)(modulePath, [...args], {
5668
+ return (0, import_node_child_process2.fork)(modulePath, [...args], {
5625
5669
  detached: options.detached,
5626
5670
  execArgv: [...options.execArgv],
5627
5671
  stdio: [...options.stdio]
@@ -5715,7 +5759,7 @@ async function startCloudflareQuickTunnel(input, runtime = defaultParentTunnelRu
5715
5759
  }
5716
5760
  var defaultSupervisorRuntime = {
5717
5761
  spawn(file, args, options) {
5718
- return (0, import_node_child_process.spawn)(file, [...args], {
5762
+ return (0, import_node_child_process2.spawn)(file, [...args], {
5719
5763
  shell: options.shell,
5720
5764
  detached: options.detached,
5721
5765
  stdio: [...options.stdio]
@@ -7043,6 +7087,7 @@ function registerTemplate(program, writer, cwd, runtime = createTemplateCommandR
7043
7087
  // src/commands/init.ts
7044
7088
  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
7089
  var PROJECT_SLUG_RE2 = /^[a-z0-9][a-z0-9-]{0,62}$/u;
7090
+ var MAX_BOOTSTRAP_CONTRACT_BYTES = 1024 * 1024;
7046
7091
  var PROJECT_STATUSES = /* @__PURE__ */ new Set(["active", "suspended", "archived"]);
7047
7092
  var PROJECT_KEYS = [
7048
7093
  "id",
@@ -7065,7 +7110,20 @@ var MANIFEST_KEYS2 = [
7065
7110
  "template_application_commitment"
7066
7111
  ];
7067
7112
  var DEFAULT_INIT_MESSAGES = import_localization7.CLI_MESSAGES.ja.init;
7068
- function assertTemplateInitOptionShape(options) {
7113
+ function assertTemplateInitOptionShape(options, messages = DEFAULT_INIT_MESSAGES) {
7114
+ if (options.openapi !== void 0 && options.project === void 0) {
7115
+ throw new UsageError(messages.optionRequires("--openapi", "--project <uuid>"));
7116
+ }
7117
+ if (options.openapi === void 0 && (options.baseUrl !== void 0 || options.serviceName !== void 0)) {
7118
+ throw new UsageError(messages.optionRequires("--base-url / --service-name", "--openapi"));
7119
+ }
7120
+ 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)) {
7121
+ throw new UsageError(
7122
+ messages.incompatibleOptions(
7123
+ "--openapi / --template / --contract / --create / --name / --slug / --connector / --create-connector"
7124
+ )
7125
+ );
7126
+ }
7069
7127
  if (options.template === void 0 && (options.connector !== void 0 || options.createConnector === true)) {
7070
7128
  throw new UsageError("--connector/--create-connector\u306F--template\u3068\u540C\u6642\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
7071
7129
  }
@@ -7081,9 +7139,83 @@ function assertTemplateInitOptionShape(options) {
7081
7139
  throw new UsageError("--template\u306F--contract/--name/--slug/--create\u3068\u4F75\u7528\u3067\u304D\u307E\u305B\u3093");
7082
7140
  }
7083
7141
  }
7142
+ async function materializeOpenApiInit(options, anchor, runtime, messages) {
7143
+ if (options.openapi === void 0) return { options, anchor };
7144
+ const contractPath = "tool-contract.json";
7145
+ prepareLocalOrThrow(runtime, anchor, contractPath, messages);
7146
+ const source = withAnchoredLocalRoot(
7147
+ anchor.root,
7148
+ anchor.rootIdentity,
7149
+ () => readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, options.openapi), {
7150
+ maxBytes: import_tool_contract7.OPENAPI_IMPORT_MAX_SOURCE_BYTES,
7151
+ root: anchor.root
7152
+ })
7153
+ );
7154
+ let imported;
7155
+ try {
7156
+ imported = (0, import_tool_contract7.importOpenApi)(source.text, {
7157
+ ...options.baseUrl === void 0 ? {} : { baseUrl: options.baseUrl },
7158
+ ...options.baseUrl === void 0 ? {} : { baseUrlMode: "missing-only" },
7159
+ ...options.serviceName === void 0 ? {} : { serviceName: options.serviceName }
7160
+ });
7161
+ } catch (error) {
7162
+ if (error instanceof import_tool_contract7.OpenApiImportError) {
7163
+ throw new UsageError(`OpenAPI\u304B\u3089Tool Contract\u3092\u751F\u6210\u3067\u304D\u307E\u305B\u3093: ${error.message}`);
7164
+ }
7165
+ throw error;
7166
+ }
7167
+ const blocked = imported.operations.filter((operation) => !operation.publishGate.ok);
7168
+ if (blocked.length > 0) {
7169
+ throw new UsageError(
7170
+ `OpenAPI\u751F\u6210\u7D50\u679C\u304Cpublish gate\u3092\u901A\u904E\u3057\u307E\u305B\u3093: ${blocked.map((operation) => operation.toolName).join(", ")}`
7171
+ );
7172
+ }
7173
+ const contracts = imported.operations.map((operation) => operation.contract);
7174
+ const contractText = `${JSON.stringify(contracts.length === 1 ? contracts[0] : { tools: contracts })}
7175
+ `;
7176
+ let createdEntryNlinkDelta = 0;
7177
+ try {
7178
+ createdEntryNlinkDelta = writePrivateFileNoReplace(
7179
+ contractPath,
7180
+ anchor.root,
7181
+ contractText,
7182
+ MAX_BOOTSTRAP_CONTRACT_BYTES,
7183
+ { expectedRootIdentity: anchor.rootIdentity }
7184
+ );
7185
+ } catch (error) {
7186
+ if (!(error instanceof LocalFilePolicyError)) throw error;
7187
+ try {
7188
+ assertLocalRootIdentity(anchor.root, anchor.rootIdentity, "OpenAPI contract fallback");
7189
+ const existing = readBoundedLocalFileSnapshot((0, import_node_path11.resolve)(anchor.root, contractPath), {
7190
+ maxBytes: MAX_BOOTSTRAP_CONTRACT_BYTES,
7191
+ root: anchor.root,
7192
+ directChildOnly: true
7193
+ });
7194
+ if (existing.text !== contractText) throw error;
7195
+ } catch {
7196
+ throw error;
7197
+ }
7198
+ }
7199
+ const refreshedAnchor = captureLocalRootOrThrow(runtime, anchor.root, messages);
7200
+ 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) {
7201
+ throw new InitCommandError(
7202
+ "AP_POLICY_DENIED",
7203
+ "local_file_changed",
7204
+ messages.failure("local_file_changed")
7205
+ );
7206
+ }
7207
+ return {
7208
+ options: {
7209
+ project: options.project,
7210
+ contract: contractPath,
7211
+ profile: options.profile
7212
+ },
7213
+ anchor: refreshedAnchor
7214
+ };
7215
+ }
7084
7216
  async function materializeTemplateInit(options, anchor, runtime, messages) {
7085
7217
  if (options.template === void 0) return { options, anchor };
7086
- assertTemplateInitOptionShape(options);
7218
+ assertTemplateInitOptionShape(options, messages);
7087
7219
  const contractPath = "tool-contract.json";
7088
7220
  const initialPlan = prepareLocalOrThrow(runtime, anchor, contractPath, messages);
7089
7221
  const loadArtifact = () => withAnchoredLocalRoot(
@@ -7520,6 +7652,7 @@ function manifestRecoveryError(error, projectId, messages) {
7520
7652
  }
7521
7653
  function throwLocalizedLocalError(error, messages) {
7522
7654
  if (error instanceof InitLocalUsageError) {
7655
+ if (error.reason === "contract_required") throw new UsageError(messages.contractRequired);
7523
7656
  throw new UsageError(messages.failure(error.reason));
7524
7657
  }
7525
7658
  if (error instanceof UsageError) {
@@ -7579,7 +7712,7 @@ function assertIdempotencyKey(value, messages) {
7579
7712
  return canonical;
7580
7713
  }
7581
7714
  async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_INIT_MESSAGES) {
7582
- assertTemplateInitOptionShape(options);
7715
+ assertTemplateInitOptionShape(options, messages);
7583
7716
  if (options.template !== void 0 && options.project === void 0) {
7584
7717
  throw new UsageError("init --template\u306B\u306Fexport\u5143\u3068\u540C\u3058--project <uuid>\u304C\u5FC5\u9808\u3067\u3059");
7585
7718
  }
@@ -7595,6 +7728,10 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7595
7728
  const materialized = await materializeTemplateInit(options, rootAnchor, runtime, messages);
7596
7729
  rootAnchor = materialized.anchor;
7597
7730
  mode = normalizeInitOptions(materialized.options, messages);
7731
+ } else if (options.openapi !== void 0) {
7732
+ const materialized = await materializeOpenApiInit(options, rootAnchor, runtime, messages);
7733
+ rootAnchor = materialized.anchor;
7734
+ mode = normalizeInitOptions(materialized.options, messages);
7598
7735
  }
7599
7736
  if (!mode) throw new UsageError(messages.failure("local_project_invalid"));
7600
7737
  let actionMode;
@@ -7620,6 +7757,9 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7620
7757
  actionMode = mode;
7621
7758
  }
7622
7759
  let plan = prepareLocalOrThrow(runtime, rootAnchor, actionMode.contract, messages);
7760
+ if (plan.toolContractCommitment === null) {
7761
+ throw new UsageError(messages.contractRequired);
7762
+ }
7623
7763
  if (actionMode.kind === "create") {
7624
7764
  assertCreateManifestAbsent(plan, messages);
7625
7765
  if (!actionMode.yes) {
@@ -7694,7 +7834,7 @@ async function runInitCommand(options, writer, cwd, runtime, messages = DEFAULT_
7694
7834
  }
7695
7835
  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
7836
  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(
7837
+ 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
7838
  "--create-connector",
7699
7839
  "Create the template connector through the existing Admin API policy boundary",
7700
7840
  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-ELZTOEAZ.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.2",
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": {