@ora-ai/cli 0.21.0 → 0.23.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 (108) hide show
  1. package/README.md +96 -1
  2. package/dist/auth-commands.d.ts.map +1 -1
  3. package/dist/auth-commands.js +12 -1
  4. package/dist/auth-commands.js.map +1 -1
  5. package/dist/core/auth.d.ts +24 -13
  6. package/dist/core/auth.d.ts.map +1 -1
  7. package/dist/core/auth.js +26 -15
  8. package/dist/core/auth.js.map +1 -1
  9. package/dist/core/credential-sources.d.ts +45 -0
  10. package/dist/core/credential-sources.d.ts.map +1 -0
  11. package/dist/core/credential-sources.js +65 -0
  12. package/dist/core/credential-sources.js.map +1 -0
  13. package/dist/core/github-actions-sign-in.d.ts +33 -0
  14. package/dist/core/github-actions-sign-in.d.ts.map +1 -0
  15. package/dist/core/github-actions-sign-in.js +54 -0
  16. package/dist/core/github-actions-sign-in.js.map +1 -0
  17. package/dist/core/output.js +14 -1
  18. package/dist/core/output.js.map +1 -1
  19. package/dist/core/run-operation.d.ts +11 -4
  20. package/dist/core/run-operation.d.ts.map +1 -1
  21. package/dist/core/run-operation.js +14 -9
  22. package/dist/core/run-operation.js.map +1 -1
  23. package/dist/core/sign-in.d.ts +34 -0
  24. package/dist/core/sign-in.d.ts.map +1 -0
  25. package/dist/core/sign-in.js +21 -0
  26. package/dist/core/sign-in.js.map +1 -0
  27. package/dist/generated/operations.d.ts +1 -1
  28. package/dist/generated/operations.d.ts.map +1 -1
  29. package/dist/generated/operations.js +1274 -73
  30. package/dist/generated/operations.js.map +1 -1
  31. package/dist/generated/types.d.ts +1445 -10
  32. package/dist/generated/types.d.ts.map +1 -1
  33. package/dist/generated/types.js +1 -1
  34. package/dist/mcp/mcp-call.d.ts +25 -0
  35. package/dist/mcp/mcp-call.d.ts.map +1 -0
  36. package/dist/mcp/mcp-call.js +44 -0
  37. package/dist/mcp/mcp-call.js.map +1 -0
  38. package/dist/mcp/mcp-command.d.ts +26 -0
  39. package/dist/mcp/mcp-command.d.ts.map +1 -0
  40. package/dist/mcp/mcp-command.js +91 -0
  41. package/dist/mcp/mcp-command.js.map +1 -0
  42. package/dist/mcp/mcp-install.d.ts +50 -0
  43. package/dist/mcp/mcp-install.d.ts.map +1 -0
  44. package/dist/mcp/mcp-install.js +71 -0
  45. package/dist/mcp/mcp-install.js.map +1 -0
  46. package/dist/mcp/mcp-protocol.d.ts +69 -0
  47. package/dist/mcp/mcp-protocol.d.ts.map +1 -0
  48. package/dist/mcp/mcp-protocol.js +96 -0
  49. package/dist/mcp/mcp-protocol.js.map +1 -0
  50. package/dist/mcp/mcp-stdio.d.ts +17 -0
  51. package/dist/mcp/mcp-stdio.d.ts.map +1 -0
  52. package/dist/mcp/mcp-stdio.js +39 -0
  53. package/dist/mcp/mcp-stdio.js.map +1 -0
  54. package/dist/mcp/mcp-tools.d.ts +81 -0
  55. package/dist/mcp/mcp-tools.d.ts.map +1 -0
  56. package/dist/mcp/mcp-tools.js +134 -0
  57. package/dist/mcp/mcp-tools.js.map +1 -0
  58. package/dist/program.d.ts +4 -9
  59. package/dist/program.d.ts.map +1 -1
  60. package/dist/program.js +9 -3
  61. package/dist/program.js.map +1 -1
  62. package/dist/render/index.js +6 -0
  63. package/dist/render/index.js.map +1 -1
  64. package/dist/render/study/counting-views.d.ts +46 -0
  65. package/dist/render/study/counting-views.d.ts.map +1 -0
  66. package/dist/render/study/counting-views.js +49 -0
  67. package/dist/render/study/counting-views.js.map +1 -0
  68. package/dist/render/study/gate-views.d.ts +56 -0
  69. package/dist/render/study/gate-views.d.ts.map +1 -0
  70. package/dist/render/study/gate-views.js +64 -0
  71. package/dist/render/study/gate-views.js.map +1 -0
  72. package/dist/render/study/renderers.d.ts +8 -0
  73. package/dist/render/study/renderers.d.ts.map +1 -0
  74. package/dist/render/study/renderers.js +31 -0
  75. package/dist/render/study/renderers.js.map +1 -0
  76. package/dist/render/study/series-views.d.ts +65 -0
  77. package/dist/render/study/series-views.d.ts.map +1 -0
  78. package/dist/render/study/series-views.js +116 -0
  79. package/dist/render/study/series-views.js.map +1 -0
  80. package/dist/render/study/study-format.d.ts +24 -0
  81. package/dist/render/study/study-format.d.ts.map +1 -0
  82. package/dist/render/study/study-format.js +42 -0
  83. package/dist/render/study/study-format.js.map +1 -0
  84. package/dist/study-ci/ci-command.d.ts +40 -0
  85. package/dist/study-ci/ci-command.d.ts.map +1 -0
  86. package/dist/study-ci/ci-command.js +151 -0
  87. package/dist/study-ci/ci-command.js.map +1 -0
  88. package/dist/study-ci/ci-rehearse-command.d.ts +11 -0
  89. package/dist/study-ci/ci-rehearse-command.d.ts.map +1 -0
  90. package/dist/study-ci/ci-rehearse-command.js +83 -0
  91. package/dist/study-ci/ci-rehearse-command.js.map +1 -0
  92. package/dist/study-ci/ci-rehearse.d.ts +62 -0
  93. package/dist/study-ci/ci-rehearse.d.ts.map +1 -0
  94. package/dist/study-ci/ci-rehearse.js +49 -0
  95. package/dist/study-ci/ci-rehearse.js.map +1 -0
  96. package/dist/study-ci/ci-run.d.ts +87 -0
  97. package/dist/study-ci/ci-run.d.ts.map +1 -0
  98. package/dist/study-ci/ci-run.js +131 -0
  99. package/dist/study-ci/ci-run.js.map +1 -0
  100. package/dist/study-ci/gate-report.d.ts +64 -0
  101. package/dist/study-ci/gate-report.d.ts.map +1 -0
  102. package/dist/study-ci/gate-report.js +80 -0
  103. package/dist/study-ci/gate-report.js.map +1 -0
  104. package/dist/study-ci/params.d.ts +8 -0
  105. package/dist/study-ci/params.d.ts.map +1 -0
  106. package/dist/study-ci/params.js +72 -0
  107. package/dist/study-ci/params.js.map +1 -0
  108. package/package.json +1 -1
