agent-first-data 0.24.0 → 0.26.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 CHANGED
@@ -17,7 +17,7 @@ console.log(render(event.toJSON(), "json"));
17
17
  console.log(render(event.toJSON(), "plain"));
18
18
  ```
19
19
 
20
- Useful names use TypeScript casing: `render`, `outputOptionsForPolicy`, `redactedValue`, `redactUrlSecrets`, `normalizeUtcOffset`, `isValidRfc3339Date`, `isValidRfc3339Time`, `isValidRfc3339`, `isValidBcp47`, `decodeProtocolEvent`, `cliParseOutput`, `cliParseLogFilters`, `buildCliError`, `buildCliVersion`, and `cliHandleVersionOrContinue`.
20
+ Useful names use TypeScript casing: `render`, `outputOptionsForPolicy`, `redactedValue`, `redactUrlSecrets`, `redactArgv`, `normalizeUtcOffset`, `isValidRfc3339Date`, `isValidRfc3339Time`, `isValidRfc3339`, `isValidBcp47`, `decodeProtocolEvent`, `cliParseOutput`, `cliParseLogFilters`, `buildCliError`, `buildCliVersion`, and `cliHandleVersionOrContinue`.
21
21
 
22
22
  ## Behavior Notes
23
23
 
@@ -26,7 +26,7 @@ Useful names use TypeScript casing: `render`, `outputOptionsForPolicy`, `redacte
26
26
  - YAML keeps original keys and values (structure-preserving, like JSON), sorting keys by UTF-16 code unit order and quoting/escaping unsafe keys and string scalars. Plain strips formatting suffixes, formats values, sorts the same way, and renders nested objects/arrays as canonical JSON.
27
27
  - Logging records use `kind:"log"` with a nested `log` payload and a separate `level` field, so error-level logs are not terminal protocol errors.
28
28
  - `buildCliError(message, hint?)` returns a strict-ready CLI error with `error.retryable:false` and `trace:{}`.
29
- - Use `cliHandleVersionOrContinue()` before argument parsing so `--version` always answers with a structured protocol-v1 `kind:"result"` version event. Explicit `--output`/`--json` wins; pass the command's normal output as `defaultOutput` (JSON when omitted), plus its value-taking global flag names.
29
+ - Use `cliHandleVersionOrContinue()` before argument parsing so `--version` always answers with a structured protocol-v1 `kind:"result"` version event. An explicit `--output` wins; pass the command's normal output as `defaultOutput` (JSON when omitted), plus its value-taking global flag names.
30
30
 
31
31
  ## Reference
32
32
 
@@ -147,7 +147,8 @@
147
147
  },
148
148
  "usage": {
149
149
  "type": "string",
150
- "minLength": 1
150
+ "minLength": 1,
151
+ "pattern": "^[^\\n\\r]+$"
151
152
  },
152
153
  "arguments": {
153
154
  "type": "array",
@@ -203,7 +204,8 @@
203
204
  },
204
205
  "usage": {
205
206
  "type": "string",
206
- "minLength": 1
207
+ "minLength": 1,
208
+ "pattern": "^[^\\n\\r]+$"
207
209
  },
