@agledger/cli 1.3.0 → 1.4.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 +27 -5
- package/SKILL.md +5 -2
- package/dist/api-client.d.ts +3 -3
- package/dist/api-client.js +46 -5
- package/dist/base.d.ts +12 -10
- package/dist/base.js +30 -18
- package/dist/commands/api.d.ts +6 -5
- package/dist/commands/api.js +39 -11
- package/dist/commands/auth.d.ts +1 -2
- package/dist/commands/auth.js +2 -3
- package/dist/commands/config.d.ts +1 -2
- package/dist/commands/config.js +1 -2
- package/dist/commands/discover.d.ts +2 -3
- package/dist/commands/discover.js +3 -4
- package/dist/commands/docs.d.ts +1 -2
- package/dist/commands/docs.js +2 -3
- package/dist/commands/help-json.d.ts +0 -1
- package/dist/commands/help-json.js +0 -1
- package/dist/commands/list-commands.d.ts +1 -2
- package/dist/commands/list-commands.js +1 -2
- package/dist/commands/login.d.ts +0 -1
- package/dist/commands/login.js +0 -1
- package/dist/commands/logout.d.ts +0 -1
- package/dist/commands/logout.js +0 -1
- package/dist/commands/verify.d.ts +3 -4
- package/dist/commands/verify.js +4 -5
- package/dist/hooks/command-not-found.d.ts +0 -1
- package/dist/hooks/command-not-found.js +1 -2
- package/dist/util/config.d.ts +0 -1
- package/dist/util/config.js +0 -1
- package/dist/util/field-parser.d.ts +35 -11
- package/dist/util/field-parser.js +35 -15
- package/oclif.manifest.json +18 -2
- package/package.json +6 -2
- package/dist/api-client.d.ts.map +0 -1
- package/dist/api-client.js.map +0 -1
- package/dist/base.d.ts.map +0 -1
- package/dist/base.js.map +0 -1
- package/dist/commands/api.d.ts.map +0 -1
- package/dist/commands/api.js.map +0 -1
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/config.d.ts.map +0 -1
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/discover.d.ts.map +0 -1
- package/dist/commands/discover.js.map +0 -1
- package/dist/commands/docs.d.ts.map +0 -1
- package/dist/commands/docs.js.map +0 -1
- package/dist/commands/help-json.d.ts.map +0 -1
- package/dist/commands/help-json.js.map +0 -1
- package/dist/commands/list-commands.d.ts.map +0 -1
- package/dist/commands/list-commands.js.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/verify.d.ts.map +0 -1
- package/dist/commands/verify.js.map +0 -1
- package/dist/hooks/command-not-found.d.ts.map +0 -1
- package/dist/hooks/command-not-found.js.map +0 -1
- package/dist/util/config.d.ts.map +0 -1
- package/dist/util/config.js.map +0 -1
- package/dist/util/field-parser.d.ts.map +0 -1
- package/dist/util/field-parser.js.map +0 -1
package/README.md
CHANGED
|
@@ -38,10 +38,13 @@ agledger api POST /v1/records --data '{
|
|
|
38
38
|
"criteria": { "summary": "summarize Q3 filings" }
|
|
39
39
|
}'
|
|
40
40
|
|
|
41
|
-
# Or build the body with typed fields
|
|
41
|
+
# Or build the body with typed fields. Use -f for a value that must stay a
|
|
42
|
+
# string: the Server does not coerce a JSON body, so an all-digit identifier
|
|
43
|
+
# passed with -F is sent as a number and refused.
|
|
42
44
|
agledger api POST /v1/records \
|
|
43
45
|
-F type=notarize-generic-v1 \
|
|
44
|
-
-F criteria.summary='summarize Q3 filings'
|
|
46
|
+
-F criteria.summary='summarize Q3 filings' \
|
|
47
|
+
-f externalTaskId=4821
|
|
45
48
|
|
|
46
49
|
# Submit a completion. On a gated record the principal then renders a Verdict
|
|
47
50
|
# (accept / reject) on the Completion; use the route documented in the API
|
|
@@ -64,8 +67,26 @@ agledger api POST /v1/records/<record-id>/completions \
|
|
|
64
67
|
| `--input file.json` | Complex payloads; reuse files |
|
|
65
68
|
| `--input -` | Pipe JSON from stdin |
|
|
66
69
|
| `-F key=value` (repeatable) | Shell-friendly; typed (`true`/`false`/`null`/numbers); nested via `a.b=v`; arrays via `arr[]=v`; JSON literals via `k={...}` / `k=[...]` |
|
|
70
|
+
| `-f key=value` (repeatable) | Same, but the value is taken verbatim as a string |
|
|
67
71
|
|
|
68
|
-
Merging order (low → high): `--data` → `--input` → `-F` → `--query`. Later sources override earlier keys.
|
|
72
|
+
Merging order (low → high): `--data` → `--input` → `-F`/`-f` → `--query`. Later sources override earlier keys.
|
|
73
|
+
|
|
74
|
+
### `-F` types the value; `-f` does not
|
|
75
|
+
|
|
76
|
+
The Server does not coerce the fields of a JSON body, so a field declared
|
|
77
|
+
`string` refuses a number. `publisher`, `platformRef`, `projectRef`,
|
|
78
|
+
`externalTaskId` and `correlationId` are plain strings that carry identifiers
|
|
79
|
+
minted by other systems, and those are frequently all digits:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
agledger api POST /v1/records -F externalTaskId=4821 # sends 4821, refused
|
|
83
|
+
agledger api POST /v1/records -f externalTaskId=4821 # sends "4821"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Reach for `-f` rather than quoting. Shell quotes that survive into the value
|
|
87
|
+
(`-F externalTaskId='"4821"'`) reach the Server as a string with the quote
|
|
88
|
+
characters inside it, and the Server accepts that: the Record is notarized,
|
|
89
|
+
signed and immutable, with an identifier no other system will match.
|
|
69
90
|
|
|
70
91
|
## Agent-native DX
|
|
71
92
|
|
|
@@ -73,6 +94,7 @@ Merging order (low → high): `--data` → `--input` → `-F` → `--query`. Lat
|
|
|
73
94
|
- `--quiet` suppresses output (exit code only)
|
|
74
95
|
- `--dry-run` on `agledger api` shows the request without sending
|
|
75
96
|
- `--paginate` on GET follows cursor pagination and streams NDJSON
|
|
97
|
+
- Every POST carries a generated `Idempotency-Key`, so one invocation is replay-safe on its own. Retrying a call that may already have reached the Server? Pass `--idempotency-key` with the first attempt's key and the Server replays the original result instead of recording the work twice
|
|
76
98
|
- Structured errors on stderr: `{error: true, code, message, suggestion, ...}`; API errors pass through verbatim
|
|
77
99
|
- Semantic exit codes: 0 (OK), 1 (general), 2 (usage), 3 (auth), 4 (forbidden), 5 (not found), 6 (conflict), 7 (rate limit), 8 (server), 9 (network), 10 (timeout). **1 is the catch-all**: an API error whose status maps to nothing more specific (a 400, for example) exits 1, as does a chain that fails `agledger verify`. Read the `code` field on stderr to tell them apart, and treat any non-zero as failure rather than keying on 1 alone.
|
|
78
100
|
- `NO_COLOR` supported per [no-color.org](https://no-color.org)
|
|
@@ -120,9 +142,9 @@ AGLEDGER_API_KEY=... AGLEDGER_API_URL=... agledger api GET /v1/records
|
|
|
120
142
|
**Credential precedence** (highest first), applied per command:
|
|
121
143
|
|
|
122
144
|
- **API key:** `--api-key` flag → `AGLEDGER_API_KEY` env → stored profile (`--profile <name>`, else the active profile).
|
|
123
|
-
- **API URL:** `--api-url` flag → `AGLEDGER_API_URL` env → stored profile URL
|
|
145
|
+
- **API URL:** `--api-url` flag → `AGLEDGER_API_URL` env → stored profile URL. There is no default: AGLedger is self-hosted, so a call with no URL from any of those three sources exits 2 with `CONFIG_ERROR` rather than guessing a host.
|
|
124
146
|
|
|
125
|
-
So once you `agledger login`, plain `agledger api ...` calls authenticate from the stored profile with no flags or env. `--dry-run` echoes the resolved auth (URL, source, masked key) so you can confirm which credentials a call would use without sending it.
|
|
147
|
+
So once you `agledger login`, plain `agledger api ...` calls authenticate from the stored profile with no flags or env. `--dry-run` echoes the resolved auth (URL, source, masked key) so you can confirm which credentials a call would use without sending it; when no URL is configured it reports `apiUrl: null` and names the error the real call would raise.
|
|
126
148
|
|
|
127
149
|
Agent keys (`agl_agt_*`) and admin keys (`agl_adm_*`) are both accepted; the API routes them appropriately.
|
|
128
150
|
|
package/SKILL.md
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
Thin cover over the AGLedger API. The CLI passes your call through to the API and forwards the response. No flag-to-body translation, no drift.
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
|
-
Credentials resolve per command with this precedence: `--api-key` flag > `AGLEDGER_API_KEY` env > stored profile (after `agledger login`). API URL: `--api-url` flag > `AGLEDGER_API_URL` env > stored profile URL
|
|
6
|
+
Credentials resolve per command with this precedence: `--api-key` flag > `AGLEDGER_API_KEY` env > stored profile (after `agledger login`). API URL: `--api-url` flag > `AGLEDGER_API_URL` env > stored profile URL.
|
|
7
|
+
|
|
8
|
+
**There is no default API URL, and it is not optional.** AGLedger is self-hosted, so the CLI has no server to guess. If none of those three sources supplies one, the command exits 2 with `CONFIG_ERROR` rather than calling a placeholder host.
|
|
7
9
|
|
|
8
10
|
## Primary command: `agledger api`
|
|
9
11
|
Call any API endpoint:
|
|
10
12
|
|
|
11
13
|
```
|
|
12
|
-
agledger api <METHOD> <PATH> [--data JSON | --input FILE | -F key=value ...]
|
|
14
|
+
agledger api <METHOD> <PATH> [--data JSON | --input FILE | -F key=value | -f key=value ...]
|
|
13
15
|
```
|
|
14
16
|
|
|
15
17
|
## Workflow (start here)
|
|
@@ -25,6 +27,7 @@ agledger api <METHOD> <PATH> [--data JSON | --input FILE | -F key=value ...]
|
|
|
25
27
|
- `--input file.json`: read JSON from file
|
|
26
28
|
- `--input -`: read JSON from stdin
|
|
27
29
|
- `-F key=value`: repeatable; types parsed (`true`/`false`/`null`/numbers); nested via `a.b=v`; arrays via `arr[]=v`
|
|
30
|
+
- `-f key=value`: same, value taken verbatim as a string. Required for identifiers that look numeric (`externalTaskId`, `correlationId`, `platformRef`, `projectRef`, `publisher`): the Server does not coerce a JSON body, so `-F externalTaskId=4821` sends a number and is refused. Do not quote around `-F` to work around it; the quote characters land inside the notarized value.
|
|
28
31
|
|
|
29
32
|
## Discovery commands
|
|
30
33
|
- `agledger list-commands --json`: full CLI inventory (10 commands)
|
package/dist/api-client.d.ts
CHANGED
|
@@ -7,17 +7,17 @@ export declare class ApiClient {
|
|
|
7
7
|
private readonly apiUrl;
|
|
8
8
|
/** Null sends no Authorization header: the Server's discovery surfaces
|
|
9
9
|
* (/health, /llms.txt, /openapi.json, /v1/conformance) answer unauthenticated,
|
|
10
|
-
* and an agent holding only a URL must be able to reach them
|
|
10
|
+
* and an agent holding only a URL must be able to reach them. */
|
|
11
11
|
private readonly apiKey;
|
|
12
12
|
private readonly userAgent;
|
|
13
13
|
private readonly timeoutMs;
|
|
14
14
|
constructor(apiUrl: string, apiKey: string | null, version?: string, timeoutMs?: number);
|
|
15
15
|
/** The base URL requests go to. Surfaced so a network failure can name the
|
|
16
|
-
* host it actually tried instead of a bare "fetch failed"
|
|
16
|
+
* host it actually tried instead of a bare "fetch failed". */
|
|
17
17
|
get baseUrl(): string;
|
|
18
18
|
request(method: string, path: string, options?: {
|
|
19
19
|
query?: Record<string, unknown>;
|
|
20
20
|
body?: unknown;
|
|
21
|
+
idempotencyKey?: string;
|
|
21
22
|
}): Promise<ApiResponse>;
|
|
22
23
|
}
|
|
23
|
-
//# sourceMappingURL=api-client.d.ts.map
|
package/dist/api-client.js
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize one query parameter.
|
|
3
|
+
*
|
|
4
|
+
* A plain object becomes the API's bracket notation (`metadata[key]=value`),
|
|
5
|
+
* which is what the `criteria` and `metadata` filters on
|
|
6
|
+
* GET /v1/records/search expect. Running it through `String(value)` instead
|
|
7
|
+
* sent the literal `[object Object]`, so every such filter returned 400.
|
|
8
|
+
*
|
|
9
|
+
* A Date becomes ISO-8601 rather than the JS locale form, which the date-time
|
|
10
|
+
* query params reject.
|
|
11
|
+
*/
|
|
12
|
+
function appendQueryParam(search, key, value) {
|
|
13
|
+
if (value instanceof Date) {
|
|
14
|
+
search.set(key, value.toISOString());
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
for (const item of value) {
|
|
19
|
+
if (item === undefined || item === null)
|
|
20
|
+
continue;
|
|
21
|
+
search.append(key, item instanceof Date ? item.toISOString() : String(item));
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === 'object') {
|
|
26
|
+
for (const [sub, subValue] of Object.entries(value)) {
|
|
27
|
+
if (subValue === undefined || subValue === null)
|
|
28
|
+
continue;
|
|
29
|
+
search.set(`${key}[${sub}]`, subValue instanceof Date ? subValue.toISOString() : String(subValue));
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
search.set(key, String(value));
|
|
34
|
+
}
|
|
1
35
|
export class ApiClient {
|
|
2
36
|
apiUrl;
|
|
3
37
|
/** Null sends no Authorization header: the Server's discovery surfaces
|
|
4
38
|
* (/health, /llms.txt, /openapi.json, /v1/conformance) answer unauthenticated,
|
|
5
|
-
* and an agent holding only a URL must be able to reach them
|
|
39
|
+
* and an agent holding only a URL must be able to reach them. */
|
|
6
40
|
apiKey;
|
|
7
41
|
userAgent;
|
|
8
42
|
timeoutMs;
|
|
@@ -13,12 +47,12 @@ export class ApiClient {
|
|
|
13
47
|
this.timeoutMs = timeoutMs;
|
|
14
48
|
}
|
|
15
49
|
/** The base URL requests go to. Surfaced so a network failure can name the
|
|
16
|
-
* host it actually tried instead of a bare "fetch failed"
|
|
50
|
+
* host it actually tried instead of a bare "fetch failed". */
|
|
17
51
|
get baseUrl() {
|
|
18
52
|
return this.apiUrl;
|
|
19
53
|
}
|
|
20
54
|
async request(method, path, options) {
|
|
21
|
-
// Reject protocol-relative paths ("//host/...")
|
|
55
|
+
// Reject protocol-relative paths ("//host/...") because with `new URL` they would
|
|
22
56
|
// be resolved against the base's protocol and silently retarget the request
|
|
23
57
|
// to an attacker-controlled host. A legitimate API path starts with a single
|
|
24
58
|
// "/". Callers (api.ts) guarantee a leading slash.
|
|
@@ -32,7 +66,7 @@ export class ApiClient {
|
|
|
32
66
|
if (options?.query) {
|
|
33
67
|
for (const [k, v] of Object.entries(options.query)) {
|
|
34
68
|
if (v !== undefined && v !== null) {
|
|
35
|
-
url.searchParams
|
|
69
|
+
appendQueryParam(url.searchParams, k, v);
|
|
36
70
|
}
|
|
37
71
|
}
|
|
38
72
|
}
|
|
@@ -46,6 +80,14 @@ export class ApiClient {
|
|
|
46
80
|
if (options?.body !== undefined) {
|
|
47
81
|
headers['Content-Type'] = 'application/json';
|
|
48
82
|
}
|
|
83
|
+
// POST is the only method the API arms for idempotency: all 18 routes that
|
|
84
|
+
// declare `idempotent: true` are POST, and on any other method the header is
|
|
85
|
+
// ignored. A generated key makes the CLI's own writes replay-safe by default;
|
|
86
|
+
// a caller retrying the same logical operation across processes passes its
|
|
87
|
+
// own key so the second attempt dedups instead of creating a second record.
|
|
88
|
+
if (method.toUpperCase() === 'POST') {
|
|
89
|
+
headers['Idempotency-Key'] = options?.idempotencyKey ?? crypto.randomUUID();
|
|
90
|
+
}
|
|
49
91
|
const controller = new AbortController();
|
|
50
92
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
51
93
|
try {
|
|
@@ -71,4 +113,3 @@ export class ApiClient {
|
|
|
71
113
|
}
|
|
72
114
|
}
|
|
73
115
|
}
|
|
74
|
-
//# sourceMappingURL=api-client.js.map
|
package/dist/base.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AGLedger CLI
|
|
3
|
-
* The CLI is a thin pass-through over the API
|
|
2
|
+
* AGLedger CLI: base command with dual-mode output, auth, and error forwarding.
|
|
3
|
+
* The CLI is a thin pass-through over the API; this base exists to make that
|
|
4
4
|
* pass-through consistent (same exit codes, same error shape, same output modes).
|
|
5
5
|
*
|
|
6
6
|
* NO_COLOR (no-color.org): the CLI emits plain JSON to both stdout (results)
|
|
7
7
|
* and stderr (errors) with no ANSI escapes of its own, so it is trivially
|
|
8
8
|
* NO_COLOR-conformant by construction. oclif's own help/error rendering also
|
|
9
|
-
* honors NO_COLOR via chalk's built-in detection
|
|
9
|
+
* honors NO_COLOR via chalk's built-in detection, so no explicit check needed.
|
|
10
10
|
*/
|
|
11
11
|
import { Command } from '@oclif/core';
|
|
12
12
|
import { ApiClient } from './api-client.js';
|
|
@@ -48,7 +48,7 @@ export declare const ErrorCode: {
|
|
|
48
48
|
};
|
|
49
49
|
export declare abstract class BaseCommand extends Command {
|
|
50
50
|
/** The URL the most recent client was built for, so a network failure can
|
|
51
|
-
* name the host it actually tried
|
|
51
|
+
* name the host it actually tried. */
|
|
52
52
|
private lastApiUrl?;
|
|
53
53
|
static baseFlags: {
|
|
54
54
|
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
@@ -63,8 +63,9 @@ export declare abstract class BaseCommand extends Command {
|
|
|
63
63
|
* Resolve credentials and build the API client.
|
|
64
64
|
*
|
|
65
65
|
* Precedence:
|
|
66
|
-
* API key
|
|
67
|
-
* API URL
|
|
66
|
+
* API key: `--api-key` flag > `AGLEDGER_API_KEY` env > stored profile.
|
|
67
|
+
* API URL: `--api-url` flag > `AGLEDGER_API_URL` env > stored profile url.
|
|
68
|
+
* There is no default; AGLedger is self-hosted.
|
|
68
69
|
*
|
|
69
70
|
* oclif merges the flag and its `env` source into `flags['api-key']` /
|
|
70
71
|
* `flags['api-url']`, so a present value there already represents flag-or-env
|
|
@@ -89,13 +90,14 @@ export declare abstract class BaseCommand extends Command {
|
|
|
89
90
|
'api-url'?: string;
|
|
90
91
|
profile?: string;
|
|
91
92
|
}): {
|
|
92
|
-
apiUrl: string;
|
|
93
|
+
apiUrl: string | null;
|
|
94
|
+
apiUrlSource?: string;
|
|
93
95
|
apiKey: string | null;
|
|
94
96
|
source: 'flag-or-env' | 'profile' | 'none';
|
|
95
97
|
profile?: string;
|
|
96
98
|
};
|
|
97
99
|
/**
|
|
98
|
-
* Call the API. Path is passed through as-is
|
|
100
|
+
* Call the API. Path is passed through as-is; caller provides the full path
|
|
99
101
|
* (e.g. `/v1/records`, `/health`, `/federation/v1/peer`). No auto-prefixing.
|
|
100
102
|
*/
|
|
101
103
|
protected callApi(flags: {
|
|
@@ -105,6 +107,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
105
107
|
}, method: string, path: string, options?: {
|
|
106
108
|
query?: Record<string, unknown>;
|
|
107
109
|
body?: unknown;
|
|
110
|
+
idempotencyKey?: string;
|
|
108
111
|
}): Promise<ApiResponse>;
|
|
109
112
|
protected output(data: unknown): void;
|
|
110
113
|
protected outputNdjson(item: unknown): void;
|
|
@@ -118,7 +121,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
118
121
|
*
|
|
119
122
|
* `suggestion` is overridable because the default names `--data` and
|
|
120
123
|
* `--input`, which only the `api` command has. `verify` was handing users
|
|
121
|
-
* recovery advice for flags it does not accept
|
|
124
|
+
* recovery advice for flags it does not accept.
|
|
122
125
|
*/
|
|
123
126
|
protected parseJsonInput(source: string, fieldName: string, suggestion?: string): unknown;
|
|
124
127
|
/** Read and parse a JSON file with structured errors. `-` reads from stdin. */
|
|
@@ -133,4 +136,3 @@ export declare abstract class BaseCommand extends Command {
|
|
|
133
136
|
protected handleError(err: unknown): never;
|
|
134
137
|
private statusToExitCode;
|
|
135
138
|
}
|
|
136
|
-
//# sourceMappingURL=base.d.ts.map
|
package/dist/base.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AGLedger CLI
|
|
3
|
-
* The CLI is a thin pass-through over the API
|
|
2
|
+
* AGLedger CLI: base command with dual-mode output, auth, and error forwarding.
|
|
3
|
+
* The CLI is a thin pass-through over the API; this base exists to make that
|
|
4
4
|
* pass-through consistent (same exit codes, same error shape, same output modes).
|
|
5
5
|
*
|
|
6
6
|
* NO_COLOR (no-color.org): the CLI emits plain JSON to both stdout (results)
|
|
7
7
|
* and stderr (errors) with no ANSI escapes of its own, so it is trivially
|
|
8
8
|
* NO_COLOR-conformant by construction. oclif's own help/error rendering also
|
|
9
|
-
* honors NO_COLOR via chalk's built-in detection
|
|
9
|
+
* honors NO_COLOR via chalk's built-in detection, so no explicit check needed.
|
|
10
10
|
*/
|
|
11
11
|
import { readFileSync } from 'node:fs';
|
|
12
12
|
import { Command, Flags } from '@oclif/core';
|
|
@@ -51,7 +51,7 @@ export const ErrorCode = {
|
|
|
51
51
|
* Discovery surfaces the Server answers without an Authorization header. A
|
|
52
52
|
* keyless `agledger api GET /health` was refused client-side before any request
|
|
53
53
|
* was made, so an agent holding only a URL had to shell out to curl for exactly
|
|
54
|
-
* the bootstrap arc the product optimizes for
|
|
54
|
+
* the bootstrap arc the product optimizes for.
|
|
55
55
|
*
|
|
56
56
|
* Read-only by construction: only GET qualifies, so this can never wave through
|
|
57
57
|
* a write. Anything not listed still requires a key, and the Server remains the
|
|
@@ -73,7 +73,7 @@ function isPublicPath(method, path) {
|
|
|
73
73
|
}
|
|
74
74
|
export class BaseCommand extends Command {
|
|
75
75
|
/** The URL the most recent client was built for, so a network failure can
|
|
76
|
-
* name the host it actually tried
|
|
76
|
+
* name the host it actually tried. */
|
|
77
77
|
lastApiUrl;
|
|
78
78
|
static baseFlags = {
|
|
79
79
|
json: Flags.boolean({ description: 'Force JSON output (default when stdout is piped)', default: false }),
|
|
@@ -94,8 +94,9 @@ export class BaseCommand extends Command {
|
|
|
94
94
|
* Resolve credentials and build the API client.
|
|
95
95
|
*
|
|
96
96
|
* Precedence:
|
|
97
|
-
* API key
|
|
98
|
-
* API URL
|
|
97
|
+
* API key: `--api-key` flag > `AGLEDGER_API_KEY` env > stored profile.
|
|
98
|
+
* API URL: `--api-url` flag > `AGLEDGER_API_URL` env > stored profile url.
|
|
99
|
+
* There is no default; AGLedger is self-hosted.
|
|
99
100
|
*
|
|
100
101
|
* oclif merges the flag and its `env` source into `flags['api-key']` /
|
|
101
102
|
* `flags['api-url']`, so a present value there already represents flag-or-env
|
|
@@ -119,13 +120,13 @@ export class BaseCommand extends Command {
|
|
|
119
120
|
const apiKey = flagKey ?? profile?.apiKey ?? null;
|
|
120
121
|
// Discovery surfaces answer without auth, so a keyless invocation proceeds
|
|
121
122
|
// anonymously rather than being refused before any request is made. The
|
|
122
|
-
// Server, not the CLI, decides what needs a key
|
|
123
|
+
// Server, not the CLI, decides what needs a key.
|
|
123
124
|
if (!apiKey && !options?.allowAnonymous) {
|
|
124
125
|
this.failWith(ErrorCode.AUTH_REQUIRED, 'No API key. Set AGLEDGER_API_KEY, use --api-key, or run `agledger login`.', ExitCode.AUTH_ERROR);
|
|
125
126
|
}
|
|
126
127
|
// No placeholder: a default of agledger.example.com resolved nowhere and
|
|
127
|
-
// turned a missing config into a DNS failure the user could not read
|
|
128
|
-
//
|
|
128
|
+
// turned a missing config into a DNS failure the user could not read.
|
|
129
|
+
// Every deployment is self-hosted, so there is no sane default.
|
|
129
130
|
const apiUrl = flagUrl ?? profile?.apiUrl;
|
|
130
131
|
if (!apiUrl) {
|
|
131
132
|
this.failWith(ErrorCode.CONFIG_ERROR, 'No API URL configured. AGLedger is self-hosted, so there is no default server to call.', ExitCode.USAGE_ERROR, 'Pass --api-url <url>, set AGLEDGER_API_URL, or run `agledger login --api-url <url> --api-key <key>`.');
|
|
@@ -147,17 +148,30 @@ export class BaseCommand extends Command {
|
|
|
147
148
|
const flagUrl = flags['api-url'] || undefined;
|
|
148
149
|
const apiKey = flagKey ?? profile?.apiKey ?? null;
|
|
149
150
|
const source = flagKey ? 'flag-or-env' : profile?.apiKey ? 'profile' : 'none';
|
|
150
|
-
|
|
151
|
+
// Null, not a placeholder. `agledger.example.com` was removed from
|
|
152
|
+
// `createApiClient`, which now refuses to build a client without a URL, but
|
|
153
|
+
// this sibling kept it. The whole job of --dry-run is to report what the
|
|
154
|
+
// real call would do, and it was reporting a host the real call refuses to
|
|
155
|
+
// use: the unconfigured case printed agledger.example.com and exited 0
|
|
156
|
+
// while the same invocation without --dry-run exited 2 with CONFIG_ERROR.
|
|
157
|
+
const apiUrl = flagUrl ?? profile?.apiUrl ?? null;
|
|
151
158
|
const mask = (k) => (k.length <= 4 ? '****' : `****${k.slice(-4)}`);
|
|
152
159
|
return {
|
|
153
160
|
apiUrl,
|
|
154
161
|
apiKey: apiKey ? mask(apiKey) : null,
|
|
155
162
|
source,
|
|
163
|
+
// A dry run whose real counterpart would refuse to send says so, rather
|
|
164
|
+
// than leaving a bare `"apiUrl": null` for the reader to interpret.
|
|
165
|
+
...(apiUrl === null
|
|
166
|
+
? {
|
|
167
|
+
apiUrlSource: 'unconfigured: this call would fail with CONFIG_ERROR (exit 2). Pass --api-url <url>, set AGLEDGER_API_URL, or run `agledger login --api-url <url> --api-key <key>`.',
|
|
168
|
+
}
|
|
169
|
+
: {}),
|
|
156
170
|
...(source === 'profile' && profileName ? { profile: profileName } : {}),
|
|
157
171
|
};
|
|
158
172
|
}
|
|
159
173
|
/**
|
|
160
|
-
* Call the API. Path is passed through as-is
|
|
174
|
+
* Call the API. Path is passed through as-is; caller provides the full path
|
|
161
175
|
* (e.g. `/v1/records`, `/health`, `/federation/v1/peer`). No auto-prefixing.
|
|
162
176
|
*/
|
|
163
177
|
async callApi(flags, method, path, options) {
|
|
@@ -187,7 +201,7 @@ export class BaseCommand extends Command {
|
|
|
187
201
|
if (this.isQuiet)
|
|
188
202
|
return;
|
|
189
203
|
if (!this.isJson) {
|
|
190
|
-
process.stderr.write(`Dry run
|
|
204
|
+
process.stderr.write(`Dry run: ${label}:\n`);
|
|
191
205
|
}
|
|
192
206
|
this.output(payload);
|
|
193
207
|
}
|
|
@@ -196,7 +210,7 @@ export class BaseCommand extends Command {
|
|
|
196
210
|
*
|
|
197
211
|
* `suggestion` is overridable because the default names `--data` and
|
|
198
212
|
* `--input`, which only the `api` command has. `verify` was handing users
|
|
199
|
-
* recovery advice for flags it does not accept
|
|
213
|
+
* recovery advice for flags it does not accept.
|
|
200
214
|
*/
|
|
201
215
|
parseJsonInput(source, fieldName, suggestion) {
|
|
202
216
|
try {
|
|
@@ -224,7 +238,7 @@ export class BaseCommand extends Command {
|
|
|
224
238
|
catch (err) {
|
|
225
239
|
this.failWith(ErrorCode.FILE_READ_ERROR, `Cannot read ${fieldName} at ${path === '-' ? 'stdin' : path}: ${err instanceof Error ? err.message : String(err)}`, ExitCode.USAGE_ERROR,
|
|
226
240
|
// Same reason the parse suggestion is overridable: the default names
|
|
227
|
-
// --input, which only the `api` command has
|
|
241
|
+
// --input, which only the `api` command has.
|
|
228
242
|
suggestion ?? 'Check that the path exists and is readable, or pipe JSON to stdin with --input -.');
|
|
229
243
|
throw new Error('unreachable');
|
|
230
244
|
}
|
|
@@ -260,8 +274,7 @@ export class BaseCommand extends Command {
|
|
|
260
274
|
if (err instanceof TypeError && String(err.message).includes('fetch')) {
|
|
261
275
|
// "fetch failed" is undici's generic message: DNS failure, connection
|
|
262
276
|
// refused and TLS problems all print identically. Name the host that was
|
|
263
|
-
// tried and the underlying cause, or the user has nothing to debug from
|
|
264
|
-
// (agents#105).
|
|
277
|
+
// tried and the underlying cause, or the user has nothing to debug from.
|
|
265
278
|
const cause = err.cause;
|
|
266
279
|
const causeCode = typeof cause?.code === 'string' ? cause.code : undefined;
|
|
267
280
|
const causeMessage = typeof cause?.message === 'string' ? cause.message : undefined;
|
|
@@ -291,4 +304,3 @@ export class BaseCommand extends Command {
|
|
|
291
304
|
return ExitCode.GENERAL_ERROR;
|
|
292
305
|
}
|
|
293
306
|
}
|
|
294
|
-
//# sourceMappingURL=base.js.map
|
package/dist/commands/api.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { BaseCommand } from '../base.js';
|
|
|
3
3
|
* Universal pass-through to the AGLedger API.
|
|
4
4
|
*
|
|
5
5
|
* Design principle: the CLI is a thin cover over the API. This command supports
|
|
6
|
-
* every route the API exposes with zero drift
|
|
6
|
+
* every route the API exposes with zero drift, and no hand-coded flag-to-body mapping.
|
|
7
7
|
*
|
|
8
8
|
* Params go to query string for GET/DELETE, to JSON body for POST/PUT/PATCH.
|
|
9
|
-
* Body sources compose in order: --data (raw JSON) → --input @file / stdin → -F fields.
|
|
9
|
+
* Body sources compose in order: --data (raw JSON) → --input @file / stdin → -F/-f fields.
|
|
10
10
|
* If multiple body sources are given, later sources take precedence for overlapping keys.
|
|
11
11
|
*/
|
|
12
12
|
export default class Api extends BaseCommand {
|
|
@@ -25,14 +25,16 @@ export default class Api extends BaseCommand {
|
|
|
25
25
|
data: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
26
26
|
input: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
27
27
|
field: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
28
|
+
'raw-field': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
28
29
|
query: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
29
30
|
paginate: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
31
|
+
'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
32
|
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
31
33
|
};
|
|
32
34
|
run(): Promise<void>;
|
|
33
35
|
/**
|
|
34
|
-
* Merge --data, --input, -F, and --query into a single params object.
|
|
35
|
-
* Precedence (low → high): --data → --input → -F fields → --query.
|
|
36
|
+
* Merge --data, --input, -F/-f, and --query into a single params object.
|
|
37
|
+
* Precedence (low → high): --data → --input → -F/-f fields → --query.
|
|
36
38
|
* Returns undefined if no source provided.
|
|
37
39
|
*/
|
|
38
40
|
private composeParams;
|
|
@@ -40,4 +42,3 @@ export default class Api extends BaseCommand {
|
|
|
40
42
|
private mergeIfObject;
|
|
41
43
|
private runPaginated;
|
|
42
44
|
}
|
|
43
|
-
//# sourceMappingURL=api.d.ts.map
|
package/dist/commands/api.js
CHANGED
|
@@ -6,10 +6,10 @@ const ALLOWED_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
|
|
|
6
6
|
* Universal pass-through to the AGLedger API.
|
|
7
7
|
*
|
|
8
8
|
* Design principle: the CLI is a thin cover over the API. This command supports
|
|
9
|
-
* every route the API exposes with zero drift
|
|
9
|
+
* every route the API exposes with zero drift, and no hand-coded flag-to-body mapping.
|
|
10
10
|
*
|
|
11
11
|
* Params go to query string for GET/DELETE, to JSON body for POST/PUT/PATCH.
|
|
12
|
-
* Body sources compose in order: --data (raw JSON) → --input @file / stdin → -F fields.
|
|
12
|
+
* Body sources compose in order: --data (raw JSON) → --input @file / stdin → -F/-f fields.
|
|
13
13
|
* If multiple body sources are given, later sources take precedence for overlapping keys.
|
|
14
14
|
*/
|
|
15
15
|
export default class Api extends BaseCommand {
|
|
@@ -19,6 +19,7 @@ export default class Api extends BaseCommand {
|
|
|
19
19
|
'agledger api GET /v1/records -F status=ACTIVE -F limit=50',
|
|
20
20
|
'agledger api POST /v1/records --data \'{"type":"notarize-generic-v1","criteria":{"summary":"..."}}\'',
|
|
21
21
|
'agledger api POST /v1/records -F type=notarize-generic-v1 -F criteria.summary="summarize Q3 filings"',
|
|
22
|
+
'agledger api POST /v1/records -F type=notarize-generic-v1 -f externalTaskId=4821 # -f keeps a digit-only id a string',
|
|
22
23
|
'agledger api POST /v1/records --input payload.json',
|
|
23
24
|
'cat payload.json | agledger api POST /v1/records --input -',
|
|
24
25
|
'agledger api GET /v1/records --paginate # streams all pages as NDJSON',
|
|
@@ -44,7 +45,12 @@ export default class Api extends BaseCommand {
|
|
|
44
45
|
field: Flags.string({
|
|
45
46
|
char: 'F',
|
|
46
47
|
multiple: true,
|
|
47
|
-
description: 'Set a field as key=value
|
|
48
|
+
description: 'Set a typed field as key=value: true/false/null, numbers, or JSON for {...}/[...]. Anything else is a string. Use -f for a value that must stay a string, such as an all-digit identifier. Supports nested (a.b.c=v) and array append (arr[]=v). Repeatable.',
|
|
49
|
+
}),
|
|
50
|
+
'raw-field': Flags.string({
|
|
51
|
+
char: 'f',
|
|
52
|
+
multiple: true,
|
|
53
|
+
description: 'Set a field as key=value, taking the value verbatim as a string. Use this for identifiers that look numeric (externalTaskId, correlationId, platformRef): the Server does not coerce a JSON body, so -F id=4821 sends a number and is refused. Same path syntax as -F. Repeatable.',
|
|
48
54
|
}),
|
|
49
55
|
query: Flags.string({
|
|
50
56
|
description: 'Extra query parameters as JSON. Merges over -F fields and --data for GET/DELETE routing.',
|
|
@@ -53,6 +59,9 @@ export default class Api extends BaseCommand {
|
|
|
53
59
|
description: 'Follow cursor pagination, stream all results as NDJSON. Requires GET on a paginated route.',
|
|
54
60
|
default: false,
|
|
55
61
|
}),
|
|
62
|
+
'idempotency-key': Flags.string({
|
|
63
|
+
description: 'Dedup key for POST, max 256 chars. One is generated per call, so pass this only when retrying a call that may already have reached the Server: reuse the first attempt\'s key and it replays the original result instead of creating a second record. Bound to method, route and body, so a retry with a changed body is rejected.',
|
|
64
|
+
}),
|
|
56
65
|
'dry-run': Flags.boolean({
|
|
57
66
|
description: 'Show the request that would be sent without calling the API.',
|
|
58
67
|
default: false,
|
|
@@ -83,6 +92,9 @@ export default class Api extends BaseCommand {
|
|
|
83
92
|
return;
|
|
84
93
|
}
|
|
85
94
|
const options = {};
|
|
95
|
+
if (flags['idempotency-key'] !== undefined) {
|
|
96
|
+
options.idempotencyKey = flags['idempotency-key'];
|
|
97
|
+
}
|
|
86
98
|
if (params !== undefined) {
|
|
87
99
|
if (method === 'GET' || method === 'DELETE') {
|
|
88
100
|
options.query = params;
|
|
@@ -92,7 +104,17 @@ export default class Api extends BaseCommand {
|
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
106
|
if (flags['dry-run']) {
|
|
95
|
-
this.dryRunOutput({
|
|
107
|
+
this.dryRunOutput({
|
|
108
|
+
method,
|
|
109
|
+
path: args.path,
|
|
110
|
+
...options,
|
|
111
|
+
// A generated key is minted inside the client at send time, so
|
|
112
|
+
// printing a concrete UUID here would name one that never ships.
|
|
113
|
+
...(method === 'POST' && options.idempotencyKey === undefined
|
|
114
|
+
? { idempotencyKey: '<generated at send time>' }
|
|
115
|
+
: {}),
|
|
116
|
+
auth: this.resolvedAuth(flags),
|
|
117
|
+
}, `would call ${method} ${args.path}`);
|
|
96
118
|
return;
|
|
97
119
|
}
|
|
98
120
|
const response = await this.callApi(flags, method, args.path, options);
|
|
@@ -103,14 +125,14 @@ export default class Api extends BaseCommand {
|
|
|
103
125
|
}
|
|
104
126
|
catch (err) {
|
|
105
127
|
if (err instanceof FieldParseError) {
|
|
106
|
-
this.failWith(ErrorCode.INVALID_FIELD, `Invalid
|
|
128
|
+
this.failWith(ErrorCode.INVALID_FIELD, `Invalid field value '${err.field}': ${err.message}`, ExitCode.USAGE_ERROR, 'Use key=value. -F types the value (number, true/false/null, JSON objects/arrays); -f takes it verbatim as a string. Nested via a.b=v, arrays via arr[]=v.');
|
|
107
129
|
}
|
|
108
130
|
this.handleError(err);
|
|
109
131
|
}
|
|
110
132
|
}
|
|
111
133
|
/**
|
|
112
|
-
* Merge --data, --input, -F, and --query into a single params object.
|
|
113
|
-
* Precedence (low → high): --data → --input → -F fields → --query.
|
|
134
|
+
* Merge --data, --input, -F/-f, and --query into a single params object.
|
|
135
|
+
* Precedence (low → high): --data → --input → -F/-f fields → --query.
|
|
114
136
|
* Returns undefined if no source provided.
|
|
115
137
|
*/
|
|
116
138
|
composeParams(flags) {
|
|
@@ -122,9 +144,16 @@ export default class Api extends BaseCommand {
|
|
|
122
144
|
const fromFile = this.readJsonSource(flags.input, '--input');
|
|
123
145
|
body = this.mergeIfObject(body, fromFile);
|
|
124
146
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
147
|
+
// -F and -f parse together so their paths build one tree rather than two
|
|
148
|
+
// objects whose shallow merge would drop a shared branch. On a collision of
|
|
149
|
+
// the same exact path, -f wins: asking for the value verbatim is the more
|
|
150
|
+
// specific request.
|
|
151
|
+
const fieldInputs = [
|
|
152
|
+
...(flags.field ?? []).map((value) => ({ value, coerce: true })),
|
|
153
|
+
...(flags['raw-field'] ?? []).map((value) => ({ value, coerce: false })),
|
|
154
|
+
];
|
|
155
|
+
if (fieldInputs.length > 0) {
|
|
156
|
+
body = this.mergeIfObject(body, parseFields(fieldInputs));
|
|
128
157
|
}
|
|
129
158
|
if (flags.query !== undefined) {
|
|
130
159
|
const fromQuery = this.parseJsonInput(flags.query, '--query');
|
|
@@ -177,4 +206,3 @@ export default class Api extends BaseCommand {
|
|
|
177
206
|
} while (cursor);
|
|
178
207
|
}
|
|
179
208
|
}
|
|
180
|
-
//# sourceMappingURL=api.js.map
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseCommand } from '../base.js';
|
|
2
2
|
/**
|
|
3
|
-
* Quick "am I logged in?" check. Local-first
|
|
3
|
+
* Quick "am I logged in?" check. Local-first: returns `authenticated: false`
|
|
4
4
|
* with exit 0 when no key is configured (useful for scripts gating on login state).
|
|
5
5
|
* When a key is configured, verifies it against the API via GET /v1/auth/me.
|
|
6
6
|
*/
|
|
@@ -15,4 +15,3 @@ export default class Auth extends BaseCommand {
|
|
|
15
15
|
};
|
|
16
16
|
run(): Promise<void>;
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=auth.d.ts.map
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseCommand } from '../base.js';
|
|
2
2
|
/**
|
|
3
|
-
* Quick "am I logged in?" check. Local-first
|
|
3
|
+
* Quick "am I logged in?" check. Local-first: returns `authenticated: false`
|
|
4
4
|
* with exit 0 when no key is configured (useful for scripts gating on login state).
|
|
5
5
|
* When a key is configured, verifies it against the API via GET /v1/auth/me.
|
|
6
6
|
*/
|
|
@@ -12,7 +12,7 @@ export default class Auth extends BaseCommand {
|
|
|
12
12
|
// Resolve the key the same way an actual call does: --api-key flag > env >
|
|
13
13
|
// stored profile in ~/.agledger/config.json. The previous check looked only
|
|
14
14
|
// at the flag/env, so `agledger auth` reported not-authenticated right after
|
|
15
|
-
// a successful `login` wrote the key to a profile
|
|
15
|
+
// a successful `login` wrote the key to a profile.
|
|
16
16
|
const auth = this.resolvedAuth(flags);
|
|
17
17
|
if (auth.source === 'none') {
|
|
18
18
|
this.output({ authenticated: false, message: 'No API key configured. Run `agledger login --api-key <key>`.' });
|
|
@@ -35,4 +35,3 @@ export default class Auth extends BaseCommand {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -2,7 +2,7 @@ import { BaseCommand } from '../base.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Inspect and switch between stored profiles in ~/.agledger/config.json.
|
|
4
4
|
*
|
|
5
|
-
* Does NOT accept setting an API key directly
|
|
5
|
+
* Does NOT accept setting an API key directly; use `agledger login --api-key X
|
|
6
6
|
* --profile name` for that (login also verifies the key against the API first).
|
|
7
7
|
*/
|
|
8
8
|
export default class Config extends BaseCommand {
|
|
@@ -21,4 +21,3 @@ export default class Config extends BaseCommand {
|
|
|
21
21
|
};
|
|
22
22
|
run(): Promise<void>;
|
|
23
23
|
}
|
|
24
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/commands/config.js
CHANGED
|
@@ -4,7 +4,7 @@ import { configPath, readConfig, writeConfig } from '../util/config.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Inspect and switch between stored profiles in ~/.agledger/config.json.
|
|
6
6
|
*
|
|
7
|
-
* Does NOT accept setting an API key directly
|
|
7
|
+
* Does NOT accept setting an API key directly; use `agledger login --api-key X
|
|
8
8
|
* --profile name` for that (login also verifies the key against the API first).
|
|
9
9
|
*/
|
|
10
10
|
export default class Config extends BaseCommand {
|
|
@@ -72,4 +72,3 @@ export default class Config extends BaseCommand {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
//# sourceMappingURL=config.js.map
|