agent-first-data 0.26.1 → 0.27.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/README.md +2 -2
- package/assets/cli-help-v2.schema.json +115 -0
- package/assets/cli-spec-v1.schema.json +334 -0
- package/assets/protocol-v1.schema.json +140 -29
- package/dist/cli.d.ts +3 -22
- package/dist/cli.js +7 -109
- package/dist/format.d.ts +27 -9
- package/dist/format.js +189 -66
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/assets/cli-help-v1.schema.json +0 -227
package/dist/cli.d.ts
CHANGED
|
@@ -105,8 +105,8 @@ export declare class CliEmitter {
|
|
|
105
105
|
private readonly format;
|
|
106
106
|
private readonly outputOptions;
|
|
107
107
|
private terminalEmitted;
|
|
108
|
-
private logFieldsProvider?;
|
|
109
108
|
private diagnostic?;
|
|
109
|
+
private strictProtocol;
|
|
110
110
|
/**
|
|
111
111
|
* Create an event-stream emitter: every event, including `error`, goes to the
|
|
112
112
|
* single `writer`. Use CliEmitter.finite for a one-shot command that should
|
|
@@ -136,7 +136,6 @@ export declare class CliEmitter {
|
|
|
136
136
|
* stderr); "stdout"/"stderr" are event-stream mode onto that one stream.
|
|
137
137
|
*/
|
|
138
138
|
static fromOutputTo(selector: OutputTo, format: OutputFormat, outputOptions?: OutputOptions): CliEmitter;
|
|
139
|
-
withLogFields(provider: () => Record<string, JsonValue>): this;
|
|
140
139
|
/**
|
|
141
140
|
* Select the sink for an event by `kind`. Finite mode (a diagnostic sink is
|
|
142
141
|
* present) keeps `result` on the primary writer (stdout) and routes
|
|
@@ -144,6 +143,8 @@ export declare class CliEmitter {
|
|
|
144
143
|
* mode (no diagnostic sink) keeps every event on the single writer.
|
|
145
144
|
*/
|
|
146
145
|
private sinkFor;
|
|
146
|
+
/** Opt this emitter into the AFDATA recommended strict profile. */
|
|
147
|
+
withStrictProtocol(): this;
|
|
147
148
|
emit(event: Event): void;
|
|
148
149
|
emitValidatedValue(value: JsonValue): void;
|
|
149
150
|
private static isBrokenPipe;
|
|
@@ -181,26 +182,6 @@ export declare function buildCliVersion(name: string, displayName: string | unde
|
|
|
181
182
|
* conventional-text path — `format` is required.
|
|
182
183
|
*/
|
|
183
184
|
export declare function cliRenderVersion(name: string, displayName: string | undefined, version: string, build: string | undefined, format: OutputFormat): string;
|
|
184
|
-
/**
|
|
185
|
-
* Render version output if --version/-V is present; otherwise return undefined.
|
|
186
|
-
* Throws for malformed version requests, for example `--version --output xml`.
|
|
187
|
-
*
|
|
188
|
-
* The one blessed behavior: `--version` always answers with a protocol-v1
|
|
189
|
-
* `kind:"result"` version event. An explicit `--output` wins; otherwise
|
|
190
|
-
* `defaultOutput` should be the command's normal output default.
|
|
191
|
-
*
|
|
192
|
-
* `valueFlags` is the caller's own value-taking global long flags (with or
|
|
193
|
-
* without leading dashes; the leading dashes are stripped internally). It is the
|
|
194
|
-
* TS analog of Rust's `&clap::Command`: the pre-parser consults it so a global
|
|
195
|
-
* flag's space-separated value (e.g. `--log request,startup`) is never mistaken
|
|
196
|
-
* for the subcommand boundary, which would hide a later `--version`/`--output`.
|
|
197
|
-
*
|
|
198
|
-
* Only a top-level version request is recognized: scanning stops at the first
|
|
199
|
-
* positional argument (the subcommand) or `--`, so `tool sub --version <value>`
|
|
200
|
-
* leaves `--version` for the subcommand's parser rather than printing the
|
|
201
|
-
* tool version.
|
|
202
|
-
*/
|
|
203
|
-
export declare function cliHandleVersionOrContinue(rawArgs: string[], valueFlags: string[], name: string, displayName: string | undefined, version: string, build: string | undefined, defaultOutput?: OutputFormat): string | undefined;
|
|
204
185
|
/**
|
|
205
186
|
* Build a standard CLI parse error value. This function cannot fail.
|
|
206
187
|
* Use when flag parsing fails or a flag value is invalid.
|
package/dist/cli.js
CHANGED
|
@@ -141,8 +141,8 @@ export class CliEmitter {
|
|
|
141
141
|
format;
|
|
142
142
|
outputOptions;
|
|
143
143
|
terminalEmitted = false;
|
|
144
|
-
logFieldsProvider;
|
|
145
144
|
diagnostic;
|
|
145
|
+
strictProtocol = false;
|
|
146
146
|
/**
|
|
147
147
|
* Create an event-stream emitter: every event, including `error`, goes to the
|
|
148
148
|
* single `writer`. Use CliEmitter.finite for a one-shot command that should
|
|
@@ -189,10 +189,6 @@ export class CliEmitter {
|
|
|
189
189
|
const writer = selector === "stdout" ? processStdoutWriter : processStderrWriter;
|
|
190
190
|
return CliEmitter.stream(writer, format, outputOptions);
|
|
191
191
|
}
|
|
192
|
-
withLogFields(provider) {
|
|
193
|
-
this.logFieldsProvider = provider;
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
192
|
/**
|
|
197
193
|
* Select the sink for an event by `kind`. Finite mode (a diagnostic sink is
|
|
198
194
|
* present) keeps `result` on the primary writer (stdout) and routes
|
|
@@ -202,9 +198,14 @@ export class CliEmitter {
|
|
|
202
198
|
sinkFor(kind) {
|
|
203
199
|
return kind !== "result" && this.diagnostic ? this.diagnostic : this.writer;
|
|
204
200
|
}
|
|
201
|
+
/** Opt this emitter into the AFDATA recommended strict profile. */
|
|
202
|
+
withStrictProtocol() {
|
|
203
|
+
this.strictProtocol = true;
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
205
206
|
emit(event) {
|
|
206
207
|
const jsonValue = event.toJSON();
|
|
207
|
-
validateProtocolEvent(jsonValue);
|
|
208
|
+
validateProtocolEvent(jsonValue, this.strictProtocol);
|
|
208
209
|
const kind = jsonValue.kind;
|
|
209
210
|
if (kind === "log" || kind === "progress") {
|
|
210
211
|
if (this.terminalEmitted) {
|
|
@@ -301,109 +302,6 @@ export function cliRenderVersion(name, displayName, version, build, format) {
|
|
|
301
302
|
const rendered = render(buildCliVersion(name, displayName, version, build), format);
|
|
302
303
|
return `${rendered.replace(/\n+$/u, "")}\n`;
|
|
303
304
|
}
|
|
304
|
-
/**
|
|
305
|
-
* Split a flag argument into its long name (leading dashes stripped, any
|
|
306
|
-
* `=value` suffix dropped) and inline value. Returns `undefined` name for a
|
|
307
|
-
* non-flag or the bare `-`. `--output=` yields an empty-string inline value.
|
|
308
|
-
*/
|
|
309
|
-
function splitFlag(arg) {
|
|
310
|
-
if (!arg.startsWith("-") || arg === "-")
|
|
311
|
-
return { name: undefined, inlineValue: undefined };
|
|
312
|
-
const eq = arg.indexOf("=");
|
|
313
|
-
const flag = eq === -1 ? arg : arg.slice(0, eq);
|
|
314
|
-
const inlineValue = eq === -1 ? undefined : arg.slice(eq + 1);
|
|
315
|
-
const name = flag.replace(/^-+/u, "");
|
|
316
|
-
if (name === "")
|
|
317
|
-
return { name: undefined, inlineValue: undefined };
|
|
318
|
-
return { name, inlineValue };
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Render version output if --version/-V is present; otherwise return undefined.
|
|
322
|
-
* Throws for malformed version requests, for example `--version --output xml`.
|
|
323
|
-
*
|
|
324
|
-
* The one blessed behavior: `--version` always answers with a protocol-v1
|
|
325
|
-
* `kind:"result"` version event. An explicit `--output` wins; otherwise
|
|
326
|
-
* `defaultOutput` should be the command's normal output default.
|
|
327
|
-
*
|
|
328
|
-
* `valueFlags` is the caller's own value-taking global long flags (with or
|
|
329
|
-
* without leading dashes; the leading dashes are stripped internally). It is the
|
|
330
|
-
* TS analog of Rust's `&clap::Command`: the pre-parser consults it so a global
|
|
331
|
-
* flag's space-separated value (e.g. `--log request,startup`) is never mistaken
|
|
332
|
-
* for the subcommand boundary, which would hide a later `--version`/`--output`.
|
|
333
|
-
*
|
|
334
|
-
* Only a top-level version request is recognized: scanning stops at the first
|
|
335
|
-
* positional argument (the subcommand) or `--`, so `tool sub --version <value>`
|
|
336
|
-
* leaves `--version` for the subcommand's parser rather than printing the
|
|
337
|
-
* tool version.
|
|
338
|
-
*/
|
|
339
|
-
export function cliHandleVersionOrContinue(rawArgs, valueFlags, name, displayName, version, build, defaultOutput = "json") {
|
|
340
|
-
const valueFlagSet = new Set(valueFlags.map((flag) => flag.replace(/^-+/u, "")));
|
|
341
|
-
let versionRequested = false;
|
|
342
|
-
let outputFormat;
|
|
343
|
-
let outputError;
|
|
344
|
-
for (let i = 0; i < rawArgs.length;) {
|
|
345
|
-
const arg = rawArgs[i];
|
|
346
|
-
if (arg === "--")
|
|
347
|
-
break;
|
|
348
|
-
// The first positional argument marks the subcommand boundary. Past it,
|
|
349
|
-
// --version and -V belong to the subcommand's own parser, matching
|
|
350
|
-
// git/cargo/clap: this pre-parser only owns a top-level version request.
|
|
351
|
-
if (!arg.startsWith("-"))
|
|
352
|
-
break;
|
|
353
|
-
const { name: flagName, inlineValue } = splitFlag(arg);
|
|
354
|
-
if (arg === "--version") {
|
|
355
|
-
versionRequested = true;
|
|
356
|
-
i += 1;
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
// `--output-to` takes a value but does not affect version text output.
|
|
360
|
-
// Consume its space-separated value so it is not mistaken for the
|
|
361
|
-
// subcommand boundary (which would hide a later `--version`/`--output`).
|
|
362
|
-
if (flagName === "output-to") {
|
|
363
|
-
const hasSpaceValue = inlineValue === undefined && rawArgs[i + 1] !== undefined && !rawArgs[i + 1].startsWith("-");
|
|
364
|
-
i += hasSpaceValue ? 2 : 1;
|
|
365
|
-
continue;
|
|
366
|
-
}
|
|
367
|
-
if (flagName === "output") {
|
|
368
|
-
let value;
|
|
369
|
-
if (inlineValue !== undefined) {
|
|
370
|
-
value = inlineValue;
|
|
371
|
-
}
|
|
372
|
-
else if (rawArgs[i + 1] !== undefined && !rawArgs[i + 1].startsWith("-")) {
|
|
373
|
-
value = rawArgs[i + 1];
|
|
374
|
-
}
|
|
375
|
-
if (value === undefined) {
|
|
376
|
-
outputError = new Error("missing value for --output: expected json, yaml, or plain");
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
try {
|
|
380
|
-
const parsedOutput = cliParseOutput(value);
|
|
381
|
-
if (outputFormat !== undefined && outputFormat !== parsedOutput) {
|
|
382
|
-
outputError = new Error(`conflicting output formats: --output ${value} conflicts with previous output format`);
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
outputFormat = parsedOutput;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
catch (e) {
|
|
389
|
-
outputError = e;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
i += inlineValue !== undefined || value === undefined ? 1 : 2;
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
// Any other flag: consult the caller's own value-taking global flags so a
|
|
396
|
-
// flag's space-separated value is never mistaken for the subcommand
|
|
397
|
-
// boundary above.
|
|
398
|
-
const hasSpaceValue = inlineValue === undefined && rawArgs[i + 1] !== undefined && !rawArgs[i + 1].startsWith("-");
|
|
399
|
-
i += hasSpaceValue && flagName !== undefined && valueFlagSet.has(flagName) ? 2 : 1;
|
|
400
|
-
}
|
|
401
|
-
if (!versionRequested)
|
|
402
|
-
return undefined;
|
|
403
|
-
if (outputError !== undefined)
|
|
404
|
-
throw outputError;
|
|
405
|
-
return cliRenderVersion(name, displayName, version, build, outputFormat ?? defaultOutput);
|
|
406
|
-
}
|
|
407
305
|
/**
|
|
408
306
|
* Build a standard CLI parse error value. This function cannot fail.
|
|
409
307
|
* Use when flag parsing fails or a flag value is invalid.
|
package/dist/format.d.ts
CHANGED
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
* precision integers, high-precision floats, exponent forms, "-0") survives
|
|
13
13
|
* decode. Parsed numbers become LosslessNumber internally; every JSON/YAML
|
|
14
14
|
* rendering path here treats it as an opaque scalar leaf (never destructured
|
|
15
|
-
* as a plain object) and re-emits its exact literal text.
|
|
16
|
-
*
|
|
15
|
+
* as a plain object) and re-emits its exact literal text. Native bigint values
|
|
16
|
+
* are also supported so callers can render integers beyond Number's safe
|
|
17
|
+
* range without first corrupting them.
|
|
17
18
|
*/
|
|
18
|
-
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
19
|
+
export type JsonValue = string | number | bigint | boolean | null | JsonValue[] | {
|
|
19
20
|
[key: string]: JsonValue;
|
|
20
21
|
};
|
|
21
22
|
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
@@ -125,7 +126,14 @@ export declare class EventDecodeError extends Error {
|
|
|
125
126
|
* return a typed decoded event.
|
|
126
127
|
*/
|
|
127
128
|
export declare function decodeProtocolEvent(text: string): DecodedEvent;
|
|
128
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Which fields a redaction pass scrubs. The default is `All`.
|
|
131
|
+
*
|
|
132
|
+
* The policy selects a *scope* inside a structured value. A command line
|
|
133
|
+
* (`redactArgv`) and a bare URL string (`redactUrlSecrets`) have no
|
|
134
|
+
* result/trace split to scope to, so on those two paths `TraceOnly` redacts in
|
|
135
|
+
* full like `All`, and only `Off` turns redaction off.
|
|
136
|
+
*/
|
|
129
137
|
export declare enum RedactionPolicy {
|
|
130
138
|
All = "All",
|
|
131
139
|
TraceOnly = "TraceOnly",
|
|
@@ -182,14 +190,21 @@ export declare function redactedValue(value: unknown, options?: {
|
|
|
182
190
|
* Redact secret components of a single URL string.
|
|
183
191
|
*
|
|
184
192
|
* A query parameter is redacted iff its (form-decoded) name ends in
|
|
185
|
-
* _secret/_SECRET or matches an exact entry in secretNames.
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
193
|
+
* _secret/_SECRET or matches an exact entry in secretNames. A fragment written
|
|
194
|
+
* in the same `k=v&k=v` shape — how an OAuth implicit-flow response carries its
|
|
195
|
+
* token — is redacted by that same rule; any other fragment passes through
|
|
196
|
+
* byte-for-byte. The userinfo password (scheme://user:pass@host) is always
|
|
197
|
+
* redacted as a structural rule. Only the secret spans are replaced with "***";
|
|
198
|
+
* every other byte is preserved. A string that is not a single,
|
|
199
|
+
* whitespace-free, scheme-prefixed URL (including a URL embedded in surrounding
|
|
200
|
+
* prose) is returned unchanged.
|
|
201
|
+
*
|
|
202
|
+
* A URL is unscoped input: `RedactionPolicy.Off` returns it unchanged, every
|
|
203
|
+
* other policy redacts it in full.
|
|
190
204
|
*/
|
|
191
205
|
export declare function redactUrlSecrets(url: string, options?: {
|
|
192
206
|
secretNames?: readonly string[];
|
|
207
|
+
policy?: RedactionPolicy;
|
|
193
208
|
}): string;
|
|
194
209
|
/**
|
|
195
210
|
* Redact secret values out of a command line.
|
|
@@ -211,6 +226,9 @@ export declare function redactUrlSecrets(url: string, options?: {
|
|
|
211
226
|
* Intended for CLIs that record their own invocation — startup diagnostics,
|
|
212
227
|
* audit trails, crash reports — where writing argv verbatim would put a
|
|
213
228
|
* credential in the log.
|
|
229
|
+
*
|
|
230
|
+
* A command line is unscoped input: `RedactionPolicy.Off` returns `args`
|
|
231
|
+
* unchanged, every other policy redacts in full.
|
|
214
232
|
*/
|
|
215
233
|
export declare function redactArgv(args: readonly string[], options?: {
|
|
216
234
|
secretNames?: readonly string[];
|