argsbarg 6.1.8 → 6.1.10
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/CHANGELOG.md +23 -1
- package/README.md +160 -68
- package/docs/README.md +1 -0
- package/docs/cli-program.md +2 -0
- package/docs/decisions.md +81 -25
- package/docs/developing.md +1 -1
- package/docs/distribution-homebrew.md +117 -104
- package/docs/http-server.md +3 -1
- package/docs/logging.md +149 -0
- package/examples/full-example/docs/cli-schema.json +18 -18
- package/examples/full-example/docs/cli.md +18 -18
- package/examples/full-example/docs/http.md +13 -1
- package/examples/full-example/justfile +20 -0
- package/index.d.ts +84 -14
- package/package.json +1 -1
- package/src/builtins/http.ts +1 -1
- package/src/builtins/mcp.ts +1 -1
- package/src/core/types.ts +17 -3
- package/src/docs/http-guide.ts +11 -1
- package/src/docs/save.ts +1 -1
- package/src/headless/tool-call.ts +1 -1
- package/src/hooks/run.ts +7 -2
- package/src/http/server.ts +19 -1
- package/src/index.ts +2 -0
- package/src/log/ecs.test.ts +68 -2
- package/src/log/ecs.ts +109 -14
- package/src/log/emitter.test.ts +95 -0
- package/src/log/emitter.ts +74 -11
- package/src/log/trace.test.ts +60 -0
- package/src/log/trace.ts +62 -0
- package/src/runtime/cli.ts +1 -1
|
@@ -195,7 +195,7 @@ MCP server and bundle tools.
|
|
|
195
195
|
| Option | Type | Required | Format / default | Description |
|
|
196
196
|
| --- | --- | --- | --- | --- |
|
|
197
197
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
198
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
198
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
199
199
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
200
200
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
201
201
|
|
|
@@ -231,7 +231,7 @@ HTTP API server for tools.
|
|
|
231
231
|
| `--port` | number | optional | — | Listen port. |
|
|
232
232
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
233
233
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
234
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
234
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
235
235
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
236
236
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
237
237
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -408,7 +408,7 @@ MCP server and bundle tools.
|
|
|
408
408
|
| Option | Type | Required | Format / default | Description |
|
|
409
409
|
| --- | --- | --- | --- | --- |
|
|
410
410
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
411
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
411
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
412
412
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
413
413
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
414
414
|
|
|
@@ -444,7 +444,7 @@ HTTP API server for tools.
|
|
|
444
444
|
| `--port` | number | optional | — | Listen port. |
|
|
445
445
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
446
446
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
447
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
447
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
448
448
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
449
449
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
450
450
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -649,7 +649,7 @@ MCP server and bundle tools.
|
|
|
649
649
|
| Option | Type | Required | Format / default | Description |
|
|
650
650
|
| --- | --- | --- | --- | --- |
|
|
651
651
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
652
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
652
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
653
653
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
654
654
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
655
655
|
|
|
@@ -685,7 +685,7 @@ HTTP API server for tools.
|
|
|
685
685
|
| `--port` | number | optional | — | Listen port. |
|
|
686
686
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
687
687
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
688
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
688
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
689
689
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
690
690
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
691
691
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -872,7 +872,7 @@ MCP server and bundle tools.
|
|
|
872
872
|
| Option | Type | Required | Format / default | Description |
|
|
873
873
|
| --- | --- | --- | --- | --- |
|
|
874
874
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
875
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
875
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
876
876
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
877
877
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
878
878
|
|
|
@@ -908,7 +908,7 @@ HTTP API server for tools.
|
|
|
908
908
|
| `--port` | number | optional | — | Listen port. |
|
|
909
909
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
910
910
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
911
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
911
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
912
912
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
913
913
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
914
914
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -1085,7 +1085,7 @@ MCP server and bundle tools.
|
|
|
1085
1085
|
| Option | Type | Required | Format / default | Description |
|
|
1086
1086
|
| --- | --- | --- | --- | --- |
|
|
1087
1087
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1088
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1088
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1089
1089
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1090
1090
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
1091
1091
|
|
|
@@ -1121,7 +1121,7 @@ HTTP API server for tools.
|
|
|
1121
1121
|
| `--port` | number | optional | — | Listen port. |
|
|
1122
1122
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
1123
1123
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1124
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1124
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1125
1125
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1126
1126
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
1127
1127
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -1309,7 +1309,7 @@ MCP server and bundle tools.
|
|
|
1309
1309
|
| Option | Type | Required | Format / default | Description |
|
|
1310
1310
|
| --- | --- | --- | --- | --- |
|
|
1311
1311
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1312
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1312
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1313
1313
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1314
1314
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
1315
1315
|
|
|
@@ -1345,7 +1345,7 @@ HTTP API server for tools.
|
|
|
1345
1345
|
| `--port` | number | optional | — | Listen port. |
|
|
1346
1346
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
1347
1347
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1348
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1348
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1349
1349
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1350
1350
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
1351
1351
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -1522,7 +1522,7 @@ MCP server and bundle tools.
|
|
|
1522
1522
|
| Option | Type | Required | Format / default | Description |
|
|
1523
1523
|
| --- | --- | --- | --- | --- |
|
|
1524
1524
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1525
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1525
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1526
1526
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1527
1527
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
1528
1528
|
|
|
@@ -1558,7 +1558,7 @@ HTTP API server for tools.
|
|
|
1558
1558
|
| `--port` | number | optional | — | Listen port. |
|
|
1559
1559
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
1560
1560
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1561
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1561
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1562
1562
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1563
1563
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
1564
1564
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -1735,7 +1735,7 @@ MCP server and bundle tools.
|
|
|
1735
1735
|
| Option | Type | Required | Format / default | Description |
|
|
1736
1736
|
| --- | --- | --- | --- | --- |
|
|
1737
1737
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1738
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1738
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1739
1739
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1740
1740
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
1741
1741
|
|
|
@@ -1771,7 +1771,7 @@ HTTP API server for tools.
|
|
|
1771
1771
|
| `--port` | number | optional | — | Listen port. |
|
|
1772
1772
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
1773
1773
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1774
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1774
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1775
1775
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1776
1776
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
1777
1777
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -1948,7 +1948,7 @@ MCP server and bundle tools.
|
|
|
1948
1948
|
| Option | Type | Required | Format / default | Description |
|
|
1949
1949
|
| --- | --- | --- | --- | --- |
|
|
1950
1950
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1951
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1951
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1952
1952
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1953
1953
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
1954
1954
|
|
|
@@ -1984,7 +1984,7 @@ HTTP API server for tools.
|
|
|
1984
1984
|
| `--port` | number | optional | — | Listen port. |
|
|
1985
1985
|
| `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
|
|
1986
1986
|
| `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
|
|
1987
|
-
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
|
|
1987
|
+
| `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
|
|
1988
1988
|
| `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
|
|
1989
1989
|
| `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
|
|
1990
1990
|
| `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<!-- Generated by full-example docs http --save; do not edit. -->
|
|
2
|
+
|
|
1
3
|
# HTTP API (full-example)
|
|
2
4
|
|
|
3
5
|
full-example exposes user commands over HTTP REST routes derived from the CLI tree.
|
|
@@ -10,7 +12,7 @@ full-example http
|
|
|
10
12
|
|
|
11
13
|
Listens on **http://127.0.0.1:3000** by default (`httpServer.host` / `httpServer.port`).
|
|
12
14
|
|
|
13
|
-
Bind is localhost-only
|
|
15
|
+
Bind is localhost-only by default — use a reverse proxy for remote access.
|
|
14
16
|
|
|
15
17
|
## Endpoints
|
|
16
18
|
|
|
@@ -45,6 +47,16 @@ Handlers must use `ctx.respond()` or return a value for API/MCP tool calls.
|
|
|
45
47
|
|
|
46
48
|
Errors use `{ "error": "..." }` with `400`, `404`, `503`, or `500`.
|
|
47
49
|
|
|
50
|
+
## Logging
|
|
51
|
+
|
|
52
|
+
Server logs go to **stderr** (one JSON object per line by default).
|
|
53
|
+
|
|
54
|
+
- Configure with `program.log` on the program root
|
|
55
|
+
- **`enrich`** — add custom JSON fields on top of the default line
|
|
56
|
+
- **`serialize`** — replace the formatter and emit your own line shape
|
|
57
|
+
|
|
58
|
+
See the argsbarg [logging guide](https://github.com/bdombro/bun-argsbarg/blob/main/docs/logging.md) for examples and the full `LogEnrichContext` shape.
|
|
59
|
+
|
|
48
60
|
## REST routes
|
|
49
61
|
|
|
50
62
|
- `POST /echo` (CLI: `full-example echo`) — Echo a message (MCP-friendly leaf).
|
|
@@ -34,6 +34,22 @@ migrate DB="./workspaces.db":
|
|
|
34
34
|
# Run schemagen, typecheck, and format
|
|
35
35
|
check: schemagen format typecheck
|
|
36
36
|
|
|
37
|
+
# demo the HTTP API
|
|
38
|
+
demo-http:
|
|
39
|
+
#!/usr/bin/env bash
|
|
40
|
+
set -euo pipefail
|
|
41
|
+
bun ./src/index.ts http --port 13000 &
|
|
42
|
+
trap 'kill $! 2>/dev/null || true' EXIT
|
|
43
|
+
until curl -sf http://127.0.0.1:13000/health/liveness >/dev/null; do sleep 0.1; done
|
|
44
|
+
|
|
45
|
+
# demo a CLI command
|
|
46
|
+
demo-cli:
|
|
47
|
+
@just run {{cli_key}} status
|
|
48
|
+
|
|
49
|
+
# demo a CLI command
|
|
50
|
+
demo-help:
|
|
51
|
+
@just run {{cli_key}} --help
|
|
52
|
+
|
|
37
53
|
# Run the CLI from source with optional args; restarts on file changes
|
|
38
54
|
dev *ARGS:
|
|
39
55
|
bun --watch ./src/index.ts {{ARGS}}
|
|
@@ -53,6 +69,10 @@ alias fmt := format
|
|
|
53
69
|
format:
|
|
54
70
|
bun run biome check ./src ./scripts --write --unsafe
|
|
55
71
|
|
|
72
|
+
# Run the HTTP server
|
|
73
|
+
http:
|
|
74
|
+
@just run http
|
|
75
|
+
|
|
56
76
|
# Alias for backward compatibility
|
|
57
77
|
install: install-local
|
|
58
78
|
|
package/index.d.ts
CHANGED
|
@@ -113,6 +113,59 @@ export declare class CliContext {
|
|
|
113
113
|
private _posMap;
|
|
114
114
|
private _positionalMap;
|
|
115
115
|
}
|
|
116
|
+
/** ECS version string written to every JSON log line. */
|
|
117
|
+
export declare const ECS_VERSION = "8.11.0";
|
|
118
|
+
/** Severity label for ECS `log.level`. */
|
|
119
|
+
export type EcsLogLevel = "debug" | "info" | "warn" | "error";
|
|
120
|
+
/** Fields merged into every ECS log line. */
|
|
121
|
+
export interface EcsServiceFields {
|
|
122
|
+
name: string;
|
|
123
|
+
version: string;
|
|
124
|
+
}
|
|
125
|
+
/** Context for {@link CliLogConfig.enrich} and {@link CliLogConfig.serialize}. */
|
|
126
|
+
export interface LogEnrichContext {
|
|
127
|
+
level: EcsLogLevel;
|
|
128
|
+
message: string;
|
|
129
|
+
action?: string;
|
|
130
|
+
requestId?: string;
|
|
131
|
+
traceId?: string;
|
|
132
|
+
spanId?: string;
|
|
133
|
+
labels?: Record<string, string | number | boolean>;
|
|
134
|
+
error?: unknown;
|
|
135
|
+
service: EcsServiceFields;
|
|
136
|
+
http?: {
|
|
137
|
+
method: string;
|
|
138
|
+
path: string;
|
|
139
|
+
status: number;
|
|
140
|
+
durationMs: number;
|
|
141
|
+
clientIp?: string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** Input for one ECS log event. */
|
|
145
|
+
export interface EcsLogEvent {
|
|
146
|
+
level: EcsLogLevel;
|
|
147
|
+
message: string;
|
|
148
|
+
action?: string;
|
|
149
|
+
labels?: Record<string, string | number | boolean>;
|
|
150
|
+
error?: unknown;
|
|
151
|
+
fields?: Record<string, unknown>;
|
|
152
|
+
requestId?: string;
|
|
153
|
+
traceId?: string;
|
|
154
|
+
spanId?: string;
|
|
155
|
+
/** Populated on HTTP/MCP access log events for {@link CliLogConfig.enrich}. */
|
|
156
|
+
http?: LogEnrichContext["http"];
|
|
157
|
+
}
|
|
158
|
+
/** Options for {@link formatEcsLine}. */
|
|
159
|
+
export interface FormatEcsLineOpts {
|
|
160
|
+
service: EcsServiceFields;
|
|
161
|
+
event: EcsLogEvent;
|
|
162
|
+
/** Additive fields merged after the ECS baseline (cannot override protected keys). */
|
|
163
|
+
enrich?: (ctx: LogEnrichContext) => Record<string, unknown>;
|
|
164
|
+
}
|
|
165
|
+
/** Formats one ECS Logging–compatible JSON log line (newline omitted). */
|
|
166
|
+
export declare function formatEcsLine(opts: FormatEcsLineOpts): string;
|
|
167
|
+
/** @deprecated Pass {@link FormatEcsLineOpts} instead. */
|
|
168
|
+
export declare function formatEcsLine(service: EcsServiceFields, event: EcsLogEvent): string;
|
|
116
169
|
/**
|
|
117
170
|
* How a leaf handler was dispatched.
|
|
118
171
|
*/
|
|
@@ -324,6 +377,10 @@ export interface CliHttpWireContext {
|
|
|
324
377
|
clientIp: string;
|
|
325
378
|
path: string;
|
|
326
379
|
method: string;
|
|
380
|
+
/** W3C trace id when `traceparent` is present on the request. */
|
|
381
|
+
traceId?: string;
|
|
382
|
+
/** Span id for this server hop when `traceparent` is present. */
|
|
383
|
+
spanId?: string;
|
|
327
384
|
}
|
|
328
385
|
/** Wire-level MCP hooks on JSON-RPC messages (observe-only). */
|
|
329
386
|
export interface CliMcpWireHooks {
|
|
@@ -672,6 +729,8 @@ export interface InvokeHookContext {
|
|
|
672
729
|
request: Request;
|
|
673
730
|
clientIp: string;
|
|
674
731
|
requestId: string;
|
|
732
|
+
traceId?: string;
|
|
733
|
+
spanId?: string;
|
|
675
734
|
};
|
|
676
735
|
mcp?: {
|
|
677
736
|
rpcMethod: string;
|
|
@@ -717,9 +776,9 @@ export interface ReadinessContext {
|
|
|
717
776
|
appConfig: AnyAppConfigSnapshot;
|
|
718
777
|
runtime: ServerRuntime;
|
|
719
778
|
}
|
|
720
|
-
/** Framework logging defaults (ECS json or human text on stderr). */
|
|
779
|
+
/** Framework logging defaults (ECS Logging json or human text on stderr). */
|
|
721
780
|
export interface CliLogConfig {
|
|
722
|
-
/** `json` = ECS lines; `text` = human stderr lines. Default: `json`. */
|
|
781
|
+
/** `json` = ECS Logging lines; `text` = human stderr lines. Default: `json`. */
|
|
723
782
|
format?: "json" | "text";
|
|
724
783
|
/** Tee stderr + append; relative paths resolve under the app config dir. */
|
|
725
784
|
file?: string;
|
|
@@ -727,6 +786,16 @@ export interface CliLogConfig {
|
|
|
727
786
|
access?: boolean;
|
|
728
787
|
/** Emit error events after the hook pipeline. Default: true. */
|
|
729
788
|
errors?: boolean;
|
|
789
|
+
/**
|
|
790
|
+
* Add non-standard fields to each JSON log line after the ECS baseline.
|
|
791
|
+
* Cannot override `@timestamp`, `log.level`, `message`, `ecs.version`, or service fields.
|
|
792
|
+
*/
|
|
793
|
+
enrich?: (ctx: LogEnrichContext) => Record<string, unknown>;
|
|
794
|
+
/**
|
|
795
|
+
* Full control over JSON log line serialization. When set, bypasses the built-in ECS formatter.
|
|
796
|
+
* The consumer owns the entire line (including newline omission).
|
|
797
|
+
*/
|
|
798
|
+
serialize?: (ctx: LogEnrichContext) => string;
|
|
730
799
|
}
|
|
731
800
|
/**
|
|
732
801
|
* Program root passed to {@link Cli}.
|
|
@@ -870,17 +939,6 @@ export interface CliSchemaRootExport extends CliSchemaExport {
|
|
|
870
939
|
/** Program-level error JSON Schema when configured on `httpServer.errors` or `mcpServer.errors`. */
|
|
871
940
|
errorSchema?: Record<string, unknown>;
|
|
872
941
|
}
|
|
873
|
-
/** Severity label for ECS `log.level`. */
|
|
874
|
-
export type EcsLogLevel = "debug" | "info" | "warn" | "error";
|
|
875
|
-
/** Input for one ECS log event. */
|
|
876
|
-
export interface EcsLogEvent {
|
|
877
|
-
level: EcsLogLevel;
|
|
878
|
-
message: string;
|
|
879
|
-
action?: string;
|
|
880
|
-
labels?: Record<string, string | number | boolean>;
|
|
881
|
-
error?: unknown;
|
|
882
|
-
fields?: Record<string, unknown>;
|
|
883
|
-
}
|
|
884
942
|
/** Resolved logging options for a server or invoke session. */
|
|
885
943
|
export interface ResolvedLogConfig {
|
|
886
944
|
format: "json" | "text";
|
|
@@ -888,6 +946,8 @@ export interface ResolvedLogConfig {
|
|
|
888
946
|
access: boolean;
|
|
889
947
|
errors: boolean;
|
|
890
948
|
dev: boolean;
|
|
949
|
+
enrich?: CliLogConfig["enrich"];
|
|
950
|
+
serialize?: CliLogConfig["serialize"];
|
|
891
951
|
}
|
|
892
952
|
/** Options for {@link LogEmitter}. */
|
|
893
953
|
export interface LogEmitterOpts {
|
|
@@ -911,10 +971,18 @@ declare class LogEmitter {
|
|
|
911
971
|
durationMs: number;
|
|
912
972
|
requestId?: string;
|
|
913
973
|
clientIp?: string;
|
|
974
|
+
traceId?: string;
|
|
975
|
+
spanId?: string;
|
|
914
976
|
}): void;
|
|
915
977
|
/** Error log after the hook pipeline (real stack always included). */
|
|
916
|
-
emitInvokeError(failureKind: string, error: unknown, clientMessage: string,
|
|
978
|
+
emitInvokeError(failureKind: string, error: unknown, clientMessage: string, meta?: {
|
|
979
|
+
labels?: Record<string, string | number | boolean>;
|
|
980
|
+
requestId?: string;
|
|
981
|
+
traceId?: string;
|
|
982
|
+
spanId?: string;
|
|
983
|
+
}): void;
|
|
917
984
|
private formatLine;
|
|
985
|
+
private buildEnrichContext;
|
|
918
986
|
private formatTextLine;
|
|
919
987
|
private appendFile;
|
|
920
988
|
}
|
|
@@ -996,6 +1064,8 @@ export declare class Cli {
|
|
|
996
1064
|
request: Request;
|
|
997
1065
|
clientIp: string;
|
|
998
1066
|
requestId: string;
|
|
1067
|
+
traceId?: string;
|
|
1068
|
+
spanId?: string;
|
|
999
1069
|
};
|
|
1000
1070
|
mcp?: {
|
|
1001
1071
|
rpcMethod: string;
|
package/package.json
CHANGED
package/src/builtins/http.ts
CHANGED
|
@@ -18,7 +18,7 @@ const HTTP_SERVE_OPTIONS: CliOption[] = [
|
|
|
18
18
|
{ name: "obscure-errors", description: "Hide unexpected errors from clients.", kind: CliOptionKind.Presence },
|
|
19
19
|
{
|
|
20
20
|
name: "log-format",
|
|
21
|
-
description: "Log format: json (ECS) or text.",
|
|
21
|
+
description: "Log format: json (ECS Logging) or text.",
|
|
22
22
|
kind: CliOptionKind.Enum,
|
|
23
23
|
choices: ["json", "text"],
|
|
24
24
|
},
|
package/src/builtins/mcp.ts
CHANGED
|
@@ -13,7 +13,7 @@ const MCP_SERVE_OPTIONS: CliOption[] = [
|
|
|
13
13
|
{ name: "obscure-errors", description: "Hide unexpected errors from clients.", kind: CliOptionKind.Presence },
|
|
14
14
|
{
|
|
15
15
|
name: "log-format",
|
|
16
|
-
description: "Log format: json (ECS) or text.",
|
|
16
|
+
description: "Log format: json (ECS Logging) or text.",
|
|
17
17
|
kind: CliOptionKind.Enum,
|
|
18
18
|
choices: ["json", "text"],
|
|
19
19
|
},
|
package/src/core/types.ts
CHANGED
|
@@ -219,6 +219,10 @@ export interface CliHttpWireContext {
|
|
|
219
219
|
clientIp: string;
|
|
220
220
|
path: string;
|
|
221
221
|
method: string;
|
|
222
|
+
/** W3C trace id when `traceparent` is present on the request. */
|
|
223
|
+
traceId?: string;
|
|
224
|
+
/** Span id for this server hop when `traceparent` is present. */
|
|
225
|
+
spanId?: string;
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
/** Wire-level MCP hooks on JSON-RPC messages (observe-only). */
|
|
@@ -596,7 +600,7 @@ export interface InvokeHookContext {
|
|
|
596
600
|
locals: CliLocals;
|
|
597
601
|
runtime?: ServerRuntime;
|
|
598
602
|
appConfig: AnyAppConfigSnapshot;
|
|
599
|
-
http?: { request: Request; clientIp: string; requestId: string };
|
|
603
|
+
http?: { request: Request; clientIp: string; requestId: string; traceId?: string; spanId?: string };
|
|
600
604
|
mcp?: { rpcMethod: string; toolName?: string; requestId: string };
|
|
601
605
|
}
|
|
602
606
|
|
|
@@ -641,9 +645,9 @@ export interface ReadinessContext {
|
|
|
641
645
|
runtime: ServerRuntime;
|
|
642
646
|
}
|
|
643
647
|
|
|
644
|
-
/** Framework logging defaults (ECS json or human text on stderr). */
|
|
648
|
+
/** Framework logging defaults (ECS Logging json or human text on stderr). */
|
|
645
649
|
export interface CliLogConfig {
|
|
646
|
-
/** `json` = ECS lines; `text` = human stderr lines. Default: `json`. */
|
|
650
|
+
/** `json` = ECS Logging lines; `text` = human stderr lines. Default: `json`. */
|
|
647
651
|
format?: "json" | "text";
|
|
648
652
|
/** Tee stderr + append; relative paths resolve under the app config dir. */
|
|
649
653
|
file?: string;
|
|
@@ -651,6 +655,16 @@ export interface CliLogConfig {
|
|
|
651
655
|
access?: boolean;
|
|
652
656
|
/** Emit error events after the hook pipeline. Default: true. */
|
|
653
657
|
errors?: boolean;
|
|
658
|
+
/**
|
|
659
|
+
* Add non-standard fields to each JSON log line after the ECS baseline.
|
|
660
|
+
* Cannot override `@timestamp`, `log.level`, `message`, `ecs.version`, or service fields.
|
|
661
|
+
*/
|
|
662
|
+
enrich?: (ctx: import("../log/ecs.ts").LogEnrichContext) => Record<string, unknown>;
|
|
663
|
+
/**
|
|
664
|
+
* Full control over JSON log line serialization. When set, bypasses the built-in ECS formatter.
|
|
665
|
+
* The consumer owns the entire line (including newline omission).
|
|
666
|
+
*/
|
|
667
|
+
serialize?: (ctx: import("../log/ecs.ts").LogEnrichContext) => string;
|
|
654
668
|
}
|
|
655
669
|
|
|
656
670
|
/**
|
package/src/docs/http-guide.ts
CHANGED
|
@@ -45,7 +45,7 @@ export function generateHttpGuide(root: CliProgram): string {
|
|
|
45
45
|
"",
|
|
46
46
|
`Listens on **${baseUrl}** by default (\`httpServer.host\` / \`httpServer.port\`).`,
|
|
47
47
|
"",
|
|
48
|
-
"Bind is localhost-only
|
|
48
|
+
"Bind is localhost-only by default — use a reverse proxy for remote access.",
|
|
49
49
|
"",
|
|
50
50
|
"## Endpoints",
|
|
51
51
|
"",
|
|
@@ -80,6 +80,16 @@ export function generateHttpGuide(root: CliProgram): string {
|
|
|
80
80
|
"",
|
|
81
81
|
'Errors use `{ "error": "..." }` with `400`, `404`, `503`, or `500`.',
|
|
82
82
|
"",
|
|
83
|
+
"## Logging",
|
|
84
|
+
"",
|
|
85
|
+
"Server logs go to **stderr** (one JSON object per line by default).",
|
|
86
|
+
"",
|
|
87
|
+
"- Configure with `program.log` on the program root",
|
|
88
|
+
"- **`enrich`** — add custom JSON fields on top of the default line",
|
|
89
|
+
"- **`serialize`** — replace the formatter and emit your own line shape",
|
|
90
|
+
"",
|
|
91
|
+
"See the argsbarg [logging guide](https://github.com/bdombro/bun-argsbarg/blob/main/docs/logging.md) for examples and the full `LogEnrichContext` shape.",
|
|
92
|
+
"",
|
|
83
93
|
];
|
|
84
94
|
|
|
85
95
|
if (root.appConfig?.entries && Object.keys(root.appConfig.entries).length > 0) {
|
package/src/docs/save.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { docsTopicContent } from "./resolve.ts";
|
|
|
8
8
|
export const DOCS_SAVE_DIR = "docs";
|
|
9
9
|
|
|
10
10
|
/** Builtin docs topics generated by argsbarg (not consumer `docs.topics`). */
|
|
11
|
-
export const DOCS_GENERATED_SAVE_TOPICS = ["mcp", "cli", "skill"] as const;
|
|
11
|
+
export const DOCS_GENERATED_SAVE_TOPICS = ["mcp", "cli", "skill", "http"] as const;
|
|
12
12
|
|
|
13
13
|
/** Whether `--save` should prepend a generated-file hint (argsbarg writers only). */
|
|
14
14
|
export function docsTopicIsGeneratedByArgsbarg(topic: string): boolean {
|
|
@@ -139,7 +139,7 @@ export async function executeHttpRouteCall(
|
|
|
139
139
|
pathParams: Record<string, string>,
|
|
140
140
|
query: Record<string, string>,
|
|
141
141
|
body: Record<string, unknown>,
|
|
142
|
-
http?: { request: Request; clientIp: string; requestId: string },
|
|
142
|
+
http?: { request: Request; clientIp: string; requestId: string; traceId?: string; spanId?: string },
|
|
143
143
|
): Promise<HeadlessToolCallResult> {
|
|
144
144
|
const argvResult = httpRequestToArgv(cli.program, route, pathParams, query, body);
|
|
145
145
|
if ("error" in argvResult) {
|
package/src/hooks/run.ts
CHANGED
|
@@ -134,8 +134,13 @@ export async function runErrorPipeline(
|
|
|
134
134
|
failureKind === "unexpected" && obscureUnexpected ? obscureUnexpectedClientMessage() : clientError.message;
|
|
135
135
|
|
|
136
136
|
emitter?.emitInvokeError(failureKind, err, displayMessage, {
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
labels: {
|
|
138
|
+
invocation: hookCtx.invocation,
|
|
139
|
+
path: hookCtx.path.join(" "),
|
|
140
|
+
},
|
|
141
|
+
requestId: hookCtx.locals.requestId,
|
|
142
|
+
traceId: hookCtx.http?.traceId,
|
|
143
|
+
spanId: hookCtx.http?.spanId,
|
|
139
144
|
});
|
|
140
145
|
|
|
141
146
|
return { failureKind, clientError, errorMsg: displayMessage };
|
package/src/http/server.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
headlessFailureToHttpResponse,
|
|
10
10
|
headlessSuccessToHttpResponse,
|
|
11
11
|
} from "../headless/tool-call.ts";
|
|
12
|
+
import { extractTraceContext, formatTraceparent } from "../log/trace.ts";
|
|
12
13
|
import type { Cli } from "../runtime/cli.ts";
|
|
13
14
|
import { leafHttpResponseDefaults } from "../runtime/exposure.ts";
|
|
14
15
|
import type { ResolvedHttpServeConfig } from "../server/overrides.ts";
|
|
@@ -70,12 +71,14 @@ export async function handleApiRequest(
|
|
|
70
71
|
const requestId = randomUUID();
|
|
71
72
|
const url = new URL(request.url);
|
|
72
73
|
const clientIp = resolveClientIp(request, trustProxy);
|
|
74
|
+
const trace = extractTraceContext(request);
|
|
73
75
|
const wireCtx: CliHttpWireContext = {
|
|
74
76
|
request,
|
|
75
77
|
requestId,
|
|
76
78
|
clientIp,
|
|
77
79
|
path: url.pathname,
|
|
78
80
|
method: request.method,
|
|
81
|
+
...(trace ? { traceId: trace.traceId, spanId: trace.spanId } : {}),
|
|
79
82
|
};
|
|
80
83
|
const hooks = cli.server?.httpHooks ?? cli.program.httpServer?.hooks;
|
|
81
84
|
const emitter = cli.server?.emitter;
|
|
@@ -99,8 +102,22 @@ export async function handleApiRequest(
|
|
|
99
102
|
durationMs,
|
|
100
103
|
requestId,
|
|
101
104
|
clientIp,
|
|
105
|
+
traceId: trace?.traceId,
|
|
106
|
+
spanId: trace?.spanId,
|
|
107
|
+
});
|
|
108
|
+
if (!trace) {
|
|
109
|
+
return response;
|
|
110
|
+
}
|
|
111
|
+
const headers = new Headers(response.headers);
|
|
112
|
+
headers.set(
|
|
113
|
+
"traceparent",
|
|
114
|
+
formatTraceparent({ traceId: trace.traceId, spanId: trace.spanId, sampled: trace.sampled }),
|
|
115
|
+
);
|
|
116
|
+
return new Response(response.body, {
|
|
117
|
+
status: response.status,
|
|
118
|
+
statusText: response.statusText,
|
|
119
|
+
headers,
|
|
102
120
|
});
|
|
103
|
-
return response;
|
|
104
121
|
};
|
|
105
122
|
|
|
106
123
|
await hooks?.onRequest?.(wireCtx);
|
|
@@ -168,6 +185,7 @@ export async function handleApiRequest(
|
|
|
168
185
|
request,
|
|
169
186
|
clientIp,
|
|
170
187
|
requestId,
|
|
188
|
+
...(trace ? { traceId: trace.traceId, spanId: trace.spanId } : {}),
|
|
171
189
|
});
|
|
172
190
|
if (result.ok) {
|
|
173
191
|
const leafHttp = leafHttpResponseDefaults(match.route.leaf);
|
package/src/index.ts
CHANGED
|
@@ -79,6 +79,8 @@ export {
|
|
|
79
79
|
wantsExplicitJson,
|
|
80
80
|
} from "./headless/routing.ts";
|
|
81
81
|
export { generateOpenApi, openApiJson } from "./http/openapi.ts";
|
|
82
|
+
export type { EcsLogEvent, LogEnrichContext } from "./log/ecs.ts";
|
|
83
|
+
export { ECS_VERSION, formatEcsLine } from "./log/ecs.ts";
|
|
82
84
|
export type { McpBundlePaths, PackMcpBundleOpts } from "./mcp/bundle.ts";
|
|
83
85
|
export { defaultMcpBundlePaths, generateMcpManifest, packMcpBundle } from "./mcp/bundle.ts";
|
|
84
86
|
export { Cli, type CliInvokeKind, type CliInvokeResult } from "./runtime/cli.ts";
|