@hginsights/hgi 0.1.1 → 0.2.0-rc.1
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 +51 -0
- package/dist/bin.js +1385 -202
- package/docs/exit-codes.md +55 -8
- package/docs/output-formats.md +38 -0
- 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 +106 -3
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,7 @@ 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
|
|
39
41
|
hgi run <tool> --input '{...}' # only after the user approves
|
|
40
42
|
```
|
|
41
43
|
|
|
@@ -43,6 +45,100 @@ hgi run <tool> --input '{...}' # only after the user a
|
|
|
43
45
|
- Output is JSON when piped and a table on a terminal. Use `-f json|jsonl|csv|yaml|table`.
|
|
44
46
|
- `--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
47
|
- `--meta` prints `{ "result": ..., "credit_cost": ..., "mcp_version": ... }` on stdout.
|
|
48
|
+
- `--label <stage>` on `call`/`run` tags the call in the local credit ledger (1 to 64 of `A-Z a-z 0-9 . _ : / -`).
|
|
49
|
+
- `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.
|
|
50
|
+
- A `{"warning":"ledger_not_updated",...}` line on stderr means the call still succeeded; do not re-run it.
|
|
51
|
+
- 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.
|
|
52
|
+
|
|
53
|
+
## Recipes
|
|
54
|
+
|
|
55
|
+
These recipes name tools as examples. Before each one:
|
|
56
|
+
|
|
57
|
+
- **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.
|
|
58
|
+
- **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.
|
|
59
|
+
- **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.
|
|
60
|
+
- **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.
|
|
61
|
+
- **Show a plan first** for more than one batch (Rule 7).
|
|
62
|
+
- Paging and batching are manual for now: a hand-written page loop and sorted id batches, as below.
|
|
63
|
+
|
|
64
|
+
### Match an account list
|
|
65
|
+
|
|
66
|
+
**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.
|
|
67
|
+
**Batch:** read `maxItems` on `hg_ids` in `company_firmographic`'s `input_schema`.
|
|
68
|
+
**Order:**
|
|
69
|
+
|
|
70
|
+
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`.
|
|
71
|
+
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`.
|
|
72
|
+
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.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
hgi call search_companies --input '{"company_identifiers":{"name":"Accor"},"firmographics":{"country_codes":[{"ids":["FR"],"inclusion_method":"ANY_PRESENT"}],"revenue":{"min":1000000000}},"limit":5}'
|
|
76
|
+
hgi call company_firmographic --input '{"hg_ids":["<id1>","<id2>"]}' --select companies.company_id,companies.firmographics.name,companies.firmographics.country_code,companies.firmographics.company_level
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Score fit and propensity
|
|
80
|
+
|
|
81
|
+
**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.
|
|
82
|
+
**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.
|
|
83
|
+
**Order:**
|
|
84
|
+
|
|
85
|
+
1. **Fit:** `company_technographic` on a sorted batch of `hg_ids`, filtered (`vendor_names`, `product_names` or `category_ids`) so pages stay small. Page with `offset`. Stop on a short page (fewer rows than `max_results`), once `total_installs_count` is reached, or at the schema's `offset` maximum. Don't stop on `has_more` alone: it can be wrong at page boundaries. At the `offset` maximum, report the result as partial and narrow the filter.
|
|
86
|
+
2. **Topics:** resolve curated topic names to ids with `list_intent_topics`.
|
|
87
|
+
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.
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# technographics page loop (needs jq); page size and offset maximum come from the schema
|
|
92
|
+
dir=$(mktemp -d) # a fresh directory per run, so concurrent runs never share files
|
|
93
|
+
schema=$(hgi tools list --json | jq '.tools[] | select(.name=="company_technographic") | .input_schema.properties')
|
|
94
|
+
max=$(jq '.max_results.maximum' <<<"$schema"); maxoff=$(jq '.offset.maximum' <<<"$schema")
|
|
95
|
+
ids='["<id1>","<id2>"]'; off=0 # one sorted batch of at most hg_ids.maxItems ids
|
|
96
|
+
while [ "$ids" != "[]" ]; do
|
|
97
|
+
if [ "$off" -gt "$maxoff" ]; then echo "partial: offset maximum reached for $ids" >&2; break; fi
|
|
98
|
+
hgi call company_technographic --input "{\"hg_ids\":$ids,\"vendor_names\":[\"<vendor>\"],\"max_results\":$max,\"offset\":$off}" -f json > "$dir/tech-$off.json" || break
|
|
99
|
+
# next page only for companies that filled this page and are short of their stated total, sorted
|
|
100
|
+
ids=$(jq -c --argjson max "$max" --argjson off "$off" '[.companies[] | select(.installs_count == $max and $off + $max < .total_installs_count) | .company_id] | sort' "$dir/tech-$off.json")
|
|
101
|
+
off=$((off + max))
|
|
102
|
+
done
|
|
103
|
+
hgi call company_intent --input '{"company_domain":"accor.com"}'
|
|
104
|
+
hgi call company_intent --input '{"company_domain":"accor.com","fields":["summary"],"topic_ids":["<topic id>"]}'
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Size wallet from spend
|
|
108
|
+
|
|
109
|
+
**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.
|
|
110
|
+
**Batch:** read `maxItems` on `hg_ids` in `company_spend`'s `input_schema`, and the maximum of `max_results`.
|
|
111
|
+
**Order:**
|
|
112
|
+
|
|
113
|
+
1. Use the `hg_id`s from the matching recipe, sorted.
|
|
114
|
+
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.
|
|
115
|
+
3. One `company_spend` call per batch of `hg_ids`, with `category_ids` set in that same call, not filtered afterwards.
|
|
116
|
+
4. Page with `max_results` and `offset` only when `all_count` exceeds the rows returned, with the same stop rule as technographics.
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
hgi call company_spend --input '{"hg_ids":["<id1>","<id2>"],"category_ids":["<category id>"]}' --select companies.company_id,companies.spend.all
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Data semantics
|
|
124
|
+
|
|
125
|
+
Verified with one live call per tool. "Scope" is what a call returns by default.
|
|
126
|
+
|
|
127
|
+
| Tool | Default scope | Nullable fields (what null means) |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `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 |
|
|
130
|
+
| `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 |
|
|
131
|
+
| `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) |
|
|
132
|
+
| `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 |
|
|
133
|
+
| `company_spend` | country: every row has a `country_code` | no field came back null in the verification call; treat a missing field as unknown |
|
|
134
|
+
|
|
135
|
+
Not null, but easy to misread:
|
|
136
|
+
|
|
137
|
+
- A batch response leaves out companies it didn't match. A left-out company is unknown, not zero.
|
|
138
|
+
- `company_domain` is `""` when you query by `hg_ids`.
|
|
139
|
+
- `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.
|
|
140
|
+
|
|
141
|
+
**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
142
|
|
|
47
143
|
## Exit codes
|
|
48
144
|
|
|
@@ -55,13 +151,20 @@ hgi run <tool> --input '{...}' # only after the user a
|
|
|
55
151
|
| 2 | invalid input or usage | fix the input; the JSON error lists the problem fields |
|
|
56
152
|
| 3 | the tool reported an error | read the message; do not blindly retry |
|
|
57
153
|
| 4 | not signed in, or login expired | ask the user to run `hgi auth login` |
|
|
154
|
+
| 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 |
|
|
58
155
|
| 5 | rate limited | wait `retry_after_seconds` from the error, then retry |
|
|
59
|
-
| 6 | out of credits | stop; tell the user. Retrying will not help |
|
|
156
|
+
| 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
157
|
| 7 | server unreachable | retry later. If `outcome_unknown` is `true`, check state before re-running a `run` |
|
|
158
|
+
| 7 `governance_unavailable` | the server could not check the budget; nothing ran (`retryable: true`) | wait a little, then retry once; hgi never retries it itself |
|
|
61
159
|
| 8 | OAuth or sign-in failure | ask the user to run `hgi auth login` again |
|
|
62
160
|
| 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
161
|
| 10 | wrong verb | use the verb the error names |
|
|
64
|
-
| 11 | forbidden | the account or
|
|
162
|
+
| 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
163
|
| 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 |
|
|
164
|
+
| 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` |
|
|
165
|
+
|
|
166
|
+
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.
|
|
167
|
+
|
|
168
|
+
## Run cap
|
|
66
169
|
|
|
67
|
-
|
|
170
|
+
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.
|