postman-cli 1.91.0 → 1.92.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/man/postman.1 +191 -6
- package/package.json +6 -6
- package/scripts/post-npm-installation.js +202 -10
package/man/postman.1
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.TH POSTMAN 1 "2026-11-
|
|
1
|
+
.TH POSTMAN 1 "2026-11-19" "v1.92.1" "Postman CLI Manual"
|
|
2
2
|
.SH NAME
|
|
3
3
|
postman \- Command\-line companion utility for Postman
|
|
4
4
|
.SH SYNOPSIS
|
|
@@ -189,6 +189,138 @@ Examples:
|
|
|
189
189
|
$ postman status ./services/api \-\-json
|
|
190
190
|
|
|
191
191
|
|
|
192
|
+
.SS "agent"
|
|
193
|
+
Manage CLI discovery hints for coding agents and plugins.
|
|
194
|
+
|
|
195
|
+
.B Usage:
|
|
196
|
+
[options] [command]
|
|
197
|
+
|
|
198
|
+
.B Subcommands:
|
|
199
|
+
.TP
|
|
200
|
+
.B agent discovery-hints
|
|
201
|
+
Manage CLI discovery hints for coding agents in global Claude Code and Codex instructions.
|
|
202
|
+
.TP
|
|
203
|
+
.B agent plugins
|
|
204
|
+
Install, inspect, or remove Postman plugins in coding agents.
|
|
205
|
+
|
|
206
|
+
.SS "agent discovery\-hints"
|
|
207
|
+
Manage CLI discovery hints for coding agents in global Claude Code and Codex instructions.
|
|
208
|
+
|
|
209
|
+
.B Usage:
|
|
210
|
+
[options] [command]
|
|
211
|
+
|
|
212
|
+
.B Subcommands:
|
|
213
|
+
.TP
|
|
214
|
+
.B agent discovery-hints add
|
|
215
|
+
Add CLI discovery hints for agents and remember this choice.
|
|
216
|
+
.TP
|
|
217
|
+
.B agent discovery-hints status
|
|
218
|
+
Inspect CLI discovery hints for agents.
|
|
219
|
+
.TP
|
|
220
|
+
.B agent discovery-hints remove
|
|
221
|
+
Remove CLI discovery hints for agents and remember this choice.
|
|
222
|
+
|
|
223
|
+
.SS "agent discovery\-hints add"
|
|
224
|
+
Add CLI discovery hints for agents and remember this choice.
|
|
225
|
+
|
|
226
|
+
.B Usage:
|
|
227
|
+
[options]
|
|
228
|
+
|
|
229
|
+
.B Options:
|
|
230
|
+
.TP
|
|
231
|
+
.B \-\-json
|
|
232
|
+
Print machine\-readable results.
|
|
233
|
+
|
|
234
|
+
.SS "agent discovery\-hints status"
|
|
235
|
+
Inspect CLI discovery hints for agents.
|
|
236
|
+
|
|
237
|
+
.B Usage:
|
|
238
|
+
[options]
|
|
239
|
+
|
|
240
|
+
.B Options:
|
|
241
|
+
.TP
|
|
242
|
+
.B \-\-json
|
|
243
|
+
Print machine\-readable results.
|
|
244
|
+
|
|
245
|
+
.SS "agent discovery\-hints remove"
|
|
246
|
+
Remove CLI discovery hints for agents and remember this choice.
|
|
247
|
+
|
|
248
|
+
.B Usage:
|
|
249
|
+
[options]
|
|
250
|
+
|
|
251
|
+
.B Options:
|
|
252
|
+
.TP
|
|
253
|
+
.B \-\-json
|
|
254
|
+
Print machine\-readable results.
|
|
255
|
+
|
|
256
|
+
.SS "agent plugins"
|
|
257
|
+
Install, inspect, or remove Postman plugins in coding agents.
|
|
258
|
+
|
|
259
|
+
.B Usage:
|
|
260
|
+
[options] [command]
|
|
261
|
+
|
|
262
|
+
.B Subcommands:
|
|
263
|
+
.TP
|
|
264
|
+
.B agent plugins install
|
|
265
|
+
install Postman plugins.
|
|
266
|
+
.TP
|
|
267
|
+
.B agent plugins status
|
|
268
|
+
status Postman plugins.
|
|
269
|
+
.TP
|
|
270
|
+
.B agent plugins remove
|
|
271
|
+
remove Postman plugins.
|
|
272
|
+
|
|
273
|
+
.SS "agent plugins install"
|
|
274
|
+
install Postman plugins.
|
|
275
|
+
|
|
276
|
+
.B Usage:
|
|
277
|
+
[options]
|
|
278
|
+
|
|
279
|
+
.B Options:
|
|
280
|
+
.TP
|
|
281
|
+
.B \-\-agent <id>
|
|
282
|
+
Limit changes to one agent: antigravity, claude\-code, codex, copilot, cursor, factory, kimi, opencode, pi.
|
|
283
|
+
.TP
|
|
284
|
+
.B \-y, \-\-yes
|
|
285
|
+
Confirm plugin changes without prompting.
|
|
286
|
+
.TP
|
|
287
|
+
.B \-\-dry\-run
|
|
288
|
+
Preview changes without modifying agent settings.
|
|
289
|
+
.TP
|
|
290
|
+
.B \-\-timeout <ms>
|
|
291
|
+
Plugin installer timeout in milliseconds. (default: 300000)
|
|
292
|
+
|
|
293
|
+
.SS "agent plugins status"
|
|
294
|
+
status Postman plugins.
|
|
295
|
+
|
|
296
|
+
.B Usage:
|
|
297
|
+
[options]
|
|
298
|
+
|
|
299
|
+
.B Options:
|
|
300
|
+
.TP
|
|
301
|
+
.B \-\-json
|
|
302
|
+
Print machine\-readable plugin status.
|
|
303
|
+
|
|
304
|
+
.SS "agent plugins remove"
|
|
305
|
+
remove Postman plugins.
|
|
306
|
+
|
|
307
|
+
.B Usage:
|
|
308
|
+
[options]
|
|
309
|
+
|
|
310
|
+
.B Options:
|
|
311
|
+
.TP
|
|
312
|
+
.B \-\-agent <id>
|
|
313
|
+
Limit changes to one agent: antigravity, claude\-code, codex, copilot, cursor, factory, kimi, opencode, pi.
|
|
314
|
+
.TP
|
|
315
|
+
.B \-y, \-\-yes
|
|
316
|
+
Confirm plugin changes without prompting.
|
|
317
|
+
.TP
|
|
318
|
+
.B \-\-dry\-run
|
|
319
|
+
Preview changes without modifying agent settings.
|
|
320
|
+
.TP
|
|
321
|
+
.B \-\-timeout <ms>
|
|
322
|
+
Plugin installer timeout in milliseconds. (default: 300000)
|
|
323
|
+
|
|
192
324
|
.SS "feedback"
|
|
193
325
|
Submit feedback about CLI usability, gaps, and improvement suggestions.
|
|
194
326
|
|
|
@@ -4636,7 +4768,7 @@ Ctrl+C cancels the run; cancellation and timeout do not roll back completed acti
|
|
|
4636
4768
|
|
|
4637
4769
|
|
|
4638
4770
|
.SS "request"
|
|
4639
|
-
Send HTTP requests from the command line with full Postman capabilities including authentication, environment variables, assertions, retries, and detailed output control. Use `postman request grpc` for gRPC.
|
|
4771
|
+
Send HTTP requests from the command line with full Postman capabilities including authentication, environment variables, assertions, retries, and detailed output control. Use `postman request grpc` for gRPC or `postman request graphql` for GraphQL.
|
|
4640
4772
|
|
|
4641
4773
|
.B Usage:
|
|
4642
4774
|
[METHOD] <URL|request\-file> [options]
|
|
@@ -4967,6 +5099,9 @@ Examples:
|
|
|
4967
5099
|
.TP
|
|
4968
5100
|
.B request grpc
|
|
4969
5101
|
Invoke a gRPC method, or list and describe the methods a server exposes. The service definition comes from server reflection unless \-\-proto or \-\-protoset is given.
|
|
5102
|
+
.TP
|
|
5103
|
+
.B request graphql
|
|
5104
|
+
Send a GraphQL query, mutation, or subscription, or inspect its schema. Uses the same GraphQL runtime as the Postman workbench.
|
|
4970
5105
|
|
|
4971
5106
|
.SS "request grpc"
|
|
4972
5107
|
Invoke a gRPC method, or list and describe the methods a server exposes. The service definition comes from server reflection unless \-\-proto or \-\-protoset is given.
|
|
@@ -5081,6 +5216,55 @@ Exit Codes:
|
|
|
5081
5216
|
|
|
5082
5217
|
|
|
5083
5218
|
|
|
5219
|
+
.SS "request graphql"
|
|
5220
|
+
Send a GraphQL query, mutation, or subscription, or inspect its schema. Uses the same GraphQL runtime as the Postman workbench.
|
|
5221
|
+
|
|
5222
|
+
.B Usage:
|
|
5223
|
+
[options] <urlOrFile>
|
|
5224
|
+
|
|
5225
|
+
.B Options:
|
|
5226
|
+
.TP
|
|
5227
|
+
.B \-\-url <url>
|
|
5228
|
+
Override the saved endpoint URL. Supports {{variables}}.
|
|
5229
|
+
.TP
|
|
5230
|
+
.B \-\-query <query>
|
|
5231
|
+
GraphQL document, inline, @path, or \- for stdin. Overrides the saved query.
|
|
5232
|
+
.TP
|
|
5233
|
+
.B \-\-variables <json>
|
|
5234
|
+
Variables, inline JSON, @path, or \- for stdin. Overrides saved variables.
|
|
5235
|
+
.TP
|
|
5236
|
+
.B \-\-operation\-name <name>
|
|
5237
|
+
Operation to execute when a document contains multiple operations.
|
|
5238
|
+
.TP
|
|
5239
|
+
.B \-\-introspect
|
|
5240
|
+
Print the schema as SDL instead of executing a query. Scripts are skipped.
|
|
5241
|
+
.TP
|
|
5242
|
+
.B \-\-schema <pathOrUrl>
|
|
5243
|
+
Import an SDL or introspection JSON schema from a file or HTTP(S) URL. Used for query validation, or with \-\-introspect to inspect the imported schema.
|
|
5244
|
+
.TP
|
|
5245
|
+
.B \-\-script\-before\-query <script>
|
|
5246
|
+
Before\-query JavaScript, inline or @path. Supports pm.* APIs.
|
|
5247
|
+
.TP
|
|
5248
|
+
.B \-\-script\-after\-response <script>
|
|
5249
|
+
After\-response JavaScript, inline or @path. pm.test() assertions affect the exit code.
|
|
5250
|
+
.TP
|
|
5251
|
+
.B \-\-json
|
|
5252
|
+
Print response JSON, or newline\-delimited response and summary events for streams. With \-\-introspect, print introspection JSON.
|
|
5253
|
+
|
|
5254
|
+
.TP Examples:
|
|
5255
|
+
|
|
5256
|
+
Examples:
|
|
5257
|
+
postman request graphql https://api.example.com/graphql \-\-introspect
|
|
5258
|
+
postman request graphql https://api.example.com/graphql \-\-query @query.graphql \-\-variables @variables.json
|
|
5259
|
+
postman request graphql ./GetUser.request.yaml \-\-auth\-bearer\-token "{{token}}" \-e dev.json
|
|
5260
|
+
postman request graphql https://api.example.com/graphql \-\-schema schema.graphql \-\-introspect
|
|
5261
|
+
postman request graphql https://api.example.com/graphql \-\-query "subscription { updates { id } }" \-H "Accept: text/event\-stream" \-\-json
|
|
5262
|
+
|
|
5263
|
+
Shared options: \-H, \-\-auth\-<type>\-<param>, \-e, \-\-timeout, \-\-cookie\-jar, \-\-export\-cookie\-jar, \-\-response\-only, \-\-verbose, \-o. See postman request \-\-help.
|
|
5264
|
+
Auth types: apikey, basic, bearer, hawk, oauth1, oauth2, edgegrid, awsv4.
|
|
5265
|
+
Subscriptions use WebSocket by default; pass \-H "Accept: text/event\-stream" for SSE. TLS and HTTP settings inherited from request are ignored with a warning. Mutations are sent once; there are no automatic retries.
|
|
5266
|
+
|
|
5267
|
+
|
|
5084
5268
|
.SS "sdk"
|
|
5085
5269
|
Generate and manage your SDKs directly from the command line.
|
|
5086
5270
|
|
|
@@ -5487,7 +5671,7 @@ Create, run, and manage Postman mocks — in your repository or in Postman cloud
|
|
|
5487
5671
|
Generate a mock from a Postman collection, an OpenAPI file or a dataset, or a static mock from a built\-in sample shopping cart (POST /cart/items, GET /cart, POST /checkout). Writes a local mock by default, or a cloud mock with \-\-workspace. Add \-\-deploy to also make it a live mock server.
|
|
5488
5672
|
.TP
|
|
5489
5673
|
.B mock run
|
|
5490
|
-
Start a mock using its path if it lives in your repository, or its id if it lives in Postman cloud (fetched and run locally).
|
|
5674
|
+
Start a mock using its path if it lives in your repository, or its id or <slug>.mock.<teamDomain> if it lives in Postman cloud (fetched and run locally).
|
|
5491
5675
|
.TP
|
|
5492
5676
|
.B mock stop
|
|
5493
5677
|
Stop a mock started with `postman mock run` on this machine, and wait until it has exited and released its port.
|
|
@@ -5599,7 +5783,7 @@ Paths can be relative (e.g. ./my\-collection.json) or absolute (e.g. /Users/me/m
|
|
|
5599
5783
|
|
|
5600
5784
|
|
|
5601
5785
|
.SS "mock run"
|
|
5602
|
-
Start a mock using its path if it lives in your repository, or its id if it lives in Postman cloud (fetched and run locally).
|
|
5786
|
+
Start a mock using its path if it lives in your repository, or its id or <slug>.mock.<teamDomain> if it lives in Postman cloud (fetched and run locally).
|
|
5603
5787
|
|
|
5604
5788
|
.B Usage:
|
|
5605
5789
|
<mockIdOrPath>
|
|
@@ -5636,6 +5820,7 @@ Pass \-\-dataset multiple times to load several .dataset.yaml files (or director
|
|
|
5636
5820
|
.TP Examples:
|
|
5637
5821
|
|
|
5638
5822
|
Eg. postman mock run 12345678\-90ab\-cdef\-1234\-567890abcdef # by id, from Postman cloud
|
|
5823
|
+
postman mock run stripe.mock.postman # by slug and team domain, from cloud
|
|
5639
5824
|
postman mock run ./postman/mocks/orders # by path, from your repository
|
|
5640
5825
|
postman mock run ./postman/mocks/orders \-\-environment ./postman/environments/dev.environment.yaml
|
|
5641
5826
|
postman mock run ./postman/mocks/orders \-\-port auto # pick any free port
|
|
@@ -6087,7 +6272,7 @@ List the simulations in your repository or Postman cloud workspace
|
|
|
6087
6272
|
Show a simulation's details using its .sim.yaml path if it lives in your repository, or its id if it lives in Postman cloud.
|
|
6088
6273
|
.TP
|
|
6089
6274
|
.B simulation run
|
|
6090
|
-
Serve a simulation's mocks on one local port, routing each by its routeKey. Pass a .sim.yaml path (local)
|
|
6275
|
+
Serve a simulation's mocks on one local port, routing each by its routeKey. Pass a .sim.yaml path (local), a Postman simulation id, or <slug>.mock.<teamDomain> (fetched and run locally).
|
|
6091
6276
|
.TP
|
|
6092
6277
|
.B simulation stop
|
|
6093
6278
|
Stop a simulation started with `postman simulation run` on this machine, and wait until it has exited and released its port.
|
|
@@ -6221,7 +6406,7 @@ Paths can be relative (e.g. ./postman/simulations/checkout.sim.yaml) or absolute
|
|
|
6221
6406
|
|
|
6222
6407
|
|
|
6223
6408
|
.SS "simulation run"
|
|
6224
|
-
Serve a simulation's mocks on one local port, routing each by its routeKey. Pass a .sim.yaml path (local)
|
|
6409
|
+
Serve a simulation's mocks on one local port, routing each by its routeKey. Pass a .sim.yaml path (local), a Postman simulation id, or <slug>.mock.<teamDomain> (fetched and run locally).
|
|
6225
6410
|
|
|
6226
6411
|
.B Usage:
|
|
6227
6412
|
[options] <simIdOrPath>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postman-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.92.1",
|
|
4
4
|
"description": "Official Postman CLI - Command-line companion for API development, testing, and automation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postman",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"scripts/"
|
|
58
58
|
],
|
|
59
59
|
"optionalDependencies": {
|
|
60
|
-
"@postman/pm-bin-macos-arm64": "1.
|
|
61
|
-
"@postman/pm-bin-macos-x64": "1.
|
|
62
|
-
"@postman/pm-bin-linux-x64": "1.
|
|
63
|
-
"@postman/pm-bin-linux-arm64": "1.
|
|
64
|
-
"@postman/pm-bin-windows-x64": "1.
|
|
60
|
+
"@postman/pm-bin-macos-arm64": "1.92.1",
|
|
61
|
+
"@postman/pm-bin-macos-x64": "1.92.1",
|
|
62
|
+
"@postman/pm-bin-linux-x64": "1.92.1",
|
|
63
|
+
"@postman/pm-bin-linux-arm64": "1.92.1",
|
|
64
|
+
"@postman/pm-bin-windows-x64": "1.92.1"
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -20,11 +20,11 @@ const POSTMAN_INSTRUCTION =
|
|
|
20
20
|
'',
|
|
21
21
|
'Claude Code users and agents can use the Postman Plugin for Claude Code for full API lifecycle',
|
|
22
22
|
'management including documentation, collections, workspaces, environments, mocks, monitors right',
|
|
23
|
-
'from
|
|
23
|
+
'from the repository.',
|
|
24
24
|
'',
|
|
25
25
|
'Install it with:',
|
|
26
|
-
' claude plugin marketplace add anthropics/claude-plugins-official',
|
|
27
|
-
' claude plugin install postman@claude-plugins-official'
|
|
26
|
+
' `claude plugin marketplace add anthropics/claude-plugins-official`',
|
|
27
|
+
' `claude plugin install postman@claude-plugins-official`'
|
|
28
28
|
].join('\n');
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -79,7 +79,7 @@ const AGENT_CONFIGURATIONS = [
|
|
|
79
79
|
name: 'Codex',
|
|
80
80
|
configurationEnvironmentVariable: 'CODEX_HOME',
|
|
81
81
|
fallbackDirectory: '.codex',
|
|
82
|
-
instructionFileNames: ['AGENTS.
|
|
82
|
+
instructionFileNames: ['AGENTS.md']
|
|
83
83
|
}
|
|
84
84
|
];
|
|
85
85
|
|
|
@@ -247,12 +247,13 @@ function configureAgent (agentConfiguration, environment, userHome, invocationDi
|
|
|
247
247
|
|
|
248
248
|
detected = true;
|
|
249
249
|
|
|
250
|
+
const instructionFile = resolveInstructionFile(agentConfiguration, configurationRoot);
|
|
251
|
+
|
|
250
252
|
return {
|
|
251
253
|
name: agentConfiguration.name,
|
|
252
254
|
detected,
|
|
253
|
-
instruction: addPostmanInstruction(
|
|
254
|
-
|
|
255
|
-
),
|
|
255
|
+
instruction: addPostmanInstruction(instructionFile),
|
|
256
|
+
path: instructionFile,
|
|
256
257
|
errorCode: null
|
|
257
258
|
};
|
|
258
259
|
}
|
|
@@ -267,7 +268,7 @@ function configureAgent (agentConfiguration, environment, userHome, invocationDi
|
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
/**
|
|
270
|
-
* Prints
|
|
271
|
+
* Prints the instruction outcome and the path changed by the installer.
|
|
271
272
|
*
|
|
272
273
|
* @param {AgentConfigurationResult} result - Agent configuration result.
|
|
273
274
|
* @returns {void}
|
|
@@ -285,6 +286,168 @@ function printAgentResult (result) {
|
|
|
285
286
|
'the Postman CLI installation is still usable.'
|
|
286
287
|
);
|
|
287
288
|
}
|
|
289
|
+
else {
|
|
290
|
+
console.log(`${result.name}: skipped (agent configuration not detected).`);
|
|
291
|
+
}
|
|
292
|
+
if (result.path) {
|
|
293
|
+
const relative = path.relative(operatingSystem.homedir(), result.path),
|
|
294
|
+
withinHome = relative !== '..' && !relative.startsWith('..' + path.sep) && !path.isAbsolute(relative),
|
|
295
|
+
displayPath = withinHome ? (relative ? '~/' + relative.split(path.sep).join('/') : '~') : result.path;
|
|
296
|
+
|
|
297
|
+
console.log(` CLI discovery hint for agents: ${displayPath}${result.instruction === 'existing' ? ' (skipped: already present)' : ''}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @param {string} userHome - User home directory.
|
|
303
|
+
* @returns {string} Shared installer preference path.
|
|
304
|
+
*/
|
|
305
|
+
function preferenceFile (userHome = operatingSystem.homedir()) {
|
|
306
|
+
return path.join(userHome, '.postman', 'installation-preferences');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* @param {string} [userHome] - User home directory.
|
|
311
|
+
* @returns {string|null} Saved choice, or null on first install.
|
|
312
|
+
*/
|
|
313
|
+
function readPreference (userHome = operatingSystem.homedir()) {
|
|
314
|
+
try {
|
|
315
|
+
const entries = fileSystem.readFileSync(preferenceFile(userHome), 'utf8').split(/\r?\n/)
|
|
316
|
+
.filter((line) => { return line.startsWith('agent-discovery-hints='); });
|
|
317
|
+
|
|
318
|
+
if (entries.length > 1) {
|
|
319
|
+
throw new Error('Invalid agent-discovery-hints preference.');
|
|
320
|
+
}
|
|
321
|
+
if (entries.length === 1) {
|
|
322
|
+
const preference = entries[0].slice('agent-discovery-hints='.length);
|
|
323
|
+
|
|
324
|
+
if (!['enabled', 'disabled'].includes(preference)) {
|
|
325
|
+
throw new Error('Invalid agent-discovery-hints preference.');
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return preference;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
if (error.code !== 'ENOENT') {
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @param {'enabled'|'disabled'} preference - Explicit user choice.
|
|
342
|
+
* @param {string} [userHome] - User home directory.
|
|
343
|
+
* @param {'agent-discovery-hints'|'agent-plugins'} [feature='agent-discovery-hints'] - Installation choice to save.
|
|
344
|
+
* @returns {void}
|
|
345
|
+
*/
|
|
346
|
+
function savePreference (preference, userHome, feature = 'agent-discovery-hints') {
|
|
347
|
+
if (!['agent-discovery-hints', 'agent-plugins'].includes(feature)) {
|
|
348
|
+
throw new Error('Unknown installation preference.');
|
|
349
|
+
}
|
|
350
|
+
const filename = preferenceFile(userHome),
|
|
351
|
+
prefix = `${feature}=`;
|
|
352
|
+
let contents = '';
|
|
353
|
+
|
|
354
|
+
try {
|
|
355
|
+
contents = fileSystem.readFileSync(filename, 'utf8');
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
if (error.code !== 'ENOENT') {
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const retained = contents.split('\n').filter((line) => { return !line.startsWith(prefix); }).join('\n'),
|
|
364
|
+
separator = retained && !retained.endsWith('\n') ? '\n' : '';
|
|
365
|
+
|
|
366
|
+
fileSystem.mkdirSync(path.dirname(filename), { recursive: true });
|
|
367
|
+
fileSystem.writeFileSync(filename, `${retained}${separator}${prefix}${preference}\n`, { mode: 0o600 });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* @param {'add'|'status'|'remove'} action - Requested operation.
|
|
372
|
+
* @param {NodeJS.ProcessEnv} [environment] - Agent configuration overrides.
|
|
373
|
+
* @returns {{preference: string|null, agents: object[]}} Per-file outcomes.
|
|
374
|
+
*/
|
|
375
|
+
function manageAgentDiscoveryHints (action, environment = process.env) {
|
|
376
|
+
const userHome = operatingSystem.homedir(),
|
|
377
|
+
invocationDirectory = resolveInvocationDirectory(environment, userHome) || process.cwd();
|
|
378
|
+
|
|
379
|
+
if (action !== 'status') {
|
|
380
|
+
savePreference(action === 'add' ? 'enabled' : 'disabled', userHome);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const agents = AGENT_CONFIGURATIONS.flatMap((configuration) => {
|
|
384
|
+
const root = resolveAgentConfigurationRoot(configuration, environment, userHome, invocationDirectory),
|
|
385
|
+
selectedFile = resolveInstructionFile(configuration, root),
|
|
386
|
+
files = action === 'add' ? [selectedFile] :
|
|
387
|
+
configuration.instructionFileNames.map((filename) => { return path.join(root, filename); });
|
|
388
|
+
|
|
389
|
+
return files.map((filename) => {
|
|
390
|
+
try {
|
|
391
|
+
if (!isDirectory(root)) {
|
|
392
|
+
return { name: configuration.name, path: filename, status: 'skipped' };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (action === 'add') {
|
|
396
|
+
return { name: configuration.name, path: filename, status: addPostmanInstruction(filename) };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
let contents;
|
|
400
|
+
|
|
401
|
+
try {
|
|
402
|
+
contents = fileSystem.readFileSync(filename, 'utf8');
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
if (error.code === 'ENOENT') {
|
|
406
|
+
return { name: configuration.name, path: filename, status: 'absent' };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const lines = contents.split(/(?<=\n)/),
|
|
413
|
+
remaining = [];
|
|
414
|
+
let inBlock = false, found = false;
|
|
415
|
+
|
|
416
|
+
for (const line of lines) {
|
|
417
|
+
const text = line.replace(/[\r\n]+$/, '');
|
|
418
|
+
|
|
419
|
+
if (text === POSTMAN_INSTRUCTION_START) {
|
|
420
|
+
if (inBlock) { throw new Error('Malformed installation block.'); }
|
|
421
|
+
inBlock = true;
|
|
422
|
+
found = true;
|
|
423
|
+
}
|
|
424
|
+
else if (text === POSTMAN_INSTRUCTION_END) {
|
|
425
|
+
if (!inBlock) { throw new Error('Malformed installation block.'); }
|
|
426
|
+
inBlock = false;
|
|
427
|
+
}
|
|
428
|
+
else if (!inBlock && text !== POSTMAN_INSTRUCTION) {
|
|
429
|
+
remaining.push(line);
|
|
430
|
+
}
|
|
431
|
+
else if (text === POSTMAN_INSTRUCTION) {
|
|
432
|
+
found = true;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (inBlock) { throw new Error('Malformed installation block.'); }
|
|
437
|
+
if (action === 'remove' && found) {
|
|
438
|
+
fileSystem.writeFileSync(filename, remaining.join(''), 'utf8');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return { name: configuration.name, path: filename,
|
|
442
|
+
status: found ? action === 'remove' ? 'removed' : 'existing' : 'absent' };
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
return { name: configuration.name, path: filename, status: 'error', errorCode: getErrorCode(error) };
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
return { preference: readPreference(userHome), agents };
|
|
288
451
|
}
|
|
289
452
|
|
|
290
453
|
/**
|
|
@@ -334,7 +497,34 @@ function runPostInstallation (environment = process.env) {
|
|
|
334
497
|
}
|
|
335
498
|
|
|
336
499
|
const userHome = operatingSystem.homedir(),
|
|
337
|
-
invocationDirectory = resolveInvocationDirectory(environment, userHome)
|
|
500
|
+
invocationDirectory = resolveInvocationDirectory(environment, userHome);
|
|
501
|
+
|
|
502
|
+
console.log('Postman CLI is installed and can be used for API Engineering work.');
|
|
503
|
+
const force = environment.POSTMAN_CLI_FORCE === 'agent-discovery-hints',
|
|
504
|
+
skip = environment.POSTMAN_CLI_SKIP === 'agent-discovery-hints',
|
|
505
|
+
preference = readPreference(userHome);
|
|
506
|
+
|
|
507
|
+
if ((environment.POSTMAN_CLI_SKIP && !skip) || (environment.POSTMAN_CLI_FORCE && !force)) {
|
|
508
|
+
throw new Error('CLI discovery hint controls for agents must name `agent-discovery-hints`.');
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (force && skip) {
|
|
512
|
+
throw new Error('Conflicting CLI discovery hint controls for agents.');
|
|
513
|
+
}
|
|
514
|
+
if (skip) {
|
|
515
|
+
savePreference('disabled', userHome);
|
|
516
|
+
}
|
|
517
|
+
if (!force) {
|
|
518
|
+
console.log('CLI discovery hints for agents: skipped (' + (skip || preference === 'disabled' ? 'opted out' :
|
|
519
|
+
((environment.CI && !['0', 'false'].includes(environment.CI)) ||
|
|
520
|
+
environment.GITHUB_ACTIONS || environment.TF_BUILD || environment.BUILD_NUMBER) ?
|
|
521
|
+
'CI Environment detected. Use `--force agent-discovery-hints` to add' :
|
|
522
|
+
'not enabled during npm installation; set `POSTMAN_CLI_FORCE=agent-discovery-hints` to add') + ').');
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
savePreference('enabled', userHome);
|
|
527
|
+
const
|
|
338
528
|
configuredAgents = AGENT_CONFIGURATIONS.map((agentConfiguration) => {
|
|
339
529
|
return {
|
|
340
530
|
agentConfiguration,
|
|
@@ -347,7 +537,6 @@ function runPostInstallation (environment = process.env) {
|
|
|
347
537
|
};
|
|
348
538
|
});
|
|
349
539
|
|
|
350
|
-
console.log('Postman CLI is installed and can be used for API Engineering work.');
|
|
351
540
|
configuredAgents.forEach(({ configurationResult }) => {
|
|
352
541
|
try {
|
|
353
542
|
printAgentResult(configurationResult);
|
|
@@ -396,5 +585,8 @@ module.exports = {
|
|
|
396
585
|
addPostmanInstruction,
|
|
397
586
|
isGlobalInstallation,
|
|
398
587
|
resolveAgentConfigurationRoot,
|
|
588
|
+
manageAgentDiscoveryHints,
|
|
589
|
+
readPreference,
|
|
590
|
+
savePreference,
|
|
399
591
|
runPostInstallation
|
|
400
592
|
};
|