spendbyteam 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +139 -2
- package/dist/checks.js +81 -0
- package/dist/cli.js +98 -0
- package/dist/constants.js +11 -0
- package/dist/doctor.js +71 -0
- package/dist/env.js +90 -0
- package/dist/fsutil.js +51 -0
- package/dist/init.js +76 -0
- package/dist/log.js +11 -0
- package/dist/managed.js +11 -0
- package/dist/paths.js +26 -0
- package/dist/settings.js +164 -0
- package/dist/state.js +35 -0
- package/dist/status.js +83 -0
- package/dist/uninstall.js +34 -0
- package/hook/hook.sh +37 -0
- package/package.json +44 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SpendByTeam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,140 @@
|
|
|
1
|
-
#
|
|
1
|
+
# spendbyteam
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect [Claude Code](https://code.claude.com) to **SpendByTeam** and see AI coding spend per team, project and client.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx spendbyteam init --token=sbt_ing_xxxxxxxx
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
This package is open source (MIT) so you can check exactly what leaves your machine. The short version: **numbers only.** No prompts, no code, no file contents, no file paths.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What gets sent
|
|
14
|
+
|
|
15
|
+
There are only two data flows. Both use your write-only ingest token (`sbt_ing_...`). It can send data but cannot read anything back.
|
|
16
|
+
|
|
17
|
+
### 1. Claude Code OpenTelemetry metrics (sent by Claude Code itself)
|
|
18
|
+
|
|
19
|
+
`init` turns on Claude Code's built-in telemetry, **metrics only**:
|
|
20
|
+
|
|
21
|
+
| Setting | Value | Why |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `CLAUDE_CODE_ENABLE_TELEMETRY` | `1` | turn telemetry on |
|
|
24
|
+
| `OTEL_METRICS_EXPORTER` | `otlp` | send metrics |
|
|
25
|
+
| `OTEL_LOGS_EXPORTER` | `none` | **no log events** (these can carry prompts and tool details) |
|
|
26
|
+
| `OTEL_TRACES_EXPORTER` | `none` | **no traces** |
|
|
27
|
+
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `http/json` | |
|
|
28
|
+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | `https://ingest.spendbyteam.com` | |
|
|
29
|
+
| `OTEL_EXPORTER_OTLP_HEADERS` | `Authorization=Bearer sbt_ing_...` | your ingest token |
|
|
30
|
+
| `OTEL_METRICS_INCLUDE_SESSION_ID` | `true` | group metrics per session |
|
|
31
|
+
| `OTEL_METRICS_INCLUDE_REPOSITORY` | `true` | map cost to a project (Claude Code ≥ 2.1.269) |
|
|
32
|
+
| `OTEL_METRICS_INCLUDE_VERSION` | `true` | Claude Code version |
|
|
33
|
+
| `OTEL_METRIC_EXPORT_INTERVAL` | `60000` | once a minute |
|
|
34
|
+
| `OTEL_RESOURCE_ATTRIBUTES` | `team.id=<id>` | only if you pass `--team-id` |
|
|
35
|
+
|
|
36
|
+
The content flags `OTEL_LOG_USER_PROMPTS`, `OTEL_LOG_TOOL_DETAILS` and `OTEL_LOG_RAW_API_BODIES` are **never set**. They stay off (the default).
|
|
37
|
+
|
|
38
|
+
Claude Code then sends counters such as `claude_code.cost.usage`, `claude_code.token.usage`, `claude_code.session.count`, `claude_code.lines_of_code.count`, `claude_code.commit.count`, `claude_code.pull_request.count`, `claude_code.code_edit_tool.decision` and `claude_code.active_time.total`. Each one comes with attributes like `session.id`, `user.email`, `organization.id`, `model`, `type` and `vcs.repository.url.full`.
|
|
39
|
+
|
|
40
|
+
The server keeps only an allowlist of attributes and drops everything else:
|
|
41
|
+
`session.id, user.email, user.account_uuid, organization.id, model, type, query_source, agent.name, skill.name, decision, start_type, vcs.repository.url.full, vcs.repository.name, vcs.owner.name, vcs.provider.name, team.id, app.version, terminal.type`.
|
|
42
|
+
`/v1/logs` and `/v1/traces` accept requests and throw them away unread, even if some other setting turns those exporters on.
|
|
43
|
+
|
|
44
|
+
### 2. The context hook (`~/.spendbyteam/hook.sh`)
|
|
45
|
+
|
|
46
|
+
OTel metrics don't include your git branch, so a small hook runs on the `SessionStart` and `CwdChanged` events (async, so it never slows Claude Code down). It sends **one** request to `POST {endpoint}/v1/context`. This is the complete body:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"session_id": "6f1c1f1e-3a51-4c2e-9d4c-5f0e2b7d8a90",
|
|
51
|
+
"event": "SessionStart",
|
|
52
|
+
"repo_url": "https://github.com/acme/web.git",
|
|
53
|
+
"branch": "feature/ABC-123-login",
|
|
54
|
+
"ticket": "ABC-123",
|
|
55
|
+
"at": "2026-11-03T09:14:05Z"
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| Field | Source |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `session_id` | from Claude Code's hook input |
|
|
62
|
+
| `event` | `SessionStart` or `CwdChanged` |
|
|
63
|
+
| `repo_url` | `git config --get remote.origin.url`, with embedded credentials, query and fragment removed (`https://user:token@host/...` → `https://host/...`). Local-path and `file://` remotes are never sent (empty string). |
|
|
64
|
+
| `branch` | `git rev-parse --abbrev-ref HEAD`; empty in a repo without commits or on a detached HEAD |
|
|
65
|
+
| `ticket` | first `ABC-123` style match in the branch name, otherwise empty |
|
|
66
|
+
| `at` | current UTC time |
|
|
67
|
+
|
|
68
|
+
The hook **never** sends the working directory path (`cwd`), your username or home directory, the transcript path, or any file contents. Outside a git repo, `repo_url`, `branch` and `ticket` are empty strings.
|
|
69
|
+
|
|
70
|
+
The hook always exits `0`. If something is missing or broken (no config, no `jq`, no network, not a git repo), it does nothing and can never break a Claude Code session. Read it yourself: [`hook/hook.sh`](hook/hook.sh) is about 35 lines. The token is passed to `curl` through a file descriptor, never on its command line, and nothing is sent unless the endpoint is `https://` (plain `http://` only for localhost).
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx spendbyteam init --token=sbt_ing_... [--endpoint=URL] [--team-id=ID] [--no-ping]
|
|
78
|
+
npx spendbyteam status
|
|
79
|
+
npx spendbyteam doctor [--no-ping]
|
|
80
|
+
npx spendbyteam uninstall
|
|
81
|
+
npx spendbyteam print-managed --token=sbt_ing_... [--endpoint=URL] [--team-id=ID]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `init`
|
|
85
|
+
|
|
86
|
+
1. Runs `claude --version` and warns if it is older than **2.1.269**. Older versions don't send repository attributes, so project mapping falls back to the hook. It also warns if `claude` isn't installed. Neither stops the install.
|
|
87
|
+
2. Warns if `jq`, `git` or `curl` is missing. The hook needs them; the cost metrics don't.
|
|
88
|
+
3. **Merges** the env block and the two hooks into `~/.claude/settings.json`:
|
|
89
|
+
- copies the current file to `~/.claude/settings.json.bak` before it writes anything
|
|
90
|
+
- keeps every other setting, env var and hook as it was
|
|
91
|
+
- is idempotent: running it again changes nothing, and running it with a new token or endpoint updates the existing entries in place (no duplicate hooks)
|
|
92
|
+
- stops without writing anything if `settings.json` is not valid JSON
|
|
93
|
+
- restricts the file to the owner (`go-rwx`), because it now contains the ingest token
|
|
94
|
+
4. Writes `~/.spendbyteam/config.json` as `{ "token": "...", "endpoint": "..." }` with mode **600** (directory 700). The hook reads it because Claude Code doesn't pass `OTEL_*` variables to hooks.
|
|
95
|
+
5. Writes `~/.spendbyteam/state.json` (mode 600): the values your env keys had before the install, so `uninstall` can put them back.
|
|
96
|
+
6. Copies the hook to `~/.spendbyteam/hook.sh` (mode 755).
|
|
97
|
+
7. Sends `GET {endpoint}/v1/ping` with the token so the panel shows the machine as connected. Skip this with `--no-ping`.
|
|
98
|
+
|
|
99
|
+
Restart running Claude Code sessions afterwards.
|
|
100
|
+
|
|
101
|
+
### `uninstall`
|
|
102
|
+
|
|
103
|
+
Removes the two hook entries, restores env keys to their pre-install values (deleting keys that didn't exist before) and deletes `~/.spendbyteam/`. If you changed one of those keys yourself after installing, your value is kept. Before writing, it saves a backup to `~/.claude/settings.json.bak`. That backup still contains the ingest token; delete it if you don't need it.
|
|
104
|
+
|
|
105
|
+
### `status` / `doctor`
|
|
106
|
+
|
|
107
|
+
`status` shows what is installed and exits `1` if anything is missing. `doctor` also checks `jq`/`git`/`curl`, the Claude Code version, the config file's permissions and whether the hook is executable, and pings the endpoint. It exits `1` if any check fails.
|
|
108
|
+
|
|
109
|
+
### `print-managed` (Team / Enterprise)
|
|
110
|
+
|
|
111
|
+
Prints [managed settings](https://code.claude.com/docs/en/settings) JSON with the same `env` block, so an admin can roll it out to everyone at once:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npx spendbyteam print-managed --token=sbt_ing_... > managed-settings.json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Put the file at `/Library/Application Support/ClaudeCode/managed-settings.json` (macOS) or `/etc/claude-code/managed-settings.json` (Linux/WSL), or paste it into server-managed settings (this also covers claude.ai/code cloud sessions). When the endpoint and headers come from managed settings, Claude Code ignores endpoints set by individual developers. The hook needs a script on each machine, so it isn't included here; developers who want branch/ticket attribution also run `npx spendbyteam init`.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Requirements
|
|
122
|
+
|
|
123
|
+
- Node.js ≥ 18.17 (only for running the CLI; nothing stays running)
|
|
124
|
+
- macOS, Linux or WSL
|
|
125
|
+
- Claude Code ≥ 2.1.269 recommended
|
|
126
|
+
- `jq`, `git`, `curl` for the context hook
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm install
|
|
132
|
+
npm test # vitest unit tests (temporary HOME) + shell tests for hook.sh
|
|
133
|
+
npm run build # → dist/
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The unit tests run every command against a throwaway `HOME` and a fake `PATH`, so they never touch your real `~/.claude`. `test/hook.test.sh` runs the real `hook.sh` with a fake `curl` and checks the exact payload: no `cwd`, credentials removed from the remote, exit 0 on any failure.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
[MIT](LICENSE)
|
package/dist/checks.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { HOOK_DEPS, MIN_CLAUDE_VERSION } from './constants.js';
|
|
5
|
+
/** Look a binary up on PATH without spawning a shell. */
|
|
6
|
+
export function which(name, envPath = process.env.PATH ?? '') {
|
|
7
|
+
for (const dir of envPath.split(path.delimiter)) {
|
|
8
|
+
if (!dir)
|
|
9
|
+
continue;
|
|
10
|
+
const candidate = path.join(dir, name);
|
|
11
|
+
try {
|
|
12
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
13
|
+
if (fs.statSync(candidate).isFile())
|
|
14
|
+
return candidate;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* not here */
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
export function missingDeps(envPath) {
|
|
23
|
+
return HOOK_DEPS.filter((d) => !which(d, envPath));
|
|
24
|
+
}
|
|
25
|
+
export function parseVersion(text) {
|
|
26
|
+
const m = /(\d+)\.(\d+)\.(\d+)/.exec(text);
|
|
27
|
+
if (!m)
|
|
28
|
+
return undefined;
|
|
29
|
+
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
30
|
+
}
|
|
31
|
+
export function compareVersions(a, b) {
|
|
32
|
+
for (let i = 0; i < 3; i++) {
|
|
33
|
+
const d = a[i] - b[i];
|
|
34
|
+
if (d !== 0)
|
|
35
|
+
return d < 0 ? -1 : 1;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
export function checkClaudeVersion() {
|
|
40
|
+
const bin = which('claude');
|
|
41
|
+
if (!bin)
|
|
42
|
+
return { status: 'missing' };
|
|
43
|
+
const res = spawnSync(bin, ['--version'], { encoding: 'utf8', timeout: 10_000 });
|
|
44
|
+
const out = `${res.stdout ?? ''}${res.stderr ?? ''}`.trim();
|
|
45
|
+
const v = parseVersion(out);
|
|
46
|
+
if (!v)
|
|
47
|
+
return { status: 'unknown', output: out };
|
|
48
|
+
const version = v.join('.');
|
|
49
|
+
const min = parseVersion(MIN_CLAUDE_VERSION);
|
|
50
|
+
return compareVersions(v, min) >= 0 ? { status: 'ok', version } : { status: 'old', version };
|
|
51
|
+
}
|
|
52
|
+
export function describeClaudeVersion(c) {
|
|
53
|
+
switch (c.status) {
|
|
54
|
+
case 'ok':
|
|
55
|
+
return `Claude Code ${c.version} (>= ${MIN_CLAUDE_VERSION})`;
|
|
56
|
+
case 'old':
|
|
57
|
+
return `Claude Code ${c.version} is older than ${MIN_CLAUDE_VERSION}: repository attributes (vcs.*) will not be sent; projects fall back to hook context. Update with "claude update".`;
|
|
58
|
+
case 'missing':
|
|
59
|
+
return `"claude" was not found on PATH. Settings are written anyway; install Claude Code >= ${MIN_CLAUDE_VERSION}.`;
|
|
60
|
+
case 'unknown':
|
|
61
|
+
return `Could not read the Claude Code version (got: ${c.output || 'no output'}). Make sure it is >= ${MIN_CLAUDE_VERSION}.`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** GET {endpoint}/v1/ping with the ingest token (TECHNICAL.md §5). */
|
|
65
|
+
export async function ping(endpoint, token, timeoutMs = 5000) {
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(`${endpoint}/v1/ping`, {
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers: { Authorization: `Bearer ${token}`, 'User-Agent': 'spendbyteam-cli' },
|
|
70
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
71
|
+
});
|
|
72
|
+
if (res.ok)
|
|
73
|
+
return { ok: true, status: res.status };
|
|
74
|
+
if (res.status === 401 || res.status === 403)
|
|
75
|
+
return { ok: false, error: `token rejected (HTTP ${res.status})` };
|
|
76
|
+
return { ok: false, error: `HTTP ${res.status}` };
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
return { ok: false, error: err.message };
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { init } from './init.js';
|
|
5
|
+
import { uninstall } from './uninstall.js';
|
|
6
|
+
import { status } from './status.js';
|
|
7
|
+
import { doctor } from './doctor.js';
|
|
8
|
+
import { managedSettingsJson } from './managed.js';
|
|
9
|
+
import { UsageError } from './env.js';
|
|
10
|
+
import { JsonFileError } from './fsutil.js';
|
|
11
|
+
import { consoleLogger } from './log.js';
|
|
12
|
+
const HELP = `spendbyteam — connect Claude Code to SpendByTeam (metrics only, no prompts or code)
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
npx spendbyteam init --token=sbt_ing_... [--endpoint=URL] [--team-id=ID] [--no-ping]
|
|
16
|
+
npx spendbyteam uninstall
|
|
17
|
+
npx spendbyteam status
|
|
18
|
+
npx spendbyteam doctor [--no-ping]
|
|
19
|
+
npx spendbyteam print-managed --token=sbt_ing_... [--endpoint=URL] [--team-id=ID]
|
|
20
|
+
|
|
21
|
+
Commands:
|
|
22
|
+
init Merge the OTel env + context hook into ~/.claude/settings.json (backup: settings.json.bak),
|
|
23
|
+
write ~/.spendbyteam/config.json (mode 600) and ~/.spendbyteam/hook.sh. Safe to re-run.
|
|
24
|
+
uninstall Undo everything init did (restores env values that existed before).
|
|
25
|
+
status Show what is installed.
|
|
26
|
+
doctor Check jq/git/curl, Claude Code version, settings, permissions and connectivity.
|
|
27
|
+
print-managed Print managed-settings JSON for Team/Enterprise admins (stdout).
|
|
28
|
+
|
|
29
|
+
Options:
|
|
30
|
+
--token Ingest token from the SpendByTeam panel (write-only).
|
|
31
|
+
--endpoint Ingest endpoint (default https://ingest.spendbyteam.com).
|
|
32
|
+
--team-id Optional static team id, sent as OTEL_RESOURCE_ATTRIBUTES=team.id=<id>.
|
|
33
|
+
--no-ping Skip the GET /v1/ping connectivity test.
|
|
34
|
+
-h, --help Show this help.
|
|
35
|
+
-v, --version Show version.
|
|
36
|
+
`;
|
|
37
|
+
function version() {
|
|
38
|
+
const require = createRequire(import.meta.url);
|
|
39
|
+
return require('../package.json').version;
|
|
40
|
+
}
|
|
41
|
+
export async function main(argv) {
|
|
42
|
+
const { values, positionals } = parseArgs({
|
|
43
|
+
args: argv,
|
|
44
|
+
allowPositionals: true,
|
|
45
|
+
strict: true,
|
|
46
|
+
options: {
|
|
47
|
+
token: { type: 'string' },
|
|
48
|
+
endpoint: { type: 'string' },
|
|
49
|
+
'team-id': { type: 'string' },
|
|
50
|
+
'no-ping': { type: 'boolean', default: false },
|
|
51
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
52
|
+
version: { type: 'boolean', short: 'v', default: false },
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
if (values.version) {
|
|
56
|
+
console.log(version());
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
const cmd = positionals[0];
|
|
60
|
+
if (values.help || !cmd || cmd === 'help') {
|
|
61
|
+
console.log(HELP);
|
|
62
|
+
return cmd || values.help ? 0 : 1;
|
|
63
|
+
}
|
|
64
|
+
if (positionals.length > 1)
|
|
65
|
+
throw new UsageError(`Unexpected argument: ${positionals[1]}`);
|
|
66
|
+
const envOpts = { token: values.token ?? '', endpoint: values.endpoint, teamId: values['team-id'] };
|
|
67
|
+
switch (cmd) {
|
|
68
|
+
case 'init':
|
|
69
|
+
await init({ ...envOpts, ping: !values['no-ping'] });
|
|
70
|
+
return 0;
|
|
71
|
+
case 'uninstall':
|
|
72
|
+
uninstall();
|
|
73
|
+
return 0;
|
|
74
|
+
case 'status':
|
|
75
|
+
return status().installed ? 0 : 1;
|
|
76
|
+
case 'doctor':
|
|
77
|
+
return (await doctor({ ping: !values['no-ping'] })) ? 0 : 1;
|
|
78
|
+
case 'print-managed':
|
|
79
|
+
process.stdout.write(managedSettingsJson(envOpts));
|
|
80
|
+
console.error('# Put this in managed-settings.json (macOS: /Library/Application Support/ClaudeCode/, Linux/WSL: /etc/claude-code/)\n' +
|
|
81
|
+
'# or in server-managed settings. Developers still run `npx spendbyteam init` for the branch/ticket hook.');
|
|
82
|
+
return 0;
|
|
83
|
+
default:
|
|
84
|
+
throw new UsageError(`Unknown command "${cmd}". Run "npx spendbyteam --help".`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
main(process.argv.slice(2)).then((code) => {
|
|
88
|
+
process.exitCode = code;
|
|
89
|
+
}, (err) => {
|
|
90
|
+
if (err instanceof UsageError || err instanceof JsonFileError || err.code?.startsWith('ERR_PARSE_ARGS')) {
|
|
91
|
+
consoleLogger.error(err.message);
|
|
92
|
+
process.exitCode = 2;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
consoleLogger.error(`Unexpected error: ${err.stack ?? String(err)}`);
|
|
96
|
+
process.exitCode = 1;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const DEFAULT_ENDPOINT = 'https://ingest.spendbyteam.com';
|
|
2
|
+
export const MIN_CLAUDE_VERSION = '2.1.269';
|
|
3
|
+
/** Command written into ~/.claude/settings.json (TECHNICAL.md §4.1). */
|
|
4
|
+
export const HOOK_COMMAND = '~/.spendbyteam/hook.sh';
|
|
5
|
+
export const HOOK_EVENTS = ['SessionStart', 'CwdChanged'];
|
|
6
|
+
export const HOOK_TIMEOUT_SECONDS = 10;
|
|
7
|
+
/** Any hook command pointing at our script counts as "ours" (also absolute-path variants). */
|
|
8
|
+
export const HOOK_COMMAND_RE = /(^|\/)\.spendbyteam\/hook\.sh$/;
|
|
9
|
+
export const TOKEN_RE = /^sbt_ing_[A-Za-z0-9_-]{8,}$/;
|
|
10
|
+
/** Dependencies the hook script needs at runtime. */
|
|
11
|
+
export const HOOK_DEPS = ['jq', 'git', 'curl'];
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HOOK_DEPS } from './constants.js';
|
|
2
|
+
import { checkClaudeVersion, describeClaudeVersion, missingDeps, ping } from './checks.js';
|
|
3
|
+
import { collectStatus } from './status.js';
|
|
4
|
+
import { paths } from './paths.js';
|
|
5
|
+
import { consoleLogger } from './log.js';
|
|
6
|
+
export async function runDoctor(opts = {}) {
|
|
7
|
+
const p = paths();
|
|
8
|
+
const checks = [];
|
|
9
|
+
const add = (level, name, detail) => checks.push({ level, name, detail });
|
|
10
|
+
const missing = missingDeps();
|
|
11
|
+
for (const dep of HOOK_DEPS) {
|
|
12
|
+
if (missing.includes(dep))
|
|
13
|
+
add('warn', dep, `${dep} not found on PATH: the context hook (branch/ticket) will not send anything`);
|
|
14
|
+
else
|
|
15
|
+
add('ok', dep, `${dep} found`);
|
|
16
|
+
}
|
|
17
|
+
const claude = checkClaudeVersion();
|
|
18
|
+
add(claude.status === 'ok' ? 'ok' : 'warn', 'claude', describeClaudeVersion(claude));
|
|
19
|
+
const s = collectStatus();
|
|
20
|
+
if (!s.config)
|
|
21
|
+
add('fail', 'config', `${p.config} missing or invalid (run init)`);
|
|
22
|
+
else
|
|
23
|
+
add('ok', 'config', `${p.config}`);
|
|
24
|
+
if (s.configMode !== undefined) {
|
|
25
|
+
if (s.configMode === 0o600)
|
|
26
|
+
add('ok', 'config mode', '600');
|
|
27
|
+
else
|
|
28
|
+
add('fail', 'config mode', `${s.configMode.toString(8)} (expected 600; fix: chmod 600 ${p.config})`);
|
|
29
|
+
}
|
|
30
|
+
if (s.settingsError)
|
|
31
|
+
add('fail', 'settings', s.settingsError);
|
|
32
|
+
else if (s.inspection) {
|
|
33
|
+
if (s.inspection.envMatches)
|
|
34
|
+
add('ok', 'settings env', 'OTel env present and matches config');
|
|
35
|
+
else
|
|
36
|
+
add('fail', 'settings env', `missing or changed: ${s.inspection.mismatchedKeys.join(', ') || 'no config to compare'}`);
|
|
37
|
+
for (const [event, ok] of Object.entries(s.inspection.hookEvents)) {
|
|
38
|
+
add(ok ? 'ok' : 'fail', `${event} hook`, ok ? 'registered' : 'not registered in settings.json');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!s.hookInstalled)
|
|
42
|
+
add('fail', 'hook.sh', `${p.hook} missing`);
|
|
43
|
+
else if (!s.hookExecutable)
|
|
44
|
+
add('fail', 'hook.sh', `${p.hook} not executable (fix: chmod +x ${p.hook})`);
|
|
45
|
+
else
|
|
46
|
+
add('ok', 'hook.sh', p.hook);
|
|
47
|
+
if (opts.ping !== false && s.config) {
|
|
48
|
+
const r = await ping(s.config.endpoint, s.config.token);
|
|
49
|
+
if (r.ok)
|
|
50
|
+
add('ok', 'ingest', `${s.config.endpoint}/v1/ping reachable`);
|
|
51
|
+
else
|
|
52
|
+
add('fail', 'ingest', `${s.config.endpoint}/v1/ping: ${r.error}`);
|
|
53
|
+
}
|
|
54
|
+
return checks;
|
|
55
|
+
}
|
|
56
|
+
export async function doctor(opts = {}) {
|
|
57
|
+
const log = opts.logger ?? consoleLogger;
|
|
58
|
+
const checks = await runDoctor(opts);
|
|
59
|
+
for (const c of checks) {
|
|
60
|
+
const line = `${c.name}: ${c.detail}`;
|
|
61
|
+
if (c.level === 'ok')
|
|
62
|
+
log.ok(line);
|
|
63
|
+
else if (c.level === 'warn')
|
|
64
|
+
log.warn(line);
|
|
65
|
+
else
|
|
66
|
+
log.error(line);
|
|
67
|
+
}
|
|
68
|
+
const failed = checks.filter((c) => c.level === 'fail').length;
|
|
69
|
+
log.info(failed === 0 ? 'No problems found.' : `${failed} problem(s) found.`);
|
|
70
|
+
return failed === 0;
|
|
71
|
+
}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DEFAULT_ENDPOINT, TOKEN_RE } from './constants.js';
|
|
2
|
+
export function validateToken(token) {
|
|
3
|
+
if (!token)
|
|
4
|
+
throw new UsageError('Missing --token (get it from the SpendByTeam panel: sbt_ing_...).');
|
|
5
|
+
const t = token.trim();
|
|
6
|
+
if (!TOKEN_RE.test(t)) {
|
|
7
|
+
throw new UsageError('Invalid token: expected an ingest token like "sbt_ing_..." (letters, digits, "_" or "-").');
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
}
|
|
11
|
+
/** Normalises the ingest endpoint. Only https is allowed, except http for localhost (development). */
|
|
12
|
+
export function normalizeEndpoint(endpoint) {
|
|
13
|
+
const raw = (endpoint ?? DEFAULT_ENDPOINT).trim();
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(raw);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new UsageError(`Invalid --endpoint: ${raw}`);
|
|
20
|
+
}
|
|
21
|
+
const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
22
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && local)) {
|
|
23
|
+
throw new UsageError('--endpoint must use https:// (http:// is only allowed for localhost).');
|
|
24
|
+
}
|
|
25
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
26
|
+
throw new UsageError('--endpoint must not contain credentials, query or fragment.');
|
|
27
|
+
}
|
|
28
|
+
return url.toString().replace(/\/+$/, '');
|
|
29
|
+
}
|
|
30
|
+
export function validateTeamId(teamId) {
|
|
31
|
+
if (teamId === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
const t = teamId.trim();
|
|
34
|
+
// OTEL_RESOURCE_ATTRIBUTES is a comma separated k=v list; keep the value static and simple (§3.3).
|
|
35
|
+
if (!/^[A-Za-z0-9._-]{1,64}$/.test(t)) {
|
|
36
|
+
throw new UsageError('--team-id may only contain letters, digits, ".", "_" or "-" (max 64 chars).');
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The OTel env block from TECHNICAL.md §3.1. Metrics only: logs and traces exporters are
|
|
42
|
+
* explicitly "none" and content flags (OTEL_LOG_USER_PROMPTS etc.) are never touched.
|
|
43
|
+
*/
|
|
44
|
+
export function buildEnv(opts) {
|
|
45
|
+
const token = validateToken(opts.token);
|
|
46
|
+
const endpoint = normalizeEndpoint(opts.endpoint);
|
|
47
|
+
const teamId = validateTeamId(opts.teamId);
|
|
48
|
+
const env = {
|
|
49
|
+
CLAUDE_CODE_ENABLE_TELEMETRY: '1',
|
|
50
|
+
OTEL_METRICS_EXPORTER: 'otlp',
|
|
51
|
+
OTEL_LOGS_EXPORTER: 'none',
|
|
52
|
+
OTEL_TRACES_EXPORTER: 'none',
|
|
53
|
+
OTEL_EXPORTER_OTLP_PROTOCOL: 'http/json',
|
|
54
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: endpoint,
|
|
55
|
+
OTEL_EXPORTER_OTLP_HEADERS: `Authorization=Bearer ${token}`,
|
|
56
|
+
OTEL_METRICS_INCLUDE_SESSION_ID: 'true',
|
|
57
|
+
OTEL_METRICS_INCLUDE_REPOSITORY: 'true',
|
|
58
|
+
OTEL_METRICS_INCLUDE_VERSION: 'true',
|
|
59
|
+
OTEL_METRIC_EXPORT_INTERVAL: '60000',
|
|
60
|
+
};
|
|
61
|
+
if (teamId)
|
|
62
|
+
env.OTEL_RESOURCE_ATTRIBUTES = `team.id=${teamId}`;
|
|
63
|
+
return env;
|
|
64
|
+
}
|
|
65
|
+
/** Keys we may write; used by uninstall/status even when the original state file is gone. */
|
|
66
|
+
export const MANAGED_ENV_KEYS = [
|
|
67
|
+
'CLAUDE_CODE_ENABLE_TELEMETRY',
|
|
68
|
+
'OTEL_METRICS_EXPORTER',
|
|
69
|
+
'OTEL_LOGS_EXPORTER',
|
|
70
|
+
'OTEL_TRACES_EXPORTER',
|
|
71
|
+
'OTEL_EXPORTER_OTLP_PROTOCOL',
|
|
72
|
+
'OTEL_EXPORTER_OTLP_ENDPOINT',
|
|
73
|
+
'OTEL_EXPORTER_OTLP_HEADERS',
|
|
74
|
+
'OTEL_METRICS_INCLUDE_SESSION_ID',
|
|
75
|
+
'OTEL_METRICS_INCLUDE_REPOSITORY',
|
|
76
|
+
'OTEL_METRICS_INCLUDE_VERSION',
|
|
77
|
+
'OTEL_METRIC_EXPORT_INTERVAL',
|
|
78
|
+
'OTEL_RESOURCE_ATTRIBUTES',
|
|
79
|
+
];
|
|
80
|
+
export function maskToken(token) {
|
|
81
|
+
if (token.length <= 12)
|
|
82
|
+
return 'sbt_ing_****';
|
|
83
|
+
return `sbt_ing_****${token.slice(-4)}`;
|
|
84
|
+
}
|
|
85
|
+
export class UsageError extends Error {
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.name = 'UsageError';
|
|
89
|
+
}
|
|
90
|
+
}
|
package/dist/fsutil.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export class JsonFileError extends Error {
|
|
4
|
+
}
|
|
5
|
+
/** Returns undefined when the file does not exist; throws (never clobbers) when it is not valid JSON. */
|
|
6
|
+
export function readJsonObject(file) {
|
|
7
|
+
let text;
|
|
8
|
+
try {
|
|
9
|
+
text = fs.readFileSync(file, 'utf8');
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
if (err.code === 'ENOENT')
|
|
13
|
+
return undefined;
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
if (text.trim() === '')
|
|
17
|
+
return {};
|
|
18
|
+
let data;
|
|
19
|
+
try {
|
|
20
|
+
data = JSON.parse(text);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
throw new JsonFileError(`${file} is not valid JSON (${err.message}). Fix it first; nothing was changed.`);
|
|
24
|
+
}
|
|
25
|
+
if (!isPlainObject(data)) {
|
|
26
|
+
throw new JsonFileError(`${file} must contain a JSON object. Fix it first; nothing was changed.`);
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
export function isPlainObject(v) {
|
|
31
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
32
|
+
}
|
|
33
|
+
/** Write via temp file + rename so a crash never leaves a half-written settings file. */
|
|
34
|
+
export function writeFileAtomic(file, content, mode) {
|
|
35
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
36
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
37
|
+
fs.writeFileSync(tmp, content, { mode });
|
|
38
|
+
fs.chmodSync(tmp, mode);
|
|
39
|
+
fs.renameSync(tmp, file);
|
|
40
|
+
}
|
|
41
|
+
export function fileMode(file) {
|
|
42
|
+
try {
|
|
43
|
+
return fs.statSync(file).mode & 0o777;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function toJson(data) {
|
|
50
|
+
return `${JSON.stringify(data, null, 2)}\n`;
|
|
51
|
+
}
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { buildEnv, normalizeEndpoint, validateToken } from './env.js';
|
|
3
|
+
import { bundledHookPath, paths } from './paths.js';
|
|
4
|
+
import { fileMode, readJsonObject, toJson, writeFileAtomic } from './fsutil.js';
|
|
5
|
+
import { mergeSettings } from './settings.js';
|
|
6
|
+
import { readState, writeConfig, writeState, ensureSbtDir } from './state.js';
|
|
7
|
+
import { checkClaudeVersion, describeClaudeVersion, missingDeps, ping } from './checks.js';
|
|
8
|
+
import { consoleLogger } from './log.js';
|
|
9
|
+
export async function init(opts) {
|
|
10
|
+
const log = opts.logger ?? consoleLogger;
|
|
11
|
+
const token = validateToken(opts.token);
|
|
12
|
+
const endpoint = normalizeEndpoint(opts.endpoint);
|
|
13
|
+
const env = buildEnv({ token, endpoint, teamId: opts.teamId });
|
|
14
|
+
const p = paths();
|
|
15
|
+
// 1. Claude Code version (warn only).
|
|
16
|
+
const claude = checkClaudeVersion();
|
|
17
|
+
if (claude.status === 'ok')
|
|
18
|
+
log.ok(describeClaudeVersion(claude));
|
|
19
|
+
else
|
|
20
|
+
log.warn(describeClaudeVersion(claude));
|
|
21
|
+
const missing = missingDeps();
|
|
22
|
+
if (missing.length > 0) {
|
|
23
|
+
log.warn(`Missing ${missing.join(', ')}: the branch/ticket hook will silently do nothing until installed. Cost metrics still work.`);
|
|
24
|
+
}
|
|
25
|
+
// 2. Merge into ~/.claude/settings.json (reads first; aborts on invalid JSON before writing anything).
|
|
26
|
+
const existing = readJsonObject(p.settings);
|
|
27
|
+
const current = existing ?? {};
|
|
28
|
+
const prevState = readState();
|
|
29
|
+
const merged = mergeSettings(current, env, prevState ? { previousEnv: prevState.previous_env, appliedEnv: prevState.applied_env } : undefined);
|
|
30
|
+
const before = existing === undefined ? undefined : toJson(existing);
|
|
31
|
+
const after = toJson(merged.settings);
|
|
32
|
+
const settingsChanged = before !== after;
|
|
33
|
+
let backupPath;
|
|
34
|
+
if (settingsChanged) {
|
|
35
|
+
if (existing !== undefined) {
|
|
36
|
+
fs.copyFileSync(p.settings, p.settingsBackup);
|
|
37
|
+
backupPath = p.settingsBackup;
|
|
38
|
+
}
|
|
39
|
+
// The file now contains the ingest token in OTEL_EXPORTER_OTLP_HEADERS: keep it private.
|
|
40
|
+
const mode = (fileMode(p.settings) ?? 0o600) & 0o700;
|
|
41
|
+
writeFileAtomic(p.settings, after, mode);
|
|
42
|
+
log.ok(`Updated ${p.settings}${backupPath ? ` (backup: ${backupPath})` : ''}`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
log.ok(`${p.settings} already up to date`);
|
|
46
|
+
}
|
|
47
|
+
for (const k of merged.overwritten)
|
|
48
|
+
log.warn(`Replaced existing env ${k} (restored on uninstall).`);
|
|
49
|
+
// 3. ~/.spendbyteam/config.json (chmod 600) + state for a clean uninstall.
|
|
50
|
+
ensureSbtDir();
|
|
51
|
+
writeConfig({ token, endpoint });
|
|
52
|
+
const now = new Date().toISOString();
|
|
53
|
+
writeState({
|
|
54
|
+
version: 1,
|
|
55
|
+
installed_at: prevState?.installed_at ?? now,
|
|
56
|
+
updated_at: now,
|
|
57
|
+
previous_env: merged.previousEnv,
|
|
58
|
+
applied_env: env,
|
|
59
|
+
});
|
|
60
|
+
log.ok(`Wrote ${p.config} (mode 600)`);
|
|
61
|
+
// 4. Hook script.
|
|
62
|
+
fs.copyFileSync(bundledHookPath(), p.hook);
|
|
63
|
+
fs.chmodSync(p.hook, 0o755);
|
|
64
|
+
log.ok(`Installed ${p.hook}`);
|
|
65
|
+
// 5. Connectivity test.
|
|
66
|
+
let pingResult;
|
|
67
|
+
if (opts.ping !== false) {
|
|
68
|
+
pingResult = await ping(endpoint, token);
|
|
69
|
+
if (pingResult.ok)
|
|
70
|
+
log.ok(`Connected to ${endpoint} — the panel will show this machine as connected.`);
|
|
71
|
+
else
|
|
72
|
+
log.warn(`Could not reach ${endpoint}/v1/ping: ${pingResult.error}. Settings are installed; run "npx spendbyteam doctor" later.`);
|
|
73
|
+
}
|
|
74
|
+
log.info('Restart Claude Code sessions for the new settings to take effect.');
|
|
75
|
+
return { settingsChanged, backupPath, overwritten: merged.overwritten, missingDeps: missing, claude, ping: pingResult };
|
|
76
|
+
}
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const color = (code) => (s) => process.stdout.isTTY && !process.env.NO_COLOR ? `\x1b[${code}m${s}\x1b[0m` : s;
|
|
2
|
+
const green = color('32');
|
|
3
|
+
const yellow = color('33');
|
|
4
|
+
const red = color('31');
|
|
5
|
+
export const consoleLogger = {
|
|
6
|
+
info: (m) => console.log(m),
|
|
7
|
+
ok: (m) => console.log(`${green('✓')} ${m}`),
|
|
8
|
+
warn: (m) => console.warn(`${yellow('!')} ${m}`),
|
|
9
|
+
error: (m) => console.error(`${red('✗')} ${m}`),
|
|
10
|
+
};
|
|
11
|
+
export const silentLogger = { info() { }, ok() { }, warn() { }, error() { } };
|
package/dist/managed.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { buildEnv } from './env.js';
|
|
2
|
+
/**
|
|
3
|
+
* Managed settings (TECHNICAL.md §3.1) for Team/Enterprise admins. Only the env block: the hook
|
|
4
|
+
* needs ~/.spendbyteam/hook.sh on each machine, so it is installed per developer with `init`.
|
|
5
|
+
*/
|
|
6
|
+
export function managedSettings(opts) {
|
|
7
|
+
return { env: buildEnv(opts) };
|
|
8
|
+
}
|
|
9
|
+
export function managedSettingsJson(opts) {
|
|
10
|
+
return `${JSON.stringify(managedSettings(opts), null, 2)}\n`;
|
|
11
|
+
}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** Resolved lazily so tests (and users) can point HOME somewhere else. */
|
|
5
|
+
export function homeDir() {
|
|
6
|
+
return process.env.HOME && process.env.HOME.length > 0 ? process.env.HOME : os.homedir();
|
|
7
|
+
}
|
|
8
|
+
export function paths() {
|
|
9
|
+
const home = homeDir();
|
|
10
|
+
const claudeDir = path.join(home, '.claude');
|
|
11
|
+
const sbtDir = path.join(home, '.spendbyteam');
|
|
12
|
+
return {
|
|
13
|
+
home,
|
|
14
|
+
claudeDir,
|
|
15
|
+
settings: path.join(claudeDir, 'settings.json'),
|
|
16
|
+
settingsBackup: path.join(claudeDir, 'settings.json.bak'),
|
|
17
|
+
sbtDir,
|
|
18
|
+
config: path.join(sbtDir, 'config.json'),
|
|
19
|
+
state: path.join(sbtDir, 'state.json'),
|
|
20
|
+
hook: path.join(sbtDir, 'hook.sh'),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** hook/hook.sh shipped in the package (works from src/ under vitest and from dist/ when built). */
|
|
24
|
+
export function bundledHookPath() {
|
|
25
|
+
return fileURLToPath(new URL('../hook/hook.sh', import.meta.url));
|
|
26
|
+
}
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { HOOK_COMMAND, HOOK_COMMAND_RE, HOOK_EVENTS, HOOK_TIMEOUT_SECONDS } from './constants.js';
|
|
2
|
+
import { MANAGED_ENV_KEYS } from './env.js';
|
|
3
|
+
import { isPlainObject, JsonFileError } from './fsutil.js';
|
|
4
|
+
export function hookEntry() {
|
|
5
|
+
return { type: 'command', command: HOOK_COMMAND, async: true, timeout: HOOK_TIMEOUT_SECONDS };
|
|
6
|
+
}
|
|
7
|
+
function isOurHook(h) {
|
|
8
|
+
return isPlainObject(h) && typeof h.command === 'string' && HOOK_COMMAND_RE.test(h.command.trim());
|
|
9
|
+
}
|
|
10
|
+
function clone(v) {
|
|
11
|
+
return JSON.parse(JSON.stringify(v));
|
|
12
|
+
}
|
|
13
|
+
function envOf(settings, file = 'settings.json') {
|
|
14
|
+
if (settings.env === undefined)
|
|
15
|
+
return {};
|
|
16
|
+
if (!isPlainObject(settings.env))
|
|
17
|
+
throw new JsonFileError(`"env" in ${file} must be an object.`);
|
|
18
|
+
return settings.env;
|
|
19
|
+
}
|
|
20
|
+
function hooksOf(settings, file = 'settings.json') {
|
|
21
|
+
if (settings.hooks === undefined)
|
|
22
|
+
return {};
|
|
23
|
+
if (!isPlainObject(settings.hooks))
|
|
24
|
+
throw new JsonFileError(`"hooks" in ${file} must be an object.`);
|
|
25
|
+
return settings.hooks;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Merge our env block and hooks into existing settings without touching anything else.
|
|
29
|
+
* Idempotent: merging twice yields identical output. `prior` (from state.json) makes re-runs keep the
|
|
30
|
+
* original pre-install values and drops keys a previous run applied but this run no longer wants.
|
|
31
|
+
*/
|
|
32
|
+
export function mergeSettings(current, env, prior) {
|
|
33
|
+
const next = clone(current);
|
|
34
|
+
const curEnv = { ...envOf(next) };
|
|
35
|
+
const previousEnv = {};
|
|
36
|
+
const overwritten = [];
|
|
37
|
+
if (prior) {
|
|
38
|
+
for (const [key, applied] of Object.entries(prior.appliedEnv)) {
|
|
39
|
+
if (key in env || curEnv[key] !== applied)
|
|
40
|
+
continue;
|
|
41
|
+
const prev = prior.previousEnv[key];
|
|
42
|
+
if (prev === null || prev === undefined)
|
|
43
|
+
delete curEnv[key];
|
|
44
|
+
else
|
|
45
|
+
curEnv[key] = prev;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const [key, value] of Object.entries(env)) {
|
|
49
|
+
if (prior && key in prior.appliedEnv && key in prior.previousEnv) {
|
|
50
|
+
previousEnv[key] = prior.previousEnv[key] ?? null;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const has = Object.prototype.hasOwnProperty.call(curEnv, key);
|
|
54
|
+
previousEnv[key] = has ? String(curEnv[key]) : null;
|
|
55
|
+
if (has && String(curEnv[key]) !== value)
|
|
56
|
+
overwritten.push(key);
|
|
57
|
+
}
|
|
58
|
+
next.env = { ...curEnv, ...env };
|
|
59
|
+
const hooks = hooksOf(next);
|
|
60
|
+
for (const event of HOOK_EVENTS) {
|
|
61
|
+
const groups = hooks[event];
|
|
62
|
+
if (groups !== undefined && !Array.isArray(groups)) {
|
|
63
|
+
throw new JsonFileError(`"hooks.${event}" in settings.json must be an array.`);
|
|
64
|
+
}
|
|
65
|
+
const list = groups ? [...groups] : [];
|
|
66
|
+
let found = false;
|
|
67
|
+
for (let i = 0; i < list.length; i++) {
|
|
68
|
+
const g = list[i];
|
|
69
|
+
if (!isPlainObject(g) || !Array.isArray(g.hooks))
|
|
70
|
+
continue;
|
|
71
|
+
if (!g.hooks.some(isOurHook))
|
|
72
|
+
continue;
|
|
73
|
+
const inner = g.hooks
|
|
74
|
+
.map((h) => {
|
|
75
|
+
if (!isOurHook(h))
|
|
76
|
+
return h;
|
|
77
|
+
if (found)
|
|
78
|
+
return undefined; // drop duplicates of our hook
|
|
79
|
+
found = true;
|
|
80
|
+
return hookEntry();
|
|
81
|
+
})
|
|
82
|
+
.filter((h) => h !== undefined);
|
|
83
|
+
list[i] = inner.length > 0 ? { ...g, hooks: inner } : undefined;
|
|
84
|
+
}
|
|
85
|
+
if (!found)
|
|
86
|
+
list.push({ hooks: [hookEntry()] });
|
|
87
|
+
hooks[event] = list.filter((g) => g !== undefined);
|
|
88
|
+
}
|
|
89
|
+
next.hooks = hooks;
|
|
90
|
+
return { settings: next, previousEnv, overwritten };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Undo mergeSettings: remove our hooks and restore/remove our env keys.
|
|
94
|
+
* Without state (state.json lost) env keys are only removed when the OTLP headers carry an
|
|
95
|
+
* SpendByTeam token, so we never strip a different collector's configuration.
|
|
96
|
+
*/
|
|
97
|
+
export function removeSettings(current, opts = {}) {
|
|
98
|
+
const next = clone(current);
|
|
99
|
+
if (next.env !== undefined && isPlainObject(next.env)) {
|
|
100
|
+
const env = next.env;
|
|
101
|
+
if (opts.previousEnv && opts.appliedEnv) {
|
|
102
|
+
for (const [key, applied] of Object.entries(opts.appliedEnv)) {
|
|
103
|
+
if (!Object.prototype.hasOwnProperty.call(env, key))
|
|
104
|
+
continue;
|
|
105
|
+
if (String(env[key]) !== applied)
|
|
106
|
+
continue; // user changed it after install; keep
|
|
107
|
+
const prev = opts.previousEnv[key];
|
|
108
|
+
if (prev === null || prev === undefined)
|
|
109
|
+
delete env[key];
|
|
110
|
+
else
|
|
111
|
+
env[key] = prev;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (typeof env.OTEL_EXPORTER_OTLP_HEADERS === 'string' && env.OTEL_EXPORTER_OTLP_HEADERS.includes('sbt_ing_')) {
|
|
115
|
+
for (const key of MANAGED_ENV_KEYS)
|
|
116
|
+
delete env[key];
|
|
117
|
+
}
|
|
118
|
+
if (Object.keys(env).length === 0)
|
|
119
|
+
delete next.env;
|
|
120
|
+
}
|
|
121
|
+
if (next.hooks !== undefined && isPlainObject(next.hooks)) {
|
|
122
|
+
const hooks = next.hooks;
|
|
123
|
+
for (const event of HOOK_EVENTS) {
|
|
124
|
+
const groups = hooks[event];
|
|
125
|
+
if (!Array.isArray(groups))
|
|
126
|
+
continue;
|
|
127
|
+
const kept = groups
|
|
128
|
+
.map((g) => {
|
|
129
|
+
if (!isPlainObject(g) || !Array.isArray(g.hooks))
|
|
130
|
+
return g;
|
|
131
|
+
const had = g.hooks.length;
|
|
132
|
+
const inner = g.hooks.filter((h) => !isOurHook(h));
|
|
133
|
+
if (inner.length === had)
|
|
134
|
+
return g;
|
|
135
|
+
return inner.length === 0 ? undefined : { ...g, hooks: inner };
|
|
136
|
+
})
|
|
137
|
+
.filter((g) => g !== undefined);
|
|
138
|
+
if (kept.length === 0)
|
|
139
|
+
delete hooks[event];
|
|
140
|
+
else
|
|
141
|
+
hooks[event] = kept;
|
|
142
|
+
}
|
|
143
|
+
if (Object.keys(hooks).length === 0)
|
|
144
|
+
delete next.hooks;
|
|
145
|
+
}
|
|
146
|
+
return next;
|
|
147
|
+
}
|
|
148
|
+
/** Compare current settings to the env we expect (status/doctor). */
|
|
149
|
+
export function inspectSettings(current, expectedEnv) {
|
|
150
|
+
const env = isPlainObject(current.env) ? current.env : {};
|
|
151
|
+
const mismatchedKeys = [];
|
|
152
|
+
if (expectedEnv) {
|
|
153
|
+
for (const [k, v] of Object.entries(expectedEnv))
|
|
154
|
+
if (env[k] !== v)
|
|
155
|
+
mismatchedKeys.push(k);
|
|
156
|
+
}
|
|
157
|
+
const hooks = isPlainObject(current.hooks) ? current.hooks : {};
|
|
158
|
+
const hookEvents = {};
|
|
159
|
+
for (const event of HOOK_EVENTS) {
|
|
160
|
+
const groups = hooks[event];
|
|
161
|
+
hookEvents[event] = Array.isArray(groups) && groups.some((g) => isPlainObject(g) && Array.isArray(g.hooks) && g.hooks.some(isOurHook));
|
|
162
|
+
}
|
|
163
|
+
return { envMatches: expectedEnv !== undefined && mismatchedKeys.length === 0, mismatchedKeys, hookEvents };
|
|
164
|
+
}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { paths } from './paths.js';
|
|
3
|
+
import { isPlainObject, readJsonObject, toJson, writeFileAtomic } from './fsutil.js';
|
|
4
|
+
export function ensureSbtDir() {
|
|
5
|
+
const { sbtDir } = paths();
|
|
6
|
+
fs.mkdirSync(sbtDir, { recursive: true, mode: 0o700 });
|
|
7
|
+
fs.chmodSync(sbtDir, 0o700);
|
|
8
|
+
}
|
|
9
|
+
/** config.json is read by hook.sh; it holds the token, so it is always chmod 600. */
|
|
10
|
+
export function writeConfig(cfg) {
|
|
11
|
+
ensureSbtDir();
|
|
12
|
+
writeFileAtomic(paths().config, toJson({ token: cfg.token, endpoint: cfg.endpoint }), 0o600);
|
|
13
|
+
}
|
|
14
|
+
export function readConfig() {
|
|
15
|
+
const data = readJsonObject(paths().config);
|
|
16
|
+
if (!data || typeof data.token !== 'string' || typeof data.endpoint !== 'string')
|
|
17
|
+
return undefined;
|
|
18
|
+
return { token: data.token, endpoint: data.endpoint };
|
|
19
|
+
}
|
|
20
|
+
export function writeState(state) {
|
|
21
|
+
ensureSbtDir();
|
|
22
|
+
writeFileAtomic(paths().state, toJson(state), 0o600);
|
|
23
|
+
}
|
|
24
|
+
export function readState() {
|
|
25
|
+
let data;
|
|
26
|
+
try {
|
|
27
|
+
data = readJsonObject(paths().state);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (!data || !isPlainObject(data.previous_env) || !isPlainObject(data.applied_env))
|
|
33
|
+
return undefined;
|
|
34
|
+
return data;
|
|
35
|
+
}
|
package/dist/status.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { buildEnv, maskToken } from './env.js';
|
|
2
|
+
import { paths } from './paths.js';
|
|
3
|
+
import { fileMode, readJsonObject } from './fsutil.js';
|
|
4
|
+
import { inspectSettings } from './settings.js';
|
|
5
|
+
import { readConfig, readState } from './state.js';
|
|
6
|
+
import { HOOK_EVENTS } from './constants.js';
|
|
7
|
+
import { consoleLogger } from './log.js';
|
|
8
|
+
export function collectStatus() {
|
|
9
|
+
const p = paths();
|
|
10
|
+
let config;
|
|
11
|
+
try {
|
|
12
|
+
config = readConfig();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
config = undefined;
|
|
16
|
+
}
|
|
17
|
+
const hookMode = fileMode(p.hook);
|
|
18
|
+
const report = {
|
|
19
|
+
installed: false,
|
|
20
|
+
config,
|
|
21
|
+
configMode: fileMode(p.config),
|
|
22
|
+
hookInstalled: hookMode !== undefined,
|
|
23
|
+
hookExecutable: hookMode !== undefined && (hookMode & 0o100) !== 0,
|
|
24
|
+
};
|
|
25
|
+
let settings;
|
|
26
|
+
try {
|
|
27
|
+
settings = readJsonObject(p.settings) ?? {};
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
report.settingsError = err.message;
|
|
31
|
+
}
|
|
32
|
+
if (settings) {
|
|
33
|
+
// Prefer what init actually applied (includes team id); fall back to config.
|
|
34
|
+
const state = readState();
|
|
35
|
+
let expected = state?.applied_env;
|
|
36
|
+
if (!expected && config) {
|
|
37
|
+
try {
|
|
38
|
+
expected = buildEnv({ token: config.token, endpoint: config.endpoint });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
expected = undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
report.inspection = inspectSettings(settings, expected);
|
|
45
|
+
}
|
|
46
|
+
report.installed = Boolean(config && report.hookInstalled && report.inspection?.envMatches && HOOK_EVENTS.every((e) => report.inspection?.hookEvents[e]));
|
|
47
|
+
return report;
|
|
48
|
+
}
|
|
49
|
+
export function status(opts = {}) {
|
|
50
|
+
const log = opts.logger ?? consoleLogger;
|
|
51
|
+
const p = paths();
|
|
52
|
+
const r = collectStatus();
|
|
53
|
+
if (!r.config && !r.hookInstalled && !r.inspection?.hookEvents.SessionStart) {
|
|
54
|
+
log.info('SpendByTeam is not installed. Run: npx spendbyteam init --token=sbt_ing_...');
|
|
55
|
+
return r;
|
|
56
|
+
}
|
|
57
|
+
if (r.config)
|
|
58
|
+
log.ok(`Config ${p.config}: endpoint ${r.config.endpoint}, token ${maskToken(r.config.token)}`);
|
|
59
|
+
else
|
|
60
|
+
log.error(`Config ${p.config} missing or invalid`);
|
|
61
|
+
if (r.configMode !== undefined && r.configMode !== 0o600)
|
|
62
|
+
log.warn(`Config mode is ${r.configMode.toString(8)}, expected 600`);
|
|
63
|
+
if (r.settingsError)
|
|
64
|
+
log.error(r.settingsError);
|
|
65
|
+
if (r.inspection) {
|
|
66
|
+
if (r.inspection.envMatches)
|
|
67
|
+
log.ok('OTel env in ~/.claude/settings.json');
|
|
68
|
+
else
|
|
69
|
+
log.error(`OTel env in ~/.claude/settings.json missing or changed: ${r.inspection.mismatchedKeys.join(', ') || 'unknown'}`);
|
|
70
|
+
for (const e of HOOK_EVENTS) {
|
|
71
|
+
if (r.inspection.hookEvents[e])
|
|
72
|
+
log.ok(`${e} hook registered`);
|
|
73
|
+
else
|
|
74
|
+
log.error(`${e} hook not registered`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (r.hookExecutable)
|
|
78
|
+
log.ok(`Hook script ${p.hook}`);
|
|
79
|
+
else
|
|
80
|
+
log.error(`Hook script ${p.hook} ${r.hookInstalled ? 'is not executable' : 'missing'}`);
|
|
81
|
+
log.info(r.installed ? 'Status: installed' : 'Status: incomplete — run "npx spendbyteam init" again or "npx spendbyteam doctor"');
|
|
82
|
+
return r;
|
|
83
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { paths } from './paths.js';
|
|
3
|
+
import { fileMode, readJsonObject, toJson, writeFileAtomic } from './fsutil.js';
|
|
4
|
+
import { removeSettings } from './settings.js';
|
|
5
|
+
import { readState } from './state.js';
|
|
6
|
+
import { consoleLogger } from './log.js';
|
|
7
|
+
export function uninstall(opts = {}) {
|
|
8
|
+
const log = opts.logger ?? consoleLogger;
|
|
9
|
+
const p = paths();
|
|
10
|
+
const state = readState();
|
|
11
|
+
let settingsChanged = false;
|
|
12
|
+
let backupPath;
|
|
13
|
+
const existing = readJsonObject(p.settings);
|
|
14
|
+
if (existing !== undefined) {
|
|
15
|
+
const next = removeSettings(existing, state ? { previousEnv: state.previous_env, appliedEnv: state.applied_env } : {});
|
|
16
|
+
const after = toJson(next);
|
|
17
|
+
if (after !== toJson(existing)) {
|
|
18
|
+
fs.copyFileSync(p.settings, p.settingsBackup);
|
|
19
|
+
backupPath = p.settingsBackup;
|
|
20
|
+
writeFileAtomic(p.settings, after, fileMode(p.settings) ?? 0o600);
|
|
21
|
+
settingsChanged = true;
|
|
22
|
+
log.ok(`Removed SpendByTeam settings from ${p.settings} (backup: ${backupPath})`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
log.ok(`${p.settings} has no SpendByTeam settings`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const removedDir = fs.existsSync(p.sbtDir);
|
|
29
|
+
fs.rmSync(p.sbtDir, { recursive: true, force: true });
|
|
30
|
+
if (removedDir)
|
|
31
|
+
log.ok(`Removed ${p.sbtDir}`);
|
|
32
|
+
log.info('SpendByTeam is uninstalled. Restart Claude Code sessions to stop sending metrics.');
|
|
33
|
+
return { settingsChanged, backupPath, removedDir };
|
|
34
|
+
}
|
package/hook/hook.sh
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# SpendByTeam context hook — açık kaynak, sadece aşağıdaki alanları gönderir.
|
|
3
|
+
set -u
|
|
4
|
+
CFG="$HOME/.spendbyteam/config.json"
|
|
5
|
+
[ -r "$CFG" ] || exit 0
|
|
6
|
+
|
|
7
|
+
INPUT=$(cat)
|
|
8
|
+
SESSION_ID=$(printf '%s' "$INPUT" | jq -r '.session_id // empty')
|
|
9
|
+
CWD=$(printf '%s' "$INPUT" | jq -r '.cwd // empty')
|
|
10
|
+
EVENT=$(printf '%s' "$INPUT" | jq -r '.hook_event_name // empty')
|
|
11
|
+
[ -n "$SESSION_ID" ] && [ -n "$CWD" ] || exit 0
|
|
12
|
+
|
|
13
|
+
TOKEN=$(jq -r '.token // empty' "$CFG"); ENDPOINT=$(jq -r '.endpoint // empty' "$CFG")
|
|
14
|
+
# Token yalnızca güvenli karakterler (header enjeksiyonu yok); endpoint https (http sadece localhost).
|
|
15
|
+
printf '%s' "$TOKEN" | grep -qE '^sbt_ing_[A-Za-z0-9_-]{1,120}$' || exit 0
|
|
16
|
+
printf '%s' "$ENDPOINT" | grep -qE '^(https://[^[:space:]]+|http://(localhost|127\.0\.0\.1|\[::1\])(:[0-9]+)?(/[^[:space:]]*)?)$' || exit 0
|
|
17
|
+
|
|
18
|
+
REMOTE=$(git -C "$CWD" config --get remote.origin.url 2>/dev/null || true)
|
|
19
|
+
# Commit'siz repo ve detached HEAD'de rev-parse "HEAD" döner: branch yok say.
|
|
20
|
+
BRANCH=$(git -C "$CWD" rev-parse --abbrev-ref HEAD 2>/dev/null) || BRANCH=""
|
|
21
|
+
[ "$BRANCH" = "HEAD" ] && BRANCH=""
|
|
22
|
+
TICKET=$(printf '%s' "$BRANCH" | grep -oE '[A-Z][A-Z0-9]+-[0-9]+' | head -1 || true)
|
|
23
|
+
|
|
24
|
+
# Remote URL'den kimlik bilgisini (scheme://user:token@host/...), query ve fragment'ı temizle.
|
|
25
|
+
REMOTE=$(printf '%s' "$REMOTE" | sed -E 's#^([A-Za-z][A-Za-z0-9+.-]*://)[^/]*@#\1#; s#[?\#].*$##')
|
|
26
|
+
# Yerel yol / file:// remote'u gönderme: kullanıcı adı ve klasör yapısı sızar (cwd kuralı).
|
|
27
|
+
printf '%s' "$REMOTE" | grep -qE '^(([A-Za-z][A-Za-z0-9+.-]*://[^/]+)|([^/:@[:space:]]+@[^/:[:space:]]+:)|([A-Za-z0-9-]+\.[A-Za-z0-9.-]+:))' \
|
|
28
|
+
&& ! printf '%s' "$REMOTE" | grep -qiE '^file://' || REMOTE=""
|
|
29
|
+
|
|
30
|
+
# Token argv'de değil (ps ile diğer kullanıcılar göremesin): header bir fd'den okunur.
|
|
31
|
+
jq -n --arg s "$SESSION_ID" --arg e "$EVENT" --arg r "$REMOTE" \
|
|
32
|
+
--arg b "$BRANCH" --arg t "$TICKET" --arg ts "$(date -u +%FT%TZ)" \
|
|
33
|
+
'{session_id:$s, event:$e, repo_url:$r, branch:$b, ticket:$t, at:$ts}' |
|
|
34
|
+
curl -sS -m 5 -X POST "$ENDPOINT/v1/context" \
|
|
35
|
+
-H @<(printf 'Authorization: Bearer %s\n' "$TOKEN") -H "Content-Type: application/json" \
|
|
36
|
+
--data-binary @- >/dev/null 2>&1 || true
|
|
37
|
+
exit 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spendbyteam",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Connect Claude Code to SpendByTeam: metrics-only OpenTelemetry + a tiny branch/ticket context hook.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://spendbyteam.com/docs/install",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/spendbyteam/cli.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"email": "support@spendbyteam.com"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"spendbyteam": "dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"hook/hook.sh",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18.17"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json && chmod +x dist/cli.js",
|
|
29
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
30
|
+
"test": "npm run test:unit && npm run test:hook",
|
|
31
|
+
"test:unit": "vitest run",
|
|
32
|
+
"test:hook": "bash test/hook.test.sh",
|
|
33
|
+
"prepublishOnly": "npm run build && npm test"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"claude-code",
|
|
37
|
+
"opentelemetry",
|
|
38
|
+
"cost",
|
|
39
|
+
"spendbyteam"
|
|
40
|
+
],
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.10.0",
|
|
43
|
+
"typescript": "^5.7.0",
|
|
44
|
+
"vitest": "^5.1.0"
|
|
45
|
+
}
|
|
46
|
+
}
|