@hginsights/hgi 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/dist/bin.js +2024 -253
- package/docs/exit-codes.md +104 -10
- package/docs/output-formats.md +92 -2
- package/docs/releasing.md +4 -1
- package/docs/security.md +14 -2
- package/npm-shrinkwrap.json +136 -136
- package/package.json +1 -1
- package/skills/hgi/SKILL.md +111 -4
package/skills/hgi/SKILL.md
CHANGED
|
@@ -15,6 +15,7 @@ description: Look up company, contact, technology, intent and spend data from th
|
|
|
15
15
|
4. **Report the credit cost after every call.** The cost is printed on stderr (`credit_cost: N`, or `{"credit_cost":N}` when stderr is not a terminal). `unknown` or `null` means the server did not report one. Tell the user what the call cost; credits are billed to their organization.
|
|
16
16
|
5. **Never read, print or copy the credentials file** under `~/.config/hgi/`, and do not put tokens in commands. If `hgi` says the login is missing or expired, ask the user to run `hgi auth login` themselves. It opens their browser.
|
|
17
17
|
6. **Using the wrong verb fails safely.** `hgi call` on a state-changing tool, or `hgi run` on a read-only tool, exits 10, names the right verb, and sends nothing.
|
|
18
|
+
7. **Show a plan before working through a list.** When the work needs more than one batch (see `## Recipes`), first run one sample batch and report its `credit_cost`. Then show the plan: the calls, the number of batches, and the total estimated by extrapolating from the sample. **Wait for the user's go-ahead** before running the rest. Estimate only from the reported `credit_cost`, never from a price list; a figure from a past run may appear only as an example, labelled "observed".
|
|
18
19
|
|
|
19
20
|
## Recommended permissions (Claude Code)
|
|
20
21
|
|
|
@@ -36,6 +37,8 @@ hgi tools list --json # what can I call?
|
|
|
36
37
|
hgi call company_enrich --input '{"domain":"acme.com"}' # lookup, JSON on stdout
|
|
37
38
|
hgi call search_companies --input '{"query":"saas"}' --select name,domain -f csv
|
|
38
39
|
hgi call <tool> --input '{"limit":100}' --out result.json # big result to a new file
|
|
40
|
+
hgi call <tool> --ids @hg_ids.txt --input '{...}' # a whole list: one JSONL row per line
|
|
41
|
+
hgi call <tool> --all-pages --input '{...}' # every page of an offset-paged tool, merged
|
|
39
42
|
hgi run <tool> --input '{...}' # only after the user approves
|
|
40
43
|
```
|
|
41
44
|
|
|
@@ -43,6 +46,102 @@ hgi run <tool> --input '{...}' # only after the user a
|
|
|
43
46
|
- Output is JSON when piped and a table on a terminal. Use `-f json|jsonl|csv|yaml|table`.
|
|
44
47
|
- `--select a,b.c` keeps only those fields (dotted paths work through arrays). Prefer it, or `--out <new file>`, for large results; results are never truncated.
|
|
45
48
|
- `--meta` prints `{ "result": ..., "credit_cost": ..., "mcp_version": ... }` on stdout.
|
|
49
|
+
- `--label <stage>` on `call`/`run` tags the call in the local credit ledger (1 to 64 of `A-Z a-z 0-9 . _ : / -`).
|
|
50
|
+
- `hgi usage [--since today|24h|7d|2026-11-01] [--by tool|label|day|call]` shows the credits `hgi` spent on this machine (local only, no sign-in, not the organization's bill). `credits` excludes calls with unknown cost (`unknown_cost_calls`); `zero_cost_calls` are cache hits or free tools.
|
|
51
|
+
- A `{"warning":"ledger_not_updated",...}` line on stderr means the call still succeeded; do not re-run it.
|
|
52
|
+
- For more than one company, use `--ids @file` (one HG id or domain per line; `--ids -` for stdin; `--ids-column <name>` for a CSV; `--batch-size <n>` to send fewer per call than the tool's limit) instead of looping. hgi batches by the tool's limit, sends batches one at a time, and prints `{"input", "result"}` or `{"input", "error"}` rows as JSONL in input order. Exit 3 means a batch failed (its rows carry the error, the rest are fine); any other non-zero exit stopped the run, and `details.rows_emitted` / `calls_made` say how far it got: keep the rows already printed and resume from there.
|
|
53
|
+
|
|
54
|
+
### Paging (`--all-pages`)
|
|
55
|
+
|
|
56
|
+
For every row of an offset-paged tool, use `hgi call <tool> --all-pages` instead of an `offset` loop. hgi pages only tools whose schemas show it is safe (an integer `offset` input and a rows array with `has_more` or a total); anything else is refused with exit 2 `not_pageable`, nothing sent. Don't pass `offset` yourself.
|
|
57
|
+
|
|
58
|
+
- **Each extra page is a separate, billed call.** For batch tools (`hg_ids`/`domains`), follow-ups go one call per unfinished company.
|
|
59
|
+
- It stops on `has_more: false`, an empty or short page, or the total reached, never on `has_more: true` alone (the server can say `true` after the last row). `--max-pages <n>` caps pages per page object (default 10, page 1 included).
|
|
60
|
+
- The result keeps the server's shape. Each page object (the result, or each `companies[]` entry) gets `pages_fetched`; one cut short says `truncated: true` and `truncated_reason`: `max_pages`, `unmatched` (a batch entry hgi could not tie to one input, so it never guesses) or the code of the call that failed. Report truncated parts as incomplete.
|
|
61
|
+
- One credit line at the end with the sum. `--meta` adds `pages_fetched` (pages requested), `retries` (re-sends) and `calls_without_cost`.
|
|
62
|
+
- Not with `--ids` (exit 2 `all_pages_with_ids`): page one company list at a time.
|
|
63
|
+
|
|
64
|
+
## Recipes
|
|
65
|
+
|
|
66
|
+
These recipes name tools as examples. Before each one:
|
|
67
|
+
|
|
68
|
+
- **Confirm the tools.** Check every tool a recipe names in `hgi tools list --json`. If one is missing, skip that step and tell the user which tool is unavailable; never substitute a guess.
|
|
69
|
+
- **Take the batch size from the schema.** Read `maxItems` on `hg_ids` or `domains`, and the maximum of `limit`, `max_results` and `offset`, in the tool's `input_schema`. Don't hard-code them.
|
|
70
|
+
- **Keep batches stable.** The server caches identical inputs for 30 days (7 for search), and a cached call costs nothing (observed). Sort ids and keep the same batches, so a re-run is free. Changing one id in a batch makes the whole batch a new input.
|
|
71
|
+
- **Missing is not zero.** No installs, no intent, or a company left out of a batch response means unknown, not zero. Record it as unknown; don't score the account down.
|
|
72
|
+
- **Show a plan first** for more than one batch (Rule 7).
|
|
73
|
+
- Batching is manual for now: sorted id batches, as below. Paging is `--all-pages` where the tool allows it (`not_pageable` otherwise).
|
|
74
|
+
|
|
75
|
+
### Match an account list
|
|
76
|
+
|
|
77
|
+
**Tools:** `search_companies`, `company_firmographic`. Confirm them in `hgi tools list --json`; if one is missing, skip that step and tell the user which tool is unavailable.
|
|
78
|
+
**Batch:** read `maxItems` on `hg_ids` in `company_firmographic`'s `input_schema`.
|
|
79
|
+
**Order:**
|
|
80
|
+
|
|
81
|
+
1. `search_companies` per account: the name, the HQ country and a revenue floor (USD), `limit` small. It returns only `hg_id`, `name`, `domain`, `domain_normalized`.
|
|
82
|
+
2. Collect the candidate `hg_id`s, sort them, and confirm them with `company_firmographic` in batches of `hg_ids`: name, `country_code`, `employees_total`, `revenue_total`, `company_level`.
|
|
83
|
+
3. Keep the row whose country and size fit. Don't roll up to the global HQ or corporate parent blindly: HG lists Legrand Lebanon as Legrand's global HQ, and the French state as EDF's parent. Use `company_level` and the parent fields only after a sanity check.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
hgi call search_companies --input '{"company_identifiers":{"name":"Accor"},"firmographics":{"country_codes":[{"ids":["FR"],"inclusion_method":"ANY_PRESENT"}],"revenue":{"min":1000000000}},"limit":5}'
|
|
87
|
+
hgi call company_firmographic --input '{"hg_ids":["<id1>","<id2>"]}' --select companies.company_id,companies.firmographics.name,companies.firmographics.country_code,companies.firmographics.company_level
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Score fit and propensity
|
|
91
|
+
|
|
92
|
+
**Tools:** `company_technographic`, `company_intent`, `list_intent_topics`. Confirm them in `hgi tools list --json`; if one is missing, skip that step and tell the user which tool is unavailable.
|
|
93
|
+
**Batch:** read `maxItems` on `hg_ids` in `company_technographic`'s `input_schema`, and the maximum of `max_results` and `offset`. `company_intent` takes one company per call.
|
|
94
|
+
**Order:**
|
|
95
|
+
|
|
96
|
+
1. **Fit:** `company_technographic` on a batch of `hg_ids`, filtered (`vendor_names`, `product_names` or `category_ids`) so pages stay small, with `--all-pages` (above). It pages each company on its own and stops on a short page or `total_installs_count`, not on `has_more` alone (it can be wrong at page boundaries). A company with `truncated: true` is partial: say so, and narrow the filter rather than raising `--max-pages`.
|
|
97
|
+
2. **Topics:** resolve curated topic names to ids with `list_intent_topics`.
|
|
98
|
+
3. **Intent:** `company_intent` on the company's web domain (`company_domain`), not only its HQ id: intent is observed on web domains. In one run, Accor had 0 topics on its HQ id and 18 on `accor.com` (observed; counts change over time). Check `company.id` and `company.name` in the response: a domain can resolve to a subsidiary.
|
|
99
|
+
4. **Baseline:** large companies are active on about 70% of the ~20,000-topic catalogue (observed), so a raw topic count measures size, not interest. Compare the curated topics (`topic_ids`) with the company's own unfiltered summary. A summary with `topic_ids` counts only those topics. `fields:["summary"]` without a topic filter rejects `granularity` (422). When you request `fields:["topics"]`, pass `granularity:"global"`: the default is one row per state, which counts a topic several times.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# every install per company, paged safely; max_results up to the schema's maximum keeps the call count down
|
|
103
|
+
hgi call company_technographic --all-pages --max-pages 5 \
|
|
104
|
+
--input '{"hg_ids":["<id1>","<id2>"],"vendor_names":["<vendor>"],"max_results":<schema maximum>}' -f json > tech.json
|
|
105
|
+
# exit 0 with truncated companies = capped; non-zero with details.partial_result = stopped early, tech.json still holds what was paid for
|
|
106
|
+
hgi call company_intent --input '{"company_domain":"accor.com"}'
|
|
107
|
+
hgi call company_intent --input '{"company_domain":"accor.com","fields":["summary"],"topic_ids":["<topic id>"]}'
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Size wallet from spend
|
|
111
|
+
|
|
112
|
+
**Tools:** `company_spend`, `get_product_category`. Confirm them in `hgi tools list --json`; if one is missing, skip that step and tell the user which tool is unavailable.
|
|
113
|
+
**Batch:** read `maxItems` on `hg_ids` in `company_spend`'s `input_schema`, and the maximum of `max_results`.
|
|
114
|
+
**Order:**
|
|
115
|
+
|
|
116
|
+
1. Use the `hg_id`s from the matching recipe, sorted.
|
|
117
|
+
2. To size one area, resolve its category ids first with `get_product_category`, as `company_spend`'s description says. Don't pass guessed `category_names`: a name that matches nothing returns 0 rows without an error.
|
|
118
|
+
3. One `company_spend` call per batch of `hg_ids`, with `category_ids` set in that same call, not filtered afterwards.
|
|
119
|
+
4. `company_spend` is not pageable with `--all-pages` (its per-company spend has no rows array). Page with `max_results` and `offset` by hand only when `all_count` exceeds the rows returned; stop on a short page or once `all_count` is reached, never on a has-more flag alone.
|
|
120
|
+
5. Rows are per country, and categories form a tree through `category_parent_id` (Total IT → Total External IT → Software, …). Sum across countries, never a parent with its children.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
hgi call company_spend --input '{"hg_ids":["<id1>","<id2>"],"category_ids":["<category id>"]}' --select companies.company_id,companies.spend.all
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Data semantics
|
|
127
|
+
|
|
128
|
+
Verified with one live call per tool. "Scope" is what a call returns by default.
|
|
129
|
+
|
|
130
|
+
| Tool | Default scope | Nullable fields (what null means) |
|
|
131
|
+
|---|---|---|
|
|
132
|
+
| `search_companies` | global: all countries unless `country_codes` filters the HQ country | no field came back null in the verification call; treat a missing field as unknown |
|
|
133
|
+
| `company_firmographic` | country: one record per entity, in its own `country_code` | `corporate_parent_id`, `corporate_parent_name`, `parent_id`, `domestic_parent_id`, `domestic_parent_name`: none (no parent above it); `fortune_500_rank`, `forbes_2000_rank`: unknown |
|
|
134
|
+
| `company_technographic` | global: default rows have `country_code: null`; `granularity` or `country_codes` give per-country rows | `country_code`: a global or unattributed row, not missing data; `product_category_level4_name`, `product_category_level5_name`: none (the category tree is shallower) |
|
|
135
|
+
| `company_intent` | global: `summary` only, for the resolved entity across all geographies; with `fields:["topics"]`, one row per state unless `granularity:"global"` | no field came back null in the verification call; treat a missing field as unknown |
|
|
136
|
+
| `company_spend` | country: every row has a `country_code` | no field came back null in the verification call; treat a missing field as unknown |
|
|
137
|
+
|
|
138
|
+
Not null, but easy to misread:
|
|
139
|
+
|
|
140
|
+
- A batch response leaves out companies it didn't match. A left-out company is unknown, not zero.
|
|
141
|
+
- `company_domain` is `""` when you query by `hg_ids`.
|
|
142
|
+
- `company_intent` on a domain answers for whichever company the domain resolves to: `accor.com` resolved to an Accor subsidiary in Australia, not the group HQ.
|
|
143
|
+
|
|
144
|
+
**HG ids** are hex strings, normally 32 characters and uppercase in responses. An id can come back with its leading zero dropped, as 31 characters: seen on a spend `category_id`, and on company ids (observed). The `hg_ids` inputs accept 31 or 32 characters. Upper-case ids and left-pad them to 32 with `0` before comparing or joining.
|
|
46
145
|
|
|
47
146
|
## Exit codes
|
|
48
147
|
|
|
@@ -55,13 +154,21 @@ hgi run <tool> --input '{...}' # only after the user a
|
|
|
55
154
|
| 2 | invalid input or usage | fix the input; the JSON error lists the problem fields |
|
|
56
155
|
| 3 | the tool reported an error | read the message; do not blindly retry |
|
|
57
156
|
| 4 | not signed in, or login expired | ask the user to run `hgi auth login` |
|
|
58
|
-
|
|
|
59
|
-
|
|
|
157
|
+
| 4 `phoenix_account_required` | the signed-in identity has no Phoenix account | stop; tell the user to sign up, or to sign in with `hgi auth login` as an account that has one |
|
|
158
|
+
| 5 | rate limited (after hgi's own retries) | wait `retry_after_seconds` from the error, then retry. For a long batch of lookups, pass `--retries 6` instead of writing your own retry loop |
|
|
159
|
+
| 6 | out of credits: `credit_limit_exceeded` (the organization) or `user_credit_limit_exceeded` (the user's personal budget) | stop; tell the user which one, and to ask an admin. Retrying will not help |
|
|
60
160
|
| 7 | server unreachable | retry later. If `outcome_unknown` is `true`, check state before re-running a `run` |
|
|
161
|
+
| 7 `governance_unavailable` | the server could not check the budget; nothing ran (`retryable: true`) | wait a little, then retry once. `hgi call --retries <n>` retries it itself; `hgi run` never does |
|
|
61
162
|
| 8 | OAuth or sign-in failure | ask the user to run `hgi auth login` again |
|
|
62
163
|
| 9 | proxy or TLS problem | the error names the cause (see `NODE_EXTRA_CA_CERTS`, `HTTPS_PROXY`). After a `run`, check `outcome_unknown` before retrying |
|
|
63
164
|
| 10 | wrong verb | use the verb the error names |
|
|
64
|
-
| 11 | forbidden | the account or
|
|
165
|
+
| 11 | forbidden, or `tool_not_enabled_for_team` | the account, organization or team lacks access to this tool; stop and tell the user to ask an admin |
|
|
65
166
|
| 12 | local credential or file problem | follow the hint. If `details.tool_ran` is `true`, the tool already ran and its result is on stdout: do not re-run it |
|
|
167
|
+
| any, with `details.partial_result: true` | `--all-pages` stopped on a later page; the pages fetched so far are on stdout (or `--out`), unfinished parts marked `truncated` | keep them, they were billed; then act on the code as its own row says. Don't re-fetch pages you already have |
|
|
168
|
+
| 13 `budget_exceeded` | the run spent its `--max-credits` cap; nothing more was sent (with `--ids`, keep the rows already printed) | stop; tell the user what was spent (`details.spent` of `details.max`). Only the user raises the cap or runs `hgi budget reset` |
|
|
169
|
+
|
|
170
|
+
Errors are JSON on stderr when it is not a terminal: `{"schema":1,"error":{"code","exit_code","message","hint","details"}}`. Branch on `error.code`, not on the message.
|
|
171
|
+
|
|
172
|
+
## Run cap
|
|
66
173
|
|
|
67
|
-
|
|
174
|
+
When the user gives a credit limit for a task, pass it as `hgi call --max-credits <n>` (or set `HGI_MAX_CREDITS`). It counts every `hgi call` in one budget; `hgi run` is not counted. **Run `export HGI_BUDGET_ID=<something unique to the task>` once first:** agent harnesses usually start a fresh shell per command, and the default budget (the parent process) would then give every call its own empty budget. The cap is client-side, on top of the server's limits, and can overshoot by the calls running at the same time. `hgi budget status` shows what the task has spent.
|