@etilic/rutter_ai 0.0.0-stage → 0.2.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.
Files changed (66) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +80 -2
  3. package/THIRD_PARTY_LICENSES.txt +111 -0
  4. package/bin/cli.cjs +94 -0
  5. package/bin/npm-runtime.cjs +125 -0
  6. package/client/darwin-arm64/bootstrap.cjs +159 -0
  7. package/client/darwin-arm64/compat.cjs +61 -0
  8. package/client/darwin-arm64/hook.cjs +597 -0
  9. package/client/darwin-arm64/install.cjs +555 -0
  10. package/client/darwin-arm64/manifest.json +1 -0
  11. package/client/darwin-arm64/mcp.cjs +5666 -0
  12. package/client/darwin-arm64/migration.cjs +53 -0
  13. package/client/darwin-arm64/node_sqlite3.node +0 -0
  14. package/client/darwin-arm64/ordered-upload.cjs +236 -0
  15. package/client/darwin-arm64/outbox.cjs +218 -0
  16. package/client/darwin-arm64/recovery.cjs +61 -0
  17. package/client/darwin-arm64/sqlite3.cjs +217 -0
  18. package/client/darwin-arm64/transcript.cjs +138 -0
  19. package/client/darwin-arm64/upload.cjs +446 -0
  20. package/client/darwin-arm64/worker.cjs +76 -0
  21. package/client/darwin-x64/bootstrap.cjs +159 -0
  22. package/client/darwin-x64/compat.cjs +61 -0
  23. package/client/darwin-x64/hook.cjs +597 -0
  24. package/client/darwin-x64/install.cjs +555 -0
  25. package/client/darwin-x64/manifest.json +1 -0
  26. package/client/darwin-x64/mcp.cjs +5666 -0
  27. package/client/darwin-x64/migration.cjs +53 -0
  28. package/client/darwin-x64/node_sqlite3.node +0 -0
  29. package/client/darwin-x64/ordered-upload.cjs +236 -0
  30. package/client/darwin-x64/outbox.cjs +218 -0
  31. package/client/darwin-x64/recovery.cjs +61 -0
  32. package/client/darwin-x64/sqlite3.cjs +217 -0
  33. package/client/darwin-x64/transcript.cjs +138 -0
  34. package/client/darwin-x64/upload.cjs +446 -0
  35. package/client/darwin-x64/worker.cjs +76 -0
  36. package/client/linux-x64-glibc/bootstrap.cjs +159 -0
  37. package/client/linux-x64-glibc/compat.cjs +61 -0
  38. package/client/linux-x64-glibc/hook.cjs +597 -0
  39. package/client/linux-x64-glibc/install.cjs +555 -0
  40. package/client/linux-x64-glibc/manifest.json +1 -0
  41. package/client/linux-x64-glibc/mcp.cjs +5666 -0
  42. package/client/linux-x64-glibc/migration.cjs +53 -0
  43. package/client/linux-x64-glibc/node_sqlite3.node +0 -0
  44. package/client/linux-x64-glibc/ordered-upload.cjs +236 -0
  45. package/client/linux-x64-glibc/outbox.cjs +218 -0
  46. package/client/linux-x64-glibc/recovery.cjs +61 -0
  47. package/client/linux-x64-glibc/sqlite3.cjs +217 -0
  48. package/client/linux-x64-glibc/transcript.cjs +138 -0
  49. package/client/linux-x64-glibc/upload.cjs +446 -0
  50. package/client/linux-x64-glibc/worker.cjs +76 -0
  51. package/client/win32-x64/bootstrap.cjs +159 -0
  52. package/client/win32-x64/compat.cjs +61 -0
  53. package/client/win32-x64/hook.cjs +597 -0
  54. package/client/win32-x64/install.cjs +555 -0
  55. package/client/win32-x64/manifest.json +1 -0
  56. package/client/win32-x64/mcp.cjs +5666 -0
  57. package/client/win32-x64/migration.cjs +53 -0
  58. package/client/win32-x64/node_sqlite3.node +0 -0
  59. package/client/win32-x64/ordered-upload.cjs +236 -0
  60. package/client/win32-x64/outbox.cjs +218 -0
  61. package/client/win32-x64/recovery.cjs +61 -0
  62. package/client/win32-x64/sqlite3.cjs +217 -0
  63. package/client/win32-x64/transcript.cjs +138 -0
  64. package/client/win32-x64/upload.cjs +446 -0
  65. package/client/win32-x64/worker.cjs +76 -0
  66. package/package.json +34 -4
