@cluesmith/codev 3.2.1 → 3.2.2

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 (146) hide show
  1. package/dashboard-dist/assets/{index-DM7OU-EI.js → index-BZ1x7x1X.js} +34 -34
  2. package/dashboard-dist/assets/index-BZ1x7x1X.js.map +1 -0
  3. package/dashboard-dist/index.html +1 -1
  4. package/dist/agent-farm/cli.d.ts.map +1 -1
  5. package/dist/agent-farm/cli.js +17 -0
  6. package/dist/agent-farm/cli.js.map +1 -1
  7. package/dist/agent-farm/commands/architect.d.ts.map +1 -1
  8. package/dist/agent-farm/commands/architect.js +6 -17
  9. package/dist/agent-farm/commands/architect.js.map +1 -1
  10. package/dist/agent-farm/commands/cleanup.js +3 -2
  11. package/dist/agent-farm/commands/cleanup.js.map +1 -1
  12. package/dist/agent-farm/commands/db.d.ts +10 -0
  13. package/dist/agent-farm/commands/db.d.ts.map +1 -1
  14. package/dist/agent-farm/commands/db.js +77 -0
  15. package/dist/agent-farm/commands/db.js.map +1 -1
  16. package/dist/agent-farm/commands/send.d.ts +40 -12
  17. package/dist/agent-farm/commands/send.d.ts.map +1 -1
  18. package/dist/agent-farm/commands/send.js +101 -34
  19. package/dist/agent-farm/commands/send.js.map +1 -1
  20. package/dist/agent-farm/commands/spawn-worktree.d.ts +12 -7
  21. package/dist/agent-farm/commands/spawn-worktree.d.ts.map +1 -1
  22. package/dist/agent-farm/commands/spawn-worktree.js +40 -19
  23. package/dist/agent-farm/commands/spawn-worktree.js.map +1 -1
  24. package/dist/agent-farm/commands/spawn.d.ts +15 -6
  25. package/dist/agent-farm/commands/spawn.d.ts.map +1 -1
  26. package/dist/agent-farm/commands/spawn.js +24 -17
  27. package/dist/agent-farm/commands/spawn.js.map +1 -1
  28. package/dist/agent-farm/commands/stop.js +2 -2
  29. package/dist/agent-farm/commands/stop.js.map +1 -1
  30. package/dist/agent-farm/commands/tower.d.ts +1 -0
  31. package/dist/agent-farm/commands/tower.d.ts.map +1 -1
  32. package/dist/agent-farm/commands/tower.js +50 -0
  33. package/dist/agent-farm/commands/tower.js.map +1 -1
  34. package/dist/agent-farm/db/consolidate.d.ts +66 -0
  35. package/dist/agent-farm/db/consolidate.d.ts.map +1 -0
  36. package/dist/agent-farm/db/consolidate.js +406 -0
  37. package/dist/agent-farm/db/consolidate.js.map +1 -0
  38. package/dist/agent-farm/db/index.d.ts +13 -4
  39. package/dist/agent-farm/db/index.d.ts.map +1 -1
  40. package/dist/agent-farm/db/index.js +100 -470
  41. package/dist/agent-farm/db/index.js.map +1 -1
  42. package/dist/agent-farm/db/schema.d.ts +11 -4
  43. package/dist/agent-farm/db/schema.d.ts.map +1 -1
  44. package/dist/agent-farm/db/schema.js +91 -2
  45. package/dist/agent-farm/db/schema.js.map +1 -1
  46. package/dist/agent-farm/db/types.d.ts +2 -0
  47. package/dist/agent-farm/db/types.d.ts.map +1 -1
  48. package/dist/agent-farm/db/types.js +1 -0
  49. package/dist/agent-farm/db/types.js.map +1 -1
  50. package/dist/agent-farm/lib/builder-lookup.d.ts.map +1 -1
  51. package/dist/agent-farm/lib/builder-lookup.js +9 -3
  52. package/dist/agent-farm/lib/builder-lookup.js.map +1 -1
  53. package/dist/agent-farm/servers/codev-config-watcher.d.ts +37 -0
  54. package/dist/agent-farm/servers/codev-config-watcher.d.ts.map +1 -0
  55. package/dist/agent-farm/servers/{worktree-config-watcher.js → codev-config-watcher.js} +15 -14
  56. package/dist/agent-farm/servers/codev-config-watcher.js.map +1 -0
  57. package/dist/agent-farm/servers/command-relay.d.ts +54 -0
  58. package/dist/agent-farm/servers/command-relay.d.ts.map +1 -0
  59. package/dist/agent-farm/servers/command-relay.js +94 -0
  60. package/dist/agent-farm/servers/command-relay.js.map +1 -0
  61. package/dist/agent-farm/servers/overview.d.ts.map +1 -1
  62. package/dist/agent-farm/servers/overview.js +12 -6
  63. package/dist/agent-farm/servers/overview.js.map +1 -1
  64. package/dist/agent-farm/servers/tower-instances.d.ts.map +1 -1
  65. package/dist/agent-farm/servers/tower-instances.js +65 -55
  66. package/dist/agent-farm/servers/tower-instances.js.map +1 -1
  67. package/dist/agent-farm/servers/tower-messages.d.ts +9 -0
  68. package/dist/agent-farm/servers/tower-messages.d.ts.map +1 -1
  69. package/dist/agent-farm/servers/tower-messages.js +24 -0
  70. package/dist/agent-farm/servers/tower-messages.js.map +1 -1
  71. package/dist/agent-farm/servers/tower-routes.d.ts +1 -1
  72. package/dist/agent-farm/servers/tower-routes.d.ts.map +1 -1
  73. package/dist/agent-farm/servers/tower-routes.js +111 -35
  74. package/dist/agent-farm/servers/tower-routes.js.map +1 -1
  75. package/dist/agent-farm/servers/tower-server.js +41 -27
  76. package/dist/agent-farm/servers/tower-server.js.map +1 -1
  77. package/dist/agent-farm/servers/tower-terminals.d.ts.map +1 -1
  78. package/dist/agent-farm/servers/tower-terminals.js +22 -5
  79. package/dist/agent-farm/servers/tower-terminals.js.map +1 -1
  80. package/dist/agent-farm/servers/tower-types.d.ts +2 -0
  81. package/dist/agent-farm/servers/tower-types.d.ts.map +1 -1
  82. package/dist/agent-farm/servers/tower-utils.d.ts +50 -5
  83. package/dist/agent-farm/servers/tower-utils.d.ts.map +1 -1
  84. package/dist/agent-farm/servers/tower-utils.js +64 -14
  85. package/dist/agent-farm/servers/tower-utils.js.map +1 -1
  86. package/dist/agent-farm/state.d.ts +34 -21
  87. package/dist/agent-farm/state.d.ts.map +1 -1
  88. package/dist/agent-farm/state.js +125 -79
  89. package/dist/agent-farm/state.js.map +1 -1
  90. package/dist/agent-farm/types.d.ts +14 -0
  91. package/dist/agent-farm/types.d.ts.map +1 -1
  92. package/dist/agent-farm/utils/config.d.ts +24 -1
  93. package/dist/agent-farm/utils/config.d.ts.map +1 -1
  94. package/dist/agent-farm/utils/config.js +59 -3
  95. package/dist/agent-farm/utils/config.js.map +1 -1
  96. package/dist/agent-farm/utils/harness.d.ts +45 -2
  97. package/dist/agent-farm/utils/harness.d.ts.map +1 -1
  98. package/dist/agent-farm/utils/harness.js +21 -0
  99. package/dist/agent-farm/utils/harness.js.map +1 -1
  100. package/dist/agent-farm/utils/workspace-path.d.ts +16 -0
  101. package/dist/agent-farm/utils/workspace-path.d.ts.map +1 -0
  102. package/dist/agent-farm/utils/workspace-path.js +26 -0
  103. package/dist/agent-farm/utils/workspace-path.js.map +1 -0
  104. package/dist/agent-farm/utils/worktree-write-guard.d.ts +56 -0
  105. package/dist/agent-farm/utils/worktree-write-guard.d.ts.map +1 -0
  106. package/dist/agent-farm/utils/worktree-write-guard.js +222 -0
  107. package/dist/agent-farm/utils/worktree-write-guard.js.map +1 -0
  108. package/dist/cli.d.ts.map +1 -1
  109. package/dist/cli.js +2 -0
  110. package/dist/cli.js.map +1 -1
  111. package/dist/commands/consult/index.d.ts +50 -2
  112. package/dist/commands/consult/index.d.ts.map +1 -1
  113. package/dist/commands/consult/index.js +121 -5
  114. package/dist/commands/consult/index.js.map +1 -1
  115. package/dist/commands/doctor.d.ts.map +1 -1
  116. package/dist/commands/doctor.js +24 -2
  117. package/dist/commands/doctor.js.map +1 -1
  118. package/dist/commands/porch/verdict.js +2 -2
  119. package/dist/commands/porch/verdict.js.map +1 -1
  120. package/dist/lib/config.d.ts +10 -0
  121. package/dist/lib/config.d.ts.map +1 -1
  122. package/dist/lib/config.js.map +1 -1
  123. package/dist/lib/forge-contracts.d.ts +8 -0
  124. package/dist/lib/forge-contracts.d.ts.map +1 -1
  125. package/dist/lib/forge-contracts.js.map +1 -1
  126. package/dist/lib/managed-block.d.ts +8 -2
  127. package/dist/lib/managed-block.d.ts.map +1 -1
  128. package/dist/lib/managed-block.js +32 -7
  129. package/dist/lib/managed-block.js.map +1 -1
  130. package/package.json +3 -3
  131. package/scripts/forge/gitea/issue-view.sh +4 -1
  132. package/scripts/forge/github/issue-view.sh +2 -2
  133. package/scripts/forge/gitlab/issue-view.sh +4 -1
  134. package/scripts/forge/linear/issue-view.sh +3 -2
  135. package/skeleton/resources/commands/consult.md +14 -0
  136. package/skeleton/roles/builder.md +21 -0
  137. package/skeleton/templates/AGENTS.md +16 -0
  138. package/skeleton/templates/CLAUDE.md +16 -0
  139. package/dashboard-dist/assets/index-DM7OU-EI.js.map +0 -1
  140. package/dist/agent-farm/db/migrate.d.ts +0 -20
  141. package/dist/agent-farm/db/migrate.d.ts.map +0 -1
  142. package/dist/agent-farm/db/migrate.js +0 -107
  143. package/dist/agent-farm/db/migrate.js.map +0 -1
  144. package/dist/agent-farm/servers/worktree-config-watcher.d.ts +0 -36
  145. package/dist/agent-farm/servers/worktree-config-watcher.d.ts.map +0 -1
  146. package/dist/agent-farm/servers/worktree-config-watcher.js.map +0 -1
