@rynx-ai/daemon 0.1.11-beta.1 → 0.1.11-beta.3

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 (148) hide show
  1. package/bundled-plugins/.rynx-plugin/marketplace.json +10 -0
  2. package/bundled-plugins/plugins/lark/.rynx-plugin/plugin.json +37 -0
  3. package/bundled-plugins/plugins/lark/dist/cli-mirror/mirror-index.d.ts +48 -0
  4. package/bundled-plugins/plugins/lark/dist/cli-mirror/mirror-index.js +54 -0
  5. package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-mirror.d.ts +85 -0
  6. package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-mirror.js +333 -0
  7. package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-watcher.d.ts +109 -0
  8. package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-watcher.js +347 -0
  9. package/bundled-plugins/plugins/lark/dist/host-adapters.d.ts +95 -0
  10. package/bundled-plugins/plugins/lark/dist/host-adapters.js +504 -0
  11. package/bundled-plugins/plugins/lark/dist/index.d.ts +7 -0
  12. package/bundled-plugins/plugins/lark/dist/index.js +7 -0
  13. package/bundled-plugins/plugins/lark/dist/lark-card-stream.d.ts +363 -0
  14. package/bundled-plugins/plugins/lark/dist/lark-card-stream.js +1335 -0
  15. package/bundled-plugins/plugins/lark/dist/lark-config-store.d.ts +30 -0
  16. package/bundled-plugins/plugins/lark/dist/lark-config-store.js +135 -0
  17. package/bundled-plugins/plugins/lark/dist/lark-content.d.ts +30 -0
  18. package/bundled-plugins/plugins/lark/dist/lark-content.js +138 -0
  19. package/bundled-plugins/plugins/lark/dist/lark-conversation-directory.d.ts +65 -0
  20. package/bundled-plugins/plugins/lark/dist/lark-conversation-directory.js +106 -0
  21. package/bundled-plugins/plugins/lark/dist/lark-diff-card.d.ts +25 -0
  22. package/bundled-plugins/plugins/lark/dist/lark-diff-card.js +58 -0
  23. package/bundled-plugins/plugins/lark/dist/lark-fork-transcript.d.ts +16 -0
  24. package/bundled-plugins/plugins/lark/dist/lark-fork-transcript.js +141 -0
  25. package/bundled-plugins/plugins/lark/dist/lark-resume-card.d.ts +31 -0
  26. package/bundled-plugins/plugins/lark/dist/lark-resume-card.js +105 -0
  27. package/bundled-plugins/plugins/lark/dist/lark-runtime-state-store.d.ts +18 -0
  28. package/bundled-plugins/plugins/lark/dist/lark-runtime-state-store.js +95 -0
  29. package/bundled-plugins/plugins/lark/dist/lark-sdk/client.d.ts +8 -0
  30. package/bundled-plugins/plugins/lark/dist/lark-sdk/client.js +32 -0
  31. package/bundled-plugins/plugins/lark/dist/lark-sdk/index.d.ts +1 -0
  32. package/bundled-plugins/plugins/lark/dist/lark-sdk/index.js +1 -0
  33. package/bundled-plugins/plugins/lark/dist/lark-sender.d.ts +114 -0
  34. package/bundled-plugins/plugins/lark/dist/lark-sender.js +323 -0
  35. package/bundled-plugins/plugins/lark/dist/lark-session-store.d.ts +13 -0
  36. package/bundled-plugins/plugins/lark/dist/lark-session-store.js +14 -0
  37. package/bundled-plugins/plugins/lark/dist/lark-settings-card.d.ts +55 -0
  38. package/bundled-plugins/plugins/lark/dist/lark-settings-card.js +158 -0
  39. package/bundled-plugins/plugins/lark/dist/lark-setup.d.ts +39 -0
  40. package/bundled-plugins/plugins/lark/dist/lark-setup.js +103 -0
  41. package/bundled-plugins/plugins/lark/dist/lark.d.ts +507 -0
  42. package/bundled-plugins/plugins/lark/dist/lark.js +1977 -0
  43. package/bundled-plugins/plugins/lark/dist/runtime.d.ts +13 -0
  44. package/bundled-plugins/plugins/lark/dist/runtime.js +131313 -0
  45. package/bundled-plugins/plugins/lark/dist/settings.d.ts +7 -0
  46. package/bundled-plugins/plugins/lark/dist/settings.js +126958 -0
  47. package/bundled-plugins/plugins/lark/package.json +57 -0
  48. package/bundled-plugins/plugins/lark/ui/assets/index-B2dhMlMU.css +1 -0
  49. package/bundled-plugins/plugins/lark/ui/assets/index-D9N-AkLX.js +201 -0
  50. package/bundled-plugins/plugins/lark/ui/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  51. package/bundled-plugins/plugins/lark/ui/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  52. package/bundled-plugins/plugins/lark/ui/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  53. package/bundled-plugins/plugins/lark/ui/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  54. package/bundled-plugins/plugins/lark/ui/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  55. package/bundled-plugins/plugins/lark/ui/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  56. package/bundled-plugins/plugins/lark/ui/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  57. package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  58. package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  59. package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  60. package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  61. package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  62. package/bundled-plugins/plugins/lark/ui/index.html +13 -0
  63. package/dist/browser-artifact-management.d.ts +4 -1
  64. package/dist/browser-artifact-management.js +18 -10
  65. package/dist/browser-artifacts.d.ts +1 -0
  66. package/dist/browser-artifacts.js +1 -0
  67. package/dist/bundled-plugins.d.ts +15 -0
  68. package/dist/bundled-plugins.js +134 -0
  69. package/dist/chrome-for-testing-runtime.d.ts +27 -0
  70. package/dist/chrome-for-testing-runtime.js +193 -0
  71. package/dist/chrome-for-testing-store.d.ts +2 -0
  72. package/dist/chrome-for-testing-store.js +9 -0
  73. package/dist/control-deps.js +2 -79
  74. package/dist/daemon-server.d.ts +7 -1
  75. package/dist/daemon-server.js +299 -84
  76. package/dist/db.js +147 -124
  77. package/dist/entry-path.d.ts +3 -0
  78. package/dist/entry-path.js +12 -0
  79. package/dist/index-daemon.js +3 -66
  80. package/dist/lifecycle.d.ts +12 -0
  81. package/dist/lifecycle.js +16 -0
  82. package/dist/maintenance-lease.d.ts +39 -0
  83. package/dist/maintenance-lease.js +250 -0
  84. package/dist/migrations/cleanup-legacy-sessions.d.ts +1 -1
  85. package/dist/migrations/cleanup-legacy-sessions.js +33 -15
  86. package/dist/official-plugins.d.ts +2 -0
  87. package/dist/official-plugins.js +2 -0
  88. package/dist/plugin-cli.d.ts +1 -3
  89. package/dist/plugin-cli.js +56 -45
  90. package/dist/plugin-host-leases.d.ts +4 -0
  91. package/dist/plugin-host-leases.js +7 -0
  92. package/dist/plugin-host-rpc.d.ts +60 -4
  93. package/dist/plugin-host-rpc.js +300 -50
  94. package/dist/plugin-installer.d.ts +24 -55
  95. package/dist/plugin-installer.js +258 -412
  96. package/dist/plugin-management-service.d.ts +30 -23
  97. package/dist/plugin-management-service.js +290 -105
  98. package/dist/plugin-marketplace.d.ts +35 -0
  99. package/dist/plugin-marketplace.js +299 -0
  100. package/dist/plugin-package.d.ts +22 -24
  101. package/dist/plugin-package.js +520 -571
  102. package/dist/plugin-skill-context.d.ts +4 -0
  103. package/dist/plugin-skill-context.js +35 -0
  104. package/dist/plugin-store.d.ts +36 -37
  105. package/dist/plugin-store.js +140 -92
  106. package/dist/plugin-supervisor.d.ts +50 -125
  107. package/dist/plugin-supervisor.js +682 -1030
  108. package/dist/pm2.d.ts +11 -2
  109. package/dist/pm2.js +130 -28
  110. package/dist/process.d.ts +12 -0
  111. package/dist/process.js +91 -0
  112. package/dist/runtime-project-store.d.ts +9 -0
  113. package/dist/runtime-project-store.js +83 -0
  114. package/dist/session-fallback-workspace.d.ts +22 -0
  115. package/dist/session-fallback-workspace.js +120 -0
  116. package/dist/session-fork-store.d.ts +41 -0
  117. package/dist/session-fork-store.js +288 -0
  118. package/dist/session-launch-operations.d.ts +23 -2
  119. package/dist/session-launch-operations.js +48 -7
  120. package/dist/session-meta-store.d.ts +7 -9
  121. package/dist/session-meta-store.js +28 -49
  122. package/dist/setup-service.d.ts +20 -0
  123. package/dist/setup-service.js +38 -0
  124. package/package.json +36 -20
  125. package/dist/browser-cli-args.d.ts +0 -20
  126. package/dist/browser-cli-args.js +0 -100
  127. package/dist/channel-store.d.ts +0 -22
  128. package/dist/channel-store.js +0 -65
  129. package/dist/cli.d.ts +0 -2
  130. package/dist/cli.js +0 -732
  131. package/dist/control-client.d.ts +0 -122
  132. package/dist/control-client.js +0 -855
  133. package/dist/control-endpoint.d.ts +0 -14
  134. package/dist/control-endpoint.js +0 -124
  135. package/dist/desktop-browser-host-client.d.ts +0 -35
  136. package/dist/desktop-browser-host-client.js +0 -415
  137. package/dist/instance-store.d.ts +0 -38
  138. package/dist/instance-store.js +0 -85
  139. package/dist/plugin-install-restart.d.ts +0 -13
  140. package/dist/plugin-install-restart.js +0 -24
  141. package/dist/plugin-runtime-control.d.ts +0 -2
  142. package/dist/plugin-runtime-control.js +0 -37
  143. package/dist/registry.d.ts +0 -10
  144. package/dist/registry.js +0 -52
  145. package/dist/setup.d.ts +0 -20
  146. package/dist/setup.js +0 -374
  147. package/dist/update.d.ts +0 -25
  148. package/dist/update.js +0 -133
