agent-first-data 0.2.3 → 0.3.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# agent-first-data
|
|
2
2
|
|
|
3
|
-
**Agent-First Data (
|
|
3
|
+
**Agent-First Data (AFDATA)** — Suffix-driven output formatting and protocol templates for AI agents.
|
|
4
4
|
|
|
5
5
|
The field name is the schema. Agents read `latency_ms` and know milliseconds, `api_key_secret` and know to redact, no external schema needed.
|
|
6
6
|
|
|
@@ -18,23 +18,37 @@ A backup tool invoked from the CLI — flags, env vars, and config all use the s
|
|
|
18
18
|
API_KEY_SECRET=sk-1234 cloudback --timeout-s 30 --max-file-size-bytes 10737418240 /data/backup.tar.gz
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
For CLI diagnostics, enable log categories explicitly:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
--log startup,request,progress,retry,redirect
|
|
25
|
+
--verbose # shorthand for all categories
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Without these flags, startup diagnostics should stay off by default.
|
|
29
|
+
|
|
30
|
+
The tool reads env vars, flags, and config — all with AFDATA suffixes — and can emit a startup diagnostic event:
|
|
22
31
|
|
|
23
32
|
```typescript
|
|
24
|
-
import {
|
|
33
|
+
import { buildJson, outputJson, outputYaml, outputPlain } from "agent-first-data";
|
|
25
34
|
|
|
26
|
-
const startup =
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
|
|
35
|
+
const startup = buildJson(
|
|
36
|
+
"log",
|
|
37
|
+
{
|
|
38
|
+
event: "startup",
|
|
39
|
+
config: { timeout_s: 30, max_file_size_bytes: 10737418240 },
|
|
40
|
+
args: { input_path: "/data/backup.tar.gz" },
|
|
41
|
+
env: { API_KEY_SECRET: process.env.API_KEY_SECRET ?? null },
|
|
42
|
+
},
|
|
30
43
|
);
|
|
31
44
|
```
|
|
32
45
|
|
|
33
46
|
Three output formats, same data:
|
|
34
47
|
|
|
35
48
|
```
|
|
36
|
-
JSON: {"code":"startup","args":{"input_path":"/data/backup.tar.gz"},"config":{"max_file_size_bytes":10737418240,"timeout_s":30},"env":{"API_KEY_SECRET":"***"}}
|
|
37
|
-
YAML: code: "
|
|
49
|
+
JSON: {"code":"log","event":"startup","args":{"input_path":"/data/backup.tar.gz"},"config":{"max_file_size_bytes":10737418240,"timeout_s":30},"env":{"API_KEY_SECRET":"***"}}
|
|
50
|
+
YAML: code: "log"
|
|
51
|
+
event: "startup"
|
|
38
52
|
args:
|
|
39
53
|
input_path: "/data/backup.tar.gz"
|
|
40
54
|
config:
|
|
@@ -42,25 +56,22 @@ YAML: code: "startup"
|
|
|
42
56
|
timeout: "30s"
|
|
43
57
|
env:
|
|
44
58
|
API_KEY: "***"
|
|
45
|
-
Plain: args.input_path=/data/backup.tar.gz code=startup config.max_file_size=10.0GB config.timeout=30s env.API_KEY=***
|
|
59
|
+
Plain: args.input_path=/data/backup.tar.gz code=log event=startup config.max_file_size=10.0GB config.timeout=30s env.API_KEY=***
|
|
46
60
|
```
|
|
47
61
|
|
|
48
62
|
`--timeout-s` → `timeout_s` → `timeout: 30s`. `API_KEY_SECRET` → `API_KEY: "***"`. The suffix is the schema.
|
|
49
63
|
|
|
50
64
|
## API Reference
|
|
51
65
|
|
|
52
|
-
Total: **
|
|
66
|
+
Total: **8 public APIs** + **AFDATA logging** (3 protocol builders + 3 output functions + 1 internal + 1 utility)
|
|
53
67
|
|
|
54
68
|
### Protocol Builders (returns JsonValue)
|
|
55
69
|
|
|
56
|
-
Build
|
|
70
|
+
Build AFDATA protocol structures. Return JSON-serializable objects for API responses.
|
|
57
71
|
|
|
58
72
|
```typescript
|
|
59
73
|
type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
|
|
60
74
|
|
|
61
|
-
// Startup (configuration)
|
|
62
|
-
buildJsonStartup(config: JsonValue, args: JsonValue, env: JsonValue): JsonValue
|
|
63
|
-
|
|
64
75
|
// Success (result)
|
|
65
76
|
buildJsonOk(result: JsonValue, trace?: JsonValue): JsonValue
|
|
66
77
|
|
|
@@ -75,13 +86,17 @@ buildJson(code: string, fields: JsonValue, trace?: JsonValue): JsonValue
|
|
|
75
86
|
|
|
76
87
|
**Example:**
|
|
77
88
|
```typescript
|
|
78
|
-
import {
|
|
89
|
+
import { buildJsonOk, buildJsonError, buildJson } from "agent-first-data";
|
|
79
90
|
|
|
80
91
|
// Startup
|
|
81
|
-
const startup =
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
|
|
92
|
+
const startup = buildJson(
|
|
93
|
+
"log",
|
|
94
|
+
{
|
|
95
|
+
event: "startup",
|
|
96
|
+
config: { api_key_secret: "sk-123", timeout_s: 30 },
|
|
97
|
+
args: { config_path: "config.yml" },
|
|
98
|
+
env: { RUST_LOG: "info" },
|
|
99
|
+
},
|
|
85
100
|
);
|
|
86
101
|
|
|
87
102
|
// Success (always include trace)
|
|
@@ -185,17 +200,22 @@ app.get("/users/:id", (req, res) => {
|
|
|
185
200
|
### Example 2: CLI Tool (Complete Lifecycle)
|
|
186
201
|
|
|
187
202
|
```typescript
|
|
188
|
-
import {
|
|
203
|
+
import { buildJsonOk, buildJson, outputYaml, outputPlain } from "agent-first-data";
|
|
189
204
|
|
|
190
205
|
// 1. Startup
|
|
191
|
-
const startup =
|
|
192
|
-
|
|
193
|
-
{
|
|
194
|
-
|
|
206
|
+
const startup = buildJson(
|
|
207
|
+
"log",
|
|
208
|
+
{
|
|
209
|
+
event: "startup",
|
|
210
|
+
config: { api_key_secret: "sk-sensitive-key", timeout_s: 30 },
|
|
211
|
+
args: { input_path: "data.json" },
|
|
212
|
+
env: { RUST_LOG: "info" },
|
|
213
|
+
},
|
|
195
214
|
);
|
|
196
215
|
console.log(outputYaml(startup));
|
|
197
216
|
// ---
|
|
198
|
-
// code: "
|
|
217
|
+
// code: "log"
|
|
218
|
+
// event: "startup"
|
|
199
219
|
// args:
|
|
200
220
|
// input_path: "data.json"
|
|
201
221
|
// config:
|
|
@@ -286,9 +306,9 @@ console.log(outputPlain(data));
|
|
|
286
306
|
// api_key=*** cache_ttl=3600s count=42 created_at=2025-02-07T00:00:00.000Z file_size=5.0MB payment=50000000msats price=$99.99 request_timeout=5.0s success_rate=95.5% user_name=alice
|
|
287
307
|
```
|
|
288
308
|
|
|
289
|
-
##
|
|
309
|
+
## AFDATA Logging
|
|
290
310
|
|
|
291
|
-
|
|
311
|
+
AFDATA-compliant structured logging. Every log line is formatted using the library's own `outputJson`/`outputPlain`/`outputYaml` functions. Span fields are carried via `AsyncLocalStorage` (async-safe), automatically flattened into each log line. Zero dependencies beyond Node.js built-ins.
|
|
292
312
|
|
|
293
313
|
### API
|
|
294
314
|
|
|
@@ -367,8 +387,8 @@ await span({ request_id: "abc-123" }, async () => {
|
|
|
367
387
|
The `code` field defaults to the log level. Override with an explicit field:
|
|
368
388
|
|
|
369
389
|
```typescript
|
|
370
|
-
log.info("Server ready", { code: "startup" });
|
|
371
|
-
// {"timestamp_epoch_ms":...,"message":"Server ready","code":"startup"}
|
|
390
|
+
log.info("Server ready", { code: "log", event: "startup" });
|
|
391
|
+
// {"timestamp_epoch_ms":...,"message":"Server ready","code":"log","event":"startup"}
|
|
372
392
|
```
|
|
373
393
|
|
|
374
394
|
### Output Fields
|
|
@@ -385,7 +405,7 @@ Every log line contains:
|
|
|
385
405
|
|
|
386
406
|
### Log Output Formats
|
|
387
407
|
|
|
388
|
-
All three formats use the library's own output functions, so
|
|
408
|
+
All three formats use the library's own output functions, so AFDATA suffix processing applies to log fields too:
|
|
389
409
|
|
|
390
410
|
| Format | Function | Keys | Values | Use case |
|
|
391
411
|
|:-------|:---------|:-----|:-------|:---------|
|
|
@@ -415,6 +435,21 @@ All formats automatically redact `_secret` fields.
|
|
|
415
435
|
- **Currency**: `_msats`, `_sats`, `_btc`, `_usd_cents`, `_eur_cents`, `_jpy`, `_{code}_cents`
|
|
416
436
|
- **Other**: `_percent`, `_secret` (auto-redacted in all formats)
|
|
417
437
|
|
|
438
|
+
## Repository
|
|
439
|
+
|
|
440
|
+
This package is part of the [agent-first-data](https://github.com/cmnspore/agent-first-data) repository, which also contains:
|
|
441
|
+
|
|
442
|
+
- **`spec/`** — Full AFDATA specification with suffix definitions, protocol format rules, and cross-language test fixtures
|
|
443
|
+
- **`skills/`** — AI coding agent skill for working with AFDATA conventions
|
|
444
|
+
|
|
445
|
+
To run tests, clone the full repository (tests use shared cross-language fixtures from `spec/fixtures/`):
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
git clone https://github.com/cmnspore/agent-first-data
|
|
449
|
+
cd agent-first-data/typescript
|
|
450
|
+
npm test
|
|
451
|
+
```
|
|
452
|
+
|
|
418
453
|
## License
|
|
419
454
|
|
|
420
455
|
MIT
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AFDATA-compliant structured logging.
|
|
3
3
|
*
|
|
4
4
|
* Outputs log events using agent-first-data formatting functions:
|
|
5
5
|
* - JSON: single-line JSONL via outputJson (secrets redacted, original keys)
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Span fields are carried via AsyncLocalStorage (async-safe).
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
|
-
* import { log, span, initJson, initPlain, initYaml } from "agent-first-data/
|
|
12
|
+
* import { log, span, initJson, initPlain, initYaml } from "agent-first-data/afdata_logging";
|
|
13
13
|
* initJson(); // or initPlain() or initYaml()
|
|
14
14
|
* log.info("Server started");
|
|
15
15
|
* await span({ request_id: "abc" }, async () => {
|
|
@@ -23,7 +23,7 @@ export declare function initPlain(): void;
|
|
|
23
23
|
/** Set log output to multi-line YAML (keys stripped, values formatted). */
|
|
24
24
|
export declare function initYaml(): void;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* AFDATA logger. Each method outputs a single log line to stdout.
|
|
27
27
|
* Format is controlled by initJson/initPlain/initYaml (default: JSON).
|
|
28
28
|
*/
|
|
29
29
|
export declare const log: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AFDATA-compliant structured logging.
|
|
3
3
|
*
|
|
4
4
|
* Outputs log events using agent-first-data formatting functions:
|
|
5
5
|
* - JSON: single-line JSONL via outputJson (secrets redacted, original keys)
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Span fields are carried via AsyncLocalStorage (async-safe).
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
|
-
* import { log, span, initJson, initPlain, initYaml } from "agent-first-data/
|
|
12
|
+
* import { log, span, initJson, initPlain, initYaml } from "agent-first-data/afdata_logging";
|
|
13
13
|
* initJson(); // or initPlain() or initYaml()
|
|
14
14
|
* log.info("Server started");
|
|
15
15
|
* await span({ request_id: "abc" }, async () => {
|
|
@@ -68,7 +68,7 @@ function emit(level, message, fields) {
|
|
|
68
68
|
process.stdout.write(line + "\n");
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* AFDATA logger. Each method outputs a single log line to stdout.
|
|
72
72
|
* Format is controlled by initJson/initPlain/initYaml (default: JSON).
|
|
73
73
|
*/
|
|
74
74
|
export const log = {
|
package/dist/format.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AFDATA output formatting and protocol templates.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 8 public APIs: 3 protocol builders + 3 output formatters + 1 redaction + 1 utility.
|
|
5
5
|
*/
|
|
6
6
|
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
7
7
|
[key: string]: JsonValue;
|
|
8
8
|
};
|
|
9
|
-
/** Build {code: "startup", config, args, env}. */
|
|
10
|
-
export declare function buildJsonStartup(config: JsonValue, args: JsonValue, env: JsonValue): JsonValue;
|
|
11
9
|
/** Build {code: "ok", result, trace?}. */
|
|
12
10
|
export declare function buildJsonOk(result: JsonValue, trace?: JsonValue): JsonValue;
|
|
13
11
|
/** Build {code: "error", error: message, trace?}. */
|
package/dist/format.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AFDATA output formatting and protocol templates.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 8 public APIs: 3 protocol builders + 3 output formatters + 1 redaction + 1 utility.
|
|
5
5
|
*/
|
|
6
6
|
// ═══════════════════════════════════════════
|
|
7
7
|
// Public API: Protocol Builders
|
|
8
8
|
// ═══════════════════════════════════════════
|
|
9
|
-
/** Build {code: "startup", config, args, env}. */
|
|
10
|
-
export function buildJsonStartup(config, args, env) {
|
|
11
|
-
return { code: "startup", config, args, env };
|
|
12
|
-
}
|
|
13
9
|
/** Build {code: "ok", result, trace?}. */
|
|
14
10
|
export function buildJsonOk(result, trace) {
|
|
15
11
|
const m = { code: "ok", result };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent-First Data (
|
|
2
|
+
* Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
|
|
3
3
|
*/
|
|
4
|
-
export {
|
|
5
|
-
export { log, span, initJson, initPlain, initYaml } from "./
|
|
4
|
+
export { buildJsonOk, buildJsonError, buildJson, outputJson, outputYaml, outputPlain, internalRedactSecrets, parseSize } from "./format.js";
|
|
5
|
+
export { log, span, initJson, initPlain, initYaml } from "./afdata_logging.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent-First Data (
|
|
2
|
+
* Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
|
|
3
3
|
*/
|
|
4
|
-
export {
|
|
5
|
-
export { log, span, initJson, initPlain, initYaml } from "./
|
|
4
|
+
export { buildJsonOk, buildJsonError, buildJson, outputJson, outputYaml, outputPlain, internalRedactSecrets, parseSize } from "./format.js";
|
|
5
|
+
export { log, span, initJson, initPlain, initYaml } from "./afdata_logging.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-first-data",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Agent-First Data (
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"import": "./dist/index.js",
|
|
16
16
|
"types": "./dist/index.d.ts"
|
|
17
17
|
},
|
|
18
|
-
"./
|
|
19
|
-
"import": "./dist/
|
|
20
|
-
"types": "./dist/
|
|
18
|
+
"./afdata_logging": {
|
|
19
|
+
"import": "./dist/afdata_logging.js",
|
|
20
|
+
"types": "./dist/afdata_logging.d.ts"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"files": [
|