@agledger/cli 2.0.0 → 2.2.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.
Files changed (48) hide show
  1. package/README.md +77 -25
  2. package/SKILL.md +15 -14
  3. package/bin/run.js +2 -2
  4. package/dist/api-client.d.ts +7 -0
  5. package/dist/api-client.js +44 -8
  6. package/dist/base.d.ts +97 -12
  7. package/dist/base.js +90 -37
  8. package/dist/cli/command.d.ts +58 -0
  9. package/dist/cli/command.js +44 -0
  10. package/dist/cli/flags.d.ts +76 -0
  11. package/dist/cli/flags.js +12 -0
  12. package/dist/cli/help.d.ts +6 -0
  13. package/dist/cli/help.js +107 -0
  14. package/dist/cli/index.d.ts +3 -0
  15. package/dist/cli/index.js +3 -0
  16. package/dist/cli/main.d.ts +22 -0
  17. package/dist/cli/main.js +223 -0
  18. package/dist/cli/parse.d.ts +20 -0
  19. package/dist/cli/parse.js +138 -0
  20. package/dist/commands/api.d.ts +106 -18
  21. package/dist/commands/api.js +103 -12
  22. package/dist/commands/auth.d.ts +35 -6
  23. package/dist/commands/auth.js +1 -1
  24. package/dist/commands/config.d.ts +43 -8
  25. package/dist/commands/config.js +9 -8
  26. package/dist/commands/discover.d.ts +35 -6
  27. package/dist/commands/docs.d.ts +41 -7
  28. package/dist/commands/docs.js +4 -4
  29. package/dist/commands/help-json.d.ts +39 -7
  30. package/dist/commands/help-json.js +27 -45
  31. package/dist/commands/list-commands.d.ts +36 -7
  32. package/dist/commands/list-commands.js +2 -2
  33. package/dist/commands/login.d.ts +66 -10
  34. package/dist/commands/login.js +30 -9
  35. package/dist/commands/logout.d.ts +41 -7
  36. package/dist/commands/logout.js +8 -8
  37. package/dist/commands/verify.d.ts +131 -11
  38. package/dist/commands/verify.js +214 -25
  39. package/dist/oidc.d.ts +47 -0
  40. package/dist/oidc.js +162 -3
  41. package/dist/util/config.d.ts +16 -1
  42. package/dist/util/config.js +50 -14
  43. package/dist/util/field-parser.d.ts +3 -1
  44. package/dist/util/field-parser.js +11 -5
  45. package/package.json +9 -21
  46. package/dist/hooks/command-not-found.d.ts +0 -3
  47. package/dist/hooks/command-not-found.js +0 -63
  48. package/oclif.manifest.json +0 -857