@@ -0,0 +1,406 @@
1
+ /**
2
+ * One-time state.db → global.db consolidation engine (Issue #1118).
3
+ *
4
+ * The retired per-workspace `state.db` files hold architect/builders/utils/
5
+ * annotations rows. This engine migrates a single `state.db` into the shared
6
+ * `global.db`, then renames the source (never deletes it). It is the single
7
+ * source of truth used by two callers:
8
+ *
9
+ * 1. The automatic boot one-off (tower-server.ts) — runs once ever, gated by
10
+ * a persistent `_consolidation` marker, against the *active* state.db.
11
+ * 2. The manual `afx db consolidate <path>` command — runs on demand against
12
+ * any satellite state.db. Not marker-gated.
13
+ *
14
+ * It knows nothing about the marker. Conflict resolution is **upsert-if-newer**
15
+ * (latest `started_at` wins): on an empty target every row inserts; on a
16
+ * non-empty target a stale overlapping row is skipped. Reads are defensive
17
+ * (`PRAGMA`-tolerant) so source files at any historical schema version migrate.
18
+ */
19
+ import Database from 'better-sqlite3';
20
+ import { existsSync, renameSync } from 'node:fs';
21
+ import { dirname, resolve } from 'node:path';
22
+ import { getConfig } from '../utils/index.js';
23
+ // Issue #1118: shared workspace-path canonicalization (single source of truth),
24
+ // aliased to `canonicalize` for the local callsites.
25
+ import { normalizeWorkspacePath as canonicalize } from '../utils/workspace-path.js';
26
+ /** The `state.db` the pre-#1118 `getDb()` would have opened for this process. */
27
+ export function activeStateDbPath() {
28
+ return resolve(getConfig().stateDir, 'state.db');
29
+ }
30
+ /** A builder's owning workspace: the prefix before the LAST `/.builders/`, else fallback. */
31
+ function deriveWorkspaceFromWorktree(worktree, fallback) {
32
+ // lastIndexOf, not indexOf — robust when the path contains an earlier
33
+ // `.builders` segment (a builder worktree nested under another).
34
+ const marker = '/.builders/';
35
+ const idx = worktree.lastIndexOf(marker);
36
+ if (idx >= 0)
37
+ return canonicalize(worktree.slice(0, idx));
38
+ return fallback;
39
+ }
40
+ /** `<workspace>/.agent-farm/state.db` → canonical `<workspace>`. */
41
+ function workspaceFromStateDbPath(file) {
42
+ return canonicalize(dirname(dirname(file)));
43
+ }
44
+ function tableExists(db, name) {
45
+ return !!db
46
+ .prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = ?")
47
+ .get(name);
48
+ }
49
+ function readRows(db, table) {
50
+ if (!tableExists(db, table))
51
+ return [];
52
+ return db.prepare(`SELECT * FROM ${table}`).all();
53
+ }
54
+ function str(v, fallback = '') {
55
+ if (v == null)
56
+ return fallback;
57
+ return String(v);
58
+ }
59
+ function num(v, fallback = 0) {
60
+ const n = Number(v);
61
+ if (Number.isFinite(n))
62
+ return n;
63
+ return fallback;
64
+ }
65
+ const VALID_STATUS = new Set(['spawning', 'implementing', 'blocked', 'pr', 'complete']);
66
+ const VALID_TYPE = new Set(['spec', 'task', 'protocol', 'shell', 'worktree', 'bugfix', 'pir']);
67
+ // ---------------------------------------------------------------------------
68
+ // Normalizers — map a source row (any historical shape) to the target shape,
69
+ // synthesizing workspace_path and clamping legacy enum values so the global
70
+ // CHECK constraints never reject a migrated row.
71
+ // ---------------------------------------------------------------------------
72
+ function normalizeArchitect(row, wsFromFile) {
73
+ // Pre-v11 rows lack workspace_path → derive from the file's own directory.
74
+ // Pre-v9 rows used integer id=1 → the singleton became 'main'.
75
+ let workspace_path;
76
+ if (row.workspace_path) {
77
+ workspace_path = canonicalize(str(row.workspace_path));
78
+ }
79
+ else {
80
+ workspace_path = wsFromFile;
81
+ }
82
+ const idRaw = row.id;
83
+ let id;
84
+ if (idRaw == null || str(idRaw) === '1') {
85
+ id = 'main';
86
+ }
87
+ else {
88
+ id = str(idRaw);
89
+ }
90
+ return {
91
+ workspace_path,
92
+ id,
93
+ pid: num(row.pid),
94
+ port: num(row.port),
95
+ cmd: str(row.cmd),
96
+ started_at: str(row.started_at),
97
+ terminal_id: row.terminal_id ?? null,
98
+ session_id: row.session_id ?? null,
99
+ };
100
+ }
101
+ function normalizeBuilder(row, wsFromFile) {
102
+ const worktree = str(row.worktree);
103
+ let workspace_path;
104
+ if (row.workspace_path) {
105
+ workspace_path = canonicalize(str(row.workspace_path));
106
+ }
107
+ else {
108
+ workspace_path = deriveWorkspaceFromWorktree(worktree, wsFromFile);
109
+ }
110
+ let status = str(row.status, 'spawning');
111
+ if (status === 'pr-ready')
112
+ status = 'pr'; // pre-v7 rename
113
+ if (!VALID_STATUS.has(status))
114
+ status = 'implementing';
115
+ let type = str(row.type, 'spec');
116
+ if (!VALID_TYPE.has(type))
117
+ type = 'spec';
118
+ const startedAt = str(row.started_at);
119
+ let issueNumber = null;
120
+ if (row.issue_number != null)
121
+ issueNumber = str(row.issue_number);
122
+ return {
123
+ workspace_path,
124
+ id: str(row.id),
125
+ name: str(row.name, str(row.id)),
126
+ port: num(row.port),
127
+ pid: num(row.pid),
128
+ status,
129
+ phase: str(row.phase),
130
+ worktree,
131
+ branch: str(row.branch),
132
+ type,
133
+ task_text: row.task_text ?? null,
134
+ protocol_name: row.protocol_name ?? null,
135
+ issue_number: issueNumber,
136
+ terminal_id: row.terminal_id ?? null,
137
+ spawned_by_architect: row.spawned_by_architect ?? null,
138
+ started_at: startedAt,
139
+ updated_at: str(row.updated_at, startedAt),
140
+ };
141
+ }
142
+ function normalizeUtil(row) {
143
+ return {
144
+ id: str(row.id),
145
+ name: str(row.name, str(row.id)),
146
+ port: num(row.port),
147
+ pid: num(row.pid),
148
+ terminal_id: row.terminal_id ?? null,
149
+ started_at: str(row.started_at),
150
+ };
151
+ }
152
+ function normalizeAnnotation(row) {
153
+ return {
154
+ id: str(row.id),
155
+ file: str(row.file),
156
+ port: num(row.port),
157
+ pid: num(row.pid),
158
+ parent_type: str(row.parent_type, 'util'),
159
+ parent_id: row.parent_id ?? null,
160
+ started_at: str(row.started_at),
161
+ };
162
+ }
163
+ // ---------------------------------------------------------------------------
164
+ // Upsert-if-newer statements. The `WHERE excluded.started_at > <table>.started_at`
165
+ // on the conflict path means a stale incoming row leaves the existing (newer)
166
+ // row untouched.
167
+ // ---------------------------------------------------------------------------
168
+ function upsertArchitect(db, r) {
169
+ db.prepare(`
170
+ INSERT INTO architect (workspace_path, id, pid, port, cmd, started_at, terminal_id, session_id)
171
+ VALUES (@workspace_path, @id, @pid, @port, @cmd, @started_at, @terminal_id, @session_id)
172
+ ON CONFLICT(workspace_path, id) DO UPDATE SET
173
+ pid = excluded.pid, port = excluded.port, cmd = excluded.cmd,
174
+ started_at = excluded.started_at, terminal_id = excluded.terminal_id,
175
+ session_id = excluded.session_id
176
+ WHERE excluded.started_at > architect.started_at
177
+ `).run(r);
178
+ }
179
+ function upsertBuilder(db, r) {
180
+ db.prepare(`
181
+ INSERT INTO builders (
182
+ workspace_path, id, name, port, pid, status, phase, worktree, branch,
183
+ type, task_text, protocol_name, issue_number, terminal_id, spawned_by_architect,
184
+ started_at, updated_at
185
+ )
186
+ VALUES (
187
+ @workspace_path, @id, @name, @port, @pid, @status, @phase, @worktree, @branch,
188
+ @type, @task_text, @protocol_name, @issue_number, @terminal_id, @spawned_by_architect,
189
+ @started_at, @updated_at
190
+ )
191
+ ON CONFLICT(workspace_path, id) DO UPDATE SET
192
+ name = excluded.name, port = excluded.port, pid = excluded.pid,
193
+ status = excluded.status, phase = excluded.phase, worktree = excluded.worktree,
194
+ branch = excluded.branch, type = excluded.type, task_text = excluded.task_text,
195
+ protocol_name = excluded.protocol_name, issue_number = excluded.issue_number,
196
+ terminal_id = excluded.terminal_id, spawned_by_architect = excluded.spawned_by_architect,
197
+ started_at = excluded.started_at, updated_at = excluded.updated_at
198
+ WHERE excluded.started_at > builders.started_at
199
+ `).run(r);
200
+ }
201
+ function upsertUtil(db, r) {
202
+ db.prepare(`
203
+ INSERT INTO utils (id, name, port, pid, terminal_id, started_at)
204
+ VALUES (@id, @name, @port, @pid, @terminal_id, @started_at)
205
+ ON CONFLICT(id) DO UPDATE SET
206
+ name = excluded.name, port = excluded.port, pid = excluded.pid,
207
+ terminal_id = excluded.terminal_id, started_at = excluded.started_at
208
+ WHERE excluded.started_at > utils.started_at
209
+ `).run(r);
210
+ }
211
+ function upsertAnnotation(db, r) {
212
+ db.prepare(`
213
+ INSERT INTO annotations (id, file, port, pid, parent_type, parent_id, started_at)
214
+ VALUES (@id, @file, @port, @pid, @parent_type, @parent_id, @started_at)
215
+ ON CONFLICT(id) DO UPDATE SET
216
+ file = excluded.file, port = excluded.port, pid = excluded.pid,
217
+ parent_type = excluded.parent_type, parent_id = excluded.parent_id,
218
+ started_at = excluded.started_at
219
+ WHERE excluded.started_at > annotations.started_at
220
+ `).run(r);
221
+ }
222
+ function buildSpecs(src, wsFromFile) {
223
+ return [
224
+ {
225
+ table: 'architect',
226
+ pk: ['workspace_path', 'id'],
227
+ rows: readRows(src, 'architect').map((r) => normalizeArchitect(r, wsFromFile)),
228
+ upsert: upsertArchitect,
229
+ },
230
+ {
231
+ table: 'builders',
232
+ pk: ['workspace_path', 'id'],
233
+ rows: readRows(src, 'builders').map((r) => normalizeBuilder(r, wsFromFile)),
234
+ upsert: upsertBuilder,
235
+ },
236
+ {
237
+ table: 'utils',
238
+ pk: ['id'],
239
+ rows: readRows(src, 'utils').map(normalizeUtil),
240
+ upsert: upsertUtil,
241
+ },
242
+ {
243
+ table: 'annotations',
244
+ pk: ['id'],
245
+ rows: readRows(src, 'annotations').map(normalizeAnnotation),
246
+ upsert: upsertAnnotation,
247
+ },
248
+ ];
249
+ }
250
+ /** Classify one incoming row against the current global table (no writes). */
251
+ function classify(db, spec, row) {
252
+ if (!tableExists(db, spec.table))
253
+ return 'inserted';
254
+ const where = spec.pk.map((c) => `${c} = ?`).join(' AND ');
255
+ const existing = db
256
+ .prepare(`SELECT started_at FROM ${spec.table} WHERE ${where}`)
257
+ .get(...spec.pk.map((c) => row[c]));
258
+ if (!existing)
259
+ return 'inserted';
260
+ if (str(row.started_at) > str(existing.started_at))
261
+ return 'updated';
262
+ return 'skipped';
263
+ }
264
+ /**
265
+ * Compute what migrating `sourcePath` into `globalDb` would do — pure read, no
266
+ * writes, no rename. Used by the `--dry-run-migration` preview.
267
+ */
268
+ export function planMigration(globalDb, sourcePath) {
269
+ if (!existsSync(sourcePath)) {
270
+ return { sourcePath, exists: false, stats: [], get total() { return 0; } };
271
+ }
272
+ const wsFromFile = workspaceFromStateDbPath(sourcePath);
273
+ const src = new Database(sourcePath, { readonly: true });
274
+ try {
275
+ const specs = buildSpecs(src, wsFromFile);
276
+ const stats = specs.map((spec) => {
277
+ const s = { table: spec.table, inserted: 0, updated: 0, skipped: 0 };
278
+ for (const row of spec.rows)
279
+ s[classify(globalDb, spec, row)]++;
280
+ return s;
281
+ });
282
+ return {
283
+ sourcePath,
284
+ exists: true,
285
+ stats,
286
+ get total() {
287
+ return stats.reduce((n, s) => n + s.inserted + s.updated + s.skipped, 0);
288
+ },
289
+ };
290
+ }
291
+ finally {
292
+ src.close();
293
+ }
294
+ }
295
+ function renameWithSidecars(file) {
296
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
297
+ const target = `${file}.pre-merge-${stamp}`;
298
+ renameSync(file, target);
299
+ for (const suffix of ['-wal', '-shm']) {
300
+ const sidecar = file + suffix;
301
+ if (existsSync(sidecar)) {
302
+ try {
303
+ renameSync(sidecar, target + suffix);
304
+ }
305
+ catch {
306
+ // Sidecar rename is best-effort; the main file is already retired.
307
+ }
308
+ }
309
+ }
310
+ return target;
311
+ }
312
+ /** Read a source state.db, build per-table specs, and classify each row. */
313
+ function prepareMigration(globalDb, sourcePath) {
314
+ const wsFromFile = workspaceFromStateDbPath(sourcePath);
315
+ const src = new Database(sourcePath, { readonly: true });
316
+ try {
317
+ const specs = buildSpecs(src, wsFromFile);
318
+ let total = 0;
319
+ const stats = specs.map((spec) => {
320
+ const s = { table: spec.table, inserted: 0, updated: 0, skipped: 0 };
321
+ for (const row of spec.rows) {
322
+ s[classify(globalDb, spec, row)]++;
323
+ total++;
324
+ }
325
+ return s;
326
+ });
327
+ return { specs, stats, total };
328
+ }
329
+ finally {
330
+ src.close();
331
+ }
332
+ }
333
+ /** Apply all upserts for the prepared specs (caller wraps in a transaction). */
334
+ function copyRows(globalDb, specs) {
335
+ for (const spec of specs) {
336
+ for (const row of spec.rows)
337
+ spec.upsert(globalDb, row);
338
+ }
339
+ }
340
+ /**
341
+ * Migrate `sourcePath` into `globalDb` (upsert-if-newer, one transaction), then
342
+ * rename the source to `*.pre-merge-<timestamp>`. Does NOT touch the
343
+ * `_consolidation` marker — that is the boot caller's concern. This is the
344
+ * manual `afx db consolidate <path>` path. Idempotent in practice: once renamed
345
+ * the source is gone, and re-running upsert-if-newer is a no-op.
346
+ */
347
+ export function applyMigration(globalDb, sourcePath) {
348
+ if (!existsSync(sourcePath)) {
349
+ return { sourcePath, migrated: false, renamedTo: null, stats: [] };
350
+ }
351
+ const { specs, stats } = prepareMigration(globalDb, sourcePath);
352
+ globalDb.transaction(() => copyRows(globalDb, specs))();
353
+ const renamedTo = renameWithSidecars(sourcePath);
354
+ return { sourcePath, migrated: true, renamedTo, stats };
355
+ }
356
+ // ---------------------------------------------------------------------------
357
+ // The `_consolidation` marker + the automatic boot one-off (Issue #1118).
358
+ // The marker's mere presence means the one-time boot cutover has run; `state.db`
359
+ // is never read again afterward.
360
+ // ---------------------------------------------------------------------------
361
+ function ensureMarkerTable(db) {
362
+ db.exec(`
363
+ CREATE TABLE IF NOT EXISTS _consolidation (
364
+ id INTEGER PRIMARY KEY CHECK (id = 1),
365
+ done_at TEXT NOT NULL DEFAULT (datetime('now')),
366
+ source_path TEXT,
367
+ rows_migrated INTEGER
368
+ )
369
+ `);
370
+ }
371
+ /** Whether the one-time boot consolidation has already run. */
372
+ export function isConsolidationDone(db) {
373
+ ensureMarkerTable(db);
374
+ return !!db.prepare('SELECT 1 FROM _consolidation WHERE id = 1').get();
375
+ }
376
+ function writeMarker(db, sourcePath, rows) {
377
+ db.prepare('INSERT OR IGNORE INTO _consolidation (id, source_path, rows_migrated) VALUES (1, ?, ?)').run(sourcePath, rows);
378
+ }
379
+ /**
380
+ * The automatic boot one-off. Runs once ever (strict policy): on the first boot
381
+ * the marker is unset, so it migrates the *active* state.db and writes the
382
+ * marker — **unconditionally**, even if the active file is absent/empty, so
383
+ * state.db is never checked again. The row copy and marker write share one
384
+ * transaction (atomic); the source rename happens after commit.
385
+ *
386
+ * Returns null if the marker was already set (no-op). Satellite files missed by
387
+ * this one-off are recoverable via the manual `afx db consolidate <path>`.
388
+ */
389
+ export function runBootConsolidation(globalDb) {
390
+ if (isConsolidationDone(globalDb))
391
+ return null;
392
+ const sourcePath = activeStateDbPath();
393
+ if (!existsSync(sourcePath)) {
394
+ // Strict: mark done even with nothing to migrate.
395
+ globalDb.transaction(() => writeMarker(globalDb, null, 0))();
396
+ return { sourcePath, migrated: false, renamedTo: null, stats: [] };
397
+ }
398
+ const { specs, stats, total } = prepareMigration(globalDb, sourcePath);
399
+ globalDb.transaction(() => {
400
+ copyRows(globalDb, specs);
401
+ writeMarker(globalDb, sourcePath, total);
402
+ })();
403
+ const renamedTo = renameWithSidecars(sourcePath);
404
+ return { sourcePath, migrated: true, renamedTo, stats };
405
+ }
406
+ //# sourceMappingURL=consolidate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consolidate.js","sourceRoot":"","sources":["../../../src/agent-farm/db/consolidate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC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AC,CAAC,EAAE,CAAC;QAC7D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACrE,CAAC;IAED,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACvE,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;QACxB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC1B,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC,EAAE,CAAC;IACL,MAAM,SAAS,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC1D,CAAC"}
@@ -6,8 +6,14 @@
6
6
  */
