@etilic/rutter_ai 0.0.0-stage → 0.2.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.
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
@@ -0,0 +1,217 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // agents/direct-memory-access/node_modules/sqlite3/lib/sqlite3-binding.js
7
+ var require_sqlite3_binding = __commonJS({
8
+ "agents/direct-memory-access/node_modules/sqlite3/lib/sqlite3-binding.js"(exports2, module2) {
9
+ module2.exports = require("./node_sqlite3.node");
10
+ }
11
+ });
12
+
13
+ // agents/direct-memory-access/node_modules/sqlite3/lib/trace.js
14
+ var require_trace = __commonJS({
15
+ "agents/direct-memory-access/node_modules/sqlite3/lib/trace.js"(exports2) {
16
+ var util = require("util");
17
+ function extendTrace(object, property, pos) {
18
+ const old = object[property];
19
+ object[property] = function() {
20
+ const error = new Error();
21
+ const name = object.constructor.name + "#" + property + "(" + Array.prototype.slice.call(arguments).map(function(el) {
22
+ return util.inspect(el, false, 0);
23
+ }).join(", ") + ")";
24
+ if (typeof pos === "undefined") pos = -1;
25
+ if (pos < 0) pos += arguments.length;
26
+ const cb = arguments[pos];
27
+ if (typeof arguments[pos] === "function") {
28
+ arguments[pos] = function replacement() {
29
+ const err = arguments[0];
30
+ if (err && err.stack && !err.__augmented) {
31
+ err.stack = filter(err).join("\n");
32
+ err.stack += "\n--> in " + name;
33
+ err.stack += "\n" + filter(error).slice(1).join("\n");
34
+ err.__augmented = true;
35
+ }
36
+ return cb.apply(this, arguments);
37
+ };
38
+ }
39
+ return old.apply(this, arguments);
40
+ };
41
+ }
42
+ exports2.extendTrace = extendTrace;
43
+ function filter(error) {
44
+ return error.stack.split("\n").filter(function(line) {
45
+ return line.indexOf(__filename) < 0;
46
+ });
47
+ }
48
+ }
49
+ });
50
+
51
+ // agents/direct-memory-access/node_modules/sqlite3/lib/sqlite3.js
52
+ var path = require("path");
53
+ var sqlite3 = require_sqlite3_binding();
54
+ var EventEmitter = require("events").EventEmitter;
55
+ module.exports = exports = sqlite3;
56
+ function normalizeMethod(fn) {
57
+ return function(sql) {
58
+ let errBack;
59
+ const args = Array.prototype.slice.call(arguments, 1);
60
+ if (typeof args[args.length - 1] === "function") {
61
+ const callback = args[args.length - 1];
62
+ errBack = function(err) {
63
+ if (err) {
64
+ callback(err);
65
+ }
66
+ };
67
+ }
68
+ const statement = new Statement(this, sql, errBack);
69
+ return fn.call(this, statement, args);
70
+ };
71
+ }
72
+ function inherits(target, source) {
73
+ for (const k in source.prototype)
74
+ target.prototype[k] = source.prototype[k];
75
+ }
76
+ sqlite3.cached = {
77
+ Database: function(file, a, b) {
78
+ if (file === "" || file === ":memory:") {
79
+ return new Database(file, a, b);
80
+ }
81
+ let db;
82
+ file = path.resolve(file);
83
+ if (!sqlite3.cached.objects[file]) {
84
+ db = sqlite3.cached.objects[file] = new Database(file, a, b);
85
+ } else {
86
+ db = sqlite3.cached.objects[file];
87
+ const callback = typeof a === "number" ? b : a;
88
+ if (typeof callback === "function") {
89
+ let cb2 = function() {
90
+ callback.call(db, null);
91
+ };
92
+ var cb = cb2;
93
+ if (db.open) process.nextTick(cb2);
94
+ else db.once("open", cb2);
95
+ }
96
+ }
97
+ return db;
98
+ },
99
+ objects: {}
100
+ };
101
+ var Database = sqlite3.Database;
102
+ var Statement = sqlite3.Statement;
103
+ var Backup = sqlite3.Backup;
104
+ inherits(Database, EventEmitter);
105
+ inherits(Statement, EventEmitter);
106
+ inherits(Backup, EventEmitter);
107
+ Database.prototype.prepare = normalizeMethod(function(statement, params) {
108
+ return params.length ? statement.bind.apply(statement, params) : statement;
109
+ });
110
+ Database.prototype.run = normalizeMethod(function(statement, params) {
111
+ statement.run.apply(statement, params).finalize();
112
+ return this;
113
+ });
114
+ Database.prototype.get = normalizeMethod(function(statement, params) {
115
+ statement.get.apply(statement, params).finalize();
116
+ return this;
117
+ });
118
+ Database.prototype.all = normalizeMethod(function(statement, params) {
119
+ statement.all.apply(statement, params).finalize();
120
+ return this;
121
+ });
122
+ Database.prototype.each = normalizeMethod(function(statement, params) {
123
+ statement.each.apply(statement, params).finalize();
124
+ return this;
125
+ });
126
+ Database.prototype.map = normalizeMethod(function(statement, params) {
127
+ statement.map.apply(statement, params).finalize();
128
+ return this;
129
+ });
130
+ Database.prototype.backup = function() {
131
+ let backup;
132
+ if (arguments.length <= 2) {
133
+ backup = new Backup(this, arguments[0], "main", "main", true, arguments[1]);
134
+ } else {
135
+ backup = new Backup(this, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
136
+ }
137
+ backup.retryErrors = [sqlite3.BUSY, sqlite3.LOCKED];
138
+ return backup;
139
+ };
140
+ Statement.prototype.map = function() {
141
+ const params = Array.prototype.slice.call(arguments);
142
+ const callback = params.pop();
143
+ params.push(function(err, rows) {
144
+ if (err) return callback(err);
145
+ const result = {};
146
+ if (rows.length) {
147
+ const keys = Object.keys(rows[0]);
148
+ const key = keys[0];
149
+ if (keys.length > 2) {
150
+ for (let i = 0; i < rows.length; i++) {
151
+ result[rows[i][key]] = rows[i];
152
+ }
153
+ } else {
154
+ const value = keys[1];
155
+ for (let i = 0; i < rows.length; i++) {
156
+ result[rows[i][key]] = rows[i][value];
157
+ }
158
+ }
159
+ }
160
+ callback(err, result);
161
+ });
162
+ return this.all.apply(this, params);
163
+ };
164
+ var isVerbose = false;
165
+ var supportedEvents = ["trace", "profile", "change"];
166
+ Database.prototype.addListener = Database.prototype.on = function(type) {
167
+ const val = EventEmitter.prototype.addListener.apply(this, arguments);
168
+ if (supportedEvents.indexOf(type) >= 0) {
169
+ this.configure(type, true);
170
+ }
171
+ return val;
172
+ };
173
+ Database.prototype.removeListener = function(type) {
174
+ const val = EventEmitter.prototype.removeListener.apply(this, arguments);
175
+ if (supportedEvents.indexOf(type) >= 0 && !this._events[type]) {
176
+ this.configure(type, false);
177
+ }
178
+ return val;
179
+ };
180
+ Database.prototype.removeAllListeners = function(type) {
181
+ const val = EventEmitter.prototype.removeAllListeners.apply(this, arguments);
182
+ if (supportedEvents.indexOf(type) >= 0) {
183
+ this.configure(type, false);
184
+ }
185
+ return val;
186
+ };
187
+ sqlite3.verbose = function() {
188
+ if (!isVerbose) {
189
+ const trace = require_trace();
190
+ [
191
+ "prepare",
192
+ "get",
193
+ "run",
194
+ "all",
195
+ "each",
196
+ "map",
197
+ "close",
198
+ "exec"
199
+ ].forEach(function(name) {
200
+ trace.extendTrace(Database.prototype, name);
201
+ });
202
+ [
203
+ "bind",
204
+ "get",
205
+ "run",
206
+ "all",
207
+ "each",
208
+ "map",
209
+ "reset",
210
+ "finalize"
211
+ ].forEach(function(name) {
212
+ trace.extendTrace(Statement.prototype, name);
213
+ });
214
+ isVerbose = true;
215
+ }
216
+ return sqlite3;
217
+ };
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ const crypto = require('node:crypto');
4
+
5
+ function digest(client, sessionId, sourceId, role) {
6
+ return crypto.createHash('sha256').update(JSON.stringify([client, sessionId, sourceId, role])).digest('hex');
7
+ }
8
+
9
+ function textBlocks(content, allowedType) {
10
+ if (typeof content === 'string') return content;
11
+ if (!Array.isArray(content)) return '';
12
+ return content.filter(block => block && block.type === allowedType && typeof block.text === 'string').map(block => block.text).join('\n');
13
+ }
14
+
15
+ function parseTranscript(client, sessionId, input, consentAt) {
16
+ const records = [];
17
+ let incomplete = false;
18
+ let codexSessionMatches = false;
19
+ for (const line of input.split('\n')) {
20
+ if (!line.trim()) continue;
21
+ let row;
22
+ try { row = JSON.parse(line); } catch { incomplete = true; continue; }
23
+ if (client === 'codex' && row.type === 'session_meta') {
24
+ if (row.payload?.id !== sessionId) return { messages: [], incomplete: true };
25
+ codexSessionMatches = true;
26
+ }
27
+ const timestamp = Date.parse(row.timestamp);
28
+ if (!Number.isFinite(timestamp) || timestamp < consentAt) continue;
29
+ let role, content, source, turn;
30
+ if (client === 'codex') {
31
+ const retained = row.metadata?.retained_source;
32
+ if (row.type !== 'response_item' || row.payload?.type !== 'message' || retained?.complete !== true) continue;
33
+ role = row.payload.role;
34
+ if (!['user', 'assistant'].includes(role) || retained.id?.role !== role) continue;
35
+ source = retained.id?.message_id;
36
+ turn = retained.id?.turn_id;
37
+ if (typeof source !== 'string' || !source || typeof turn !== 'string' || !turn) continue;
38
+ content = textBlocks(row.payload.content, role === 'user' ? 'input_text' : 'output_text');
39
+ } else if (client === 'claude') {
40
+ if (row.isSidechain !== false || row.isMeta === true || row.sessionId !== sessionId || !['user', 'assistant'].includes(row.type)) continue;
41
+ role = row.type;
42
+ if (row.message?.role !== role || typeof row.uuid !== 'string' || !row.uuid) continue;
43
+ source = row.uuid;
44
+ content = textBlocks(row.message.content, 'text');
45
+ } else throw new Error('Unsupported client');
46
+ if (!content.trim()) continue;
47
+ records.push({ role, content, direct_event_id: digest(client, sessionId, source, role), timestamp: new Date(timestamp).toISOString(), turn });
48
+ }
49
+ // Stop fires after a turn; only the last assistant text for a turn is the final reply.
50
+ const output = [];
51
+ let pending = null;
52
+ for (const record of records) {
53
+ if (record.role === 'user') {
54
+ if (pending) output.push(pending);
55
+ pending = null;
56
+ output.push(record);
57
+ } else {
58
+ if (pending && client === 'codex' && pending.turn !== record.turn) output.push(pending);
59
+ pending = record;
60
+ }
61
+ }
62
+ if (pending) output.push(pending);
63
+ return { messages: codexSessionMatches || client !== 'codex' ? output.map(({ turn, ...message }) => message) : [], incomplete: incomplete || (client === 'codex' && !codexSessionMatches) };
64
+ }
65
+
66
+ // Ordered capture uses explicit completion barriers. Retained turn_id is an
67
+ // item identifier in current Codex logs: progress messages can have different
68
+ // values within one user turn, so it cannot identify final assistant replies.
69
+ function parseOrderedTranscript(client, sessionId, input, consentAt = 0, { stopCompleted = false, authorizedEventIds = [], authorizedPrompt } = {}) {
70
+ const output = [], seen = new Map();
71
+ let pending = null, matchedSession = client !== 'codex', offset = 0, incomplete = false;
72
+ let initialPrompt = null;
73
+ const push = record => {
74
+ if (!record) return;
75
+ const prior = seen.get(record.direct_event_id);
76
+ if (prior) {
77
+ if (prior.content !== record.content || prior.role !== record.role) incomplete = true;
78
+ return;
79
+ }
80
+ seen.set(record.direct_event_id, record); output.push(record);
81
+ };
82
+ for (const line of input.split('\n')) {
83
+ const position = offset; offset += Buffer.byteLength(line) + 1;
84
+ if (!line.trim()) continue;
85
+ let row;
86
+ try { row = JSON.parse(line); } catch { incomplete = true; break; }
87
+ const p = row.payload || {};
88
+ if (client === 'codex' && row.type === 'session_meta') {
89
+ if (p.id !== sessionId || (p.source && typeof p.source === 'object')) return { messages: [], incomplete: true };
90
+ matchedSession = true; continue;
91
+ }
92
+ if (client === 'codex' && row.type === 'event_msg' && p.type === 'task_complete') {
93
+ // Completion text is used only to identify an already retained source,
94
+ // never as an alternative source of private/internal message content.
95
+ if (pending && p.last_agent_message === pending.content) push(pending);
96
+ else if (pending) incomplete = true;
97
+ pending = null; continue;
98
+ }
99
+ const timestamp = Date.parse(row.timestamp);
100
+ if (!Number.isFinite(timestamp)) continue;
101
+ let role, source, content, final = false;
102
+ if (client === 'codex') {
103
+ const retained = row.metadata?.retained_source;
104
+ if (row.type !== 'response_item' || p.type !== 'message' || retained?.complete !== true) continue;
105
+ role = p.role; source = retained.id?.message_id;
106
+ if (!['user', 'assistant'].includes(role) || retained.id?.role !== role || typeof source !== 'string' || !source) continue;
107
+ content = textBlocks(p.content, role === 'user' ? 'input_text' : 'output_text');
108
+ if (role === 'assistant' && p.channel && p.channel !== 'final') continue;
109
+ final = p.channel === 'final';
110
+ } else if (client === 'claude') {
111
+ if (row.sessionId !== sessionId || row.isSidechain !== false || row.isMeta === true || !['user', 'assistant'].includes(row.type)) continue;
112
+ role = row.type; source = row.uuid;
113
+ if (row.message?.role !== role || typeof source !== 'string' || !source) continue;
114
+ content = textBlocks(row.message.content, 'text');
115
+ if (role === 'assistant' && Array.isArray(row.message.content) && row.message.content.some(block => block?.type === 'tool_use')) continue;
116
+ final = ['end_turn', 'max_tokens', 'stop_sequence'].includes(row.message.stop_reason);
117
+ } else throw new Error('Unsupported client');
118
+ if (!content.trim()) continue;
119
+ // Source position is independent of consent filtering and wall clocks.
120
+ const record = { role, content, direct_event_id: digest(client, sessionId, source, role),
121
+ timestamp: new Date(timestamp).toISOString(), source_order: Number.isSafeInteger(row.ordinal) && row.ordinal >= 0 ? row.ordinal : position };
122
+ if (role === 'user') {
123
+ pending = null;
124
+ if (timestamp >= consentAt || authorizedEventIds.includes(record.direct_event_id)) push(record);
125
+ else if (authorizedPrompt && position >= authorizedPrompt.after_bytes
126
+ && crypto.createHash('sha256').update(content).digest('hex') === authorizedPrompt.hash) initialPrompt = record;
127
+ }
128
+ else { pending = timestamp >= consentAt ? record : null; if (final) { push(pending); pending = null; } }
129
+ }
130
+ // Claude Stop is itself a completed-turn event. Codex requires its persisted
131
+ // task_complete or channel=final because a Stop snapshot can still be stale.
132
+ if (client === 'claude' && stopCompleted && !incomplete) push(pending);
133
+ if (!incomplete) push(initialPrompt);
134
+ output.sort((a, b) => a.source_order - b.source_order);
135
+ return { messages: matchedSession ? output : [], incomplete: incomplete || !matchedSession, checkpoint: incomplete ? 0 : Buffer.byteLength(input) };
136
+ }
137
+
138
+ module.exports = { parseTranscript, parseOrderedTranscript };