dsh-plugin-sessiongraph-native 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CC ZHAO
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/lib/index.d.ts ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Loader for the native Rust index kernel.
3
+ *
4
+ * The kernel is a napi-rs `cdylib` (`sessiongraph-core.<platform>-<arch>.node`) built from
5
+ * `crates/sessiongraph-core` and copied beside this module by `build-native.sh`. Nothing here may
6
+ * throw: a machine without a built binary is a normal state, and the caller decides whether to fall
7
+ * back to the TypeScript indexer. So every probe is wrapped, and a load failure simply yields
8
+ * `undefined`.
9
+ *
10
+ * Field names: the Rust side declares snake_case (`index_path`, `elapsed_ms`) and napi-rs maps them
11
+ * to camelCase JS properties (`indexPath`, `elapsedMs`), which is what {@link NativeIndexReport}
12
+ * describes. Verified against the built module by `tests/native.spec.ts`.
13
+ * @module dsh-plugin-sessiongraph-native
14
+ */
15
+ /** Options for one native index run. Mirrors the Rust `IndexOptions` (napi camelCases it). */
16
+ export interface NativeIndexOptions {
17
+ /** Directory the harness writes its session logs to (`~/.dsh/sessions`). */
18
+ sessionsRoot: string;
19
+ /** Absolute path of the index file to write (`<indexRoot>/index.db`). */
20
+ indexPath: string;
21
+ /** Rebuild every session from scratch into `index.db.tmp` and rename it into place. */
22
+ force?: boolean;
23
+ /** Index only sessions whose `cwd` matches this workspace (exact, or a prefix without `/`). */
24
+ workspaceFilter?: string;
25
+ /** Index only one session, by full id or unambiguous prefix. */
26
+ sessionFilter?: string;
27
+ /** Longest message text stored whole (default 4000). */
28
+ maxEntryChars?: number;
29
+ /** Longest tool invocation text stored whole (default 2000). */
30
+ toolCallChars?: number;
31
+ /** Logs larger than this are skipped and reported in `failed` (default 67108864). */
32
+ maxFileBytes?: number;
33
+ }
34
+ /** One session log the native kernel could not parse. */
35
+ export interface NativeFailedSession {
36
+ /** Absolute path of the log. */
37
+ path: string;
38
+ /** Bounded reason, at most 200 characters. */
39
+ reason: string;
40
+ }
41
+ /** What one native index run did. Field-for-field `SessiongraphIndexReport`. */
42
+ export interface NativeIndexReport {
43
+ /** Absolute path of the index the run wrote. */
44
+ indexPath: string;
45
+ /** Sessions added since the previous run. */
46
+ added: number;
47
+ /** Sessions whose source changed and were re-written. */
48
+ updated: number;
49
+ /** Sessions skipped because their source was unchanged. */
50
+ skipped: number;
51
+ /** Sessions dropped because their source file disappeared. */
52
+ removed: number;
53
+ /**
54
+ * Live (still-running) sessions rebuilt from the host's in-memory view this run. The native
55
+ * kernel has no access to the host's `sessionQuery`, so it always reports 0: the caller's live
56
+ * pass owns those rows, and this kernel preserves them (`live://` rows are never removed here).
57
+ */
58
+ liveSessions?: number;
59
+ /** Live sessions left out by the caller's cap. Always 0 from this kernel, for the same reason. */
60
+ liveSkipped?: number;
61
+ /** Sessions discovered in total across all source roots. */
62
+ discovered: number;
63
+ /** Sessions that failed to parse, with a bounded reason. */
64
+ failed: NativeFailedSession[];
65
+ /** Searchable entries in the index after the run. */
66
+ entries: number;
67
+ /** Sessions in the index after the run. */
68
+ sessions: number;
69
+ /** Distinct workspaces in the index after the run. */
70
+ workspaces: number;
71
+ /** Bytes the index occupies after the run. */
72
+ bytes: number;
73
+ /** Wall-clock duration of the run, milliseconds. */
74
+ elapsedMs: number;
75
+ }
76
+ /** The loaded native module's surface. */
77
+ export interface NativeKernel {
78
+ /**
79
+ * Build or refresh one index, synchronously.
80
+ * @param options - roots and scope switches.
81
+ * @returns what the run did.
82
+ * @throws when the index cannot be written; parse failures are reported, not thrown.
83
+ */
84
+ indexSessions(options: NativeIndexOptions): NativeIndexReport;
85
+ }
86
+ /**
87
+ * Load the native kernel, or report that this machine has none.
88
+ *
89
+ * Probes the build outputs in order — the local `.node` beside this module first, then the napi-rs
90
+ * platform-package convention — and returns `undefined` when none of them loads. It never throws,
91
+ * so an absent binary degrades to a caller-side fallback instead of a plugin load failure.
92
+ * @returns the kernel, or `undefined` when no usable binary is present.
93
+ */
94
+ export declare function loadNative(): NativeKernel | undefined;
95
+ //# sourceMappingURL=index.d.ts.map
package/lib/index.js ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Loader for the native Rust index kernel.
3
+ *
4
+ * The kernel is a napi-rs `cdylib` (`sessiongraph-core.<platform>-<arch>.node`) built from
5
+ * `crates/sessiongraph-core` and copied beside this module by `build-native.sh`. Nothing here may
6
+ * throw: a machine without a built binary is a normal state, and the caller decides whether to fall
7
+ * back to the TypeScript indexer. So every probe is wrapped, and a load failure simply yields
8
+ * `undefined`.
9
+ *
10
+ * Field names: the Rust side declares snake_case (`index_path`, `elapsed_ms`) and napi-rs maps them
11
+ * to camelCase JS properties (`indexPath`, `elapsedMs`), which is what {@link NativeIndexReport}
12
+ * describes. Verified against the built module by `tests/native.spec.ts`.
13
+ * @module dsh-plugin-sessiongraph-native
14
+ */
15
+ import { createRequire } from 'node:module';
16
+ /** `undefined` until the first {@link loadNative} call, then the kernel or `null` when absent. */
17
+ let cached;
18
+ /**
19
+ * Load the native kernel, or report that this machine has none.
20
+ *
21
+ * Probes the build outputs in order — the local `.node` beside this module first, then the napi-rs
22
+ * platform-package convention — and returns `undefined` when none of them loads. It never throws,
23
+ * so an absent binary degrades to a caller-side fallback instead of a plugin load failure.
24
+ * @returns the kernel, or `undefined` when no usable binary is present.
25
+ */
26
+ export function loadNative() {
27
+ if (cached !== undefined)
28
+ return cached ?? undefined;
29
+ cached = null;
30
+ try {
31
+ const require = createRequire(import.meta.url);
32
+ for (const specifier of candidateSpecifiers()) {
33
+ try {
34
+ const loaded = require(specifier);
35
+ const kernel = asKernel(loaded);
36
+ if (kernel !== undefined) {
37
+ cached = kernel;
38
+ return kernel;
39
+ }
40
+ }
41
+ catch {
42
+ // Missing, unbuilt, or built for another ABI: try the next candidate.
43
+ }
44
+ }
45
+ }
46
+ catch {
47
+ // `createRequire` cannot fail in practice; keep the no-throw contract regardless.
48
+ }
49
+ return undefined;
50
+ }
51
+ /**
52
+ * Candidate module specifiers for the built binary, most local first.
53
+ * @returns specifiers to probe in order.
54
+ */
55
+ function candidateSpecifiers() {
56
+ const platform = `${process.platform}-${process.arch}`;
57
+ return [
58
+ `../sessiongraph-core.${platform}.node`,
59
+ `../dsh-plugin-sessiongraph-native.${platform}.node`,
60
+ `dsh-plugin-sessiongraph-native-${platform}`,
61
+ '../sessiongraph-core.node',
62
+ ];
63
+ }
64
+ /**
65
+ * Narrow a loaded module to the kernel surface.
66
+ * @param value - whatever `require` returned.
67
+ * @returns the kernel, or undefined when the shape is wrong.
68
+ */
69
+ function asKernel(value) {
70
+ if (typeof value !== 'object' || value === null)
71
+ return undefined;
72
+ const candidate = value;
73
+ return typeof candidate.indexSessions === 'function' ? candidate : undefined;
74
+ }
75
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "dsh-plugin-sessiongraph-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Native Rust index kernel for DeepSeek Harness sessiongraph — scan, multi-frame zstd decode, JSONL parse and SQLite write, exposed to Node through napi-rs",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "cordis",
10
+ "sessiongraph",
11
+ "session",
12
+ "session-history",
13
+ "indexer",
14
+ "zstd",
15
+ "sqlite",
16
+ "rust",
17
+ "napi",
18
+ "ai-agent"
19
+ ],
20
+ "license": "MIT",
21
+ "author": "CC ZHAO",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/CC19990113/dsh-plugin-sessiongraph.git",
25
+ "directory": "packages/native"
26
+ },
27
+ "homepage": "https://github.com/CC19990113/dsh-plugin-sessiongraph#readme",
28
+ "bugs": "https://github.com/CC19990113/dsh-plugin-sessiongraph/issues",
29
+ "type": "module",
30
+ "main": "lib/index.js",
31
+ "types": "lib/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./lib/index.d.ts",
35
+ "default": "./lib/index.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "files": [
40
+ "*.node",
41
+ "lib/**/*.js",
42
+ "lib/**/*.d.ts"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "provenance": true
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^22.10.0"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -b",
53
+ "build:native": "./build-native.sh"
54
+ }
6
55
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.