@@ -1,19 +1,32 @@
1
- import { Args, Flags } from '@oclif/core';
1
+ import { accessSync, constants, statSync, writeFileSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
+ import { Args, Flags } from '../cli/index.js';
2
4
  import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
5
+ import { queryParams } from '../api-client.js';
3
6
  import { parseFields, FieldParseError } from '../util/field-parser.js';
7
+ /** Whether a string holds an ASCII control character (U+0000 to U+001F, or U+007F). */
8
+ function hasControlCharacter(text) {
9
+ return [...text].some((c) => {
10
+ const code = c.charCodeAt(0);
11
+ return code <= 0x1f || code === 0x7f;
12
+ });
13
+ }
14
+ /** The longest Idempotency-Key the Server takes. */
15
+ const MAX_IDEMPOTENCY_KEY_LENGTH = 256;
4
16
  const ALLOWED_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
5
17
  /**
6
18
  * Universal pass-through to the AGLedger API.
7
19
  *
8
- * Design principle: the CLI is a thin cover over the API. This command supports
9
- * every route the API exposes with zero drift, and no hand-coded flag-to-body mapping.
20
+ * Design principle: the CLI is a thin pass-through to the API. It has no
21
+ * per-route code, so it reaches every route the API exposes, and it does no
22
+ * flag-to-body mapping beyond parsing the -F and -f fields.
10
23
  *
11
24
  * Params go to query string for GET/DELETE, to JSON body for POST/PUT/PATCH.
12
25
  * Body sources compose in order: --data (raw JSON) → --input @file / stdin → -F/-f fields.
13
26
  * If multiple body sources are given, later sources take precedence for overlapping keys.
14
27
  */
15
28
  export default class Api extends BaseCommand {
16
- static description = 'Call any AGLedger API endpoint. Pass-through with zero flag translation: use the exact path and body shape documented in the API (see `agledger discover` or GET /openapi.json).';
29
+ static description = 'Call any AGLedger API endpoint. Pass-through: the request is sent as given, with no per-endpoint flag translation. Use the exact path and body shape documented in the API (see `agledger discover` or GET /openapi.json).';
17
30
  static examples = [
18
31
  'agledger api GET /health',
19
32
  'agledger api GET /v1/records -F status=ACTIVE -F limit=50',
@@ -23,6 +36,9 @@ export default class Api extends BaseCommand {
23
36
  'agledger api POST /v1/records --input payload.json',
24
37
  'cat payload.json | agledger api POST /v1/records --input -',
25
38
  'agledger api GET /v1/records --paginate # streams all pages as NDJSON',
39
+ 'agledger api GET /v1/records/search -F criteriaGte.amount=500 -F producedBy.modelId=gpt-x # bracket query: criteriaGte[amount]=500',
40
+ 'agledger api GET /v1/records/counts -F groupBy=status,type # up to two dimensions',
41
+ 'agledger api GET /v1/records/<record-id>/audit-export -F format=html --output audit.html # text formats are written as the Server sent them',
26
42
  ];
27
43
  static args = {
28
44
  method: Args.string({
@@ -45,7 +61,7 @@ export default class Api extends BaseCommand {
45
61
  field: Flags.string({
46
62
  char: 'F',
47
63
  multiple: true,
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.',
64
+ description: 'Set a typed field as key=value: true/false/null, numbers that print back as typed (0123 stays a string), 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
65
  }),
50
66
  'raw-field': Flags.string({
51
67
  char: 'f',
@@ -60,7 +76,10 @@ export default class Api extends BaseCommand {
60
76
  default: false,
61
77
  }),
62
78
  'idempotency-key': Flags.string({
63
- description: 'Dedup key for POST, max 256 chars. One is generated per call and shown by --verbose, and a TIMEOUT or dropped-connection error carries it as `idempotencyKey`. 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, where a rerun without it can create a duplicate. Bound to method, route and body, so a retry with a changed body is rejected.',
79
+ description: 'Dedup key for POST, max 256 chars. One is generated per call and shown by --verbose, and a TIMEOUT or dropped-connection error carries it as `idempotencyKey`. 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, where a rerun without it can create a duplicate. Bound to method, route and body, so a retry with a changed body is rejected. A 409 `IDEMPOTENCY_KEY_IN_FLIGHT` says the first attempt is still running: wait for its Retry-After and rerun with the same key. A 409 `IDEMPOTENT_WRITE_COMMITTED` says it already landed: follow its `refreshUrl` rather than retrying. A 503 `SERVER_SHUTTING_DOWN` is retryable with the same key.',
80
+ }),
81
+ output: Flags.string({
82
+ description: 'Write the response body to this file instead of stdout. A text response (the `html`, `csv` or `ndjson` audit export) is written byte for byte as the Server sent it; a JSON response is written pretty-printed.',
64
83
  }),
65
84
  'dry-run': Flags.boolean({
66
85
  description: 'Show the request that would be sent without calling the API.',
@@ -80,9 +99,18 @@ export default class Api extends BaseCommand {
80
99
  // Reject control characters before building the request URL. Agent-supplied
81
100
  // paths are untrusted input; control chars enable request-line / header
82
101
  // injection and never appear in a legitimate API path.
83
- if (/[\x00-\x1f\x7f]/.test(args.path)) {
102
+ if (hasControlCharacter(args.path)) {
84
103
  this.failWith(ErrorCode.INVALID_PATH, 'Path contains control characters', ExitCode.USAGE_ERROR, 'Remove control characters (newlines, tabs, null bytes) from the path.');
85
104
  }
105
+ const key = flags['idempotency-key'];
106
+ if (key !== undefined && !(key.length >= 1 && key.length <= MAX_IDEMPOTENCY_KEY_LENGTH && /^[\x20-\x7e]+$/.test(key))) {
107
+ this.failWith(ErrorCode.INVALID_FIELD, `--idempotency-key must be 1 to ${MAX_IDEMPOTENCY_KEY_LENGTH} printable ASCII characters, with no newline or control character.`, ExitCode.USAGE_ERROR, 'Use a UUID, or any short opaque string unique to this logical operation.');
108
+ }
109
+ if (flags.output !== undefined)
110
+ this.requireWritableOutput(flags.output);
111
+ if (flags.paginate && flags.output !== undefined) {
112
+ this.failWith(ErrorCode.INVALID_FIELD, '--paginate streams NDJSON to stdout and cannot be combined with --output', ExitCode.USAGE_ERROR, 'Redirect the stream instead: agledger api GET <path> --paginate > pages.ndjson');
113
+ }
86
114
  const params = this.composeParams(flags);
87
115
  if (flags.paginate) {
88
116
  if (method !== 'GET') {
@@ -97,6 +125,8 @@ export default class Api extends BaseCommand {
97
125
  }
98
126
  if (params !== undefined) {
99
127
  if (method === 'GET' || method === 'DELETE') {
128
+ // What a dry run shows is what is sent: a query with no wire form is refused here too.
129
+ queryParams(params);
100
130
  options.query = params;
101
131
  }
102
132
  else {
@@ -122,7 +152,7 @@ export default class Api extends BaseCommand {
122
152
  if (!response.ok) {
123
153
  this.handleApiError(response);
124
154
  }
125
- this.output(response.body);
155
+ this.emit(response.body, flags.output);
126
156
  }
127
157
  catch (err) {
128
158
  if (err instanceof FieldParseError) {
@@ -131,6 +161,65 @@ export default class Api extends BaseCommand {
131
161
  this.handleError(err);
132
162
  }
133
163
  }
164
+ /**
165
+ * A text response (`format=html|csv|ndjson` on an audit export, `/llms.txt`)
166
+ * reaches the client as `{ _raw, _contentType }`. Printing that wrapper as JSON
167
+ * would hand back an escaped string, so the text goes out as the Server sent
168
+ * it, to stdout or to `--output`. JSON responses print as before.
169
+ */
170
+ emit(body, outputPath) {
171
+ const raw = body !== null && typeof body === 'object' && typeof body._raw === 'string'
172
+ ? body._raw
173
+ : undefined;
174
+ if (outputPath !== undefined) {
175
+ try {
176
+ writeFileSync(outputPath, raw ?? JSON.stringify(body, null, 2) + '\n');
177
+ }
178
+ catch (err) {
179
+ // The request has been sent, and a write may have been applied. The body
180
+ // and the key it went out under are all the caller has of it.
181
+ if (raw === undefined)
182
+ this.output(body);
183
+ else if (!this.isQuiet)
184
+ process.stdout.write(raw);
185
+ const key = this.sentIdempotencyKey;
186
+ this.failWith(ErrorCode.FILE_WRITE_ERROR, `The response was received but cannot be written to ${outputPath}: ${err instanceof Error ? err.message : String(err)}. It was printed to stdout instead.`, ExitCode.GENERAL_ERROR, key
187
+ ? `The request was applied. Do not resend it without --idempotency-key ${key}, which replays the first result instead of recording the work twice.`
188
+ : 'The request was sent. Fix the path and rerun.', key ? { idempotencyKey: key } : undefined);
189
+ }
190
+ return;
191
+ }
192
+ if (raw === undefined) {
193
+ this.output(body);
194
+ }
195
+ else if (!this.isQuiet) {
196
+ process.stdout.write(raw);
197
+ }
198
+ }
199
+ /** Refuse an --output path that could not be written, before anything is sent. */
200
+ requireWritableOutput(path) {
201
+ let problem;
202
+ if (path === '') {
203
+ problem = 'is empty';
204
+ }
205
+ else {
206
+ try {
207
+ if (statSync(path, { throwIfNoEntry: false })?.isDirectory()) {
208
+ problem = 'is a directory';
209
+ }
210
+ else {
211
+ // An existing file must be writable; a new one needs a writable directory.
212
+ accessSync(statSync(path, { throwIfNoEntry: false }) ? path : dirname(path), constants.W_OK);
213
+ }
214
+ }
215
+ catch (err) {
216
+ problem = `cannot be written (${err.code ?? 'unknown error'})`;
217
+ }
218
+ }
219
+ if (problem) {
220
+ this.failWith(ErrorCode.FILE_WRITE_ERROR, `--output ${JSON.stringify(path)} ${problem}, so the request was not sent.`, ExitCode.USAGE_ERROR, 'Give a path in a writable directory.');
221
+ }
222
+ }
134
223
  /**
135
224
  * Merge --data, --input, -F/-f, and --query into a single params object.
136
225
  * Precedence (low → high): --data → --input → -F/-f fields → --query.
@@ -175,9 +264,8 @@ export default class Api extends BaseCommand {
175
264
  return incoming;
176
265
  }
177
266
  async runPaginated(flags, path, params, dryRun) {
178
- const baseQuery = params && typeof params === 'object' && !Array.isArray(params)
179
- ? { ...params }
180
- : {};
267
+ queryParams(params);
268
+ const baseQuery = params ? { ...params } : {};
181
269
  if (dryRun) {
182
270
  this.dryRunOutput({ method: 'GET', path, query: baseQuery, paginate: true, auth: this.resolvedAuth(flags) }, `would stream all pages of GET ${path}`);
183
271
  return;
@@ -193,7 +281,10 @@ export default class Api extends BaseCommand {
193
281
  this.handleApiError(response);
194
282
  }
195
283
  const page = (response.body ?? {});
196
- const items = (page.data ?? []);
284
+ if (!Array.isArray(page.data)) {
285
+ this.failWith(ErrorCode.NOT_PAGINATED, `The response from GET ${path} is not a paginated list (it has no "data" array), so there is nothing to stream.`, ExitCode.USAGE_ERROR, 'Drop --paginate for a route that returns a single object, or check the path with `agledger api GET /openapi.json`.');
286
+ }
287
+ const items = page.data;
197
288
  for (const item of items) {
198
289
  this.outputNdjson(item);
199
290
  }
@@ -10,12 +10,41 @@ import { BaseCommand } from '../base.js';
10
10
  export default class Auth extends BaseCommand {
11
11
  static description: string;
12
12
  static flags: {
13
- json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
- quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
- 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
- 'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
- profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
- verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ json: {
14
+ readonly description: "Force JSON output (default when stdout is piped)";
15
+ readonly default: false;
16
+ } & {
17
+ readonly type: 'boolean';
18
+ };
19
+ quiet: {
20
+ readonly description: "Suppress output (exit code only)";
21
+ readonly default: false;
22
+ } & {
23
+ readonly type: 'boolean';
24
+ };
25
+ 'api-key': {
26
+ readonly description: "AGLedger API key";
27
+ readonly env: "AGLEDGER_API_KEY";
28
+ } & {
29
+ readonly type: 'option';
30
+ };
31
+ 'api-url': {
32
+ readonly description: "AGLedger API base URL";
33
+ readonly env: "AGLEDGER_API_URL";
34
+ } & {
35
+ readonly type: 'option';
36
+ };
37
+ profile: {
38
+ readonly description: "Stored profile to use for credentials (falls back to the active profile)";
39
+ } & {
40
+ readonly type: 'option';
41
+ };
42
+ verbose: {
43
+ readonly description: "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.";
44
+ readonly default: false;
45
+ } & {
46
+ readonly type: 'boolean';
47
+ };
19
48
  };
20
49
  run(): Promise<void>;
21
50
  }
@@ -36,7 +36,7 @@ export default class Auth extends BaseCommand {
36
36
  credential: auth.credential,
37
37
  ...(auth.oidcTokenSource ? { oidcTokenSource: auth.oidcTokenSource } : {}),
38
38
  ...(auth.profile ? { profile: auth.profile } : {}),
39
- ...(cert ? { cert } : {}),
39
+ ...(cert ? { cert, publicKeyJwk: client.credential?.publicKeyJwk } : {}),
40
40
  account: response.body,
41
41
  });
42
42
  }
@@ -9,16 +9,51 @@ export default class Config extends BaseCommand {
9
9
  static description: string;
10
10
  static examples: string[];
11
11
  static args: {
12
- action: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
13
- profile: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
12
+ action: {
13
+ readonly description: "Action: list, get, use, path";
14
+ readonly required: true;
15
+ readonly options: readonly ["list", "get", "use", "path"];
16
+ };
17
+ profile: {
18
+ readonly description: "Profile name (for `use`)";
19
+ };
14
20
  };
15
21
  static flags: {
16
- json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
- quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
- 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
- 'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
- verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
21
- profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ json: {
23
+ readonly description: "Force JSON output (default when stdout is piped)";
24
+ readonly default: false;
25
+ } & {
26
+ readonly type: 'boolean';
27
+ };
28
+ quiet: {
29
+ readonly description: "Suppress output (exit code only)";
30
+ readonly default: false;
31
+ } & {
32
+ readonly type: 'boolean';
33
+ };
34
+ 'api-key': {
35
+ type: 'option';
36
+ description: "AGLedger API key";
37
+ env: "AGLEDGER_API_KEY";
38
+ hidden: boolean;
39
+ };
40
+ 'api-url': {
41
+ type: 'option';
42
+ description: "AGLedger API base URL";
43
+ env: "AGLEDGER_API_URL";
44
+ hidden: boolean;
45
+ };
46
+ verbose: {
47
+ type: 'boolean';
48
+ description: "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.";
49
+ default: false;
50
+ hidden: boolean;
51
+ };
52
+ profile: {
53
+ readonly description: "Profile name to inspect (for `get`)";
54
+ } & {
55
+ readonly type: 'option';
56
+ };
22
57
  };
23
58
  run(): Promise<void>;
24
59
  }
@@ -1,6 +1,6 @@
1
- import { Args, Flags } from '@oclif/core';
1
+ import { Args, Flags } from '../cli/index.js';
2
2
  import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
3
- import { configPath, readConfig, writeConfig } from '../util/config.js';
3
+ import { configPath, getProfile, readConfig, writeConfig } from '../util/config.js';
4
4
  /** What kind of credential a profile holds. Never echoes the key itself. */
5
5
  function credentialOf(p) {
6
6
  if (p.apiKey)
@@ -33,16 +33,17 @@ export default class Config extends BaseCommand {
33
33
  profile: Args.string({ description: 'Profile name (for `use`)' }),
34
34
  };
35
35
  static flags = {
36
- ...BaseCommand.baseFlags,
36
+ ...BaseCommand.offlineFlags,
37
37
  profile: Flags.string({ description: 'Profile name to inspect (for `get`)' }),
38
38
  };
39
39
  async run() {
40
40
  const { args, flags } = await this.parse(Config);
41
+ if (args.action === 'path') {
42
+ this.output({ path: configPath() });
43
+ return;
44
+ }
41
45
  const config = readConfig();
42
46
  switch (args.action) {
43
- case 'path':
44
- this.output({ path: configPath() });
45
- return;
46
47
  case 'list': {
47
48
  const profiles = Object.entries(config.profiles).map(([name, p]) => ({
48
49
  name,
@@ -58,7 +59,7 @@ export default class Config extends BaseCommand {
58
59
  if (!name) {
59
60
  this.failWith(ErrorCode.MISSING_INPUT, 'No active profile. Run `agledger config list` or `agledger login`.', ExitCode.USAGE_ERROR);
60
61
  }
61
- const profile = config.profiles[name];
62
+ const profile = getProfile(config, name);
62
63
  if (!profile) {
63
64
  this.failWith(ErrorCode.MISSING_INPUT, `Profile '${name}' not found.`, ExitCode.USAGE_ERROR, `Run \`agledger config list\` to see profiles.`);
64
65
  }
@@ -77,7 +78,7 @@ export default class Config extends BaseCommand {
77
78
  if (!target) {
78
79
  this.failWith(ErrorCode.MISSING_INPUT, '`config use` requires a profile name.', ExitCode.USAGE_ERROR, 'Example: agledger config use prod');
79
80
  }
80
- if (!config.profiles[target]) {
81
+ if (!getProfile(config, target)) {
81
82
  this.failWith(ErrorCode.MISSING_INPUT, `Profile '${target}' not found.`, ExitCode.USAGE_ERROR, 'Run `agledger config list` to see profiles, or `agledger login --profile <name>` to create one.');
82
83
  }
83
84
  config.activeProfile = target;
@@ -10,12 +10,41 @@ import { BaseCommand } from '../base.js';
10
10
  export default class Discover extends BaseCommand {
11
11
  static description: string;
12
12
  static flags: {
13
- json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
- quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
- 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
- 'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
- profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
- verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ json: {
14
+ readonly description: "Force JSON output (default when stdout is piped)";
15
+ readonly default: false;
16
+ } & {
17
+ readonly type: 'boolean';
18
+ };
19
+ quiet: {
20
+ readonly description: "Suppress output (exit code only)";
21
+ readonly default: false;
22
+ } & {
23
+ readonly type: 'boolean';
24
+ };
25
+ 'api-key': {
26
+ readonly description: "AGLedger API key";
27
+ readonly env: "AGLEDGER_API_KEY";
28
+ } & {
29
+ readonly type: 'option';
30
+ };
31
+ 'api-url': {
32
+ readonly description: "AGLedger API base URL";
33
+ readonly env: "AGLEDGER_API_URL";
34
+ } & {
35
+ readonly type: 'option';
36
+ };
37
+ profile: {
38
+ readonly description: "Stored profile to use for credentials (falls back to the active profile)";
39
+ } & {
40
+ readonly type: 'option';
41
+ };
42
+ verbose: {
43
+ readonly description: "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.";
44
+ readonly default: false;
45
+ } & {
46
+ readonly type: 'boolean';
47
+ };
19
48
  };
20
49
  run(): Promise<void>;
21
50
  }
@@ -9,13 +9,47 @@ export default class Docs extends BaseCommand {
9
9
  static description: string;
10
10
  static examples: string[];
11
11
  static flags: {
12
- json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
- quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
- 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
- 'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
- profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
- verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
- full: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ json: {
13
+ readonly description: "Force JSON output (default when stdout is piped)";
14
+ readonly default: false;
15
+ } & {
16
+ readonly type: 'boolean';
17
+ };
18
+ quiet: {
19
+ readonly description: "Suppress output (exit code only)";
20
+ readonly default: false;
21
+ } & {
22
+ readonly type: 'boolean';
23
+ };
24
+ 'api-key': {
25
+ readonly description: "AGLedger API key";
26
+ readonly env: "AGLEDGER_API_KEY";
27
+ } & {
28
+ readonly type: 'option';
29
+ };
30
+ 'api-url': {
31
+ readonly description: "AGLedger API base URL";
32
+ readonly env: "AGLEDGER_API_URL";
33
+ } & {
34
+ readonly type: 'option';
35
+ };
36
+ profile: {
37
+ readonly description: "Stored profile to use for credentials (falls back to the active profile)";
38
+ } & {
39
+ readonly type: 'option';
40
+ };
41
+ verbose: {
42
+ readonly description: "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.";
43
+ readonly default: false;
44
+ } & {
45
+ readonly type: 'boolean';
46
+ };
47
+ full: {
48
+ readonly description: "Fetch the expanded llms-full.txt narrative instead of the concise llms.txt.";
49
+ readonly default: false;
50
+ } & {
51
+ readonly type: 'boolean';
52
+ };
19
53
  };
20
54
  run(): Promise<void>;
21
55
  }
@@ -1,4 +1,4 @@
1
- import { Flags } from '@oclif/core';
1
+ import { Flags } from '../cli/index.js';
2
2
  import { BaseCommand } from '../base.js';
3
3
  /**
4
4
  * Fetch the API's agent-oriented documentation narrative. The API serves a
@@ -9,9 +9,9 @@ import { BaseCommand } from '../base.js';
9
9
  export default class Docs extends BaseCommand {
10
10
  static description = "Fetch the API's agent-oriented documentation narrative (llms.txt / llms-full.txt).";
11
11
  static examples = [
12
- '<%= config.bin %> docs',
13
- '<%= config.bin %> docs --full',
14
- '<%= config.bin %> docs --full > agledger-llms.txt',
12
+ 'agledger docs',
13
+ 'agledger docs --full',
14
+ 'agledger docs --full > agledger-llms.txt',
15
15
  ];
16
16
  static flags = {
17
17
  ...BaseCommand.baseFlags,
@@ -3,15 +3,47 @@ import { BaseCommand } from '../base.js';
3
3
  export default class HelpJson extends BaseCommand {
4
4
  static description: string;
5
5
  static args: {
6
- command: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
6
+ command: {
7
+ readonly description: "CLI command name (e.g., \"api\", \"discover\", \"login\")";
8
+ readonly required: true;
9
+ };
7
10
  };
8
11
  static flags: {
9
- json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
- quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
- 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
- 'api-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
- profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
- verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ json: {
13
+ readonly description: "Force JSON output (default when stdout is piped)";
14
+ readonly default: false;
15
+ } & {
16
+ readonly type: 'boolean';
17
+ };
18
+ quiet: {
19
+ readonly description: "Suppress output (exit code only)";
20
+ readonly default: false;
21
+ } & {
22
+ readonly type: 'boolean';
23
+ };
24
+ 'api-key': {
25
+ type: 'option';
26
+ description: "AGLedger API key";
27
+ env: "AGLEDGER_API_KEY";
28
+ hidden: boolean;
29
+ };
30
+ 'api-url': {
31
+ type: 'option';
32
+ description: "AGLedger API base URL";
33
+ env: "AGLEDGER_API_URL";
34
+ hidden: boolean;
35
+ };
36
+ profile: {
37
+ type: 'option';
38
+ description: "Stored profile to use for credentials (falls back to the active profile)";
39
+ hidden: boolean;
40
+ };
41
+ verbose: {
42
+ type: 'boolean';
43
+ description: "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.";
44
+ default: false;
45
+ hidden: boolean;
46
+ };
15
47
  };
16
48
  run(): Promise<void>;
17
49
  }
@@ -1,4 +1,5 @@
1
- import { Args } from '@oclif/core';
1
+ import { Args, allFlags } from '../cli/index.js';
2
+ import { loadCommand } from '../cli/main.js';
2
3
  import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
3
4
  /** Per-command JSON schema for agent consumption (~200 tokens per command). */
4
5
  export default class HelpJson extends BaseCommand {
@@ -6,52 +7,33 @@ export default class HelpJson extends BaseCommand {
6
7
  static args = {
7
8
  command: Args.string({ description: 'CLI command name (e.g., "api", "discover", "login")', required: true }),
8
9
  };
9
- static flags = { ...BaseCommand.baseFlags };
10
+ static flags = { ...BaseCommand.offlineFlags };
10
11
  async run() {
11
12
  const { args } = await this.parse(HelpJson);
12
- try {
13
- const plugin = this.config.plugins.get(this.config.pjson.name);
14
- if (!plugin) {
15
- this.output({ error: 'Plugin not found' });
16
- return;
17
- }
18
- const cmdId = args.command.replace(/ /g, ':');
19
- const cmd = plugin.commands.find((c) => c.id === cmdId || c.aliases?.includes(cmdId));
20
- if (!cmd) {
21
- this.failWith(ErrorCode.COMMAND_NOT_FOUND, `Command "${args.command}" not found`, ExitCode.USAGE_ERROR, 'Run "agledger list-commands" to see available commands');
22
- }
23
- this.output({
24
- name: cmd.id.replace(/:/g, ' '),
25
- description: cmd.description ?? '',
26
- args: Object.fromEntries(Object.entries(cmd.args ?? {}).map(([k, v]) => [
27
- k,
28
- { description: v.description, required: v.required },
29
- ])),
30
- flags: Object.fromEntries(Object.entries(cmd.flags ?? {})
31
- .filter(([k]) => !['json', 'api-key', 'api-url'].includes(k))
32
- .map(([k, v]) => {
33
- const char = v.char;
34
- return [
35
- k,
36
- {
37
- description: v.description,
38
- required: v.required ?? false,
39
- type: v.type,
40
- // Surface the short alias (e.g. -F for --field) so a doc that
41
- // shows the short form can be verified against this schema.
42
- ...(typeof char === 'string' ? { char } : {}),
43
- },
44
- ];
45
- })),
46
- });
47
- }
48
- catch (err) {
49
- if (err instanceof Error && err.message.startsWith('EEXIT:'))
50
- throw err;
51
- this.output({
52
- error: `Could not load schema for "${args.command}"`,
53
- suggestion: 'Run "agledger list-commands" to see available commands',
54
- });
13
+ const cmd = await loadCommand(args.command);
14
+ if (!cmd) {
15
+ this.failWith(ErrorCode.COMMAND_NOT_FOUND, `Command "${args.command}" not found`, ExitCode.USAGE_ERROR, 'Run "agledger list-commands" to see available commands');
55
16
  }
17
+ this.output({
18
+ name: args.command,
19
+ description: cmd.description ?? '',
20
+ args: Object.fromEntries(Object.entries(cmd.args ?? {}).map(([k, v]) => [
21
+ k,
22
+ { description: v.description, required: v.required },
23
+ ])),
24
+ flags: Object.fromEntries(Object.entries(allFlags(cmd))
25
+ .filter(([k]) => !['json', 'api-key', 'api-url'].includes(k))
26
+ .map(([k, v]) => [
27
+ k,
28
+ {
29
+ description: v.description,
30
+ required: v.type === 'option' ? (v.required ?? false) : false,
31
+ type: v.type,
32
+ // Surface the short alias (e.g. -F for --field) so a doc that
33
+ // shows the short form can be verified against this schema.
34
+ ...(v.char ? { char: v.char } : {}),
35
+ },
36
+ ])),
37
+ });
56
38
  }
57
39
  }