package/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Tencent is pleased to support the open source community by making TencentDB Agent Memory available.
2
+
3
+ Copyright (C) 2026 Tencent. All rights reserved.
4
+
5
+ TencentDB Agent Memory is licensed under the MIT.
6
+
7
+
8
+ Terms of the MIT:
9
+ --------------------------------------------------------------------
10
+ Permission is hereby granted, free of charge, to any person obtaining
11
+ a copy of this software and associated documentation files (the
12
+ "Software"), to deal in the Software without restriction, including
13
+ without limitation the rights to use, copy, modify, merge, publish,
14
+ distribute, sublicense, and/or sell copies of the Software, and to
15
+ permit persons to whom the Software is furnished to do so, subject to
16
+ the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be
19
+ included in all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # Rutter AI Memory client
2
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.
3
+ Connect Codex and Claude Code to Memory using local Hooks and MCP.
4
+
5
+ ```sh
6
+ npm install -g @etilic/rutter_ai
7
+ rutter-ai setup
8
+
9
+ # Later updates
10
+ npm update -g @etilic/rutter_ai
11
+ ```
12
+
13
+ Requires **Node.js 22+**. Included runtimes: Linux x64 glibc 2.31+, Windows x64,
14
+ macOS Intel x64 and Apple Silicon arm64. Linux musl/Alpine, Linux arm64 and
15
+ Windows arm64 are not included. No compiler, Git or external `tar` is required
16
+ on the user's computer. Use a writable npm global prefix; changing Node/npm
17
+ installation paths may require running setup again.
18
+
19
+ The Memory server must support `ordered-v1`. The default endpoint is
20
+ `https://efficiencybyai.com/knowledge/v3` (service `default`). Setup asks for
21
+ your Memory User_Key, verifies it, registers Hooks/MCP and a recovery job.
22
+ Restart Codex/Claude after initial setup. Existing installations from Gitee
23
+ need to run `rutter-ai setup` once to adopt the fixed entry points.
24
+
25
+ | Task | Command |
26
+ | --- | --- |
27
+ | Connect or repair registrations | `rutter-ai setup` |
28
+ | Configure only one client | `rutter-ai setup --client codex` or `--client claude` |
29
+ | Change User_Key | `rutter-ai config key` |
30
+ | Re-enter connection settings | `rutter-ai setup --reconfigure` |
31
+ | Directory project default | `rutter-ai config project set` / `show` / `clear` |
32
+ | Check upload status | `rutter-ai diagnostics --status` |
33
+ | Clear diagnostic logs only | `rutter-ai diagnostics --clear-log` |
34
+ | Choose a local conversation | `rutter-ai upload-session --list` |
35
+ | Installed and active versions | `rutter-ai version` |
36
+ | Validate and activate immediately | `rutter-ai activate` |
37
+ | Remove integration | `rutter-ai uninstall`, then `npm uninstall -g @etilic/rutter_ai` |
38
+
39
+ `rutter-direct-memory` remains available as an alias. Existing flags are retained.
40
+
41
+ ## Updates and parallel windows
42
+
43
+ npm installs files without running installation scripts or asking for credentials.
44
+ After npm update, the next Hook, MCP startup or recovery invocation checks the
45
+ package manifest, validates file hashes and the native SQLite engine, copies an
46
+ immutable release, then atomically switches the active pointer. A running MCP
47
+ process continues with its old release until the client restarts. `version`
48
+ shows the package and active versions separately.
49
+
50
+ Hooks and recovery tasks use fixed entries under
51
+ `~/.config/rutter-direct-memory/runtime/`; versioned code lives in `releases/`.
52
+ Upgrades retain old release directories, credentials, session consent, upload
53
+ switches and pending SQLite data. They do not rerun the full installer. Already
54
+ running calls keep their old files. Concurrent callers can install the same
55
+ release without overwriting it. If package files are temporarily missing or a
56
+ new release fails validation, the fixed entry reports a warning and continues
57
+ using its previous release. Run `rutter-ai activate` to diagnose activation errors.
58
+
59
+ Removing npm files alone does not remove the durable integration. Explicit
60
+ `uninstall` disables upload, discards pending local upload text and removes
61
+ managed registrations; it does not delete already uploaded server data.
62
+
63
+ ## Upload and recovery limits
64
+
65
+ Stop captures eligible main-session user text and final assistant replies into a
66
+ private SQLite WAL outbox. Workers keep snapshots until a matching durable L0
67
+ ACK. Network failures remain pending for retry; authentication failures pause
68
+ uploads. Background recovery uses Linux systemd user timers, macOS LaunchAgents
69
+ or Windows user scheduled tasks. Registration requires the corresponding user
70
+ service facilities and permissions; setup reports registration failures.
71
+
72
+ Tools, reasoning, sidechains and unsupported/incomplete sources are excluded.
73
+ A queue count of zero does not prove all source text was captured. Missing Hook
74
+ triggers, lost source files, disk failures or explicit disable can still cause
75
+ uncaptured or discarded data. No zero-loss guarantee is made. Real server
76
+ compatibility and a user's OS service availability must be verified separately.
77
+
78
+ The native bindings use N-API 6 with patched SQLite: Linux 3.51.3,
79
+ Windows/macOS 3.52.0. Platform artifacts are bundled in npm, not downloaded from
80
+ Gitee during installation. See the project's current client guide for release
81
+ verification evidence and operational limitations.
@@ -0,0 +1,111 @@
1
+ @modelcontextprotocol/sdk@1.0.4
2
+ ===============================
3
+ License: MIT
4
+ MIT License
5
+
6
+ Copyright (c) 2024 Anthropic, PBC
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+
26
+
27
+ zod@3.25.76
28
+ ===========
29
+ License: MIT
30
+ MIT License
31
+
32
+ Copyright (c) 2025 Colin McDonnell
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy
35
+ of this software and associated documentation files (the "Software"), to deal
36
+ in the Software without restriction, including without limitation the rights
37
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
+ copies of the Software, and to permit persons to whom the Software is
39
+ furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all
42
+ copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
+ SOFTWARE.
51
+
52
+
53
+ sqlite3@5.1.7 — BSD-3-Clause
54
+ Copyright (c) MapBox
55
+ All rights reserved.
56
+
57
+ Redistribution and use in source and binary forms, with or without modification,
58
+ are permitted provided that the following conditions are met:
59
+
60
+ - Redistributions of source code must retain the above copyright notice, this
61
+ list of conditions and the following disclaimer.
62
+ - Redistributions in binary form must reproduce the above copyright notice, this
63
+ list of conditions and the following disclaimer in the documentation and/or
64
+ other materials provided with the distribution.
65
+ - Neither the name "MapBox" nor the names of its contributors may be
66
+ used to endorse or promote products derived from this software without
67
+ specific prior written permission.
68
+
69
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
70
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
71
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
73
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
74
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
75
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
76
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
78
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79
+ Native runtime windows-x64: sqlite3@6.0.1 (BSD-3-Clause), SQLite 3.52.0; https://github.com/TryGhost/node-sqlite3/releases/tag/v6.0.1
80
+
81
+ Native runtime macos-x64: sqlite3@6.0.1 (BSD-3-Clause), SQLite 3.52.0; https://github.com/TryGhost/node-sqlite3/releases/tag/v6.0.1
82
+
83
+ Native runtime macos-arm64: sqlite3@6.0.1 (BSD-3-Clause), SQLite 3.52.0; https://github.com/TryGhost/node-sqlite3/releases/tag/v6.0.1
84
+
85
+
86
+ sqlite3@6.0.1 — BSD-3-Clause
87
+ Copyright (c) 2013-2026 Mapbox & Ghost Foundation
88
+ All rights reserved.
89
+
90
+ Redistribution and use in source and binary forms, with or without modification,
91
+ are permitted provided that the following conditions are met:
92
+
93
+ - Redistributions of source code must retain the above copyright notice, this
94
+ list of conditions and the following disclaimer.
95
+ - Redistributions in binary form must reproduce the above copyright notice, this
96
+ list of conditions and the following disclaimer in the documentation and/or
97
+ other materials provided with the distribution.
98
+ - Neither the name "MapBox" nor the names of its contributors may be
99
+ used to endorse or promote products derived from this software without
100
+ specific prior written permission.
101
+
102
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
103
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
104
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
105
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
106
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
107
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
108
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
109
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
111
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/bin/cli.cjs ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const { spawnSync } = require('node:child_process');
7
+
8
+ const runtime = require('./npm-runtime.cjs');
9
+ const { installBundle } = runtime;
10
+ const DEFAULT_SERVER = 'https://efficiencybyai.com/knowledge';
11
+
12
+ function main(argv = process.argv.slice(2), { bundle, env = process.env, packageRoot = path.resolve(__dirname, '..') } = {}) {
13
+ if (Number(process.versions.node.split('.')[0]) < 22) throw new Error('Node.js 22 or newer is required.');
14
+ bundle = bundle || runtime.selectBundle(packageRoot);
15
+ if (argv[0] === '--version' || argv[0] === 'version') {
16
+ const active = runtime.readActive(env);
17
+ process.stdout.write(JSON.stringify({ package: require(path.join(packageRoot, 'package.json')).version, active: active?.version || null, release: active?.release || null }) + '\n');
18
+ return 0;
19
+ }
20
+ if (argv[0] === 'activate') {
21
+ if (argv.slice(1).some(arg => arg !== '--if-configured')) throw new Error('Usage: rutter-ai activate');
22
+ const active = runtime.activate(packageRoot, env, { ifConfigured: argv.includes('--if-configured') });
23
+ if (!argv.includes('--if-configured')) process.stdout.write(active ? `Active runtime: ${active.version}\n` : 'Run rutter-ai setup.\n');
24
+ return 0;
25
+ }
26
+ if (argv[0] === 'setup') argv = argv.slice(1);
27
+ if (argv[0] === 'uninstall') argv = ['--uninstall', ...argv.slice(1)];
28
+ if (argv[0] === 'config') {
29
+ const active = runtime.activate(packageRoot, env, { ifConfigured: true });
30
+ const release = active?.directory || installBundle(bundle, env);
31
+ const result = spawnSync(process.execPath, [path.join(release, 'install.cjs'), ...argv], { stdio: 'inherit', env: active ? { ...env, RUTTER_DIRECT_MEMORY_HOOK_PATH: path.join(active.runtime, 'hook.cjs'), RUTTER_DIRECT_MEMORY_RECOVERY_SCRIPT: path.join(active.runtime, 'ordered-upload.cjs') } : env });
32
+ if (result.error) throw result.error;
33
+ return result.status ?? 1;
34
+ }
35
+ if (argv[0] === 'diagnostics') {
36
+ const action = argv[1] || '--status';
37
+ if (argv.length > 2 || !['--status', '--clear-log'].includes(action)) throw new Error('Usage: rutter-direct-memory diagnostics [--status|--clear-log]');
38
+ const release = installBundle(bundle, env);
39
+ const result = spawnSync(process.execPath, [path.join(release, 'upload.cjs'), action], { stdio: 'inherit', env: { ...env, RUTTER_DIRECT_MEMORY_HOOK_PATH: path.join(runtime.runtimePath(env), 'hook.cjs'), RUTTER_DIRECT_MEMORY_RECOVERY_SCRIPT: path.join(runtime.runtimePath(env), 'ordered-upload.cjs') } });
40
+ if (result.error) throw result.error;
41
+ return result.status ?? 1;
42
+ }
43
+ if (argv[0] === 'upload-session') {
44
+ const release = installBundle(bundle, env);
45
+ const result = spawnSync(process.execPath, [path.join(release, 'upload.cjs'), '--sessions', ...argv.slice(1)], { stdio: 'inherit', env: { ...env, RUTTER_DIRECT_MEMORY_HOOK_PATH: path.join(runtime.runtimePath(env), 'hook.cjs'), RUTTER_DIRECT_MEMORY_RECOVERY_SCRIPT: path.join(runtime.runtimePath(env), 'ordered-upload.cjs') } });
46
+ if (result.error) throw result.error;
47
+ return result.status ?? 1;
48
+ }
49
+ let server;
50
+ const forwarded = [];
51
+ for (let index = 0; index < argv.length; index++) {
52
+ const arg = argv[index];
53
+ if (arg === '--server') {
54
+ server = argv[++index];
55
+ if (!server || server.startsWith('--')) throw new Error('--server requires a Memory server URL.');
56
+ } else if (arg.startsWith('--server=')) server = arg.slice(9);
57
+ else forwarded.push(arg);
58
+ }
59
+ const installer = require(path.join(bundle, 'install.cjs'));
60
+ const args = installer.parseArgs(forwarded);
61
+ if (!['both', 'codex', 'claude'].includes(args.client)) throw new Error('client must be both, codex or claude.');
62
+ if (args.help) {
63
+ process.stdout.write('Install: rutter-ai setup | Update: npm update -g @etilic/rutter_ai | Repair activation: rutter-ai activate\n');
64
+ process.stdout.write('Local settings: rutter-direct-memory config key | config project set|show|clear\n');
65
+ process.stdout.write('Client diagnostics: rutter-direct-memory diagnostics [--status|--clear-log]\n');
66
+ process.stdout.write('Selected local conversation: rutter-direct-memory upload-session [--list | --session ID] [--client codex|claude]\n');
67
+ process.stdout.write(`Usage: rutter-direct-memory [--server https://memory.example.com] [--client both|codex|claude] [--reconfigure] [--uninstall]\nDefaults to ${DEFAULT_SERVER}/v3 (Service ID: default). Enter only your Memory User_Key; no SSH or model API key required. Use --server for another deployment.\n`);
68
+ return 0;
69
+ }
70
+ const quickSetup = server === undefined;
71
+ server = require(path.join(bundle, 'bootstrap.cjs')).baseUrl(server ?? DEFAULT_SERVER);
72
+ const active = runtime.activate(packageRoot, env);
73
+ const release = active.directory;
74
+ const result = spawnSync(process.execPath, [path.join(release, 'install.cjs'), ...forwarded], {
75
+ stdio: 'inherit', env: { ...env, RUTTER_DIRECT_MEMORY_HOOK_PATH: path.join(active.runtime, 'hook.cjs'), RUTTER_DIRECT_MEMORY_RECOVERY_SCRIPT: path.join(active.runtime, 'ordered-upload.cjs'), RUTTER_DIRECT_MEMORY_SERVER: server, RUTTER_DIRECT_MEMORY_QUICK_SETUP: quickSetup ? '1' : '0' },
76
+ });
77
+ if (result.error) throw result.error;
78
+ return result.status ?? 1;
79
+ }
80
+
81
+ if (require.main === module) {
82
+ const log = { write(message) { try { const file = path.join(runtime.runtimePath(process.env), '../install.log'); fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 }); fs.appendFileSync(file, `${new Date().toISOString()} ${message}\n`, { mode: 0o600 }); } catch {} } };
83
+ const help = process.argv.slice(2).some(arg => arg === '--help' || arg === '-h') || ['upload-session', 'diagnostics', 'config', 'activate', 'version', '--version'].includes(process.argv[2]);
84
+ if (!help) log.write('stage=package preflight');
85
+ try {
86
+ process.exitCode = main();
87
+ if (!help && process.exitCode !== 0) log.write(`failure stage=installer process exit=${process.exitCode}`);
88
+ } catch (error) {
89
+ const code = typeof error?.code === 'string' && /^[A-Z0-9_]{1,32}$/.test(error.code) ? error.code : 'UNKNOWN';
90
+ log.write(`failure stage=package preflight code=${code}`);
91
+ process.stderr.write(`${error.message}\n`); process.exitCode = 1;
92
+ }
93
+ }
94
+ module.exports = { installBundle, main, DEFAULT_SERVER };
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const os = require('node:os');
5
+ const path = require('node:path');
6
+ const crypto = require('node:crypto');
7
+ const { spawnSync } = require('node:child_process');
8
+ const files = ['hook.cjs', 'install.cjs', 'mcp.cjs', 'transcript.cjs', 'upload.cjs', 'compat.cjs', 'outbox.cjs', 'worker.cjs', 'ordered-upload.cjs', 'recovery.cjs', 'migration.cjs', 'sqlite3.cjs', 'node_sqlite3.node'];
9
+ const entries = ['hook.cjs', 'mcp.cjs', 'ordered-upload.cjs', 'upload.cjs', 'install.cjs'];
10
+ const digest = data => crypto.createHash('sha256').update(data).digest('hex');
11
+ const rootPath = env => path.join(env.HOME || os.homedir(), '.config', 'rutter-direct-memory');
12
+ const runtimePath = env => path.join(rootPath(env), 'runtime');
13
+
14
+ function target(platform = process.platform, arch = process.arch, libc = platform === 'linux' ? (process.report.getReport().header.glibcVersionRuntime ? 'glibc' : 'musl') : null) {
15
+ const value = [platform, arch, libc].filter(Boolean).join('-');
16
+ if (!['linux-x64-glibc', 'win32-x64', 'darwin-x64', 'darwin-arm64'].includes(value)) throw new Error(`Unsupported platform: ${value}`);
17
+ return value;
18
+ }
19
+
20
+ function selectBundle(packageRoot) {
21
+ const client = path.join(packageRoot, 'client');
22
+ return fs.existsSync(path.join(client, 'manifest.json')) ? client : path.join(client, target());
23
+ }
24
+
25
+ function installBundle(bundle, env = process.env) {
26
+ const manifest = JSON.parse(fs.readFileSync(path.join(bundle, 'manifest.json'), 'utf8'));
27
+ if (manifest.runtime && (manifest.runtime.platform !== process.platform || manifest.runtime.arch !== process.arch
28
+ || (process.platform === 'linux' && manifest.runtime.libc !== (process.report.getReport().header.glibcVersionRuntime ? 'glibc' : 'musl')))) throw new Error('This client package has no compatible prebuilt SQLite runtime for this platform; use a matching platform release.');
29
+ if (!/^[a-f0-9]{20}$/.test(manifest.version) || !manifest.files || Object.keys(manifest.files).length !== files.length
30
+ || files.some(file => !/^[a-f0-9]{64}$/.test(manifest.files[file] || ''))
31
+ || digest(JSON.stringify(manifest.files)).slice(0, 20) !== manifest.version) throw new Error('Invalid client package manifest.');
32
+ const payload = files.map(file => {
33
+ const data = fs.readFileSync(path.join(bundle, file));
34
+ if (digest(data) !== manifest.files[file]) throw new Error(`Checksum mismatch: ${file}`);
35
+ return [file, data];
36
+ });
37
+ const root = path.join(rootPath(env), 'releases');
38
+ fs.mkdirSync(root, { recursive: true, mode: 0o700 });
39
+ const release = path.join(root, manifest.version);
40
+ const verifyExisting = () => {
41
+ for (const [file] of payload) if (digest(fs.readFileSync(path.join(release, file))) !== manifest.files[file]) throw new Error('Existing release has unexpected contents; remove it before retrying.');
42
+ };
43
+ if (fs.existsSync(release)) { verifyExisting(); return release; }
44
+ const stage = fs.mkdtempSync(path.join(root, '.package-'));
45
+ try {
46
+ for (const [file, data] of payload) fs.writeFileSync(path.join(stage, file), data, { mode: 0o600, flag: 'wx' });
47
+ try { fs.renameSync(stage, release); }
48
+ catch (error) {
49
+ // Another Hook or npm invocation can finish the same immutable release first.
50
+ if (!fs.existsSync(release)) throw error;
51
+ verifyExisting();
52
+ }
53
+ } finally { fs.rmSync(stage, { recursive: true, force: true }); }
54
+ return release;
55
+ }
56
+
57
+ function atomicWrite(file, data) {
58
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
59
+ const temp = `${file}.${process.pid}.${crypto.randomBytes(6).toString('hex')}.tmp`;
60
+ try {
61
+ fs.writeFileSync(temp, data, { mode: 0o600, flag: 'wx' });
62
+ const fd = fs.openSync(temp, 'r+');
63
+ try { fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
64
+ fs.renameSync(temp, file);
65
+ } finally { fs.rmSync(temp, { force: true }); }
66
+ }
67
+
68
+ function readActive(env = process.env) {
69
+ try {
70
+ const active = JSON.parse(fs.readFileSync(path.join(runtimePath(env), 'active.json'), 'utf8'));
71
+ if (active.format !== 1 || !/^[a-f0-9]{20}$/.test(active.release) || !path.isAbsolute(active.packageRoot)) throw new Error('Invalid active runtime');
72
+ return active;
73
+ } catch (error) { if (error.code === 'ENOENT') return null; throw error; }
74
+ }
75
+
76
+ function activate(packageRoot, env = process.env, { ifConfigured = false } = {}) {
77
+ if (ifConfigured && !readActive(env)) return null;
78
+ const bundle = selectBundle(packageRoot);
79
+ const release = installBundle(bundle, env);
80
+ // Probe the actual native module without opening or modifying the user's outbox.
81
+ const probe = spawnSync(process.execPath, ['-e', `
82
+ const sqlite = require(process.argv[1]);
83
+ const safe = require(process.argv[2]).safeSqliteVersion;
84
+ const db = new sqlite.Database(':memory:', error => {
85
+ if (error) process.exit(1);
86
+ db.get('SELECT sqlite_version() AS version', (error, row) => {
87
+ db.close(() => process.exit(error || !safe(row.version) ? 1 : 0));
88
+ });
89
+ });`, path.join(release, 'sqlite3.cjs'), path.join(release, 'outbox.cjs')], { env, encoding: 'utf8', timeout: 15000, windowsHide: true });
90
+ if (probe.error || probe.status !== 0) throw new Error('SQLite runtime validation failed; previous active version and pending uploads are unchanged.');
91
+ const runtime = runtimePath(env);
92
+ const manager = fs.readFileSync(path.join(packageRoot, 'bin/npm-runtime.cjs'));
93
+ atomicWrite(path.join(runtime, 'manager.cjs'), manager);
94
+ for (const entry of entries) {
95
+ const file = path.join(runtime, entry);
96
+ const source = `'use strict';\nprocess.exitCode = require('./manager.cjs').launch(${JSON.stringify(entry)});\n`;
97
+ if (!fs.existsSync(file)) atomicWrite(file, source);
98
+ }
99
+ const active = { format: 1, packageRoot, release: path.basename(release), version: JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8')).version };
100
+ atomicWrite(path.join(runtime, 'active.json'), JSON.stringify(active) + '\n');
101
+ return { ...active, directory: release, runtime };
102
+ }
103
+
104
+ function launch(entry, argv = process.argv.slice(2), env = process.env) {
105
+ if (!entries.includes(entry)) throw new Error('Unknown runtime entry');
106
+ let active = readActive(env);
107
+ if (!active) throw new Error('Run rutter-ai setup first.');
108
+ // Also works when npm lifecycle scripts were disabled. A package temporarily
109
+ // missing during npm replacement falls back to the already validated release.
110
+ try {
111
+ const manifest = JSON.parse(fs.readFileSync(path.join(selectBundle(active.packageRoot), 'manifest.json'), 'utf8'));
112
+ const version = JSON.parse(fs.readFileSync(path.join(active.packageRoot, 'package.json'), 'utf8')).version;
113
+ if (manifest.version !== active.release || version !== active.version) active = activate(active.packageRoot, env);
114
+ } catch {
115
+ process.stderr.write('Memory package update unavailable; continuing with the previous runtime. Run rutter-ai activate to diagnose.\n');
116
+ }
117
+ const runtime = runtimePath(env);
118
+ const result = spawnSync(process.execPath, [path.join(rootPath(env), 'releases', active.release, entry), ...argv], {
119
+ stdio: 'inherit', windowsHide: true, env: { ...env, RUTTER_DIRECT_MEMORY_HOOK_PATH: path.join(runtime, 'hook.cjs'), RUTTER_DIRECT_MEMORY_RECOVERY_SCRIPT: path.join(runtime, 'ordered-upload.cjs') },
120
+ });
121
+ if (result.error) throw result.error;
122
+ return result.status ?? 1;
123
+ }
124
+
125
+ module.exports = { files, target, selectBundle, installBundle, activate, readActive, runtimePath, launch };
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __commonJS = (cb, mod) => function __require() {
5
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
+ };
7
+
8
+ // agents/direct-memory-access/compat.cjs
9
+ var require_compat = __commonJS({
10
+ "agents/direct-memory-access/compat.cjs"(exports2, module2) {
11
+ "use strict";
12
+ var http = require("http");
13
+ var https = require("https");
14
+ var readline = require("readline");
15
+ function request2(url, options = {}) {
16
+ return new Promise((resolve, reject) => {
17
+ var _a, _b;
18
+ let target;
19
+ try {
20
+ target = new URL(url);
21
+ } catch {
22
+ reject(new Error("Invalid service URL"));
23
+ return;
24
+ }
25
+ if (!["http:", "https:"].includes(target.protocol) || target.username || target.password) {
26
+ reject(new Error("Invalid service URL"));
27
+ return;
28
+ }
29
+ const deadline = options.timeoutMs === void 0 ? 15e3 : options.timeoutMs;
30
+ const maxBytes = options.maxBytes === void 0 ? 8 * 1024 * 1024 : options.maxBytes;
31
+ let timer, response, settled = false;
32
+ const finish = (error, value) => {
33
+ var _a2;
34
+ if (settled) return;
35
+ settled = true;
36
+ clearTimeout(timer);
37
+ (_a2 = options.signal) == null ? void 0 : _a2.removeEventListener("abort", abort);
38
+ if (error) {
39
+ response == null ? void 0 : response.destroy();
40
+ req.destroy();
41
+ reject(error);
42
+ } else resolve(value);
43
+ };
44
+ const abort = () => {
45
+ const error = new Error("Request aborted");
46
+ error.name = "AbortError";
47
+ finish(error);
48
+ };
49
+ const req = (target.protocol === "https:" ? https : http).request(target, {
50
+ method: options.method || "GET",
51
+ headers: options.headers,
52
+ agent: false
53
+ }, (res) => {
54
+ response = res;
55
+ if (res.statusCode >= 300 && res.statusCode < 400) {
56
+ finish(new Error("Redirect refused"));
57
+ return;
58
+ }
59
+ let size = 0;
60
+ const chunks = [];
61
+ res.on("data", (chunk) => {
62
+ size += chunk.length;
63
+ if (size > maxBytes) {
64
+ finish(new Error("Response size limit exceeded"));
65
+ return;
66
+ }
67
+ chunks.push(chunk);
68
+ });
69
+ res.once("aborted", () => finish(new Error("Response interrupted")));
70
+ res.once("error", () => finish(new Error("Response interrupted")));
71
+ res.once("end", () => {
72
+ const body = Buffer.concat(chunks).toString("utf8");
73
+ finish(null, {
74
+ status: res.statusCode,
75
+ ok: res.statusCode >= 200 && res.statusCode < 300,
76
+ headers: { get: (name) => res.headers[String(name).toLowerCase()] || null },
77
+ text: async () => body,
78
+ json: async () => JSON.parse(body),
79
+ arrayBuffer: async () => Buffer.concat(chunks)
80
+ });
81
+ });
82
+ });
83
+ req.once("error", () => finish(new Error("Service connection failed")));
84
+ timer = setTimeout(() => {
85
+ const error = new Error("Request deadline exceeded");
86
+ error.name = "TimeoutError";
87
+ finish(error);
88
+ }, deadline);
89
+ if ((_a = options.signal) == null ? void 0 : _a.aborted) {
90
+ abort();
91
+ return;
92
+ }
93
+ (_b = options.signal) == null ? void 0 : _b.addEventListener("abort", abort, { once: true });
94
+ req.end(options.body);
95
+ });
96
+ }
97
+ function createInterface(options) {
98
+ const rl = readline.createInterface(options);
99
+ return { question: (prompt) => new Promise((resolve) => rl.question(prompt, resolve)), close: () => rl.close() };
100
+ }
101
+ module2.exports = { request: request2, createInterface, performance: require("perf_hooks").performance };
102
+ }
103
+ });
104
+
105
+ // agents/direct-memory-access/bootstrap.cjs
106
+ var fs = require("node:fs");
107
+ var os = require("node:os");
108
+ var path = require("node:path");
109
+ var crypto = require("node:crypto");
110
+ var { spawnSync } = require("node:child_process");
111
+ var { request } = require_compat();
112
+ var names = ["hook.cjs", "install.cjs", "mcp.cjs", "transcript.cjs", "upload.cjs", "compat.cjs", "outbox.cjs", "worker.cjs", "ordered-upload.cjs", "recovery.cjs", "migration.cjs", "sqlite3.cjs", "node_sqlite3.node"];
113
+ function baseUrl(value) {
114
+ const url = new URL(value);
115
+ const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
116
+ if (!(url.protocol === "https:" || local && url.protocol === "http:") || url.username || url.password || url.search || url.hash) throw new Error("Use an HTTPS server URL, or HTTP on localhost.");
117
+ url.pathname = url.pathname.replace(/\/+$/, "");
118
+ return url.toString().replace(/\/$/, "");
119
+ }
120
+ async function download(url, limit) {
121
+ const response = await request(url, { timeoutMs: 3e4, maxBytes: limit });
122
+ if (!response.ok) throw new Error(`Download failed (${response.status}).`);
123
+ return Buffer.from(await response.arrayBuffer());
124
+ }
125
+ async function main() {
126
+ if (Number(process.versions.node.split(".")[0]) < 16) throw new Error("Node.js 16 or newer is required.");
127
+ if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("Run the installer in an interactive terminal.");
128
+ const base = baseUrl(process.argv[2]);
129
+ const manifest = JSON.parse((await download(`${base}/direct-memory-client/manifest.json`, 16384)).toString("utf8"));
130
+ if (manifest.runtime && (manifest.runtime.platform !== process.platform || manifest.runtime.arch !== process.arch || process.platform === "linux" && manifest.runtime.libc !== (process.report.getReport().header.glibcVersionRuntime ? "glibc" : "musl"))) throw new Error("This client package has no compatible prebuilt SQLite runtime for this platform; use a matching platform release.");
131
+ if (!/^[a-f0-9]{20}$/.test(manifest.version) || !manifest.files || Object.keys(manifest.files).length !== names.length || names.some((name) => !/^[a-f0-9]{64}$/.test(manifest.files[name] || ""))) throw new Error("Invalid package manifest.");
132
+ const root = path.join(process.env.HOME || os.homedir(), ".config", "rutter-direct-memory", "releases");
133
+ fs.mkdirSync(root, { recursive: true, mode: 448 });
134
+ const stage = fs.mkdtempSync(path.join(root, ".download-"));
135
+ try {
136
+ for (const name of names) {
137
+ const data = await download(`${base}/direct-memory-client/${name}`, 10 * 1024 * 1024);
138
+ if (crypto.createHash("sha256").update(data).digest("hex") !== manifest.files[name]) throw new Error(`Checksum mismatch: ${name}`);
139
+ fs.writeFileSync(path.join(stage, name), data, { mode: 384, flag: "wx" });
140
+ }
141
+ const release = path.join(root, manifest.version);
142
+ if (fs.existsSync(release)) {
143
+ for (const name of names) {
144
+ const hash = crypto.createHash("sha256").update(fs.readFileSync(path.join(release, name))).digest("hex");
145
+ if (hash !== manifest.files[name]) throw new Error("Existing release has unexpected contents; remove it before retrying.");
146
+ }
147
+ } else fs.renameSync(stage, release);
148
+ const result = spawnSync(process.execPath, [path.join(release, "install.cjs"), ...process.argv.slice(3)], { stdio: "inherit", env: { ...process.env, RUTTER_DIRECT_MEMORY_SERVER: base } });
149
+ if (result.error) throw result.error;
150
+ process.exitCode = result.status ?? 1;
151
+ } finally {
152
+ fs.rmSync(stage, { recursive: true, force: true });
153
+ }
154
+ }
155
+ if (require.main === module) main().catch((error) => {
156
+ console.error(error.message);
157
+ process.exitCode = 1;
158
+ });
159
+ module.exports = { baseUrl, download };