package/README.md CHANGED
@@ -40,6 +40,36 @@ key is stored at `~/.config/ora/config.json` (0600) and exchanged for a
40
40
  short-lived token on every call — the key itself never travels beyond the
41
41
  token exchange.
42
42
 
43
+ ### Keyless sign-in from GitHub Actions
44
+
45
+ A job can sign in with no ora secret stored in the repository. Trust the repository on an api key
46
+ (Settings → API keys → CI sign-in), then give the job an identity token and the key's ID:
47
+
48
+ permissions:
49
+ id-token: write
50
+ steps:
51
+ - uses: ./.github/actions/ora-study-gate # hands the CLI the job's identity token
52
+ with:
53
+ api-key-id: 1b0f6a2c-… # the key's ID. Not a secret
54
+
55
+ The job signs in **as that key**: its scopes, its expiry, its revocation. `ora whoami` prints a
56
+ `via:` line naming the repository and ref that signed in.
57
+
58
+ Running the CLI from your own step instead: set `ORA_API_KEY_ID`, and pass
59
+ `ACTIONS_ID_TOKEN_REQUEST_URL` and `ACTIONS_ID_TOKEN_REQUEST_TOKEN` to the step (read them in an
60
+ `actions/github-script` step; a shell step may not see them). The identity token is requested for
61
+ the API origin the CLI is pointed at; `ORA_CI_AUDIENCE` overrides that.
62
+
63
+ Which credential is used, first match wins: `ORA_API_KEY`, then `ORA_API_KEY_ID` in a job that can
64
+ request its identity token, then the key `ora login` stored. If `ORA_API_KEY_ID` is set and the
65
+ job has no identity token, the CLI stops and says so. It never falls back to a stored key.
66
+
67
+ | Refusal | Meaning |
68
+ | --- | --- |
69
+ | `CI_NOT_TRUSTED` | No trust of the key admits this job: check the repository, the ref (`refs/pull/*/merge` for pull requests) and the environment |
70
+ | `CI_TOKEN_INVALID` | The identity token did not verify, or was requested for another audience |
71
+ | `CI_IDENTITY_UNAVAILABLE` | GitHub issued the job no identity token: add `permissions: id-token: write` |
72
+
43
73
  ### Point the CLI at an environment (`--api-url`)
44
74
 
45
75
  By default the CLI talks to the URL embedded in its spec
@@ -193,6 +223,30 @@ read the results, improve, schedule, with a recipe per objective (be recommended
193
223
  away, book a demo, MCP discovery, MCP usage). It comes from your Studio account, so it needs the same
194
224
  API key as the other commands (scope `intents:read`).
195
225
 
