flipstream 0.5.0 → 0.6.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 (85) hide show
  1. package/README.md +168 -12
  2. package/dist/commands/auth/login.js +7 -1
  3. package/dist/commands/auth/status.js +29 -3
  4. package/dist/commands/catalog.d.ts +15 -0
  5. package/dist/commands/catalog.js +110 -0
  6. package/dist/commands/connections/list.d.ts +1 -0
  7. package/dist/commands/connections/list.js +27 -1
  8. package/dist/commands/contract.d.ts +11 -0
  9. package/dist/commands/contract.js +35 -0
  10. package/dist/commands/health.d.ts +10 -0
  11. package/dist/commands/health.js +31 -0
  12. package/dist/commands/log/add.js +6 -2
  13. package/dist/commands/query.d.ts +15 -2
  14. package/dist/commands/query.js +255 -42
  15. package/dist/commands/skills/install.d.ts +16 -0
  16. package/dist/commands/skills/install.js +55 -0
  17. package/dist/commands/workspaces/connections.js +3 -1
  18. package/dist/commands/workspaces/get.js +4 -2
  19. package/dist/commands/workspaces/list.js +3 -0
  20. package/dist/lib/api/errors.d.ts +1 -0
  21. package/dist/lib/api/errors.js +13 -2
  22. package/dist/lib/api/http.d.ts +2 -0
  23. package/dist/lib/api/http.js +40 -4
  24. package/dist/lib/api/ids.d.ts +1 -0
  25. package/dist/lib/api/ids.js +5 -0
  26. package/dist/lib/api/short-uuid.d.ts +1 -0
  27. package/dist/lib/api/short-uuid.js +30 -0
  28. package/dist/lib/auth/flow.js +8 -1
  29. package/dist/lib/auth/headless.js +14 -10
  30. package/dist/lib/auth/refresh.js +21 -1
  31. package/dist/lib/command/base.d.ts +4 -0
  32. package/dist/lib/command/base.js +97 -3
  33. package/dist/lib/command/flags.d.ts +4 -0
  34. package/dist/lib/command/flags.js +11 -0
  35. package/dist/lib/command/planner.d.ts +9 -0
  36. package/dist/lib/command/planner.js +14 -0
  37. package/dist/lib/config/constants.d.ts +3 -1
  38. package/dist/lib/config/constants.js +14 -1
  39. package/dist/lib/config/xdg.d.ts +4 -0
  40. package/dist/lib/config/xdg.js +56 -1
  41. package/dist/lib/errors.d.ts +20 -1
  42. package/dist/lib/errors.js +125 -17
  43. package/dist/lib/output/dialogs.d.ts +27 -0
  44. package/dist/lib/output/dialogs.js +94 -0
  45. package/dist/lib/output/interactivity.d.ts +11 -0
  46. package/dist/lib/output/interactivity.js +48 -0
  47. package/dist/lib/output/redact.d.ts +1 -0
  48. package/dist/lib/output/redact.js +12 -0
  49. package/dist/lib/output/runlog.d.ts +3 -0
  50. package/dist/lib/output/runlog.js +72 -0
  51. package/dist/lib/output/sanitize.d.ts +2 -0
  52. package/dist/lib/output/sanitize.js +57 -0
  53. package/dist/lib/output/sidecar.d.ts +30 -0
  54. package/dist/lib/output/sidecar.js +58 -0
  55. package/dist/lib/output/table.js +5 -1
  56. package/dist/lib/output/trace.d.ts +11 -0
  57. package/dist/lib/output/trace.js +89 -0
  58. package/dist/lib/planner/catalog.d.ts +26 -0
  59. package/dist/lib/planner/catalog.js +60 -0
  60. package/dist/lib/planner/client.d.ts +14 -0
  61. package/dist/lib/planner/client.js +47 -0
  62. package/dist/lib/planner/connection.d.ts +14 -0
  63. package/dist/lib/planner/connection.js +139 -0
  64. package/dist/lib/planner/diagnose.d.ts +8 -0
  65. package/dist/lib/planner/diagnose.js +50 -0
  66. package/dist/lib/planner/errors.d.ts +14 -0
  67. package/dist/lib/planner/errors.js +129 -0
  68. package/dist/lib/planner/filters.d.ts +8 -0
  69. package/dist/lib/planner/filters.js +74 -0
  70. package/dist/lib/planner/request.d.ts +24 -0
  71. package/dist/lib/planner/request.js +51 -0
  72. package/dist/lib/planner/suggest.d.ts +2 -0
  73. package/dist/lib/planner/suggest.js +45 -0
  74. package/dist/lib/planner/vocabulary.d.ts +9 -0
  75. package/dist/lib/planner/vocabulary.js +95 -0
  76. package/dist/lib/skills/install.d.ts +24 -0
  77. package/dist/lib/skills/install.js +69 -0
  78. package/dist/lib/store/keyring.d.ts +3 -0
  79. package/dist/lib/store/keyring.js +45 -2
  80. package/dist/lib/store/memory-store.d.ts +1 -0
  81. package/dist/lib/store/memory-store.js +5 -0
  82. package/docs/AGENT-CONTRACT.md +238 -0
  83. package/oclif.manifest.json +392 -8
  84. package/package.json +7 -3
  85. package/skill/SKILL.md +55 -0
