@hginsights/hgi 0.0.0 → 0.1.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.
@@ -0,0 +1,48 @@
1
+ # Compatibility policy
2
+
3
+ `hgi` is a thin client. It does not carry a list of tools, parameters or result shapes: it asks the server what is available, every time it acts.
4
+
5
+ ## What this means for releases
6
+
7
+ - **A change to the server's tool set does not need an `hgi` release.** New tools appear in `hgi tools list` and can be called straight away; removed tools stop being listed and fail with `unknown_tool` (exit 2).
8
+ - `hgi call` and `hgi run` read a fresh tool list on every invocation and refresh the local cache from it. `hgi tools list` alone reads that cache (up to 15 minutes old); `hgi tools list --refresh` skips it. A tool listing printed before any call can therefore be briefly stale.
9
+ - Which verb a tool needs comes from its `readOnlyHint` annotation on that fresh list. A tool that stops advertising `readOnlyHint: true` is treated as state-changing (`run`); `hgi call` on it fails with exit 10 and names `hgi run`.
10
+ - Tool input is validated against the schema the server advertises. A tool that gains an optional field keeps accepting old inputs. A tool that gains a required field rejects old inputs with exit 2 and names the field.
11
+ - The credit cost comes from `_meta.creditCost` on a successful result. If a server stops sending it, the call still succeeds and the cost is reported as unknown.
12
+
13
+ An `hgi` release is needed only when the **protocol** changes in a way the bundled MCP SDK cannot speak, or when the OAuth flow changes.
14
+
15
+ ## Supported MCP protocol versions
16
+
17
+ `hgi` uses the MCP TypeScript SDK pinned in `npm-shrinkwrap.json` and speaks the protocol versions that SDK supports:
18
+
19
+ - `2025-11-25`
20
+ - `2025-06-18`
21
+ - `2025-03-26`
22
+ - `2024-11-05`
23
+ - `2024-10-07`
24
+
25
+ The list above is checked against the SDK by a test, so it cannot drift from what ships. `hgi` offers the newest version and accepts the server's choice if it is on the list. The version the server actually uses is shown by `hgi tools list` (`mcp_version`). The server's own tool-set version (for example `v2`) is separate from the protocol version.
26
+
27
+ ## When the server drops a capability
28
+
29
+ | The server stops... | `hgi` does |
30
+ |---|---|
31
+ | listing a tool | the tool disappears from `tools list`; calling it exits 2 (`unknown_tool`) |
32
+ | marking a tool read-only | the tool becomes `run`-only |
33
+ | sending `_meta.creditCost` | the call succeeds; cost is reported as unknown |
34
+ | supporting a protocol version `hgi` offered | the server picks another version from the list above and `hgi` follows it |
35
+ | supporting any version on the list | the connection fails with `server_unreachable` (exit 7, `details.reason: unsupported_protocol_version`) and tells you to upgrade `hgi`; it never crashes |
36
+ | the OAuth features `hgi` uses (PKCE S256, loopback redirect, client metadata document) | sign-in is rejected by the server and fails with `oauth_error` (exit 8) carrying the server's error; `hgi` does not probe for these features first |
37
+
38
+ ## Deprecation
39
+
40
+ Removing an `hgi` command, flag, output field or exit code is a breaking change and ships in a new major version. Exit codes and the JSON error body are documented in [exit-codes.md](exit-codes.md) and are stable within a major version. The shipped Claude Code skill is updated in the same release as any change it describes.
41
+
42
+ ## Which version works with which server
43
+
44
+ There is no minimum-server-version table, because the CLI asks the server what it supports. The only version pair that matters is the protocol list above. Releases are tagged `vX.Y.Z`; the newest release is the one tested against the current server. Node-based installs require Node.js 22.19 or newer; the prebuilt binaries bundle their own Node.js.
45
+
46
+ ## How this is tested
47
+
48
+ For `v0.1.0` there is no earlier build to run against a newer server, so the test suite runs one build against two server tool sets (`test/e2e/compat.test.ts`). From `v0.1.1` the plan is for CI to also run the previous release's binary against the current test server. That job does not exist yet; it needs a first published release to test against, and is listed in the release checklist ([releasing.md](releasing.md)).
@@ -0,0 +1,49 @@
1
+ # Exit codes and error format
2
+
3
+ Every failure has its own exit code, so a script can branch without parsing English.
4
+
5
+ | Exit | `error.code` | When |
6
+ |---|---|---|
7
+ | 0 | | success |
8
+ | 1 | `internal_error` | a bug in `hgi`. Never used for a server response or a usage error |
9
+ | 2 | `invalid_input` | bad flags or usage; invalid JSON; input that fails the tool's schema; unknown tool; unreadable `--input @file`; `--out` refusals (exists, symlink, protected path, `--force` on `call`); config-dir workspace guard |
10
+ | 3 | `tool_error` | the tool returned `isError` (including server-side invalid arguments, which the server reports in-band), a JSON-RPC error, or a response `hgi` could not parse after the call was sent |
11
+ | 4 | `login_required`, `login_expired` | no credentials; a second 401 after one refresh; the refresh token was rejected (`invalid_grant`) |
12
+ | 5 | `rate_limited` | 429 after bounded retries (MCP calls); a 429 from the userinfo or revoke endpoint exits at once |
13
+ | 6 | `credit_limit_exceeded` | `_meta.errorCode === "credit_limit_exceeded"` on a tool result |
14
+ | 7 | `server_unreachable` | DNS failure, refused connection, timeout, HTTP 5xx, an unexpected redirect from the MCP endpoint, the server shedding load after retries, or the server choosing an MCP protocol version this `hgi` does not speak (`details.reason` is `unsupported_protocol_version`; upgrade `hgi`) |
15
+ | 8 | `oauth_error` | discovery or issuer mismatch, state or redirect mismatch, consent denied, a rejected or reused sign-in code, a token-endpoint failure, an unexpected redirect on an auth request |
16
+ | 9 | `network_proxy_tls` | TLS verification failure or proxy failure; the message names the cause (for example `DEPTH_ZERO_SELF_SIGNED_CERT`) |
17
+ | 10 | `wrong_verb` | `hgi call` on a state-changing tool, or `hgi run` on a read-only one. Nothing is sent |
18
+ | 11 | `forbidden` | HTTP 403 |
19
+ | 12 | `local_state_error` | corrupt or unsafe-mode credentials file (`details.kind` is `credentials_corrupt` or `credentials_unsafe`), lock timeout, or a failed local write. If `details.tool_ran` is `true` (an `--out` write failed *after* the tool ran), the tool already ran and was billed, its result was printed to stdout instead, and you must **not** re-run it |
20
+
21
+ `hgi --help` and `hgi --version` exit 0.
22
+
23
+ ## The error body
24
+
25
+ When stderr is not a terminal (or you pass `--json-errors`), errors are one JSON object on stderr and nothing on stdout (the one exception: exit 12 with `details.tool_ran: true`, where the tool already ran and its result is printed on stdout):
26
+
27
+ ```json
28
+ {"schema":1,"error":{"code":"credit_limit_exceeded","exit_code":6,"message":"...","hint":"...","details":{"tool":"company_enrich"}}}
29
+ ```
30
+
31
+ - `schema` is the version of this format. New fields may be added; existing ones keep their meaning.
32
+ - `code` and `exit_code` are stable. `message` and `hint` are for humans.
33
+ - `details` carries machine-readable context where it exists:
34
+ - `retry_after_seconds` on `rate_limited`
35
+ - `outcome_unknown` on `tools/call` failures (see below)
36
+ - `expected_verb` on `wrong_verb`
37
+ - `reason` on `invalid_input` and `oauth_error` (for example `unknown_tool`, `schema`, `state_mismatch`)
38
+ - `cause` on `server_unreachable` and `network_proxy_tls` (a Node error code)
39
+ - `location_host` on an unexpected redirect
40
+
41
+ On a terminal, errors are plain text with a hint.
42
+
43
+ ## `outcome_unknown`
44
+
45
+ `hgi` retries only failures that happen **before the server runs the tool**: a 401 (after a refresh), a 429, the server's 503 "shedding load" response, and a refused or unresolvable connection. If a connection drops, times out, a proxy resets it, or a 5xx arrives **after** a `tools/call` was sent, it is not retried, because `hgi run` could start the work twice. The error then has `"outcome_unknown": true` and a hint to check state first. This marker is added to every network-class or unclassified failure once the call was sent, so it can appear with exit 1, 7 or 9. An exhausted load-shed retry has `"outcome_unknown": false`: nothing ran and retrying is safe.
46
+
47
+ ## Credit cost
48
+
49
+ Success prints the tool result on stdout and the credit cost on stderr (`credit_cost: 3`, or `{"credit_cost":3}` when stderr is not a terminal). Tools that do not report a cost (external, aggregated tools) show `unknown` / `null`, never `0`.
@@ -0,0 +1,35 @@
1
+ # Open-source approval record
2
+
3
+ The repository stays private until legal and security approval is recorded in the internal tracking issue. Changing visibility to public before that is a policy violation. This page is the checklist the reviewers fill in; the signed-off copy lives in the issue, not here.
4
+
5
+ **Approved commit SHA:** `________` (any later commit needs a re-check before the flip)
6
+
7
+ ## Legal
8
+
9
+ - [ ] License: MIT, `LICENSE` present, copyright holder correct.
10
+ - [ ] `THIRD_PARTY_NOTICES` generated by `scripts/make-notices.mjs` and reviewed; every production dependency license is on the allowlist (MIT, ISC, Apache-2.0, BSD-2/3-Clause, 0BSD, MPL-2.0, BlueOak-1.0.0, Python-2.0, CC0-1.0).
11
+ - [ ] The binaries bundle the Node.js runtime: its `LICENSE` ships beside the binary as `NODE_LICENSE`, and the reviewers accept Node.js's aggregated third-party notices.
12
+ - [ ] No customer data, internal hostnames, internal ticket links, or non-public product names in the repository, docs, tests or fixtures.
13
+ - [ ] Trademark and branding use of "HG Insights" acceptable.
14
+ - [ ] Data-handling statement: `hgi` sends requests only to the configured server, stores tokens locally, and has no telemetry (`docs/security.md`, README).
15
+
16
+ ## Security
17
+
18
+ - [ ] `SECURITY.md` present; private vulnerability reporting will be enabled by `scripts/configure-repo-security.sh`.
19
+ - [ ] Secret scan of **all refs** clean: `gitleaks git --log-opts="--all"`; plus Actions run logs, uploaded artifacts, and PR / issue / review comment threads reviewed by a person and old runs deleted.
20
+ - [ ] `docs/security.md` risk acceptance (30-day refresh token in a `0600` file) reviewed and still accepted.
21
+ - [ ] SBOM reviewed; `npm audit --omit=dev` clean at the high level.
22
+ - [ ] Release pipeline reviewed ([releasing.md](releasing.md)): no secrets in the repository before the flip, `release` environment and tag ruleset applied at the flip.
23
+
24
+ ## After the flip: prove the controls (paste results into the issue)
25
+
26
+ - [ ] A scratch branch with a **fake** secret was blocked by push protection or flagged by gitleaks. Use a syntactically valid, non-live GitHub token shape (`ghp_` followed by 36 random alphanumeric characters, generated at test time and never committed); documented example keys such as `AKIAIOSFODNN7EXAMPLE` are deliberately ignored by push protection and prove nothing. Record which control fired. Delete the branch afterwards.
27
+ - [ ] A direct push to `main` was rejected.
28
+ - [ ] A pull request without an approving review cannot be merged.
29
+
30
+ ## Sign-off
31
+
32
+ | Role | Name | Date | Link to approval |
33
+ |---|---|---|---|
34
+ | Legal | | | |
35
+ | Security | | | |
@@ -0,0 +1,56 @@
1
+ # Output formats
2
+
3
+ By default `hgi` prints **JSON when stdout is not a terminal** and a **table on a terminal**. Use `-f` to choose: `json`, `jsonl`, `csv`, `yaml`, `table`.
4
+
5
+ Results are never truncated. A large result prints complete in every format. Use `--out <file>` to write it to a new file instead of stdout.
6
+
7
+ ## What "the result" is
8
+
9
+ `hgi call` / `hgi run` print the tool's result, picked in this order:
10
+
11
+ 1. `structuredContent` if the tool returned it (this wins over any summary text block).
12
+ 2. Otherwise, if there is exactly one text block, that text parsed as JSON. Text that is not JSON becomes `{"text": "<raw text>"}`.
13
+ 3. Otherwise (several blocks, or non-text blocks): `{"content": [<blocks verbatim>]}`.
14
+
15
+ `--select` and every format below operate on that value.
16
+
17
+ ## Rows
18
+
19
+ `jsonl`, `csv` and `table` need rows. The rows are:
20
+
21
+ - the value itself, if it is an array;
22
+ - otherwise the one top-level property that is an array of objects (for example `companies` in `{"total": 2, "companies": [...]}`), if there is exactly one;
23
+ - otherwise a single row (the whole value).
24
+
25
+ | Format | Output |
26
+ |---|---|
27
+ | `json` | the value; compact when piped, indented on a terminal |
28
+ | `jsonl` | one JSON object per row, one per line |
29
+ | `csv` | RFC 4180. Header is the ordered union of the rows' keys. Nested objects and arrays are written as JSON in the cell. `\r\n` line endings |
30
+ | `yaml` | the value as YAML |
31
+ | `table` | aligned columns, never truncated. A single object prints as a field/value table |
32
+
33
+ ## `--select`
34
+
35
+ `--select a,b.c` keeps only those fields. Dotted paths go through arrays, so `--select total,companies.name,companies.hq.city` keeps `total` and, for every element of `companies`, only `name` and `hq.city`. Names that are absent are skipped. A shorter path wins over a longer one (`a` and `a.b` select all of `a`).
36
+
37
+ ## `--meta`
38
+
39
+ `--meta` replaces the bare result on stdout with an envelope:
40
+
41
+ ```json
42
+ {"result": {...}, "credit_cost": 2, "mcp_version": "v2"}
43
+ ```
44
+
45
+ `--select` trims the `result` inside the envelope, so `--meta --select name` gives `{"result": {"name": ...}, "credit_cost": ..., "mcp_version": ...}`.
46
+
47
+ ## `hgi tools list`
48
+
49
+ `hgi tools list --json` prints `{base_url, mcp_version, server, fetched_at, from_cache, count, tools: [...]}`. Each tool has `name`, `verb` (`call` or `run`), `read_only` (`true`, `false` or `null` when the server gave no annotation), `description`, `required`, `parameters` and the full `input_schema`. The list is cached for 15 minutes per server, organization and user; `--refresh` asks the server. The served MCP version comes from the server (`X-MCP-Version`).
50
+
51
+ On a terminal or with `-f table|csv`, `tools list` prints `name`, `verb`, `required`, `description` (table descriptions are shortened to their first line) and the MCP version on stderr.
52
+
53
+ ## Safety notes
54
+
55
+ - **CSV and spreadsheets.** Cells are written as the data is. A value that starts with `=`, `+`, `-` or `@` (third-party text can) is read as a formula by Excel and Google Sheets. Open untrusted exports as text, or prefix such cells yourself.
56
+ - **Terminals.** On a terminal, `table`, `csv` and `yaml` output and human-readable errors have control characters and escape sequences replaced by visible `\xNN` forms, so a tool result cannot rewrite your screen, retitle your window or write your clipboard. JSON and JSONL on a terminal additionally rewrite C1 control characters and bidirectional overrides as `\\uXXXX` escapes, which keeps the document valid and the values identical. YAML, table and CSV on a terminal replace control characters, lone carriage returns, C1 controls and invisible formatting marks (bidi overrides, zero-width space, BOM) with visible `\\xNN` / `\\uNNNN` forms. A lone carriage return is shown as `\\x0d`.
@@ -0,0 +1,100 @@
1
+ # Releasing hgi
2
+
3
+ How a release is built, what it needs, and how to go from "private repository" to "published `v0.1.0`". The pipeline is `.github/workflows/release.yml`.
4
+
5
+ ## What a release contains
6
+
7
+ | Asset | Notes |
8
+ |---|---|
9
+ | `hgi-vX.Y.Z-{darwin-arm64,darwin-x64,linux-x64,linux-arm64}.tar.gz` | `hgi`, `LICENSE`, `THIRD_PARTY_NOTICES`, `NODE_LICENSE`. macOS binaries carry an ad-hoc signature only (see [macOS](#macos-homebrew-and-npm-not-developer-id-signed)) |
10
+ | `SHA256SUMS` | over every asset |
11
+ | `hgi-vX.Y.Z.sbom.cdx.json` | CycloneDX: production npm dependencies plus the bundled Node.js runtime and its components |
12
+ | `hginsights-hgi-X.Y.Z.tgz` | the exact npm tarball that is published (with provenance) |
13
+ | attestations | GitHub build-provenance attestation for every asset |
14
+
15
+ The binaries are Node.js single-executable applications: the official Node.js release pinned in `packaging/node-sha256.json` (verified by SHA-256 before use) with the bundled program injected. They are 110-130 MB. Linux binaries need glibc 2.28 or newer; Alpine/musl is unsupported (use `npm install -g`). Node 22 reaches end of life on 2027-04-30; rebuild on Node security releases and move to the next LTS before then.
16
+
17
+ ## Trust boundaries in the pipeline
18
+
19
+ | Job | Holds | Runs |
20
+ |---|---|---|
21
+ | `build-linux`, `build-darwin`, `package` | no secrets | `npm ci --ignore-scripts`, build, package |
22
+ | `attest` | attestation OIDC token | verifies checksums, attests; no repository code |
23
+ | `npm-publish` (`release` environment) | npm OIDC token | publishes the prebuilt, smoke-tested tarball with `--ignore-scripts` |
24
+ | `homebrew-pr` (`release` environment) | GitHub App credential, scoped to the tap | renders the formula, opens a PR (never pushes to the tap's `main`) |
25
+
26
+ Release jobs need the `release` GitHub environment, which only `v*` **tags** may deploy to. Manual runs of the workflow are dry runs: no secrets, nothing published.
27
+
28
+ ## Secrets (environment `release`)
29
+
30
+ Store these **only after the repository is public and `scripts/configure-repo-security.sh --apply` has run**. On a private GitHub Free repository any writer can read a repository secret by editing a workflow.
31
+
32
+ | Secret | What | Who provides it |
33
+ |---|---|---|
34
+ | `TAP_APP_CLIENT_ID`, `TAP_APP_PRIVATE_KEY` | the GitHub App that opens the formula PR on `HGInsights/homebrew-tap` | org owner |
35
+
36
+ npm needs no stored secret: it uses trusted publishing. There are no Apple credentials: macOS binaries are not Developer ID signed.
37
+
38
+ ### What the secrets are
39
+
40
+ `TAP_APP_CLIENT_ID` and `TAP_APP_PRIVATE_KEY` belong to a GitHub App that is installed on `HGInsights/homebrew-tap` only, with **Contents: read and write** and **Pull requests: read and write** and nothing else. The workflow mints a short-lived token limited to that one repository on every release; the app never pushes to the tap's `main`, it only opens a pull request. The tap should have a ruleset on `main` requiring a pull request (it is public, so this works on the Free plan). How the app is created and who holds its key is an organization-admin matter and is not documented in this repository.
41
+
42
+ ## One-time npm bootstrap
43
+
44
+ ### Prerequisite
45
+
46
+ The `@hginsights` npm organization must exist, with at least two owners who have 2FA enabled.
47
+
48
+ ### Publish the placeholder and connect the workflow
49
+
50
+ Trusted publishing is configured per existing package, so the package must exist first. Do this immediately before the rehearsal tag, as an owner of the scope:
51
+
52
+ 1. `npm publish --access public` a placeholder version `0.0.0` (the registry makes the first version `latest` whatever the tag).
53
+ 2. On npmjs.com, package settings: add a trusted publisher: repository `HGInsights/hgi-cli`, workflow `release.yml`, environment `release`.
54
+ 3. `npm deprecate @hginsights/hgi@0.0.0 "placeholder; use 0.1.0 or newer"`.
55
+
56
+ Verify these npm steps against npm's current documentation when you do them; the rules have changed recently. The first real test of the OIDC exchange is the `-rc.1` publish; if it fails with an authentication error, check the trusted-publisher settings first (the publish job deliberately has no `registry-url`, so no placeholder token is configured). Trusted publishing needs npm 11.5.1 or newer, so the publish job runs on Node 24 (which bundles npm 11) and fails if the bundled npm is older; it never downloads npm at publish time.
57
+
58
+ ## Cutting a release
59
+
60
+ 1. Bump `version` in `package.json` (and `npm-shrinkwrap.json`: `npm install --package-lock-only`), open a PR, merge it.
61
+ 2. **Rehearse** with a release candidate: bump to `X.Y.Z-rc.1`, merge, tag `vX.Y.Z-rc.1`. This does everything for real (GitHub prerelease, smoke tests on all four platforms, `brew install` of the rendered formula, npm publish under dist-tag `next` with provenance) except opening the Homebrew PR.
62
+ 3. Run `scripts/verify-release.sh vX.Y.Z-rc.1 --route binary|npm` on clean machines.
63
+ 4. Bump to `X.Y.Z`, merge, tag `vX.Y.Z`. This publishes `latest` and opens the tap PR; merge it after checking the checksums match.
64
+ 5. Run `scripts/verify-release.sh vX.Y.Z --route brew|binary|npm` on a clean macOS and a clean Linux machine and paste the output into the tracking issue.
65
+ 6. After the first release: add a `compat-previous-release` CI job that runs the previous release's binary against the current fake-server fixtures (`docs/compatibility.md` promises it from `v0.1.1`).
66
+
67
+ Dry run at any time: Actions > Release > Run workflow (builds and packages everything; nothing is published).
68
+
69
+ ## Making the repository public (first release only)
70
+
71
+ In this order. Each step is a gate for the next.
72
+
73
+ 0. **Before anything else:** make sure the `@hginsights` npm organization and the tap GitHub App exist (see the prerequisites above). Make sure the release team (`--release-team`) has at least two members and every team named in `.github/CODEOWNERS` has write access to the repository (the script checks both and refuses to `--apply` otherwise).
74
+ 1. Final scan: `gitleaks git --log-opts="--all"`, and manually review Actions logs, artifacts, and the PR, issue and review comment threads (gitleaks does not read comments). Delete old workflow runs and artifacts.
75
+ 2. Legal and security sign-off ([oss-approval.md](oss-approval.md)), recorded in the tracking issue **with the approved commit SHA**. Any later commit needs a re-check.
76
+ 3. Make the repository public.
77
+ 4. `bash scripts/configure-repo-security.sh --release-team <slug> --apply`.
78
+ 5. Prove the controls: push a scratch branch containing a fake secret (expect it to be blocked or alerted) and attempt a direct push to `main` (expect a rejection). Paste the results into the tracking issue, then delete the scratch branch.
79
+ 6. Add the secrets above to the `release` environment.
80
+ 7. npm bootstrap.
81
+ 8. Tag `vX.Y.Z-rc.1`; 9. verify and evaluate; 10. tag `vX.Y.Z`; 11. verify on clean machines.
82
+
83
+ ## macOS: Homebrew and npm, not Developer ID signed
84
+
85
+ **Decision:** macOS binaries are not Developer ID signed or notarized. Apple Developer credentials, a notarization step and an installer package add real cost and lead time for little user-visible value here, because the supported macOS routes avoid the problem:
86
+
87
+ - **Homebrew** and **`curl`** downloads do not set macOS's quarantine attribute, so Gatekeeper never assesses the binary and it runs without a warning.
88
+ - **npm** runs under Node, which is already signed.
89
+ - The binaries carry an **ad-hoc signature** (`codesign -s -`), which is all Apple Silicon needs to execute a binary. The release smoke job checks that it is intact.
90
+
91
+ What users lose: a macOS tarball downloaded through a **browser** is quarantined and blocked by Gatekeeper until the user runs `xattr -d com.apple.quarantine hgi` once. The README and the release notes say so. Some enterprise endpoint-security or MDM policies only allow notarized binaries; those users should install through npm.
92
+
93
+ **Revisit** if a customer needs a notarized binary: add a Developer ID Application certificate, a signing job that holds the credentials and installs nothing from npm, and a notarization step (`notarytool`). Nothing else in the pipeline needs to change.
94
+
95
+ ## Rollback
96
+
97
+ - GitHub release: edit it to a draft or delete it (`gh release delete`); delete the tag only if no one has consumed it.
98
+ - npm: versions are immutable. `npm deprecate @hginsights/hgi@X.Y.Z "<reason>"` and publish a fixed patch version.
99
+ - Homebrew: close the tap PR, or revert the formula commit.
100
+ - A compromised GitHub App key: generate a new key, update `TAP_APP_PRIVATE_KEY`, then delete the compromised key (in that order, so the app is never without a working key).
@@ -0,0 +1,52 @@
1
+ # Security model
2
+
3
+ `hgi` signs you in through your browser and stores a session on your machine. This page states what is stored, what protects it, and which risks are accepted.
4
+
5
+ ## Accepted risk: the credentials file
6
+
7
+ `hgi auth login` writes your session to `~/.config/hgi/credentials-<host>.json`. It holds a 1-hour access token and a **30-day refresh token**, in a file with mode `0600` inside a directory with mode `0700`.
8
+
9
+ **An AI agent (or any program) running as the same operating-system user can read that file.** That is common for command-line tools that keep a login, and it is accepted for `hgi`.
10
+
11
+ - Risk owner: the Office of the CTO, HG Insights. Accepted 2026-09-30.
12
+ - What this means for you: treat any agent that runs shell commands as you as able to act as you against HG Insights for up to 30 days, until you run `hgi auth logout`.
13
+ - Future work, not in this release: shorter token lifetimes and OS keychain storage.
14
+
15
+ `hgi` never prints a token. Tokens are masked in every output, error and `--debug` log, and your agent's instructions (`SKILL.md`) tell it not to read the file.
16
+
17
+ ## How the credentials file is protected
18
+
19
+ - Created atomically with mode `0600` from the first write (a temporary file opened with `O_EXCL`, then renamed), in a `0700` directory.
20
+ - A pre-existing symlink at the credentials path, or a symlinked `~/.config/hgi` directory, is refused. `hgi` never follows it.
21
+ - Stored under `~/.config/hgi/` (or `$XDG_CONFIG_HOME/hgi`), never in a project directory. `HGI_CONFIG_DIR`, `XDG_CONFIG_HOME` and `XDG_CACHE_HOME` overrides inside a git working tree are refused.
22
+ - One file per server, and a token is only ever sent to the server it was issued by. OAuth endpoints found through discovery must be on the same origin as the base URL, and `hgi` never follows an HTTP redirect on an auth or MCP request, so a token cannot be replayed to another host.
23
+ - Several `hgi` processes share a lock around refresh, so parallel commands do not invalidate each other's sessions.
24
+
25
+ ## Signing in and out
26
+
27
+ - Sign-in uses the OAuth authorization-code flow with PKCE (S256). The loopback listener binds `127.0.0.1` only, on a random port, and accepts exactly one callback with an exact `state` match. With `--no-browser`, a pasted callback URL must match the exact redirect URI and state and is used once.
28
+ - `hgi auth logout` asks the server to revoke both tokens and deletes the file. If the server cannot be reached it keeps the file and tells you so (you are **not** signed out). `--force` deletes the local file anyway and warns that the server-side session may stay valid for up to 30 days.
29
+ - A repeat `hgi auth login` revokes the previous session after saving the new one. If that revoke cannot be delivered, login still succeeds and warns you.
30
+ - After a revoke, the access token stops working at once on the userinfo endpoint. The MCP endpoint may accept it for up to about 30 seconds (the server caches validated tokens briefly).
31
+
32
+ ### Residual risks
33
+
34
+ - If you suspect a token has been stolen, run `hgi auth logout` and ask your administrator or your HG Insights representative to revoke your sessions.
35
+ - A refresh response lost after the server rotated the refresh token consumes it. You will be asked to sign in again.
36
+ - The refresh lock is an advisory file lock with a 30-second stale window and an ownership check before every credential write. A process that is suspended for longer than that at an unlucky instant (for example a laptop asleep between the last check and the final rename) could still overwrite credentials a newer `hgi` process just saved. No advisory lock can exclude this. The cost is signing in again; it cannot expose a token.
37
+
38
+ ## What `call` and `run` do
39
+
40
+ - `hgi call` only runs tools the server marks `readOnlyHint: true`, decided against a fresh tool list on every invocation. `hgi run` runs everything else, including tools with no annotations. There is no `--yes` flag, so a host permission rule on `hgi call *` approves only lookups.
41
+ - `--out <file>` never overwrites an existing file on `hgi call`, never follows symlinks, and refuses paths inside hgi's config and cache directories. `--input @file` refuses hgi's own credential and cache files (including through symlinks and hard links). An allowlisted agent can still write a **new** file or send any other file it can read to HG Insights as tool input; scope your allowlist accordingly.
42
+ - Credit cost is reported after each call. Credits are billed to your organization.
43
+
44
+ ## Network
45
+
46
+ - `https` is required except for loopback hosts used in tests.
47
+ - Proxies are honored (`HTTPS_PROXY`, `HTTP_PROXY`, `NO_PROXY`). Corporate TLS inspection needs `NODE_EXTRA_CA_CERTS`. TLS and proxy failures name their cause.
48
+ - `hgi` sends the User-Agent `hgi/<version>` and nothing else about you. No telemetry.
49
+
50
+ ## Reporting a vulnerability
51
+
52
+ Please do not open a public issue. Use GitHub's private vulnerability reporting on this repository (Security tab), or contact your HG Insights representative.