@nanonets/graft 0.10.1 → 0.12.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 +32 -11
- package/dist/ai/crux.d.ts.map +1 -1
- package/dist/ai/crux.js +7 -6
- package/dist/ai/crux.js.map +1 -1
- package/dist/ai/failure.d.ts +49 -0
- package/dist/ai/failure.d.ts.map +1 -0
- package/dist/ai/failure.js +74 -0
- package/dist/ai/failure.js.map +1 -0
- package/dist/ai/llm/anthropic.d.ts.map +1 -1
- package/dist/ai/llm/anthropic.js +4 -1
- package/dist/ai/llm/anthropic.js.map +1 -1
- package/dist/ai/llm/claude-cli.d.ts +60 -0
- package/dist/ai/llm/claude-cli.d.ts.map +1 -0
- package/dist/ai/llm/claude-cli.js +417 -0
- package/dist/ai/llm/claude-cli.js.map +1 -0
- package/dist/ai/llm/openai.d.ts.map +1 -1
- package/dist/ai/llm/openai.js +2 -0
- package/dist/ai/llm/openai.js.map +1 -1
- package/dist/ai/llm/types.d.ts +9 -0
- package/dist/ai/llm/types.d.ts.map +1 -1
- package/dist/ai/llm/types.js +12 -1
- package/dist/ai/llm/types.js.map +1 -1
- package/dist/ask/ask.d.ts.map +1 -1
- package/dist/ask/ask.js +39 -45
- package/dist/ask/ask.js.map +1 -1
- package/dist/ask/fuse.d.ts +83 -46
- package/dist/ask/fuse.d.ts.map +1 -1
- package/dist/ask/fuse.js +165 -67
- package/dist/ask/fuse.js.map +1 -1
- package/dist/blast/blast-cli.d.ts +30 -0
- package/dist/blast/blast-cli.d.ts.map +1 -0
- package/dist/blast/blast-cli.js +163 -0
- package/dist/blast/blast-cli.js.map +1 -0
- package/dist/blast/blast.d.ts +119 -0
- package/dist/blast/blast.d.ts.map +1 -0
- package/dist/blast/blast.js +383 -0
- package/dist/blast/blast.js.map +1 -0
- package/dist/blast/diff.d.ts +53 -0
- package/dist/blast/diff.d.ts.map +1 -0
- package/dist/blast/diff.js +193 -0
- package/dist/blast/diff.js.map +1 -0
- package/dist/blast/modules.d.ts +33 -0
- package/dist/blast/modules.d.ts.map +1 -0
- package/dist/blast/modules.js +83 -0
- package/dist/blast/modules.js.map +1 -0
- package/dist/blast/name.d.ts +61 -0
- package/dist/blast/name.d.ts.map +1 -0
- package/dist/blast/name.js +233 -0
- package/dist/blast/name.js.map +1 -0
- package/dist/blast/render.d.ts +37 -0
- package/dist/blast/render.d.ts.map +1 -0
- package/dist/blast/render.js +300 -0
- package/dist/blast/render.js.map +1 -0
- package/dist/blast/viz.d.ts +17 -0
- package/dist/blast/viz.d.ts.map +1 -0
- package/dist/blast/viz.js +324 -0
- package/dist/blast/viz.js.map +1 -0
- package/dist/claude/hooks.d.ts.map +1 -1
- package/dist/claude/hooks.js +18 -2
- package/dist/claude/hooks.js.map +1 -1
- package/dist/claude/shim-template.d.ts.map +1 -1
- package/dist/claude/shim-template.js +45 -15
- package/dist/claude/shim-template.js.map +1 -1
- package/dist/claude/state.d.ts +5 -0
- package/dist/claude/state.d.ts.map +1 -1
- package/dist/claude/state.js.map +1 -1
- package/dist/cli-picker.d.ts +44 -5
- package/dist/cli-picker.d.ts.map +1 -1
- package/dist/cli-picker.js +73 -26
- package/dist/cli-picker.js.map +1 -1
- package/dist/cli.js +270 -14
- package/dist/cli.js.map +1 -1
- package/dist/context/build.d.ts +8 -0
- package/dist/context/build.d.ts.map +1 -1
- package/dist/context/build.js +57 -9
- package/dist/context/build.js.map +1 -1
- package/dist/context/check.d.ts.map +1 -1
- package/dist/context/check.js +7 -6
- package/dist/context/check.js.map +1 -1
- package/dist/context/node-file.d.ts.map +1 -1
- package/dist/context/node-file.js +9 -2
- package/dist/context/node-file.js.map +1 -1
- package/dist/graph/bindings.d.ts.map +1 -1
- package/dist/graph/bindings.js +171 -8
- package/dist/graph/bindings.js.map +1 -1
- package/dist/graph/build.d.ts.map +1 -1
- package/dist/graph/build.js +36 -16
- package/dist/graph/build.js.map +1 -1
- package/dist/graph/check.d.ts +4 -0
- package/dist/graph/check.d.ts.map +1 -1
- package/dist/graph/check.js +8 -1
- package/dist/graph/check.js.map +1 -1
- package/dist/graph/container.d.ts +63 -0
- package/dist/graph/container.d.ts.map +1 -0
- package/dist/graph/container.js +185 -0
- package/dist/graph/container.js.map +1 -0
- package/dist/graph/enrich.d.ts +18 -0
- package/dist/graph/enrich.d.ts.map +1 -1
- package/dist/graph/enrich.js +55 -2
- package/dist/graph/enrich.js.map +1 -1
- package/dist/graph/extract.d.ts +3 -1
- package/dist/graph/extract.d.ts.map +1 -1
- package/dist/graph/extract.js +215 -8
- package/dist/graph/extract.js.map +1 -1
- package/dist/graph/generic.d.ts +34 -1
- package/dist/graph/generic.d.ts.map +1 -1
- package/dist/graph/generic.js +152 -3
- package/dist/graph/generic.js.map +1 -1
- package/dist/graph/queries/clojure.scm +58 -0
- package/dist/graph/resolve.d.ts.map +1 -1
- package/dist/graph/resolve.js +132 -2
- package/dist/graph/resolve.js.map +1 -1
- package/dist/graph/scopes.d.ts +2 -2
- package/dist/graph/scopes.d.ts.map +1 -1
- package/dist/graph/scopes.js +8 -6
- package/dist/graph/scopes.js.map +1 -1
- package/dist/graph/source-files.d.ts +13 -4
- package/dist/graph/source-files.d.ts.map +1 -1
- package/dist/graph/source-files.js +35 -12
- package/dist/graph/source-files.js.map +1 -1
- package/dist/graph/types.d.ts +1 -1
- package/dist/graph/types.d.ts.map +1 -1
- package/dist/graph/workspace-cli.d.ts +2 -0
- package/dist/graph/workspace-cli.d.ts.map +1 -1
- package/dist/graph/workspace-cli.js +10 -4
- package/dist/graph/workspace-cli.js.map +1 -1
- package/dist/graph/workspace.d.ts +11 -6
- package/dist/graph/workspace.d.ts.map +1 -1
- package/dist/graph/workspace.js +24 -13
- package/dist/graph/workspace.js.map +1 -1
- package/dist/graph/write.d.ts.map +1 -1
- package/dist/graph/write.js +25 -2
- package/dist/graph/write.js.map +1 -1
- package/dist/hosts/antigravity.d.ts +7 -0
- package/dist/hosts/antigravity.d.ts.map +1 -0
- package/dist/hosts/antigravity.js +42 -0
- package/dist/hosts/antigravity.js.map +1 -0
- package/dist/hosts/init.d.ts.map +1 -1
- package/dist/hosts/init.js +6 -1
- package/dist/hosts/init.js.map +1 -1
- package/dist/hosts/mcp-config.d.ts.map +1 -1
- package/dist/hosts/mcp-config.js +7 -0
- package/dist/hosts/mcp-config.js.map +1 -1
- package/dist/hosts/plan.d.ts +1 -1
- package/dist/hosts/plan.d.ts.map +1 -1
- package/dist/hosts/plan.js +2 -0
- package/dist/hosts/plan.js.map +1 -1
- package/dist/hosts/registry.d.ts.map +1 -1
- package/dist/hosts/registry.js +13 -0
- package/dist/hosts/registry.js.map +1 -1
- package/dist/ingest/fs.d.ts +9 -2
- package/dist/ingest/fs.d.ts.map +1 -1
- package/dist/ingest/fs.js +100 -16
- package/dist/ingest/fs.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +45 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/telemetry/contract.d.ts +90 -0
- package/dist/telemetry/contract.d.ts.map +1 -0
- package/dist/telemetry/contract.js +203 -0
- package/dist/telemetry/contract.js.map +1 -0
- package/dist/telemetry/flush.d.ts +21 -0
- package/dist/telemetry/flush.d.ts.map +1 -0
- package/dist/telemetry/flush.js +84 -0
- package/dist/telemetry/flush.js.map +1 -0
- package/dist/telemetry/gate.d.ts +16 -0
- package/dist/telemetry/gate.d.ts.map +1 -0
- package/dist/telemetry/gate.js +64 -0
- package/dist/telemetry/gate.js.map +1 -0
- package/dist/telemetry/identity.d.ts +33 -0
- package/dist/telemetry/identity.d.ts.map +1 -0
- package/dist/telemetry/identity.js +80 -0
- package/dist/telemetry/identity.js.map +1 -0
- package/dist/telemetry/index.d.ts +18 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +16 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/key.d.ts +21 -0
- package/dist/telemetry/key.d.ts.map +1 -0
- package/dist/telemetry/key.js +49 -0
- package/dist/telemetry/key.js.map +1 -0
- package/dist/telemetry/notice.d.ts +19 -0
- package/dist/telemetry/notice.d.ts.map +1 -0
- package/dist/telemetry/notice.js +90 -0
- package/dist/telemetry/notice.js.map +1 -0
- package/dist/telemetry/queue.d.ts +35 -0
- package/dist/telemetry/queue.d.ts.map +1 -0
- package/dist/telemetry/queue.js +162 -0
- package/dist/telemetry/queue.js.map +1 -0
- package/dist/telemetry/send.d.ts +19 -0
- package/dist/telemetry/send.d.ts.map +1 -0
- package/dist/telemetry/send.js +84 -0
- package/dist/telemetry/send.js.map +1 -0
- package/dist/telemetry/sessions.d.ts +8 -0
- package/dist/telemetry/sessions.d.ts.map +1 -0
- package/dist/telemetry/sessions.js +81 -0
- package/dist/telemetry/sessions.js.map +1 -0
- package/dist/telemetry/track.d.ts +43 -0
- package/dist/telemetry/track.d.ts.map +1 -0
- package/dist/telemetry/track.js +108 -0
- package/dist/telemetry/track.js.map +1 -0
- package/dist/upkeep-run.d.ts +15 -0
- package/dist/upkeep-run.d.ts.map +1 -0
- package/dist/upkeep-run.js +60 -0
- package/dist/upkeep-run.js.map +1 -0
- package/dist/upkeep.d.ts +114 -0
- package/dist/upkeep.d.ts.map +1 -0
- package/dist/upkeep.js +232 -0
- package/dist/upkeep.js.map +1 -0
- package/dist/util/num.d.ts +3 -0
- package/dist/util/num.d.ts.map +1 -0
- package/dist/util/num.js +20 -0
- package/dist/util/num.js.map +1 -0
- package/dist/util/state.d.ts +11 -4
- package/dist/util/state.d.ts.map +1 -1
- package/dist/util/state.js +9 -0
- package/dist/util/state.js.map +1 -1
- package/dist/viewer/app.js +1 -1
- package/dist/viewer/index.html +1 -0
- package/dist/viewer/style.css +23 -2
- package/dist/viz/assemble.d.ts +33 -0
- package/dist/viz/assemble.d.ts.map +1 -1
- package/dist/viz/assemble.js.map +1 -1
- package/dist/viz/export.d.ts +39 -0
- package/dist/viz/export.d.ts.map +1 -0
- package/dist/viz/export.js +98 -0
- package/dist/viz/export.js.map +1 -0
- package/package.json +6 -5
- package/scripts/stamp-telemetry-key.mjs +53 -0
package/dist/ingest/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/ingest/fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/ingest/fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpD,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IAC/B,cAAc;IACd,MAAM;IACN,OAAO;IACP,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,aAAa;IACb,MAAM;CACP,CAAC,CAAC;AAEH,uFAAuF;AACvF,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAA8B;IACxE,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACtC,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAqBD,MAAM,UAAU,OAAO,CACrB,GAAW,EACX,QAA8B,EAC9B,OAAoB,EAAE;IAEtB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cp/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAsCA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,SAAM,GAAG,IAAI,CAgFtF"}
|
package/dist/mcp/server.js
CHANGED
|
@@ -5,6 +5,23 @@
|
|
|
5
5
|
import { createInterface } from 'node:readline';
|
|
6
6
|
import { TOOLS, callTool } from './tools.js';
|
|
7
7
|
import { mcpInstructions } from './instructions.js';
|
|
8
|
+
import { runUpkeep } from '../upkeep-run.js';
|
|
9
|
+
import { runningVersion } from '../upkeep.js';
|
|
10
|
+
import { maybeFlushInBackground, track } from '../telemetry/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* MCP tool name → the command enum the telemetry contract knows. A tool absent
|
|
13
|
+
* here is simply not counted: `track` would drop an unlisted command anyway, and
|
|
14
|
+
* mapping by hand keeps the wire vocabulary identical across the CLI and MCP so
|
|
15
|
+
* `ask` means the same thing in both.
|
|
16
|
+
*/
|
|
17
|
+
const TOOL_COMMAND = {
|
|
18
|
+
graft_find_code: 'ask',
|
|
19
|
+
graft_find_all: 'grep',
|
|
20
|
+
graft_trace_calls: 'callers',
|
|
21
|
+
graft_file_api: 'skeleton',
|
|
22
|
+
graft_repo_map: 'map',
|
|
23
|
+
graft_check_freshness: 'check',
|
|
24
|
+
};
|
|
8
25
|
function send(msg) {
|
|
9
26
|
process.stdout.write(`${JSON.stringify(msg)}\n`);
|
|
10
27
|
}
|
|
@@ -20,6 +37,23 @@ function replyError(id, code, message) {
|
|
|
20
37
|
* lookup misses. The caller already knows it.
|
|
21
38
|
*/
|
|
22
39
|
export function startMcpServer(root, dirOverride, version = '0') {
|
|
40
|
+
// The self-maintenance pass, run once at boot. This is the ONLY channel that
|
|
41
|
+
// reaches hosts with no hook support (Cursor, and any plain MCP client): it
|
|
42
|
+
// refreshes rule files an older `graft init` wrote, and kicks off the cached
|
|
43
|
+
// registry check. Both are fail-soft, and the resulting lines ride along in
|
|
44
|
+
// `instructions` below — stdout is protocol-only, so there is nowhere else to
|
|
45
|
+
// put them. Never blocks: the registry fetch happens in a detached child.
|
|
46
|
+
const upkeep = runUpkeep(root, runningVersion()).lines;
|
|
47
|
+
for (const line of upkeep)
|
|
48
|
+
console.error(line);
|
|
49
|
+
// Same deal for the telemetry queue: flushed from a detached child at boot, so
|
|
50
|
+
// a Cursor user who never touches the CLI still gets their events out.
|
|
51
|
+
//
|
|
52
|
+
// Deliberately NOT the first-run notice. This server's stderr goes to an editor
|
|
53
|
+
// log nobody reads, so printing it here would mark the disclosure as shown
|
|
54
|
+
// without anyone having seen it. It stays pending for the next CLI command,
|
|
55
|
+
// and `graft init`'s picker is the channel that reached this user already.
|
|
56
|
+
maybeFlushInBackground();
|
|
23
57
|
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
24
58
|
rl.on('line', (line) => {
|
|
25
59
|
const text = line.trim();
|
|
@@ -42,7 +76,7 @@ export function startMcpServer(root, dirOverride, version = '0') {
|
|
|
42
76
|
capabilities: { tools: {} },
|
|
43
77
|
serverInfo: { name: 'graft', version },
|
|
44
78
|
// The one channel that survives tool deferral — see ./instructions.ts.
|
|
45
|
-
instructions: mcpInstructions(),
|
|
79
|
+
instructions: upkeep.length ? `${upkeep.join('\n')}\n\n${mcpInstructions()}` : mcpInstructions(),
|
|
46
80
|
});
|
|
47
81
|
return;
|
|
48
82
|
case 'notifications/initialized':
|
|
@@ -66,7 +100,16 @@ export function startMcpServer(root, dirOverride, version = '0') {
|
|
|
66
100
|
// graph/refresh.ts). `callTool` absorbs its own errors, so the only thing
|
|
67
101
|
// that can reject here is a bug — surface it as a JSON-RPC error rather
|
|
68
102
|
// than an unhandled rejection that kills the server.
|
|
69
|
-
callTool(root, name, args, dirOverride).then((r) =>
|
|
103
|
+
callTool(root, name, args, dirOverride).then((r) => {
|
|
104
|
+
// No `hit`: `isError` means the tool failed, which is not the same
|
|
105
|
+
// question as "did the graph have an answer". Absent beats wrong.
|
|
106
|
+
// hasOwn for the same reason as track()'s: a client is free to send
|
|
107
|
+
// `{"name":"constructor"}`, and a plain lookup would hand `track` a
|
|
108
|
+
// function rather than undefined.
|
|
109
|
+
const command = Object.hasOwn(TOOL_COMMAND, name) ? TOOL_COMMAND[name] : undefined;
|
|
110
|
+
track('query', { command, surface: 'mcp' }, { repo: root, host: 'mcp' });
|
|
111
|
+
reply(id, { content: [{ type: 'text', text: r.text }], isError: r.isError });
|
|
112
|
+
}, (err) => replyError(id, -32603, err instanceof Error ? err.message : String(err)));
|
|
70
113
|
return;
|
|
71
114
|
}
|
|
72
115
|
default:
|
package/dist/mcp/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,YAAY,GAA2B;IAC3C,eAAe,E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K,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAClF,CAAC;gBACF,OAAO;YACT,CAAC;YACD;gBACE,IAAI,CAAC,cAAc;oBAAE,UAAU,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The telemetry contract: the complete, machine-enforced list of what graft may
|
|
3
|
+
* send. `TELEMETRY.md` is the same list in prose, and the two are kept in
|
|
4
|
+
* lockstep — an event or property that is not in this file cannot be sent, and
|
|
5
|
+
* one that is not in `TELEMETRY.md` must not be added here.
|
|
6
|
+
*
|
|
7
|
+
* Why an allowlist rather than a review rule: every telemetry incident in the
|
|
8
|
+
* tools we studied came from a call site quietly adding a property nobody
|
|
9
|
+
* audited. `track()` (track.ts) drops unknown events and unknown keys instead of
|
|
10
|
+
* trusting its callers, so a future `track('query', { path })` sends `query`
|
|
11
|
+
* with no `path` rather than leaking one. The blast radius of a careless call
|
|
12
|
+
* site is "we lose a metric", never "we received someone's source tree".
|
|
13
|
+
*
|
|
14
|
+
* The other half of that guarantee is the value side: every number crosses as a
|
|
15
|
+
* BUCKET and every string as a member of a fixed union. A raw file count plus a
|
|
16
|
+
* language set starts to fingerprint a specific repo; `"100-500"` does not. A
|
|
17
|
+
* raw error message is a path, a symbol, and sometimes a snippet of code; an
|
|
18
|
+
* enum member is not.
|
|
19
|
+
*
|
|
20
|
+
* This module is pure — no I/O, no config, no clock. It is the file a reviewer
|
|
21
|
+
* (or a suspicious user, since the repo is public) reads to verify the claim.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The contract itself. Common properties (see {@link COMMON_KEYS}) are stamped
|
|
25
|
+
* centrally by `track()` and are deliberately not repeated per event.
|
|
26
|
+
*/
|
|
27
|
+
export declare const EVENTS: Record<string, ReadonlySet<string>>;
|
|
28
|
+
/** Stamped on every event by `track()`; not listed per event above. */
|
|
29
|
+
export declare const COMMON_KEYS: readonly ["app_version", "os", "arch", "node_major", "ci", "agent_host", "repo_id"];
|
|
30
|
+
/** Which surface issued a query. `hook` is Claude Code's prompt hook, which
|
|
31
|
+
* queries on the user's behalf without them typing a command. */
|
|
32
|
+
export type Surface = 'cli' | 'mcp' | 'hook';
|
|
33
|
+
/** Which editor/agent graft is running under. Derived from the surface and the
|
|
34
|
+
* wiring on disk — never from a hostname, a username, or an env var's value. */
|
|
35
|
+
export type AgentHost = 'claude-code' | 'cursor' | 'mcp' | 'cli';
|
|
36
|
+
/**
|
|
37
|
+
* The commands worth counting. A command absent here is simply not reported —
|
|
38
|
+
* `track()` drops the event rather than sending a free-form string, which is
|
|
39
|
+
* what keeps a future `graft <something-user-named>` from becoming a data leak.
|
|
40
|
+
*/
|
|
41
|
+
export declare const TRACKED_COMMANDS: readonly ["ask", "grep", "callers", "skeleton", "map", "check", "blast", "viz"];
|
|
42
|
+
export type TrackedCommand = (typeof TRACKED_COMMANDS)[number];
|
|
43
|
+
export declare function isTrackedCommand(name: string): name is TrackedCommand;
|
|
44
|
+
/** Where a failing build died. Coarse on purpose: enough to route a bug, not
|
|
45
|
+
* enough to describe anyone's repo. */
|
|
46
|
+
export declare const BUILD_STAGES: readonly ["walk", "extract", "graph", "summarize", "synthesize", "write"];
|
|
47
|
+
export type BuildStage = (typeof BUILD_STAGES)[number];
|
|
48
|
+
/**
|
|
49
|
+
* The failure taxonomy. Anything unrecognised becomes `E_UNKNOWN` — the point of
|
|
50
|
+
* a closed set is that an unclassified error contributes a count and nothing
|
|
51
|
+
* else, so no message text can ride along inside a "code".
|
|
52
|
+
*/
|
|
53
|
+
export declare const ERROR_CODES: readonly ["E_UNKNOWN", "E_PARSE", "E_TIMEOUT", "E_LLM", "E_AUTH", "E_RATE_LIMIT", "E_NETWORK", "E_DISK", "E_PERMISSION", "E_OOM", "E_LOCK"];
|
|
54
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
55
|
+
/**
|
|
56
|
+
* Map a thrown value to a code without letting its text through. Only fixed
|
|
57
|
+
* substrings are matched, and only a member of {@link ERROR_CODES} is returned —
|
|
58
|
+
* the error's own message is never the return value, not even in part.
|
|
59
|
+
*/
|
|
60
|
+
export declare function errorCode(err: unknown): ErrorCode;
|
|
61
|
+
/** Repo scale. Exact counts fingerprint a repo; these five labels answer the
|
|
62
|
+
* only question we have ("toy, service, or monorepo?"). */
|
|
63
|
+
export declare function filesBucket(n: number): string;
|
|
64
|
+
/** Wall-clock for a build. Coarse enough that it says "fast/slow", not "this
|
|
65
|
+
* exact machine on this exact tree". */
|
|
66
|
+
export declare function durationBucket(ms: number): string;
|
|
67
|
+
/** Generic small-count bucket, for the per-session read counters. */
|
|
68
|
+
export declare function countBucket(n: number): string;
|
|
69
|
+
/** Estimated tokens saved in one session — the README's central claim, in the
|
|
70
|
+
* only resolution we need to defend it. */
|
|
71
|
+
export declare function savedTokensBucket(n: number): string;
|
|
72
|
+
/**
|
|
73
|
+
* Languages, normalised, filtered to a safe shape, and capped.
|
|
74
|
+
*
|
|
75
|
+
* Sorted so `["go","ts"]` and `["ts","go"]` aggregate as one value, deduped, and
|
|
76
|
+
* cut to eight — a repo with a very long tail of languages is itself a
|
|
77
|
+
* distinguishing fact, and the tail answers no question we have.
|
|
78
|
+
*
|
|
79
|
+
* The character filter is the part that matters. This is the only property in
|
|
80
|
+
* the contract that is not drawn from a closed set defined in this file: the
|
|
81
|
+
* values come from the parser registry, several modules away, via
|
|
82
|
+
* `languageLabelOf() ?? container.name ?? generic.name ?? "unknown"`. That is
|
|
83
|
+
* safe today, but it means the no-free-text guarantee would rest on a promise
|
|
84
|
+
* made elsewhere — and a future generic extractor naming itself after the
|
|
85
|
+
* extension it matched would quietly turn this into a channel for file
|
|
86
|
+
* metadata. Anything outside `[a-z0-9+#._-]`, or longer than 24 characters, is
|
|
87
|
+
* therefore dropped here rather than trusted.
|
|
88
|
+
*/
|
|
89
|
+
export declare function langsValue(langs: readonly string[]): string;
|
|
90
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/telemetry/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAgBtD,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,WAAW,qFAQd,CAAC;AAMX;kEACkE;AAClE,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7C;iFACiF;AACjF,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,iFAEnB,CAAC;AACX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,cAAc,CAErE;AAED;wCACwC;AACxC,eAAO,MAAM,YAAY,2EAA4E,CAAC;AACtG,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,WAAW,6IAGd,CAAC;AACX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAoBjD;AAMD;4DAC4D;AAC5D,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAO7C;AAED;yCACyC;AACzC,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAQjD;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAO7C;AAED;4CAC4C;AAC5C,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAK3D"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The telemetry contract: the complete, machine-enforced list of what graft may
|
|
3
|
+
* send. `TELEMETRY.md` is the same list in prose, and the two are kept in
|
|
4
|
+
* lockstep — an event or property that is not in this file cannot be sent, and
|
|
5
|
+
* one that is not in `TELEMETRY.md` must not be added here.
|
|
6
|
+
*
|
|
7
|
+
* Why an allowlist rather than a review rule: every telemetry incident in the
|
|
8
|
+
* tools we studied came from a call site quietly adding a property nobody
|
|
9
|
+
* audited. `track()` (track.ts) drops unknown events and unknown keys instead of
|
|
10
|
+
* trusting its callers, so a future `track('query', { path })` sends `query`
|
|
11
|
+
* with no `path` rather than leaking one. The blast radius of a careless call
|
|
12
|
+
* site is "we lose a metric", never "we received someone's source tree".
|
|
13
|
+
*
|
|
14
|
+
* The other half of that guarantee is the value side: every number crosses as a
|
|
15
|
+
* BUCKET and every string as a member of a fixed union. A raw file count plus a
|
|
16
|
+
* language set starts to fingerprint a specific repo; `"100-500"` does not. A
|
|
17
|
+
* raw error message is a path, a symbol, and sometimes a snippet of code; an
|
|
18
|
+
* enum member is not.
|
|
19
|
+
*
|
|
20
|
+
* This module is pure — no I/O, no config, no clock. It is the file a reviewer
|
|
21
|
+
* (or a suspicious user, since the repo is public) reads to verify the claim.
|
|
22
|
+
*/
|
|
23
|
+
/* -------------------------------------------------------------------------- */
|
|
24
|
+
/* the event → allowed-property-keys map */
|
|
25
|
+
/* -------------------------------------------------------------------------- */
|
|
26
|
+
/**
|
|
27
|
+
* The contract itself. Common properties (see {@link COMMON_KEYS}) are stamped
|
|
28
|
+
* centrally by `track()` and are deliberately not repeated per event.
|
|
29
|
+
*/
|
|
30
|
+
export const EVENTS = {
|
|
31
|
+
/** Once per machine, when the install id is first minted. The denominator. */
|
|
32
|
+
first_run: new Set(),
|
|
33
|
+
/** `graft init` completed. Tells us which agents people actually wire, and
|
|
34
|
+
* how many decline telemetry at the picker. */
|
|
35
|
+
init_completed: new Set(['agents', 'consent']),
|
|
36
|
+
/** A build finished. The activation event — an install that never reaches one
|
|
37
|
+
* of these is the funnel leak we most want to see. */
|
|
38
|
+
build_completed: new Set(['files_bucket', 'langs', 'mode', 'duration_bucket', 'incremental']),
|
|
39
|
+
/** A build threw. `stage`/`code` are enums; the message never travels. */
|
|
40
|
+
build_failed: new Set(['stage', 'code']),
|
|
41
|
+
/** One query, from any surface. The DAU backbone and the dead-command detector. */
|
|
42
|
+
query: new Set(['command', 'surface', 'hit']),
|
|
43
|
+
/** One closed agent session, summarised. `graft_reads` vs `source_reads` is
|
|
44
|
+
* the single number that says whether an agent prefers graft to grep. */
|
|
45
|
+
session_summary: new Set(['graft_reads_bucket', 'source_reads_bucket', 'saved_tokens_bucket']),
|
|
46
|
+
};
|
|
47
|
+
/** Stamped on every event by `track()`; not listed per event above. */
|
|
48
|
+
export const COMMON_KEYS = [
|
|
49
|
+
'app_version',
|
|
50
|
+
'os',
|
|
51
|
+
'arch',
|
|
52
|
+
'node_major',
|
|
53
|
+
'ci',
|
|
54
|
+
'agent_host',
|
|
55
|
+
'repo_id',
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* The commands worth counting. A command absent here is simply not reported —
|
|
59
|
+
* `track()` drops the event rather than sending a free-form string, which is
|
|
60
|
+
* what keeps a future `graft <something-user-named>` from becoming a data leak.
|
|
61
|
+
*/
|
|
62
|
+
export const TRACKED_COMMANDS = [
|
|
63
|
+
'ask', 'grep', 'callers', 'skeleton', 'map', 'check', 'blast', 'viz',
|
|
64
|
+
];
|
|
65
|
+
export function isTrackedCommand(name) {
|
|
66
|
+
return TRACKED_COMMANDS.includes(name);
|
|
67
|
+
}
|
|
68
|
+
/** Where a failing build died. Coarse on purpose: enough to route a bug, not
|
|
69
|
+
* enough to describe anyone's repo. */
|
|
70
|
+
export const BUILD_STAGES = ['walk', 'extract', 'graph', 'summarize', 'synthesize', 'write'];
|
|
71
|
+
/**
|
|
72
|
+
* The failure taxonomy. Anything unrecognised becomes `E_UNKNOWN` — the point of
|
|
73
|
+
* a closed set is that an unclassified error contributes a count and nothing
|
|
74
|
+
* else, so no message text can ride along inside a "code".
|
|
75
|
+
*/
|
|
76
|
+
export const ERROR_CODES = [
|
|
77
|
+
'E_UNKNOWN', 'E_PARSE', 'E_TIMEOUT', 'E_LLM', 'E_AUTH', 'E_RATE_LIMIT',
|
|
78
|
+
'E_NETWORK', 'E_DISK', 'E_PERMISSION', 'E_OOM', 'E_LOCK',
|
|
79
|
+
];
|
|
80
|
+
/**
|
|
81
|
+
* Map a thrown value to a code without letting its text through. Only fixed
|
|
82
|
+
* substrings are matched, and only a member of {@link ERROR_CODES} is returned —
|
|
83
|
+
* the error's own message is never the return value, not even in part.
|
|
84
|
+
*/
|
|
85
|
+
export function errorCode(err) {
|
|
86
|
+
const code = err?.code;
|
|
87
|
+
if (typeof code === 'string') {
|
|
88
|
+
if (code === 'ENOSPC' || code === 'EDQUOT')
|
|
89
|
+
return 'E_DISK';
|
|
90
|
+
if (code === 'EACCES' || code === 'EPERM')
|
|
91
|
+
return 'E_PERMISSION';
|
|
92
|
+
if (code === 'ENOMEM')
|
|
93
|
+
return 'E_OOM';
|
|
94
|
+
if (code === 'ETIMEDOUT' || code === 'ESOCKETTIMEDOUT')
|
|
95
|
+
return 'E_TIMEOUT';
|
|
96
|
+
if (code === 'ENOTFOUND' || code === 'ECONNREFUSED' || code === 'ECONNRESET')
|
|
97
|
+
return 'E_NETWORK';
|
|
98
|
+
}
|
|
99
|
+
const status = err?.status;
|
|
100
|
+
if (typeof status === 'number') {
|
|
101
|
+
if (status === 401 || status === 403)
|
|
102
|
+
return 'E_AUTH';
|
|
103
|
+
if (status === 429)
|
|
104
|
+
return 'E_RATE_LIMIT';
|
|
105
|
+
if (status >= 500)
|
|
106
|
+
return 'E_LLM';
|
|
107
|
+
}
|
|
108
|
+
const msg = err instanceof Error ? err.message.toLowerCase() : '';
|
|
109
|
+
if (msg.includes('timeout') || msg.includes('timed out'))
|
|
110
|
+
return 'E_TIMEOUT';
|
|
111
|
+
if (msg.includes('parse') || msg.includes('syntax'))
|
|
112
|
+
return 'E_PARSE';
|
|
113
|
+
if (msg.includes('lock'))
|
|
114
|
+
return 'E_LOCK';
|
|
115
|
+
return 'E_UNKNOWN';
|
|
116
|
+
}
|
|
117
|
+
/* -------------------------------------------------------------------------- */
|
|
118
|
+
/* buckets — every number crosses the wire as a label */
|
|
119
|
+
/* -------------------------------------------------------------------------- */
|
|
120
|
+
/** Repo scale. Exact counts fingerprint a repo; these five labels answer the
|
|
121
|
+
* only question we have ("toy, service, or monorepo?"). */
|
|
122
|
+
export function filesBucket(n) {
|
|
123
|
+
if (n <= 0)
|
|
124
|
+
return '0';
|
|
125
|
+
if (n < 50)
|
|
126
|
+
return '1-49';
|
|
127
|
+
if (n < 200)
|
|
128
|
+
return '50-199';
|
|
129
|
+
if (n < 1000)
|
|
130
|
+
return '200-999';
|
|
131
|
+
if (n < 5000)
|
|
132
|
+
return '1000-4999';
|
|
133
|
+
return '5000+';
|
|
134
|
+
}
|
|
135
|
+
/** Wall-clock for a build. Coarse enough that it says "fast/slow", not "this
|
|
136
|
+
* exact machine on this exact tree". */
|
|
137
|
+
export function durationBucket(ms) {
|
|
138
|
+
const s = ms / 1000;
|
|
139
|
+
if (s < 1)
|
|
140
|
+
return '<1s';
|
|
141
|
+
if (s < 5)
|
|
142
|
+
return '1-5s';
|
|
143
|
+
if (s < 30)
|
|
144
|
+
return '5-30s';
|
|
145
|
+
if (s < 120)
|
|
146
|
+
return '30s-2m';
|
|
147
|
+
if (s < 600)
|
|
148
|
+
return '2-10m';
|
|
149
|
+
return '10m+';
|
|
150
|
+
}
|
|
151
|
+
/** Generic small-count bucket, for the per-session read counters. */
|
|
152
|
+
export function countBucket(n) {
|
|
153
|
+
if (n <= 0)
|
|
154
|
+
return '0';
|
|
155
|
+
if (n < 5)
|
|
156
|
+
return '1-4';
|
|
157
|
+
if (n < 20)
|
|
158
|
+
return '5-19';
|
|
159
|
+
if (n < 50)
|
|
160
|
+
return '20-49';
|
|
161
|
+
if (n < 200)
|
|
162
|
+
return '50-199';
|
|
163
|
+
return '200+';
|
|
164
|
+
}
|
|
165
|
+
/** Estimated tokens saved in one session — the README's central claim, in the
|
|
166
|
+
* only resolution we need to defend it. */
|
|
167
|
+
export function savedTokensBucket(n) {
|
|
168
|
+
if (n <= 0)
|
|
169
|
+
return '0';
|
|
170
|
+
if (n < 1000)
|
|
171
|
+
return '<1k';
|
|
172
|
+
if (n < 5000)
|
|
173
|
+
return '1-5k';
|
|
174
|
+
if (n < 20000)
|
|
175
|
+
return '5-20k';
|
|
176
|
+
if (n < 100000)
|
|
177
|
+
return '20-100k';
|
|
178
|
+
return '100k+';
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Languages, normalised, filtered to a safe shape, and capped.
|
|
182
|
+
*
|
|
183
|
+
* Sorted so `["go","ts"]` and `["ts","go"]` aggregate as one value, deduped, and
|
|
184
|
+
* cut to eight — a repo with a very long tail of languages is itself a
|
|
185
|
+
* distinguishing fact, and the tail answers no question we have.
|
|
186
|
+
*
|
|
187
|
+
* The character filter is the part that matters. This is the only property in
|
|
188
|
+
* the contract that is not drawn from a closed set defined in this file: the
|
|
189
|
+
* values come from the parser registry, several modules away, via
|
|
190
|
+
* `languageLabelOf() ?? container.name ?? generic.name ?? "unknown"`. That is
|
|
191
|
+
* safe today, but it means the no-free-text guarantee would rest on a promise
|
|
192
|
+
* made elsewhere — and a future generic extractor naming itself after the
|
|
193
|
+
* extension it matched would quietly turn this into a channel for file
|
|
194
|
+
* metadata. Anything outside `[a-z0-9+#._-]`, or longer than 24 characters, is
|
|
195
|
+
* therefore dropped here rather than trusted.
|
|
196
|
+
*/
|
|
197
|
+
export function langsValue(langs) {
|
|
198
|
+
const clean = langs
|
|
199
|
+
.map((l) => l.toLowerCase().trim())
|
|
200
|
+
.filter((l) => l.length > 0 && l.length <= 24 && /^[a-z0-9+#._-]+$/.test(l));
|
|
201
|
+
return [...new Set(clean)].sort().slice(0, 8).join(',');
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/telemetry/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAwC;IACzD,8EAA8E;IAC9E,SAAS,EAAE,IAAI,GAAG,EAAU;IAC5B;oDACgD;IAChD,cAAc,EAAE,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACtD;2DACuD;IACvD,eAAe,EAAE,IAAI,GAAG,CAAS,CAAC,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;IACrG,0EAA0E;IAC1E,YAAY,EAAE,IAAI,GAAG,CAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAChD,mFAAmF;IACnF,KAAK,EAAE,IAAI,GAAG,CAAS,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC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E,OAAO,SAAS,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwB;IACjD,MAAM,KAAK,GAAG,KAAK;SAChB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,EAAE,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SendResult } from './send.js';
|
|
2
|
+
/** Matches `UPDATE_TTL_MS`: a day is the natural period for both. */
|
|
3
|
+
export declare const FLUSH_TTL_MS: number;
|
|
4
|
+
export declare function needsFlush(flushedAt: number | undefined, now?: number): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Spawn the flush if the queue has something in it and a day has passed. Returns
|
|
7
|
+
* whether a child was started, for tests. Never waits, never throws.
|
|
8
|
+
*/
|
|
9
|
+
export declare function maybeFlushInBackground(home?: string, now?: number): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a failed send is worth keeping the batch for.
|
|
12
|
+
*
|
|
13
|
+
* A 5xx or a transport failure is ours to retry — a week offline should not be
|
|
14
|
+
* a week of lost events. A 4xx is not: a bad key or a malformed batch will fail
|
|
15
|
+
* identically forever, and retrying it would pin the queue at its cap until it
|
|
16
|
+
* starts dropping the events that WOULD have sent.
|
|
17
|
+
*/
|
|
18
|
+
export declare function shouldRequeue(res: SendResult): boolean;
|
|
19
|
+
/** The `graft _telemetry-flush` body, running in the detached child. */
|
|
20
|
+
export declare function runFlush(home?: string): Promise<void>;
|
|
21
|
+
//# sourceMappingURL=flush.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush.d.ts","sourceRoot":"","sources":["../../src/telemetry/flush.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvD,qEAAqE;AACrE,eAAO,MAAM,YAAY,QAAsB,CAAC;AAMhD,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,SAAa,GAAG,OAAO,CAEnF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,OAAO,CAe/E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAGtD;AAED,wEAAwE;AACxE,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Getting the queue off the machine without any command ever waiting for it.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately the same shape as `maybeRefreshInBackground` in `upkeep.ts`,
|
|
5
|
+
* which has been doing this for the npm registry check since 0.7: check a
|
|
6
|
+
* timestamp, write the timestamp BEFORE spawning so a child that dies cannot
|
|
7
|
+
* make every subsequent command spawn another one, then `spawn` detached and
|
|
8
|
+
* `unref`. The parent returns immediately and never learns the outcome.
|
|
9
|
+
*
|
|
10
|
+
* Once a day, not once a command. Events are cheap to hold and the questions we
|
|
11
|
+
* are asking ("how many repos activated this week") do not get better answers
|
|
12
|
+
* from lower latency.
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import { statSync } from 'node:fs';
|
|
16
|
+
import { graftCliPath } from '../claude/paths.js';
|
|
17
|
+
import { drain, queuePath, requeue } from './queue.js';
|
|
18
|
+
import { patchState, readState } from './identity.js';
|
|
19
|
+
import { sendBatch } from './send.js';
|
|
20
|
+
import { telemetryOn } from './gate.js';
|
|
21
|
+
/** Matches `UPDATE_TTL_MS`: a day is the natural period for both. */
|
|
22
|
+
export const FLUSH_TTL_MS = 24 * 60 * 60 * 1000;
|
|
23
|
+
function queueHasEvents(home) {
|
|
24
|
+
try {
|
|
25
|
+
return statSync(queuePath(home)).size > 0;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function needsFlush(flushedAt, now = Date.now()) {
|
|
32
|
+
return typeof flushedAt !== 'number' || now - flushedAt >= FLUSH_TTL_MS;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Spawn the flush if the queue has something in it and a day has passed. Returns
|
|
36
|
+
* whether a child was started, for tests. Never waits, never throws.
|
|
37
|
+
*/
|
|
38
|
+
export function maybeFlushInBackground(home, now = Date.now()) {
|
|
39
|
+
try {
|
|
40
|
+
if (!telemetryOn(home))
|
|
41
|
+
return false;
|
|
42
|
+
if (!queueHasEvents(home))
|
|
43
|
+
return false;
|
|
44
|
+
if (!needsFlush(readState(home)?.flushedAt, now))
|
|
45
|
+
return false;
|
|
46
|
+
patchState({ flushedAt: now }, home); // before the spawn, so a dying child costs one attempt
|
|
47
|
+
const child = spawn(process.execPath, [graftCliPath(), '_telemetry-flush'], {
|
|
48
|
+
detached: true,
|
|
49
|
+
stdio: 'ignore',
|
|
50
|
+
});
|
|
51
|
+
child.unref();
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return false; // no spawn available (sandbox, ENOMEM) — try again tomorrow
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether a failed send is worth keeping the batch for.
|
|
60
|
+
*
|
|
61
|
+
* A 5xx or a transport failure is ours to retry — a week offline should not be
|
|
62
|
+
* a week of lost events. A 4xx is not: a bad key or a malformed batch will fail
|
|
63
|
+
* identically forever, and retrying it would pin the queue at its cap until it
|
|
64
|
+
* starts dropping the events that WOULD have sent.
|
|
65
|
+
*/
|
|
66
|
+
export function shouldRequeue(res) {
|
|
67
|
+
if (res.ok)
|
|
68
|
+
return false;
|
|
69
|
+
return res.status === undefined || res.status >= 500;
|
|
70
|
+
}
|
|
71
|
+
/** The `graft _telemetry-flush` body, running in the detached child. */
|
|
72
|
+
export async function runFlush(home) {
|
|
73
|
+
try {
|
|
74
|
+
if (!telemetryOn(home))
|
|
75
|
+
return;
|
|
76
|
+
const events = drain(home);
|
|
77
|
+
if (events.length === 0)
|
|
78
|
+
return;
|
|
79
|
+
if (shouldRequeue(await sendBatch(events)))
|
|
80
|
+
requeue(events, home);
|
|
81
|
+
}
|
|
82
|
+
catch { /* a failed flush is a non-event by design */ }
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=flush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush.js","sourceRoot":"","sources":["../../src/telemetry/flush.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,qEAAqE;AACrE,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE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AAC,GAAe;IAC3C,IAAI,GAAG,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IACzB,OAAO,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;AACvD,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAa;IAC1C,IAAI,CAAC;QACH,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YAAE,OAAO;QAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAChC,IAAI,aAAa,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;YAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC,CAAC,6CAA6C,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type OffReason = 'no-key' | 'do-not-track' | 'ci' | 'disabled';
|
|
2
|
+
/** The `DO_NOT_TRACK` convention: set and not `0`/empty means "off". */
|
|
3
|
+
export declare function doNotTrack(env?: NodeJS.ProcessEnv): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* CI detection. `CI` covers essentially every provider; the rest are the ones
|
|
6
|
+
* that historically did not set it. Deliberately generous — a false positive
|
|
7
|
+
* costs one uncounted user, a false negative pollutes the dataset.
|
|
8
|
+
*/
|
|
9
|
+
export declare function inCi(env?: NodeJS.ProcessEnv): boolean;
|
|
10
|
+
/** Null when telemetry may run, otherwise the first gate that closed. */
|
|
11
|
+
export declare function offReason(home?: string, env?: NodeJS.ProcessEnv): OffReason | null;
|
|
12
|
+
export declare function telemetryOn(home?: string, env?: NodeJS.ProcessEnv): boolean;
|
|
13
|
+
/** One line for `graft telemetry status`, naming the gate that is closed so a
|
|
14
|
+
* user who thinks they disabled it can see which switch actually took. */
|
|
15
|
+
export declare function explainOff(reason: OffReason): string;
|
|
16
|
+
//# sourceMappingURL=gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/telemetry/gate.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,cAAc,GAAG,IAAI,GAAG,UAAU,CAAC;AAEtE,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAGxE;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAMlE;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,SAAS,GAAG,IAAI,CAM/F;AAED,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAExF;AAED;2EAC2E;AAC3E,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAOpD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single "may we send?" predicate, checked before every append and again
|
|
3
|
+
* before every send.
|
|
4
|
+
*
|
|
5
|
+
* Four independent gates, in the order a user would expect them to win:
|
|
6
|
+
*
|
|
7
|
+
* 1. A key at all — dev builds and forks have none (see key.ts), so the whole
|
|
8
|
+
* subsystem is inert for anyone who did not install a published graft.
|
|
9
|
+
* 2. `DO_NOT_TRACK` — the cross-tool convention (consoledonottrack.com).
|
|
10
|
+
* Honoured unconditionally: it outranks our own setting, because a user who
|
|
11
|
+
* set it machine-wide has already answered the question for every tool.
|
|
12
|
+
* 3. CI — a build server is not a user. Counting it would inflate every number
|
|
13
|
+
* we care about and tell us nothing about a person.
|
|
14
|
+
* 4. The user's own choice, from the `graft init` picker or
|
|
15
|
+
* `graft telemetry disable`. Default on when never set.
|
|
16
|
+
*
|
|
17
|
+
* Re-checked at every append rather than cached at boot, so `graft telemetry
|
|
18
|
+
* disable` in one terminal takes effect in a long-lived MCP server in another
|
|
19
|
+
* without a restart.
|
|
20
|
+
*/
|
|
21
|
+
import { posthogKey } from './key.js';
|
|
22
|
+
import { readState } from './identity.js';
|
|
23
|
+
/** The `DO_NOT_TRACK` convention: set and not `0`/empty means "off". */
|
|
24
|
+
export function doNotTrack(env = process.env) {
|
|
25
|
+
const v = env.DO_NOT_TRACK;
|
|
26
|
+
return v !== undefined && v !== '' && v !== '0';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* CI detection. `CI` covers essentially every provider; the rest are the ones
|
|
30
|
+
* that historically did not set it. Deliberately generous — a false positive
|
|
31
|
+
* costs one uncounted user, a false negative pollutes the dataset.
|
|
32
|
+
*/
|
|
33
|
+
export function inCi(env = process.env) {
|
|
34
|
+
if (env.CI !== undefined && env.CI !== '' && env.CI !== '0' && env.CI !== 'false')
|
|
35
|
+
return true;
|
|
36
|
+
return Boolean(env.GITHUB_ACTIONS || env.GITLAB_CI || env.BUILDKITE || env.CIRCLECI ||
|
|
37
|
+
env.TEAMCITY_VERSION || env.JENKINS_URL || env.TF_BUILD || env.BUILD_NUMBER);
|
|
38
|
+
}
|
|
39
|
+
/** Null when telemetry may run, otherwise the first gate that closed. */
|
|
40
|
+
export function offReason(home, env = process.env) {
|
|
41
|
+
if (!posthogKey())
|
|
42
|
+
return 'no-key';
|
|
43
|
+
if (doNotTrack(env))
|
|
44
|
+
return 'do-not-track';
|
|
45
|
+
if (inCi(env))
|
|
46
|
+
return 'ci';
|
|
47
|
+
if (readState(home)?.enabled === false)
|
|
48
|
+
return 'disabled';
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
export function telemetryOn(home, env = process.env) {
|
|
52
|
+
return offReason(home, env) === null;
|
|
53
|
+
}
|
|
54
|
+
/** One line for `graft telemetry status`, naming the gate that is closed so a
|
|
55
|
+
* user who thinks they disabled it can see which switch actually took. */
|
|
56
|
+
export function explainOff(reason) {
|
|
57
|
+
switch (reason) {
|
|
58
|
+
case 'no-key': return 'off — this build has no telemetry key (a fork, or a local `npm run build`); nothing can be sent';
|
|
59
|
+
case 'do-not-track': return 'off — DO_NOT_TRACK is set in this environment';
|
|
60
|
+
case 'ci': return 'off — this looks like CI';
|
|
61
|
+
case 'disabled': return 'off — you disabled it (`graft telemetry enable` to turn it back on)';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../../src/telemetry/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI1C,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC7D,MAAM,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC;IAC3B,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,MAAyB,OAAO,CAAC,GAAG;IACvD,IAAI,GAAG,CAAC,EAAE,KAAK,SAAS,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,CAAC,EAAE,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC/F,OAAO,OAAO,CACZ,GAAG,CAAC,cAAc,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,QAAQ;QACpE,GAAG,CAAC,gBAAgB,IA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