package/README.md CHANGED
@@ -107,14 +107,18 @@ If you already removed the binary, clean up manually:
107
107
  * [`flipstream auth login`](#flipstream-auth-login)
108
108
  * [`flipstream auth logout`](#flipstream-auth-logout)
109
109
  * [`flipstream auth status`](#flipstream-auth-status)
110
+ * [`flipstream catalog [SOURCE]`](#flipstream-catalog-source)
110
111
  * [`flipstream commands`](#flipstream-commands)
111
112
  * [`flipstream conn list`](#flipstream-conn-list)
112
113
  * [`flipstream connections list`](#flipstream-connections-list)
114
+ * [`flipstream contract`](#flipstream-contract)
115
+ * [`flipstream health`](#flipstream-health)
113
116
  * [`flipstream log add MESSAGE`](#flipstream-log-add-message)
114
117
  * [`flipstream log list`](#flipstream-log-list)
115
118
  * [`flipstream logs add MESSAGE`](#flipstream-logs-add-message)
116
119
  * [`flipstream logs list`](#flipstream-logs-list)
117
120
  * [`flipstream query`](#flipstream-query)
121
+ * [`flipstream skills install`](#flipstream-skills-install)
118
122
  * [`flipstream version`](#flipstream-version)
119
123
  * [`flipstream workspaces connections ID`](#flipstream-workspaces-connections-id)
120
124
  * [`flipstream workspaces get ID`](#flipstream-workspaces-get-id)
@@ -240,6 +244,45 @@ EXAMPLES
240
244
  $ flipstream auth status --json
241
245
  ```
242
246
 
247
+ ## `flipstream catalog [SOURCE]`
248
+
249
+ Show the dimensions and metrics a source accepts.
250
+
251
+ ```
252
+ USAGE
253
+ $ flipstream catalog [SOURCE] [--json] [-H <value>] [--ndjson] [--timeout <value>] [--verbose] [--auth-host
254
+ <value>] [--url <value>]
255
+
256
+ ARGUMENTS
257
+ [SOURCE] A source name (omit to list every source).
258
+
259
+ FLAGS
260
+ -H, --host=<value> OAuth provider host (defaults to the prod issuer).
261
+ --auth-host=<value> OAuth issuer host for credentials/refresh (defaults to the prod issuer).
262
+ --ndjson Stream output as NDJSON (one compact JSON object per line).
263
+ --timeout=<value> Network timeout in milliseconds.
264
+ --url=<value> Query-planner base URL (default: the prod planner; env FLIPSTREAM_PLANNER_URL).
265
+ --verbose Print redacted diagnostics to stderr.
266
+
267
+ GLOBAL FLAGS
268
+ --json Format output as json.
269
+
270
+ DESCRIPTION
271
+ Show the dimensions and metrics a source accepts.
272
+
273
+ Print the request vocabulary the query planner accepts. The names shown ARE what `query` takes: `-d` and `-m` and
274
+ filter keys use an item's `name` (the wire name, e.g. search_date), never its `label` (what a human reads, e.g. Date).
275
+ Read from the SERVICE, never from a local data-model checkout — the two differ exactly when it matters most, right
276
+ after a version bump.
277
+
278
+ EXAMPLES
279
+ $ flipstream catalog
280
+
281
+ $ flipstream catalog gsc
282
+
283
+ $ flipstream catalog gsc --json
284
+ ```
285
+
243
286
  ## `flipstream commands`
244
287
 
245
288
  List all flipstream commands.
@@ -351,6 +394,68 @@ EXAMPLES
351
394
  $ flipstream conn list --all
352
395
  ```
353
396
 
397
+ ## `flipstream contract`
398
+
399
+ Print the agent contract (machine-facing promises) to stdout.
400
+
401
+ ```
402
+ USAGE
403
+ $ flipstream contract [--json] [-H <value>] [--ndjson] [--timeout <value>] [--verbose]
404
+
405
+ FLAGS
406
+ -H, --host=<value> OAuth provider host (defaults to the prod issuer).
407
+ --ndjson Stream output as NDJSON (one compact JSON object per line).
408
+ --timeout=<value> Network timeout in milliseconds.
409
+ --verbose Print redacted diagnostics to stderr.
410
+
411
+ GLOBAL FLAGS
412
+ --json Format output as json.
413
+
414
+ DESCRIPTION
415
+ Print the agent contract (machine-facing promises) to stdout.
416
+
417
+ Print docs/AGENT-CONTRACT.md — the frozen machine contract (output modes, exit codes, error envelope, per-command JSON
418
+ shapes) — to stdout, from the installed package, no network needed. Context self-service for agents: read this before
419
+ driving the CLI programmatically.
420
+
421
+ EXAMPLES
422
+ $ flipstream contract
423
+
424
+ $ flipstream contract --json
425
+ ```
426
+
427
+ ## `flipstream health`
428
+
429
+ Check that the query planner is reachable.
430
+
431
+ ```
432
+ USAGE
433
+ $ flipstream health [--json] [-H <value>] [--ndjson] [--timeout <value>] [--verbose] [--url <value>]
434
+
435
+ FLAGS
436
+ -H, --host=<value> OAuth provider host (defaults to the prod issuer).
437
+ --ndjson Stream output as NDJSON (one compact JSON object per line).
438
+ --timeout=<value> Network timeout in milliseconds.
439
+ --url=<value> Query-planner base URL (default: the prod planner; env FLIPSTREAM_PLANNER_URL).
440
+ --verbose Print redacted diagnostics to stderr.
441
+
442
+ GLOBAL FLAGS
443
+ --json Format output as json.
444
+
445
+ DESCRIPTION
446
+ Check that the query planner is reachable.
447
+
448
+ Check that the query planner is answering. This is the ONE endpoint that takes no token, so it separates "the service
449
+ is down" from "my credentials are wrong" before any auth debugging starts.
450
+
451
+ EXAMPLES
452
+ $ flipstream health
453
+
454
+ $ flipstream health --json
455
+
456
+ $ flipstream health --url http://localhost:8080
457
+ ```
458
+
354
459
  ## `flipstream log add MESSAGE`
355
460
 
356
461
  Add an entry to a workspace's log.
@@ -517,18 +622,69 @@ EXAMPLES
517
622
 
518
623
  ## `flipstream query`
519
624
 
520
- Run an opaque query against the Flipstream data API.
625
+ Run a logical query against the Flipstream query planner.
521
626
 
522
627
  ```
523
628
  USAGE
524
629
  $ flipstream query [--json] [-H <value>] [--ndjson] [--timeout <value>] [--verbose] [--auth-host <value>]
525
- [--body <value> | --body-file <value>]
630
+ [--url <value>] [--body <value> | --body-file <value>] [--connection-id <value>] [-d <value>...] [--dry-run] [-f
631
+ <value>...] [-m <value>...] [--offset <value>] [--rows <value>] [-s <value>...] [--source <value>] [--table <value>]
632
+
633
+ FLAGS
634
+ -H, --host=<value> OAuth provider host (defaults to the prod issuer).
635
+ -d, --dimension=<value>... Dimension name (repeatable).
636
+ -f, --filter=<value>... Filter as col=a,b | col=from..to | col=<json> (repeatable). 'col=' is refused.
637
+ -m, --metric=<value>... Metric name (repeatable).
638
+ -s, --sort=<value>... FIELD[:asc|desc] (repeatable).
639
+ --auth-host=<value> OAuth issuer host for credentials/refresh (defaults to the prod issuer).
640
+ --body=<value> Send this JSON body verbatim.
641
+ --body-file=<value> Path to a file holding the JSON body verbatim ("-" reads stdin).
642
+ --connection-id=<value> Connection UUID, or a name to look up.
643
+ --dry-run Print the request body and send nothing.
644
+ --ndjson Stream output as NDJSON (one compact JSON object per line).
645
+ --offset=<value> Row offset.
646
+ --rows=<value> Row limit (default 100).
647
+ --source=<value> The dataset discriminator, e.g. gsc.
648
+ --table=<value> Physical table — honoured only for an unmodelled source.
649
+ --timeout=<value> Network timeout in milliseconds.
650
+ --url=<value> Query-planner base URL (default: the prod planner; env FLIPSTREAM_PLANNER_URL).
651
+ --verbose Print redacted diagnostics to stderr.
652
+
653
+ GLOBAL FLAGS
654
+ --json Format output as json.
655
+
656
+ DESCRIPTION
657
+ Run a logical query against the Flipstream query planner.
658
+
659
+ Send a LOGICAL query (source + dimensions + metrics + filters) to the Flipstream query planner, which resolves which
660
+ physical table answers it and returns the rows. Run `flipstream catalog <source>` first — the names it prints ARE what
661
+ -d, -m and filter keys take. --body/--body-file/stdin still forwards a JSON body verbatim for shapes the flags cannot
662
+ express.
663
+
664
+ EXAMPLES
665
+ $ flipstream catalog gsc
666
+
667
+ $ flipstream query --source gsc --connection-id <id|name> -d search_date -d query -m clicks -f 'search_date=2026-01-01..2026-02-01' --rows 20
668
+
669
+ $ flipstream query --source gsc --connection-id <id> -d query -m clicks --dry-run
670
+
671
+ $ flipstream query --body-file request.json --json
672
+ ```
673
+
674
+ ## `flipstream skills install`
675
+
676
+ Install the flipstream skill for detected AI coding agents.
677
+
678
+ ```
679
+ USAGE
680
+ $ flipstream skills install [--json] [-H <value>] [--ndjson] [--timeout <value>] [--verbose] [--agent
681
+ claude-code|codex|cursor|opencode...] [-y]
526
682
 
527
683
  FLAGS
528
684
  -H, --host=<value> OAuth provider host (defaults to the prod issuer).
529
- --auth-host=<value> OAuth issuer host for credentials/refresh (defaults to the prod issuer).
530
- --body=<value> Opaque JSON request body as a string.
531
- --body-file=<value> Path to a file holding the opaque JSON request body.
685
+ -y, --yes Install without asking.
686
+ --agent=<option>... Install for this agent id only (repeatable). Known: claude-code, codex, cursor, opencode.
687
+ <options: claude-code|codex|cursor|opencode>
532
688
  --ndjson Stream output as NDJSON (one compact JSON object per line).
533
689
  --timeout=<value> Network timeout in milliseconds.
534
690
  --verbose Print redacted diagnostics to stderr.
@@ -537,18 +693,18 @@ GLOBAL FLAGS
537
693
  --json Format output as json.
538
694
 
539
695
  DESCRIPTION
540
- Run an opaque query against the Flipstream data API.
696
+ Install the flipstream skill for detected AI coding agents.
541
697
 
542
- Send an OPAQUE JSON body (--body, --body-file, or piped stdin) to the Flipstream data API and print the structured
543
- JSON response. The CLI never constructs, validates, or transforms the query payload the body is forwarded verbatim
544
- (your agent/Skill builds it).
698
+ Install the flipstream skill (SKILL.md) into the global skills directory of every detected AI coding agent (Claude
699
+ Code, Codex, Cursor, OpenCode). Detection is local env/dir inspection only nothing is reported anywhere. The skill
700
+ teaches an agent to retrieve the command surface and data vocabulary from the CLI instead of guessing.
545
701
 
546
702
  EXAMPLES
547
- $ flipstream query --body '{"opaque":true}'
703
+ $ flipstream skills install
548
704
 
549
- echo '{"opaque":true}' | flipstream query
705
+ $ flipstream skills install --yes
550
706
 
551
- $ flipstream query --body-file query.json --json
707
+ $ flipstream skills install --agent claude-code --agent codex
552
708
  ```
553
709
 
554
710
  ## `flipstream version`
@@ -44,6 +44,12 @@ export default class AuthLogin extends BaseCommand {
44
44
  }
45
45
  // Emit only the (redacted) decoded claims — never the raw token.
46
46
  const claims = redact(result.claims);
47
- return this.respond(claims, (data) => this.log(JSON.stringify(data)));
47
+ return this.respond(claims, (data) => {
48
+ this.log(JSON.stringify(data));
49
+ // Close the loop (E11-3, #102): a fresh login has exactly two sensible
50
+ // next moves — prove the pipe works, then learn the vocabulary.
51
+ this.footer(`\nNext: ${this.config.bin} health (checks the query planner is reachable)\n` +
52
+ ` ${this.config.bin} catalog (lists the sources you can query)`);
53
+ });
48
54
  }
49
55
  }
@@ -1,8 +1,15 @@
1
1
  import { tokenClaims } from '../../lib/auth/claims.js';
2
2
  import { BaseCommand } from '../../lib/command/base.js';
3
3
  import { ExitCode } from '../../lib/exit-codes.js';
4
- import { redact } from '../../lib/output/redact.js';
4
+ import { isCI } from '../../lib/output/interactivity.js';
5
+ import { maskAccount, redact } from '../../lib/output/redact.js';
5
6
  import { createStore } from '../../lib/store/index.js';
7
+ // 'expires in 25m' below an hour, 'expires in 2h' above — never a rounded-to-0h.
8
+ function formatRemaining(seconds) {
9
+ if (seconds < 3600)
10
+ return `${Math.max(1, Math.round(seconds / 60))}m`;
11
+ return `${Math.round(seconds / 3600)}h`;
12
+ }
6
13
  export default class AuthStatus extends BaseCommand {
7
14
  static description = 'Show the current Flipstream authentication status for a host.';
8
15
  static examples = ['<%= config.bin %> auth status', '<%= config.bin %> auth status --json'];
@@ -37,11 +44,30 @@ export default class AuthStatus extends BaseCommand {
37
44
  scopes: creds.scopes,
38
45
  });
39
46
  return this.respond(status, () => {
40
- const relative = expired ? 'expired' : `expires in ${Math.round((creds.expiresAt - nowSeconds) / 3600)}h`;
47
+ // ONE formatter for both the stdout line and the stderr note a status
48
+ // command must not contradict itself about its own subject (E11-2 review).
49
+ const remaining = formatRemaining(creds.expiresAt - nowSeconds);
50
+ const relative = expired ? 'expired' : `expires in ${remaining}`;
51
+ // Disclosure tier (E11-4): mask the account in CI human output. This is
52
+ // HYGIENE for the human line, not a privacy control — the --json path
53
+ // (the one agents/CI actually consume) keeps the stable value by
54
+ // contract, so a public build log is not made safe by this alone.
55
+ const shown = typeof displayAccount === 'string' ? displayAccount : 'unknown';
41
56
  this.log(`Logged in to ${host}`);
42
- this.log(` account: ${typeof displayAccount === 'string' ? displayAccount : 'unknown'}`);
57
+ this.log(` account: ${isCI() ? maskAccount(shown) : shown}`);
43
58
  this.log(` expires: ${expiresAtIso} (${relative})`);
44
59
  this.log(` scopes: ${creds.scopes.join(' ')}`);
60
+ // Expiry narration (E11-2, #101): state the consequence, not just the fact.
61
+ // An expired ACCESS token is normal — commands refresh it on use — so the
62
+ // warning names the failure mode that actually needs the human (refresh
63
+ // rejected → session_expired) rather than crying wolf.
64
+ if (expired) {
65
+ this.note('the access token has expired; commands refresh it automatically — if one fails with ' +
66
+ 'session_expired, run `flipstream auth login`');
67
+ }
68
+ else if (creds.expiresAt - nowSeconds < 24 * 3600) {
69
+ this.note(`the access token expires in ${remaining} and will refresh automatically on use`);
70
+ }
45
71
  });
46
72
  }
47
73
  }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../lib/command/base.js';
2
+ export default class Catalog extends BaseCommand<typeof Catalog> {
3
+ static args: {
4
+ source: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ 'auth-host': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ };
12
+ static summary: string;
13
+ run(): Promise<unknown>;
14
+ private renderSource;
15
+ }
@@ -0,0 +1,110 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../lib/command/base.js';
3
+ import { plannerFlags } from '../lib/command/flags.js';
4
+ import { authedPlannerClient } from '../lib/command/planner.js';
5
+ import { resolveHost, resolvePlannerUrl } from '../lib/config/xdg.js';
6
+ import { AuthRequiredError } from '../lib/errors.js';
7
+ import { redact } from '../lib/output/redact.js';
8
+ import { sanitizeTerminal } from '../lib/output/sanitize.js';
9
+ import { renderTable } from '../lib/output/table.js';
10
+ import { parseCatalogIndex, parseCatalogSource } from '../lib/planner/catalog.js';
11
+ import { mapCatalogError } from '../lib/planner/errors.js';
12
+ import { createStore } from '../lib/store/index.js';
13
+ export default class Catalog extends BaseCommand {
14
+ static args = {
15
+ source: Args.string({
16
+ description: 'A source name (omit to list every source).',
17
+ // oclif fills a MISSING positional from stdin when stdin is not a TTY, so
18
+ // `echo x | flipstream catalog` would silently become `catalog x` — and a
19
+ // spawned process (the normal case for an agent) has a non-TTY stdin it may
20
+ // never close, which makes that read hang forever. Nothing here wants stdin.
21
+ ignoreStdin: true,
22
+ required: false,
23
+ }),
24
+ };
25
+ static description = 'Print the request vocabulary the query planner accepts. The names shown ARE what `query` takes: `-d` and ' +
26
+ "`-m` and filter keys use an item's `name` (the wire name, e.g. search_date), never its `label` (what a human " +
27
+ 'reads, e.g. Date). Read from the SERVICE, never from a local data-model checkout — the two differ exactly ' +
28
+ 'when it matters most, right after a version bump.';
29
+ static examples = [
30
+ '<%= config.bin %> catalog',
31
+ '<%= config.bin %> catalog gsc',
32
+ '<%= config.bin %> catalog gsc --json',
33
+ ];
34
+ static flags = { ...plannerFlags };
35
+ static summary = 'Show the dimensions and metrics a source accepts.';
36
+ async run() {
37
+ const url = resolvePlannerUrl({ urlFlag: this.flags.url });
38
+ const authHost = resolveHost({ hostFlag: this.flags['auth-host'] ?? this.flags.host });
39
+ const store = createStore();
40
+ if (!store.load(authHost))
41
+ throw AuthRequiredError.notLoggedIn();
42
+ const client = authedPlannerClient({ authHost, store, timeoutMs: this.flags.timeout, url });
43
+ const { source } = this.args;
44
+ let raw;
45
+ const started = Date.now();
46
+ try {
47
+ raw = await client.getCatalog(source, { timeoutMs: this.flags.timeout });
48
+ }
49
+ catch (error) {
50
+ throw mapCatalogError(error, { bin: this.config.bin, source, url });
51
+ }
52
+ // Which host answered (E11-2): the planner and the admin API are different
53
+ // origins, and "which one did I just talk to" is the first debugging question.
54
+ this.verboseLog(`GET ${url}/catalog${source === undefined ? '' : `/${source}`} (${Date.now() - started} ms)`);
55
+ // Redact BEFORE the document becomes output, exactly as `query` does. The
56
+ // served catalog is an allowlist projection built by data-model, so nothing
57
+ // secret should be in it — but "should" is the service's promise, and this is
58
+ // our own output boundary. A projection here would instead drop fields the
59
+ // service legitimately adds, so redaction (which masks secret-NAMED keys and
60
+ // leaves the rest untouched) is the right tool: it keeps `--json` faithful to
61
+ // the document as served while still refusing to print a credential.
62
+ const payload = redact(raw);
63
+ if (source === undefined) {
64
+ const index = parseCatalogIndex(payload);
65
+ return this.respond(payload, () => {
66
+ renderTable(index.sources.map((entry) => ({ ...entry })), [
67
+ { key: 'name', name: 'Source' },
68
+ { key: 'label', name: 'Label' },
69
+ { key: 'dimensions', name: 'Dimensions' },
70
+ { key: 'metrics', name: 'Metrics' },
71
+ ], 'No sources.');
72
+ // Footer to STDERR: it is guidance, not data, and stdout must stay clean.
73
+ const hint = index.defaultSource === undefined ? '' : `, default ${index.defaultSource}`;
74
+ this.footer(`\n${index.sources.length} source(s)${hint}; \`${this.config.bin} catalog ${index.defaultSource ?? '<source>'}\` for its names`);
75
+ });
76
+ }
77
+ const entry = parseCatalogSource(payload);
78
+ return this.respond(payload, () => this.renderSource(entry));
79
+ }
80
+ renderSource(entry) {
81
+ this.log(sanitizeTerminal(`${entry.name} — ${entry.label}`));
82
+ if (entry.description)
83
+ this.log(sanitizeTerminal(entry.description));
84
+ for (const [heading, items] of [
85
+ ['DIMENSIONS', entry.dimensions],
86
+ ['METRICS', entry.metrics],
87
+ ]) {
88
+ this.log(`\n${heading}`);
89
+ renderTable(items.map((item) => ({ ...item })), [
90
+ { key: 'name', name: 'Name' },
91
+ { key: 'label', name: 'Label' },
92
+ { key: 'type', name: 'Type' },
93
+ { key: 'description', name: 'Description' },
94
+ ], '(none)');
95
+ }
96
+ if (entry.customDimensionsMax !== undefined) {
97
+ this.log(`\nCUSTOM DIMENSIONS up to ${entry.customDimensionsMax} per connection`);
98
+ }
99
+ // A runnable next command built from THIS source's real names (E11-3, #102):
100
+ // the reader of a catalog is one edit away from a working query, so hand
101
+ // them that edit. stderr — guidance, not data.
102
+ const dimension = entry.dimensions[0]?.name;
103
+ const metric = entry.metrics[0]?.name;
104
+ if (dimension !== undefined && metric !== undefined) {
105
+ this.footer(`\nTry: ${this.config.bin} query --source ${entry.name} --connection-id <id|name> ` +
106
+ `-d ${dimension} -m ${metric} --json\n` +
107
+ ` (${this.config.bin} connections list prints the ids)`);
108
+ }
109
+ }
110
+ }
@@ -16,4 +16,5 @@ export default class ConnectionsList extends BaseCommand<typeof ConnectionsList>
16
16
  count: number;
17
17
  records: unknown[];
18
18
  }>;
19
+ private printUsageFooter;
19
20
  }
@@ -30,6 +30,7 @@ export default class ConnectionsList extends BaseCommand {
30
30
  if (!store.load(host))
31
31
  throw AuthRequiredError.notLoggedIn();
32
32
  const client = authedAdminClient(host, store, this.flags.timeout);
33
+ const startedMs = Date.now();
33
34
  const projected = await fetchConnections(client, {
34
35
  all: this.flags.all,
35
36
  limit: this.flags.limit,
@@ -39,6 +40,31 @@ export default class ConnectionsList extends BaseCommand {
39
40
  workspace,
40
41
  });
41
42
  await hydrate(client, projected.records, [WORKSPACE_NAME]);
42
- return this.respondList(projected, (records) => renderConnectionsTable(records));
43
+ // Which origin answered (E11-2): planner vs admin is the first debugging question.
44
+ this.verboseLog(`GET ${host}/connections (${Date.now() - startedMs} ms)`);
45
+ return this.respondList(projected, (records) => {
46
+ renderConnectionsTable(records);
47
+ this.printUsageFooter(records);
48
+ });
49
+ }
50
+ // The exact next command with a REAL id from the results (E11-3, #102) — the
51
+ // whole reason an agent lists connections is to feed one into `query`.
52
+ // stderr — guidance, not data; only in the human path (respondList gates it).
53
+ printUsageFooter(records) {
54
+ const first = records.find((record) => {
55
+ const candidate = record;
56
+ return typeof candidate?.id === 'string' && candidate.active !== false;
57
+ });
58
+ if (first === undefined) {
59
+ // All-inactive is exactly when the reader is about to be confused:
60
+ // `query` will refuse every one of these ids.
61
+ if (records.length > 0) {
62
+ this.footer('\nNo ACTIVE connection in these results — query refuses an inactive connection.');
63
+ }
64
+ return;
65
+ }
66
+ // The id is a server-supplied string — footer() redacts + sanitizes it.
67
+ this.footer(`\nTry: ${this.config.bin} query --source <source> --connection-id ${first.id} -d <dim> -m <metric> --json\n` +
68
+ ` (${this.config.bin} catalog lists the sources and their names)`);
43
69
  }
44
70
  }
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../lib/command/base.js';
2
+ export default class Contract extends BaseCommand<typeof Contract> {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {};
6
+ static summary: string;
7
+ run(): Promise<{
8
+ contractVersion: string;
9
+ markdown: string;
10
+ }>;
11
+ }
@@ -0,0 +1,35 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { BaseCommand } from '../lib/command/base.js';
5
+ import { CONTRACT_VERSION } from '../lib/config/constants.js';
6
+ import { CliError } from '../lib/errors.js';
7
+ import { ExitCode } from '../lib/exit-codes.js';
8
+ // <package root>/docs/AGENT-CONTRACT.md, resolved relative to this module so it
9
+ // works from dist in the published tarball and from src in dev.
10
+ function contractPath() {
11
+ const here = dirname(fileURLToPath(import.meta.url));
12
+ return join(here, '..', '..', 'docs', 'AGENT-CONTRACT.md');
13
+ }
14
+ export default class Contract extends BaseCommand {
15
+ static description = 'Print docs/AGENT-CONTRACT.md — the frozen machine contract (output modes, exit codes, error envelope, ' +
16
+ 'per-command JSON shapes) — to stdout, from the installed package, no network needed. Context self-service ' +
17
+ 'for agents: read this before driving the CLI programmatically.';
18
+ static examples = ['<%= config.bin %> contract', '<%= config.bin %> contract --json'];
19
+ static flags = {};
20
+ static summary = 'Print the agent contract (machine-facing promises) to stdout.';
21
+ async run() {
22
+ let markdown;
23
+ try {
24
+ markdown = readFileSync(contractPath(), 'utf8');
25
+ }
26
+ catch {
27
+ // Never a raw ENOENT: the class name is not a contract code, and the
28
+ // absolute path (with the OS username) does not belong on stdout.
29
+ throw new CliError('The packaged agent contract is missing from this installation.', 'contract_unavailable', ExitCode.GENERIC).withDetails({ hint: 'Reinstall the CLI: npm i -g flipstream', retryable: false });
30
+ }
31
+ // The document IS the data here, so human mode prints it verbatim on
32
+ // stdout; --json wraps it with the version for programmatic consumers.
33
+ return this.respond({ contractVersion: CONTRACT_VERSION, markdown }, () => this.log(markdown));
34
+ }
35
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseCommand } from '../lib/command/base.js';
2
+ export default class Health extends BaseCommand<typeof Health> {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ };
8
+ static summary: string;
9
+ run(): Promise<unknown>;
10
+ }
@@ -0,0 +1,31 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { mapDataError } from '../lib/api/errors.js';
3
+ import { BaseCommand } from '../lib/command/base.js';
4
+ import { resolvePlannerUrl } from '../lib/config/xdg.js';
5
+ import { getPlannerHealth } from '../lib/planner/client.js';
6
+ export default class Health extends BaseCommand {
7
+ static description = 'Check that the query planner is answering. This is the ONE endpoint that takes no token, so it separates ' +
8
+ '"the service is down" from "my credentials are wrong" before any auth debugging starts.';
9
+ static examples = [
10
+ '<%= config.bin %> health',
11
+ '<%= config.bin %> health --json',
12
+ '<%= config.bin %> health --url http://localhost:8080',
13
+ ];
14
+ static flags = {
15
+ url: Flags.string({
16
+ description: 'Query-planner base URL (default: the prod planner; env FLIPSTREAM_PLANNER_URL).',
17
+ }),
18
+ };
19
+ static summary = 'Check that the query planner is reachable.';
20
+ async run() {
21
+ const url = resolvePlannerUrl({ urlFlag: this.flags.url });
22
+ let payload;
23
+ try {
24
+ payload = await getPlannerHealth(url, { timeoutMs: this.flags.timeout });
25
+ }
26
+ catch (error) {
27
+ throw mapDataError(error);
28
+ }
29
+ return this.respond(payload, (data) => this.log(JSON.stringify(data, null, 2)));
30
+ }
31
+ }
@@ -8,7 +8,7 @@ import { createStore } from '../../lib/store/index.js';
8
8
  export default class LogAdd extends BaseCommand {
9
9
  static aliases = ['logs:add'];
10
10
  static args = {
11
- message: Args.string({ description: 'The log entry text.', required: true }),
11
+ message: Args.string({ description: 'The log entry text.', ignoreStdin: true, required: true }),
12
12
  };
13
13
  static description = "Add an entry to a workspace's log (the logbook). You give the workspace (--workspace/--ws) and the message; the " +
14
14
  'organization is derived from the workspace, and the dates default to now (override with --start/--end). ' +
@@ -20,7 +20,11 @@ export default class LogAdd extends BaseCommand {
20
20
  static flags = {
21
21
  end: Flags.string({ description: 'End date (ISO 8601). Defaults to now.' }),
22
22
  start: Flags.string({ description: 'Start date (ISO 8601). Defaults to now.' }),
23
- workspace: Flags.string({ aliases: ['ws'], description: 'Workspace id (UUID) the entry belongs to.', required: true }),
23
+ workspace: Flags.string({
24
+ aliases: ['ws'],
25
+ description: 'Workspace id (UUID) the entry belongs to.',
26
+ required: true,
27
+ }),
24
28
  };
25
29
  static summary = "Add an entry to a workspace's log.";
26
30
  async run() {
@@ -3,11 +3,24 @@ export default class Query extends BaseCommand<typeof Query> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
- 'auth-host': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
6
  body: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
7
  'body-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'connection-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ dimension: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ filter: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ metric: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ offset: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ rows: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ sort: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ source: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ table: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'auth-host': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
20
  };
10
21
  static summary: string;
11
22
  run(): Promise<unknown>;
12
- private parseBody;
23
+ private engineFailureDetails;
24
+ private enrichPlannerError;
25
+ private readVerbatimBody;
13
26
  }