7
7
  import Database from 'better-sqlite3';
8
8
  /**
9
- * Get the local database instance (state.db)
10
- * Creates and initializes the database if it doesn't exist
9
+ * Get the database instance.
10
+ *
11
+ * Issue #1118: state.db is retired. getDb() now returns the single user-global
12
+ * global.db connection — the same instance as getGlobalDb(). Per-workspace rows
13
+ * (architect, builders) are disambiguated by their `workspace_path` column
14
+ * within the shared file, so the connection no longer depends on Tower's
15
+ * start-cwd. Kept as a distinct export so the many existing callsites that read
16
+ * dashboard state (architect/builders/utils/annotations) don't churn.
11
17
  */
12
18
  export declare function getDb(): Database.Database;
13
19
  /**
@@ -16,7 +22,9 @@ export declare function getDb(): Database.Database;
16
22
  */
17
23
  export declare function getGlobalDb(): Database.Database;
18
24
  /**
19
- * Close the local database connection
25
+ * Close the database connection.
26
+ * Issue #1118: getDb() aliases the global connection, so this closes the shared
27
+ * global.db. Kept for callsites that historically closed "the local db".
20
28
  */
21
29
  export declare function closeDb(): void;
22
30
  /**
@@ -28,7 +36,8 @@ export declare function closeGlobalDb(): void;
28
36
  */
29
37
  export declare function closeAllDbs(): void;
30
38
  /**
31
- * Get the path to the local database
39
+ * Get the path to the database.
40
+ * Issue #1118: the local db path is now the global db path.
32
41
  */
33
42
  export declare function getDbPath(): string;
34
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent-farm/db/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AA0CtC;;;GAGG;AACH,wBAAgB,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAKzC;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAK/C;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAK9B;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAKpC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAGlC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAGlC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAMxC;AA8yBD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EACV,WAAW,EACX,SAAS,EACT,MAAM,EACN,YAAY,GACb,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent-farm/db/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAyCtC;;;;;;;;;GASG;AACH,wBAAgB,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAEzC;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAK/C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAE9B;AAED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