@agledger/cli 1.3.1 → 1.4.1
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/LICENSE +3 -2
- package/README.md +25 -3
- package/SKILL.md +2 -1
- package/dist/api-client.d.ts +3 -2
- package/dist/api-client.js +46 -4
- package/dist/base.d.ts +9 -8
- package/dist/base.js +15 -16
- package/dist/commands/api.d.ts +6 -4
- package/dist/commands/api.js +39 -10
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/auth.js +2 -2
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +1 -1
- package/dist/commands/discover.d.ts +2 -2
- package/dist/commands/discover.js +3 -3
- package/dist/commands/docs.d.ts +1 -1
- package/dist/commands/docs.js +2 -2
- package/dist/commands/list-commands.d.ts +1 -1
- package/dist/commands/list-commands.js +1 -1
- package/dist/commands/verify.d.ts +3 -3
- package/dist/commands/verify.js +4 -4
- package/dist/hooks/command-not-found.js +1 -1
- package/dist/util/field-parser.d.ts +35 -10
- package/dist/util/field-parser.js +35 -14
- package/oclif.manifest.json +18 -2
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -84,8 +84,9 @@ cause of action accrues, to the maximum extent permitted by applicable law.
|
|
|
84
84
|
|
|
85
85
|
6. EXPORT COMPLIANCE
|
|
86
86
|
|
|
87
|
-
The Software may include cryptographic functionality
|
|
88
|
-
256-
|
|
87
|
+
The Software may include cryptographic functionality, including Ed25519
|
|
88
|
+
(EdDSA), ECDSA using curve P-256 with SHA-256, HMAC-SHA-256, AES-256-GCM,
|
|
89
|
+
HKDF-SHA-256, and SHA-256. AGLedger LLC classifies the Software under
|
|
89
90
|
ECCN 5D002 in good faith. To the extent AGLedger LLC makes the source code of
|
|
90
91
|
the Software publicly available through a public repository, that source code
|
|
91
92
|
is subject to the treatment afforded under 15 CFR § 742.15(b) of the U.S.
|
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)
|
package/SKILL.md
CHANGED
|
@@ -11,7 +11,7 @@ Credentials resolve per command with this precedence: `--api-key` flag > `AGLEDG
|
|
|
11
11
|
Call any API endpoint:
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
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 ...]
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Workflow (start here)
|
|
@@ -27,6 +27,7 @@ agledger api <METHOD> <PATH> [--data JSON | --input FILE | -F key=value ...]
|
|
|
27
27
|
- `--input file.json`: read JSON from file
|
|
28
28
|
- `--input -`: read JSON from stdin
|
|
29
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.
|
|
30
31
|
|
|
31
32
|
## Discovery commands
|
|
32
33
|
- `agledger list-commands --json`: full CLI inventory (10 commands)
|
package/dist/api-client.d.ts
CHANGED
|
@@ -7,16 +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
|
}
|
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 {
|
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,9 +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
|
|
66
|
+
* API key: `--api-key` flag > `AGLEDGER_API_KEY` env > stored profile.
|
|
67
67
|
* API URL: `--api-url` flag > `AGLEDGER_API_URL` env > stored profile url.
|
|
68
|
-
* There is no default; AGLedger is self-hosted
|
|
68
|
+
* There is no default; AGLedger is self-hosted.
|
|
69
69
|
*
|
|
70
70
|
* oclif merges the flag and its `env` source into `flags['api-key']` /
|
|
71
71
|
* `flags['api-url']`, so a present value there already represents flag-or-env
|
|
@@ -97,7 +97,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
97
97
|
profile?: string;
|
|
98
98
|
};
|
|
99
99
|
/**
|
|
100
|
-
* Call the API. Path is passed through as-is
|
|
100
|
+
* Call the API. Path is passed through as-is; caller provides the full path
|
|
101
101
|
* (e.g. `/v1/records`, `/health`, `/federation/v1/peer`). No auto-prefixing.
|
|
102
102
|
*/
|
|
103
103
|
protected callApi(flags: {
|
|
@@ -107,6 +107,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
107
107
|
}, method: string, path: string, options?: {
|
|
108
108
|
query?: Record<string, unknown>;
|
|
109
109
|
body?: unknown;
|
|
110
|
+
idempotencyKey?: string;
|
|
110
111
|
}): Promise<ApiResponse>;
|
|
111
112
|
protected output(data: unknown): void;
|
|
112
113
|
protected outputNdjson(item: unknown): void;
|
|
@@ -120,7 +121,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
120
121
|
*
|
|
121
122
|
* `suggestion` is overridable because the default names `--data` and
|
|
122
123
|
* `--input`, which only the `api` command has. `verify` was handing users
|
|
123
|
-
* recovery advice for flags it does not accept
|
|
124
|
+
* recovery advice for flags it does not accept.
|
|
124
125
|
*/
|
|
125
126
|
protected parseJsonInput(source: string, fieldName: string, suggestion?: string): unknown;
|
|
126
127
|
/** Read and parse a JSON file with structured errors. `-` reads from stdin. */
|
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,9 +94,9 @@ export class BaseCommand extends Command {
|
|
|
94
94
|
* Resolve credentials and build the API client.
|
|
95
95
|
*
|
|
96
96
|
* Precedence:
|
|
97
|
-
* API key
|
|
97
|
+
* API key: `--api-key` flag > `AGLEDGER_API_KEY` env > stored profile.
|
|
98
98
|
* API URL: `--api-url` flag > `AGLEDGER_API_URL` env > stored profile url.
|
|
99
|
-
* There is no default; AGLedger is self-hosted
|
|
99
|
+
* There is no default; AGLedger is self-hosted.
|
|
100
100
|
*
|
|
101
101
|
* oclif merges the flag and its `env` source into `flags['api-key']` /
|
|
102
102
|
* `flags['api-url']`, so a present value there already represents flag-or-env
|
|
@@ -120,13 +120,13 @@ export class BaseCommand extends Command {
|
|
|
120
120
|
const apiKey = flagKey ?? profile?.apiKey ?? null;
|
|
121
121
|
// Discovery surfaces answer without auth, so a keyless invocation proceeds
|
|
122
122
|
// anonymously rather than being refused before any request is made. The
|
|
123
|
-
// Server, not the CLI, decides what needs a key
|
|
123
|
+
// Server, not the CLI, decides what needs a key.
|
|
124
124
|
if (!apiKey && !options?.allowAnonymous) {
|
|
125
125
|
this.failWith(ErrorCode.AUTH_REQUIRED, 'No API key. Set AGLEDGER_API_KEY, use --api-key, or run `agledger login`.', ExitCode.AUTH_ERROR);
|
|
126
126
|
}
|
|
127
127
|
// No placeholder: a default of agledger.example.com resolved nowhere and
|
|
128
|
-
// turned a missing config into a DNS failure the user could not read
|
|
129
|
-
//
|
|
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.
|
|
130
130
|
const apiUrl = flagUrl ?? profile?.apiUrl;
|
|
131
131
|
if (!apiUrl) {
|
|
132
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>`.');
|
|
@@ -148,7 +148,7 @@ export class BaseCommand extends Command {
|
|
|
148
148
|
const flagUrl = flags['api-url'] || undefined;
|
|
149
149
|
const apiKey = flagKey ?? profile?.apiKey ?? null;
|
|
150
150
|
const source = flagKey ? 'flag-or-env' : profile?.apiKey ? 'profile' : 'none';
|
|
151
|
-
// Null, not a placeholder.
|
|
151
|
+
// Null, not a placeholder. `agledger.example.com` was removed from
|
|
152
152
|
// `createApiClient`, which now refuses to build a client without a URL, but
|
|
153
153
|
// this sibling kept it. The whole job of --dry-run is to report what the
|
|
154
154
|
// real call would do, and it was reporting a host the real call refuses to
|
|
@@ -171,7 +171,7 @@ export class BaseCommand extends Command {
|
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
|
-
* Call the API. Path is passed through as-is
|
|
174
|
+
* Call the API. Path is passed through as-is; caller provides the full path
|
|
175
175
|
* (e.g. `/v1/records`, `/health`, `/federation/v1/peer`). No auto-prefixing.
|
|
176
176
|
*/
|
|
177
177
|
async callApi(flags, method, path, options) {
|
|
@@ -210,7 +210,7 @@ export class BaseCommand extends Command {
|
|
|
210
210
|
*
|
|
211
211
|
* `suggestion` is overridable because the default names `--data` and
|
|
212
212
|
* `--input`, which only the `api` command has. `verify` was handing users
|
|
213
|
-
* recovery advice for flags it does not accept
|
|
213
|
+
* recovery advice for flags it does not accept.
|
|
214
214
|
*/
|
|
215
215
|
parseJsonInput(source, fieldName, suggestion) {
|
|
216
216
|
try {
|
|
@@ -238,7 +238,7 @@ export class BaseCommand extends Command {
|
|
|
238
238
|
catch (err) {
|
|
239
239
|
this.failWith(ErrorCode.FILE_READ_ERROR, `Cannot read ${fieldName} at ${path === '-' ? 'stdin' : path}: ${err instanceof Error ? err.message : String(err)}`, ExitCode.USAGE_ERROR,
|
|
240
240
|
// Same reason the parse suggestion is overridable: the default names
|
|
241
|
-
// --input, which only the `api` command has
|
|
241
|
+
// --input, which only the `api` command has.
|
|
242
242
|
suggestion ?? 'Check that the path exists and is readable, or pipe JSON to stdin with --input -.');
|
|
243
243
|
throw new Error('unreachable');
|
|
244
244
|
}
|
|
@@ -274,8 +274,7 @@ export class BaseCommand extends Command {
|
|
|
274
274
|
if (err instanceof TypeError && String(err.message).includes('fetch')) {
|
|
275
275
|
// "fetch failed" is undici's generic message: DNS failure, connection
|
|
276
276
|
// refused and TLS problems all print identically. Name the host that was
|
|
277
|
-
// tried and the underlying cause, or the user has nothing to debug from
|
|
278
|
-
// (agents#105).
|
|
277
|
+
// tried and the underlying cause, or the user has nothing to debug from.
|
|
279
278
|
const cause = err.cause;
|
|
280
279
|
const causeCode = typeof cause?.code === 'string' ? cause.code : undefined;
|
|
281
280
|
const causeMessage = typeof cause?.message === 'string' ? cause.message : undefined;
|
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;
|
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');
|
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
|
*/
|
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>`.' });
|
|
@@ -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 {
|
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 {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseCommand } from '../base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Cold-start discovery for agents and humans. Mirrors the MCP server's
|
|
4
|
-
* `agledger_discover` tool
|
|
4
|
+
* `agledger_discover` tool: same shape, same quickstart.
|
|
5
5
|
*
|
|
6
6
|
* Returns health, identity, scopes, a 4-step quickstart workflow, and a pointer
|
|
7
7
|
* to live API discovery (OpenAPI). Failures on either call don't
|
|
8
|
-
* abort
|
|
8
|
+
* abort; partial results are returned so agents can reason about what's reachable.
|
|
9
9
|
*/
|
|
10
10
|
export default class Discover extends BaseCommand {
|
|
11
11
|
static description: string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseCommand } from '../base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Cold-start discovery for agents and humans. Mirrors the MCP server's
|
|
4
|
-
* `agledger_discover` tool
|
|
4
|
+
* `agledger_discover` tool: same shape, same quickstart.
|
|
5
5
|
*
|
|
6
6
|
* Returns health, identity, scopes, a 4-step quickstart workflow, and a pointer
|
|
7
7
|
* to live API discovery (OpenAPI). Failures on either call don't
|
|
8
|
-
* abort
|
|
8
|
+
* abort; partial results are returned so agents can reason about what's reachable.
|
|
9
9
|
*/
|
|
10
10
|
export default class Discover extends BaseCommand {
|
|
11
11
|
static description = 'Check API health and current identity, and return the quickstart workflow. Call this first.';
|
|
@@ -13,7 +13,7 @@ export default class Discover extends BaseCommand {
|
|
|
13
13
|
async run() {
|
|
14
14
|
const { flags } = await this.parse(Discover);
|
|
15
15
|
// "Call this first" has to be true without a key: /health answers
|
|
16
|
-
// unauthenticated, and /v1/auth/me simply reports no identity
|
|
16
|
+
// unauthenticated, and /v1/auth/me simply reports no identity.
|
|
17
17
|
const client = this.createApiClient(flags, { allowAnonymous: true });
|
|
18
18
|
const [health, identity] = await Promise.allSettled([
|
|
19
19
|
client.request('GET', '/health'),
|
package/dist/commands/docs.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseCommand } from '../base.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Fetch the API's agent-oriented documentation narrative. The API serves a
|
|
4
4
|
* concise `/llms.txt` and an expanded `/llms-full.txt` (the llms.txt
|
|
5
|
-
* convention)
|
|
5
|
+
* convention); `discover` only points at `openapi.json`, so this closes the
|
|
6
6
|
* loop for an agent that wants the prose narrative without reaching for curl.
|
|
7
7
|
*/
|
|
8
8
|
export default class Docs extends BaseCommand {
|
package/dist/commands/docs.js
CHANGED
|
@@ -3,7 +3,7 @@ import { BaseCommand } from '../base.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Fetch the API's agent-oriented documentation narrative. The API serves a
|
|
5
5
|
* concise `/llms.txt` and an expanded `/llms-full.txt` (the llms.txt
|
|
6
|
-
* convention)
|
|
6
|
+
* convention); `discover` only points at `openapi.json`, so this closes the
|
|
7
7
|
* loop for an agent that wants the prose narrative without reaching for curl.
|
|
8
8
|
*/
|
|
9
9
|
export default class Docs extends BaseCommand {
|
|
@@ -23,7 +23,7 @@ export default class Docs extends BaseCommand {
|
|
|
23
23
|
async run() {
|
|
24
24
|
const { flags } = await this.parse(Docs);
|
|
25
25
|
// llms.txt is served unauthenticated: an agent holding only a URL must be
|
|
26
|
-
// able to read the narrative before it has a key
|
|
26
|
+
// able to read the narrative before it has a key.
|
|
27
27
|
const client = this.createApiClient(flags, { allowAnonymous: true });
|
|
28
28
|
const path = flags.full ? '/llms-full.txt' : '/llms.txt';
|
|
29
29
|
const res = await client.request('GET', path);
|
|
@@ -2,7 +2,7 @@ import { BaseCommand } from '../base.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Low-token command inventory for agent discovery.
|
|
4
4
|
*
|
|
5
|
-
* The CLI is a thin cover over the API
|
|
5
|
+
* The CLI is a thin cover over the API; the bulk of functionality lives under
|
|
6
6
|
* `agledger api <METHOD> <path>`. This list shows CLI-local commands only;
|
|
7
7
|
* for API operations, agents should call `agledger discover` or
|
|
8
8
|
* `agledger api GET /openapi.json`.
|
|
@@ -2,7 +2,7 @@ import { BaseCommand } from '../base.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Low-token command inventory for agent discovery.
|
|
4
4
|
*
|
|
5
|
-
* The CLI is a thin cover over the API
|
|
5
|
+
* The CLI is a thin cover over the API; the bulk of functionality lives under
|
|
6
6
|
* `agledger api <METHOD> <path>`. This list shows CLI-local commands only;
|
|
7
7
|
* for API operations, agents should call `agledger discover` or
|
|
8
8
|
* `agledger api GET /openapi.json`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseCommand } from '../base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Offline verification of a record audit export (format 2.0, COSE_Sign1).
|
|
4
|
-
* Runs entirely offline
|
|
4
|
+
* Runs entirely offline: no network calls, no API key required. The
|
|
5
5
|
* verification core is `@agledger/verify-core` (one dep, no network), shared
|
|
6
6
|
* with the SDK, MCP server, and `@agledger/verify`; parity with the independent
|
|
7
7
|
* Python port is enforced via the shared conformance corpus.
|
|
@@ -23,8 +23,8 @@ export default class Verify extends BaseCommand {
|
|
|
23
23
|
/**
|
|
24
24
|
* Accept the raw `GET /v1/verification-keys` response shape. That endpoint
|
|
25
25
|
* returns an envelope `{ data: [{ keyId, publicKey, ... }], canonicalization, ... }`,
|
|
26
|
-
* not the bare array its consumers expect
|
|
27
|
-
* straight from the endpoint verifies without hand-editing
|
|
26
|
+
* not the bare array its consumers expect, so unwrap `.data` so a file saved
|
|
27
|
+
* straight from the endpoint verifies without hand-editing. A bare
|
|
28
28
|
* `[{keyId, publicKey}]` list or a `{keyId: base64}` map passes through
|
|
29
29
|
* untouched; verify-core then validates the shape and throws on anything else.
|
|
30
30
|
*/
|
package/dist/commands/verify.js
CHANGED
|
@@ -3,7 +3,7 @@ import { verifyAuditExport, } from '@agledger/verify-core';
|
|
|
3
3
|
import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
|
|
4
4
|
/**
|
|
5
5
|
* Offline verification of a record audit export (format 2.0, COSE_Sign1).
|
|
6
|
-
* Runs entirely offline
|
|
6
|
+
* Runs entirely offline: no network calls, no API key required. The
|
|
7
7
|
* verification core is `@agledger/verify-core` (one dep, no network), shared
|
|
8
8
|
* with the SDK, MCP server, and `@agledger/verify`; parity with the independent
|
|
9
9
|
* Python port is enforced via the shared conformance corpus.
|
|
@@ -56,7 +56,7 @@ export default class Verify extends BaseCommand {
|
|
|
56
56
|
// verify-core throws TypeError at the OOB-key boundary when the file's
|
|
57
57
|
// shape is wrong (e.g. {keyId: 42}, [null], "..."). Catch it so the CLI
|
|
58
58
|
// emits its structured-error envelope rather than oclif's raw exception
|
|
59
|
-
// trace
|
|
59
|
+
// trace; agents parsing stderr need {code, message, suggestion}, not a
|
|
60
60
|
// stack frame. See verify-core/audit-export.ts normalizeOutOfBandKeys.
|
|
61
61
|
let result;
|
|
62
62
|
try {
|
|
@@ -85,8 +85,8 @@ export default class Verify extends BaseCommand {
|
|
|
85
85
|
/**
|
|
86
86
|
* Accept the raw `GET /v1/verification-keys` response shape. That endpoint
|
|
87
87
|
* returns an envelope `{ data: [{ keyId, publicKey, ... }], canonicalization, ... }`,
|
|
88
|
-
* not the bare array its consumers expect
|
|
89
|
-
* straight from the endpoint verifies without hand-editing
|
|
88
|
+
* not the bare array its consumers expect, so unwrap `.data` so a file saved
|
|
89
|
+
* straight from the endpoint verifies without hand-editing. A bare
|
|
90
90
|
* `[{keyId, publicKey}]` list or a `{keyId: base64}` map passes through
|
|
91
91
|
* untouched; verify-core then validates the shape and throws on anything else.
|
|
92
92
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Unknown commands printed only "command X not found", with no nearest match
|
|
3
|
-
* and no pointer to how to find the real one
|
|
3
|
+
* and no pointer to how to find the real one. An agent that
|
|
4
4
|
* guessed a verb had nothing to recover from, which matters here because the
|
|
5
5
|
* CLI deliberately has few commands: almost everything goes through
|
|
6
6
|
* `agledger api`, and a wrong guess is the expected first move.
|
|
@@ -1,27 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Parses `-F/--field` flag values into a nested object.
|
|
2
|
+
* Parses `-F/--field` and `-f/--raw-field` flag values into a nested object.
|
|
3
3
|
*
|
|
4
|
-
* Conventions (modeled on `gh api
|
|
4
|
+
* Conventions (modeled on `gh api`, which has the same two flags):
|
|
5
5
|
* - `key=value` → { key: "value" }
|
|
6
|
-
* - `key=true|false|null` → typed literal
|
|
7
|
-
* - `key=42` / `key=3.14` → number
|
|
8
|
-
* - `key=[...]` / `key={...}` → JSON-parsed array/object
|
|
6
|
+
* - `key=true|false|null` → typed literal (`-F` only)
|
|
7
|
+
* - `key=42` / `key=3.14` → number (`-F` only)
|
|
8
|
+
* - `key=[...]` / `key={...}` → JSON-parsed array/object (`-F` only)
|
|
9
9
|
* - `a.b.c=value` → nested: { a: { b: { c: "value" } } }
|
|
10
10
|
* - `arr[]=a arr[]=b` → { arr: ["a", "b"] }
|
|
11
11
|
* - `items[].name=x` → { items: [{ name: "x" }] } (appends new element)
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* A raw field takes its value as a string, always. Path syntax is identical;
|
|
14
|
+
* only the value side differs.
|
|
15
|
+
*
|
|
16
|
+
* Why both: the Server stopped coercing JSON bodies, so a field declared
|
|
17
|
+
* `string` refuses a number. `publisher`, `platformRef`, `projectRef`,
|
|
18
|
+
* `externalTaskId` and `correlationId` are plain strings carrying identifiers
|
|
19
|
+
* minted by other systems, which are frequently all digits, and `-F id=4821`
|
|
20
|
+
* types that as a number and is refused. There was no `-F` form that produced
|
|
21
|
+
* the four characters: quoting reached the Server as a string with the quote
|
|
22
|
+
* marks inside it, which the Server accepts, so the nearest workaround
|
|
23
|
+
* notarized a corrupted identifier into a signed, immutable Record. `-f`
|
|
24
|
+
* is the correct one-character answer.
|
|
25
|
+
*
|
|
26
|
+
* Why dot is nesting, not a literal: the AGLedger API uses camelCase / snake_case
|
|
27
|
+
* throughout and has zero property keys containing '.', verified by scanning openapi.json.
|
|
15
28
|
* If the API ever introduces one, we'll need to add an escape syntax (e.g. `a\.b=v`).
|
|
16
29
|
*
|
|
17
|
-
* If no `=` is present, throws
|
|
30
|
+
* If no `=` is present, throws; callers decide how to surface the error.
|
|
18
31
|
*/
|
|
19
32
|
export declare class FieldParseError extends Error {
|
|
20
33
|
readonly field: string;
|
|
21
34
|
constructor(field: string, message: string);
|
|
22
35
|
}
|
|
36
|
+
/** One `key=value` entry, and whether its value side gets typed. */
|
|
37
|
+
export interface FieldInput {
|
|
38
|
+
value: string;
|
|
39
|
+
/** `-F` typed, `-f` verbatim string. */
|
|
40
|
+
coerce: boolean;
|
|
41
|
+
}
|
|
23
42
|
/**
|
|
24
|
-
* Parse
|
|
43
|
+
* Parse `-F` and `-f` flag values into a single nested object.
|
|
25
44
|
* Repeated paths merge; later values override earlier ones (except for `[]` which appends).
|
|
45
|
+
*
|
|
46
|
+
* Both flags parse in one call so their paths build one tree: `-F a.b=1 -f a.c=2`
|
|
47
|
+
* has to land as `{a: {b: 1, c: "2"}}`, and parsing them separately would produce
|
|
48
|
+
* two objects whose shallow merge drops one of the two `a` branches.
|
|
49
|
+
*
|
|
50
|
+
* A bare string means `-F`, so existing callers keep the typed behaviour.
|
|
26
51
|
*/
|
|
27
|
-
export declare function parseFields(fields: string
|
|
52
|
+
export declare function parseFields(fields: Array<string | FieldInput>): Record<string, unknown>;
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Parses `-F/--field` flag values into a nested object.
|
|
2
|
+
* Parses `-F/--field` and `-f/--raw-field` flag values into a nested object.
|
|
3
3
|
*
|
|
4
|
-
* Conventions (modeled on `gh api
|
|
4
|
+
* Conventions (modeled on `gh api`, which has the same two flags):
|
|
5
5
|
* - `key=value` → { key: "value" }
|
|
6
|
-
* - `key=true|false|null` → typed literal
|
|
7
|
-
* - `key=42` / `key=3.14` → number
|
|
8
|
-
* - `key=[...]` / `key={...}` → JSON-parsed array/object
|
|
6
|
+
* - `key=true|false|null` → typed literal (`-F` only)
|
|
7
|
+
* - `key=42` / `key=3.14` → number (`-F` only)
|
|
8
|
+
* - `key=[...]` / `key={...}` → JSON-parsed array/object (`-F` only)
|
|
9
9
|
* - `a.b.c=value` → nested: { a: { b: { c: "value" } } }
|
|
10
10
|
* - `arr[]=a arr[]=b` → { arr: ["a", "b"] }
|
|
11
11
|
* - `items[].name=x` → { items: [{ name: "x" }] } (appends new element)
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* A raw field takes its value as a string, always. Path syntax is identical;
|
|
14
|
+
* only the value side differs.
|
|
15
|
+
*
|
|
16
|
+
* Why both: the Server stopped coercing JSON bodies, so a field declared
|
|
17
|
+
* `string` refuses a number. `publisher`, `platformRef`, `projectRef`,
|
|
18
|
+
* `externalTaskId` and `correlationId` are plain strings carrying identifiers
|
|
19
|
+
* minted by other systems, which are frequently all digits, and `-F id=4821`
|
|
20
|
+
* types that as a number and is refused. There was no `-F` form that produced
|
|
21
|
+
* the four characters: quoting reached the Server as a string with the quote
|
|
22
|
+
* marks inside it, which the Server accepts, so the nearest workaround
|
|
23
|
+
* notarized a corrupted identifier into a signed, immutable Record. `-f`
|
|
24
|
+
* is the correct one-character answer.
|
|
25
|
+
*
|
|
26
|
+
* Why dot is nesting, not a literal: the AGLedger API uses camelCase / snake_case
|
|
27
|
+
* throughout and has zero property keys containing '.', verified by scanning openapi.json.
|
|
15
28
|
* If the API ever introduces one, we'll need to add an escape syntax (e.g. `a\.b=v`).
|
|
16
29
|
*
|
|
17
|
-
* If no `=` is present, throws
|
|
30
|
+
* If no `=` is present, throws; callers decide how to surface the error.
|
|
18
31
|
*/
|
|
19
32
|
export class FieldParseError extends Error {
|
|
20
33
|
field;
|
|
@@ -37,13 +50,13 @@ function coerceValue(raw) {
|
|
|
37
50
|
return Number(raw);
|
|
38
51
|
if (/^-?\d*\.\d+$/.test(raw))
|
|
39
52
|
return Number(raw);
|
|
40
|
-
// JSON literals only if clearly bracketed
|
|
53
|
+
// JSON literals only if clearly bracketed, which avoids misinterpreting strings.
|
|
41
54
|
if ((raw.startsWith('{') && raw.endsWith('}')) || (raw.startsWith('[') && raw.endsWith(']'))) {
|
|
42
55
|
try {
|
|
43
56
|
return JSON.parse(raw);
|
|
44
57
|
}
|
|
45
58
|
catch {
|
|
46
|
-
// Fall through
|
|
59
|
+
// Fall through: treat as string if JSON parse fails.
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
62
|
return raw;
|
|
@@ -115,15 +128,23 @@ function assignNested(target, segments, value, originalField) {
|
|
|
115
128
|
}
|
|
116
129
|
}
|
|
117
130
|
/**
|
|
118
|
-
* Parse
|
|
131
|
+
* Parse `-F` and `-f` flag values into a single nested object.
|
|
119
132
|
* Repeated paths merge; later values override earlier ones (except for `[]` which appends).
|
|
133
|
+
*
|
|
134
|
+
* Both flags parse in one call so their paths build one tree: `-F a.b=1 -f a.c=2`
|
|
135
|
+
* has to land as `{a: {b: 1, c: "2"}}`, and parsing them separately would produce
|
|
136
|
+
* two objects whose shallow merge drops one of the two `a` branches.
|
|
137
|
+
*
|
|
138
|
+
* A bare string means `-F`, so existing callers keep the typed behaviour.
|
|
120
139
|
*/
|
|
121
140
|
export function parseFields(fields) {
|
|
122
141
|
const result = {};
|
|
123
|
-
for (const
|
|
142
|
+
for (const entry of fields) {
|
|
143
|
+
const field = typeof entry === 'string' ? entry : entry.value;
|
|
144
|
+
const coerce = typeof entry === 'string' ? true : entry.coerce;
|
|
124
145
|
const eq = field.indexOf('=');
|
|
125
146
|
if (eq === -1) {
|
|
126
|
-
throw new FieldParseError(field, `missing '='
|
|
147
|
+
throw new FieldParseError(field, `missing '=': use key=value, not just '${field}'`);
|
|
127
148
|
}
|
|
128
149
|
const path = field.slice(0, eq);
|
|
129
150
|
const rawValue = field.slice(eq + 1);
|
|
@@ -131,7 +152,7 @@ export function parseFields(fields) {
|
|
|
131
152
|
throw new FieldParseError(field, `field path is empty before '='`);
|
|
132
153
|
}
|
|
133
154
|
const segments = splitPath(path);
|
|
134
|
-
assignNested(result, segments, coerceValue(rawValue), field);
|
|
155
|
+
assignNested(result, segments, coerce ? coerceValue(rawValue) : rawValue, field);
|
|
135
156
|
}
|
|
136
157
|
return result;
|
|
137
158
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"agledger api GET /v1/records -F status=ACTIVE -F limit=50",
|
|
21
21
|
"agledger api POST /v1/records --data '{\"type\":\"notarize-generic-v1\",\"criteria\":{\"summary\":\"...\"}}'",
|
|
22
22
|
"agledger api POST /v1/records -F type=notarize-generic-v1 -F criteria.summary=\"summarize Q3 filings\"",
|
|
23
|
+
"agledger api POST /v1/records -F type=notarize-generic-v1 -f externalTaskId=4821 # -f keeps a digit-only id a string",
|
|
23
24
|
"agledger api POST /v1/records --input payload.json",
|
|
24
25
|
"cat payload.json | agledger api POST /v1/records --input -",
|
|
25
26
|
"agledger api GET /v1/records --paginate # streams all pages as NDJSON"
|
|
@@ -76,12 +77,20 @@
|
|
|
76
77
|
},
|
|
77
78
|
"field": {
|
|
78
79
|
"char": "F",
|
|
79
|
-
"description": "Set a field as key=value
|
|
80
|
+
"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.",
|
|
80
81
|
"name": "field",
|
|
81
82
|
"hasDynamicHelp": false,
|
|
82
83
|
"multiple": true,
|
|
83
84
|
"type": "option"
|
|
84
85
|
},
|
|
86
|
+
"raw-field": {
|
|
87
|
+
"char": "f",
|
|
88
|
+
"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.",
|
|
89
|
+
"name": "raw-field",
|
|
90
|
+
"hasDynamicHelp": false,
|
|
91
|
+
"multiple": true,
|
|
92
|
+
"type": "option"
|
|
93
|
+
},
|
|
85
94
|
"query": {
|
|
86
95
|
"description": "Extra query parameters as JSON. Merges over -F fields and --data for GET/DELETE routing.",
|
|
87
96
|
"name": "query",
|
|
@@ -95,6 +104,13 @@
|
|
|
95
104
|
"allowNo": false,
|
|
96
105
|
"type": "boolean"
|
|
97
106
|
},
|
|
107
|
+
"idempotency-key": {
|
|
108
|
+
"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.",
|
|
109
|
+
"name": "idempotency-key",
|
|
110
|
+
"hasDynamicHelp": false,
|
|
111
|
+
"multiple": false,
|
|
112
|
+
"type": "option"
|
|
113
|
+
},
|
|
98
114
|
"dry-run": {
|
|
99
115
|
"description": "Show the request that would be sent without calling the API.",
|
|
100
116
|
"name": "dry-run",
|
|
@@ -702,5 +718,5 @@
|
|
|
702
718
|
]
|
|
703
719
|
}
|
|
704
720
|
},
|
|
705
|
-
"version": "1.
|
|
721
|
+
"version": "1.4.1"
|
|
706
722
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agledger/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "AGLedger CLI: developer and agent interface for AGLedger",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
"prepublishOnly": "npm run build && npm run lint:pkg"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@agledger/verify-core": "^1.
|
|
35
|
-
"@oclif/core": "^
|
|
34
|
+
"@agledger/verify-core": "^1.4.0",
|
|
35
|
+
"@oclif/core": "^5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@arethetypeswrong/cli": "^0.18.3",
|
|
39
39
|
"@types/node": "^24.0.0",
|
|
40
|
-
"oclif": "^
|
|
40
|
+
"oclif": "^5.0.1",
|
|
41
41
|
"publint": "^0.3.21",
|
|
42
42
|
"typescript": "^7.0.2",
|
|
43
|
-
"vitest": "^
|
|
43
|
+
"vitest": "^5.0.0"
|
|
44
44
|
},
|
|
45
45
|
"oclif": {
|
|
46
46
|
"bin": "agledger",
|