@refactorlabs/recount 0.5.5

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Refactor Labs Pty Ltd
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 ADDED
@@ -0,0 +1,74 @@
1
+ # @refactorlabs/recount
2
+
3
+ Application explainability for modern software. Recount captures the reasoning behind your application's decisions and presents it as an interactive timeline, making it easy for engineers, support teams, product managers, and business stakeholders to understand what happened - and why.
4
+
5
+ This is the Node.js SDK for [Recount](https://recount.refactor.gg).
6
+
7
+ **[Documentation](https://recount.refactor.gg/docs)**
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @refactorlabs/recount
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ Wrap the function that makes a decision in `startTrace`, then add a span per step. No `RECOUNT_API_KEY`? All calls silently no-op, so it's safe to wire up before you have one.
18
+
19
+ ```ts
20
+ import recount from '@refactorlabs/recount';
21
+
22
+ await recount.startTrace('Discount eligibility - ORDER-4471', async () => {
23
+ recount.addSpan('table', 'Discount rules', {
24
+ output: recount
25
+ .table()
26
+ .fromRecords([
27
+ { rule: 'Loyalty tier', value: 'Gold', result: 'Pass' },
28
+ { rule: 'Order total ≥ $50', value: '$84.00', result: 'Pass' },
29
+ { rule: 'No active disputes', value: '0', result: 'Pass' }
30
+ ])
31
+ .highlightRows((row) => (row.result === 'Pass' ? 'success' : 'danger'))
32
+ .build()
33
+ });
34
+
35
+ recount.addSpan('json', 'Result', {
36
+ output: { decision: 'approved', discount: '15%' }
37
+ });
38
+ });
39
+ ```
40
+
41
+ That trace shows up in the [Recount dashboard](https://recount.refactor.gg) as a readable timeline - not a log dump - that a support agent or auditor can open and see exactly why the discount was approved.
42
+
43
+ ## Integrations
44
+
45
+ Wrap a client once and every call through it is traced automatically - don't hand-write spans for these:
46
+
47
+ ```ts
48
+ import { wrapAnthropic } from '@refactorlabs/recount/anthropic';
49
+ import { wrapOpenAI } from '@refactorlabs/recount/openai';
50
+ import { wrapCollection } from '@refactorlabs/recount/mongodb';
51
+
52
+ const anthropic = wrapAnthropic(new Anthropic());
53
+ const openai = wrapOpenAI(new OpenAI());
54
+ const users = wrapCollection(db.collection('users')); // findOne, find, updateOne, aggregate, ...
55
+ ```
56
+
57
+ See the [full docs](https://recount.refactor.gg/docs) for span types, the `table()`/`chart()` builders, redaction, alerts, and `addGroup` for bounded lists.
58
+
59
+ ## Claude Code skill
60
+
61
+ This package ships a [Claude Code](https://claude.com/claude-code) Skill that finds decision logic
62
+ in your codebase (pricing, billing, discounts, access control, LLM calls) and instruments it with
63
+ Recount automatically. To use it in your project:
64
+
65
+ ```sh
66
+ mkdir -p .claude/skills/recount-instrument
67
+ cp node_modules/@refactorlabs/recount/recount-instrument/SKILL.md .claude/skills/recount-instrument/
68
+ ```
69
+
70
+ Then in Claude Code, ask it to "add recount tracing to this" or "instrument this with recount".
71
+
72
+ ## License
73
+
74
+ MIT
@@ -0,0 +1,33 @@
1
+ import { AsyncLocalStorage } from 'async_hooks';
2
+
3
+ var __typeError = (msg) => {
4
+ throw TypeError(msg);
5
+ };
6
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
7
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
8
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
9
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
10
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
11
+ var _key = /* @__PURE__ */ Symbol.for("@refactorlabs/recount.storage");
12
+ var _nameKey = /* @__PURE__ */ Symbol.for("@refactorlabs/recount.spanName");
13
+ var _g = globalThis;
14
+ if (!_g[_key]) _g[_key] = new AsyncLocalStorage();
15
+ if (!_g[_nameKey]) _g[_nameKey] = new AsyncLocalStorage();
16
+ var storage = _g[_key];
17
+ var nameStorage = _g[_nameKey];
18
+ function getActiveTrace() {
19
+ return storage.getStore();
20
+ }
21
+ function runWithTrace(trace, fn) {
22
+ return storage.run(trace, fn);
23
+ }
24
+ function getNextSpanName() {
25
+ return nameStorage.getStore();
26
+ }
27
+ function runWithSpanName(name, fn) {
28
+ return nameStorage.run(name, fn);
29
+ }
30
+
31
+ export { __privateAdd, __privateGet, __privateMethod, __privateSet, getActiveTrace, getNextSpanName, runWithSpanName, runWithTrace };
32
+ //# sourceMappingURL=chunk-XKR3GXTH.js.map
33
+ //# sourceMappingURL=chunk-XKR3GXTH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/context.ts"],"names":[],"mappings":";;;;;;;;;;AAKA,IAAM,IAAA,mBAAO,MAAA,CAAO,GAAA,CAAI,+BAA+B,CAAA;AACvD,IAAM,QAAA,mBAAW,MAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA;AAC5D,IAAM,EAAA,GAAK,UAAA;AACX,IAAI,CAAC,GAAG,IAAI,CAAA,KAAM,IAAI,CAAA,GAAI,IAAI,iBAAA,EAAyB;AACvD,IAAI,CAAC,GAAG,QAAQ,CAAA,KAAM,QAAQ,CAAA,GAAI,IAAI,iBAAA,EAA0B;AAChE,IAAM,OAAA,GAAU,GAAG,IAAI,CAAA;AACvB,IAAM,WAAA,GAAc,GAAG,QAAQ,CAAA;AAExB,SAAS,cAAA,GAAoC;AAClD,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;AAEO,SAAS,YAAA,CACd,OACA,EAAA,EACY;AACZ,EAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,EAAO,EAAE,CAAA;AAC9B;AAEO,SAAS,eAAA,GAAsC;AACpD,EAAA,OAAO,YAAY,QAAA,EAAS;AAC9B;AAEO,SAAS,eAAA,CACd,MACA,EAAA,EACY;AACZ,EAAA,OAAO,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,CAAA;AACjC","file":"chunk-XKR3GXTH.js","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { Trace } from '../trace.ts';\n\n// Global singleton ensures all CJS entry points share one AsyncLocalStorage instance.\nconst _key = Symbol.for('@refactorlabs/recount.storage');\nconst _nameKey = Symbol.for('@refactorlabs/recount.spanName');\nconst _g = globalThis as Record<symbol, AsyncLocalStorage<unknown>>;\nif (!_g[_key]) _g[_key] = new AsyncLocalStorage<Trace>();\nif (!_g[_nameKey]) _g[_nameKey] = new AsyncLocalStorage<string>();\nconst storage = _g[_key] as AsyncLocalStorage<Trace>;\nconst nameStorage = _g[_nameKey] as AsyncLocalStorage<string>;\n\nexport function getActiveTrace(): Trace | undefined {\n return storage.getStore();\n}\n\nexport function runWithTrace<T>(\n trace: Trace,\n fn: () => Promise<T>\n): Promise<T> {\n return storage.run(trace, fn);\n}\n\nexport function getNextSpanName(): string | undefined {\n return nameStorage.getStore();\n}\n\nexport function runWithSpanName<T>(\n name: string,\n fn: () => Promise<T>\n): Promise<T> {\n return nameStorage.run(name, fn);\n}\n"]}