package/dist/db.js CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * `~/.rynx/rynx.db` — the daemon's SQLite store. Concerns kept apart:
3
- * - `channels` — a chat type + its plugin-owned config/credentials.
4
- * - `instances` — a runnable binding: a chat channel + an agent (1:1 with a channel,
5
- * enforced by a UNIQUE channel_id). This is what the daemon mounts.
6
- * - `plugins` — static manifests, grants and immutable install locations.
3
+ * - `plugin_installations` — source-qualified manifests, capabilities, and immutable packages.
4
+ * - `plugin_marketplaces` — catalog registrations; catalog data is never executable.
7
5
  * - `plugin_session_launch_operations` — durable idempotency/tombstones.
8
6
  * - `control_links` — generic, one-use links to the local session console.
9
7
  * - `runtime_pairing_claims` / `runtime_client_grants` — one-use enrollment
@@ -16,15 +14,18 @@
16
14
  * Connections are cached per resolved path so tests can point `RYNX_DB` /
17
15
  * `RYNX_HOME` at a temp dir. Override with `RYNX_DB` (full path) or `RYNX_HOME`.
18
16
  */
19
- import { randomUUID } from "node:crypto";
20
- import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync } from "node:fs";
21
- import { homedir } from "node:os";
22
- import { dirname, join } from "node:path";
17
+ import { chmodSync, mkdirSync } from "node:fs";
18
+ import { dirname, isAbsolute, join, resolve } from "node:path";
19
+ import { rynxHome } from "@rynx-ai/core";
23
20
  import Database from "better-sqlite3";
