@andpipes/cli 0.1.4 → 0.1.6
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/README.md +2 -0
- package/dist/bin.cjs +503 -144
- package/dist/bin.js +1 -1
- package/dist/{chunk-VFSDVWMN.js → chunk-TTC7UVIV.js} +483 -116
- package/dist/index.cjs +507 -148
- package/dist/index.d.cts +63 -7
- package/dist/index.d.ts +63 -7
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -32,10 +32,11 @@ function readVersion() {
|
|
|
32
32
|
// src/cli.ts
|
|
33
33
|
import {
|
|
34
34
|
CLI_MESSAGES as CLI_MESSAGES12,
|
|
35
|
-
DEFAULT_LOCALE as
|
|
35
|
+
DEFAULT_LOCALE as DEFAULT_LOCALE11,
|
|
36
36
|
LOCALIZED_TEXT as LOCALIZED_TEXT4,
|
|
37
37
|
normalizeLocale,
|
|
38
|
-
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES4
|
|
38
|
+
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES4,
|
|
39
|
+
PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES as PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES2
|
|
39
40
|
} from "@andpipes/localization";
|
|
40
41
|
import { Command } from "commander";
|
|
41
42
|
|
|
@@ -64,6 +65,7 @@ import {
|
|
|
64
65
|
onboardingTemplateApplicationCommitment,
|
|
65
66
|
onboardingTemplateBindingCommitment,
|
|
66
67
|
PUBLICATION_CONFIRMATION_SIGNATURE_RE,
|
|
68
|
+
PUBLICATION_REVIEW_PROFILE_HEADER,
|
|
67
69
|
PUBLICATION_SHA256_COMMITMENT_RE,
|
|
68
70
|
parseExternalSaasTemplate,
|
|
69
71
|
parseOAuthScopeRegistrationResponse,
|
|
@@ -550,6 +552,26 @@ var ConfirmationRequiredError = class extends Error {
|
|
|
550
552
|
}
|
|
551
553
|
};
|
|
552
554
|
|
|
555
|
+
// src/lib/publication-review-profile.ts
|
|
556
|
+
var CLI_PUBLICATION_REVIEW_PROFILE = 2;
|
|
557
|
+
var PUBLICATION_ERROR_REASON_CODES = Object.freeze({
|
|
558
|
+
publication_plan_stale: "AP_CONFLICT",
|
|
559
|
+
publication_review_profile_invalid: "AP_INPUT_INVALID",
|
|
560
|
+
publication_schema_review_too_large: "AP_INPUT_INVALID",
|
|
561
|
+
schema_review_receipt_mismatch: "AP_CONFLICT"
|
|
562
|
+
});
|
|
563
|
+
function isPublicationErrorReasonFor(code, reason) {
|
|
564
|
+
return typeof reason === "string" && Object.hasOwn(PUBLICATION_ERROR_REASON_CODES, reason) && PUBLICATION_ERROR_REASON_CODES[reason] === code;
|
|
565
|
+
}
|
|
566
|
+
function parsePublicationErrorReason(status, code, details) {
|
|
567
|
+
if (status < 400 || status > 499) return void 0;
|
|
568
|
+
if (details === null || typeof details !== "object" || Array.isArray(details)) return void 0;
|
|
569
|
+
const record = details;
|
|
570
|
+
const keys = Object.keys(record);
|
|
571
|
+
if (keys.length !== 1 || keys[0] !== "reason") return void 0;
|
|
572
|
+
return isPublicationErrorReasonFor(code, record.reason) ? record.reason : void 0;
|
|
573
|
+
}
|
|
574
|
+
|
|
553
575
|
// src/lib/backend.ts
|
|
554
576
|
var ADMIN_API_ORIGIN = "https://api.andpipe.com";
|
|
555
577
|
var ADMIN_API_TIMEOUT_MS = 1e4;
|
|
@@ -579,6 +601,7 @@ var AdminApiClientError = class extends Error {
|
|
|
579
601
|
detailsAbsent;
|
|
580
602
|
scopeRegistrationReason;
|
|
581
603
|
publishGateToolNames;
|
|
604
|
+
publicationReason;
|
|
582
605
|
constructor(code, message, status, confirmationRequired, openApiAuthModeMismatch, safeDetails = {}) {
|
|
583
606
|
super(message);
|
|
584
607
|
this.name = "AdminApiClientError";
|
|
@@ -589,6 +612,7 @@ var AdminApiClientError = class extends Error {
|
|
|
589
612
|
this.detailsAbsent = safeDetails.detailsAbsent === true;
|
|
590
613
|
this.scopeRegistrationReason = safeDetails.scopeRegistrationReason;
|
|
591
614
|
this.publishGateToolNames = safeDetails.publishGateToolNames === void 0 ? void 0 : Object.freeze([...safeDetails.publishGateToolNames]);
|
|
615
|
+
this.publicationReason = safeDetails.publicationReason;
|
|
592
616
|
}
|
|
593
617
|
};
|
|
594
618
|
function clientError(code, message, status) {
|
|
@@ -803,7 +827,8 @@ function withKnownResponseStatus(error, responseStatus) {
|
|
|
803
827
|
{
|
|
804
828
|
detailsAbsent: error.detailsAbsent,
|
|
805
829
|
...error.scopeRegistrationReason === void 0 ? {} : { scopeRegistrationReason: error.scopeRegistrationReason },
|
|
806
|
-
...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames }
|
|
830
|
+
...error.publishGateToolNames === void 0 ? {} : { publishGateToolNames: error.publishGateToolNames },
|
|
831
|
+
...error.publicationReason === void 0 ? {} : { publicationReason: error.publicationReason }
|
|
807
832
|
}
|
|
808
833
|
);
|
|
809
834
|
}
|
|
@@ -872,6 +897,7 @@ function safeApiError(status, value) {
|
|
|
872
897
|
const code = typeof candidate === "string" && SAFE_AP_CODE_RE.test(candidate) ? candidate : "AP_HTTP_ERROR";
|
|
873
898
|
const confirmationRequired = code === "AP_CONFIRMATION_REQUIRED" && status === 409 ? parsePublicationConfirmationRequiredDetails(errorRecord?.details) : void 0;
|
|
874
899
|
const openApiAuthModeMismatch = code === "AP_CONFLICT" && status === 409 ? parseOpenApiImportAuthModeMismatch(errorRecord?.details) : void 0;
|
|
900
|
+
const publicationReason = parsePublicationErrorReason(status, code, errorRecord?.details);
|
|
875
901
|
return new AdminApiClientError(
|
|
876
902
|
code,
|
|
877
903
|
`Admin API request failed (${code}; HTTP ${status})`,
|
|
@@ -881,7 +907,8 @@ function safeApiError(status, value) {
|
|
|
881
907
|
{
|
|
882
908
|
// AP error envelopeを受け取れた場合だけ「detailsなし」を判定できる。
|
|
883
909
|
detailsAbsent: errorRecord !== void 0 && (errorRecord.details === null || errorRecord.details === void 0),
|
|
884
|
-
...parseScopeRegistrationErrorDetails(status, errorRecord?.details)
|
|
910
|
+
...parseScopeRegistrationErrorDetails(status, errorRecord?.details),
|
|
911
|
+
...publicationReason === void 0 ? {} : { publicationReason }
|
|
885
912
|
}
|
|
886
913
|
);
|
|
887
914
|
}
|
|
@@ -1015,6 +1042,13 @@ function publicationPlanBody(input) {
|
|
|
1015
1042
|
...input.templateProvenance === void 0 ? {} : { templateProvenance: input.templateProvenance }
|
|
1016
1043
|
};
|
|
1017
1044
|
}
|
|
1045
|
+
function publicationReviewProfileOption(options) {
|
|
1046
|
+
if (options === void 0) return void 0;
|
|
1047
|
+
if (options === null || typeof options !== "object" || Object.keys(options).join(",") !== "reviewProfile" || options.reviewProfile !== 2) {
|
|
1048
|
+
throw clientError("AP_INPUT_INVALID", "tool publication review profile option is invalid");
|
|
1049
|
+
}
|
|
1050
|
+
return options.reviewProfile;
|
|
1051
|
+
}
|
|
1018
1052
|
function publicationApplyBody(input) {
|
|
1019
1053
|
const common = publicationPlanBody(input);
|
|
1020
1054
|
if (!PUBLICATION_SHA256_COMMITMENT_RE.test(input.planCommitment)) {
|
|
@@ -1370,6 +1404,10 @@ var AdminApiClient = class {
|
|
|
1370
1404
|
this.#sleep = options.sleep ?? ((milliseconds) => new Promise((resolve6) => setTimeout(resolve6, milliseconds)));
|
|
1371
1405
|
}
|
|
1372
1406
|
async #request(path, options = {}) {
|
|
1407
|
+
return (await this.#requestWithHeaders(path, options)).value;
|
|
1408
|
+
}
|
|
1409
|
+
/** 2xx bodyと、そのresponse headerを返す。headerはcommand層が必要な値だけを読む。 */
|
|
1410
|
+
async #requestWithHeaders(path, options = {}) {
|
|
1373
1411
|
const url = buildUrl(path);
|
|
1374
1412
|
const method = options.method ?? "GET";
|
|
1375
1413
|
const attempts = method === "GET" ? ADMIN_API_MAX_GET_ATTEMPTS : 1;
|
|
@@ -1391,6 +1429,9 @@ var AdminApiClient = class {
|
|
|
1391
1429
|
if (options.authenticated !== false) headers.set("Authorization", `Bearer ${this.#token}`);
|
|
1392
1430
|
if (body !== void 0) headers.set("Content-Type", "application/json");
|
|
1393
1431
|
if (options.idempotencyKey) headers.set("Idempotency-Key", options.idempotencyKey);
|
|
1432
|
+
if (options.reviewProfile !== void 0) {
|
|
1433
|
+
headers.set(PUBLICATION_REVIEW_PROFILE_HEADER, String(options.reviewProfile));
|
|
1434
|
+
}
|
|
1394
1435
|
response = await this.#fetch(url, {
|
|
1395
1436
|
method,
|
|
1396
1437
|
headers,
|
|
@@ -1447,8 +1488,8 @@ var AdminApiClient = class {
|
|
|
1447
1488
|
}
|
|
1448
1489
|
throw safeApiError(response.status, errorBody);
|
|
1449
1490
|
}
|
|
1450
|
-
if (options.responseType === "text") return text;
|
|
1451
|
-
return parseJson(text);
|
|
1491
|
+
if (options.responseType === "text") return { value: text, headers: response.headers };
|
|
1492
|
+
return { value: parseJson(text), headers: response.headers };
|
|
1452
1493
|
}
|
|
1453
1494
|
throw clientError("AP_NETWORK_ERROR", "Admin API request failed");
|
|
1454
1495
|
}
|
|
@@ -1594,24 +1635,41 @@ var AdminApiClient = class {
|
|
|
1594
1635
|
status: connector.status
|
|
1595
1636
|
};
|
|
1596
1637
|
}
|
|
1597
|
-
async planPublication(projectId, body) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1638
|
+
async planPublication(projectId, body, options) {
|
|
1639
|
+
const reviewProfile = publicationReviewProfileOption(options);
|
|
1640
|
+
const response = await this.#requestWithHeaders(
|
|
1641
|
+
`/v1/projects/${assertProjectId(projectId)}/tool-publications:plan`,
|
|
1642
|
+
{
|
|
1643
|
+
method: "POST",
|
|
1644
|
+
body: publicationPlanBody(body),
|
|
1645
|
+
maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
|
|
1646
|
+
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
|
|
1647
|
+
...reviewProfile === void 0 ? {} : { reviewProfile }
|
|
1648
|
+
}
|
|
1649
|
+
);
|
|
1650
|
+
if (reviewProfile === void 0) return response.value;
|
|
1651
|
+
const planResponse = {
|
|
1652
|
+
body: response.value,
|
|
1653
|
+
reviewProfileHeader: response.headers.get(PUBLICATION_REVIEW_PROFILE_HEADER)
|
|
1654
|
+
};
|
|
1655
|
+
return planResponse;
|
|
1604
1656
|
}
|
|
1605
|
-
|
|
1657
|
+
/**
|
|
1658
|
+
* 初回apply(confirmation=null)と承認済みapply。options付き (#730) だけreview profile headerを送る。
|
|
1659
|
+
* request bodyとIdempotency-Keyはheaderの有無で変えない。
|
|
1660
|
+
*/
|
|
1661
|
+
async applyPublication(projectId, idempotencyKey, body, options) {
|
|
1606
1662
|
if (!/^[A-Za-z0-9._:-]{22,200}$/u.test(idempotencyKey)) {
|
|
1607
1663
|
throw clientError("AP_INPUT_INVALID", "tool publication Idempotency-Key is invalid");
|
|
1608
1664
|
}
|
|
1665
|
+
const reviewProfile = publicationReviewProfileOption(options);
|
|
1609
1666
|
return this.#request(`/v1/projects/${assertProjectId(projectId)}/tool-publications`, {
|
|
1610
1667
|
method: "POST",
|
|
1611
1668
|
body: publicationApplyBody(body),
|
|
1612
1669
|
idempotencyKey,
|
|
1613
1670
|
maxRequestBytes: ADMIN_API_PUBLICATION_REQUEST_MAX_BYTES,
|
|
1614
|
-
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES
|
|
1671
|
+
maxResponseBytes: ADMIN_API_PUBLICATION_RESPONSE_MAX_BYTES,
|
|
1672
|
+
...reviewProfile === void 0 ? {} : { reviewProfile }
|
|
1615
1673
|
});
|
|
1616
1674
|
}
|
|
1617
1675
|
async planOpenApiImport(projectId, input) {
|
|
@@ -3167,8 +3225,8 @@ async function downloadAuditExportArtifact(input) {
|
|
|
3167
3225
|
} finally {
|
|
3168
3226
|
reader.releaseLock();
|
|
3169
3227
|
}
|
|
3170
|
-
const
|
|
3171
|
-
if (bytes !== authorization.manifest.byteCount ||
|
|
3228
|
+
const sha2563 = hash.digest("hex");
|
|
3229
|
+
if (bytes !== authorization.manifest.byteCount || sha2563 !== authorization.manifest.contentSha256) {
|
|
3172
3230
|
throw new UsageError("\u76E3\u67FB\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u306E\u5185\u5BB9\u304C\u7F72\u540Dmanifest\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093");
|
|
3173
3231
|
}
|
|
3174
3232
|
await file.sync();
|
|
@@ -3187,7 +3245,7 @@ async function downloadAuditExportArtifact(input) {
|
|
|
3187
3245
|
} finally {
|
|
3188
3246
|
await directory.close();
|
|
3189
3247
|
}
|
|
3190
|
-
return { output: canonicalTarget, sha256:
|
|
3248
|
+
return { output: canonicalTarget, sha256: sha2563, bytes };
|
|
3191
3249
|
} finally {
|
|
3192
3250
|
clearTimeout(timeout);
|
|
3193
3251
|
await file.close().catch(() => void 0);
|
|
@@ -7844,12 +7902,247 @@ function registerLogs(program, writer, locale = DEFAULT_LOCALE6) {
|
|
|
7844
7902
|
});
|
|
7845
7903
|
}
|
|
7846
7904
|
|
|
7905
|
+
// src/commands/muse.ts
|
|
7906
|
+
import { createHash as createHash4 } from "crypto";
|
|
7907
|
+
import { lstatSync as lstatSync6, mkdirSync as mkdirSync2 } from "fs";
|
|
7908
|
+
import { join as join6 } from "path";
|
|
7909
|
+
import {
|
|
7910
|
+
DEFAULT_LOCALE as DEFAULT_LOCALE8,
|
|
7911
|
+
MUSE_SETUP_MESSAGES,
|
|
7912
|
+
MUSE_SETUP_STATE_KEYS
|
|
7913
|
+
} from "@andpipes/localization";
|
|
7914
|
+
import { prepareMuseBundle } from "@andpipes/tool-contract";
|
|
7915
|
+
|
|
7916
|
+
// src/commands/validate.ts
|
|
7917
|
+
import { existsSync as existsSync2 } from "fs";
|
|
7918
|
+
import { resolve as resolve4 } from "path";
|
|
7919
|
+
import {
|
|
7920
|
+
CLI_MESSAGES as CLI_MESSAGES8,
|
|
7921
|
+
DEFAULT_LOCALE as DEFAULT_LOCALE7,
|
|
7922
|
+
LOCALIZED_TEXT as LOCALIZED_TEXT3
|
|
7923
|
+
} from "@andpipes/localization";
|
|
7924
|
+
function resolveContractPath(file, cwd, locale = DEFAULT_LOCALE7) {
|
|
7925
|
+
const messages = CLI_MESSAGES8[locale].validate;
|
|
7926
|
+
if (file) {
|
|
7927
|
+
const abs = resolve4(cwd, file);
|
|
7928
|
+
if (!existsSync2(abs)) {
|
|
7929
|
+
throw new UsageError(messages.fileNotFound(file));
|
|
7930
|
+
}
|
|
7931
|
+
return abs;
|
|
7932
|
+
}
|
|
7933
|
+
for (const candidate of CONTRACT_FILENAMES) {
|
|
7934
|
+
const abs = resolve4(cwd, candidate);
|
|
7935
|
+
if (existsSync2(abs)) {
|
|
7936
|
+
return abs;
|
|
7937
|
+
}
|
|
7938
|
+
}
|
|
7939
|
+
throw new UsageError(messages.defaultFileNotFound(CONTRACT_FILENAMES));
|
|
7940
|
+
}
|
|
7941
|
+
function loadContract(path, locale = DEFAULT_LOCALE7) {
|
|
7942
|
+
void locale;
|
|
7943
|
+
return loadContractFile(path).contract;
|
|
7944
|
+
}
|
|
7945
|
+
function registerValidate(program, writer, cwd, locale = DEFAULT_LOCALE7) {
|
|
7946
|
+
const text = LOCALIZED_TEXT3[locale].cli;
|
|
7947
|
+
const messages = CLI_MESSAGES8[locale].validate;
|
|
7948
|
+
program.command("validate").description(`${text.validateDescription} (10 checks)`).option("--file <path>", messages.fileOption).action((opts) => {
|
|
7949
|
+
const path = resolveContractPath(opts.file, cwd(), locale);
|
|
7950
|
+
const loaded = loadContractFile(path);
|
|
7951
|
+
const report = loaded.report;
|
|
7952
|
+
const publishGate = loaded.publishGate;
|
|
7953
|
+
json(writer, { checks: report.results, publishGate });
|
|
7954
|
+
const fail2 = report.results.filter((r) => r.status === "fail").length;
|
|
7955
|
+
const pending = report.results.filter((r) => r.status === "pending").length;
|
|
7956
|
+
const pass = report.results.filter((r) => r.status === "pass").length;
|
|
7957
|
+
info(
|
|
7958
|
+
writer,
|
|
7959
|
+
`${text.resultLabel}: pass=${pass} fail=${fail2} pending=${pending} (pending=${text.backendPending})`
|
|
7960
|
+
);
|
|
7961
|
+
info(
|
|
7962
|
+
writer,
|
|
7963
|
+
messages.publishGateSummary(publishGate.errors.length, publishGate.warnings.length)
|
|
7964
|
+
);
|
|
7965
|
+
if (!report.ok || !publishGate.ok) {
|
|
7966
|
+
process.exitCode = 1;
|
|
7967
|
+
info(writer, messages.failed);
|
|
7968
|
+
}
|
|
7969
|
+
});
|
|
7970
|
+
}
|
|
7971
|
+
|
|
7972
|
+
// src/commands/muse.ts
|
|
7973
|
+
var DEFAULT_MUSE_OUTPUT_DIR = "andpipe-muse-preparation";
|
|
7974
|
+
var OUTPUT_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
7975
|
+
var MAX_MUSE_FILE_BYTES = 8 * 1024 * 1024;
|
|
7976
|
+
var MUSE_PREPARATION_FILE_KEYS = Object.freeze(
|
|
7977
|
+
{
|
|
7978
|
+
"muse/connector.internal.json": "connector",
|
|
7979
|
+
"muse/openapi.json": "openapi",
|
|
7980
|
+
"muse/SKILL.md": "skill",
|
|
7981
|
+
"muse/setup.md": "setup",
|
|
7982
|
+
"muse/compatibility.json": "compatibility",
|
|
7983
|
+
"provenance/build.json": "provenance"
|
|
7984
|
+
}
|
|
7985
|
+
);
|
|
7986
|
+
var REASON_KEYS = {
|
|
7987
|
+
invalid_input: "invalid_input",
|
|
7988
|
+
selection_required: "selection_required",
|
|
7989
|
+
selection_invalid: "selection_invalid",
|
|
7990
|
+
contract_invalid: "contract_invalid",
|
|
7991
|
+
schema_unsupported: "schema_unsupported",
|
|
7992
|
+
sensitive_content: "sensitive_content",
|
|
7993
|
+
risk_unsupported: "risk_unsupported"
|
|
7994
|
+
};
|
|
7995
|
+
function parseToolNames(value, locale) {
|
|
7996
|
+
const names = (value ?? "").split(",").map((name) => name.trim()).filter((name) => name.length > 0);
|
|
7997
|
+
if (names.length === 0) throw new UsageError(MUSE_SETUP_MESSAGES[locale].cli.toolsRequired);
|
|
7998
|
+
return names;
|
|
7999
|
+
}
|
|
8000
|
+
function parseOutputDir(value, locale) {
|
|
8001
|
+
const output = value ?? DEFAULT_MUSE_OUTPUT_DIR;
|
|
8002
|
+
if (!OUTPUT_DIR_RE.test(output) || output === "." || output === "..") {
|
|
8003
|
+
throw new UsageError(MUSE_SETUP_MESSAGES[locale].cli.outputInvalid);
|
|
8004
|
+
}
|
|
8005
|
+
return output;
|
|
8006
|
+
}
|
|
8007
|
+
function sha2562(text) {
|
|
8008
|
+
return `sha256:${createHash4("sha256").update(text, "utf8").digest("hex")}`;
|
|
8009
|
+
}
|
|
8010
|
+
function createOwnedDirectory(path) {
|
|
8011
|
+
mkdirSync2(path, { mode: 448 });
|
|
8012
|
+
return ownedDirectoryIdentity(path);
|
|
8013
|
+
}
|
|
8014
|
+
function ownedDirectoryIdentity(path) {
|
|
8015
|
+
let stat2;
|
|
8016
|
+
try {
|
|
8017
|
+
stat2 = lstatSync6(path);
|
|
8018
|
+
} catch {
|
|
8019
|
+
throw new LocalFilePolicyError("local_file_changed", "output directory changed after create");
|
|
8020
|
+
}
|
|
8021
|
+
const identity = localRootIdentityFromStat(stat2, "local_file_changed", "output directory");
|
|
8022
|
+
assertOwnerOnlyLocalWrite(identity, "output directory");
|
|
8023
|
+
return identity;
|
|
8024
|
+
}
|
|
8025
|
+
function errorCode(error) {
|
|
8026
|
+
const code = typeof error === "object" && error !== null ? error.code : null;
|
|
8027
|
+
return typeof code === "string" && /^[A-Z][A-Z0-9_]{1,31}$/u.test(code) ? code : null;
|
|
8028
|
+
}
|
|
8029
|
+
function museWriteOrder(paths) {
|
|
8030
|
+
const isProvenance = (path) => path.startsWith("provenance/");
|
|
8031
|
+
return [...paths].sort(
|
|
8032
|
+
(left, right) => isProvenance(left) === isProvenance(right) ? left < right ? -1 : 1 : isProvenance(left) ? 1 : -1
|
|
8033
|
+
);
|
|
8034
|
+
}
|
|
8035
|
+
function writeBundle(root, output, files, locale) {
|
|
8036
|
+
const messages = MUSE_SETUP_MESSAGES[locale].cli;
|
|
8037
|
+
const target = join6(root, output);
|
|
8038
|
+
const ordered = museWriteOrder(Object.keys(files));
|
|
8039
|
+
const directoryNames = /* @__PURE__ */ new Set();
|
|
8040
|
+
for (const path of ordered) {
|
|
8041
|
+
const [directory, name, ...rest] = path.split("/");
|
|
8042
|
+
if (!directory || !name || rest.length > 0 || !MUSE_PREPARATION_FILE_KEYS[path]) {
|
|
8043
|
+
throw new LocalFilePolicyError("local_file_invalid", "unexpected preparation file path");
|
|
8044
|
+
}
|
|
8045
|
+
directoryNames.add(directory);
|
|
8046
|
+
}
|
|
8047
|
+
try {
|
|
8048
|
+
mkdirSync2(target, { mode: 448 });
|
|
8049
|
+
} catch (error) {
|
|
8050
|
+
const code = errorCode(error);
|
|
8051
|
+
if (code === "EEXIST") throw new UsageError(messages.outputExists(output));
|
|
8052
|
+
throw new UsageError(`${messages.outputCreateFailed(output)}${code ? ` (${code})` : ""}`);
|
|
8053
|
+
}
|
|
8054
|
+
try {
|
|
8055
|
+
const targetIdentity = ownedDirectoryIdentity(target);
|
|
8056
|
+
const directories = /* @__PURE__ */ new Map();
|
|
8057
|
+
for (const directory of directoryNames) {
|
|
8058
|
+
assertLocalRootSecurityIdentity(target, targetIdentity, "muse output directory");
|
|
8059
|
+
directories.set(directory, createOwnedDirectory(join6(target, directory)));
|
|
8060
|
+
}
|
|
8061
|
+
for (const path of ordered) {
|
|
8062
|
+
const [directory, name] = path.split("/");
|
|
8063
|
+
const expected = directories.get(directory);
|
|
8064
|
+
assertLocalRootSecurityIdentity(target, targetIdentity, "muse output directory");
|
|
8065
|
+
const delta = writePrivateFileNoReplace(
|
|
8066
|
+
name,
|
|
8067
|
+
join6(target, directory),
|
|
8068
|
+
files[path],
|
|
8069
|
+
MAX_MUSE_FILE_BYTES,
|
|
8070
|
+
{ expectedRootIdentity: expected }
|
|
8071
|
+
);
|
|
8072
|
+
directories.set(directory, localRootIdentityWithNlink(expected, expected.nlink + delta));
|
|
8073
|
+
}
|
|
8074
|
+
} catch (error) {
|
|
8075
|
+
const reason = error instanceof LocalFilePolicyError ? ` (${error.reason})` : "";
|
|
8076
|
+
throw new UsageError(`${messages.outputIncomplete(output)}${reason}`);
|
|
8077
|
+
}
|
|
8078
|
+
}
|
|
8079
|
+
function runMusePrepare(options, writer, cwd, locale = DEFAULT_LOCALE8) {
|
|
8080
|
+
const messages = MUSE_SETUP_MESSAGES[locale];
|
|
8081
|
+
const toolNames = parseToolNames(options.tools, locale);
|
|
8082
|
+
const output = parseOutputDir(options.output, locale);
|
|
8083
|
+
const anchor = captureLocalRootPath(cwd);
|
|
8084
|
+
const loaded = loadContractFile(resolveContractPath(options.file, cwd, locale));
|
|
8085
|
+
const selected = new Set(toolNames);
|
|
8086
|
+
const result = prepareMuseBundle(
|
|
8087
|
+
loaded.tools.filter((tool) => selected.has(tool.tool)),
|
|
8088
|
+
{ toolNames }
|
|
8089
|
+
);
|
|
8090
|
+
const flags = {
|
|
8091
|
+
enabled: result.enabled,
|
|
8092
|
+
liveVerified: result.liveVerified,
|
|
8093
|
+
submissionReady: result.submissionReady
|
|
8094
|
+
};
|
|
8095
|
+
if (result.status === "blocked") {
|
|
8096
|
+
const reason = messages.reasons[REASON_KEYS[result.reason]];
|
|
8097
|
+
json(writer, { status: "blocked", reason: result.reason, ...flags });
|
|
8098
|
+
info(writer, messages.cli.blocked);
|
|
8099
|
+
info(writer, `${messages.cli.reasonLabel}: ${reason.cause}`);
|
|
8100
|
+
info(writer, `${messages.cli.fixLabel}: ${reason.fix}`);
|
|
8101
|
+
process.exitCode = 1;
|
|
8102
|
+
return;
|
|
8103
|
+
}
|
|
8104
|
+
assertLocalRootSecurityIdentity(anchor.root, anchor.rootIdentity, "muse output");
|
|
8105
|
+
writeBundle(anchor.root, output, result.files, locale);
|
|
8106
|
+
const paths = Object.keys(result.files).sort();
|
|
8107
|
+
json(writer, {
|
|
8108
|
+
status: "prepared",
|
|
8109
|
+
output,
|
|
8110
|
+
contentHash: result.contentHash,
|
|
8111
|
+
...flags,
|
|
8112
|
+
files: paths.map((path) => ({ path, sha256: sha2562(result.files[path]) }))
|
|
8113
|
+
});
|
|
8114
|
+
info(writer, messages.cli.prepared(output));
|
|
8115
|
+
info(writer, messages.cli.notConnected);
|
|
8116
|
+
for (const path of paths) {
|
|
8117
|
+
const key = MUSE_PREPARATION_FILE_KEYS[path];
|
|
8118
|
+
if (key) info(writer, ` ${output}/${path}: ${messages.files[key]}`);
|
|
8119
|
+
}
|
|
8120
|
+
info(writer, `${messages.cli.statesHeading}:`);
|
|
8121
|
+
for (const key of MUSE_SETUP_STATE_KEYS) {
|
|
8122
|
+
const state = messages.states[key];
|
|
8123
|
+
info(
|
|
8124
|
+
writer,
|
|
8125
|
+
`- ${state.title}: ${key === "prepared" ? messages.cli.preparedNow : state.status}`
|
|
8126
|
+
);
|
|
8127
|
+
}
|
|
8128
|
+
info(writer, messages.cli.nextStep);
|
|
8129
|
+
}
|
|
8130
|
+
function registerMuse(program, writer, cwd, locale = DEFAULT_LOCALE8) {
|
|
8131
|
+
const messages = MUSE_SETUP_MESSAGES[locale].cli;
|
|
8132
|
+
const muse = program.command("muse").description(messages.groupDescription);
|
|
8133
|
+
muse.command("prepare").description(messages.prepareDescription).option(
|
|
8134
|
+
"--tools <names>",
|
|
8135
|
+
messages.toolsOption,
|
|
8136
|
+
(value, previous) => previous === void 0 ? value : `${previous},${value}`
|
|
8137
|
+
).option("--file <path>", messages.fileOption).option("--output <dir>", messages.outputOption, DEFAULT_MUSE_OUTPUT_DIR).action((options) => runMusePrepare(options, writer, cwd(), locale));
|
|
8138
|
+
}
|
|
8139
|
+
|
|
7847
8140
|
// src/commands/oauth.ts
|
|
7848
8141
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
7849
8142
|
import { readFileSync as readFileSync2 } from "fs";
|
|
7850
8143
|
import {
|
|
7851
|
-
CLI_MESSAGES as
|
|
7852
|
-
DEFAULT_LOCALE as
|
|
8144
|
+
CLI_MESSAGES as CLI_MESSAGES10,
|
|
8145
|
+
DEFAULT_LOCALE as DEFAULT_LOCALE9,
|
|
7853
8146
|
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES3
|
|
7854
8147
|
} from "@andpipes/localization";
|
|
7855
8148
|
import {
|
|
@@ -7861,8 +8154,9 @@ import {
|
|
|
7861
8154
|
// src/commands/publish.ts
|
|
7862
8155
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
7863
8156
|
import {
|
|
7864
|
-
CLI_MESSAGES as
|
|
7865
|
-
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES2
|
|
8157
|
+
CLI_MESSAGES as CLI_MESSAGES9,
|
|
8158
|
+
OAUTH_SCOPE_REGISTRATION_MESSAGES as OAUTH_SCOPE_REGISTRATION_MESSAGES2,
|
|
8159
|
+
PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES
|
|
7866
8160
|
} from "@andpipes/localization";
|
|
7867
8161
|
import {
|
|
7868
8162
|
assertCanonicalPublicationSize as assertCanonicalPublicationSize2,
|
|
@@ -7873,14 +8167,19 @@ import {
|
|
|
7873
8167
|
parsePublicationSafeDiffDto,
|
|
7874
8168
|
parsePublicationWarningsDto,
|
|
7875
8169
|
publicationCommitment as publicationCommitment2,
|
|
8170
|
+
selectPublicationReviewProfile,
|
|
7876
8171
|
toolName as toolName2
|
|
7877
8172
|
} from "@andpipes/tool-contract";
|
|
7878
8173
|
var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
7879
8174
|
var SAFE_AP_CODE_RE2 = /^AP_[A-Z0-9_]{1,64}$/u;
|
|
7880
8175
|
var PUBLICATION_RESPONSE_MAX_BYTES = 96 * 1024;
|
|
7881
8176
|
var INITIAL_APPLY_MAX_ATTEMPTS = 3;
|
|
7882
|
-
var DEFAULT_PUBLISH_MESSAGES =
|
|
8177
|
+
var DEFAULT_PUBLISH_MESSAGES = CLI_MESSAGES9.ja.publish;
|
|
7883
8178
|
var DEFAULT_SCOPE_REGISTRATION_MESSAGES2 = OAUTH_SCOPE_REGISTRATION_MESSAGES2.ja.cli;
|
|
8179
|
+
var DEFAULT_SCHEMA_REVIEW_MESSAGES = PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES.ja;
|
|
8180
|
+
var REVIEW_PROFILE_REQUEST = Object.freeze({
|
|
8181
|
+
reviewProfile: CLI_PUBLICATION_REVIEW_PROFILE
|
|
8182
|
+
});
|
|
7884
8183
|
var PLAN_KEYS = [
|
|
7885
8184
|
"requestId",
|
|
7886
8185
|
"environment",
|
|
@@ -8040,10 +8339,41 @@ function parseWarnings(value, messages) {
|
|
|
8040
8339
|
throw responseInvalid("publication_warnings_invalid", messages);
|
|
8041
8340
|
}
|
|
8042
8341
|
}
|
|
8043
|
-
function
|
|
8342
|
+
function schemaReviewFailure(code, reason, text, status) {
|
|
8343
|
+
return new PublishCommandError(code, reason, `${text} (${reason})`, status);
|
|
8344
|
+
}
|
|
8345
|
+
function negotiateReviewProfile(response, messages, schemaReviewMessages) {
|
|
8346
|
+
const envelope = asRecord4(response);
|
|
8347
|
+
if (!envelope || !hasExactKeys3(envelope, ["body", "reviewProfileHeader"]) || envelope.reviewProfileHeader !== null && typeof envelope.reviewProfileHeader !== "string") {
|
|
8348
|
+
throw responseInvalid("publication_plan_invalid", messages);
|
|
8349
|
+
}
|
|
8350
|
+
const header = envelope.reviewProfileHeader;
|
|
8351
|
+
if (header !== null && header !== "1" && header !== "2") {
|
|
8352
|
+
throw schemaReviewFailure(
|
|
8353
|
+
"AP_RESPONSE_INVALID",
|
|
8354
|
+
"publication_review_profile_header_invalid",
|
|
8355
|
+
schemaReviewMessages.reviewProfileHeaderInvalid
|
|
8356
|
+
);
|
|
8357
|
+
}
|
|
8358
|
+
const body = asRecord4(envelope.body);
|
|
8359
|
+
const bodyDeclaresProfile = body !== null && Object.hasOwn(body, "reviewProfile");
|
|
8360
|
+
const profile = header === "2" ? 2 : 1;
|
|
8361
|
+
if (profile === 2 ? !bodyDeclaresProfile || body?.reviewProfile !== 2 : bodyDeclaresProfile) {
|
|
8362
|
+
throw schemaReviewFailure(
|
|
8363
|
+
"AP_CONFLICT",
|
|
8364
|
+
"publication_review_profile_mismatch",
|
|
8365
|
+
schemaReviewMessages.reviewProfileMismatch
|
|
8366
|
+
);
|
|
8367
|
+
}
|
|
8368
|
+
return {
|
|
8369
|
+
session: header === null ? { kind: "legacy", profile: 1 } : { kind: "negotiated", profile },
|
|
8370
|
+
body: envelope.body
|
|
8371
|
+
};
|
|
8372
|
+
}
|
|
8373
|
+
function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, profile, messages) {
|
|
8044
8374
|
assertCanonicalResponseSize(value, "publication_plan_too_large", messages);
|
|
8045
8375
|
const plan = asRecord4(value);
|
|
8046
|
-
if (!plan || !hasExactKeys3(plan, PLAN_KEYS) || !isCanonicalUuid(plan.requestId) || plan.environment !== "production" || plan.connectorId !== connectorId || !isCanonicalTimestamp(plan.connectorRevision) || !isCommitment(plan.connectorCommitment) || !isCommitment(plan.policyCommitment) || plan.candidateCommitment !== candidateCommitment || !isCommitment(plan.candidateCommitment) || !isCommitment(plan.baseCommitment) || !isCommitment(plan.planCommitment) || !Array.isArray(plan.tools) || typeof plan.applyAllowed !== "boolean" || !Array.isArray(plan.blockedReasons) || !plan.blockedReasons.every(
|
|
8376
|
+
if (!plan || !hasExactKeys3(plan, profile === 2 ? [...PLAN_KEYS, "reviewProfile"] : PLAN_KEYS) || profile === 2 && plan.reviewProfile !== 2 || !isCanonicalUuid(plan.requestId) || plan.environment !== "production" || plan.connectorId !== connectorId || !isCanonicalTimestamp(plan.connectorRevision) || !isCommitment(plan.connectorCommitment) || !isCommitment(plan.policyCommitment) || plan.candidateCommitment !== candidateCommitment || !isCommitment(plan.candidateCommitment) || !isCommitment(plan.baseCommitment) || !isCommitment(plan.planCommitment) || !Array.isArray(plan.tools) || typeof plan.applyAllowed !== "boolean" || !Array.isArray(plan.blockedReasons) || !plan.blockedReasons.every(
|
|
8047
8377
|
(reason) => typeof reason === "string" && BLOCKED_REASONS.has(reason)
|
|
8048
8378
|
) || !isStrictlySorted(plan.blockedReasons) || plan.applyAllowed !== (plan.blockedReasons.length === 0)) {
|
|
8049
8379
|
throw responseInvalid("publication_plan_invalid", messages);
|
|
@@ -8052,6 +8382,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8052
8382
|
let safeDiff;
|
|
8053
8383
|
try {
|
|
8054
8384
|
safeDiff = parsePublicationSafeDiffDto({
|
|
8385
|
+
...profile === 2 ? { reviewProfile: 2 } : {},
|
|
8055
8386
|
tools: plan.tools,
|
|
8056
8387
|
retainedTools: plan.retainedTools,
|
|
8057
8388
|
warnings: plan.warnings
|
|
@@ -8059,13 +8390,16 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8059
8390
|
} catch {
|
|
8060
8391
|
throw responseInvalid("publication_safe_diff_invalid", messages);
|
|
8061
8392
|
}
|
|
8393
|
+
if (safeDiff.reviewProfile === 2 !== (profile === 2)) {
|
|
8394
|
+
throw responseInvalid("publication_safe_diff_invalid", messages);
|
|
8395
|
+
}
|
|
8062
8396
|
const tools = safeDiff.tools;
|
|
8063
8397
|
const toolNames = tools.map((tool) => tool.toolName);
|
|
8064
8398
|
if (!isStrictlySorted(toolNames) || JSON.stringify(toolNames) !== JSON.stringify(expectedToolNames)) {
|
|
8065
8399
|
throw responseInvalid("publication_plan_tools_order_invalid", messages);
|
|
8066
8400
|
}
|
|
8067
8401
|
const warnings = safeDiff.warnings;
|
|
8068
|
-
const expectedPlanCommitment = publicationCommitment2("plan", {
|
|
8402
|
+
const expectedPlanCommitment = publicationCommitment2(profile === 2 ? "planV2" : "plan", {
|
|
8069
8403
|
candidateCommitment,
|
|
8070
8404
|
baseCommitment: plan.baseCommitment,
|
|
8071
8405
|
connectorId,
|
|
@@ -8093,6 +8427,7 @@ function parsePlan(value, connectorId, candidateCommitment, expectedToolNames, m
|
|
|
8093
8427
|
throw responseInvalid("publication_plan_gate_inconsistent", messages);
|
|
8094
8428
|
}
|
|
8095
8429
|
return {
|
|
8430
|
+
...profile === 2 ? { reviewProfile: 2 } : {},
|
|
8096
8431
|
requestId: plan.requestId,
|
|
8097
8432
|
environment: "production",
|
|
8098
8433
|
connectorId,
|
|
@@ -8220,8 +8555,36 @@ function typedStatus2(error) {
|
|
|
8220
8555
|
const status = error.status;
|
|
8221
8556
|
return typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 ? status : void 0;
|
|
8222
8557
|
}
|
|
8223
|
-
function
|
|
8558
|
+
function typedPublicationReason(error, code) {
|
|
8559
|
+
if (error === null || typeof error !== "object") return void 0;
|
|
8560
|
+
const status = typedStatus2(error);
|
|
8561
|
+
if (status === void 0 || status < 400 || status > 499) return void 0;
|
|
8562
|
+
const reason = error.publicationReason;
|
|
8563
|
+
return isPublicationErrorReasonFor(code, reason) ? reason : void 0;
|
|
8564
|
+
}
|
|
8565
|
+
function publicationReasonText(reason, schemaReviewMessages) {
|
|
8566
|
+
switch (reason) {
|
|
8567
|
+
case "publication_schema_review_too_large":
|
|
8568
|
+
return schemaReviewMessages.schemaReviewTooLarge;
|
|
8569
|
+
case "publication_review_profile_invalid":
|
|
8570
|
+
return schemaReviewMessages.reviewProfileInvalid;
|
|
8571
|
+
case "schema_review_receipt_mismatch":
|
|
8572
|
+
return schemaReviewMessages.receiptMismatch;
|
|
8573
|
+
case "publication_plan_stale":
|
|
8574
|
+
return schemaReviewMessages.planStale;
|
|
8575
|
+
}
|
|
8576
|
+
}
|
|
8577
|
+
function remoteError(error, phase, messages, schemaReviewMessages) {
|
|
8224
8578
|
const code = typedCode2(error) ?? "AP_NETWORK_ERROR";
|
|
8579
|
+
const publicationReason = schemaReviewMessages === void 0 ? void 0 : typedPublicationReason(error, code);
|
|
8580
|
+
if (publicationReason !== void 0 && schemaReviewMessages !== void 0) {
|
|
8581
|
+
return schemaReviewFailure(
|
|
8582
|
+
code,
|
|
8583
|
+
publicationReason,
|
|
8584
|
+
publicationReasonText(publicationReason, schemaReviewMessages),
|
|
8585
|
+
typedStatus2(error)
|
|
8586
|
+
);
|
|
8587
|
+
}
|
|
8225
8588
|
return new PublishCommandError(
|
|
8226
8589
|
code,
|
|
8227
8590
|
`${phase}_failed`,
|
|
@@ -8283,6 +8646,42 @@ function writeSafeJson(writer, value) {
|
|
|
8283
8646
|
function writePlan(writer, plan) {
|
|
8284
8647
|
writeSafeJson(writer, { phase: "plan", ...plan });
|
|
8285
8648
|
}
|
|
8649
|
+
function writeSchemaReviewSummary(writer, plan, schemaReviewMessages) {
|
|
8650
|
+
if (plan.reviewProfile !== 2) return;
|
|
8651
|
+
const reviewed = plan.tools.filter((tool) => (tool.schemaReview?.enums.length ?? 0) > 0);
|
|
8652
|
+
if (reviewed.length === 0) return;
|
|
8653
|
+
interactive(writer, schemaReviewMessages.heading);
|
|
8654
|
+
for (const tool of reviewed) {
|
|
8655
|
+
const review = tool.schemaReview;
|
|
8656
|
+
if (!review) continue;
|
|
8657
|
+
const count = (change) => review.enums.filter((entry) => entry.change === change).length;
|
|
8658
|
+
interactive(
|
|
8659
|
+
writer,
|
|
8660
|
+
schemaReviewMessages.toolSummary({
|
|
8661
|
+
toolName: terminalSafeText(tool.toolName),
|
|
8662
|
+
total: review.enums.length,
|
|
8663
|
+
added: count("added"),
|
|
8664
|
+
changed: count("changed"),
|
|
8665
|
+
removed: count("removed"),
|
|
8666
|
+
unchanged: count("unchanged"),
|
|
8667
|
+
valueReviewRequired: review.humanValueReviewRequired
|
|
8668
|
+
})
|
|
8669
|
+
);
|
|
8670
|
+
}
|
|
8671
|
+
if (reviewed.some((tool) => tool.schemaReview?.humanValueReviewRequired === true)) {
|
|
8672
|
+
interactive(writer, schemaReviewMessages.valueReviewInWebAdmin);
|
|
8673
|
+
}
|
|
8674
|
+
}
|
|
8675
|
+
function candidateNeedsReviewProfile2(candidateContract) {
|
|
8676
|
+
return selectPublicationReviewProfile({
|
|
8677
|
+
requestedProfile: CLI_PUBLICATION_REVIEW_PROFILE,
|
|
8678
|
+
candidateContract,
|
|
8679
|
+
currentTools: []
|
|
8680
|
+
}) === 2;
|
|
8681
|
+
}
|
|
8682
|
+
function applyPublicationWithProfile(client, projectId, idempotencyKey, body, session) {
|
|
8683
|
+
return session.kind === "negotiated" ? client.applyPublication(projectId, idempotencyKey, body, REVIEW_PROFILE_REQUEST) : client.applyPublication(projectId, idempotencyKey, body);
|
|
8684
|
+
}
|
|
8286
8685
|
function writeResult(writer, result) {
|
|
8287
8686
|
writeSafeJson(writer, { phase: "result", ...result });
|
|
8288
8687
|
}
|
|
@@ -8375,7 +8774,13 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
|
|
|
8375
8774
|
for (let attempt = 0; attempt < INITIAL_APPLY_MAX_ATTEMPTS; attempt += 1) {
|
|
8376
8775
|
try {
|
|
8377
8776
|
const result = parsePublicationResult(
|
|
8378
|
-
await
|
|
8777
|
+
await applyPublicationWithProfile(
|
|
8778
|
+
input.client,
|
|
8779
|
+
input.projectId,
|
|
8780
|
+
input.idempotencyKey,
|
|
8781
|
+
input.body,
|
|
8782
|
+
input.session
|
|
8783
|
+
),
|
|
8379
8784
|
input.plan,
|
|
8380
8785
|
input.messages
|
|
8381
8786
|
);
|
|
@@ -8401,7 +8806,7 @@ async function sendInitialApplyWithSameAnchorRetry(input) {
|
|
|
8401
8806
|
return { kind: "confirmation_required", details: confirmationRequired };
|
|
8402
8807
|
}
|
|
8403
8808
|
if (!malformedConfirmationAnchor && !initialApplyResultMayBeUnknown(error)) {
|
|
8404
|
-
throw remoteError(error, "initial_apply", input.messages);
|
|
8809
|
+
throw remoteError(error, "initial_apply", input.messages, input.schemaReviewMessages);
|
|
8405
8810
|
}
|
|
8406
8811
|
if (attempt === INITIAL_APPLY_MAX_ATTEMPTS - 1) {
|
|
8407
8812
|
throw new PublishCommandError(
|
|
@@ -8526,7 +8931,7 @@ async function pollPublication(client, projectId, details, plan, writer, runtime
|
|
|
8526
8931
|
}
|
|
8527
8932
|
throw confirmationStopped("AP_CONFIRMATION_EXPIRED", "publication_poll_attempt_limit", messages);
|
|
8528
8933
|
}
|
|
8529
|
-
async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
|
|
8934
|
+
async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
|
|
8530
8935
|
const normalized = normalizePublishOptions(options, messages);
|
|
8531
8936
|
const project = loadPublicationProject(runtime.loadProject, cwd, messages);
|
|
8532
8937
|
const projectId = project.manifest.project_id;
|
|
@@ -8547,18 +8952,25 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8547
8952
|
const client = runtime.createClient(normalized.profile);
|
|
8548
8953
|
let rawPlan;
|
|
8549
8954
|
try {
|
|
8550
|
-
rawPlan = await client.planPublication(projectId, planRequest);
|
|
8955
|
+
rawPlan = await client.planPublication(projectId, planRequest, REVIEW_PROFILE_REQUEST);
|
|
8551
8956
|
} catch (error) {
|
|
8552
|
-
throw remoteError(error, "plan", messages);
|
|
8957
|
+
throw remoteError(error, "plan", messages, schemaReviewMessages);
|
|
8553
8958
|
}
|
|
8959
|
+
const negotiated = negotiateReviewProfile(rawPlan, messages, schemaReviewMessages);
|
|
8960
|
+
const session = negotiated.session;
|
|
8554
8961
|
const plan = parsePlan(
|
|
8555
|
-
|
|
8962
|
+
negotiated.body,
|
|
8556
8963
|
connectorId,
|
|
8557
8964
|
planRequest.candidateCommitment,
|
|
8558
8965
|
expectedToolNames,
|
|
8966
|
+
session.profile,
|
|
8559
8967
|
messages
|
|
8560
8968
|
);
|
|
8561
8969
|
writePlan(writer, plan);
|
|
8970
|
+
writeSchemaReviewSummary(writer, plan, schemaReviewMessages);
|
|
8971
|
+
if (session.kind === "legacy" && plan.blockedReasons.includes("opaque_change") && candidateNeedsReviewProfile2(planRequest.candidateContract)) {
|
|
8972
|
+
interactive(writer, schemaReviewMessages.adminApiUpdatePending);
|
|
8973
|
+
}
|
|
8562
8974
|
if (plan.blockedReasons.includes("connector_mismatch")) {
|
|
8563
8975
|
interactive(writer, messages.connectorMismatchRemediation);
|
|
8564
8976
|
}
|
|
@@ -8589,7 +9001,9 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8589
9001
|
idempotencyKey,
|
|
8590
9002
|
body: initialApplyRequest,
|
|
8591
9003
|
plan,
|
|
8592
|
-
|
|
9004
|
+
session,
|
|
9005
|
+
messages,
|
|
9006
|
+
schemaReviewMessages
|
|
8593
9007
|
});
|
|
8594
9008
|
let details;
|
|
8595
9009
|
if (initial.kind === "response") {
|
|
@@ -8618,7 +9032,13 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8618
9032
|
}
|
|
8619
9033
|
try {
|
|
8620
9034
|
const result = parsePublicationResult(
|
|
8621
|
-
await
|
|
9035
|
+
await applyPublicationWithProfile(
|
|
9036
|
+
client,
|
|
9037
|
+
projectId,
|
|
9038
|
+
idempotencyKey,
|
|
9039
|
+
applyRequest(decision.confirmation),
|
|
9040
|
+
session
|
|
9041
|
+
),
|
|
8622
9042
|
plan,
|
|
8623
9043
|
messages,
|
|
8624
9044
|
details.publicationId
|
|
@@ -8628,7 +9048,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8628
9048
|
} catch (error) {
|
|
8629
9049
|
if (error instanceof PublishCommandError && error.code === "AP_RESPONSE_INVALID") {
|
|
8630
9050
|
} else if (!approvedApplyResultMayBeUnknown(error)) {
|
|
8631
|
-
throw remoteError(error, "approved_apply", messages);
|
|
9051
|
+
throw remoteError(error, "approved_apply", messages, schemaReviewMessages);
|
|
8632
9052
|
}
|
|
8633
9053
|
}
|
|
8634
9054
|
const recovered = await pollPublication(
|
|
@@ -8651,7 +9071,7 @@ async function runPublishCommand(options, writer, cwd, runtime, messages = DEFAU
|
|
|
8651
9071
|
}
|
|
8652
9072
|
writeResult(writer, recovered.result);
|
|
8653
9073
|
}
|
|
8654
|
-
function registerPublish(program, writer, cwd, createClient, description2 = "Tool Contract\u3092production publication workflow\u3067\u5B89\u5168\u306B\u516C\u958B\u3057\u307E\u3059", runtime = createPublishCommandRuntime(createClient), messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2) {
|
|
9074
|
+
function registerPublish(program, writer, cwd, createClient, description2 = "Tool Contract\u3092production publication workflow\u3067\u5B89\u5168\u306B\u516C\u958B\u3057\u307E\u3059", runtime = createPublishCommandRuntime(createClient), messages = DEFAULT_PUBLISH_MESSAGES, scopeRegistrationMessages = DEFAULT_SCOPE_REGISTRATION_MESSAGES2, schemaReviewMessages = DEFAULT_SCHEMA_REVIEW_MESSAGES) {
|
|
8655
9075
|
program.command("publish").description(description2).option("--connector <connector-uuid>", messages.connectorOption).option("--dry-run", messages.dryRunOption, false).option("--apply", messages.applyOption, false).option("--yes", messages.yesOption, false).option("--profile <name>", messages.profileOption, DEFAULT_PROFILE_NAME).option("--project <project-uuid>", messages.projectOption).action(async (commandOptions) => {
|
|
8656
9076
|
await runPublishCommand(
|
|
8657
9077
|
commandOptions,
|
|
@@ -8659,7 +9079,8 @@ function registerPublish(program, writer, cwd, createClient, description2 = "Too
|
|
|
8659
9079
|
cwd(),
|
|
8660
9080
|
runtime,
|
|
8661
9081
|
messages,
|
|
8662
|
-
scopeRegistrationMessages
|
|
9082
|
+
scopeRegistrationMessages,
|
|
9083
|
+
schemaReviewMessages
|
|
8663
9084
|
);
|
|
8664
9085
|
});
|
|
8665
9086
|
}
|
|
@@ -8679,8 +9100,8 @@ function isUrl(value) {
|
|
|
8679
9100
|
function field(meta, snake, camel) {
|
|
8680
9101
|
return snake in meta ? meta[snake] : meta[camel];
|
|
8681
9102
|
}
|
|
8682
|
-
function validateOAuthMetadata(meta, locale =
|
|
8683
|
-
const messages =
|
|
9103
|
+
function validateOAuthMetadata(meta, locale = DEFAULT_LOCALE9) {
|
|
9104
|
+
const messages = CLI_MESSAGES10[locale].oauth;
|
|
8684
9105
|
const results = [];
|
|
8685
9106
|
if (!meta || typeof meta !== "object" || Array.isArray(meta)) {
|
|
8686
9107
|
return {
|
|
@@ -8774,9 +9195,9 @@ function parseDraftOption(value, messages) {
|
|
|
8774
9195
|
}
|
|
8775
9196
|
return { toolId, versionId };
|
|
8776
9197
|
}
|
|
8777
|
-
function normalizeOAuthScopeRegisterOptions(options, locale =
|
|
9198
|
+
function normalizeOAuthScopeRegisterOptions(options, locale = DEFAULT_LOCALE9) {
|
|
8778
9199
|
const messages = OAUTH_SCOPE_REGISTRATION_MESSAGES3[locale].cli;
|
|
8779
|
-
const cliMessages =
|
|
9200
|
+
const cliMessages = CLI_MESSAGES10[locale];
|
|
8780
9201
|
const apply = options.apply === true;
|
|
8781
9202
|
if (options.yes === true && !apply) throw new UsageError(messages.yesRequiresApply);
|
|
8782
9203
|
if (apply && options.yes !== true) {
|
|
@@ -8922,7 +9343,7 @@ async function projectAccessibility(client, projectId, error) {
|
|
|
8922
9343
|
}
|
|
8923
9344
|
function localCandidateSource(normalized, cwd, runtime, locale) {
|
|
8924
9345
|
const messages = OAUTH_SCOPE_REGISTRATION_MESSAGES3[locale].cli;
|
|
8925
|
-
const publishMessages =
|
|
9346
|
+
const publishMessages = CLI_MESSAGES10[locale].publish;
|
|
8926
9347
|
const project = loadPublicationProject(runtime.loadProject, cwd, publishMessages);
|
|
8927
9348
|
const projectId = assertManifestProject(project, normalized.projectId, publishMessages);
|
|
8928
9349
|
const connectorId = normalized.connectorId ?? project.manifest.connector_id;
|
|
@@ -8951,7 +9372,7 @@ function localCandidateSource(normalized, cwd, runtime, locale) {
|
|
|
8951
9372
|
expectedToolNames: candidate.expectedToolNames
|
|
8952
9373
|
};
|
|
8953
9374
|
}
|
|
8954
|
-
async function runOAuthScopeRegisterCommand(options, writer, cwd, runtime, locale =
|
|
9375
|
+
async function runOAuthScopeRegisterCommand(options, writer, cwd, runtime, locale = DEFAULT_LOCALE9) {
|
|
8955
9376
|
const messages = OAUTH_SCOPE_REGISTRATION_MESSAGES3[locale];
|
|
8956
9377
|
const normalized = normalizeOAuthScopeRegisterOptions(options, locale);
|
|
8957
9378
|
const target = normalized.kind === "saved_drafts" ? {
|
|
@@ -9000,7 +9421,7 @@ async function runOAuthScopeRegisterCommand(options, writer, cwd, runtime, local
|
|
|
9000
9421
|
throw new OAuthScopeRegistrationCommandError(
|
|
9001
9422
|
"AP_NETWORK_ERROR",
|
|
9002
9423
|
"secure_random_invalid",
|
|
9003
|
-
|
|
9424
|
+
CLI_MESSAGES10[locale].publish.failure("secure_random_invalid")
|
|
9004
9425
|
);
|
|
9005
9426
|
}
|
|
9006
9427
|
let applied;
|
|
@@ -9030,7 +9451,7 @@ function upstreamOAuthWizardUrl(profile, projectId, connectorId) {
|
|
|
9030
9451
|
return url.toString();
|
|
9031
9452
|
}
|
|
9032
9453
|
async function loadOAuthMetadata(opts, locale) {
|
|
9033
|
-
const messages =
|
|
9454
|
+
const messages = CLI_MESSAGES10[locale];
|
|
9034
9455
|
if (opts.file && opts.issuer) {
|
|
9035
9456
|
throw new UsageError("--file \u3068 --issuer \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093");
|
|
9036
9457
|
}
|
|
@@ -9047,7 +9468,7 @@ async function loadOAuthMetadata(opts, locale) {
|
|
|
9047
9468
|
}
|
|
9048
9469
|
}
|
|
9049
9470
|
async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
9050
|
-
const messages =
|
|
9471
|
+
const messages = CLI_MESSAGES10[locale];
|
|
9051
9472
|
const parsed = await loadOAuthMetadata(opts, locale);
|
|
9052
9473
|
const report = validateOAuthMetadata(parsed, locale);
|
|
9053
9474
|
json(writer, report.results);
|
|
@@ -9058,8 +9479,8 @@ async function runOAuthMetadataValidate(opts, writer, locale) {
|
|
|
9058
9479
|
info(writer, messages.oauth.metadataOk);
|
|
9059
9480
|
}
|
|
9060
9481
|
}
|
|
9061
|
-
function registerOauth(program, writer, locale =
|
|
9062
|
-
const messages =
|
|
9482
|
+
function registerOauth(program, writer, locale = DEFAULT_LOCALE9, dependencies = {}) {
|
|
9483
|
+
const messages = CLI_MESSAGES10[locale];
|
|
9063
9484
|
const oauth = program.command("oauth").description(messages.oauth.commandDescription);
|
|
9064
9485
|
oauth.command("init").description(messages.oauth.initDescription).requiredOption("--provider <name>", messages.oauth.providerOption).action((opts) => {
|
|
9065
9486
|
info(writer, messages.oauth.templateHeading(opts.provider));
|
|
@@ -9207,7 +9628,7 @@ function registerOauth(program, writer, locale = DEFAULT_LOCALE7, dependencies =
|
|
|
9207
9628
|
|
|
9208
9629
|
// src/commands/openapi.ts
|
|
9209
9630
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
9210
|
-
import { resolve as
|
|
9631
|
+
import { resolve as resolve5 } from "path";
|
|
9211
9632
|
import {
|
|
9212
9633
|
importOpenApi as importOpenApi2,
|
|
9213
9634
|
OPENAPI_IMPORT_MAX_SOURCE_BYTES as OPENAPI_IMPORT_MAX_SOURCE_BYTES2,
|
|
@@ -9270,7 +9691,7 @@ async function runOpenApiImportCommand(options, writer, cwd, runtime = createOpe
|
|
|
9270
9691
|
if (normalized.apply && !/^[a-f0-9]{64}$/.test(normalized.planCommitment ?? "")) {
|
|
9271
9692
|
throw new UsageError("--apply \u306B\u306Fpreview\u3067\u5F97\u305F --plan-commitment \u304C\u5FC5\u9808\u3067\u3059");
|
|
9272
9693
|
}
|
|
9273
|
-
const snapshot = readBoundedLocalFileSnapshot(
|
|
9694
|
+
const snapshot = readBoundedLocalFileSnapshot(resolve5(cwd, normalized.file), {
|
|
9274
9695
|
maxBytes: OPENAPI_IMPORT_MAX_SOURCE_BYTES2,
|
|
9275
9696
|
root: cwd
|
|
9276
9697
|
});
|
|
@@ -9358,15 +9779,15 @@ function registerOpenApi(program, writer, cwd, runtime = createOpenApiImportRunt
|
|
|
9358
9779
|
}
|
|
9359
9780
|
|
|
9360
9781
|
// src/commands/review-package.ts
|
|
9361
|
-
import { CLI_MESSAGES as
|
|
9782
|
+
import { CLI_MESSAGES as CLI_MESSAGES11, DEFAULT_LOCALE as DEFAULT_LOCALE10 } from "@andpipes/localization";
|
|
9362
9783
|
var TARGETS = ["chatgpt", "claude", "generic_mcp"];
|
|
9363
|
-
function assertTarget(value, locale =
|
|
9784
|
+
function assertTarget(value, locale = DEFAULT_LOCALE10) {
|
|
9364
9785
|
if (!TARGETS.includes(value)) {
|
|
9365
|
-
throw new UsageError(
|
|
9786
|
+
throw new UsageError(CLI_MESSAGES11[locale].reviewPackage.invalidTarget(value, TARGETS));
|
|
9366
9787
|
}
|
|
9367
9788
|
}
|
|
9368
|
-
function registerReviewPackage(program, writer, locale =
|
|
9369
|
-
const messages =
|
|
9789
|
+
function registerReviewPackage(program, writer, locale = DEFAULT_LOCALE10, cwd = () => process.cwd()) {
|
|
9790
|
+
const messages = CLI_MESSAGES11[locale];
|
|
9370
9791
|
const reviewPackage = program.command("review-package").description(messages.reviewPackage.commandDescription);
|
|
9371
9792
|
reviewPackage.command("generate").description(messages.reviewPackage.generateDescription).requiredOption("--project <project>", messages.common.projectOption).requiredOption("--package-version <version>", messages.reviewPackage.packageVersionOption).option("--target <target>", messages.reviewPackage.targetOption).option(
|
|
9372
9793
|
"--from-template",
|
|
@@ -9427,69 +9848,13 @@ function registerReviewPackage(program, writer, locale = DEFAULT_LOCALE8, cwd =
|
|
|
9427
9848
|
});
|
|
9428
9849
|
}
|
|
9429
9850
|
|
|
9430
|
-
// src/commands/validate.ts
|
|
9431
|
-
import { existsSync as existsSync2 } from "fs";
|
|
9432
|
-
import { resolve as resolve5 } from "path";
|
|
9433
|
-
import {
|
|
9434
|
-
CLI_MESSAGES as CLI_MESSAGES11,
|
|
9435
|
-
DEFAULT_LOCALE as DEFAULT_LOCALE9,
|
|
9436
|
-
LOCALIZED_TEXT as LOCALIZED_TEXT3
|
|
9437
|
-
} from "@andpipes/localization";
|
|
9438
|
-
function resolveContractPath(file, cwd, locale = DEFAULT_LOCALE9) {
|
|
9439
|
-
const messages = CLI_MESSAGES11[locale].validate;
|
|
9440
|
-
if (file) {
|
|
9441
|
-
const abs = resolve5(cwd, file);
|
|
9442
|
-
if (!existsSync2(abs)) {
|
|
9443
|
-
throw new UsageError(messages.fileNotFound(file));
|
|
9444
|
-
}
|
|
9445
|
-
return abs;
|
|
9446
|
-
}
|
|
9447
|
-
for (const candidate of CONTRACT_FILENAMES) {
|
|
9448
|
-
const abs = resolve5(cwd, candidate);
|
|
9449
|
-
if (existsSync2(abs)) {
|
|
9450
|
-
return abs;
|
|
9451
|
-
}
|
|
9452
|
-
}
|
|
9453
|
-
throw new UsageError(messages.defaultFileNotFound(CONTRACT_FILENAMES));
|
|
9454
|
-
}
|
|
9455
|
-
function loadContract(path, locale = DEFAULT_LOCALE9) {
|
|
9456
|
-
void locale;
|
|
9457
|
-
return loadContractFile(path).contract;
|
|
9458
|
-
}
|
|
9459
|
-
function registerValidate(program, writer, cwd, locale = DEFAULT_LOCALE9) {
|
|
9460
|
-
const text = LOCALIZED_TEXT3[locale].cli;
|
|
9461
|
-
const messages = CLI_MESSAGES11[locale].validate;
|
|
9462
|
-
program.command("validate").description(`${text.validateDescription} (10 checks)`).option("--file <path>", messages.fileOption).action((opts) => {
|
|
9463
|
-
const path = resolveContractPath(opts.file, cwd(), locale);
|
|
9464
|
-
const loaded = loadContractFile(path);
|
|
9465
|
-
const report = loaded.report;
|
|
9466
|
-
const publishGate = loaded.publishGate;
|
|
9467
|
-
json(writer, { checks: report.results, publishGate });
|
|
9468
|
-
const fail2 = report.results.filter((r) => r.status === "fail").length;
|
|
9469
|
-
const pending = report.results.filter((r) => r.status === "pending").length;
|
|
9470
|
-
const pass = report.results.filter((r) => r.status === "pass").length;
|
|
9471
|
-
info(
|
|
9472
|
-
writer,
|
|
9473
|
-
`${text.resultLabel}: pass=${pass} fail=${fail2} pending=${pending} (pending=${text.backendPending})`
|
|
9474
|
-
);
|
|
9475
|
-
info(
|
|
9476
|
-
writer,
|
|
9477
|
-
messages.publishGateSummary(publishGate.errors.length, publishGate.warnings.length)
|
|
9478
|
-
);
|
|
9479
|
-
if (!report.ok || !publishGate.ok) {
|
|
9480
|
-
process.exitCode = 1;
|
|
9481
|
-
info(writer, messages.failed);
|
|
9482
|
-
}
|
|
9483
|
-
});
|
|
9484
|
-
}
|
|
9485
|
-
|
|
9486
9851
|
// src/cli.ts
|
|
9487
9852
|
function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale = normalizeLocale(process.env.ANDPIPE_LOCALE ?? process.env.LANG)) {
|
|
9488
9853
|
const text = LOCALIZED_TEXT4[locale].cli;
|
|
9489
9854
|
const messages = CLI_MESSAGES12[locale];
|
|
9490
9855
|
const scopeRegistrationMessages = OAUTH_SCOPE_REGISTRATION_MESSAGES4[locale].cli;
|
|
9491
9856
|
const program = new Command();
|
|
9492
|
-
program.name(CLI_NAME).description(text.description).option("--locale <locale>", messages.localeOption,
|
|
9857
|
+
program.name(CLI_NAME).description(text.description).option("--locale <locale>", messages.localeOption, DEFAULT_LOCALE11).version(readVersion());
|
|
9493
9858
|
registerAuth(program, writer, locale);
|
|
9494
9859
|
registerAuditExport(program, writer, locale);
|
|
9495
9860
|
registerInit(
|
|
@@ -9512,6 +9877,7 @@ function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale
|
|
|
9512
9877
|
registerDoctor(program, writer, locale);
|
|
9513
9878
|
registerLogs(program, writer, locale);
|
|
9514
9879
|
registerTemplate(program, writer, cwd);
|
|
9880
|
+
registerMuse(program, writer, cwd, locale);
|
|
9515
9881
|
registerPublish(
|
|
9516
9882
|
program,
|
|
9517
9883
|
writer,
|
|
@@ -9520,7 +9886,8 @@ function buildProgram(writer = defaultWriter, cwd = () => process.cwd(), locale
|
|
|
9520
9886
|
text.publishDescription,
|
|
9521
9887
|
void 0,
|
|
9522
9888
|
messages.publish,
|
|
9523
|
-
scopeRegistrationMessages
|
|
9889
|
+
scopeRegistrationMessages,
|
|
9890
|
+
PUBLICATION_SCHEMA_REVIEW_CLI_MESSAGES2[locale]
|
|
9524
9891
|
);
|
|
9525
9892
|
return program;
|
|
9526
9893
|
}
|
|
@@ -9629,6 +9996,8 @@ export {
|
|
|
9629
9996
|
normalizeInitOptions,
|
|
9630
9997
|
runInitCommand,
|
|
9631
9998
|
registerInit,
|
|
9999
|
+
resolveContractPath,
|
|
10000
|
+
loadContract,
|
|
9632
10001
|
PublishCommandError,
|
|
9633
10002
|
createPublishCommandRuntime,
|
|
9634
10003
|
normalizePublishOptions,
|
|
@@ -9641,8 +10010,6 @@ export {
|
|
|
9641
10010
|
createOpenApiImportRuntime,
|
|
9642
10011
|
runOpenApiImportCommand,
|
|
9643
10012
|
registerOpenApi,
|
|
9644
|
-
resolveContractPath,
|
|
9645
|
-
loadContract,
|
|
9646
10013
|
buildProgram,
|
|
9647
10014
|
runCli,
|
|
9648
10015
|
packageName
|