agent-first-data 0.7.3 → 0.8.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 +15 -3
- package/dist/format.d.ts +8 -2
- package/dist/format.js +53 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Plain: args.input_path=/data/backup.tar.gz code=log event=startup config.max_fil
|
|
|
63
63
|
|
|
64
64
|
## API Reference
|
|
65
65
|
|
|
66
|
-
Total: **
|
|
66
|
+
Total: **15 public APIs and 2 types** + **AFDATA logging** (3 protocol builders + 2 redacted value helpers + 4 output functions + 1 internal + 1 utility + 4 CLI helpers + `OutputFormat` + `RedactionPolicy`)
|
|
67
67
|
|
|
68
68
|
### Protocol Builders (returns JsonValue)
|
|
69
69
|
|
|
@@ -82,6 +82,15 @@ buildJsonError(message: string, hint?: string, trace?: JsonValue): JsonValue
|
|
|
82
82
|
buildJson(code: string, fields: JsonValue, trace?: JsonValue): JsonValue
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
### Redacted Values (returns JsonValue)
|
|
86
|
+
|
|
87
|
+
Use these before raw HTTP/MCP/SSE serializers that do not call `outputJson`.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
redactedValue(value: unknown): JsonValue
|
|
91
|
+
redactedValueWith(value: unknown, redactionPolicy: RedactionPolicy): JsonValue
|
|
92
|
+
```
|
|
93
|
+
|
|
85
94
|
**Use case:** structured protocol payloads (frameworks automatically serialize)
|
|
86
95
|
|
|
87
96
|
**Example:**
|
|
@@ -134,6 +143,7 @@ outputPlain(value: JsonValue): string // Single-line logfmt, keys stripped, val
|
|
|
134
143
|
enum RedactionPolicy {
|
|
135
144
|
RedactionTraceOnly = "RedactionTraceOnly",
|
|
136
145
|
RedactionNone = "RedactionNone",
|
|
146
|
+
RedactionStrict = "RedactionStrict",
|
|
137
147
|
}
|
|
138
148
|
```
|
|
139
149
|
|
|
@@ -485,9 +495,11 @@ All formats automatically redact `_secret` fields.
|
|
|
485
495
|
- **Currency**: `_msats`, `_sats`, `_btc`, `_usd_cents`, `_eur_cents`, `_jpy`, `_{code}_cents`
|
|
486
496
|
- **Other**: `_percent`, `_secret` (auto-redacted in all formats)
|
|
487
497
|
|
|
498
|
+
TypeScript uses JavaScript `number` for JSON values, so `_epoch_ns` values above `Number.MAX_SAFE_INTEGER` lose precision. Prefer `_epoch_ms` for JSON interchange, or convert nanosecond values before formatting.
|
|
499
|
+
|
|
488
500
|
## Repository
|
|
489
501
|
|
|
490
|
-
This package is part of the [agent-first-data](https://github.com/
|
|
502
|
+
This package is part of the [agent-first-data](https://github.com/agentfirstkit/agent-first-data) repository, which also contains:
|
|
491
503
|
|
|
492
504
|
- **`spec/`** — Full AFDATA specification with suffix definitions, protocol format rules, and cross-language test fixtures
|
|
493
505
|
- **`skills/`** — AI coding agent skill for working with AFDATA conventions
|
|
@@ -495,7 +507,7 @@ This package is part of the [agent-first-data](https://github.com/cmnspore/agent
|
|
|
495
507
|
To run tests, clone the full repository (tests use shared cross-language fixtures from `spec/fixtures/`):
|
|
496
508
|
|
|
497
509
|
```bash
|
|
498
|
-
git clone https://github.com/
|
|
510
|
+
git clone https://github.com/agentfirstkit/agent-first-data
|
|
499
511
|
cd agent-first-data/typescript
|
|
500
512
|
npm test
|
|
501
513
|
```
|
package/dist/format.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AFDATA output formatting and protocol templates.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 11 public APIs and 1 type: protocol builders, redacted value helpers,
|
|
5
|
+
* output formatters, redaction, parseSize, and RedactionPolicy.
|
|
5
6
|
*/
|
|
6
7
|
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
7
8
|
[key: string]: JsonValue;
|
|
@@ -14,7 +15,8 @@ export declare function buildJsonError(message: string, hint?: string, trace?: J
|
|
|
14
15
|
export declare function buildJson(code: string, fields: JsonValue, trace?: JsonValue): JsonValue;
|
|
15
16
|
export declare enum RedactionPolicy {
|
|
16
17
|
RedactionTraceOnly = "RedactionTraceOnly",
|
|
17
|
-
RedactionNone = "RedactionNone"
|
|
18
|
+
RedactionNone = "RedactionNone",
|
|
19
|
+
RedactionStrict = "RedactionStrict"
|
|
18
20
|
}
|
|
19
21
|
/** Format as single-line JSON. Secrets redacted, original keys, raw values. */
|
|
20
22
|
export declare function outputJson(value: JsonValue): string;
|
|
@@ -26,6 +28,10 @@ export declare function outputYaml(value: JsonValue): string;
|
|
|
26
28
|
export declare function outputPlain(value: JsonValue): string;
|
|
27
29
|
/** Redact _secret fields in-place. */
|
|
28
30
|
export declare function internalRedactSecrets(value: JsonValue): void;
|
|
31
|
+
/** Return a JSON-safe copy with default _secret redaction applied. */
|
|
32
|
+
export declare function redactedValue(value: unknown): JsonValue;
|
|
33
|
+
/** Return a JSON-safe copy with an explicit redaction policy applied. */
|
|
34
|
+
export declare function redactedValueWith(value: unknown, redactionPolicy: RedactionPolicy): JsonValue;
|
|
29
35
|
/**
|
|
30
36
|
* Parse a human-readable size string into bytes.
|
|
31
37
|
* Accepts bare numbers or numbers followed by a unit letter (B/K/M/G/T).
|
package/dist/format.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AFDATA output formatting and protocol templates.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 11 public APIs and 1 type: protocol builders, redacted value helpers,
|
|
5
|
+
* output formatters, redaction, parseSize, and RedactionPolicy.
|
|
5
6
|
*/
|
|
6
7
|
// ═══════════════════════════════════════════
|
|
7
8
|
// Public API: Protocol Builders
|
|
@@ -37,34 +38,31 @@ export var RedactionPolicy;
|
|
|
37
38
|
(function (RedactionPolicy) {
|
|
38
39
|
RedactionPolicy["RedactionTraceOnly"] = "RedactionTraceOnly";
|
|
39
40
|
RedactionPolicy["RedactionNone"] = "RedactionNone";
|
|
41
|
+
RedactionPolicy["RedactionStrict"] = "RedactionStrict";
|
|
40
42
|
})(RedactionPolicy || (RedactionPolicy = {}));
|
|
41
43
|
/** Format as single-line JSON. Secrets redacted, original keys, raw values. */
|
|
42
44
|
export function outputJson(value) {
|
|
43
|
-
|
|
44
|
-
redactSecrets(v);
|
|
45
|
-
return JSON.stringify(v);
|
|
45
|
+
return JSON.stringify(redactedValue(value));
|
|
46
46
|
}
|
|
47
47
|
/** Format as single-line JSON with explicit redaction policy. */
|
|
48
48
|
export function outputJsonWith(value, redactionPolicy) {
|
|
49
|
-
|
|
50
|
-
applyRedactionPolicy(v, redactionPolicy);
|
|
51
|
-
return JSON.stringify(v);
|
|
49
|
+
return JSON.stringify(redactedValueWith(value, redactionPolicy));
|
|
52
50
|
}
|
|
53
51
|
/** Format as multi-line YAML. Keys stripped, values formatted, secrets redacted. */
|
|
54
52
|
export function outputYaml(value) {
|
|
55
|
-
value =
|
|
53
|
+
value = redactedValue(value);
|
|
56
54
|
const lines = ["---"];
|
|
57
55
|
renderYamlProcessed(value, 0, lines);
|
|
58
56
|
return lines.join("\n");
|
|
59
57
|
}
|
|
60
58
|
/** Format as single-line logfmt. Keys stripped, values formatted, secrets redacted. */
|
|
61
59
|
export function outputPlain(value) {
|
|
62
|
-
value =
|
|
60
|
+
value = redactedValue(value);
|
|
63
61
|
const pairs = [];
|
|
64
62
|
collectPlainPairs(value, "", pairs);
|
|
65
63
|
pairs.sort(([a], [b]) => jcsCompare(a, b));
|
|
66
64
|
return pairs
|
|
67
|
-
.map(([k, v]) =>
|
|
65
|
+
.map(([k, v]) => `${k}=${quoteLogfmtValue(v)}`)
|
|
68
66
|
.join(" ");
|
|
69
67
|
}
|
|
70
68
|
// ═══════════════════════════════════════════
|
|
@@ -74,6 +72,18 @@ export function outputPlain(value) {
|
|
|
74
72
|
export function internalRedactSecrets(value) {
|
|
75
73
|
redactSecrets(value);
|
|
76
74
|
}
|
|
75
|
+
/** Return a JSON-safe copy with default _secret redaction applied. */
|
|
76
|
+
export function redactedValue(value) {
|
|
77
|
+
const v = sanitizeForJson(value);
|
|
78
|
+
redactSecrets(v);
|
|
79
|
+
return v;
|
|
80
|
+
}
|
|
81
|
+
/** Return a JSON-safe copy with an explicit redaction policy applied. */
|
|
82
|
+
export function redactedValueWith(value, redactionPolicy) {
|
|
83
|
+
const v = sanitizeForJson(value);
|
|
84
|
+
applyRedactionPolicy(v, redactionPolicy);
|
|
85
|
+
return v;
|
|
86
|
+
}
|
|
77
87
|
/**
|
|
78
88
|
* Parse a human-readable size string into bytes.
|
|
79
89
|
* Accepts bare numbers or numbers followed by a unit letter (B/K/M/G/T).
|
|
@@ -136,6 +146,23 @@ function redactSecrets(value) {
|
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
148
|
}
|
|
149
|
+
function redactSecretsStrict(value) {
|
|
150
|
+
if (isObject(value)) {
|
|
151
|
+
for (const k of Object.keys(value)) {
|
|
152
|
+
if (k.endsWith("_secret") || k.endsWith("_SECRET")) {
|
|
153
|
+
value[k] = "***";
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
redactSecretsStrict(value[k]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else if (Array.isArray(value)) {
|
|
161
|
+
for (const item of value) {
|
|
162
|
+
redactSecretsStrict(item);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
139
166
|
function applyRedactionPolicy(value, redactionPolicy) {
|
|
140
167
|
switch (redactionPolicy) {
|
|
141
168
|
case RedactionPolicy.RedactionTraceOnly:
|
|
@@ -145,6 +172,9 @@ function applyRedactionPolicy(value, redactionPolicy) {
|
|
|
145
172
|
break;
|
|
146
173
|
case RedactionPolicy.RedactionNone:
|
|
147
174
|
break;
|
|
175
|
+
case RedactionPolicy.RedactionStrict:
|
|
176
|
+
redactSecretsStrict(value);
|
|
177
|
+
break;
|
|
148
178
|
default:
|
|
149
179
|
// Safety fallback for unknown values.
|
|
150
180
|
redactSecrets(value);
|
|
@@ -503,6 +533,19 @@ function plainScalar(value) {
|
|
|
503
533
|
return value.toString();
|
|
504
534
|
return String(value);
|
|
505
535
|
}
|
|
536
|
+
function quoteLogfmtValue(value) {
|
|
537
|
+
if (value === "")
|
|
538
|
+
return "";
|
|
539
|
+
if (!/[\s="\\]/.test(value))
|
|
540
|
+
return value;
|
|
541
|
+
const escaped = value
|
|
542
|
+
.replace(/\\/g, "\\\\")
|
|
543
|
+
.replace(/"/g, '\\"')
|
|
544
|
+
.replace(/\n/g, "\\n")
|
|
545
|
+
.replace(/\r/g, "\\r")
|
|
546
|
+
.replace(/\t/g, "\\t");
|
|
547
|
+
return `"${escaped}"`;
|
|
548
|
+
}
|
|
506
549
|
// ═══════════════════════════════════════════
|
|
507
550
|
// Utilities
|
|
508
551
|
// ═══════════════════════════════════════════
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
|
|
3
3
|
*/
|
|
4
|
-
export { buildJsonOk, buildJsonError, buildJson, RedactionPolicy, outputJson, outputJsonWith, outputYaml, outputPlain, internalRedactSecrets, parseSize, } from "./format.js";
|
|
4
|
+
export { buildJsonOk, buildJsonError, buildJson, RedactionPolicy, outputJson, outputJsonWith, outputYaml, outputPlain, internalRedactSecrets, redactedValue, redactedValueWith, parseSize, } from "./format.js";
|
|
5
5
|
export { log, span, initJson, initPlain, initYaml } from "./afdata_logging.js";
|
|
6
6
|
export { type OutputFormat, cliParseOutput, cliParseLogFilters, cliOutput, buildCliError } from "./cli.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
|
|
3
3
|
*/
|
|
4
|
-
export { buildJsonOk, buildJsonError, buildJson, RedactionPolicy, outputJson, outputJsonWith, outputYaml, outputPlain, internalRedactSecrets, parseSize, } from "./format.js";
|
|
4
|
+
export { buildJsonOk, buildJsonError, buildJson, RedactionPolicy, outputJson, outputJsonWith, outputYaml, outputPlain, internalRedactSecrets, redactedValue, redactedValueWith, parseSize, } from "./format.js";
|
|
5
5
|
export { log, span, initJson, initPlain, initYaml } from "./afdata_logging.js";
|
|
6
6
|
export { cliParseOutput, cliParseLogFilters, cliOutput, buildCliError } from "./cli.js";
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-first-data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates for AI agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/
|
|
8
|
+
"url": "https://github.com/agentfirstkit/agent-first-data"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "dist/index.js",
|