@foothill/agent-move 1.0.6
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/.github/screenshot.png +0 -0
- package/README.md +266 -0
- package/bin/cli.js +229 -0
- package/package.json +53 -0
- package/packages/client/dist/assets/BufferResource-Ddjob236.js +185 -0
- package/packages/client/dist/assets/CanvasRenderer-B0w6SYyW.js +1 -0
- package/packages/client/dist/assets/Filter-NcMGuiK-.js +1 -0
- package/packages/client/dist/assets/RenderTargetSystem-DgAzY5_U.js +172 -0
- package/packages/client/dist/assets/WebGLRenderer-DUWXDPIX.js +156 -0
- package/packages/client/dist/assets/WebGPURenderer-C1HbrllR.js +41 -0
- package/packages/client/dist/assets/browserAll-CaF1Fl0O.js +14 -0
- package/packages/client/dist/assets/index-CMmR_RuS.css +1 -0
- package/packages/client/dist/assets/index-Dh8yWoLP.js +711 -0
- package/packages/client/dist/assets/webworkerAll-BJ6UhC7r.js +83 -0
- package/packages/client/dist/favicon.svg +27 -0
- package/packages/client/dist/index.html +167 -0
- package/packages/client/package.json +19 -0
- package/packages/server/dist/config.d.ts +12 -0
- package/packages/server/dist/config.d.ts.map +1 -0
- package/packages/server/dist/config.js +19 -0
- package/packages/server/dist/config.js.map +1 -0
- package/packages/server/dist/hooks/hook-event-manager.d.ts +39 -0
- package/packages/server/dist/hooks/hook-event-manager.d.ts.map +1 -0
- package/packages/server/dist/hooks/hook-event-manager.js +161 -0
- package/packages/server/dist/hooks/hook-event-manager.js.map +1 -0
- package/packages/server/dist/hooks/hook-installer.d.ts +14 -0
- package/packages/server/dist/hooks/hook-installer.d.ts.map +1 -0
- package/packages/server/dist/hooks/hook-installer.js +179 -0
- package/packages/server/dist/hooks/hook-installer.js.map +1 -0
- package/packages/server/dist/index.d.ts +4 -0
- package/packages/server/dist/index.d.ts.map +1 -0
- package/packages/server/dist/index.js +3544 -0
- package/packages/server/dist/index.js.map +1 -0
- package/packages/server/dist/routes/api.d.ts +4 -0
- package/packages/server/dist/routes/api.d.ts.map +1 -0
- package/packages/server/dist/routes/api.js +27 -0
- package/packages/server/dist/routes/api.js.map +1 -0
- package/packages/server/dist/state/activity-processor.d.ts +31 -0
- package/packages/server/dist/state/activity-processor.d.ts.map +1 -0
- package/packages/server/dist/state/activity-processor.js +417 -0
- package/packages/server/dist/state/activity-processor.js.map +1 -0
- package/packages/server/dist/state/agent-state-manager.d.ts +107 -0
- package/packages/server/dist/state/agent-state-manager.d.ts.map +1 -0
- package/packages/server/dist/state/agent-state-manager.js +1622 -0
- package/packages/server/dist/state/agent-state-manager.js.map +1 -0
- package/packages/server/dist/state/anomaly-detector.d.ts +23 -0
- package/packages/server/dist/state/anomaly-detector.d.ts.map +1 -0
- package/packages/server/dist/state/anomaly-detector.js +272 -0
- package/packages/server/dist/state/anomaly-detector.js.map +1 -0
- package/packages/server/dist/state/identity-manager.d.ts +31 -0
- package/packages/server/dist/state/identity-manager.d.ts.map +1 -0
- package/packages/server/dist/state/identity-manager.js +63 -0
- package/packages/server/dist/state/identity-manager.js.map +1 -0
- package/packages/server/dist/state/role-resolver.d.ts +23 -0
- package/packages/server/dist/state/role-resolver.d.ts.map +1 -0
- package/packages/server/dist/state/role-resolver.js +43 -0
- package/packages/server/dist/state/role-resolver.js.map +1 -0
- package/packages/server/dist/state/task-graph-manager.d.ts +31 -0
- package/packages/server/dist/state/task-graph-manager.d.ts.map +1 -0
- package/packages/server/dist/state/task-graph-manager.js +191 -0
- package/packages/server/dist/state/task-graph-manager.js.map +1 -0
- package/packages/server/dist/state/tool-chain-tracker.d.ts +23 -0
- package/packages/server/dist/state/tool-chain-tracker.d.ts.map +1 -0
- package/packages/server/dist/state/tool-chain-tracker.js +113 -0
- package/packages/server/dist/state/tool-chain-tracker.js.map +1 -0
- package/packages/server/dist/watcher/agent-watcher.d.ts +16 -0
- package/packages/server/dist/watcher/agent-watcher.d.ts.map +1 -0
- package/packages/server/dist/watcher/agent-watcher.js +0 -0
- package/packages/server/dist/watcher/agent-watcher.js.map +1 -0
- package/packages/server/dist/watcher/claude-paths.d.ts +32 -0
- package/packages/server/dist/watcher/claude-paths.d.ts.map +1 -0
- package/packages/server/dist/watcher/claude-paths.js +104 -0
- package/packages/server/dist/watcher/claude-paths.js.map +1 -0
- package/packages/server/dist/watcher/file-watcher.d.ts +17 -0
- package/packages/server/dist/watcher/file-watcher.d.ts.map +1 -0
- package/packages/server/dist/watcher/file-watcher.js +347 -0
- package/packages/server/dist/watcher/file-watcher.js.map +1 -0
- package/packages/server/dist/watcher/git-info.d.ts +3 -0
- package/packages/server/dist/watcher/git-info.d.ts.map +1 -0
- package/packages/server/dist/watcher/git-info.js +35 -0
- package/packages/server/dist/watcher/git-info.js.map +1 -0
- package/packages/server/dist/watcher/jsonl-parser.d.ts +21 -0
- package/packages/server/dist/watcher/jsonl-parser.d.ts.map +1 -0
- package/packages/server/dist/watcher/jsonl-parser.js +95 -0
- package/packages/server/dist/watcher/jsonl-parser.js.map +1 -0
- package/packages/server/dist/watcher/opencode/opencode-parser.d.ts +58 -0
- package/packages/server/dist/watcher/opencode/opencode-parser.d.ts.map +1 -0
- package/packages/server/dist/watcher/opencode/opencode-parser.js +256 -0
- package/packages/server/dist/watcher/opencode/opencode-parser.js.map +1 -0
- package/packages/server/dist/watcher/opencode/opencode-paths.d.ts +20 -0
- package/packages/server/dist/watcher/opencode/opencode-paths.d.ts.map +1 -0
- package/packages/server/dist/watcher/opencode/opencode-paths.js +35 -0
- package/packages/server/dist/watcher/opencode/opencode-paths.js.map +1 -0
- package/packages/server/dist/watcher/opencode/opencode-watcher.d.ts +49 -0
- package/packages/server/dist/watcher/opencode/opencode-watcher.d.ts.map +1 -0
- package/packages/server/dist/watcher/opencode/opencode-watcher.js +1292 -0
- package/packages/server/dist/watcher/opencode/opencode-watcher.js.map +1 -0
- package/packages/server/dist/watcher/session-scanner.d.ts +7 -0
- package/packages/server/dist/watcher/session-scanner.d.ts.map +1 -0
- package/packages/server/dist/watcher/session-scanner.js +69 -0
- package/packages/server/dist/watcher/session-scanner.js.map +1 -0
- package/packages/server/dist/ws/broadcaster.d.ts +18 -0
- package/packages/server/dist/ws/broadcaster.d.ts.map +1 -0
- package/packages/server/dist/ws/broadcaster.js +152 -0
- package/packages/server/dist/ws/broadcaster.js.map +1 -0
- package/packages/server/dist/ws/ws-handler.d.ts +6 -0
- package/packages/server/dist/ws/ws-handler.d.ts.map +1 -0
- package/packages/server/dist/ws/ws-handler.js +55 -0
- package/packages/server/dist/ws/ws-handler.js.map +1 -0
- package/packages/server/package.json +25 -0
- package/packages/shared/dist/constants/colors.d.ts +46 -0
- package/packages/shared/dist/constants/colors.d.ts.map +1 -0
- package/packages/shared/dist/constants/colors.js +178 -0
- package/packages/shared/dist/constants/colors.js.map +1 -0
- package/packages/shared/dist/constants/names.d.ts +6 -0
- package/packages/shared/dist/constants/names.d.ts.map +1 -0
- package/packages/shared/dist/constants/names.js +28 -0
- package/packages/shared/dist/constants/names.js.map +1 -0
- package/packages/shared/dist/constants/tools.d.ts +15 -0
- package/packages/shared/dist/constants/tools.d.ts.map +1 -0
- package/packages/shared/dist/constants/tools.js +120 -0
- package/packages/shared/dist/constants/tools.js.map +1 -0
- package/packages/shared/dist/constants/zones.d.ts +37 -0
- package/packages/shared/dist/constants/zones.d.ts.map +1 -0
- package/packages/shared/dist/constants/zones.js +128 -0
- package/packages/shared/dist/constants/zones.js.map +1 -0
- package/packages/shared/dist/index.d.ts +15 -0
- package/packages/shared/dist/index.d.ts.map +1 -0
- package/packages/shared/dist/index.js +7 -0
- package/packages/shared/dist/index.js.map +1 -0
- package/packages/shared/dist/types/agent.d.ts +85 -0
- package/packages/shared/dist/types/agent.d.ts.map +1 -0
- package/packages/shared/dist/types/agent.js +2 -0
- package/packages/shared/dist/types/agent.js.map +1 -0
- package/packages/shared/dist/types/anomaly.d.ts +18 -0
- package/packages/shared/dist/types/anomaly.d.ts.map +1 -0
- package/packages/shared/dist/types/anomaly.js +6 -0
- package/packages/shared/dist/types/anomaly.js.map +1 -0
- package/packages/shared/dist/types/hooks.d.ts +51 -0
- package/packages/shared/dist/types/hooks.d.ts.map +1 -0
- package/packages/shared/dist/types/hooks.js +2 -0
- package/packages/shared/dist/types/hooks.js.map +1 -0
- package/packages/shared/dist/types/jsonl.d.ts +62 -0
- package/packages/shared/dist/types/jsonl.d.ts.map +1 -0
- package/packages/shared/dist/types/jsonl.js +3 -0
- package/packages/shared/dist/types/jsonl.js.map +1 -0
- package/packages/shared/dist/types/task-graph.d.ts +20 -0
- package/packages/shared/dist/types/task-graph.d.ts.map +1 -0
- package/packages/shared/dist/types/task-graph.js +2 -0
- package/packages/shared/dist/types/task-graph.js.map +1 -0
- package/packages/shared/dist/types/tool-chain.d.ts +17 -0
- package/packages/shared/dist/types/tool-chain.d.ts.map +1 -0
- package/packages/shared/dist/types/tool-chain.js +2 -0
- package/packages/shared/dist/types/tool-chain.js.map +1 -0
- package/packages/shared/dist/types/websocket.d.ts +132 -0
- package/packages/shared/dist/types/websocket.d.ts.map +1 -0
- package/packages/shared/dist/types/websocket.js +2 -0
- package/packages/shared/dist/types/websocket.js.map +1 -0
- package/packages/shared/dist/types/zone.d.ts +21 -0
- package/packages/shared/dist/types/zone.d.ts.map +1 -0
- package/packages/shared/dist/types/zone.js +2 -0
- package/packages/shared/dist/types/zone.js.map +1 -0
- package/packages/shared/package.json +15 -0
|
@@ -0,0 +1,1292 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// dist/watcher/opencode/opencode-watcher.js
|
|
9
|
+
import chokidar from "chokidar";
|
|
10
|
+
import { homedir } from "os";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
import { homedir as homedir2 } from "os";
|
|
13
|
+
import { join as join2 } from "path";
|
|
14
|
+
import { existsSync } from "fs";
|
|
15
|
+
var __create = Object.create;
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
18
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
19
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
20
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
21
|
+
var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
22
|
+
get: (a, b) => (typeof __require !== "undefined" ? __require : a)[b]
|
|
23
|
+
}) : x)(function(x) {
|
|
24
|
+
if (typeof __require !== "undefined") return __require.apply(this, arguments);
|
|
25
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
26
|
+
});
|
|
27
|
+
var __commonJS = (cb, mod) => function __require22() {
|
|
28
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
29
|
+
};
|
|
30
|
+
var __copyProps = (to, from, except, desc) => {
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return to;
|
|
37
|
+
};
|
|
38
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
39
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
40
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
41
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
42
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
43
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
44
|
+
mod
|
|
45
|
+
));
|
|
46
|
+
var require_util = __commonJS({
|
|
47
|
+
"../../node_modules/better-sqlite3/lib/util.js"(exports) {
|
|
48
|
+
"use strict";
|
|
49
|
+
exports.getBooleanOption = (options, key) => {
|
|
50
|
+
let value = false;
|
|
51
|
+
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
52
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
exports.cppdb = /* @__PURE__ */ Symbol();
|
|
57
|
+
exports.inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var require_sqlite_error = __commonJS({
|
|
61
|
+
"../../node_modules/better-sqlite3/lib/sqlite-error.js"(exports, module) {
|
|
62
|
+
"use strict";
|
|
63
|
+
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
64
|
+
function SqliteError(message, code) {
|
|
65
|
+
if (new.target !== SqliteError) {
|
|
66
|
+
return new SqliteError(message, code);
|
|
67
|
+
}
|
|
68
|
+
if (typeof code !== "string") {
|
|
69
|
+
throw new TypeError("Expected second argument to be a string");
|
|
70
|
+
}
|
|
71
|
+
Error.call(this, message);
|
|
72
|
+
descriptor.value = "" + message;
|
|
73
|
+
Object.defineProperty(this, "message", descriptor);
|
|
74
|
+
Error.captureStackTrace(this, SqliteError);
|
|
75
|
+
this.code = code;
|
|
76
|
+
}
|
|
77
|
+
Object.setPrototypeOf(SqliteError, Error);
|
|
78
|
+
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
79
|
+
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
80
|
+
module.exports = SqliteError;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
var require_file_uri_to_path = __commonJS({
|
|
84
|
+
"../../node_modules/file-uri-to-path/index.js"(exports, module) {
|
|
85
|
+
var sep = __require2("path").sep || "/";
|
|
86
|
+
module.exports = fileUriToPath;
|
|
87
|
+
function fileUriToPath(uri) {
|
|
88
|
+
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
89
|
+
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
90
|
+
}
|
|
91
|
+
var rest = decodeURI(uri.substring(7));
|
|
92
|
+
var firstSlash = rest.indexOf("/");
|
|
93
|
+
var host = rest.substring(0, firstSlash);
|
|
94
|
+
var path = rest.substring(firstSlash + 1);
|
|
95
|
+
if ("localhost" == host) host = "";
|
|
96
|
+
if (host) {
|
|
97
|
+
host = sep + sep + host;
|
|
98
|
+
}
|
|
99
|
+
path = path.replace(/^(.+)\|/, "$1:");
|
|
100
|
+
if (sep == "\\") {
|
|
101
|
+
path = path.replace(/\//g, "\\");
|
|
102
|
+
}
|
|
103
|
+
if (/^.+\:/.test(path)) {
|
|
104
|
+
} else {
|
|
105
|
+
path = sep + path;
|
|
106
|
+
}
|
|
107
|
+
return host + path;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
var require_bindings = __commonJS({
|
|
112
|
+
"../../node_modules/bindings/bindings.js"(exports, module) {
|
|
113
|
+
var fs = __require2("fs");
|
|
114
|
+
var path = __require2("path");
|
|
115
|
+
var fileURLToPath = require_file_uri_to_path();
|
|
116
|
+
var join3 = path.join;
|
|
117
|
+
var dirname = path.dirname;
|
|
118
|
+
var exists = fs.accessSync && function(path2) {
|
|
119
|
+
try {
|
|
120
|
+
fs.accessSync(path2);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
} || fs.existsSync || path.existsSync;
|
|
126
|
+
var defaults = {
|
|
127
|
+
arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
|
|
128
|
+
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
129
|
+
platform: process.platform,
|
|
130
|
+
arch: process.arch,
|
|
131
|
+
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
132
|
+
version: process.versions.node,
|
|
133
|
+
bindings: "bindings.node",
|
|
134
|
+
try: [
|
|
135
|
+
// node-gyp's linked version in the "build" dir
|
|
136
|
+
["module_root", "build", "bindings"],
|
|
137
|
+
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
138
|
+
["module_root", "build", "Debug", "bindings"],
|
|
139
|
+
["module_root", "build", "Release", "bindings"],
|
|
140
|
+
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
141
|
+
["module_root", "out", "Debug", "bindings"],
|
|
142
|
+
["module_root", "Debug", "bindings"],
|
|
143
|
+
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
144
|
+
["module_root", "out", "Release", "bindings"],
|
|
145
|
+
["module_root", "Release", "bindings"],
|
|
146
|
+
// Legacy from node-waf, node <= 0.4.x
|
|
147
|
+
["module_root", "build", "default", "bindings"],
|
|
148
|
+
// Production "Release" buildtype binary (meh...)
|
|
149
|
+
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
150
|
+
// node-qbs builds
|
|
151
|
+
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
152
|
+
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
153
|
+
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
154
|
+
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
155
|
+
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
function bindings(opts) {
|
|
159
|
+
if (typeof opts == "string") {
|
|
160
|
+
opts = { bindings: opts };
|
|
161
|
+
} else if (!opts) {
|
|
162
|
+
opts = {};
|
|
163
|
+
}
|
|
164
|
+
Object.keys(defaults).map(function(i2) {
|
|
165
|
+
if (!(i2 in opts)) opts[i2] = defaults[i2];
|
|
166
|
+
});
|
|
167
|
+
if (!opts.module_root) {
|
|
168
|
+
opts.module_root = exports.getRoot(exports.getFileName());
|
|
169
|
+
}
|
|
170
|
+
if (path.extname(opts.bindings) != ".node") {
|
|
171
|
+
opts.bindings += ".node";
|
|
172
|
+
}
|
|
173
|
+
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require2;
|
|
174
|
+
var tries = [], i = 0, l = opts.try.length, n, b, err;
|
|
175
|
+
for (; i < l; i++) {
|
|
176
|
+
n = join3.apply(
|
|
177
|
+
null,
|
|
178
|
+
opts.try[i].map(function(p) {
|
|
179
|
+
return opts[p] || p;
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
tries.push(n);
|
|
183
|
+
try {
|
|
184
|
+
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
185
|
+
if (!opts.path) {
|
|
186
|
+
b.path = n;
|
|
187
|
+
}
|
|
188
|
+
return b;
|
|
189
|
+
} catch (e) {
|
|
190
|
+
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
191
|
+
throw e;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
err = new Error(
|
|
196
|
+
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
197
|
+
return opts.arrow + a;
|
|
198
|
+
}).join("\n")
|
|
199
|
+
);
|
|
200
|
+
err.tries = tries;
|
|
201
|
+
throw err;
|
|
202
|
+
}
|
|
203
|
+
module.exports = exports = bindings;
|
|
204
|
+
exports.getFileName = function getFileName(calling_file) {
|
|
205
|
+
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
206
|
+
Error.stackTraceLimit = 10;
|
|
207
|
+
Error.prepareStackTrace = function(e, st) {
|
|
208
|
+
for (var i = 0, l = st.length; i < l; i++) {
|
|
209
|
+
fileName = st[i].getFileName();
|
|
210
|
+
if (fileName !== __filename) {
|
|
211
|
+
if (calling_file) {
|
|
212
|
+
if (fileName !== calling_file) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
Error.captureStackTrace(dummy);
|
|
222
|
+
dummy.stack;
|
|
223
|
+
Error.prepareStackTrace = origPST;
|
|
224
|
+
Error.stackTraceLimit = origSTL;
|
|
225
|
+
var fileSchema = "file://";
|
|
226
|
+
if (fileName.indexOf(fileSchema) === 0) {
|
|
227
|
+
fileName = fileURLToPath(fileName);
|
|
228
|
+
}
|
|
229
|
+
return fileName;
|
|
230
|
+
};
|
|
231
|
+
exports.getRoot = function getRoot(file) {
|
|
232
|
+
var dir = dirname(file), prev;
|
|
233
|
+
while (true) {
|
|
234
|
+
if (dir === ".") {
|
|
235
|
+
dir = process.cwd();
|
|
236
|
+
}
|
|
237
|
+
if (exists(join3(dir, "package.json")) || exists(join3(dir, "node_modules"))) {
|
|
238
|
+
return dir;
|
|
239
|
+
}
|
|
240
|
+
if (prev === dir) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
prev = dir;
|
|
246
|
+
dir = join3(dir, "..");
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
var require_wrappers = __commonJS({
|
|
252
|
+
"../../node_modules/better-sqlite3/lib/methods/wrappers.js"(exports) {
|
|
253
|
+
"use strict";
|
|
254
|
+
var { cppdb } = require_util();
|
|
255
|
+
exports.prepare = function prepare(sql) {
|
|
256
|
+
return this[cppdb].prepare(sql, this, false);
|
|
257
|
+
};
|
|
258
|
+
exports.exec = function exec(sql) {
|
|
259
|
+
this[cppdb].exec(sql);
|
|
260
|
+
return this;
|
|
261
|
+
};
|
|
262
|
+
exports.close = function close() {
|
|
263
|
+
this[cppdb].close();
|
|
264
|
+
return this;
|
|
265
|
+
};
|
|
266
|
+
exports.loadExtension = function loadExtension(...args) {
|
|
267
|
+
this[cppdb].loadExtension(...args);
|
|
268
|
+
return this;
|
|
269
|
+
};
|
|
270
|
+
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
271
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
272
|
+
return this;
|
|
273
|
+
};
|
|
274
|
+
exports.unsafeMode = function unsafeMode(...args) {
|
|
275
|
+
this[cppdb].unsafeMode(...args);
|
|
276
|
+
return this;
|
|
277
|
+
};
|
|
278
|
+
exports.getters = {
|
|
279
|
+
name: {
|
|
280
|
+
get: function name() {
|
|
281
|
+
return this[cppdb].name;
|
|
282
|
+
},
|
|
283
|
+
enumerable: true
|
|
284
|
+
},
|
|
285
|
+
open: {
|
|
286
|
+
get: function open() {
|
|
287
|
+
return this[cppdb].open;
|
|
288
|
+
},
|
|
289
|
+
enumerable: true
|
|
290
|
+
},
|
|
291
|
+
inTransaction: {
|
|
292
|
+
get: function inTransaction() {
|
|
293
|
+
return this[cppdb].inTransaction;
|
|
294
|
+
},
|
|
295
|
+
enumerable: true
|
|
296
|
+
},
|
|
297
|
+
readonly: {
|
|
298
|
+
get: function readonly() {
|
|
299
|
+
return this[cppdb].readonly;
|
|
300
|
+
},
|
|
301
|
+
enumerable: true
|
|
302
|
+
},
|
|
303
|
+
memory: {
|
|
304
|
+
get: function memory() {
|
|
305
|
+
return this[cppdb].memory;
|
|
306
|
+
},
|
|
307
|
+
enumerable: true
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
var require_transaction = __commonJS({
|
|
313
|
+
"../../node_modules/better-sqlite3/lib/methods/transaction.js"(exports, module) {
|
|
314
|
+
"use strict";
|
|
315
|
+
var { cppdb } = require_util();
|
|
316
|
+
var controllers = /* @__PURE__ */ new WeakMap();
|
|
317
|
+
module.exports = function transaction(fn) {
|
|
318
|
+
if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
|
|
319
|
+
const db = this[cppdb];
|
|
320
|
+
const controller = getController(db, this);
|
|
321
|
+
const { apply } = Function.prototype;
|
|
322
|
+
const properties = {
|
|
323
|
+
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
324
|
+
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
325
|
+
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
326
|
+
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
327
|
+
database: { value: this, enumerable: true }
|
|
328
|
+
};
|
|
329
|
+
Object.defineProperties(properties.default.value, properties);
|
|
330
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
331
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
332
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
333
|
+
return properties.default.value;
|
|
334
|
+
};
|
|
335
|
+
var getController = (db, self) => {
|
|
336
|
+
let controller = controllers.get(db);
|
|
337
|
+
if (!controller) {
|
|
338
|
+
const shared = {
|
|
339
|
+
commit: db.prepare("COMMIT", self, false),
|
|
340
|
+
rollback: db.prepare("ROLLBACK", self, false),
|
|
341
|
+
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
|
|
342
|
+
release: db.prepare("RELEASE ` _bs3. `", self, false),
|
|
343
|
+
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
|
|
344
|
+
};
|
|
345
|
+
controllers.set(db, controller = {
|
|
346
|
+
default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
|
|
347
|
+
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
|
|
348
|
+
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
|
|
349
|
+
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return controller;
|
|
353
|
+
};
|
|
354
|
+
var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
355
|
+
let before, after, undo;
|
|
356
|
+
if (db.inTransaction) {
|
|
357
|
+
before = savepoint;
|
|
358
|
+
after = release;
|
|
359
|
+
undo = rollbackTo;
|
|
360
|
+
} else {
|
|
361
|
+
before = begin;
|
|
362
|
+
after = commit;
|
|
363
|
+
undo = rollback;
|
|
364
|
+
}
|
|
365
|
+
before.run();
|
|
366
|
+
try {
|
|
367
|
+
const result = apply.call(fn, this, arguments);
|
|
368
|
+
if (result && typeof result.then === "function") {
|
|
369
|
+
throw new TypeError("Transaction function cannot return a promise");
|
|
370
|
+
}
|
|
371
|
+
after.run();
|
|
372
|
+
return result;
|
|
373
|
+
} catch (ex) {
|
|
374
|
+
if (db.inTransaction) {
|
|
375
|
+
undo.run();
|
|
376
|
+
if (undo !== rollback) after.run();
|
|
377
|
+
}
|
|
378
|
+
throw ex;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
var require_pragma = __commonJS({
|
|
384
|
+
"../../node_modules/better-sqlite3/lib/methods/pragma.js"(exports, module) {
|
|
385
|
+
"use strict";
|
|
386
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
387
|
+
module.exports = function pragma(source, options) {
|
|
388
|
+
if (options == null) options = {};
|
|
389
|
+
if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
|
|
390
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
391
|
+
const simple = getBooleanOption(options, "simple");
|
|
392
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
393
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
var require_backup = __commonJS({
|
|
398
|
+
"../../node_modules/better-sqlite3/lib/methods/backup.js"(exports, module) {
|
|
399
|
+
"use strict";
|
|
400
|
+
var fs = __require2("fs");
|
|
401
|
+
var path = __require2("path");
|
|
402
|
+
var { promisify } = __require2("util");
|
|
403
|
+
var { cppdb } = require_util();
|
|
404
|
+
var fsAccess = promisify(fs.access);
|
|
405
|
+
module.exports = async function backup(filename, options) {
|
|
406
|
+
if (options == null) options = {};
|
|
407
|
+
if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
|
|
408
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
409
|
+
filename = filename.trim();
|
|
410
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
411
|
+
const handler = "progress" in options ? options.progress : null;
|
|
412
|
+
if (!filename) throw new TypeError("Backup filename cannot be an empty string");
|
|
413
|
+
if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
|
|
414
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
415
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
416
|
+
if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
|
|
417
|
+
await fsAccess(path.dirname(filename)).catch(() => {
|
|
418
|
+
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
419
|
+
});
|
|
420
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
421
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
422
|
+
};
|
|
423
|
+
var runBackup = (backup, handler) => {
|
|
424
|
+
let rate = 0;
|
|
425
|
+
let useDefault = true;
|
|
426
|
+
return new Promise((resolve, reject) => {
|
|
427
|
+
setImmediate(function step() {
|
|
428
|
+
try {
|
|
429
|
+
const progress = backup.transfer(rate);
|
|
430
|
+
if (!progress.remainingPages) {
|
|
431
|
+
backup.close();
|
|
432
|
+
resolve(progress);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (useDefault) {
|
|
436
|
+
useDefault = false;
|
|
437
|
+
rate = 100;
|
|
438
|
+
}
|
|
439
|
+
if (handler) {
|
|
440
|
+
const ret = handler(progress);
|
|
441
|
+
if (ret !== void 0) {
|
|
442
|
+
if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
443
|
+
else throw new TypeError("Expected progress callback to return a number or undefined");
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
setImmediate(step);
|
|
447
|
+
} catch (err) {
|
|
448
|
+
backup.close();
|
|
449
|
+
reject(err);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
var require_serialize = __commonJS({
|
|
457
|
+
"../../node_modules/better-sqlite3/lib/methods/serialize.js"(exports, module) {
|
|
458
|
+
"use strict";
|
|
459
|
+
var { cppdb } = require_util();
|
|
460
|
+
module.exports = function serialize(options) {
|
|
461
|
+
if (options == null) options = {};
|
|
462
|
+
if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
|
|
463
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
464
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
465
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
466
|
+
return this[cppdb].serialize(attachedName);
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
var require_function = __commonJS({
|
|
471
|
+
"../../node_modules/better-sqlite3/lib/methods/function.js"(exports, module) {
|
|
472
|
+
"use strict";
|
|
473
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
474
|
+
module.exports = function defineFunction(name, options, fn) {
|
|
475
|
+
if (options == null) options = {};
|
|
476
|
+
if (typeof options === "function") {
|
|
477
|
+
fn = options;
|
|
478
|
+
options = {};
|
|
479
|
+
}
|
|
480
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
481
|
+
if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
|
|
482
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
483
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
484
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
485
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
486
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
487
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
488
|
+
let argCount = -1;
|
|
489
|
+
if (!varargs) {
|
|
490
|
+
argCount = fn.length;
|
|
491
|
+
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
|
|
492
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
493
|
+
}
|
|
494
|
+
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
495
|
+
return this;
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
var require_aggregate = __commonJS({
|
|
500
|
+
"../../node_modules/better-sqlite3/lib/methods/aggregate.js"(exports, module) {
|
|
501
|
+
"use strict";
|
|
502
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
503
|
+
module.exports = function defineAggregate(name, options) {
|
|
504
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
505
|
+
if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
|
|
506
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
507
|
+
const start = "start" in options ? options.start : null;
|
|
508
|
+
const step = getFunctionOption(options, "step", true);
|
|
509
|
+
const inverse = getFunctionOption(options, "inverse", false);
|
|
510
|
+
const result = getFunctionOption(options, "result", false);
|
|
511
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
512
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
513
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
514
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
515
|
+
let argCount = -1;
|
|
516
|
+
if (!varargs) {
|
|
517
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
518
|
+
if (argCount > 0) argCount -= 1;
|
|
519
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
520
|
+
}
|
|
521
|
+
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
522
|
+
return this;
|
|
523
|
+
};
|
|
524
|
+
var getFunctionOption = (options, key, required) => {
|
|
525
|
+
const value = key in options ? options[key] : null;
|
|
526
|
+
if (typeof value === "function") return value;
|
|
527
|
+
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
528
|
+
if (required) throw new TypeError(`Missing required option "${key}"`);
|
|
529
|
+
return null;
|
|
530
|
+
};
|
|
531
|
+
var getLength = ({ length }) => {
|
|
532
|
+
if (Number.isInteger(length) && length >= 0) return length;
|
|
533
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
var require_table = __commonJS({
|
|
538
|
+
"../../node_modules/better-sqlite3/lib/methods/table.js"(exports, module) {
|
|
539
|
+
"use strict";
|
|
540
|
+
var { cppdb } = require_util();
|
|
541
|
+
module.exports = function defineTable(name, factory) {
|
|
542
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
543
|
+
if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
|
|
544
|
+
let eponymous = false;
|
|
545
|
+
if (typeof factory === "object" && factory !== null) {
|
|
546
|
+
eponymous = true;
|
|
547
|
+
factory = defer(parseTableDefinition(factory, "used", name));
|
|
548
|
+
} else {
|
|
549
|
+
if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
550
|
+
factory = wrapFactory(factory);
|
|
551
|
+
}
|
|
552
|
+
this[cppdb].table(factory, name, eponymous);
|
|
553
|
+
return this;
|
|
554
|
+
};
|
|
555
|
+
function wrapFactory(factory) {
|
|
556
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
557
|
+
const thisObject = {
|
|
558
|
+
module: moduleName,
|
|
559
|
+
database: databaseName,
|
|
560
|
+
table: tableName
|
|
561
|
+
};
|
|
562
|
+
const def = apply.call(factory, thisObject, args);
|
|
563
|
+
if (typeof def !== "object" || def === null) {
|
|
564
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
565
|
+
}
|
|
566
|
+
return parseTableDefinition(def, "returned", moduleName);
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
570
|
+
if (!hasOwnProperty.call(def, "rows")) {
|
|
571
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
572
|
+
}
|
|
573
|
+
if (!hasOwnProperty.call(def, "columns")) {
|
|
574
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
575
|
+
}
|
|
576
|
+
const rows = def.rows;
|
|
577
|
+
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
578
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
579
|
+
}
|
|
580
|
+
let columns = def.columns;
|
|
581
|
+
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
582
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
583
|
+
}
|
|
584
|
+
if (columns.length !== new Set(columns).size) {
|
|
585
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
586
|
+
}
|
|
587
|
+
if (!columns.length) {
|
|
588
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
589
|
+
}
|
|
590
|
+
let parameters;
|
|
591
|
+
if (hasOwnProperty.call(def, "parameters")) {
|
|
592
|
+
parameters = def.parameters;
|
|
593
|
+
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
594
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
parameters = inferParameters(rows);
|
|
598
|
+
}
|
|
599
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
600
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
601
|
+
}
|
|
602
|
+
if (parameters.length > 32) {
|
|
603
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
604
|
+
}
|
|
605
|
+
for (const parameter of parameters) {
|
|
606
|
+
if (columns.includes(parameter)) {
|
|
607
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
let safeIntegers = 2;
|
|
611
|
+
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
612
|
+
const bool = def.safeIntegers;
|
|
613
|
+
if (typeof bool !== "boolean") {
|
|
614
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
615
|
+
}
|
|
616
|
+
safeIntegers = +bool;
|
|
617
|
+
}
|
|
618
|
+
let directOnly = false;
|
|
619
|
+
if (hasOwnProperty.call(def, "directOnly")) {
|
|
620
|
+
directOnly = def.directOnly;
|
|
621
|
+
if (typeof directOnly !== "boolean") {
|
|
622
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const columnDefinitions = [
|
|
626
|
+
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
627
|
+
...columns.map(identifier)
|
|
628
|
+
];
|
|
629
|
+
return [
|
|
630
|
+
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
631
|
+
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
632
|
+
parameters,
|
|
633
|
+
safeIntegers,
|
|
634
|
+
directOnly
|
|
635
|
+
];
|
|
636
|
+
}
|
|
637
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
638
|
+
return function* virtualTable(...args) {
|
|
639
|
+
const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
640
|
+
for (let i = 0; i < columnMap.size; ++i) {
|
|
641
|
+
output.push(null);
|
|
642
|
+
}
|
|
643
|
+
for (const row of generator(...args)) {
|
|
644
|
+
if (Array.isArray(row)) {
|
|
645
|
+
extractRowArray(row, output, columnMap.size, moduleName);
|
|
646
|
+
yield output;
|
|
647
|
+
} else if (typeof row === "object" && row !== null) {
|
|
648
|
+
extractRowObject(row, output, columnMap, moduleName);
|
|
649
|
+
yield output;
|
|
650
|
+
} else {
|
|
651
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
function extractRowArray(row, output, columnCount, moduleName) {
|
|
657
|
+
if (row.length !== columnCount) {
|
|
658
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
659
|
+
}
|
|
660
|
+
const offset = output.length - columnCount;
|
|
661
|
+
for (let i = 0; i < columnCount; ++i) {
|
|
662
|
+
output[i + offset] = row[i];
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function extractRowObject(row, output, columnMap, moduleName) {
|
|
666
|
+
let count = 0;
|
|
667
|
+
for (const key of Object.keys(row)) {
|
|
668
|
+
const index = columnMap.get(key);
|
|
669
|
+
if (index === void 0) {
|
|
670
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
671
|
+
}
|
|
672
|
+
output[index] = row[key];
|
|
673
|
+
count += 1;
|
|
674
|
+
}
|
|
675
|
+
if (count !== columnMap.size) {
|
|
676
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function inferParameters({ length }) {
|
|
680
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
681
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
682
|
+
}
|
|
683
|
+
const params = [];
|
|
684
|
+
for (let i = 0; i < length; ++i) {
|
|
685
|
+
params.push(`$${i + 1}`);
|
|
686
|
+
}
|
|
687
|
+
return params;
|
|
688
|
+
}
|
|
689
|
+
var { hasOwnProperty } = Object.prototype;
|
|
690
|
+
var { apply } = Function.prototype;
|
|
691
|
+
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
692
|
+
});
|
|
693
|
+
var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
694
|
+
var defer = (x) => () => x;
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
var require_inspect = __commonJS({
|
|
698
|
+
"../../node_modules/better-sqlite3/lib/methods/inspect.js"(exports, module) {
|
|
699
|
+
"use strict";
|
|
700
|
+
var DatabaseInspection = function Database2() {
|
|
701
|
+
};
|
|
702
|
+
module.exports = function inspect(depth, opts) {
|
|
703
|
+
return Object.assign(new DatabaseInspection(), this);
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
var require_database = __commonJS({
|
|
708
|
+
"../../node_modules/better-sqlite3/lib/database.js"(exports, module) {
|
|
709
|
+
"use strict";
|
|
710
|
+
var fs = __require2("fs");
|
|
711
|
+
var path = __require2("path");
|
|
712
|
+
var util = require_util();
|
|
713
|
+
var SqliteError = require_sqlite_error();
|
|
714
|
+
var DEFAULT_ADDON;
|
|
715
|
+
function Database2(filenameGiven, options) {
|
|
716
|
+
if (new.target == null) {
|
|
717
|
+
return new Database2(filenameGiven, options);
|
|
718
|
+
}
|
|
719
|
+
let buffer;
|
|
720
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
721
|
+
buffer = filenameGiven;
|
|
722
|
+
filenameGiven = ":memory:";
|
|
723
|
+
}
|
|
724
|
+
if (filenameGiven == null) filenameGiven = "";
|
|
725
|
+
if (options == null) options = {};
|
|
726
|
+
if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
|
|
727
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
728
|
+
if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
729
|
+
if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
730
|
+
const filename = filenameGiven.trim();
|
|
731
|
+
const anonymous = filename === "" || filename === ":memory:";
|
|
732
|
+
const readonly = util.getBooleanOption(options, "readonly");
|
|
733
|
+
const fileMustExist = util.getBooleanOption(options, "fileMustExist");
|
|
734
|
+
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
735
|
+
const verbose = "verbose" in options ? options.verbose : null;
|
|
736
|
+
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
737
|
+
if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
738
|
+
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
739
|
+
if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
740
|
+
if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
|
|
741
|
+
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
742
|
+
let addon;
|
|
743
|
+
if (nativeBinding == null) {
|
|
744
|
+
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
745
|
+
} else if (typeof nativeBinding === "string") {
|
|
746
|
+
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require2;
|
|
747
|
+
addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
748
|
+
} else {
|
|
749
|
+
addon = nativeBinding;
|
|
750
|
+
}
|
|
751
|
+
if (!addon.isInitialized) {
|
|
752
|
+
addon.setErrorConstructor(SqliteError);
|
|
753
|
+
addon.isInitialized = true;
|
|
754
|
+
}
|
|
755
|
+
if (!anonymous && !filename.startsWith("file:") && !fs.existsSync(path.dirname(filename))) {
|
|
756
|
+
throw new TypeError("Cannot open database because the directory does not exist");
|
|
757
|
+
}
|
|
758
|
+
Object.defineProperties(this, {
|
|
759
|
+
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
760
|
+
...wrappers.getters
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
var wrappers = require_wrappers();
|
|
764
|
+
Database2.prototype.prepare = wrappers.prepare;
|
|
765
|
+
Database2.prototype.transaction = require_transaction();
|
|
766
|
+
Database2.prototype.pragma = require_pragma();
|
|
767
|
+
Database2.prototype.backup = require_backup();
|
|
768
|
+
Database2.prototype.serialize = require_serialize();
|
|
769
|
+
Database2.prototype.function = require_function();
|
|
770
|
+
Database2.prototype.aggregate = require_aggregate();
|
|
771
|
+
Database2.prototype.table = require_table();
|
|
772
|
+
Database2.prototype.loadExtension = wrappers.loadExtension;
|
|
773
|
+
Database2.prototype.exec = wrappers.exec;
|
|
774
|
+
Database2.prototype.close = wrappers.close;
|
|
775
|
+
Database2.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
776
|
+
Database2.prototype.unsafeMode = wrappers.unsafeMode;
|
|
777
|
+
Database2.prototype[util.inspect] = require_inspect();
|
|
778
|
+
module.exports = Database2;
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
var require_lib = __commonJS({
|
|
782
|
+
"../../node_modules/better-sqlite3/lib/index.js"(exports, module) {
|
|
783
|
+
"use strict";
|
|
784
|
+
module.exports = require_database();
|
|
785
|
+
module.exports.SqliteError = require_sqlite_error();
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
var import_better_sqlite3 = __toESM(require_lib(), 1);
|
|
789
|
+
var config = {
|
|
790
|
+
port: parseInt(process.env.AGENT_MOVE_PORT || "3333", 10),
|
|
791
|
+
claudeHome: join(homedir(), ".claude"),
|
|
792
|
+
idleTimeoutMs: 45e3,
|
|
793
|
+
/** How long after going idle before an agent is automatically shutdown/removed */
|
|
794
|
+
shutdownTimeoutMs: 30 * 60 * 1e3,
|
|
795
|
+
// 30 minutes
|
|
796
|
+
/** How recently a session file must be modified to be considered "active" on startup */
|
|
797
|
+
activeThresholdMs: 10 * 60 * 1e3,
|
|
798
|
+
// 10 minutes
|
|
799
|
+
/** Enable OpenCode session watching (auto-detected if storage dir exists) */
|
|
800
|
+
enableOpenCode: process.env.AGENT_MOVE_OPENCODE !== "false"
|
|
801
|
+
};
|
|
802
|
+
function getOpenCodeDbPath() {
|
|
803
|
+
const home = homedir2();
|
|
804
|
+
const candidates = [
|
|
805
|
+
join2(home, ".local", "share", "opencode", "opencode.db"),
|
|
806
|
+
// Windows fallback via LOCALAPPDATA
|
|
807
|
+
...process.env.LOCALAPPDATA ? [join2(process.env.LOCALAPPDATA, "opencode", "opencode.db")] : [],
|
|
808
|
+
join2(home, ".opencode", "opencode.db")
|
|
809
|
+
];
|
|
810
|
+
for (const candidate of candidates) {
|
|
811
|
+
if (existsSync(candidate))
|
|
812
|
+
return candidate;
|
|
813
|
+
}
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
function parseOpenCodeSession(row) {
|
|
817
|
+
const segments = row.directory.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
818
|
+
const projectName = segments[segments.length - 1] || "opencode";
|
|
819
|
+
return {
|
|
820
|
+
// Use the actual directory as projectPath so getGitBranch() gets a valid cwd.
|
|
821
|
+
// projectDir uses the project_id hash to group agents belonging to the same project.
|
|
822
|
+
projectPath: row.directory || row.project_id,
|
|
823
|
+
projectName,
|
|
824
|
+
isSubagent: !!row.parent_id,
|
|
825
|
+
projectDir: row.project_id,
|
|
826
|
+
parentSessionId: row.parent_id ? `oc:${row.parent_id}` : null
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
var TOOL_NAME_MAP = {
|
|
830
|
+
// OpenCode lowercase → canonical PascalCase
|
|
831
|
+
read: "Read",
|
|
832
|
+
write: "Write",
|
|
833
|
+
edit: "Edit",
|
|
834
|
+
patch: "Patch",
|
|
835
|
+
glob: "Glob",
|
|
836
|
+
bash: "Bash",
|
|
837
|
+
grep: "Grep",
|
|
838
|
+
websearch: "WebSearch",
|
|
839
|
+
webfetch: "WebFetch",
|
|
840
|
+
todoread: "TodoRead",
|
|
841
|
+
todowrite: "TodoWrite"
|
|
842
|
+
};
|
|
843
|
+
function normalizeToolName(name) {
|
|
844
|
+
return TOOL_NAME_MAP[name] ?? name;
|
|
845
|
+
}
|
|
846
|
+
function normalizeToolInput(input) {
|
|
847
|
+
if (!("filePath" in input) && !("oldString" in input) && !("newString" in input) && !("replaceAll" in input)) {
|
|
848
|
+
return input;
|
|
849
|
+
}
|
|
850
|
+
const out = { ...input };
|
|
851
|
+
if ("filePath" in out) {
|
|
852
|
+
out.file_path = out.filePath;
|
|
853
|
+
delete out.filePath;
|
|
854
|
+
}
|
|
855
|
+
if ("oldString" in out) {
|
|
856
|
+
out.old_string = out.oldString;
|
|
857
|
+
delete out.oldString;
|
|
858
|
+
}
|
|
859
|
+
if ("newString" in out) {
|
|
860
|
+
out.new_string = out.newString;
|
|
861
|
+
delete out.newString;
|
|
862
|
+
}
|
|
863
|
+
if ("replaceAll" in out) {
|
|
864
|
+
out.replace_all = out.replaceAll;
|
|
865
|
+
delete out.replaceAll;
|
|
866
|
+
}
|
|
867
|
+
return out;
|
|
868
|
+
}
|
|
869
|
+
var ZONES = [
|
|
870
|
+
// Row 0
|
|
871
|
+
{
|
|
872
|
+
id: "search",
|
|
873
|
+
label: "Search",
|
|
874
|
+
description: "Grep, WebSearch \u2014 Research & lookup",
|
|
875
|
+
icon: "\u{1F4DA}",
|
|
876
|
+
color: 15381256,
|
|
877
|
+
colStart: 0,
|
|
878
|
+
colSpan: 5,
|
|
879
|
+
rowStart: 0,
|
|
880
|
+
rowSpan: 1,
|
|
881
|
+
x: 0,
|
|
882
|
+
y: 0,
|
|
883
|
+
width: 0,
|
|
884
|
+
height: 0
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
id: "terminal",
|
|
888
|
+
label: "Terminal",
|
|
889
|
+
description: "Bash commands \u2014 Server room",
|
|
890
|
+
icon: "\u{1F4BB}",
|
|
891
|
+
color: 2278750,
|
|
892
|
+
colStart: 5,
|
|
893
|
+
colSpan: 3,
|
|
894
|
+
rowStart: 0,
|
|
895
|
+
rowSpan: 1,
|
|
896
|
+
x: 0,
|
|
897
|
+
y: 0,
|
|
898
|
+
width: 0,
|
|
899
|
+
height: 0
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
id: "web",
|
|
903
|
+
label: "Web",
|
|
904
|
+
description: "WebFetch, Browser \u2014 Network hub",
|
|
905
|
+
icon: "\u{1F310}",
|
|
906
|
+
color: 9133302,
|
|
907
|
+
colStart: 8,
|
|
908
|
+
colSpan: 4,
|
|
909
|
+
rowStart: 0,
|
|
910
|
+
rowSpan: 1,
|
|
911
|
+
x: 0,
|
|
912
|
+
y: 0,
|
|
913
|
+
width: 0,
|
|
914
|
+
height: 0
|
|
915
|
+
},
|
|
916
|
+
// Row 1
|
|
917
|
+
{
|
|
918
|
+
id: "files",
|
|
919
|
+
label: "Files",
|
|
920
|
+
description: "Read, Write, Edit, Glob \u2014 File storage",
|
|
921
|
+
icon: "\u{1F4C1}",
|
|
922
|
+
color: 3900150,
|
|
923
|
+
colStart: 0,
|
|
924
|
+
colSpan: 4,
|
|
925
|
+
rowStart: 1,
|
|
926
|
+
rowSpan: 1,
|
|
927
|
+
x: 0,
|
|
928
|
+
y: 0,
|
|
929
|
+
width: 0,
|
|
930
|
+
height: 0
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
id: "thinking",
|
|
934
|
+
label: "Thinking",
|
|
935
|
+
description: "Planning, Questions \u2014 Conference area",
|
|
936
|
+
icon: "\u{1F4AD}",
|
|
937
|
+
color: 16347926,
|
|
938
|
+
colStart: 4,
|
|
939
|
+
colSpan: 5,
|
|
940
|
+
rowStart: 1,
|
|
941
|
+
rowSpan: 1,
|
|
942
|
+
x: 0,
|
|
943
|
+
y: 0,
|
|
944
|
+
width: 0,
|
|
945
|
+
height: 0
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
id: "messaging",
|
|
949
|
+
label: "Messaging",
|
|
950
|
+
description: "SendMessage, Teams \u2014 Chat & relax",
|
|
951
|
+
icon: "\u{1F4AC}",
|
|
952
|
+
color: 15485081,
|
|
953
|
+
colStart: 9,
|
|
954
|
+
colSpan: 3,
|
|
955
|
+
rowStart: 1,
|
|
956
|
+
rowSpan: 1,
|
|
957
|
+
x: 0,
|
|
958
|
+
y: 0,
|
|
959
|
+
width: 0,
|
|
960
|
+
height: 0
|
|
961
|
+
},
|
|
962
|
+
// Row 2
|
|
963
|
+
{
|
|
964
|
+
id: "spawn",
|
|
965
|
+
label: "Spawn",
|
|
966
|
+
description: "Agent spawn/despawn \u2014 Entry portal",
|
|
967
|
+
icon: "\u{1F300}",
|
|
968
|
+
color: 11032055,
|
|
969
|
+
colStart: 0,
|
|
970
|
+
colSpan: 3,
|
|
971
|
+
rowStart: 2,
|
|
972
|
+
rowSpan: 1,
|
|
973
|
+
x: 0,
|
|
974
|
+
y: 0,
|
|
975
|
+
width: 0,
|
|
976
|
+
height: 0
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
id: "idle",
|
|
980
|
+
label: "Idle",
|
|
981
|
+
description: "Idle agents rest here \u2014 Kitchen & lounge",
|
|
982
|
+
icon: "\u2615",
|
|
983
|
+
color: 7041664,
|
|
984
|
+
colStart: 3,
|
|
985
|
+
colSpan: 5,
|
|
986
|
+
rowStart: 2,
|
|
987
|
+
rowSpan: 1,
|
|
988
|
+
x: 0,
|
|
989
|
+
y: 0,
|
|
990
|
+
width: 0,
|
|
991
|
+
height: 0
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
id: "tasks",
|
|
995
|
+
label: "Tasks",
|
|
996
|
+
description: "TaskCreate, TaskUpdate \u2014 Kanban & planning",
|
|
997
|
+
icon: "\u{1F4CB}",
|
|
998
|
+
color: 1357990,
|
|
999
|
+
colStart: 8,
|
|
1000
|
+
colSpan: 4,
|
|
1001
|
+
rowStart: 2,
|
|
1002
|
+
rowSpan: 1,
|
|
1003
|
+
x: 0,
|
|
1004
|
+
y: 0,
|
|
1005
|
+
width: 0,
|
|
1006
|
+
height: 0
|
|
1007
|
+
}
|
|
1008
|
+
];
|
|
1009
|
+
var ZONE_MAP = new Map(ZONES.map((z) => [z.id, z]));
|
|
1010
|
+
var OpenCodeParser = class {
|
|
1011
|
+
/**
|
|
1012
|
+
* Convert an OpenCode part JSON object into a ParsedActivity.
|
|
1013
|
+
* All tool names and input field names are normalized to canonical form
|
|
1014
|
+
* so downstream code (activity-processor, TOOL_ZONE_MAP, etc.) needs no
|
|
1015
|
+
* agent-specific branches.
|
|
1016
|
+
*
|
|
1017
|
+
* Returns null for parts that carry no actionable activity.
|
|
1018
|
+
*/
|
|
1019
|
+
parsePart(partData, messageData) {
|
|
1020
|
+
if (partData.type === "tool") {
|
|
1021
|
+
const tool = partData;
|
|
1022
|
+
if (tool.state.status === "pending")
|
|
1023
|
+
return null;
|
|
1024
|
+
const rawInput = tool.state.input ?? {};
|
|
1025
|
+
return {
|
|
1026
|
+
type: "tool_use",
|
|
1027
|
+
toolName: normalizeToolName(tool.tool),
|
|
1028
|
+
toolInput: normalizeToolInput(rawInput),
|
|
1029
|
+
agentName: messageData?.agent,
|
|
1030
|
+
model: messageData?.modelID
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
if (partData.type === "text") {
|
|
1034
|
+
const text = partData;
|
|
1035
|
+
if (text.synthetic)
|
|
1036
|
+
return null;
|
|
1037
|
+
const trimmed = text.text?.trim() ?? "";
|
|
1038
|
+
if (trimmed.length === 0 || trimmed.length >= 200)
|
|
1039
|
+
return null;
|
|
1040
|
+
return {
|
|
1041
|
+
type: "text",
|
|
1042
|
+
text: trimmed,
|
|
1043
|
+
agentName: messageData?.agent,
|
|
1044
|
+
model: messageData?.modelID
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
if (partData.type === "reasoning") {
|
|
1048
|
+
const reasoning = partData;
|
|
1049
|
+
const trimmed = reasoning.text?.trim() ?? "";
|
|
1050
|
+
return {
|
|
1051
|
+
type: "tool_use",
|
|
1052
|
+
toolName: "thinking",
|
|
1053
|
+
toolInput: trimmed.length > 0 ? { thought: trimmed.slice(0, 120) } : void 0,
|
|
1054
|
+
agentName: messageData?.agent,
|
|
1055
|
+
model: messageData?.modelID
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Emit token usage from an assistant message row.
|
|
1062
|
+
* Called once per assistant message.
|
|
1063
|
+
*/
|
|
1064
|
+
parseTokenUsage(messageData) {
|
|
1065
|
+
if (messageData.role !== "assistant")
|
|
1066
|
+
return null;
|
|
1067
|
+
const t = messageData.tokens;
|
|
1068
|
+
if (!t?.input && !t?.output)
|
|
1069
|
+
return null;
|
|
1070
|
+
return {
|
|
1071
|
+
type: "token_usage",
|
|
1072
|
+
inputTokens: t.input,
|
|
1073
|
+
outputTokens: t.output,
|
|
1074
|
+
cacheReadTokens: t.cache?.read,
|
|
1075
|
+
cacheCreationTokens: t.cache?.write,
|
|
1076
|
+
model: messageData.modelID,
|
|
1077
|
+
agentName: messageData.agent
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
var OpenCodeWatcher = class {
|
|
1082
|
+
stateManager;
|
|
1083
|
+
watcher = null;
|
|
1084
|
+
db = null;
|
|
1085
|
+
parser = new OpenCodeParser();
|
|
1086
|
+
/** Timestamp watermark for incremental polling (ms) */
|
|
1087
|
+
lastMessageTs = 0;
|
|
1088
|
+
/** Tracks time_created (not time_updated) so each part is processed exactly once */
|
|
1089
|
+
lastPartCreatedTs = 0;
|
|
1090
|
+
/** sessionId → SessionInfo cache */
|
|
1091
|
+
sessions = /* @__PURE__ */ new Map();
|
|
1092
|
+
/** messageId → parsed message data cache */
|
|
1093
|
+
messages = /* @__PURE__ */ new Map();
|
|
1094
|
+
/** callID → true — deduplicates tool_use per tool invocation */
|
|
1095
|
+
seenCallIds = /* @__PURE__ */ new Set();
|
|
1096
|
+
/** row id → true — deduplicates text/token events */
|
|
1097
|
+
seenIds = /* @__PURE__ */ new Set();
|
|
1098
|
+
// Prepared statements (initialised after DB opens)
|
|
1099
|
+
stmtAllSessions;
|
|
1100
|
+
stmtRecentSessions;
|
|
1101
|
+
stmtMessagesBySession;
|
|
1102
|
+
stmtPartsBySession;
|
|
1103
|
+
stmtNewMessages;
|
|
1104
|
+
stmtNewParts;
|
|
1105
|
+
constructor(stateManager) {
|
|
1106
|
+
this.stateManager = stateManager;
|
|
1107
|
+
}
|
|
1108
|
+
async start() {
|
|
1109
|
+
const activeThresholdMs = config.activeThresholdMs;
|
|
1110
|
+
const dbPath = getOpenCodeDbPath();
|
|
1111
|
+
if (!dbPath) {
|
|
1112
|
+
console.log("[opencode] No database found \u2014 OpenCode not installed or not yet used");
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
console.log(`[opencode] Database found at ${dbPath}`);
|
|
1116
|
+
try {
|
|
1117
|
+
this.db = new import_better_sqlite3.default(dbPath, { readonly: true, fileMustExist: true });
|
|
1118
|
+
this.prepareStatements();
|
|
1119
|
+
} catch (err) {
|
|
1120
|
+
console.error("[opencode] Failed to open database:", err);
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
this.loadAllSessions();
|
|
1124
|
+
this.replayRecentSessions(activeThresholdMs);
|
|
1125
|
+
if (this.lastMessageTs === 0)
|
|
1126
|
+
this.lastMessageTs = Date.now() - 5e3;
|
|
1127
|
+
if (this.lastPartCreatedTs === 0)
|
|
1128
|
+
this.lastPartCreatedTs = Date.now() - 5e3;
|
|
1129
|
+
const walPath = dbPath + "-wal";
|
|
1130
|
+
this.watcher = chokidar.watch(walPath, {
|
|
1131
|
+
persistent: true,
|
|
1132
|
+
ignoreInitial: true,
|
|
1133
|
+
usePolling: true,
|
|
1134
|
+
interval: 500,
|
|
1135
|
+
disableGlobbing: true
|
|
1136
|
+
});
|
|
1137
|
+
this.watcher.on("change", () => this.poll());
|
|
1138
|
+
this.watcher.on("add", () => this.poll());
|
|
1139
|
+
console.log("[opencode] Watching for new activity");
|
|
1140
|
+
}
|
|
1141
|
+
stop() {
|
|
1142
|
+
this.watcher?.close();
|
|
1143
|
+
this.db?.close();
|
|
1144
|
+
this.sessions.clear();
|
|
1145
|
+
this.messages.clear();
|
|
1146
|
+
this.seenCallIds.clear();
|
|
1147
|
+
this.seenIds.clear();
|
|
1148
|
+
}
|
|
1149
|
+
// ── Prepared statements ────────────────────────────────────────────────────
|
|
1150
|
+
prepareStatements() {
|
|
1151
|
+
const db = this.db;
|
|
1152
|
+
this.stmtAllSessions = db.prepare("SELECT id, directory, parent_id, title, project_id FROM session");
|
|
1153
|
+
this.stmtRecentSessions = db.prepare("SELECT id, directory, parent_id, title, project_id FROM session WHERE time_updated > ?");
|
|
1154
|
+
this.stmtMessagesBySession = db.prepare("SELECT id, session_id, time_updated, data FROM message WHERE session_id = ? ORDER BY time_created");
|
|
1155
|
+
this.stmtPartsBySession = db.prepare("SELECT id, message_id, session_id, time_created, time_updated, data FROM part WHERE session_id = ? ORDER BY time_created");
|
|
1156
|
+
this.stmtNewMessages = db.prepare("SELECT id, session_id, time_updated, data FROM message WHERE time_updated > ? ORDER BY time_updated");
|
|
1157
|
+
this.stmtNewParts = db.prepare("SELECT id, message_id, session_id, time_created, time_updated, data FROM part WHERE time_created > ? ORDER BY time_created");
|
|
1158
|
+
}
|
|
1159
|
+
// ── Session cache ──────────────────────────────────────────────────────────
|
|
1160
|
+
loadAllSessions() {
|
|
1161
|
+
const rows = this.stmtAllSessions.all();
|
|
1162
|
+
for (const row of rows) {
|
|
1163
|
+
this.sessions.set(row.id, parseOpenCodeSession(row));
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
// ── Startup replay ─────────────────────────────────────────────────────────
|
|
1167
|
+
replayRecentSessions(activeThresholdMs) {
|
|
1168
|
+
const cutoff = Date.now() - activeThresholdMs;
|
|
1169
|
+
const recent = this.stmtRecentSessions.all(cutoff);
|
|
1170
|
+
if (recent.length === 0)
|
|
1171
|
+
return;
|
|
1172
|
+
console.log(`[opencode] Replaying ${recent.length} recent session(s)`);
|
|
1173
|
+
for (const session of recent) {
|
|
1174
|
+
this.sessions.set(session.id, parseOpenCodeSession(session));
|
|
1175
|
+
this.replaySession(session.id);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
replaySession(sessionId) {
|
|
1179
|
+
const messages = this.stmtMessagesBySession.all(sessionId);
|
|
1180
|
+
for (const msg of messages) {
|
|
1181
|
+
this.processMessageRow(msg);
|
|
1182
|
+
if (msg.time_updated > this.lastMessageTs)
|
|
1183
|
+
this.lastMessageTs = msg.time_updated;
|
|
1184
|
+
}
|
|
1185
|
+
const parts = this.stmtPartsBySession.all(sessionId);
|
|
1186
|
+
for (const part of parts) {
|
|
1187
|
+
this.processPartRow(part);
|
|
1188
|
+
if (part.time_created > this.lastPartCreatedTs)
|
|
1189
|
+
this.lastPartCreatedTs = part.time_created;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
// ── Live polling ───────────────────────────────────────────────────────────
|
|
1193
|
+
poll() {
|
|
1194
|
+
if (!this.db)
|
|
1195
|
+
return;
|
|
1196
|
+
try {
|
|
1197
|
+
const newSessions = this.stmtRecentSessions.all(Date.now() - 6e4);
|
|
1198
|
+
for (const row of newSessions) {
|
|
1199
|
+
if (!this.sessions.has(row.id)) {
|
|
1200
|
+
this.sessions.set(row.id, parseOpenCodeSession(row));
|
|
1201
|
+
console.log(`[opencode] New session: ${row.id.slice(0, 20)} (${row.directory})`);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
const newMessages = this.stmtNewMessages.all(this.lastMessageTs);
|
|
1205
|
+
for (const msg of newMessages) {
|
|
1206
|
+
this.processMessageRow(msg);
|
|
1207
|
+
if (msg.time_updated > this.lastMessageTs)
|
|
1208
|
+
this.lastMessageTs = msg.time_updated;
|
|
1209
|
+
}
|
|
1210
|
+
const newParts = this.stmtNewParts.all(this.lastPartCreatedTs);
|
|
1211
|
+
for (const part of newParts) {
|
|
1212
|
+
this.processPartRow(part);
|
|
1213
|
+
if (part.time_created > this.lastPartCreatedTs)
|
|
1214
|
+
this.lastPartCreatedTs = part.time_created;
|
|
1215
|
+
}
|
|
1216
|
+
} catch (err) {
|
|
1217
|
+
console.error("[opencode] Poll error:", err);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
// ── Row processors ─────────────────────────────────────────────────────────
|
|
1221
|
+
processMessageRow(row) {
|
|
1222
|
+
let data;
|
|
1223
|
+
try {
|
|
1224
|
+
data = JSON.parse(row.data);
|
|
1225
|
+
} catch {
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
this.messages.set(row.id, data);
|
|
1229
|
+
const seenKey = "msg:" + row.id;
|
|
1230
|
+
if (this.seenIds.has(seenKey))
|
|
1231
|
+
return;
|
|
1232
|
+
this.seenIds.add(seenKey);
|
|
1233
|
+
const activity = this.parser.parseTokenUsage(data);
|
|
1234
|
+
if (!activity)
|
|
1235
|
+
return;
|
|
1236
|
+
const sessionInfo = this.getSessionInfo(row.session_id);
|
|
1237
|
+
this.stateManager.processMessage(this.prefixed(row.session_id), activity, sessionInfo);
|
|
1238
|
+
}
|
|
1239
|
+
processPartRow(row) {
|
|
1240
|
+
let data;
|
|
1241
|
+
try {
|
|
1242
|
+
data = JSON.parse(row.data);
|
|
1243
|
+
} catch {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const messageData = this.messages.get(row.message_id);
|
|
1247
|
+
if (data.type === "step-start" || data.type === "step-finish") {
|
|
1248
|
+
if (this.seenIds.has(row.id))
|
|
1249
|
+
return;
|
|
1250
|
+
this.seenIds.add(row.id);
|
|
1251
|
+
this.stateManager.heartbeat(this.prefixed(row.session_id));
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
if (data.type === "tool" && data.callID) {
|
|
1255
|
+
if (this.seenCallIds.has(data.callID))
|
|
1256
|
+
return;
|
|
1257
|
+
this.seenCallIds.add(data.callID);
|
|
1258
|
+
} else {
|
|
1259
|
+
if (this.seenIds.has(row.id))
|
|
1260
|
+
return;
|
|
1261
|
+
this.seenIds.add(row.id);
|
|
1262
|
+
}
|
|
1263
|
+
const activity = this.parser.parsePart(data, messageData);
|
|
1264
|
+
if (!activity)
|
|
1265
|
+
return;
|
|
1266
|
+
const sessionInfo = this.getSessionInfo(row.session_id);
|
|
1267
|
+
this.stateManager.processMessage(this.prefixed(row.session_id), activity, sessionInfo);
|
|
1268
|
+
}
|
|
1269
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
1270
|
+
getSessionInfo(sessionId) {
|
|
1271
|
+
const cached = this.sessions.get(sessionId);
|
|
1272
|
+
if (cached)
|
|
1273
|
+
return cached;
|
|
1274
|
+
this.loadAllSessions();
|
|
1275
|
+
return this.sessions.get(sessionId) ?? this.fallbackSession();
|
|
1276
|
+
}
|
|
1277
|
+
prefixed(id) {
|
|
1278
|
+
return id.startsWith("oc:") ? id : `oc:${id}`;
|
|
1279
|
+
}
|
|
1280
|
+
fallbackSession() {
|
|
1281
|
+
return {
|
|
1282
|
+
projectPath: "opencode",
|
|
1283
|
+
projectName: "opencode",
|
|
1284
|
+
isSubagent: false,
|
|
1285
|
+
projectDir: "opencode",
|
|
1286
|
+
parentSessionId: null
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
export {
|
|
1291
|
+
OpenCodeWatcher
|
|
1292
|
+
};
|