@nanonets/graft 0.10.1 → 0.12.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/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/viz/assemble.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export interface VizNode {
|
|
|
4
4
|
type: string;
|
|
5
5
|
summary: string;
|
|
6
6
|
sources: string[];
|
|
7
|
+
/** Code to show under the node, in place of `sources`. Set by
|
|
8
|
+
* `blast --export-viz`, where every node stands for real changed lines. */
|
|
9
|
+
evidence?: Evidence[];
|
|
7
10
|
}
|
|
8
11
|
export interface VizEdge {
|
|
9
12
|
source: string;
|
|
@@ -11,12 +14,42 @@ export interface VizEdge {
|
|
|
11
14
|
relation: string;
|
|
12
15
|
description?: string;
|
|
13
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* One line of code shown under a node, with the sign git gave it (` ` for an
|
|
19
|
+
* unchanged line quoted as context — the affected side has no diff to show).
|
|
20
|
+
*/
|
|
21
|
+
export interface EvidenceLine {
|
|
22
|
+
/** Post-image line number; a deleted line has none. */
|
|
23
|
+
n: number | null;
|
|
24
|
+
sign: "+" | "-" | " ";
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A snippet a panel shows instead of a bare path.
|
|
29
|
+
*
|
|
30
|
+
* A reviewer reading "src/blast/blast-cli.ts · L172-L193" has to go and open the
|
|
31
|
+
* file to learn anything; the same block with four lines of the actual change in
|
|
32
|
+
* it answers the question where they are standing.
|
|
33
|
+
*/
|
|
34
|
+
export interface Evidence {
|
|
35
|
+
/** `symbol · path:12-34` — grep-able, because a span alone is not. */
|
|
36
|
+
label: string;
|
|
37
|
+
/** Why these lines are here, e.g. `calls blastVizGraph` or `added`. */
|
|
38
|
+
note?: string;
|
|
39
|
+
lines: EvidenceLine[];
|
|
40
|
+
/** Lines the cap dropped, so a folded hunk says so rather than lying. */
|
|
41
|
+
more?: number;
|
|
42
|
+
}
|
|
14
43
|
export interface VizGraph {
|
|
15
44
|
meta: {
|
|
16
45
|
nodeCount: number;
|
|
17
46
|
edgeCount: number;
|
|
18
47
|
skippedFiles: number;
|
|
19
48
|
droppedEdges: number;
|
|
49
|
+
/** Why there is nothing to draw, when there is nothing to draw. A published
|
|
50
|
+
* page cannot answer a question a reader asks of the console, so an empty
|
|
51
|
+
* canvas has to say what it means — see `blastVizGraph`. */
|
|
52
|
+
emptyNote?: string;
|
|
20
53
|
};
|
|
21
54
|
nodes: VizNode[];
|
|
22
55
|
edges: VizEdge[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assemble.d.ts","sourceRoot":"","sources":["../../src/viz/assemble.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"assemble.d.ts","sourceRoot":"","sources":["../../src/viz/assemble.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;+EAC2E;IAC3E,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,uDAAuD;IACvD,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjB,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB;;oEAE4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKrD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAErD;AAoBD,uEAAuE;AACvE,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAmDjE"}
|
package/dist/viz/assemble.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../src/viz/assemble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../src/viz/assemble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;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AK,CAAC,MAAM;SAC7C;QACD,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type VizGraph } from "./assemble.js";
|
|
2
|
+
export interface VizExportOptions {
|
|
3
|
+
contextDir: string;
|
|
4
|
+
/** Where index.html, app.js and style.css were bundled (dist/viewer). */
|
|
5
|
+
viewerDir: string;
|
|
6
|
+
/** Directory to write index.html into. Created if absent. */
|
|
7
|
+
outDir: string;
|
|
8
|
+
repoName: string;
|
|
9
|
+
/** Shown in the appbar beside the repo name — e.g. "PR #151". */
|
|
10
|
+
subtitle?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Context graph to inline instead of assembling one from the deep tier's concept
|
|
13
|
+
* files. `graft blast --export-viz` passes the blast radius itself, which is how a
|
|
14
|
+
* PR gets a Context tab worth opening without a `--deep` build.
|
|
15
|
+
*/
|
|
16
|
+
contextGraph?: VizGraph;
|
|
17
|
+
/**
|
|
18
|
+
* Tabs the page offers. Default: all three.
|
|
19
|
+
*
|
|
20
|
+
* A blast page passes `["context"]`. The Code tab there is the repo's whole
|
|
21
|
+
* wiring graph — 1,377 nodes on graft itself, a hairball that answers nothing
|
|
22
|
+
* about the pull request, and ~95% of the exported megabyte — and Outline is the
|
|
23
|
+
* repo's file tree. Dropping them makes the page a tenth of the size and removes
|
|
24
|
+
* two tabs a reviewer has no reason to open.
|
|
25
|
+
*/
|
|
26
|
+
tabs?: Array<"context" | "code" | "outline">;
|
|
27
|
+
}
|
|
28
|
+
export interface VizExportResult {
|
|
29
|
+
file: string;
|
|
30
|
+
bytes: number;
|
|
31
|
+
contextNodes: number;
|
|
32
|
+
codeNodes: number;
|
|
33
|
+
/** Tab the exported page opens on — see the reasoning in {@link exportViz}. */
|
|
34
|
+
defaultTab: "context" | "code";
|
|
35
|
+
/** Tabs written into the page. */
|
|
36
|
+
tabs: Array<"context" | "code" | "outline">;
|
|
37
|
+
}
|
|
38
|
+
export declare function exportViz(opts: VizExportOptions): VizExportResult;
|
|
39
|
+
//# sourceMappingURL=export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/viz/export.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAwB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAC;IACxB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,UAAU,EAAE,SAAS,GAAG,MAAM,CAAC;IAC/B,kCAAkC;IAClC,IAAI,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;CAC7C;AAmCD,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,eAAe,CAmDjE"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `graft viz --export <dir>`: the same viewer, as one self-contained HTML file.
|
|
3
|
+
*
|
|
4
|
+
* This exists so a PR comment has somewhere real to point. A Mermaid diagram in a
|
|
5
|
+
* comment can hold about five circles before it stops being readable, and it can
|
|
6
|
+
* never hold the thing a reviewer actually wants next — click an area, see its
|
|
7
|
+
* dependent symbols at exact `file:line`. Every other tool in this space solved
|
|
8
|
+
* that the same way: keep a small table in the comment and link out to a hosted
|
|
9
|
+
* view. Exporting rather than hosting keeps graft's promise intact — no account, no
|
|
10
|
+
* server, no telemetry; the artifact is a file you can open with `file://`, publish
|
|
11
|
+
* to GitHub Pages, or attach to a build.
|
|
12
|
+
*
|
|
13
|
+
* The output inlines the CSS, the bundled JS and both graphs, because a file served
|
|
14
|
+
* from a Pages subdirectory cannot rely on absolute asset paths (`/app.js` resolves
|
|
15
|
+
* to the domain root, not the PR's folder) and a reader must not need a web server.
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { assembleContextGraph } from "./assemble.js";
|
|
20
|
+
/** The wiring graph as the viewer's endpoint would have served it, or null. */
|
|
21
|
+
function codeGraph(contextDir) {
|
|
22
|
+
const file = join(contextDir, ".graph", "wiring.json");
|
|
23
|
+
if (!existsSync(file))
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
27
|
+
return parsed?.meta?.version === 1 ? parsed : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* JSON safe to drop inside a `<script>` element.
|
|
35
|
+
*
|
|
36
|
+
* `</script>` anywhere in the data — a summary quoting HTML, a symbol named after a
|
|
37
|
+
* tag — would close the element and spill the rest of the graph into the page as
|
|
38
|
+
* text. `<` is escaped as a unicode sequence, which is still valid JSON to the
|
|
39
|
+
* parser and inert to the HTML tokenizer.
|
|
40
|
+
*/
|
|
41
|
+
function inlineJson(value) {
|
|
42
|
+
return JSON.stringify(value ?? null)
|
|
43
|
+
.replace(/</g, "\\u003c")
|
|
44
|
+
// Line and paragraph separators are legal in a JSON string and illegal in a
|
|
45
|
+
// JavaScript source line, so an unescaped one is a syntax error at load time.
|
|
46
|
+
.replace(/\u2028/g, "\\u2028")
|
|
47
|
+
.replace(/\u2029/g, "\\u2029");
|
|
48
|
+
}
|
|
49
|
+
/** The two tags this exporter rewrites, verbatim from viewer/index.html. */
|
|
50
|
+
const LINK_TAG = '<link rel="stylesheet" href="/style.css">';
|
|
51
|
+
const SCRIPT_TAG = '<script type="module" src="/app.js"></script>';
|
|
52
|
+
export function exportViz(opts) {
|
|
53
|
+
const html = readFileSync(join(opts.viewerDir, "index.html"), "utf8");
|
|
54
|
+
// Checked on the SOURCE, before anything is inlined. Checking the assembled page
|
|
55
|
+
// instead looks equivalent and is not: a stylesheet comment or a bundled string
|
|
56
|
+
// containing one of these tags would fail an export that was in fact correct.
|
|
57
|
+
if (!html.includes(LINK_TAG) || !html.includes(SCRIPT_TAG)) {
|
|
58
|
+
throw new Error("viz export: viewer/index.html no longer matches the asset tags this exporter rewrites");
|
|
59
|
+
}
|
|
60
|
+
const css = readFileSync(join(opts.viewerDir, "style.css"), "utf8");
|
|
61
|
+
const js = readFileSync(join(opts.viewerDir, "app.js"), "utf8");
|
|
62
|
+
const context = opts.contextGraph ?? assembleContextGraph(opts.contextDir);
|
|
63
|
+
const tabs = opts.tabs ?? ["context", "code", "outline"];
|
|
64
|
+
// Both remaining tabs read the wiring graph, so dropping them drops the payload
|
|
65
|
+
// as well — the point of the option, not a side effect of it.
|
|
66
|
+
const wanted = tabs.includes("code") || tabs.includes("outline");
|
|
67
|
+
const code = wanted ? codeGraph(opts.contextDir) : null;
|
|
68
|
+
// Which tab to open on. The viewer starts on Context, which only a `--deep` build
|
|
69
|
+
// fills: a structural build writes wiring cards (no frontmatter, so nothing to
|
|
70
|
+
// assemble) and INDEX.md, and INDEX alone assembles to a single node. Since the
|
|
71
|
+
// PR path is now structural by design, opening on Context would show a canvas
|
|
72
|
+
// with one dot while the whole wiring graph sat behind an unadvertised tab.
|
|
73
|
+
const codeNodes = code?.nodes?.length ?? 0;
|
|
74
|
+
// A supplied graph is the caller's whole point, so it is always the landing tab.
|
|
75
|
+
const defaultTab = opts.contextGraph || context.nodes.length > 1 || codeNodes === 0 ? "context" : "code";
|
|
76
|
+
const contextGraph = {
|
|
77
|
+
...context,
|
|
78
|
+
meta: { ...context.meta, repoName: opts.repoName, subtitle: opts.subtitle, defaultTab, tabs },
|
|
79
|
+
};
|
|
80
|
+
const data = [
|
|
81
|
+
"<script>window.__GRAFT_DATA__ = {",
|
|
82
|
+
` contextGraph: ${inlineJson(contextGraph)},`,
|
|
83
|
+
` codeGraph: ${inlineJson(code)}`,
|
|
84
|
+
"};</script>",
|
|
85
|
+
].join("\n");
|
|
86
|
+
// Replacer FUNCTIONS, not replacement strings: `$&`, `$\'` and friends are
|
|
87
|
+
// substitution patterns inside a replacement string, and a minified bundle is
|
|
88
|
+
// full of them — the first version of this put the original `<script src>` tag
|
|
89
|
+
// back into the page via a stray `$&` in app.js. A function is taken verbatim.
|
|
90
|
+
const page = html
|
|
91
|
+
.replace(LINK_TAG, () => `<style>\n${css}\n</style>`)
|
|
92
|
+
.replace(SCRIPT_TAG, () => `${data}\n<script type="module">\n${js}\n</script>`);
|
|
93
|
+
mkdirSync(opts.outDir, { recursive: true });
|
|
94
|
+
const file = join(opts.outDir, "index.html");
|
|
95
|
+
writeFileSync(file, page);
|
|
96
|
+
return { file, bytes: Buffer.byteLength(page), contextNodes: contextGraph.nodes.length, codeNodes, defaultTab, tabs };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/viz/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAiB,MAAM,eAAe,CAAC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,IAAI,GAAG;QACX,mCAAmC;QACnC,mBAAmB,UAAU,CAAC,YAAY,CAAC,GAAG;QAC9C,gBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE;QAClC,aAAa;KACd,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,2EAA2E;IAC3E,8EAA8E;IAC9E,+EAA+E;IAC/E,+EAA+E;IAC/E,MAAM,IAAI,GAAG,IAAI;SACd,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,YAAY,GAAG,YAAY,CAAC;SACpD,OAAO,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,6BAA6B,EAAE,aAAa,CAAC,CAAC;IAElF,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC7C,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AACxH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nanonets/graft",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Build a repo's context graph as a folder of linked markdown files
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "Build a repo's context graph as a folder of linked markdown files: a local, regenerable cache that every query keeps in sync with your code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
7
7
|
"agents",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"cli": "tsx src/cli.ts",
|
|
49
49
|
"test": "node scripts/run-tests.mjs",
|
|
50
50
|
"prepare": "npm run build",
|
|
51
|
-
"prepublishOnly": "npm run build",
|
|
51
|
+
"prepublishOnly": "npm run build && node scripts/stamp-telemetry-key.mjs",
|
|
52
52
|
"postinstall": "node scripts/postinstall.mjs"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=20"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@anthropic-ai/sdk": "^0.
|
|
58
|
+
"@anthropic-ai/sdk": "^0.116.0",
|
|
59
59
|
"commander": "^15.0.0",
|
|
60
60
|
"dotenv": "^17.4.2",
|
|
61
61
|
"gray-matter": "^4.0.3",
|
|
@@ -63,9 +63,10 @@
|
|
|
63
63
|
"tree-sitter": "^0.21.1",
|
|
64
64
|
"tree-sitter-go": "^0.23.4",
|
|
65
65
|
"tree-sitter-java": "^0.23.5",
|
|
66
|
+
"tree-sitter-php": "^0.23.4",
|
|
66
67
|
"tree-sitter-python": "^0.21.0",
|
|
67
68
|
"tree-sitter-typescript": "^0.23.2",
|
|
68
|
-
"tree-sitter-
|
|
69
|
+
"tree-sitter-wasm": "^1.1.4",
|
|
69
70
|
"vscode-jsonrpc": "^8.2.1",
|
|
70
71
|
"vscode-languageserver-protocol": "^3.18.2",
|
|
71
72
|
"web-tree-sitter": "^0.25.10"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bakes the PostHog key into the built `dist/telemetry/key.js` at publish time.
|
|
3
|
+
*
|
|
4
|
+
* This is what makes "forks never send" true by construction rather than by
|
|
5
|
+
* policy. The key exists only in the published tarball: the repository holds an
|
|
6
|
+
* empty string, so a clone, a fork, a CI build, and a contributor's local
|
|
7
|
+
* `npm run build` all produce a graft whose telemetry module short-circuits on
|
|
8
|
+
* the very first check.
|
|
9
|
+
*
|
|
10
|
+
* Runs from `prepublishOnly`, after `npm run build`. Without GRAFT_POSTHOG_KEY
|
|
11
|
+
* in the environment it prints a warning and changes nothing — publishing a
|
|
12
|
+
* telemetry-less build is a valid thing to do, and it must never be a hard
|
|
13
|
+
* failure at the moment someone is trying to ship.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
|
|
19
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
20
|
+
const target = join(root, 'dist', 'telemetry', 'key.js');
|
|
21
|
+
|
|
22
|
+
const key = process.env.GRAFT_POSTHOG_KEY ?? '';
|
|
23
|
+
const host = process.env.GRAFT_POSTHOG_HOST ?? '';
|
|
24
|
+
|
|
25
|
+
if (!key) {
|
|
26
|
+
console.warn('⚠ GRAFT_POSTHOG_KEY not set — publishing a build that sends no telemetry.');
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
if (!existsSync(target)) {
|
|
30
|
+
console.warn(`⚠ ${target} not found — did the build run? Skipping the telemetry key stamp.`);
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
// A key with a quote or a newline in it would break the generated literal (and
|
|
34
|
+
// is not a PostHog key). Refuse rather than emit something that won't parse.
|
|
35
|
+
if (!/^[A-Za-z0-9_-]+$/.test(key)) {
|
|
36
|
+
console.error('✗ GRAFT_POSTHOG_KEY contains characters that are not valid in a project key.');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
if (host && !/^https:\/\/[A-Za-z0-9.-]+(:\d+)?$/.test(host)) {
|
|
40
|
+
console.error('✗ GRAFT_POSTHOG_HOST must be a plain https origin, e.g. https://eu.i.posthog.com');
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const src = readFileSync(target, 'utf8');
|
|
45
|
+
let out = src.replace(/const BAKED_KEY = ['"][^'"]*['"];/, `const BAKED_KEY = '${key}';`);
|
|
46
|
+
if (host) out = out.replace(/const BAKED_HOST = ['"][^'"]*['"];/, `const BAKED_HOST = '${host}';`);
|
|
47
|
+
|
|
48
|
+
if (out === src) {
|
|
49
|
+
console.error('✗ could not find BAKED_KEY in dist/telemetry/key.js — the stamp target moved.');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
writeFileSync(target, out);
|
|
53
|
+
console.log(`✓ telemetry key stamped into dist/telemetry/key.js${host ? ` (host ${host})` : ''}`);
|