226
+ ### MCP — give your coding agent the CLI's commands as tools
227
+
228
+ ora mcp install --product study # this project, for Claude Code (.mcp.json)
229
+ ora mcp install --agent cursor --product study # Cursor (.cursor/mcp.json)
230
+ ora mcp config --product study --read-only # print the entry, for any other agent
231
+ ora mcp serve --product study # what the agent runs: an MCP server on stdio
232
+
233
+ `ora mcp serve` is the CLI served over the Model Context Protocol. Every tool is a command: `study_get`
234
+ runs `ora study get <id>`, takes the same parameters (a JSON body goes in `body`) and answers the API's
235
+ JSON. There is no second list: a command added to the CLI is a tool the next time the server starts.
236
+
237
+ - `--product <key>` (repeatable) serves one product's commands: `study`, `studio`, `experiment` or
238
+ `platform`. Without it the server offers every command, which is a long tool list for an agent.
239
+ - `--read-only` serves only the commands that read. A read sent as a POST (a study's run query) stays.
240
+ - **The API key still decides what any call may do.** The server never widens it. Give the agent a key
241
+ with the scopes you want it to have.
242
+ - A refusal reaches the agent as a tool error with the API's own status, code and words, so it can fix
243
+ the call. A write is never retried.
244
+ - The server uses the key the CLI already has (`ora login`, or `ORA_API_KEY` in the agent's
245
+ environment). `install` writes the command and its flags into the agent's configuration, and never a key.
246
+ It merges into an existing file and leaves every other server in it alone.
247
+ - Commands that stream (`… stream`) are not offered: a tool call answers once.
248
+ - An answer over 200,000 characters is refused with its size, not cut in half: ask a narrower command.
249
+
196
250
  ### Sessions — long-lived agent environments
197
251
 
198
252
  ora sessions catalog # harnesses + models you can launch
@@ -233,6 +287,46 @@ leaderboard); two or more groups are compared.
233
287
  ora study publish <id> --file publish.json # {"slug": "my-study", "visibility": "public", "skillNames": "withheld"}
234
288
  ora study update-details <id> --file details.json # rename or re-describe it, any time
235
289
 
290
+ **Before you spend.** Prove a design on its smallest real run first:
291
+
292
+ ora study rehearse --file study.json # one real run per group; same body as create
293
+ ora study rehearsal-report <id> # what it proved, group by group
294
+ ora study ci rehearse --file study.json --mode setup # wait for the answer; setup / mock start no agent
295
+
296
+ **A study as a merge check.** A gate answers pass, fail, or "not enough runs
297
+ to decide", against a floor or against an earlier study of the same series:
298
+
299
+ ora study gate <id> --file gate.json # {"maxDrop": {"pp": 10}, "baseline": {"series": {"branch": "main"}}}
300
+ ora study ci run --file study.json --gate gate.json --series cli/pr-gate
301
+ # create, launch, wait, answer: exit 0 pass, 1 fail, 2 undecided
302
+ ora study series # the organization's series
303
+ ora study series-trend --series cli/pr-gate # one series over time, split where it stopped being comparable
304
+ ora study carry-plan <id> # what a series study would carry instead of run, and why the rest runs
305
+ ora study set-carry <id> --file carry.json # turn carrying on or off before launch: {"carry": null} runs every job
306
+ ora study ci run … --no-carry # this one study runs every job, whatever its body file says
307
+
308
+ A study that declares `"carry": {"from": "series"}` takes the runs of its
309
+ unchanged jobs from the series' previous study instead of running them again.
310
+ Whether it does is yours to change until the study launches.
311
+
312
+ **Reading the runs.**
313
+
314
+ ora study query <id> --file query.json # which runs, split how, measured on what
315
+ ora study query-vocabulary <id> # what its runs can be split by and measured on
316
+ ora study save-view <id> --file view.json # keep a question; `views`, `run-view`, `delete-view`
317
+ ora study behaviors <id> # the study's own questions about each run, and how they held up
318
+ ora study run-screens <id> <runId> # whether a run is valid evidence, with the quotes it stands on
319
+ ora study run-spans <id> <runId> # the run's stored spans
320
+ ora study run-delivered <id> <runId> # the files and images the run delivered
321
+
322
+ **After it finished.**
323
+
324
+ ora study revise-grading <id> --file revision.json # change a finished study's checks, with a reason; re-grades
325
+ ora study grading-revisions <id> # the record of every revision
326
+ ora study retest <id> --file retest.json # run the benchmark's own checker again over the files runs saved
327
+ ora study retests <id> # what every re-check found
328
+ ora study rerun-infra-failures <id> # re-run, in place, the jobs ora's own infrastructure failed
329
+
236
330
  **Scopes**: `study.studies:read` / `study.studies:write`, plus `study.addons:read`
237
331
  for the add-on catalog.
238
332
 
@@ -359,7 +453,8 @@ refused key exchange) prints `{error, code}`:
359
453
 
360
454
  ora experiment runs list --json | jq '.results[] | {id, harness, status}'
361
455
 
