@salesforce/b2c-tooling-sdk 2.3.0 → 2.5.0
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/data/guides/enrichment.json +291 -0
- package/data/guides/index.json +426 -37
- package/data/schemas/dw.schema.json +590 -0
- package/data/tooling/index.json +18 -9
- package/dist/esm/cli/base-command.d.ts +20 -1
- package/dist/esm/cli/base-command.js +61 -11
- package/dist/esm/cli/base-command.js.map +1 -1
- package/dist/esm/cli/cartridge-command.js +2 -1
- package/dist/esm/cli/cartridge-command.js.map +1 -1
- package/dist/esm/cli/command-search.d.ts +85 -0
- package/dist/esm/cli/command-search.js +147 -0
- package/dist/esm/cli/command-search.js.map +1 -0
- package/dist/esm/cli/config.d.ts +10 -1
- package/dist/esm/cli/config.js +18 -9
- package/dist/esm/cli/config.js.map +1 -1
- package/dist/esm/cli/hooks.d.ts +13 -0
- package/dist/esm/cli/hooks.js +11 -0
- package/dist/esm/cli/hooks.js.map +1 -1
- package/dist/esm/cli/index.d.ts +2 -0
- package/dist/esm/cli/index.js +2 -0
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/cli/instance-command.d.ts +1 -0
- package/dist/esm/cli/instance-command.js +2 -1
- package/dist/esm/cli/instance-command.js.map +1 -1
- package/dist/esm/cli/mrt-command.d.ts +3 -2
- package/dist/esm/cli/mrt-command.js +4 -4
- package/dist/esm/cli/mrt-command.js.map +1 -1
- package/dist/esm/cli/oauth-command.d.ts +1 -0
- package/dist/esm/cli/ods-command.d.ts +1 -0
- package/dist/esm/cli/webdav-command.d.ts +1 -0
- package/dist/esm/clients/custom-apis.d.ts +36 -2
- package/dist/esm/clients/custom-apis.js +57 -4
- package/dist/esm/clients/custom-apis.js.map +1 -1
- package/dist/esm/clients/index.d.ts +1 -1
- package/dist/esm/clients/index.js +1 -1
- package/dist/esm/clients/index.js.map +1 -1
- package/dist/esm/clients/scapi-backend-utils.d.ts +15 -0
- package/dist/esm/clients/scapi-backend-utils.js +28 -1
- package/dist/esm/clients/scapi-backend-utils.js.map +1 -1
- package/dist/esm/clients/scapi-fallback-backend.js +2 -2
- package/dist/esm/clients/scapi-fallback-backend.js.map +1 -1
- package/dist/esm/clients/scapi-schemas.generated.d.ts +2 -2
- package/dist/esm/compat/dispatcher.js +2 -2
- package/dist/esm/compat/dispatcher.js.map +1 -1
- package/dist/esm/config/config-origins.d.ts +19 -0
- package/dist/esm/config/config-origins.js +11 -0
- package/dist/esm/config/config-origins.js.map +1 -0
- package/dist/esm/config/config-write.d.ts +86 -0
- package/dist/esm/config/config-write.js +296 -0
- package/dist/esm/config/config-write.js.map +1 -0
- package/dist/esm/config/dw-json-schema.d.ts +14 -0
- package/dist/esm/config/dw-json-schema.js +269 -0
- package/dist/esm/config/dw-json-schema.js.map +1 -0
- package/dist/esm/config/dw-json.d.ts +2 -0
- package/dist/esm/config/dw-json.js +10 -6
- package/dist/esm/config/dw-json.js.map +1 -1
- package/dist/esm/config/index.d.ts +13 -4
- package/dist/esm/config/index.js +8 -3
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/instance-manager.d.ts +64 -28
- package/dist/esm/config/instance-manager.js +145 -63
- package/dist/esm/config/instance-manager.js.map +1 -1
- package/dist/esm/config/mapping.d.ts +5 -0
- package/dist/esm/config/mapping.js +20 -1
- package/dist/esm/config/mapping.js.map +1 -1
- package/dist/esm/config/project-environment.d.ts +62 -0
- package/dist/esm/config/project-environment.js +113 -0
- package/dist/esm/config/project-environment.js.map +1 -1
- package/dist/esm/config/resolver.d.ts +22 -0
- package/dist/esm/config/resolver.js +106 -37
- package/dist/esm/config/resolver.js.map +1 -1
- package/dist/esm/config/sources/dw-json-source.d.ts +9 -1
- package/dist/esm/config/sources/dw-json-source.js +59 -23
- package/dist/esm/config/sources/dw-json-source.js.map +1 -1
- package/dist/esm/config/sources/env-source.d.ts +70 -9
- package/dist/esm/config/sources/env-source.js +205 -47
- package/dist/esm/config/sources/env-source.js.map +1 -1
- package/dist/esm/config/sources/index.d.ts +1 -1
- package/dist/esm/config/sources/index.js +1 -1
- package/dist/esm/config/sources/index.js.map +1 -1
- package/dist/esm/config/types.d.ts +53 -3
- package/dist/esm/docs/search.js +3 -1
- package/dist/esm/docs/search.js.map +1 -1
- package/dist/esm/docs/types.d.ts +3 -1
- package/dist/esm/guidance/bundle.d.ts +33 -0
- package/dist/esm/guidance/bundle.js +268 -0
- package/dist/esm/guidance/bundle.js.map +1 -0
- package/dist/esm/guidance/catalog.d.ts +8 -1
- package/dist/esm/guidance/catalog.js +48 -6
- package/dist/esm/guidance/catalog.js.map +1 -1
- package/dist/esm/guidance/index.d.ts +1 -0
- package/dist/esm/guidance/index.js +1 -0
- package/dist/esm/guidance/index.js.map +1 -1
- package/dist/esm/guidance/types.d.ts +17 -1
- package/dist/esm/guidance/types.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operations/jobs/run-system-job.js +2 -2
- package/dist/esm/operations/jobs/run-system-job.js.map +1 -1
- package/dist/esm/plugins/discovery.js +2 -1
- package/dist/esm/plugins/discovery.js.map +1 -1
- package/dist/esm/scapi/catalog.d.ts +5 -2
- package/dist/esm/scapi/catalog.js.map +1 -1
- package/dist/esm/scapi/index.d.ts +6 -2
- package/dist/esm/scapi/index.js +4 -2
- package/dist/esm/scapi/index.js.map +1 -1
- package/dist/esm/scapi/live.d.ts +14 -3
- package/dist/esm/scapi/live.js +33 -5
- package/dist/esm/scapi/live.js.map +1 -1
- package/dist/esm/scapi/local.d.ts +26 -0
- package/dist/esm/scapi/local.js +143 -0
- package/dist/esm/scapi/local.js.map +1 -0
- package/dist/esm/scapi/request.d.ts +2 -2
- package/dist/esm/scapi/request.js +4 -2
- package/dist/esm/scapi/request.js.map +1 -1
- package/dist/esm/scapi/runtime.d.ts +5 -0
- package/dist/esm/scapi/runtime.js.map +1 -1
- package/dist/esm/scapi/schema-source.d.ts +90 -0
- package/dist/esm/scapi/schema-source.js +146 -0
- package/dist/esm/scapi/schema-source.js.map +1 -0
- package/dist/esm/scapi/worker-source.js +31 -7
- package/dist/esm/scapi/worker-source.js.map +1 -1
- package/dist/esm/telemetry/telemetry.d.ts +1 -0
- package/dist/esm/telemetry/telemetry.js +18 -1
- package/dist/esm/telemetry/telemetry.js.map +1 -1
- package/dist/esm/telemetry/types.d.ts +9 -0
- package/dist/esm/test-utils/config-isolation.js +21 -15
- package/dist/esm/test-utils/config-isolation.js.map +1 -1
- package/dist/esm/ux/agent-context.d.ts +69 -0
- package/dist/esm/ux/agent-context.js +133 -0
- package/dist/esm/ux/agent-context.js.map +1 -0
- package/dist/esm/ux/confirm.d.ts +27 -0
- package/dist/esm/ux/confirm.js +32 -0
- package/dist/esm/ux/confirm.js.map +1 -1
- package/dist/esm/ux/index.d.ts +2 -1
- package/dist/esm/ux/index.js +2 -1
- package/dist/esm/ux/index.js.map +1 -1
- package/node_modules/@salesforce/b2c-api-schemas/manifest.json +83 -42
- package/node_modules/@salesforce/b2c-api-schemas/package.json +1 -1
- package/node_modules/@salesforce/b2c-api-schemas/scapi/cdn/zones/v1.json +6798 -238
- package/node_modules/@salesforce/b2c-api-schemas/scapi/checkout/orders/v1.json +2296 -205
- package/node_modules/@salesforce/b2c-api-schemas/scapi/checkout/shopper-baskets/v1.json +5571 -666
- package/node_modules/@salesforce/b2c-api-schemas/scapi/checkout/shopper-baskets/v2.json +6062 -371
- package/node_modules/@salesforce/b2c-api-schemas/scapi/checkout/shopper-orders/v1.json +3426 -360
- package/node_modules/@salesforce/b2c-api-schemas/scapi/checkout/shopper-payments/v1.json +351 -99
- package/node_modules/@salesforce/b2c-api-schemas/scapi/configuration/cors/v1.json +172 -12
- package/node_modules/@salesforce/b2c-api-schemas/scapi/configuration/preferences/v1.json +1497 -111
- package/node_modules/@salesforce/b2c-api-schemas/scapi/configuration/shopper-configurations/v1.json +202 -36
- package/node_modules/@salesforce/b2c-api-schemas/scapi/configuration/timeouts/v1.json +79 -10
- package/node_modules/@salesforce/b2c-api-schemas/scapi/custom-object/custom-objects/v1.json +785 -49
- package/node_modules/@salesforce/b2c-api-schemas/scapi/custom-object/shopper-custom-objects/v1.json +191 -40
- package/node_modules/@salesforce/b2c-api-schemas/scapi/customer/customers/v1.json +1483 -107
- package/node_modules/@salesforce/b2c-api-schemas/scapi/customer/shopper-customers/v1.json +4854 -787
- package/node_modules/@salesforce/b2c-api-schemas/scapi/dx/custom-apis/v1.json +119 -15
- package/node_modules/@salesforce/b2c-api-schemas/scapi/dx/object-definitions/v1.json +1699 -80
- package/node_modules/@salesforce/b2c-api-schemas/scapi/dx/scapi-schemas/v1.json +252 -18
- package/node_modules/@salesforce/b2c-api-schemas/scapi/dx/scripts/v1.json +329 -23
- package/node_modules/@salesforce/b2c-api-schemas/scapi/experience/experiences/v1.json +4208 -234
- package/node_modules/@salesforce/b2c-api-schemas/scapi/experience/shopper-experience/v1.json +1591 -247
- package/node_modules/@salesforce/b2c-api-schemas/scapi/intelligence/analytics/v1.json +396 -8
- package/node_modules/@salesforce/b2c-api-schemas/scapi/inventory/availability/v1.json +1242 -69
- package/node_modules/@salesforce/b2c-api-schemas/scapi/inventory/impex/v1.json +2354 -248
- package/node_modules/@salesforce/b2c-api-schemas/scapi/inventory/reservation/v1.json +1550 -45
- package/node_modules/@salesforce/b2c-api-schemas/scapi/inventory/segmentation/v1.json +6615 -0
- package/node_modules/@salesforce/b2c-api-schemas/scapi/merchant/roles/v1.json +1520 -59
- package/node_modules/@salesforce/b2c-api-schemas/scapi/merchant/users/v1.json +397 -17
- package/node_modules/@salesforce/b2c-api-schemas/scapi/observability/metrics/v1.json +1241 -27
- package/node_modules/@salesforce/b2c-api-schemas/scapi/operation/jobs/v1.json +1069 -68
- package/node_modules/@salesforce/b2c-api-schemas/scapi/operation/replications/v1.json +410 -23
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/assignments/v1.json +502 -102
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/campaigns/v1.json +1112 -94
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/coupons/v1.json +820 -93
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/gift-certificates/v1.json +845 -92
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/promotions/v1.json +2716 -674
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/shopper-gift-certificates/v1.json +130 -47
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/shopper-promotions/v1.json +233 -63
- package/node_modules/@salesforce/b2c-api-schemas/scapi/pricing/source-code-groups/v1.json +630 -70
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/catalogs/v1.json +2886 -348
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/inventory-lists/v1.json +520 -19
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/price-books/v1.json +3115 -293
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/products/v1.json +3313 -138
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/shopper-availability/v1.json +266 -52
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/shopper-delivery-estimates/v1.json +256 -48
- package/node_modules/@salesforce/b2c-api-schemas/scapi/product/shopper-products/v1.json +1744 -306
- package/node_modules/@salesforce/b2c-api-schemas/scapi/search/shopper-search/v1.json +1661 -120
- package/node_modules/@salesforce/b2c-api-schemas/scapi/shopper/auth/v1.json +2174 -118
- package/node_modules/@salesforce/b2c-api-schemas/scapi/shopper/auth-admin/v1.json +1373 -24
- package/node_modules/@salesforce/b2c-api-schemas/scapi/shopper/consents/v1.json +531 -20
- package/node_modules/@salesforce/b2c-api-schemas/scapi/shopper/shopper-agents/v1.json +154 -6
- package/node_modules/@salesforce/b2c-api-schemas/scapi/shopper/shopper-consents/v1.json +596 -79
- package/node_modules/@salesforce/b2c-api-schemas/scapi/shopper/shopper-context/v1.json +456 -42
- package/node_modules/@salesforce/b2c-api-schemas/scapi/site/seo/v1.json +101 -23
- package/node_modules/@salesforce/b2c-api-schemas/scapi/site/shopper-seo/v1.json +184 -41
- package/node_modules/@salesforce/b2c-api-schemas/scapi/site/sites/v1.json +995 -47
- package/node_modules/@salesforce/b2c-api-schemas/scapi/store/shopper-stores/v1.json +370 -67
- package/node_modules/@salesforce/b2c-api-schemas/scapi/store/store-redirect-mappings/v1.json +319 -11
- package/node_modules/@salesforce/b2c-api-schemas/scapi/store/stores/v1.json +1109 -64
- package/node_modules/@salesforce/b2c-api-schemas/scapi/storefront/deployments/v1.json +1442 -0
- package/node_modules/@salesforce/b2c-api-schemas/scapi/storefront/environments/v1.json +4293 -0
- package/node_modules/@salesforce/b2c-api-schemas/scapi/storefront/storefronts/v1.json +1371 -0
- package/package.json +5 -2
- package/specs/scapi-schemas-v1.yaml +4 -1
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2
|
|
4
4
|
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { randomBytes } from 'node:crypto';
|
|
6
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { AppInsightsClient } from './app-insights-client.js';
|
|
10
10
|
import { getLogger } from '../logging/index.js';
|
|
11
|
+
import { getAgentContext } from '../ux/agent-context.js';
|
|
11
12
|
const generateRandomId = () => randomBytes(20).toString('hex');
|
|
12
13
|
/**
|
|
13
14
|
* Best-effort detection of a CI / non-interactive automation environment.
|
|
@@ -38,6 +39,19 @@ function detectCI() {
|
|
|
38
39
|
env.BITBUCKET_BUILD_NUMBER ||
|
|
39
40
|
env.CODEBUILD_BUILD_ID);
|
|
40
41
|
}
|
|
42
|
+
function buildAgentAttributes(cliId) {
|
|
43
|
+
const context = getAgentContext();
|
|
44
|
+
if (!context.isAgentic || !context.harness)
|
|
45
|
+
return { isAgent: false };
|
|
46
|
+
const attributes = { isAgent: true, agent: context.harness.id };
|
|
47
|
+
if (context.sessionId) {
|
|
48
|
+
attributes.agentSessionKey = createHash('sha256')
|
|
49
|
+
.update(`b2c-agent-session-v1\0${cliId}\0${context.harness.id}\0${context.sessionId}`)
|
|
50
|
+
.digest('hex')
|
|
51
|
+
.slice(0, 32);
|
|
52
|
+
}
|
|
53
|
+
return attributes;
|
|
54
|
+
}
|
|
41
55
|
/**
|
|
42
56
|
* Sanitize attributes to only include string, number, boolean (App Insights–safe).
|
|
43
57
|
* Aligns with sf CLI telemetry record() validation.
|
|
@@ -147,6 +161,7 @@ export class Telemetry {
|
|
|
147
161
|
flushIntervalMs;
|
|
148
162
|
flushTimer;
|
|
149
163
|
isCI;
|
|
164
|
+
agentAttributes;
|
|
150
165
|
/**
|
|
151
166
|
* Check if telemetry is disabled via environment variables.
|
|
152
167
|
* Supports both SF_DISABLE_TELEMETRY (sf CLI standard) and SFCC_DISABLE_TELEMETRY.
|
|
@@ -175,6 +190,7 @@ export class Telemetry {
|
|
|
175
190
|
this.version = options.version ?? '0.0.0';
|
|
176
191
|
this.flushIntervalMs = options.flushIntervalMs;
|
|
177
192
|
this.isCI = detectCI();
|
|
193
|
+
this.agentAttributes = buildAgentAttributes(this.cliId);
|
|
178
194
|
if (process.env.SFCC_TELEMETRY_LOG === 'true') {
|
|
179
195
|
this.traceLog = getLogger().child({ component: 'telemetry' });
|
|
180
196
|
}
|
|
@@ -309,6 +325,7 @@ export class Telemetry {
|
|
|
309
325
|
timestamp: String(Date.now()),
|
|
310
326
|
processUptime: process.uptime() * 1000,
|
|
311
327
|
isCI: this.isCI,
|
|
328
|
+
...this.agentAttributes,
|
|
312
329
|
};
|
|
313
330
|
}
|
|
314
331
|
createClient() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../src/telemetry/telemetry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;
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E,2EAA2E;QAC3E,+CAA+C;QAC/C,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,cAAwB,CAAC,CAAC;QAEpE,oCAAoC;QACpC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7D,sDAAsD;QACtD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;QAEhE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -36,6 +36,15 @@ export interface TelemetryEventProperties extends TelemetryAttributes {
|
|
|
36
36
|
* can otherwise dominate volume and skew blended KPIs.
|
|
37
37
|
*/
|
|
38
38
|
isCI: boolean;
|
|
39
|
+
/** Whether the event originated from a process driven by an AI coding agent. */
|
|
40
|
+
isAgent: boolean;
|
|
41
|
+
/** Detected agent harness id (e.g. `claude-code`), when {@link isAgent} is true. */
|
|
42
|
+
agent?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Salted, truncated hash of the agent harness session id, for grouping events
|
|
45
|
+
* from one agent session. The raw session id is never sent.
|
|
46
|
+
*/
|
|
47
|
+
agentSessionKey?: string;
|
|
39
48
|
}
|
|
40
49
|
/**
|
|
41
50
|
* Options for creating a Telemetry instance.
|
|
@@ -3,46 +3,52 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2
|
|
4
4
|
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
6
9
|
import { resetLogger } from '../logging/index.js';
|
|
7
|
-
const ADDITIONAL_ENV_VARS = ['COMMERCE_API_SLAS_SECRET', 'LANGUAGE', 'NO_COLOR'];
|
|
10
|
+
const ADDITIONAL_ENV_VARS = ['B2C_CONFIG_DIR', 'COMMERCE_API_SLAS_SECRET', 'LANGUAGE', 'NO_COLOR'];
|
|
11
|
+
function isIsolatedEnvVar(key) {
|
|
12
|
+
return (key.startsWith('SFCC_') || key.startsWith('MRT_') || key.startsWith('PUBLIC__') || ADDITIONAL_ENV_VARS.includes(key));
|
|
13
|
+
}
|
|
8
14
|
let state = null;
|
|
9
15
|
export function isolateConfig() {
|
|
10
16
|
if (state)
|
|
11
17
|
throw new Error('isolateConfig() called without cleanup - call restoreConfig() first');
|
|
12
18
|
const savedEnvVars = {};
|
|
13
19
|
for (const key of Object.keys(process.env)) {
|
|
14
|
-
if (
|
|
20
|
+
if (isIsolatedEnvVar(key)) {
|
|
15
21
|
savedEnvVars[key] = process.env[key];
|
|
16
22
|
delete process.env[key];
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
|
-
for (const key of ADDITIONAL_ENV_VARS) {
|
|
20
|
-
savedEnvVars[key] = process.env[key];
|
|
21
|
-
delete process.env[key];
|
|
22
|
-
}
|
|
23
25
|
process.env.SFCC_CONFIG = '/dev/null';
|
|
26
|
+
// Commands load no .env during tests
|
|
27
|
+
process.env.SFCC_DOTENV_FILE = '';
|
|
24
28
|
process.env.MRT_CREDENTIALS_FILE = '/dev/null';
|
|
25
29
|
process.env.SFCC_LOG_LEVEL = 'silent';
|
|
30
|
+
// An empty settings directory, so the user's global default dw.json is never read or written
|
|
31
|
+
const configDirectory = mkdtempSync(path.join(tmpdir(), 'b2c-test-config-'));
|
|
32
|
+
process.env.B2C_CONFIG_DIR = configDirectory;
|
|
26
33
|
// Reset global logger so it picks up the new SFCC_LOG_LEVEL
|
|
27
34
|
resetLogger();
|
|
28
|
-
state = { savedEnvVars };
|
|
35
|
+
state = { configDirectory, savedEnvVars };
|
|
29
36
|
}
|
|
30
37
|
export function restoreConfig() {
|
|
31
38
|
if (!state)
|
|
32
39
|
return;
|
|
33
40
|
// Reset logger before restoring env vars
|
|
34
41
|
resetLogger();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (const [key, value] of Object.entries(state.savedEnvVars)) {
|
|
39
|
-
if (value === undefined) {
|
|
42
|
+
// Drop anything the test set, not just the variables isolateConfig() replaced
|
|
43
|
+
for (const key of Object.keys(process.env)) {
|
|
44
|
+
if (isIsolatedEnvVar(key))
|
|
40
45
|
delete process.env[key];
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
}
|
|
47
|
+
for (const [key, value] of Object.entries(state.savedEnvVars)) {
|
|
48
|
+
if (value !== undefined)
|
|
43
49
|
process.env[key] = value;
|
|
44
|
-
}
|
|
45
50
|
}
|
|
51
|
+
rmSync(state.configDirectory, { recursive: true, force: true });
|
|
46
52
|
state = null;
|
|
47
53
|
}
|
|
48
54
|
//# sourceMappingURL=config-isolation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-isolation.js","sourceRoot":"","sources":["../../../src/test-utils/config-isolation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAEhD,MAAM,mBAAmB,GAAG,CAAC,0BAA0B,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"config-isolation.js","sourceRoot":"","sources":["../../../src/test-utils/config-isolation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAC/B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAEhD,MAAM,mBAAmB,GAAG,CAAC,gBAAgB,EAAE,0BAA0B,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAEnG,SAAS,gBAAgB,CAAC,GA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AAI,CAAC,KAAK;QAAE,OAAO;IAEnB,yCAAyC;IACzC,WAAW,EAAE,CAAC;IAEd,8EAA8E;IAC9E,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,IAAI,gBAAgB,CAAC,GAAG,CAAC;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9D,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACpD,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;IAE9D,KAAK,GAAG,IAAI,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort detection of AI coding agent harnesses (Claude Code, Cursor,
|
|
3
|
+
* Codex, etc.) from the environment of the current process.
|
|
4
|
+
*
|
|
5
|
+
* Detection is advisory: it tailors help output, disables interactive prompts,
|
|
6
|
+
* and attributes telemetry. It must never block or fail a command.
|
|
7
|
+
*
|
|
8
|
+
* Detection relies only on environment variables that harnesses set for their
|
|
9
|
+
* child processes. Users can override detection with `SFCC_AGENT`:
|
|
10
|
+
*
|
|
11
|
+
* - `SFCC_AGENT=<name>` forces agent mode and reports `<name>` as the harness
|
|
12
|
+
* - `SFCC_AGENT=0` (or `false`/`no`/`off`) disables detection entirely
|
|
13
|
+
*
|
|
14
|
+
* @module ux/agent-context
|
|
15
|
+
*/
|
|
16
|
+
/** An AI coding agent harness (the tool driving the CLI). */
|
|
17
|
+
export interface AgentHarness {
|
|
18
|
+
/** Stable identifier (e.g. `claude-code`). */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Human-readable name (e.g. `Claude Code`). */
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
23
|
+
/** A single detector match. */
|
|
24
|
+
export interface AgentMatch {
|
|
25
|
+
harness: AgentHarness;
|
|
26
|
+
/** Harness session/thread/conversation identifier, when exposed. */
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
/** Environment variable names that produced the match. */
|
|
29
|
+
signals: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** Result of agent detection. */
|
|
32
|
+
export interface AgentContext {
|
|
33
|
+
/** True when any harness was detected (or forced via `SFCC_AGENT`). */
|
|
34
|
+
isAgentic: boolean;
|
|
35
|
+
/** Highest-precedence harness, or null. */
|
|
36
|
+
harness: AgentHarness | null;
|
|
37
|
+
/** First available session identifier across matches, or null. */
|
|
38
|
+
sessionId: null | string;
|
|
39
|
+
/** All matches in precedence order. */
|
|
40
|
+
matches: readonly AgentMatch[];
|
|
41
|
+
}
|
|
42
|
+
export type AgentEnvironment = Readonly<Record<string, string | undefined>>;
|
|
43
|
+
export type AgentDetector = (env: AgentEnvironment) => AgentMatch | null;
|
|
44
|
+
/**
|
|
45
|
+
* Detectors in precedence order. Direct agents precede host surfaces so that,
|
|
46
|
+
* for example, Claude Code launched inside Warp is reported as Claude Code
|
|
47
|
+
* while the Warp match is retained in `matches`.
|
|
48
|
+
*/
|
|
49
|
+
export declare const agentDetectors: readonly AgentDetector[];
|
|
50
|
+
/**
|
|
51
|
+
* Detects whether the current process is being driven by an AI coding agent.
|
|
52
|
+
*
|
|
53
|
+
* @param env - Environment to inspect (defaults to `process.env`)
|
|
54
|
+
* @param detectors - Detectors in precedence order (defaults to {@link agentDetectors})
|
|
55
|
+
*/
|
|
56
|
+
export declare function detectAgentContext(env?: AgentEnvironment, detectors?: readonly AgentDetector[]): AgentContext;
|
|
57
|
+
/**
|
|
58
|
+
* Cached {@link detectAgentContext} for `process.env`. The environment of a
|
|
59
|
+
* process does not change in ways relevant to detection, so detect once.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getAgentContext(): AgentContext;
|
|
62
|
+
/** Clears the cached agent context (for tests). */
|
|
63
|
+
export declare function resetAgentContext(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Whether interactive prompts can be shown: stdin is a TTY and the process is
|
|
66
|
+
* not driven by an AI agent (agents typically cannot answer prompts, and
|
|
67
|
+
* hanging on one wastes the agent's turn).
|
|
68
|
+
*/
|
|
69
|
+
export declare function isInteractive(): boolean;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, Salesforce, Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2
|
|
4
|
+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
*/
|
|
6
|
+
const FALSE_LIKE_VALUES = new Set(['', '0', 'false', 'no', 'off']);
|
|
7
|
+
/** Returns the trimmed value, treating false-like values as unset. */
|
|
8
|
+
function value(env, name) {
|
|
9
|
+
const raw = env[name];
|
|
10
|
+
if (typeof raw !== 'string')
|
|
11
|
+
return undefined;
|
|
12
|
+
const normalized = raw.trim();
|
|
13
|
+
return FALSE_LIKE_VALUES.has(normalized.toLowerCase()) ? undefined : normalized;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds a detector that matches when any marker env var equals its expected
|
|
17
|
+
* value (or is set to any truthy value when `expected` is omitted).
|
|
18
|
+
*/
|
|
19
|
+
function markerDetector(harness, markers, sessionVars = []) {
|
|
20
|
+
return (env) => {
|
|
21
|
+
const signals = [];
|
|
22
|
+
for (const { name, expected } of markers) {
|
|
23
|
+
const matched = expected === undefined ? value(env, name) !== undefined : env[name] === expected;
|
|
24
|
+
if (matched)
|
|
25
|
+
signals.push(name);
|
|
26
|
+
}
|
|
27
|
+
if (signals.length === 0)
|
|
28
|
+
return null;
|
|
29
|
+
let sessionId;
|
|
30
|
+
for (const name of sessionVars) {
|
|
31
|
+
const v = value(env, name);
|
|
32
|
+
if (v) {
|
|
33
|
+
signals.push(name);
|
|
34
|
+
sessionId ??= v;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { harness, sessionId, signals };
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Detectors in precedence order. Direct agents precede host surfaces so that,
|
|
42
|
+
* for example, Claude Code launched inside Warp is reported as Claude Code
|
|
43
|
+
* while the Warp match is retained in `matches`.
|
|
44
|
+
*/
|
|
45
|
+
export const agentDetectors = [
|
|
46
|
+
markerDetector({ id: 'opencode', name: 'OpenCode' }, [{ name: 'OPENCODE', expected: '1' }]),
|
|
47
|
+
markerDetector({ id: 'qwen-code', name: 'Qwen Code' }, [{ name: 'QWEN_CODE_SESSION_ID' }], ['QWEN_CODE_SESSION_ID']),
|
|
48
|
+
markerDetector({ id: 'pi', name: 'Pi' }, [
|
|
49
|
+
{ name: 'PI_CODING_AGENT', expected: 'true' },
|
|
50
|
+
{ name: 'AI_AGENT', expected: 'pi' },
|
|
51
|
+
], ['PI_SESSION_ID']),
|
|
52
|
+
markerDetector({ id: 'cursor-agent', name: 'Cursor Agent' }, [{ name: 'CURSOR_AGENT', expected: '1' }], ['CURSOR_CONVERSATION_ID']),
|
|
53
|
+
markerDetector({ id: 'claude-code', name: 'Claude Code' }, [{ name: 'CLAUDECODE', expected: '1' }], ['CLAUDE_CODE_SESSION_ID']),
|
|
54
|
+
markerDetector({ id: 'codex', name: 'OpenAI Codex' }, [{ name: 'CODEX_THREAD_ID' }], ['CODEX_THREAD_ID']),
|
|
55
|
+
markerDetector({ id: 'amp', name: 'Amp' }, [{ name: 'AMP_CURRENT_THREAD_ID' }], ['AMP_CURRENT_THREAD_ID']),
|
|
56
|
+
markerDetector({ id: 'gemini-cli', name: 'Gemini CLI' }, [{ name: 'GEMINI_CLI', expected: '1' }]),
|
|
57
|
+
markerDetector({ id: 'auggie', name: 'Auggie' }, [{ name: 'AUGMENT_AGENT', expected: '1' }]),
|
|
58
|
+
markerDetector({ id: 'crush', name: 'Crush' }, [
|
|
59
|
+
{ name: 'CRUSH', expected: '1' },
|
|
60
|
+
{ name: 'AI_AGENT', expected: 'crush' },
|
|
61
|
+
]),
|
|
62
|
+
markerDetector({ id: 'vscode-copilot-agent', name: 'GitHub Copilot in VS Code' }, [
|
|
63
|
+
{ name: 'AI_AGENT', expected: 'github_copilot_vscode_agent' },
|
|
64
|
+
{ name: 'COPILOT_AGENT', expected: '1' },
|
|
65
|
+
]),
|
|
66
|
+
markerDetector({ id: 'warp', name: 'Warp' }, [{ name: 'OZ_RUN_ID' }], ['OZ_RUN_ID']),
|
|
67
|
+
];
|
|
68
|
+
const NOT_AGENTIC = { isAgentic: false, harness: null, sessionId: null, matches: [] };
|
|
69
|
+
/** Normalizes a user-supplied agent name into an id (lowercase, dash-separated). */
|
|
70
|
+
function toAgentId(name) {
|
|
71
|
+
return (name
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.replaceAll(/[^a-z0-9]+/g, '-')
|
|
74
|
+
.replaceAll(/^-|-$/g, '') || 'custom');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Detects whether the current process is being driven by an AI coding agent.
|
|
78
|
+
*
|
|
79
|
+
* @param env - Environment to inspect (defaults to `process.env`)
|
|
80
|
+
* @param detectors - Detectors in precedence order (defaults to {@link agentDetectors})
|
|
81
|
+
*/
|
|
82
|
+
export function detectAgentContext(env = process.env, detectors = agentDetectors) {
|
|
83
|
+
const override = env.SFCC_AGENT;
|
|
84
|
+
if (override !== undefined) {
|
|
85
|
+
const forced = value(env, 'SFCC_AGENT');
|
|
86
|
+
if (!forced)
|
|
87
|
+
return NOT_AGENTIC;
|
|
88
|
+
// Values like "1"/"true" force agent mode without naming a harness.
|
|
89
|
+
const generic = ['1', 'true', 'yes', 'on'].includes(forced.toLowerCase());
|
|
90
|
+
const harness = generic ? { id: 'unknown', name: 'Unknown agent' } : { id: toAgentId(forced), name: forced };
|
|
91
|
+
const match = { harness, signals: ['SFCC_AGENT'] };
|
|
92
|
+
return { isAgentic: true, harness, sessionId: null, matches: [match] };
|
|
93
|
+
}
|
|
94
|
+
const matches = [];
|
|
95
|
+
for (const detector of detectors) {
|
|
96
|
+
try {
|
|
97
|
+
const match = detector(env);
|
|
98
|
+
if (match)
|
|
99
|
+
matches.push(match);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Detection is advisory and must never prevent a command from running.
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
isAgentic: matches.length > 0,
|
|
107
|
+
harness: matches[0]?.harness ?? null,
|
|
108
|
+
sessionId: matches.find((m) => m.sessionId)?.sessionId ?? null,
|
|
109
|
+
matches,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
let cached;
|
|
113
|
+
/**
|
|
114
|
+
* Cached {@link detectAgentContext} for `process.env`. The environment of a
|
|
115
|
+
* process does not change in ways relevant to detection, so detect once.
|
|
116
|
+
*/
|
|
117
|
+
export function getAgentContext() {
|
|
118
|
+
cached ??= detectAgentContext();
|
|
119
|
+
return cached;
|
|
120
|
+
}
|
|
121
|
+
/** Clears the cached agent context (for tests). */
|
|
122
|
+
export function resetAgentContext() {
|
|
123
|
+
cached = undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Whether interactive prompts can be shown: stdin is a TTY and the process is
|
|
127
|
+
* not driven by an AI agent (agents typically cannot answer prompts, and
|
|
128
|
+
* hanging on one wastes the agent's turn).
|
|
129
|
+
*/
|
|
130
|
+
export function isInteractive() {
|
|
131
|
+
return Boolean(process.stdin.isTTY) && !getAgentContext().isAgentic;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=agent-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-context.js","sourceRoot":"","sources":["../../../src/ux/agent-context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;A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B,IAAI,KAAK;gBAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,uEAAuE;QACzE,CAAC;IACH,CAAC;IAED,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,IAAI;QACpC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,SAAS,IAAI,IAAI;QAC9D,OAAO;KACR,CAAC;AACJ,CAAC;AAED,IAAI,MAAgC,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,kBAAkB,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,iBAAiB;IAC/B,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,SAAS,CAAC;AACtE,CAAC"}
|
package/dist/esm/ux/confirm.d.ts
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
export interface ConfirmOptions {
|
|
2
2
|
/** Default to yes when the user presses Enter without typing. Defaults to false (no). */
|
|
3
3
|
defaultYes?: boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Behavior when prompting is not possible (no TTY on stdin, or an AI agent
|
|
6
|
+
* is driving the process):
|
|
7
|
+
*
|
|
8
|
+
* - `'error'` (default): throw {@link ConfirmationRequiredError} so the
|
|
9
|
+
* command fails fast with a non-zero exit instead of hanging
|
|
10
|
+
* - `'default'`: resolve to the default answer (`defaultYes`) without prompting
|
|
11
|
+
*/
|
|
12
|
+
nonInteractive?: 'default' | 'error';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Thrown by {@link confirm} when a confirmation is required but cannot be
|
|
16
|
+
* prompted for. Callers should skip the prompt with an explicit flag
|
|
17
|
+
* (typically `--force` or `--yes`).
|
|
18
|
+
*/
|
|
19
|
+
export declare class ConfirmationRequiredError extends Error {
|
|
20
|
+
/** The confirmation message that could not be prompted. */
|
|
21
|
+
readonly prompt: string;
|
|
22
|
+
readonly code = "CONFIRMATION_REQUIRED";
|
|
23
|
+
constructor(
|
|
24
|
+
/** The confirmation message that could not be prompted. */
|
|
25
|
+
prompt: string);
|
|
4
26
|
}
|
|
5
27
|
/**
|
|
6
28
|
* Simple yes/no confirmation prompt.
|
|
7
29
|
*
|
|
8
30
|
* Output goes to stderr so it doesn't interfere with structured stdout output.
|
|
9
31
|
*
|
|
32
|
+
* When prompting is not possible (stdin is not a TTY, or an AI agent is
|
|
33
|
+
* detected), this throws {@link ConfirmationRequiredError} by default rather
|
|
34
|
+
* than waiting on input that will never arrive. See {@link ConfirmOptions.nonInteractive}.
|
|
35
|
+
*
|
|
10
36
|
* @param message - Prompt message (the hint is appended automatically)
|
|
11
37
|
* @param options - Options to control default behavior
|
|
12
38
|
* @returns true if user confirmed, false otherwise
|
|
39
|
+
* @throws ConfirmationRequiredError when prompting is not possible and `nonInteractive` is `'error'`
|
|
13
40
|
*/
|
|
14
41
|
export declare function confirm(message: string, options?: ConfirmOptions): Promise<boolean>;
|
package/dist/esm/ux/confirm.js
CHANGED
|
@@ -4,17 +4,49 @@
|
|
|
4
4
|
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
5
|
*/
|
|
6
6
|
import * as readline from 'node:readline';
|
|
7
|
+
import { getAgentContext, isInteractive } from './agent-context.js';
|
|
8
|
+
/**
|
|
9
|
+
* Thrown by {@link confirm} when a confirmation is required but cannot be
|
|
10
|
+
* prompted for. Callers should skip the prompt with an explicit flag
|
|
11
|
+
* (typically `--force` or `--yes`).
|
|
12
|
+
*/
|
|
13
|
+
export class ConfirmationRequiredError extends Error {
|
|
14
|
+
prompt;
|
|
15
|
+
code = 'CONFIRMATION_REQUIRED';
|
|
16
|
+
constructor(
|
|
17
|
+
/** The confirmation message that could not be prompted. */
|
|
18
|
+
prompt) {
|
|
19
|
+
const agent = getAgentContext().harness;
|
|
20
|
+
const reason = agent
|
|
21
|
+
? `running under an AI agent (${agent.name}), so interactive prompts are disabled`
|
|
22
|
+
: 'no interactive terminal is available';
|
|
23
|
+
super(`Confirmation required but ${reason}:\n ${prompt.trim()}\n` +
|
|
24
|
+
`Re-run with the command's --force (or --yes) flag to proceed without prompting.`);
|
|
25
|
+
this.prompt = prompt;
|
|
26
|
+
this.name = 'ConfirmationRequiredError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
7
29
|
/**
|
|
8
30
|
* Simple yes/no confirmation prompt.
|
|
9
31
|
*
|
|
10
32
|
* Output goes to stderr so it doesn't interfere with structured stdout output.
|
|
11
33
|
*
|
|
34
|
+
* When prompting is not possible (stdin is not a TTY, or an AI agent is
|
|
35
|
+
* detected), this throws {@link ConfirmationRequiredError} by default rather
|
|
36
|
+
* than waiting on input that will never arrive. See {@link ConfirmOptions.nonInteractive}.
|
|
37
|
+
*
|
|
12
38
|
* @param message - Prompt message (the hint is appended automatically)
|
|
13
39
|
* @param options - Options to control default behavior
|
|
14
40
|
* @returns true if user confirmed, false otherwise
|
|
41
|
+
* @throws ConfirmationRequiredError when prompting is not possible and `nonInteractive` is `'error'`
|
|
15
42
|
*/
|
|
16
43
|
export async function confirm(message, options) {
|
|
17
44
|
const defaultYes = options?.defaultYes ?? false;
|
|
45
|
+
if (!isInteractive()) {
|
|
46
|
+
if (options?.nonInteractive === 'default')
|
|
47
|
+
return defaultYes;
|
|
48
|
+
throw new ConfirmationRequiredError(message);
|
|
49
|
+
}
|
|
18
50
|
const hint = defaultYes ? '(Y/n)' : '(y/N)';
|
|
19
51
|
const rl = readline.createInterface({
|
|
20
52
|
input: process.stdin,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirm.js","sourceRoot":"","sources":["../../../src/ux/confirm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"confirm.js","sourceRoot":"","sources":["../../../src/ux/confirm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAgBlE;;;;GAIG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAKvC;IAJF,IAAI,GAAG,uBAAuB,CAAC;IAExC;IACE,2DAA2D;IAClD,MAAc;QAEvB,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC,OAAO,CAAC;QACxC,MAAM,MAAM,GAAG,KAAK;YAClB,CAAC,CAAC,8BAA8B,KAAK,CAAC,IAAI,wCAAwC;YAClF,CAAC,CAAC,sCAAsC,CAAC;QAC3C,KAAK,CACH,6BAA6B,MAAM,QAAQ,MAAM,CAAC,IAAI,EAAE,IAAI;YAC1D,iFAAiF,CACpF,CAAC;QATO,WAAM,GAAN,MAAM,CAAQ;QAUvB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,OAAwB;IACrE,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;IAEhD,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;QACrB,IAAI,OAAO,EAAE,cAAc,KAAK,SAAS;YAAE,OAAO,UAAU,CAAC;QAC7D,MAAM,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IAE5C,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,EAAE,CAAC,QAAQ,CAAC,GAAG,OAAO,IAAI,IAAI,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE;YAC5C,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YAC/C,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;gBACtB,OAAO,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,KAAK,CAAC,CAAC;YACtD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/ux/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { confirm, type ConfirmOptions } from './confirm.js';
|
|
1
|
+
export { confirm, ConfirmationRequiredError, type ConfirmOptions } from './confirm.js';
|
|
2
|
+
export { agentDetectors, detectAgentContext, getAgentContext, isInteractive, resetAgentContext, type AgentContext, type AgentDetector, type AgentEnvironment, type AgentHarness, type AgentMatch, } from './agent-context.js';
|
package/dist/esm/ux/index.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2
|
|
4
4
|
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
5
|
*/
|
|
6
|
-
export { confirm } from './confirm.js';
|
|
6
|
+
export { confirm, ConfirmationRequiredError } from './confirm.js';
|
|
7
|
+
export { agentDetectors, detectAgentContext, getAgentContext, isInteractive, resetAgentContext, } from './agent-context.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/ux/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ux/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,OAAO,EAAsB,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ux/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,OAAO,EAAE,yBAAyB,EAAsB,MAAM,cAAc,CAAC;AACrF,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,GAMlB,MAAM,oBAAoB,CAAC"}
|