24
21
  const connections = new Map();
25
22
  /** Absolute path to the SQLite file (override via `RYNX_DB`, else `~/.rynx/rynx.db`). */
26
23
  export function dbPath() {
27
- return process.env.RYNX_DB?.trim() || join(daemonHome(), "rynx.db");
24
+ const configured = process.env.RYNX_DB?.trim();
25
+ if (configured && !isAbsolute(configured)) {
26
+ throw new Error("RYNX_DB must be an absolute path");
27
+ }
28
+ return configured ? resolve(configured) : join(rynxHome(), "rynx.db");
28
29
  }
29
30
  /** Open (or reuse) the database at the current path, migrating + importing on first open. */
30
31
  export function db() {
@@ -37,7 +38,7 @@ export function db() {
37
38
  conn.pragma("busy_timeout = 5000");
38
39
  conn.pragma("foreign_keys = ON");
39
40
  migrate(conn);
40
- // The store may hold channel secrets (e.g. LARK_APP_SECRET) — keep it private.
41
+ // Plugin state and daemon credentials are private.
41
42
  try {
42
43
  chmodSync(path, 0o600);
43
44
  }
@@ -49,34 +50,46 @@ export function db() {
49
50
  }
50
51
  function migrate(conn) {
51
52
  conn.exec(`
52
- CREATE TABLE IF NOT EXISTS plugins (
53
- name TEXT PRIMARY KEY,
54
- spec TEXT NOT NULL,
55
- source TEXT NOT NULL,
56
- version TEXT,
57
- enabled INTEGER NOT NULL DEFAULT 1,
58
- installed_at TEXT NOT NULL,
59
- updated_at TEXT,
60
- install_path TEXT,
61
- manifest TEXT,
62
- integrity TEXT,
63
- grants TEXT
53
+ CREATE TABLE IF NOT EXISTS plugin_marketplaces (
54
+ marketplace_id TEXT PRIMARY KEY,
55
+ source_type TEXT NOT NULL CHECK(source_type IN ('git', 'local')),
56
+ requested_source TEXT NOT NULL,
57
+ resolved_revision TEXT NOT NULL,
58
+ source_fingerprint TEXT NOT NULL,
59
+ built_in INTEGER NOT NULL DEFAULT 0,
60
+ catalog TEXT NOT NULL,
61
+ created_at TEXT NOT NULL,
62
+ refreshed_at TEXT NOT NULL
64
63
  );
65
- CREATE TABLE IF NOT EXISTS channels (
66
- id TEXT PRIMARY KEY,
67
- name TEXT NOT NULL UNIQUE,
68
- type TEXT NOT NULL,
69
- options TEXT,
70
- created_at TEXT NOT NULL,
71
- updated_at TEXT NOT NULL
64
+ CREATE TABLE IF NOT EXISTS plugin_marketplace_bindings (
65
+ marketplace_id TEXT PRIMARY KEY,
66
+ source_fingerprint TEXT NOT NULL,
67
+ created_at TEXT NOT NULL
72
68
  );
73
- CREATE TABLE IF NOT EXISTS instances (
74
- id TEXT PRIMARY KEY,
75
- channel_id TEXT NOT NULL UNIQUE REFERENCES channels(id) ON DELETE CASCADE,
76
- agent TEXT,
77
- enabled INTEGER NOT NULL DEFAULT 1,
78
- created_at TEXT NOT NULL,
79
- updated_at TEXT NOT NULL
69
+ INSERT OR IGNORE INTO plugin_marketplace_bindings (
70
+ marketplace_id, source_fingerprint, created_at
71
+ )
72
+ SELECT marketplace_id, source_fingerprint, created_at
73
+ FROM plugin_marketplaces;
74
+ CREATE TABLE IF NOT EXISTS plugin_installations (
75
+ canonical_id TEXT PRIMARY KEY,
76
+ marketplace_id TEXT NOT NULL,
77
+ plugin_id TEXT NOT NULL,
78
+ source_type TEXT NOT NULL CHECK(source_type IN ('git', 'local')),
79
+ requested_source TEXT NOT NULL,
80
+ resolved_revision TEXT NOT NULL,
81
+ source_fingerprint TEXT NOT NULL,
82
+ version TEXT NOT NULL,
83
+ enabled INTEGER NOT NULL DEFAULT 1,
84
+ installed_at TEXT NOT NULL,
85
+ updated_at TEXT NOT NULL,
86
+ install_path TEXT NOT NULL,
87
+ manifest TEXT NOT NULL,
88
+ integrity TEXT NOT NULL,
89
+ capabilities TEXT NOT NULL,
90
+ runtime_state TEXT,
91
+ runtime_error TEXT,
92
+ UNIQUE(marketplace_id, plugin_id)
80
93
  );
81
94
  CREATE TABLE IF NOT EXISTS session_items (
82
95
  id TEXT PRIMARY KEY,
@@ -142,16 +155,25 @@ function migrate(conn) {
142
155
  ON DELETE CASCADE
143
156
  );
144
157
  CREATE TABLE IF NOT EXISTS sessions (
158
+ id TEXT PRIMARY KEY,
159
+ workspace TEXT NOT NULL,
160
+ execution TEXT NOT NULL,
161
+ title TEXT,
162
+ forked_from_session_id TEXT,
163
+ source TEXT NOT NULL,
164
+ created_at TEXT NOT NULL,
165
+ updated_at TEXT
166
+ );
167
+ CREATE TABLE IF NOT EXISTS session_snapshot_cleanup (
168
+ session_id TEXT PRIMARY KEY
169
+ );
170
+ CREATE TABLE IF NOT EXISTS runtime_projects (
145
171
  id TEXT PRIMARY KEY,
146
- provider TEXT,
147
- agent TEXT,
148
- config TEXT,
149
- model TEXT,
150
- reasoning_effort TEXT,
151
- title TEXT,
152
- source TEXT,
172
+ name TEXT NOT NULL,
173
+ directories_json TEXT NOT NULL,
174
+ primary_dir TEXT NOT NULL,
153
175
  created_at TEXT NOT NULL,
154
- updated_at TEXT
176
+ updated_at TEXT NOT NULL
155
177
  );
156
178
  CREATE TABLE IF NOT EXISTS session_pending_messages (
157
179
  session_id TEXT PRIMARY KEY REFERENCES sessions(id) ON DELETE CASCADE,
@@ -173,6 +195,7 @@ function migrate(conn) {
173
195
  scope_id TEXT NOT NULL,
174
196
  operation_id TEXT NOT NULL,
175
197
  request_hash TEXT NOT NULL,
198
+ raw_request_hash TEXT,
176
199
  session_id TEXT NOT NULL,
177
200
  state TEXT NOT NULL DEFAULT 'active' CHECK(state IN ('active', 'deleted')),
178
201
  created_at TEXT NOT NULL,
@@ -187,6 +210,31 @@ function migrate(conn) {
187
210
  );
188
211
  CREATE INDEX IF NOT EXISTS idx_plugin_session_launch_operations_session
189
212
  ON plugin_session_launch_operations(session_id);
213
+ CREATE TABLE IF NOT EXISTS session_fork_operations (
214
+ operation_id TEXT PRIMARY KEY,
215
+ request_hash TEXT NOT NULL,
216
+ source_session_id TEXT NOT NULL,
217
+ target_session_id TEXT NOT NULL UNIQUE,
218
+ title TEXT,
219
+ fork_position INTEGER,
220
+ state TEXT NOT NULL DEFAULT 'reserved'
221
+ CHECK(state IN ('reserved', 'completed', 'target_deleted')),
222
+ error TEXT,
223
+ created_at TEXT NOT NULL,
224
+ updated_at TEXT NOT NULL,
225
+ completed_at TEXT,
226
+ deleted_at TEXT,
227
+ CHECK(
228
+ (state = 'reserved' AND completed_at IS NULL AND deleted_at IS NULL)
229
+ OR (state = 'completed' AND completed_at IS NOT NULL AND deleted_at IS NULL)
230
+ OR (state = 'target_deleted' AND deleted_at IS NOT NULL)
231
+ )
232
+ );
233
+ CREATE INDEX IF NOT EXISTS idx_session_fork_operations_source
234
+ ON session_fork_operations(source_session_id, state);
235
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_session_fork_operations_reserved_source
236
+ ON session_fork_operations(source_session_id)
237
+ WHERE state = 'reserved';
190
238
  CREATE TABLE IF NOT EXISTS control_links (
191
239
  token TEXT PRIMARY KEY,
192
240
  plugin_id TEXT NOT NULL,
@@ -260,97 +308,72 @@ function migrate(conn) {
260
308
  CREATE INDEX IF NOT EXISTS idx_runtime_pending_enrollments_expires
261
309
  ON runtime_pending_enrollments(expires_at);
262
310
  `);
311
+ migratePluginCapabilities(conn);
312
+ migrateSessionSnapshots(conn);
263
313
  // Breaking plugin-runtime cutover: remove obsolete core-owned state.
264
314
  conn.exec(`
265
315
  DROP TABLE IF EXISTS control_sessions;
266
316
  DROP TABLE IF EXISTS plugin_daemon_worker_settings;
267
317
  `);
268
- // `sessions` is the unified machine-session record (console + every channel).
269
- // Add the identity columns to a pre-existing table (SQLite has no
270
- // ADD COLUMN IF NOT EXISTS) and backfill the origin of rows written before
271
- // this change — they were all console sessions.
272
- addColumnIfMissing(conn, "sessions", "source", "TEXT");
273
- addColumnIfMissing(conn, "sessions", "updated_at", "TEXT");
274
- addColumnIfMissing(conn, "sessions", "provider", "TEXT");
275
- const sessionColumns = conn.prepare("PRAGMA table_info(sessions)").all();
276
- if (sessionColumns.some((column) => column.name === "executor")) {
277
- conn.exec("UPDATE sessions SET provider = executor WHERE provider IS NULL AND executor IS NOT NULL");
278
- }
279
- addColumnIfMissing(conn, "plugins", "updated_at", "TEXT");
280
- addColumnIfMissing(conn, "plugins", "install_path", "TEXT");
281
- addColumnIfMissing(conn, "plugins", "manifest", "TEXT");
282
- addColumnIfMissing(conn, "plugins", "integrity", "TEXT");
283
- addColumnIfMissing(conn, "plugins", "grants", "TEXT");
284
- conn.exec("UPDATE sessions SET source = 'console' WHERE source IS NULL");
285
- conn.exec("UPDATE plugins SET updated_at = installed_at WHERE updated_at IS NULL");
286
- importLegacyConfig(conn);
287
- }
288
- /** Idempotently add a column to an existing table (no-op if already present). */
289
- function addColumnIfMissing(conn, table, column, ddl) {
290
- const cols = conn.prepare(`PRAGMA table_info(${table})`).all();
291
- if (cols.some((c) => c.name === column))
292
- return;
293
- conn.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${ddl}`);
318
+ addColumnIfMissing(conn, "plugin_marketplaces", "built_in", "INTEGER NOT NULL DEFAULT 0");
319
+ addColumnIfMissing(conn, "sessions", "forked_from_session_id", "TEXT");
320
+ addColumnIfMissing(conn, "plugin_session_launch_operations", "raw_request_hash", "TEXT");
294
321
  }
295
322
  /**
296
- * One-time import of a pre-existing `~/.rynx/config.json` (the old hand-edited
297
- * format, where each entry mixed channel config + agent binding). Each entry
298
- * becomes a `channels` row (the config) plus an `instances` row (the binding).
299
- * The instance keeps the entry's key as its `id` so per-instance on-disk state
300
- * (keyed by instanceId) stays intact. Runs only when empty; the file is renamed
301
- * afterwards so it's never read — or hand-edited — again.
323
+ * Breaking Session cutover: the previous rows contain mutable Agent/Provider
324
+ * references and no immutable workspace/execution snapshots, so they cannot be
325
+ * migrated faithfully. Remove every database-owned Session artifact and create
326
+ * the new snapshot-only table. User workspace directories are never touched.
302
327
  */
303
- function importLegacyConfig(conn) {
304
- const { n } = conn.prepare("SELECT COUNT(*) AS n FROM channels").get();
305
- if (n > 0)
328
+ function migrateSessionSnapshots(conn) {
329
+ const columns = conn.prepare("PRAGMA table_info(sessions)").all();
330
+ const names = new Set(columns.map((column) => column.name));
331
+ if (names.has("workspace") && names.has("execution"))
306
332
  return;
307
- const legacy = process.env.RYNX_CONFIG?.trim() || join(daemonHome(), "config.json");
308
- if (!existsSync(legacy))
333
+ conn.transaction(() => {
334
+ conn.exec(`
335
+ INSERT OR IGNORE INTO session_snapshot_cleanup (session_id)
336
+ SELECT id FROM sessions;
337
+ DELETE FROM session_message_operation_resources;
338
+ DELETE FROM session_message_operations;
339
+ DELETE FROM session_resources;
340
+ DELETE FROM session_items;
341
+ DELETE FROM session_pending_messages;
342
+ DELETE FROM session_emulator_bindings;
343
+ DELETE FROM plugin_session_launch_operations;
344
+ DELETE FROM session_fork_operations;
345
+ DELETE FROM control_links;
346
+ DELETE FROM sessions;
347
+ DROP TABLE sessions;
348
+ CREATE TABLE sessions (
349
+ id TEXT PRIMARY KEY,
350
+ workspace TEXT NOT NULL,
351
+ execution TEXT NOT NULL,
352
+ title TEXT,
353
+ forked_from_session_id TEXT,
354
+ source TEXT NOT NULL,
355
+ created_at TEXT NOT NULL,
356
+ updated_at TEXT
357
+ );
358
+ `);
359
+ }).immediate();
360
+ }
361
+ function migratePluginCapabilities(conn) {
362
+ const columns = conn
363
+ .prepare("PRAGMA table_info(plugin_installations)")
364
+ .all();
365
+ if (columns.some((column) => column.name === "capabilities"))
309
366
  return;
310
- let channels;
311
- try {
312
- const parsed = JSON.parse(readFileSync(legacy, "utf8"));
313
- if (parsed.channels && typeof parsed.channels === "object") {
314
- channels = parsed.channels;
315
- }
316
- }
317
- catch {
318
- return; // malformed legacy file — leave it alone, start empty
319
- }
320
- if (!channels)
367
+ if (columns.some((column) => column.name === "grants")) {
368
+ conn.exec("ALTER TABLE plugin_installations RENAME COLUMN grants TO capabilities");
321
369
  return;
322
- const now = new Date().toISOString();
323
- const insertChannel = conn.prepare(`INSERT OR IGNORE INTO channels (id, name, type, options, created_at, updated_at)
324
- VALUES (@id, @name, @type, @options, @now, @now)`);
325
- const insertInstance = conn.prepare(`INSERT OR IGNORE INTO instances (id, channel_id, agent, enabled, created_at, updated_at)
326
- VALUES (@id, @channelId, @agent, @enabled, @now, @now)`);
327
- const tx = conn.transaction(() => {
328
- for (const [key, entry] of Object.entries(channels)) {
329
- const channelId = randomUUID();
330
- insertChannel.run({
331
- id: channelId,
332
- name: key,
333
- type: entry.type ?? key,
334
- options: entry.options ? JSON.stringify(entry.options) : null,
335
- now,
336
- });
337
- insertInstance.run({
338
- id: key, // preserve the old key as the runtime instanceId
339
- channelId,
340
- agent: entry.agent ?? null,
341
- enabled: entry.enabled === false ? 0 : 1,
342
- now,
343
- });
344
- }
345
- });
346
- tx();
347
- try {
348
- renameSync(legacy, `${legacy}.imported`);
349
- }
350
- catch {
351
- /* leave the source in place if it can't be renamed */
352
370
  }
371
+ conn.exec("ALTER TABLE plugin_installations ADD COLUMN capabilities TEXT NOT NULL DEFAULT '[]'");
353
372
  }
354
- function daemonHome() {
355
- return process.env.RYNX_HOME?.trim() || join(homedir(), ".rynx");
373
+ /** Idempotently add a column to an existing table (no-op if already present). */
374
+ function addColumnIfMissing(conn, table, column, ddl) {
375
+ const cols = conn.prepare(`PRAGMA table_info(${table})`).all();
376
+ if (cols.some((c) => c.name === column))
377
+ return;
378
+ conn.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${ddl}`);
356
379
  }
@@ -0,0 +1,3 @@
1
+ /** Resolve the executable daemon module without importing its side-effectful entry. */
2
+ export declare function resolveDaemonEntry(moduleUrl?: string): string;
3
+ export declare function installedDaemonVersion(): string;
@@ -0,0 +1,12 @@
1
+ import { createRequire } from "node:module";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ const require = createRequire(import.meta.url);
5
+ /** Resolve the executable daemon module without importing its side-effectful entry. */
6
+ export function resolveDaemonEntry(moduleUrl = import.meta.url) {
7
+ return join(dirname(fileURLToPath(moduleUrl)), "index-daemon.js");
8
+ }
9
+ export function installedDaemonVersion() {
10
+ const manifest = require("../package.json");
11
+ return typeof manifest.version === "string" ? manifest.version : "0.0.0";
12
+ }
@@ -1,70 +1,7 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * The resident daemon entry — this is what pm2 keeps alive.
4
- *
5
- * Boot order matters: install the EPIPE guard first (we're a pm2 child).
6
- * The composition root reads static plugin manifests, projects chat instances
7
- * onto remote runner handles, and supervises non-chat plugin workers. Installed
8
- * plugin code is loaded only in child processes.
9
- */
10
- import { startRynxDaemonServer } from "./daemon-server.js";
11
- import { installStdioEpipeGuard } from "./stdio-epipe-guard.js";
12
- installStdioEpipeGuard();
13
- async function main() {
14
- const followsApp = process.env.RYNX_DAEMON_LIFECYCLE === "follow-app";
15
- let parentDisconnected = followsApp && !process.connected;
16
- const recordParentDisconnect = () => {
17
- parentDisconnected = true;
18
- };
19
- if (followsApp)
20
- process.once("disconnect", recordParentDisconnect);
21
- let server;
22
- try {
23
- server = await startRynxDaemonServer();
24
- }
25
- catch (error) {
26
- process.off("disconnect", recordParentDisconnect);
27
- throw error;
28
- }
29
- let shutdownPromise;
30
- const shutdown = (signal) => {
31
- if (shutdownPromise)
32
- return shutdownPromise;
33
- process.off("SIGINT", onSigint);
34
- process.off("SIGTERM", onSigterm);
35
- process.off("disconnect", onDisconnect);
36
- shutdownPromise = (async () => {
37
- console.log(JSON.stringify({ level: "info", type: "shutdown", signal }));
38
- await server.shutdown();
39
- })();
40
- shutdownPromise.catch((error) => {
41
- process.exitCode = 1;
42
- console.error(`Shutdown failed: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}`);
43
- });
44
- return shutdownPromise;
45
- };
46
- const onSigint = () => {
47
- void shutdown("SIGINT");
48
- };
49
- const onSigterm = () => {
50
- void shutdown("SIGTERM");
51
- };
52
- const onDisconnect = () => {
53
- if (process.env.RYNX_DAEMON_LIFECYCLE === "follow-app") {
54
- void shutdown("APP_DISCONNECT");
55
- }
56
- };
57
- process.once("SIGINT", onSigint);
58
- process.once("SIGTERM", onSigterm);
59
- if (followsApp) {
60
- process.once("disconnect", onDisconnect);
61
- process.off("disconnect", recordParentDisconnect);
62
- if (parentDisconnected || !process.connected) {
63
- void shutdown("APP_DISCONNECT");
64
- }
65
- }
66
- }
67
- main().catch((err) => {
2
+ /** Direct daemon executable retained only for standalone PM2 supervision. */
3
+ import { runDaemonProcess } from "./process.js";
4
+ runDaemonProcess().catch((err) => {
68
5
  console.error(`Fatal error: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}`);
69
6
  process.exit(1);
70
7
  });
@@ -0,0 +1,12 @@
1
+ export { formatControlUrl, isPm2DaemonOnline, statusDaemon, stopDaemon, streamLogs, } from "./pm2.js";
2
+ export { resolveDaemonEntry } from "./entry-path.js";
3
+ export interface StandaloneDaemonLaunchContext {
4
+ builtinSkillsDir: string;
5
+ cliVersion: string;
6
+ productVersion: string;
7
+ }
8
+ export declare function startDaemon(options: {
9
+ force: boolean;
10
+ quiet?: boolean;
11
+ context: StandaloneDaemonLaunchContext;
12
+ }): number;
@@ -0,0 +1,16 @@
1
+ import { startDaemon as startPm2Daemon, } from "./pm2.js";
2
+ export { formatControlUrl, isPm2DaemonOnline, statusDaemon, stopDaemon, streamLogs, } from "./pm2.js";
3
+ export { resolveDaemonEntry } from "./entry-path.js";
4
+ export function startDaemon(options) {
5
+ return startPm2Daemon({
6
+ force: options.force,
7
+ quiet: options.quiet,
8
+ launchEnvironment: {
9
+ RYNX_BUILTIN_SKILLS_DIR: options.context.builtinSkillsDir,
10
+ RYNX_CLI_VERSION: options.context.cliVersion,
11
+ RYNX_DISTRIBUTION: "standalone",
12
+ RYNX_PRODUCT_VERSION: options.context.productVersion,
13
+ RYNX_DAEMON_LIFECYCLE: "standalone",
14
+ },
15
+ });
16
+ }
@@ -0,0 +1,39 @@
1
+ export type MaintenanceLeaseReleaseOutcome = "released" | "not_active" | "denied";
2
+ export interface MaintenanceLeaseStoreOptions {
3
+ filePath?: string;
4
+ now?: () => number;
5
+ ttlMs?: number;
6
+ /** Test seam; production fsyncs the lease directory after rename/remove. */
7
+ syncDirectory?: (directory: string) => void;
8
+ /** Process-local recovery hook, invoked once when a live lease is observed expired. */
9
+ onExpired?: () => void;
10
+ }
11
+ export declare function maintenanceLeaseFile(env?: NodeJS.ProcessEnv): string;
12
+ /**
13
+ * Cross-process admission fence used only during daemon replacement.
14
+ *
15
+ * The raw bearer token is never persisted. The bounded expiry means a crashed
16
+ * upgrader cannot leave the daemon permanently unavailable, while atomic rename
17
+ * ensures a replacement daemon sees either the complete lease or no lease.
18
+ */
19
+ export declare class MaintenanceLeaseStore {
20
+ private readonly filePath;
21
+ private readonly now;
22
+ private readonly ttlMs;
23
+ private readonly syncDirectory;
24
+ private readonly onExpired;
25
+ private lease;
26
+ private expiryTimer;
27
+ constructor(options?: MaintenanceLeaseStoreOptions);
28
+ isActive(): boolean;
29
+ isHeldBy(token: string): boolean;
30
+ acquire(token: string): boolean;
31
+ release(token: string): MaintenanceLeaseReleaseOutcome;
32
+ private readPersistedLease;
33
+ private writePersistedLease;
34
+ private clear;
35
+ private clearFile;
36
+ private expire;
37
+ private scheduleExpiry;
38
+ private cancelExpiry;
39
+ }