208
210
  "arguments": {
209
211
  "type": "array",
package/dist/cli.d.ts CHANGED
@@ -186,7 +186,7 @@ export declare function cliRenderVersion(name: string, displayName: string | und
186
186
  * Throws for malformed version requests, for example `--version --output xml`.
187
187
  *
188
188
  * The one blessed behavior: `--version` always answers with a protocol-v1
189
- * `kind:"result"` version event. Explicit `--output`/`--json` wins; otherwise
189
+ * `kind:"result"` version event. An explicit `--output` wins; otherwise
190
190
  * `defaultOutput` should be the command's normal output default.
191
191
  *
192
192
  * `valueFlags` is the caller's own value-taking global long flags (with or
package/dist/cli.js CHANGED
@@ -322,7 +322,7 @@ function splitFlag(arg) {
322
322
  * Throws for malformed version requests, for example `--version --output xml`.
323
323
  *
324
324
  * The one blessed behavior: `--version` always answers with a protocol-v1
325
- * `kind:"result"` version event. Explicit `--output`/`--json` wins; otherwise
325
+ * `kind:"result"` version event. An explicit `--output` wins; otherwise
326
326
  * `defaultOutput` should be the command's normal output default.
327
327
  *
328
328
  * `valueFlags` is the caller's own value-taking global long flags (with or
@@ -356,16 +356,6 @@ export function cliHandleVersionOrContinue(rawArgs, valueFlags, name, displayNam
356
356
  i += 1;
357
357
  continue;
358
358
  }
359
- if (arg === "--json") {
360
- if (outputFormat !== undefined && outputFormat !== "json") {
361
- outputError = new Error("conflicting output formats: --json conflicts with previous output format");
362
- }
363
- else {
364
- outputFormat = "json";
365
- }
366
- i += 1;
367
- continue;
368
- }
369
359
  // `--output-to` takes a value but does not affect version text output.
370
360
  // Consume its space-separated value so it is not mistaken for the
371
361
  // subcommand boundary (which would hide a later `--version`/`--output`).
package/dist/format.d.ts CHANGED
@@ -191,6 +191,31 @@ export declare function redactedValue(value: unknown, options?: {
191
191
  export declare function redactUrlSecrets(url: string, options?: {
192
192
  secretNames?: readonly string[];
193
193
  }): string;
194
+ /**
195
+ * Redact secret values out of a command line.
196
+ *
197
+ * A long flag whose name is secret by AFDATA naming (`--api-key-secret`, or an
198
+ * exact `secretNames` entry) has its value replaced by `***`, in both
199
+ * `--flag=value` and `--flag value` spellings. Everything else is preserved
200
+ * byte-for-byte.
201
+ *
202
+ * Free text is deliberately never scanned: a bare `api_key_secret=sk-live`
203
+ * positional, or a secret-looking token after a non-secret flag, is left alone.
204
+ * AFDATA decides sensitivity from the *field name*, and argv is no exception —
205
+ * rename the flag rather than pattern-matching values. A flag with no value
206
+ * (end of argv, or followed by another flag) is likewise left inspectable.
207
+ *
208
+ * Only long (`--`) flags are recognized, matching the convention's
209
+ * long-flags-only rule.
210
+ *
211
+ * Intended for CLIs that record their own invocation — startup diagnostics,
212
+ * audit trails, crash reports — where writing argv verbatim would put a
213
+ * credential in the log.
214
+ */
215
+ export declare function redactArgv(args: readonly string[], options?: {
216
+ secretNames?: readonly string[];
217
+ policy?: RedactionPolicy;
218
+ }): string[];
194
219
  /**
195
220
  * Normalize a fixed UTC offset string to "UTC" or ±HH:MM.
196
221
  * This helper handles fixed offsets only; IANA timezone names and DST rules
package/dist/format.js CHANGED
@@ -476,6 +476,67 @@ export function redactUrlSecrets(url, options) {
476
476
  const redacted = redactUrlInStr(url, secretNameSet(options ?? {}));
477
477
  return redacted ?? url;
478
478
  }
479
+ /**
480
+ * Redact secret values out of a command line.
481
+ *
482
+ * A long flag whose name is secret by AFDATA naming (`--api-key-secret`, or an
483
+ * exact `secretNames` entry) has its value replaced by `***`, in both
484
+ * `--flag=value` and `--flag value` spellings. Everything else is preserved
485
+ * byte-for-byte.
486
+ *
487
+ * Free text is deliberately never scanned: a bare `api_key_secret=sk-live`
488
+ * positional, or a secret-looking token after a non-secret flag, is left alone.
489
+ * AFDATA decides sensitivity from the *field name*, and argv is no exception —
490
+ * rename the flag rather than pattern-matching values. A flag with no value
491
+ * (end of argv, or followed by another flag) is likewise left inspectable.
492
+ *
493
+ * Only long (`--`) flags are recognized, matching the convention's
494
+ * long-flags-only rule.
495
+ *
496
+ * Intended for CLIs that record their own invocation — startup diagnostics,
497
+ * audit trails, crash reports — where writing argv verbatim would put a
498
+ * credential in the log.
499
+ */
500
+ export function redactArgv(args, options) {
501
+ if (options?.policy === RedactionPolicy.Off)
502
+ return [...args];
503
+ const secretNames = secretNameSet(options ?? {});
504
+ const out = [];
505
+ let redactNext = false;
506
+ for (const arg of args) {
507
+ if (redactNext) {
508
+ redactNext = false;
509
+ if (!arg.startsWith("-")) {
510
+ out.push("***");
511
+ continue;
512
+ }
513
+ }
514
+ if (arg.startsWith("--")) {
515
+ const rest = arg.slice(2);
516
+ const equals = rest.indexOf("=");
517
+ if (equals >= 0) {
518
+ const name = rest.slice(0, equals);
519
+ if (isSecretFlagName(name, secretNames)) {
520
+ out.push(`--${name}=***`);
521
+ continue;
522
+ }
523
+ }
524
+ else if (isSecretFlagName(rest, secretNames)) {
525
+ redactNext = true;
526
+ }
527
+ }
528
+ out.push(arg);
529
+ }
530
+ return out;
531
+ }
532
+ /**
533
+ * Whether a long flag's name is secret, normalizing the kebab-case flag
534
+ * spelling to the snake_case field spelling the convention is defined in.
535
+ */
536
+ function isSecretFlagName(flagName, secretNames) {
537
+ const normalized = flagName.replace(/-/gu, "_");
538
+ return isSecretKey(normalized, secretNames) || isSecretKey(flagName, secretNames);
539
+ }
479
540
  /**
480
541
  * Normalize a fixed UTC offset string to "UTC" or ±HH:MM.
481
542
  * This helper handles fixed offsets only; IANA timezone names and DST rules
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
3
3
  */
4
- export { jsonResult, jsonError, jsonProgress, jsonLog, Event, EventBuildError, JsonResultBuilder, JsonErrorBuilder, JsonProgressBuilder, JsonLogBuilder, type LogLevel, validateProtocolEvent, validateProtocolStream, decodeProtocolEvent, type DecodedEvent, type DecodedResult, type DecodedError, type DecodedProgress, type DecodedLog, EventDecodeError, type JsonValue, RedactionPolicy, PlainStyle, type OutputOptions, outputOptionsForPolicy, redactedValue, redactUrlSecrets, normalizeUtcOffset, isValidRfc3339Date, isValidRfc3339Time, isValidRfc3339, isValidBcp47, } from "./format.js";
4
+ export { jsonResult, jsonError, jsonProgress, jsonLog, Event, EventBuildError, JsonResultBuilder, JsonErrorBuilder, JsonProgressBuilder, JsonLogBuilder, type LogLevel, validateProtocolEvent, validateProtocolStream, decodeProtocolEvent, type DecodedEvent, type DecodedResult, type DecodedError, type DecodedProgress, type DecodedLog, EventDecodeError, type JsonValue, RedactionPolicy, PlainStyle, type OutputOptions, outputOptionsForPolicy, redactedValue, redactArgv, redactUrlSecrets, normalizeUtcOffset, isValidRfc3339Date, isValidRfc3339Time, isValidRfc3339, isValidBcp47, } from "./format.js";
5
5
  export { type OutputFormat, type OutputTo, type CliEventWriter, CliEmitter, LogFilters, cliParseOutput, parseOutputTo, cliParseLogFilters, render, buildCliError, buildCliVersion, cliRenderVersion, cliHandleVersionOrContinue, } from "./cli.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
3
3
  */
4
- export { jsonResult, jsonError, jsonProgress, jsonLog, Event, EventBuildError, JsonResultBuilder, JsonErrorBuilder, JsonProgressBuilder, JsonLogBuilder, validateProtocolEvent, validateProtocolStream, decodeProtocolEvent, EventDecodeError, RedactionPolicy, PlainStyle, outputOptionsForPolicy, redactedValue, redactUrlSecrets, normalizeUtcOffset, isValidRfc3339Date, isValidRfc3339Time, isValidRfc3339, isValidBcp47, } from "./format.js";
4
+ export { jsonResult, jsonError, jsonProgress, jsonLog, Event, EventBuildError, JsonResultBuilder, JsonErrorBuilder, JsonProgressBuilder, JsonLogBuilder, validateProtocolEvent, validateProtocolStream, decodeProtocolEvent, EventDecodeError, RedactionPolicy, PlainStyle, outputOptionsForPolicy, redactedValue, redactArgv, redactUrlSecrets, normalizeUtcOffset, isValidRfc3339Date, isValidRfc3339Time, isValidRfc3339, isValidBcp47, } from "./format.js";
5
5
  export { CliEmitter, LogFilters, cliParseOutput, parseOutputTo, cliParseLogFilters, render, buildCliError, buildCliVersion, cliRenderVersion, cliHandleVersionOrContinue, } from "./cli.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-first-data",
3
- "version": "0.24.0",
3
+ "version": "0.26.0",
4
4
  "description": "A naming convention that lets AI agents understand your data without being told what it means, plus a CLI and library for reading and safely editing structured JSON, TOML, YAML, dotenv, and INI documents.",
5
5
  "license": "MIT",
6
6
  "repository": {