notex-companion 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +875 -0
- package/dist/context.d.ts +6 -0
- package/dist/cors.d.ts +9 -0
- package/dist/footer.d.ts +12 -0
- package/dist/graph.d.ts +39 -0
- package/dist/http.d.ts +21 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +769 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/net.d.ts +14 -0
- package/dist/ops.d.ts +75 -0
- package/dist/pairing.d.ts +6 -0
- package/dist/scoring.d.ts +17 -0
- package/dist/serve.d.ts +26 -0
- package/dist/traversal.d.ts +16 -0
- package/dist/types.d.ts +68 -0
- package/package.json +43 -0
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startMcpStub(): void;
|
package/dist/net.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type FetchHandler = (req: Request) => Promise<Response>;
|
|
2
|
+
export type MinimalServer = {
|
|
3
|
+
readonly hostname: string;
|
|
4
|
+
readonly port: number;
|
|
5
|
+
stop(closeActiveConnections?: boolean): void;
|
|
6
|
+
};
|
|
7
|
+
export type StartServerOptions = {
|
|
8
|
+
hostname: string;
|
|
9
|
+
port: number;
|
|
10
|
+
fetch: FetchHandler;
|
|
11
|
+
};
|
|
12
|
+
export type Runtime = "bun" | "node";
|
|
13
|
+
export declare function detectRuntime(): Runtime;
|
|
14
|
+
export declare function startServer(opts: StartServerOptions, runtime?: Runtime): MinimalServer;
|
package/dist/ops.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { GraphIndex } from "./graph.js";
|
|
2
|
+
import { type GraphEdge, type GraphNode, type OpResponse } from "./types.js";
|
|
3
|
+
/** Also the version /v1/ping reports (companion-api.md §4.1) — the two must never drift apart. */
|
|
4
|
+
export declare const API_VERSION = "0.1.0";
|
|
5
|
+
export type StatusResult = {
|
|
6
|
+
apiVersion: string;
|
|
7
|
+
capabilities: string[];
|
|
8
|
+
limits: {
|
|
9
|
+
maxNodes: number;
|
|
10
|
+
maxDepth: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare function status(index: GraphIndex): OpResponse<StatusResult>;
|
|
14
|
+
export type SearchRequest = {
|
|
15
|
+
q: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
};
|
|
18
|
+
export type SearchResult = {
|
|
19
|
+
results: Array<GraphNode & {
|
|
20
|
+
score: number;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export declare function search(index: GraphIndex, req: SearchRequest): OpResponse<SearchResult>;
|
|
24
|
+
export type QueryRequest = {
|
|
25
|
+
question: string;
|
|
26
|
+
terms?: string[];
|
|
27
|
+
depth?: number;
|
|
28
|
+
maxNodes?: number;
|
|
29
|
+
seeds?: number;
|
|
30
|
+
include?: Array<"subgraph" | "context" | "footer">;
|
|
31
|
+
};
|
|
32
|
+
export type QueryResult = {
|
|
33
|
+
subgraph: {
|
|
34
|
+
nodes: GraphNode[];
|
|
35
|
+
edges: GraphEdge[];
|
|
36
|
+
seeds: string[];
|
|
37
|
+
};
|
|
38
|
+
context?: {
|
|
39
|
+
markdown: string;
|
|
40
|
+
sources: Array<{
|
|
41
|
+
file: string;
|
|
42
|
+
location: string;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
/** See companion-api.md §4.8 / notex-mcp-server.md §5 — same buildFooter as the write paths. */
|
|
46
|
+
footer?: string;
|
|
47
|
+
/** Set when no seed cleared the seed-score floor — an exact label or label-token match. */
|
|
48
|
+
lowConfidence?: {
|
|
49
|
+
topScore: number;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare function query(index: GraphIndex, req: QueryRequest): OpResponse<QueryResult>;
|
|
53
|
+
export type PathRequest = {
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
maxDepth?: number;
|
|
57
|
+
};
|
|
58
|
+
export type PathResult = {
|
|
59
|
+
found: boolean;
|
|
60
|
+
nodes: GraphNode[];
|
|
61
|
+
edges: GraphEdge[];
|
|
62
|
+
};
|
|
63
|
+
/** Fully deterministic, undirected, no scoring (companion-api.md §4.5) — plain BFS. */
|
|
64
|
+
export declare function path(index: GraphIndex, req: PathRequest): OpResponse<PathResult>;
|
|
65
|
+
export type NodeRequest = {
|
|
66
|
+
id: string;
|
|
67
|
+
};
|
|
68
|
+
export type NodeResult = {
|
|
69
|
+
node: GraphNode;
|
|
70
|
+
neighbours: Array<{
|
|
71
|
+
node: GraphNode;
|
|
72
|
+
edge: GraphEdge;
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
export declare function node(index: GraphIndex, req: NodeRequest): OpResponse<NodeResult>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Loads the persisted token, or generates and persists a new one. `rotate: true` always regenerates. */
|
|
2
|
+
export declare function loadOrCreateToken(checkoutPath: string, opts?: {
|
|
3
|
+
rotate?: boolean;
|
|
4
|
+
}): string;
|
|
5
|
+
/** The single pasteable line printed at startup (companion-api.md §3.2). */
|
|
6
|
+
export declare function pairingLine(baseUrl: string, token: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** camelCase / snake_case / path segments → discrete lowercase tokens. */
|
|
2
|
+
export declare function shatter(text: string): string[];
|
|
3
|
+
export declare function terms(question: string): string[];
|
|
4
|
+
export type ScoreIndexEntry = {
|
|
5
|
+
id: string;
|
|
6
|
+
labelTokens: Set<string>;
|
|
7
|
+
pathTokens: Set<string>;
|
|
8
|
+
labelLower: string;
|
|
9
|
+
};
|
|
10
|
+
export type ScoredNode = {
|
|
11
|
+
id: string;
|
|
12
|
+
score: number;
|
|
13
|
+
/** Cleared the seed-score floor: at least one term matched a whole label or a whole label token. */
|
|
14
|
+
exact: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** label tokens weigh full; path tokens weigh less — a path match is weaker evidence. */
|
|
17
|
+
export declare function scoreNodes(index: ScoreIndexEntry[], queryTerms: string[]): ScoredNode[];
|
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type GraphState } from "./http.js";
|
|
2
|
+
import { type MinimalServer } from "./net.js";
|
|
3
|
+
export type ServeOptions = {
|
|
4
|
+
/** Absolute path of the checkout to serve — where graphify-out/graph.json and .notex/ live. */
|
|
5
|
+
checkoutPath: string;
|
|
6
|
+
/**
|
|
7
|
+
* Fixed at 7717 by default (companion-api.md §3.1). Pass 0 for an OS-assigned port — but
|
|
8
|
+
* only under Bun (`bun test`, or any consumer running on the Bun runtime): the plain-Node
|
|
9
|
+
* fallback in net.ts binds synchronously and can't read back an OS-assigned port before
|
|
10
|
+
* returning, so it throws for `port: 0` rather than silently ignoring it.
|
|
11
|
+
*/
|
|
12
|
+
port?: number;
|
|
13
|
+
/** Additional allowed origins beyond the dev default (companion-api.md §5). */
|
|
14
|
+
origins?: string[];
|
|
15
|
+
rotateToken?: boolean;
|
|
16
|
+
nodeEnv?: string;
|
|
17
|
+
/** Fires once the graph finishes loading (or fails to) — the CLI uses this for startup output. */
|
|
18
|
+
onGraphState?: (state: GraphState) => void;
|
|
19
|
+
};
|
|
20
|
+
export type ServeHandle = {
|
|
21
|
+
server: MinimalServer;
|
|
22
|
+
token: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
pairingLine: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function serve(opts: ServeOptions): ServeHandle;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Truncated } from "./types.js";
|
|
2
|
+
export type TraversalEdge = {
|
|
3
|
+
source: string;
|
|
4
|
+
target: string;
|
|
5
|
+
weight: number;
|
|
6
|
+
};
|
|
7
|
+
export type AdjacencyMap<E> = Map<string, Array<{
|
|
8
|
+
other: string;
|
|
9
|
+
edge: E;
|
|
10
|
+
}>>;
|
|
11
|
+
export type TraversalResult<E> = {
|
|
12
|
+
nodeIds: string[];
|
|
13
|
+
edges: E[];
|
|
14
|
+
truncated: Truncated | null;
|
|
15
|
+
};
|
|
16
|
+
export declare function traverse<E extends TraversalEdge>(adjacency: AdjacencyMap<E>, allEdges: E[], seedIds: string[], depth: number, maxNodes: number): TraversalResult<E>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Returned by `status` and echoed on every op response. */
|
|
2
|
+
export type GraphStamp = {
|
|
3
|
+
builtAt: string;
|
|
4
|
+
graphHash: string;
|
|
5
|
+
nodeCount: number;
|
|
6
|
+
edgeCount: number;
|
|
7
|
+
communityCount: number;
|
|
8
|
+
checkoutPath: string;
|
|
9
|
+
headSha: string | null;
|
|
10
|
+
graphRoot: string;
|
|
11
|
+
rootPrefix: string;
|
|
12
|
+
};
|
|
13
|
+
export type GraphNode = {
|
|
14
|
+
id: string;
|
|
15
|
+
label: string;
|
|
16
|
+
sourceFile: string;
|
|
17
|
+
sourceLocation: string;
|
|
18
|
+
fileType: string;
|
|
19
|
+
community: {
|
|
20
|
+
id: number;
|
|
21
|
+
name: string;
|
|
22
|
+
} | null;
|
|
23
|
+
};
|
|
24
|
+
export type GraphEdge = {
|
|
25
|
+
source: string;
|
|
26
|
+
target: string;
|
|
27
|
+
relation: string;
|
|
28
|
+
weight: number;
|
|
29
|
+
confidence: string;
|
|
30
|
+
sourceFile: string;
|
|
31
|
+
sourceLocation: string;
|
|
32
|
+
};
|
|
33
|
+
export type Truncated = {
|
|
34
|
+
reason: "maxNodes" | "depth";
|
|
35
|
+
omittedCount: number;
|
|
36
|
+
};
|
|
37
|
+
export type Degraded = {
|
|
38
|
+
expansion: "none";
|
|
39
|
+
};
|
|
40
|
+
export type OpResponse<T> = {
|
|
41
|
+
graph: GraphStamp;
|
|
42
|
+
degraded?: Degraded;
|
|
43
|
+
truncated?: Truncated;
|
|
44
|
+
} & T;
|
|
45
|
+
export type ErrorResponse = {
|
|
46
|
+
error: {
|
|
47
|
+
code: string;
|
|
48
|
+
message: string;
|
|
49
|
+
detail?: unknown;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare const ERROR_CODES: {
|
|
53
|
+
readonly unauthorized: "unauthorized";
|
|
54
|
+
readonly notFound: "not_found";
|
|
55
|
+
readonly graphUnreadable: "graph_unreadable";
|
|
56
|
+
readonly invalidRequest: "invalid_request";
|
|
57
|
+
readonly graphLoading: "graph_loading";
|
|
58
|
+
};
|
|
59
|
+
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
60
|
+
/**
|
|
61
|
+
* Thrown by ops for the error cases in companion-api.md §2.4. A transport binding
|
|
62
|
+
* (REST, MCP) maps `code` to its own status/error shape; this module stays transport-free.
|
|
63
|
+
*/
|
|
64
|
+
export declare class OpError extends Error {
|
|
65
|
+
readonly code: ErrorCode;
|
|
66
|
+
readonly detail?: unknown;
|
|
67
|
+
constructor(code: ErrorCode, message: string, detail?: unknown);
|
|
68
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "notex-companion",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local retrieval companion for Notex — reads a checkout's graphify-out/graph.json and serves deterministic search/query/path/node lookups over loopback HTTP and (stub) MCP stdio. No LLM, no graph building, no network beyond 127.0.0.1.",
|
|
5
|
+
"keywords": ["notex", "graphify", "mcp", "code-graph"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/bhirmbani/notex.git",
|
|
10
|
+
"directory": "packages/companion"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/bhirmbani/notex/tree/main/packages/companion#readme",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"bin": {
|
|
15
|
+
"notex-companion": "dist/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist", "README.md"],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "bun test",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"build": "rm -rf dist && bun run build:cli && bun run build:lib && bun run build:types && chmod +x dist/cli.js",
|
|
34
|
+
"build:cli": "bun build ./src/bin.ts --target=node --format=esm --outfile=dist/cli.js --banner=\"#!/usr/bin/env node\"",
|
|
35
|
+
"build:lib": "bun build ./src/index.ts --target=node --format=esm --outfile=dist/index.js",
|
|
36
|
+
"build:types": "tsc -p tsconfig.build.json && node scripts/fix-dts-extensions.mjs",
|
|
37
|
+
"prepublishOnly": "bun run typecheck && bun test && bun run build"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/bun": "^1.3.14",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
42
|
+
}
|
|
43
|
+
}
|