tokenoscopy 0.0.0-stage → 0.3.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.
@@ -0,0 +1,78 @@
1
+ import { SessionSummary, SessionEvent } from '@tokenoscopy/shared';
2
+ export { redactText, redactValue } from '@tokenoscopy/shared';
3
+
4
+ /**
5
+ * How is this machine paying for tokens? It changes what the dollar figure
6
+ * MEANS, so guessing is worse than admitting we don't know.
7
+ *
8
+ * api_key — an API key or Console-billed OAuth account. Every token is
9
+ * marginal money. A runaway is a real invoice; a dollar cap
10
+ * is literally a dollar cap.
11
+ * subscription — Pro/Max seat. The invoice is fixed, so our dollar figure
12
+ * is NOTIONAL (what this would have cost at API rates). The
13
+ * real scarce resource is the rolling usage limit: a retry
14
+ * loop doesn't cost extra money, it costs the developer
15
+ * their afternoon.
16
+ *
17
+ * Note that OAuth login does NOT imply either lane — Claude Code also signs
18
+ * in to Console accounts that bill per token. Each lane needs POSITIVE
19
+ * evidence; a signed-in account with nothing that says how it bills is
20
+ * `unknown`, not a guess.
21
+ *
22
+ * `hasAvailableSubscription` used to be the deciding field. It reads `false`
23
+ * on live Max accounts, which is how every seat in the fleet came to be
24
+ * labelled real money. The organisation fields on `oauthAccount` are what
25
+ * actually describe the plan.
26
+ */
27
+ type AuthMode = "api_key" | "subscription" | "unknown";
28
+ interface AuthVerdict {
29
+ mode: AuthMode;
30
+ /** Which fact decided it — shown by `doctor`, never uploaded. */
31
+ evidence: string;
32
+ }
33
+ /** The slice of ~/.claude.json we read. Every field is optional by design. */
34
+ interface ClaudeJson {
35
+ hasAvailableSubscription?: boolean;
36
+ customApiKeyResponses?: {
37
+ approved?: string[];
38
+ rejected?: string[];
39
+ };
40
+ oauthAccount?: {
41
+ accountUuid?: string;
42
+ organizationType?: string | null;
43
+ billingType?: string | null;
44
+ organizationRateLimitTier?: string | null;
45
+ userRateLimitTier?: string | null;
46
+ };
47
+ }
48
+ type Env = Record<string, string | undefined>;
49
+ declare function classifyAuth(env: Env, cfg: ClaudeJson | null): AuthVerdict;
50
+ declare function readClaudeJson(): ClaudeJson | null;
51
+ declare function detectAuth(): AuthVerdict;
52
+ declare function detectAuthMode(): AuthMode;
53
+ /** Is the dollar figure real money, or a notional list-price equivalent? */
54
+ declare function costIsRealMoney(mode: AuthMode): boolean;
55
+
56
+ /**
57
+ * Claude Code JSONL transcript parser.
58
+ *
59
+ * Format contract (empirically verified — docs/research/capture-surfaces.md §1.3):
60
+ * - Append-only, one JSON object per line, at ~/.claude/projects/<cwd-slug>/<session>.jsonl
61
+ * - Record types observed live: user / assistant / system / summary / attachment /
62
+ * file-history-snapshot / last-prompt / mode / permission-mode / queue-operation
63
+ * - One LLM request can span MULTIPLE assistant records (one per content block),
64
+ * each repeating the same `requestId` and the same `usage` — usage must be
65
+ * counted exactly once per requestId (community-confirmed double-count trap).
66
+ * - Unknown record types are counted, preserved as warnings, never fatal —
67
+ * the format is undocumented-but-stable and versioned per record.
68
+ */
69
+ interface ParsedTranscript {
70
+ summary: SessionSummary;
71
+ events: SessionEvent[];
72
+ warnings: string[];
73
+ }
74
+ /** Derive a repo label from cwd WITHOUT leaking the full local path. */
75
+ declare function repoLabelFromCwd(cwd: string | undefined): string | undefined;
76
+ declare function parseTranscript(jsonl: string): ParsedTranscript;
77
+
78
+ export { type AuthMode, type AuthVerdict, type ClaudeJson, type ParsedTranscript, classifyAuth, costIsRealMoney, detectAuth, detectAuthMode, parseTranscript, readClaudeJson, repoLabelFromCwd };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import {
2
+ classifyAuth,
3
+ costIsRealMoney,
4
+ detectAuth,
5
+ detectAuthMode,
6
+ parseTranscript,
7
+ readClaudeJson,
8
+ redactText,
9
+ redactValue,
10
+ repoLabelFromCwd
11
+ } from "./chunk-AZYPMFOF.js";
12
+ export {
13
+ classifyAuth,
14
+ costIsRealMoney,
15
+ detectAuth,
16
+ detectAuthMode,
17
+ parseTranscript,
18
+ readClaudeJson,
19
+ redactText,
20
+ redactValue,
21
+ repoLabelFromCwd
22
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "tokenoscopy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.1",
4
+ "description": "Flight recorder & spend control for coding-agent fleets. Records Claude Code sessions (hooks + transcripts), replays them, and enforces budgets.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "tokenoscopy": "dist/cli.js"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "prepublishOnly": "npm run build && node ../../scripts/sdk-smoke.mjs",
25
+ "typecheck": "tsc --noEmit",
26
+ "test": "vitest run --passWithNoTests"
27
+ },
28
+ "dependencies": {
29
+ "zod": "^3.24.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^20",
33
+ "tsup": "^8.4.0",
34
+ "typescript": "^5",
35
+ "vitest": "^3.0.0",
36
+ "@tokenoscopy/shared": "0.0.1"
37
+ },
38
+ "engines": {
39
+ "node": ">=20"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/getriff-ai/tokenoscopy.git",
44
+ "directory": "packages/sdk"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "homepage": "https://tokenoscopy.com",
50
+ "bugs": {
51
+ "url": "https://tokenoscopy.com/docs#support"
52
+ },
53
+ "keywords": [
54
+ "claude-code",
55
+ "ai-agents",
56
+ "observability",
57
+ "spend-control",
58
+ "session-replay",
59
+ "flight-recorder"
60
+ ]
61
+ }