362
- In CI, export `ORA_API_KEY` instead of logging in. Point at another
456
+ In CI, export `ORA_API_KEY` instead of logging in, or sign in with no stored secret
457
+ ([keyless sign-in](#keyless-sign-in-from-github-actions)). Point at another
363
458
  environment with `ORA_API_URL` or `--api-url`.
364
459
 
365
460
  Studio views are drawn in Ora cream on a dark terminal and in Ora ink on a light one, read from
@@ -1 +1 @@
1
- {"version":3,"file":"auth-commands.d.ts","sourceRoot":"","sources":["../src/auth-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BnH;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAyBvH;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAWtE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CASvE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAUvE"}
1
+ {"version":3,"file":"auth-commands.d.ts","sourceRoot":"","sources":["../src/auth-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BnH;AAUD;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BvH;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAWtE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CASvE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAUvE"}
@@ -12,6 +12,7 @@ import { clearCredentials, readConfig, resolveApiUrl, writeConfig } from "./core
12
12
  import { promptForKey } from "./core/login.js";
13
13
  import { renderError } from "./core/output.js";
14
14
  import { credentials } from "./core/run-operation.js";
15
+ import { apiKeySignIn } from "./core/sign-in.js";
15
16
  import { SPEC } from "./generated/operations.js";
16
17
  /**
17
18
  * The login core: validate the `ora_sk_` prefix → store → verify by
@@ -34,7 +35,7 @@ export async function performLogin(deps, opts) {
34
35
  deps.out(`Verifying against ${apiUrl}`);
35
36
  writeConfig({ ...previous, apiKey: key, ...(opts.apiUrl ? { apiUrl } : {}) }, deps.dir);
36
37
  try {
37
- const token = await deps.makeAuth({ apiUrl, apiKey: key }).forceRefresh();
38
+ const token = await deps.makeAuth({ apiUrl, signIn: apiKeySignIn(key) }).forceRefresh();
38
39
  const claims = decodeClaims(token);
39
40
  deps.out(`Logged in. org=${String(claims.org ?? claims.organizationId ?? "?")} subject=${String(claims.sub ?? "?")}`);
40
41
  return true;
@@ -46,6 +47,15 @@ export async function performLogin(deps, opts) {
46
47
  return false;
47
48
  }
48
49
  }
50
+ /** Which CI job signed in, when the token was minted for one (keyless sign-in). Display only. */
51
+ function federationLine(federation) {
52
+ if (!federation || typeof federation !== "object")
53
+ return [];
54
+ const { issuer, repository, ref } = federation;
55
+ if (typeof repository !== "string")
56
+ return [];
57
+ return [`via: ${[issuer, repository, ref].filter((part) => typeof part === "string").join(" ")} (keyless CI sign-in)`];
58
+ }
49
59
  /**
50
60
  * The whoami core: verify the configured key and print its identity. THE one
51
61
  * implementation — shared verbatim by the scripted `whoami` action and the
@@ -71,6 +81,7 @@ export async function performWhoami(deps, opts) {
71
81
  `org: ${String(claims.org ?? claims.organizationId ?? "?")}`,
72
82
  `subject: ${String(claims.sub ?? "?")}`,
73
83
  ...(Array.isArray(claims.scopes) ? [`scopes: ${claims.scopes.join(", ")}`] : []),
84
+ ...federationLine(claims.federation),
74
85
  `api: ${creds.apiUrl}`,
75
86
  ].join("\n"));
76
87
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"auth-commands.js","sourceRoot":"","sources":["../src/auth-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAGjD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAkB,EAAE,IAA0C;IAC/F,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,w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O;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,4CAA4C,CAAC;SACzD,WAAW,CAAC,OAAO,EAAE,2BAA2B,CAAC;SACjD,MAAM,CAAC,GAAG,EAAE;QACX,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,IAAkB;IAC/D,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,kEAAkE,CAAC;SAC/E,MAAM,CAAC,QAAQ,EAAE,4BAA4B,CAAC;SAC9C,MAAM,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;SACtD,WAAW,CAAC,OAAO,EAAE,gDAAgD,CAAC;SACtE,MAAM,CAAC,KAAK,EAAE,IAAyC,EAAE,EAAE;QAC1D,MAAM,aAAa,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1,34 +1,38 @@
1
1
  /**
2
- * Api-key → short-lived token exchange.
2
+ * Credential → short-lived token exchange.
3
3
  *
4
- * The credential travels ONLY as "Authorization: Bearer <ora_sk_…>" to
5
- * POST /auth/token (the doc's own rule: never in the request body). The
6
- * response {token, expiresIn} is cached on disk (0600) and reused until a 30s
7
- * skew before expiry, so a token can't die between "checked" and "used".
4
+ * WHAT is presented is a {@link SignIn}'s (sign-in.ts): an api key's secret,
5
+ * or a CI job's identity token. Either way the credential travels ONLY as
6
+ * "Authorization: Bearer <credential>" to POST /auth/token (the doc's own
7
+ * rule: never in the request body). The response {token, expiresIn} is cached
8
+ * on disk (0600) and reused until a 30s skew before expiry, so a token can't
9
+ * die between "checked" and "used".
8
10
  *
9
- * The cache is keyed to (apiUrl, sha256(key)) — pointing the CLI at staging or
10
- * switching keys can never replay a token minted elsewhere. Cache write
11
- * failures are swallowed: a cache is an optimization, not a requirement.
11
+ * The cache is keyed to (apiUrl, the sign-in's cache key) — pointing the CLI
12
+ * at staging or switching credentials can never replay a token minted
13
+ * elsewhere. Cache write failures are swallowed: a cache is an optimization,
14
+ * not a requirement.
12
15
  */
16
+ import { type SignIn } from "./sign-in.js";
13
17
  export declare class AuthError extends Error {
14
18
  readonly status: number;
15
19
  readonly code: string;
16
20
  constructor(message: string, status: number, code: string);
17
21
  }
18
- export interface ApiKeyAuthDeps {
22
+ export interface TokenExchangeAuthDeps {
19
23
  apiUrl: string;
20
- apiKey: string;
24
+ signIn: SignIn;
21
25
  dir?: string;
22
26
  fetchFn?: typeof fetch;
23
27
  now?: () => number;
24
28
  }
25
- export declare class ApiKeyAuth {
29
+ export declare class TokenExchangeAuth {
26
30
  private readonly apiUrl;
27
- private readonly apiKey;
31
+ private readonly signIn;
28
32
  private readonly dir;
29
33
  private readonly fetchFn;
30
34
  private readonly now;
31
- constructor(deps: ApiKeyAuthDeps);
35
+ constructor(deps: TokenExchangeAuthDeps);
32
36
  getToken(): Promise<string>;
33
37
  forceRefresh(): Promise<string>;
34
38
  clearCache(): void;
@@ -36,6 +40,13 @@ export declare class ApiKeyAuth {
36
40
  private keyDigest;
37
41
  private readCache;
38
42
  }
43
+ export interface ApiKeyAuthDeps extends Omit<TokenExchangeAuthDeps, "signIn"> {
44
+ apiKey: string;
45
+ }
46
+ /** The exchange for an api key's own secret: {@link TokenExchangeAuth} over {@link apiKeySignIn}. */
47
+ export declare class ApiKeyAuth extends TokenExchangeAuth {
48
+ constructor({ apiKey, ...deps }: ApiKeyAuthDeps);
49
+ }
39
50
  /** JWT payload claims, {} on anything unparseable. Display only — never trust. */
40
51
  export declare function decodeClaims(token: string): Record<string, unknown>;
41
52
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","s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token exchange.
3
3
  *
4
- * The credential travels ONLY as "Authorization: Bearer <ora_sk_…>" to
5
- * POST /auth/token (the doc's own rule: never in the request body). The
6
- * response {token, expiresIn} is cached on disk (0600) and reused until a 30s
7
- * skew before expiry, so a token can't die between "checked" and "used".
4
+ * WHAT is presented is a {@link SignIn}'s (sign-in.ts): an api key's secret,
5
+ * or a CI job's identity token. Either way the credential travels ONLY as
6
+ * "Authorization: Bearer <credential>" to POST /auth/token (the doc's own
7
+ * rule: never in the request body). The response {token, expiresIn} is cached
8
+ * on disk (0600) and reused until a 30s skew before expiry, so a token can't
9
+ * die between "checked" and "used".
8
10
  *
9
- * The cache is keyed to (apiUrl, sha256(key)) — pointing the CLI at staging or
10
- * switching keys can never replay a token minted elsewhere. Cache write
11
- * failures are swallowed: a cache is an optimization, not a requirement.
11
+ * The cache is keyed to (apiUrl, the sign-in's cache key) — pointing the CLI
12
+ * at staging or switching credentials can never replay a token minted
13
+ * elsewhere. Cache write failures are swallowed: a cache is an optimization,
14
+ * not a requirement.
12
15
  */
13
- import { createHash } from "node:crypto";
14
16
  import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
15
17
  import { join } from "node:path";
16
18
  import { configDir } from "./config.js";
19
+ import { apiKeySignIn } from "./sign-in.js";
17
20
  const EXPIRY_SKEW_MS = 30_000;
18
21
  const DEFAULT_EXPIRES_IN_S = 900;
19
22
  export class AuthError extends Error {
@@ -26,15 +29,15 @@ export class AuthError extends Error {
26
29
  this.name = "AuthError";
27
30
  }
28
31
  }
29
- export class ApiKeyAuth {
32
+ export class TokenExchangeAuth {
30
33
  apiUrl;
31
- apiKey;
34
+ signIn;
32
35
  dir;
33
36
  fetchFn;
34
37
  now;
35
38
  constructor(deps) {
36
39
  this.apiUrl = deps.apiUrl;
37
- this.apiKey = deps.apiKey;
40
+ this.signIn = deps.signIn;
38
41
  this.dir = deps.dir ?? configDir();
39
42
  this.fetchFn = deps.fetchFn ?? fetch;
40
43
  this.now = deps.now ?? Date.now;
@@ -46,10 +49,12 @@ export class ApiKeyAuth {
46
49
  return this.forceRefresh();
47
50
  }
48
51
  async forceRefresh() {
52
+ // Made fresh for every exchange: a CI job's identity token is accepted once.
53
+ const presented = await this.signIn.present();
49
54
  const res = await this.fetchFn(`${this.apiUrl}/auth/token`, {
50
55
  method: "POST",
51
- headers: { authorization: `Bearer ${this.apiKey}`, "content-type": "application/json" },
52
- body: "{}",
56
+ headers: { authorization: `Bearer ${presented.bearer}`, "content-type": "application/json" },
57
+ body: JSON.stringify(presented.body),
53
58
  });
54
59
  const body = (await res.json().catch(() => ({})));
55
60
  if (!res.ok || typeof body.token !== "string") {
@@ -79,7 +84,7 @@ export class ApiKeyAuth {
79
84
  return join(this.dir, "token.json");
80
85
  }
81
86
  keyDigest() {
82
- return createHash("sha256").update(this.apiKey).digest("hex").slice(0, 16);
87
+ return this.signIn.cacheKey;
83
88
  }
84
89
  readCache() {
85
90
  try {
@@ -95,6 +100,12 @@ export class ApiKeyAuth {
95
100
  }
96
101
  }
97
102
  }
103
+ /** The exchange for an api key's own secret: {@link TokenExchangeAuth} over {@link apiKeySignIn}. */
104
+ export class ApiKeyAuth extends TokenExchangeAuth {
105
+ constructor({ apiKey, ...deps }) {
106
+ super({ ...deps, signIn: apiKeySignIn(apiKey) });
107
+ }
108
+ }
98
109
  /** JWT payload claims, {} on anything unparseable. Display only — never trust. */
99
110
  export function decodeClaims(token) {
100
111
  const payload = token.split(".")[1];
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/core/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE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,QAAQ,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAC;YAC1F,OAAO,MAAqB,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAMD,qGAAqG;AACrG,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAC/C,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,EAAkB;QAC7C,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAA4B,CAAC;IACnG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * WHERE THE CLI'S CREDENTIAL COMES FROM — an ordered registry of sources
3
+ * (Strategy + Registry). The first source that has something to say decides.
4
+ *
5
+ * THE ORDER, and why:
6
+ * 1. `ORA_API_KEY` in the environment: the most explicit thing a person or a
7
+ * job can say;
8
+ * 2. keyless CI sign-in (`ORA_API_KEY_ID` in a job that can request its
9
+ * identity token): chosen by naming a key id, with no secret anywhere;
10
+ * 3. the key `ora login` stored on this machine.
11
+ *
12
+ * A SOURCE THAT WAS ASKED FOR AND CANNOT WORK SAYS SO. A job that sets
13
+ * `ORA_API_KEY_ID` but has no identity token gets that told to it, by name.
14
+ * It never falls through to a stored key: signing in as something other than
15
+ * what was asked for is the failure to avoid.
16
+ *
17
+ * Adding a source (another CI system, a keychain) is one entry here.
18
+ */
19
+ import type { OraConfig } from "./config.js";
20
+ import { type SignIn } from "./sign-in.js";
21
+ export interface CredentialContext {
22
+ cfg: OraConfig;
23
+ env: NodeJS.ProcessEnv;
24
+ /** The API origin the CLI is pointed at. */
25
+ apiUrl: string;
26
+ fetchFn?: typeof fetch;
27
+ }
28
+ /** What a source says: a way to sign in, a reason it was asked for and cannot work, or nothing (null). */
29
+ export type CredentialResolution = {
30
+ signIn: SignIn;
31
+ } | {
32
+ problem: string;
33
+ } | null;
34
+ export interface CredentialSource {
35
+ readonly id: string;
36
+ resolve(ctx: CredentialContext): CredentialResolution;
37
+ }
38
+ /** The variable that names the api key a CI job signs in as. Its value is an id, not a secret. */
39
+ export declare const API_KEY_ID_ENV = "ORA_API_KEY_ID";
40
+ /** Overrides the audience a CI identity token is requested for (default: the API origin). */
41
+ export declare const CI_AUDIENCE_ENV = "ORA_CI_AUDIENCE";
42
+ export declare const CREDENTIAL_SOURCES: readonly CredentialSource[];
43
+ /** The first source with something to say decides; null when none has. */
44
+ export declare function resolveSignIn(ctx: CredentialContext, sources?: readonly CredentialSource[]): CredentialResolution;
45
+ //# sourceMappingURL=credential-sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-sources.d.ts","sourceRoot":"","sources":["../../src/core/credential-sources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAC;IACf,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAED,0GAA0G;AAC1G,MAAM,MAAM,oBAAoB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAEnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,oBAAoB,CAAC;CACvD;AAED,kGAAkG;AAClG,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,6FAA6F;AAC7F,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAoCjD,eAAO,MAAM,kBAAkB,EAAE,SAAS,gBAAgB,EAAoD,CAAC;AAE/G,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,GAAG,EAAE,iBAAiB,EAAE,OAAO,GAAE,SAAS,gBAAgB,EAAuB,GAAG,oBAAoB,CAMrI"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * WHERE THE CLI'S CREDENTIAL COMES FROM — an ordered registry of sources
3
+ * (Strategy + Registry). The first source that has something to say decides.
4
+ *
5
+ * THE ORDER, and why:
6
+ * 1. `ORA_API_KEY` in the environment: the most explicit thing a person or a
7
+ * job can say;
8
+ * 2. keyless CI sign-in (`ORA_API_KEY_ID` in a job that can request its
9
+ * identity token): chosen by naming a key id, with no secret anywhere;
10
+ * 3. the key `ora login` stored on this machine.
11
+ *
12
+ * A SOURCE THAT WAS ASKED FOR AND CANNOT WORK SAYS SO. A job that sets
13
+ * `ORA_API_KEY_ID` but has no identity token gets that told to it, by name.
14
+ * It never falls through to a stored key: signing in as something other than
15
+ * what was asked for is the failure to avoid.
16
+ *
17
+ * Adding a source (another CI system, a keychain) is one entry here.
18
+ */
19
+ import { GITHUB_ID_TOKEN_REQUEST_TOKEN, GITHUB_ID_TOKEN_REQUEST_URL, githubActionsSignIn } from "./github-actions-sign-in.js";
20
+ import { apiKeySignIn } from "./sign-in.js";
21
+ /** The variable that names the api key a CI job signs in as. Its value is an id, not a secret. */
22
+ export const API_KEY_ID_ENV = "ORA_API_KEY_ID";
23
+ /** Overrides the audience a CI identity token is requested for (default: the API origin). */
24
+ export const CI_AUDIENCE_ENV = "ORA_CI_AUDIENCE";
25
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
26
+ const envApiKey = {
27
+ id: "env_api_key",
28
+ resolve: ({ env }) => (env.ORA_API_KEY ? { signIn: apiKeySignIn(env.ORA_API_KEY) } : null),
29
+ };
30
+ const githubActionsKeyless = {
31
+ id: "github_actions_keyless",
32
+ resolve({ env, apiUrl, fetchFn }) {
33
+ const apiKeyId = env[API_KEY_ID_ENV]?.trim();
34
+ if (!apiKeyId)
35
+ return null;
36
+ if (!UUID.test(apiKeyId)) {
37
+ return { problem: `${API_KEY_ID_ENV} is not an api key id. It is the key's ID (a UUID, shown beside the key in Settings, API keys), not the ora_sk_ secret.` };
38
+ }
39
+ const requestUrl = env[GITHUB_ID_TOKEN_REQUEST_URL];
40
+ const requestToken = env[GITHUB_ID_TOKEN_REQUEST_TOKEN];
41
+ if (!requestUrl || !requestToken) {
42
+ return {
43
+ problem: `${API_KEY_ID_ENV} is set, but this job has no identity token to sign in with. ` +
44
+ "In GitHub Actions, give the job `permissions: id-token: write` and run the CLI through the ora study-gate action " +
45
+ `(or pass ${GITHUB_ID_TOKEN_REQUEST_URL} and ${GITHUB_ID_TOKEN_REQUEST_TOKEN} to the step). Anywhere else, set ORA_API_KEY.`,
46
+ };
47
+ }
48
+ return { signIn: githubActionsSignIn({ apiKeyId, audience: env[CI_AUDIENCE_ENV]?.trim() || apiUrl, requestUrl, requestToken, fetchFn }) };
49
+ },
50
+ };
51
+ const storedApiKey = {
52
+ id: "stored_api_key",
53
+ resolve: ({ cfg }) => (cfg.apiKey ? { signIn: apiKeySignIn(cfg.apiKey) } : null),
54
+ };
55
+ export const CREDENTIAL_SOURCES = [envApiKey, githubActionsKeyless, storedApiKey];
56
+ /** The first source with something to say decides; null when none has. */
57
+ export function resolveSignIn(ctx, sources = CREDENTIAL_SOURCES) {
58
+ for (const source of sources) {
59
+ const resolution = source.resolve(ctx);
60
+ if (resolution)
61
+ return resolution;
62
+ }
63
+ return null;
64
+ }
65
+ //# sourceMappingURL=credential-sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-sources.js","sourceRoot":"","sources":["../../src/core/credential-sources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,6BAA6B,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAC9H,OAAO,EAAE,YAAY,EAAe,MAAM,cAAc,CAAC;AAkBzD,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAC/C,6FAA6F;AAC7F,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAE/E,MAAM,SAAS,GAAqB;IAClC,EAAE,EAAE,aAAa;IACjB,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;CAC3F,CAAC;AAEF,MAAM,oBAAoB,GAAqB;IAC7C,EAAE,EAAE,wBAAwB;IAC5B,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE;QAC9B,MAAM,QAAQ,GAAG,GAAG,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,OAAO,EA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
2
+ * KEYLESS SIGN-IN FROM GITHUB ACTIONS — a job proves which repository it runs
3
+ * for with the short-lived identity token GitHub issues it, and signs in as
4
+ * the api key that trusts that repository. No ora secret is stored in GitHub.
5
+ *
6
+ * WHAT THE JOB NEEDS:
7
+ * - `permissions: id-token: write`, which makes GitHub offer the job an
8
+ * identity token through two variables (the request url and a bearer for
9
+ * it);
10
+ * - `ORA_API_KEY_ID`: the ID of the api key to sign in as. An id is not a
11
+ * secret. The key must trust the repository (Settings, API keys).
12
+ *
13
+ * A FRESH TOKEN PER EXCHANGE. ora accepts an identity token once, and GitHub's
14
+ * lasts minutes, while a study can run for an hour. So this asks GitHub for a
15
+ * new one every time the CLI exchanges, never keeping one.
16
+ *
17
+ * THE AUDIENCE is the ora API origin the CLI is pointed at: a token requested
18
+ * for one deployment is useless at another. `ORA_CI_AUDIENCE` overrides it for
19
+ * a deployment that names its audience differently.
20
+ */
21
+ import { type SignIn } from "./sign-in.js";
22
+ /** The two variables GitHub gives a job that may request its identity token. */
23
+ export declare const GITHUB_ID_TOKEN_REQUEST_URL = "ACTIONS_ID_TOKEN_REQUEST_URL";
24
+ export declare const GITHUB_ID_TOKEN_REQUEST_TOKEN = "ACTIONS_ID_TOKEN_REQUEST_TOKEN";
25
+ export interface GithubActionsSignInDeps {
26
+ apiKeyId: string;
27
+ audience: string;
28
+ requestUrl: string;
29
+ requestToken: string;
30
+ fetchFn?: typeof fetch;
31
+ }
32
+ export declare function githubActionsSignIn({ apiKeyId, audience, requestUrl, requestToken, fetchFn }: GithubActionsSignInDeps): SignIn;
33
+ //# sourceMappingURL=github-actions-sign-in.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-actions-sign-in.d.ts","sourceRoot":"","sources":["../../src/core/github-actions-sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAmB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAE5D,gFAAgF;AAChF,eAAO,MAAM,2BAA2B,iCAAiC,CAAC;AAC1E,eAAO,MAAM,6BAA6B,mCAAmC,CAAC;AAE9E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,OAAe,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAyBtI"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * KEYLESS SIGN-IN FROM GITHUB ACTIONS — a job proves which repository it runs
3
+ * for with the short-lived identity token GitHub issues it, and signs in as
4
+ * the api key that trusts that repository. No ora secret is stored in GitHub.
5
+ *
6
+ * WHAT THE JOB NEEDS:
7
+ * - `permissions: id-token: write`, which makes GitHub offer the job an
8
+ * identity token through two variables (the request url and a bearer for
9
+ * it);
10
+ * - `ORA_API_KEY_ID`: the ID of the api key to sign in as. An id is not a
11
+ * secret. The key must trust the repository (Settings, API keys).
12
+ *
13
+ * A FRESH TOKEN PER EXCHANGE. ora accepts an identity token once, and GitHub's
14
+ * lasts minutes, while a study can run for an hour. So this asks GitHub for a
15
+ * new one every time the CLI exchanges, never keeping one.
16
+ *
17
+ * THE AUDIENCE is the ora API origin the CLI is pointed at: a token requested
18
+ * for one deployment is useless at another. `ORA_CI_AUDIENCE` overrides it for
19
+ * a deployment that names its audience differently.
20
+ */
21
+ import { AuthError } from "./auth.js";
22
+ import { keylessCacheKey } from "./sign-in.js";
23
+ /** The two variables GitHub gives a job that may request its identity token. */
24
+ export const GITHUB_ID_TOKEN_REQUEST_URL = "ACTIONS_ID_TOKEN_REQUEST_URL";
25
+ export const GITHUB_ID_TOKEN_REQUEST_TOKEN = "ACTIONS_ID_TOKEN_REQUEST_TOKEN";
26
+ export function githubActionsSignIn({ apiKeyId, audience, requestUrl, requestToken, fetchFn = fetch }) {
27
+ return {
28
+ kind: "ci_oidc",
29
+ cacheKey: keylessCacheKey("ci_oidc", apiKeyId),
30
+ async present() {
31
+ let url;
32
+ try {
33
+ url = new URL(requestUrl);
34
+ }
35
+ catch {
36
+ throw new AuthError(`${GITHUB_ID_TOKEN_REQUEST_URL} is not a url: this job cannot ask GitHub for its identity token`, 0, "CI_IDENTITY_UNAVAILABLE");
37
+ }
38
+ url.searchParams.set("audience", audience);
39
+ let res;
40
+ try {
41
+ res = await fetchFn(url, { headers: { authorization: `Bearer ${requestToken}`, accept: "application/json" } });
42
+ }
43
+ catch (error) {
44
+ throw new AuthError(`could not reach GitHub for this job's identity token: ${error instanceof Error ? error.message : String(error)}`, 0, "CI_IDENTITY_UNAVAILABLE");
45
+ }
46
+ const body = (await res.json().catch(() => ({})));
47
+ if (!res.ok || typeof body.value !== "string" || body.value === "") {
48
+ throw new AuthError(`GitHub did not issue this job an identity token (HTTP ${res.status})`, res.status, "CI_IDENTITY_UNAVAILABLE");
49
+ }
50
+ return { bearer: body.value, body: { apiKeyId } };
51
+ },
52
+ };
53
+ }
54
+ //# sourceMappingURL=github-actions-sign-in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-actions-sign-in.js","sourceRoot":"","sources":["../../src/core/github-actions-sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,eAAe,EAAe,MAAM,cAAc,CAAC;AAE5D,gFAAgF;AAChF,MAAM,CAAC,MAAM,2BAA2B,GAAG,8BAA8B,CAAC;AAC1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,gCAAgC,CAAC;AAU9E,MAAM,UAAU,mBAAmB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAA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,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -84,8 +84,21 @@ function renderErrorJson(err) {
84
84
  return JSON.stringify({ error: err.message, code: err.code });
85
85
  return JSON.stringify({ error: err instanceof Error ? err.message : String(err), code: "CLI_ERROR" });
86
86
  }
87
+ /**
88
+ * What to do about a failed sign-in, by its code: the first entry that matches. A keyless CI job has no key to
89
+ * log in with, so telling it to `ora login` would send its owner the wrong way.
90
+ */
91
+ const AUTH_HINTS = [
92
+ { matches: (code) => code === "CI_IDENTITY_UNAVAILABLE", hint: "Give the job `permissions: id-token: write`, then run it again." },
93
+ {
94
+ matches: (code) => code.startsWith("CI_"),
95
+ hint: "Check that the api key trusts this repository, ref and environment (Settings, API keys, CI sign-in), and that ORA_API_KEY_ID is that key's ID.",
96
+ },
97
+ { matches: () => true, hint: "Run `ora login` with a valid api key." },
98
+ ];
87
99
  function authFailureStory(code, message) {
88
- return [chalk.red(`Authentication failed (${code}): ${message}`), "Run `ora login` with a valid api key."].join("\n");
100
+ const hint = AUTH_HINTS.find((entry) => entry.matches(code)).hint;
101
+ return [chalk.red(`Authentication failed (${code}): ${message}`), hint].join("\n");
89
102
  }
90
103
  function renderApiError(err, ctx) {
91
104
  if (err.status === 402) {