@solidactions/cli 3.10.2 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -95,6 +95,7 @@ solidactions database pull analytics .solidactions/databases/analytics.db --yes
95
95
  solidactions database pull analytics --writable
96
96
  solidactions database import analytics backup.sql --yes
97
97
  solidactions database import analytics backup.sql --resume <checkpoint> --yes
98
+ solidactions database push analytics complete.db --yes
98
99
  ```
99
100
 
100
101
  `--json` produces machine-readable output where supported. `delete`, `exec`,
@@ -111,6 +112,16 @@ By default, `pull` atomically publishes a read-only local replica at
111
112
  `.solidactions/databases/<safe-stem>.db`, or at an explicit path. Reuse that
112
113
  file for local analytics and transformations. `pull --writable` instead opens a
113
114
  foreground session: writes go to the live workspace database.
115
+
116
+ `database push` replaces the complete remote database from a local SQLite file.
117
+ It requires `--yes`, never changes the source file, and normalizes a private
118
+ snapshot to UTF-8 SQLite with 4096-byte pages, no auto-vacuum, and WAL mode.
119
+ The normalized snapshot can have a different byte size from the source.
120
+ Quiesce writers before starting: replacement invalidates the old database URL
121
+ and credentials. Empty databases additionally require `--allow-empty`; use
122
+ `--idempotency-key <uuid>` to safely replay an interrupted operation.
123
+ Reported countable rows include ordinary user tables; internal, virtual, and
124
+ shadow tables are excluded.
114
125
  No offline merge or background write-back continues after exit.
115
126
 
116
127
  `dump` publishes only a complete SQL file through an owned temporary path and
@@ -237,7 +248,7 @@ Use `solidactions <command> --help` for full flag details on any command.
237
248
  | `project deploy <name> [path]` | `-e`, `--create`, `--config-only`, `--paused`, `--no-git-metadata` | Deploy or sync config only; optionally land YAML schedules paused |
238
249
  | `project enable <project>` | `-e` (default `dev`) | Allow new starts through this project gate |
239
250
  | `project disable <project>` | `-e` (default `dev`) | Block new root starts without cancelling existing roots |
240
- | `project view <project>` | `-e` (default `dev`) | View status, `Enabled: on|off`, and client-reported deployed revision |
251
+ | `project view <project>` | `-e` (default `dev`), `--json` | View status, `Enabled: on|off`, and client-reported deployed revision, incl. an `N behind origin/<branch> at deploy` drift clause when the deployment is behind the default branch |
241
252
  | `project pull <name> [path]` | `-y` | Pull source (warns before overwriting) |
242
253
  | `project logs <name>` | | View build logs |
243
254
  | `project list` | `--json` | List project families; environments render as `environment:on/off` |
@@ -277,7 +288,7 @@ its project or schedule.
277
288
  |---------|-----------|-------------|
278
289
  | `run start <project> <workflow>` | `-e`, `-i`, `--wait` | Trigger a workflow run |
279
290
  | `run list [project]` | `--json`, `--detailed`, `--status`, `--since`, `--workflow`, `--limit`, `--offset` | List and filter runs |
280
- | `run view <run-id>` | `--json`, `--timeline`, `--steps`, `--logs` | Inspect a run |
291
+ | `run view <run-id>` | `--json`, `--timeline`, `--steps`, `--logs` | Inspect a run, incl. the deployed revision (`Revision (latest session): ...`, or `deployed_revision` under `--json`) |
281
292
 
282
293
  ### env
283
294
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "cli_name": "solidactions",
4
- "cli_version": "3.10.2",
4
+ "cli_version": "3.12.0",
5
5
  "global_options": [
6
6
  {
7
7
  "flags": "-V, --version",
@@ -911,6 +911,80 @@
911
911
  }
912
912
  ]
913
913
  },
914
+ {
915
+ "path": [
916
+ "database",
917
+ "push"
918
+ ],
919
+ "name": "push",
920
+ "aliases": [],
921
+ "description": "Replace from a private WAL/4096-byte/auto-vacuum NONE snapshot; source file is unchanged; countable rows exclude internal, virtual, and shadow tables",
922
+ "hidden": false,
923
+ "arguments": [
924
+ {
925
+ "name": "database",
926
+ "required": true,
927
+ "variadic": false,
928
+ "description": "Database name"
929
+ },
930
+ {
931
+ "name": "file.db",
932
+ "required": true,
933
+ "variadic": false,
934
+ "description": "Complete SQLite database file"
935
+ }
936
+ ],
937
+ "options": [
938
+ {
939
+ "flags": "-y, --yes",
940
+ "long": "--yes",
941
+ "short": "-y",
942
+ "description": "Acknowledge destructive replacement",
943
+ "required": true,
944
+ "value_required": false,
945
+ "value_optional": false,
946
+ "variadic": false,
947
+ "negated": false,
948
+ "hidden": false
949
+ },
950
+ {
951
+ "flags": "--allow-empty",
952
+ "long": "--allow-empty",
953
+ "short": null,
954
+ "description": "Allow a database with zero countable rows",
955
+ "required": false,
956
+ "value_required": false,
957
+ "value_optional": false,
958
+ "variadic": false,
959
+ "negated": false,
960
+ "hidden": false
961
+ },
962
+ {
963
+ "flags": "--idempotency-key <uuid>",
964
+ "long": "--idempotency-key",
965
+ "short": null,
966
+ "description": "Reuse a bulk-load operation UUID",
967
+ "required": false,
968
+ "value_required": true,
969
+ "value_optional": false,
970
+ "variadic": false,
971
+ "negated": false,
972
+ "hidden": false
973
+ },
974
+ {
975
+ "flags": "-h, --help",
976
+ "long": "--help",
977
+ "short": "-h",
978
+ "description": "display help for command",
979
+ "required": false,
980
+ "value_required": false,
981
+ "value_optional": false,
982
+ "variadic": false,
983
+ "negated": false,
984
+ "hidden": false
985
+ }
986
+ ]
987
+ },
914
988
  {
915
989
  "path": [
916
990
  "database",
@@ -985,6 +1059,18 @@
985
1059
  "hidden": false,
986
1060
  "default": "dev"
987
1061
  },
1062
+ {
1063
+ "flags": "--json",
1064
+ "long": "--json",
1065
+ "short": null,
1066
+ "description": "Output as JSON",
1067
+ "required": false,
1068
+ "value_required": false,
1069
+ "value_optional": false,
1070
+ "variadic": false,
1071
+ "negated": false,
1072
+ "hidden": false
1073
+ },
988
1074
  {
989
1075
  "flags": "-h, --help",
990
1076
  "long": "--help",
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.normalizeDatabaseForPush = normalizeDatabaseForPush;
40
+ exports.assertCountableTableLimit = assertCountableTableLimit;
41
+ exports.databasePushWithConfig = databasePushWithConfig;
42
+ exports.databasePush = databasePush;
43
+ const axios_1 = __importDefault(require("axios"));
44
+ const crypto_1 = require("crypto");
45
+ const fs_1 = __importDefault(require("fs"));
46
+ const os_1 = __importDefault(require("os"));
47
+ const path_1 = __importDefault(require("path"));
48
+ const url_1 = require("url");
49
+ const client_1 = require("@libsql/client");
50
+ const database_data_plane_1 = require("../utils/database-data-plane");
51
+ const MAX_BYTES = 20_000_000_000;
52
+ const PAGE_SIZE = 4096;
53
+ const POLL_MS = 2_000;
54
+ const TERMINAL = new Set(['promoted', 'failed', 'aborted']);
55
+ const PHASES = new Set(['preparing', 'uploading', 'validating', 'finalizing', 'promoted_pending_ready', 'promoted', 'aborting', 'aborted', 'failed']);
56
+ // Laravel's unversioned `uuid` validation accepts the canonical hexadecimal
57
+ // 8-4-4-4-12 representation regardless of UUID version (including UUIDv7).
58
+ const IDEMPOTENCY_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
59
+ const OPERATION_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
60
+ const EXCLUDED_PREFIXES = ['sqlite_', '_litestream', 'libsql_', '_turso_'];
61
+ function sqlString(value) {
62
+ return `'${value.replace(/'/g, "''")}'`;
63
+ }
64
+ function sqlIdentifier(value) {
65
+ return `"${value.replace(/"/g, '""')}"`;
66
+ }
67
+ function scalar(rows, label) {
68
+ if (rows.length !== 1 || rows[0].length < 1)
69
+ throw new Error(`Invalid ${label} result.`);
70
+ return rows[0][0];
71
+ }
72
+ function integer(value, label) {
73
+ const parsed = Number(value);
74
+ if (!Number.isSafeInteger(parsed) || parsed < 0)
75
+ throw new Error(`Invalid ${label}.`);
76
+ return parsed;
77
+ }
78
+ function isExcluded(name) {
79
+ const folded = name.toLowerCase();
80
+ return EXCLUDED_PREFIXES.some((prefix) => folded.startsWith(prefix));
81
+ }
82
+ function safeNormalizationError(error) {
83
+ if (error instanceof database_data_plane_1.DatabaseOperationError)
84
+ return error;
85
+ if (error?.code === 'ENOENT') {
86
+ return new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'The source database file was not found; no source file was changed.');
87
+ }
88
+ const text = error instanceof Error ? error.message.toLowerCase() : '';
89
+ if (text.includes('database is locked') || text.includes('busy')) {
90
+ return new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'The SQLite snapshot is busy. Quiesce local writers and retry; the source database was not changed.');
91
+ }
92
+ if (text.includes('encrypted') || text.includes('not a database') || text.includes('malformed') || text.includes('corrupt')) {
93
+ return new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'The SQLite file is corrupt, encrypted, or not a database. Export an unencrypted SQLite database and retry; the source database was not changed.');
94
+ }
95
+ if (text.includes('no space') || text.includes('disk full')) {
96
+ return new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'Temporary disk space is insufficient for database normalization; the source database was not changed.');
97
+ }
98
+ return new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'The local SQLite binding could not open or normalize a temporary copy. Verify Node 20 platform support and the input file; the source database was not changed.');
99
+ }
100
+ async function sha256(file) {
101
+ const hash = (0, crypto_1.createHash)('sha256');
102
+ for await (const chunk of fs_1.default.createReadStream(file))
103
+ hash.update(chunk);
104
+ return hash.digest('hex');
105
+ }
106
+ async function removeSidecars(file) {
107
+ await Promise.all(['-wal', '-shm', '-journal'].map((suffix) => fs_1.default.promises.rm(`${file}${suffix}`, { force: true })));
108
+ }
109
+ async function normalizeDatabaseForPush(sourceInput, dependencies = {}) {
110
+ const source = path_1.default.resolve(sourceInput);
111
+ let directory;
112
+ let sourceClient;
113
+ let stageClient;
114
+ let finalClient;
115
+ try {
116
+ const sourceStat = await fs_1.default.promises.stat(source);
117
+ if (!sourceStat.isFile() || sourceStat.size === 0)
118
+ throw new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'A database push requires a non-empty regular SQLite file; the source database was not changed.');
119
+ if (sourceStat.size > MAX_BYTES)
120
+ throw new database_data_plane_1.DatabaseOperationError('bulk_load_too_large', 'The database exceeds the decimal 20,000,000,000-byte bulk-load limit; the source database was not changed.');
121
+ const tempRoot = dependencies.tempRoot ?? os_1.default.tmpdir();
122
+ const statfs = dependencies.statfs ?? fs_1.default.promises.statfs;
123
+ const space = await statfs(tempRoot);
124
+ const available = Number(space.bavail) * Number(space.bsize);
125
+ if (!Number.isFinite(available) || available < sourceStat.size * 2 + 16 * 1024 * 1024) {
126
+ throw new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'Temporary disk space is insufficient for two normalized database copies; the source database was not changed.');
127
+ }
128
+ directory = await fs_1.default.promises.mkdtemp(path_1.default.join(tempRoot, 'solidactions-database-push-'));
129
+ await fs_1.default.promises.chmod(directory, 0o700);
130
+ const snapshot = path_1.default.join(directory, 'snapshot.db');
131
+ const final = path_1.default.join(directory, 'upload.db');
132
+ sourceClient = (0, client_1.createClient)({ url: (0, url_1.pathToFileURL)(source).href, intMode: 'number' });
133
+ await sourceClient.execute(`VACUUM INTO ${sqlString(snapshot)}`);
134
+ await sourceClient.close();
135
+ sourceClient = undefined;
136
+ stageClient = (0, client_1.createClient)({ url: (0, url_1.pathToFileURL)(snapshot).href, intMode: 'number' });
137
+ await stageClient.execute('PRAGMA journal_mode=DELETE');
138
+ await stageClient.execute('PRAGMA page_size=4096');
139
+ await stageClient.execute('PRAGMA auto_vacuum=NONE');
140
+ await stageClient.execute(`VACUUM INTO ${sqlString(final)}`);
141
+ await stageClient.close();
142
+ stageClient = undefined;
143
+ finalClient = (0, client_1.createClient)({ url: (0, url_1.pathToFileURL)(final).href, intMode: 'number' });
144
+ const mode = String(scalar((await finalClient.execute('PRAGMA journal_mode=WAL')).rows, 'journal mode')).toLowerCase();
145
+ const checkpoint = (await finalClient.execute('PRAGMA wal_checkpoint(TRUNCATE)')).rows[0];
146
+ if (mode !== 'wal' || !checkpoint || Number(checkpoint[0]) !== 0)
147
+ throw new Error('WAL checkpoint is busy.');
148
+ await finalClient.close();
149
+ finalClient = undefined;
150
+ await removeSidecars(final);
151
+ await fs_1.default.promises.chmod(final, 0o400);
152
+ finalClient = (0, client_1.createClient)({ url: (0, url_1.pathToFileURL)(final).href, intMode: 'number' });
153
+ const encoding = String(scalar((await finalClient.execute('PRAGMA encoding')).rows, 'encoding'));
154
+ if (encoding.toUpperCase() !== 'UTF-8') {
155
+ throw new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'The database encoding is not UTF-8 and cannot be changed in place. Export or rebuild a new UTF-8 SQLite database; the source database was not changed.');
156
+ }
157
+ const pageSize = integer(scalar((await finalClient.execute('PRAGMA page_size')).rows, 'page size'), 'page size');
158
+ const autoVacuum = integer(scalar((await finalClient.execute('PRAGMA auto_vacuum')).rows, 'auto vacuum'), 'auto vacuum');
159
+ const persistedMode = String(scalar((await finalClient.execute('PRAGMA journal_mode')).rows, 'journal mode')).toLowerCase();
160
+ const integrity = String(scalar((await finalClient.execute('PRAGMA integrity_check(1)')).rows, 'integrity'));
161
+ if (pageSize !== PAGE_SIZE || autoVacuum !== 0 || persistedMode !== 'wal' || integrity !== 'ok')
162
+ throw new Error('Normalized SQLite invariants failed.');
163
+ const schemaResult = await finalClient.execute('SELECT type, name, tbl_name, sql FROM sqlite_master WHERE sql IS NOT NULL ORDER BY type COLLATE BINARY, name COLLATE BINARY, tbl_name COLLATE BINARY, sql COLLATE BINARY');
164
+ const schema = schemaResult.rows
165
+ .map((row) => Array.from(row, (value) => value === null ? null : String(value)))
166
+ .filter((row) => !isExcluded(String(row[1])) && !isExcluded(String(row[2])));
167
+ const schemaSha = (0, crypto_1.createHash)('sha256').update(JSON.stringify(schema), 'utf8').digest('hex');
168
+ const tableList = await finalClient.execute('PRAGMA table_list');
169
+ const candidates = tableList.rows
170
+ .filter((row) => String(row[2]) === 'table')
171
+ .map((row) => String(row[1]))
172
+ .filter((name) => !isExcluded(name));
173
+ const masterNames = new Set(schema.filter((row) => row[0] === 'table').map((row) => row[1]));
174
+ const names = candidates.filter((name) => masterNames.has(name)).sort((a, b) => Buffer.from(a).compare(Buffer.from(b)));
175
+ assertCountableTableLimit(names.length);
176
+ const tables = {};
177
+ let totalRows = 0;
178
+ for (const name of names) {
179
+ const count = integer(scalar((await finalClient.execute(`SELECT COUNT(*) FROM ${sqlIdentifier(name)}`)).rows, `row count for ${name}`), `row count for ${name}`);
180
+ tables[name] = count;
181
+ totalRows += count;
182
+ if (!Number.isSafeInteger(totalRows))
183
+ throw new Error('Row count overflow.');
184
+ }
185
+ const pageCount = integer(scalar((await finalClient.execute('PRAGMA page_count')).rows, 'page count'), 'page count');
186
+ await finalClient.close();
187
+ finalClient = undefined;
188
+ await removeSidecars(final);
189
+ const inputBytes = (await fs_1.default.promises.stat(final)).size;
190
+ if (inputBytes !== pageCount * PAGE_SIZE || inputBytes < PAGE_SIZE)
191
+ throw new Error('Normalized byte count mismatch.');
192
+ if (inputBytes > MAX_BYTES)
193
+ throw new database_data_plane_1.DatabaseOperationError('bulk_load_too_large', 'The normalized database exceeds the decimal 20,000,000,000-byte bulk-load limit; the source database was not changed.');
194
+ const digest = await sha256(final);
195
+ return {
196
+ file: final, inputBytes, pageCount, totalRows,
197
+ manifest: { sha256: digest, schema_sha256: schemaSha, tables },
198
+ cleanup: async () => { if (directory)
199
+ await fs_1.default.promises.rm(directory, { recursive: true, force: true }); },
200
+ };
201
+ }
202
+ catch (error) {
203
+ try {
204
+ await sourceClient?.close();
205
+ }
206
+ catch { /* sanitized below */ }
207
+ try {
208
+ await stageClient?.close();
209
+ }
210
+ catch { /* sanitized below */ }
211
+ try {
212
+ await finalClient?.close();
213
+ }
214
+ catch { /* sanitized below */ }
215
+ if (directory) {
216
+ try {
217
+ await fs_1.default.promises.chmod(directory, 0o700);
218
+ }
219
+ catch { /* cleanup remains best effort */ }
220
+ await fs_1.default.promises.rm(directory, { recursive: true, force: true });
221
+ }
222
+ throw safeNormalizationError(error);
223
+ }
224
+ }
225
+ function assertCountableTableLimit(count) {
226
+ if (count > 1_000) {
227
+ throw new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'The database has more than 1,000 countable tables and cannot be bulk loaded; the source database was not changed.');
228
+ }
229
+ }
230
+ function hardDeadlineMs(bytes) {
231
+ return Math.min(4 * 60 * 60_000, 30 * 60_000 + Math.ceil(bytes / 2_000_000) * 1000);
232
+ }
233
+ // A push may keep polling past the client's own hard deadline, but only as far
234
+ // as the deadline the SERVER reports for the phase it is in (#1287 R18), and
235
+ // never unboundedly: `hard_expires_at` is the UPLOAD deadline, while validation
236
+ // runs on a lease of its own that legitimately outlives it. Giving up on the
237
+ // upload deadline abandoned pushes whose validation was perfectly healthy.
238
+ const MAX_POLL_EXTENSION_MS = 60 * 60_000;
239
+ function extendedPollDeadline(current, uploadDeadlineAt, serverDeadline) {
240
+ if (typeof serverDeadline !== 'string')
241
+ return current;
242
+ const parsed = Date.parse(serverDeadline);
243
+ if (!Number.isFinite(parsed))
244
+ return current;
245
+ return Math.max(current, Math.min(parsed + POLL_MS, uploadDeadlineAt + MAX_POLL_EXTENSION_MS));
246
+ }
247
+ function stableOperation(data) {
248
+ const operation = data?.operation;
249
+ if (!operation || typeof operation.id !== 'string' || !OPERATION_UUID.test(operation.id) || typeof operation.phase !== 'string' || !PHASES.has(operation.phase))
250
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'The database bulk-load response was invalid.');
251
+ return operation;
252
+ }
253
+ async function databasePushWithConfig(name, file, options, config, dependencies = {}) {
254
+ if (!options.yes)
255
+ throw new database_data_plane_1.DatabaseOperationError('confirmation_required', 'Database push is destructive and requires --yes.');
256
+ const key = options.idempotencyKey ?? (0, crypto_1.randomUUID)();
257
+ if (!IDEMPOTENCY_UUID.test(key))
258
+ throw new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', '--idempotency-key must be a UUID.');
259
+ const stdout = dependencies.stdout ?? console.log;
260
+ const sleep = dependencies.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
261
+ const normalized = await normalizeDatabaseForPush(file, dependencies);
262
+ let operationId;
263
+ let promoteAccepted = false;
264
+ let terminalObserved = false;
265
+ try {
266
+ if (normalized.totalRows === 0 && !options.allowEmpty)
267
+ throw new database_data_plane_1.DatabaseOperationError('invalid_bulk_database', 'This database has zero countable rows. Retry with --allow-empty only if replacing the remote database with an empty database is intended; the source database was not changed.');
268
+ const deadlineMs = hardDeadlineMs(normalized.inputBytes);
269
+ const clock = dependencies.now ?? Date.now;
270
+ const deadlineAt = clock() + deadlineMs;
271
+ const remaining = () => {
272
+ const value = deadlineAt - clock();
273
+ if (value <= 0)
274
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'Database replacement did not finish before the displayed hard deadline. Retry with the same idempotency key.');
275
+ return value;
276
+ };
277
+ const controlRemaining = () => Math.min(database_data_plane_1.DEFAULT_DATABASE_CONTROL_PLANE_TIMEOUT_MS, remaining());
278
+ stdout(`WARNING: This destructively replaces database "${name}". Quiesce all writers; old URLs and credentials will become invalid. A private snapshot is normalized to WAL, 4096-byte pages, and auto-vacuum NONE; the source file is unchanged.`);
279
+ stdout(`Hard deadline: ${Math.ceil(deadlineMs / 60_000)} minutes for ${normalized.inputBytes} bytes. Idempotency key: ${key}`);
280
+ const prepareBody = {
281
+ operation: 'bulk_load_prepare', name, bulk_mode: 'replace', input_bytes: normalized.inputBytes,
282
+ page_count: normalized.pageCount, manifest: normalized.manifest, allow_empty: options.allowEmpty === true, idempotency_key: key,
283
+ };
284
+ const prepare = await (0, database_data_plane_1.requestDatabaseOperation)(config, prepareBody, { post: dependencies.post, controlPlaneTimeoutMs: controlRemaining() });
285
+ const operation = stableOperation(prepare);
286
+ operationId = String(operation.id);
287
+ const upload = prepare?.upload;
288
+ if (typeof upload?.url !== 'string' || typeof upload?.token !== 'string')
289
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'The database upload credential response was invalid.');
290
+ const uploader = dependencies.upload ?? axios_1.default.post;
291
+ let uploaded;
292
+ let renewalFailure;
293
+ let renewing = Promise.resolve();
294
+ const renewalTimer = setInterval(() => {
295
+ renewing = renewing.then(async () => {
296
+ const replay = await (0, database_data_plane_1.requestDatabaseOperation)(config, prepareBody, { post: dependencies.post, controlPlaneTimeoutMs: controlRemaining() });
297
+ const replayOperation = stableOperation(replay);
298
+ if (replayOperation.id !== operation.id)
299
+ throw new database_data_plane_1.DatabaseOperationError('bulk_load_conflict', 'The bulk-load replay returned a different operation.');
300
+ // A replay is a LEASE renewal only (#1287 R9b): the server
301
+ // returns no credential, because an in-progress direct upload
302
+ // cannot swap tokens mid-flight. The original single-use
303
+ // credential stays valid until the hard deadline. Should any
304
+ // server ever include one, it is neither retained nor printed.
305
+ }).catch((error) => { renewalFailure = error; });
306
+ }, 5 * 60_000);
307
+ try {
308
+ uploaded = await uploader(upload.url, fs_1.default.createReadStream(normalized.file), {
309
+ headers: { Authorization: `Bearer ${upload.token}`, 'Content-Type': 'application/octet-stream', 'Content-Length': String(normalized.inputBytes) },
310
+ maxBodyLength: normalized.inputBytes, maxContentLength: 1024, timeout: remaining(),
311
+ validateStatus: (status) => (status >= 200 && status < 300) || status === 413,
312
+ });
313
+ }
314
+ catch {
315
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'Candidate upload failed. The upstream response was hidden to protect credentials; the source database was not changed.');
316
+ }
317
+ finally {
318
+ clearInterval(renewalTimer);
319
+ await renewing;
320
+ }
321
+ if (renewalFailure)
322
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'The database upload lease could not be renewed; the source database was not changed.');
323
+ if (uploaded.status < 200 || uploaded.status > 299) {
324
+ if (uploaded.status === 413)
325
+ throw new database_data_plane_1.DatabaseOperationError('bulk_load_too_large', 'The upstream database service rejected the upload size; the source database was not changed.');
326
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'Candidate upload failed. The upstream response was hidden to protect credentials; the source database was not changed.');
327
+ }
328
+ await (0, database_data_plane_1.requestDatabaseOperation)(config, { operation: 'bulk_load_promote', operation_id: operation.id, idempotency_key: key, upload_http_status: uploaded.status }, { post: dependencies.post, controlPlaneTimeoutMs: controlRemaining() });
329
+ promoteAccepted = true;
330
+ let pollDeadlineAt = deadlineAt;
331
+ const pollControlRemaining = () => {
332
+ const value = pollDeadlineAt - clock();
333
+ if (value <= 0)
334
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'Database replacement did not finish before the displayed hard deadline. Retry with the same idempotency key.');
335
+ return Math.min(database_data_plane_1.DEFAULT_DATABASE_CONTROL_PLANE_TIMEOUT_MS, value);
336
+ };
337
+ while (clock() <= pollDeadlineAt) {
338
+ const response = await (0, database_data_plane_1.requestDatabaseOperation)(config, { operation: 'bulk_load_status', operation_id: operation.id }, { post: dependencies.post, controlPlaneTimeoutMs: pollControlRemaining() });
339
+ const status = stableOperation(response);
340
+ pollDeadlineAt = extendedPollDeadline(pollDeadlineAt, deadlineAt, status.deadline_at);
341
+ if (!TERMINAL.has(String(status.phase))) {
342
+ await sleep(POLL_MS);
343
+ continue;
344
+ }
345
+ terminalObserved = true;
346
+ if (status.phase !== 'promoted')
347
+ throw new database_data_plane_1.DatabaseOperationError(typeof status.failure_code === 'string' ? status.failure_code : 'upstream_unavailable', `Database replacement ended in ${status.phase}.`);
348
+ stdout(`Database "${name}" replaced successfully (${String(status.rows_loaded ?? normalized.totalRows)} countable rows). Reacquire database credentials before reconnecting.`);
349
+ return;
350
+ }
351
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'Database replacement did not finish before the displayed hard deadline. Retry status with the same idempotency key.');
352
+ }
353
+ catch (error) {
354
+ if (operationId && !promoteAccepted) {
355
+ try {
356
+ await (0, database_data_plane_1.requestDatabaseOperation)(config, { operation: 'bulk_load_abort', operation_id: operationId, idempotency_key: key }, { post: dependencies.post });
357
+ }
358
+ catch {
359
+ // Preserve the original credential-safe failure. The durable
360
+ // operation deadline and server reconciliation own cleanup.
361
+ }
362
+ }
363
+ if (operationId && promoteAccepted && !terminalObserved) {
364
+ throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', `Promotion was accepted, but status could not be confirmed. Operation ${operationId} remains active; retry with idempotency key ${key}.`);
365
+ }
366
+ throw error;
367
+ }
368
+ finally {
369
+ await normalized.cleanup();
370
+ }
371
+ }
372
+ async function databasePush(name, file, options) {
373
+ const { requireConfigWithWorkspace } = await Promise.resolve().then(() => __importStar(require('../utils/api')));
374
+ await databasePushWithConfig(name, file, options, await requireConfigWithWorkspace());
375
+ }
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.projectViewJsonProjection = projectViewJsonProjection;
6
7
  exports.projectSlugForView = projectSlugForView;
7
8
  exports.formatDeploymentRevision = formatDeploymentRevision;
8
9
  exports.formatProjectView = formatProjectView;
@@ -13,6 +14,47 @@ const chalk_1 = __importDefault(require("chalk"));
13
14
  const api_1 = require("../utils/api");
14
15
  const slug_1 = require("../utils/slug");
15
16
  const source_provenance_1 = require("../utils/source-provenance");
17
+ /**
18
+ * Projects exactly the fields `DeploymentDetail` declares.
19
+ *
20
+ * The server's DeploymentResource serializes more than this — `failure_reason`
21
+ * today, more tomorrow — and that field is always null for a *successful*
22
+ * deployment, which is the only kind this endpoint returns here. Listing the
23
+ * fields explicitly keeps `--json` a documented contract instead of a mirror of
24
+ * whatever the API happens to add next.
25
+ */
26
+ function deploymentJsonProjection(deployment) {
27
+ return {
28
+ id: deployment.id,
29
+ status: deployment.status,
30
+ source_hash: deployment.source_hash,
31
+ metadata_source: deployment.metadata_source ?? null,
32
+ commit_sha: deployment.commit_sha ?? null,
33
+ short_sha: deployment.short_sha ?? null,
34
+ branch: deployment.branch ?? null,
35
+ tag: deployment.tag ?? null,
36
+ commit_subject: deployment.commit_subject ?? null,
37
+ commit_author_date: deployment.commit_author_date ?? null,
38
+ remote_url: deployment.remote_url ?? null,
39
+ dirty: deployment.dirty ?? null,
40
+ default_branch: deployment.default_branch ?? null,
41
+ default_branch_sha: deployment.default_branch_sha ?? null,
42
+ commits_behind: deployment.commits_behind ?? null,
43
+ completed_at: deployment.completed_at ?? null,
44
+ };
45
+ }
46
+ function projectViewJsonProjection(project) {
47
+ const deployment = project.latest_successful_deployment ?? null;
48
+ return {
49
+ slug: project.slug ?? null,
50
+ name: project.name ?? null,
51
+ status: project.status ?? null,
52
+ enabled: project.enabled ?? null,
53
+ deployed_hash: project.deployed_hash ?? null,
54
+ deployment_matches_deployed_hash: project.deployment_matches_deployed_hash ?? false,
55
+ latest_successful_deployment: deployment === null ? null : deploymentJsonProjection(deployment),
56
+ };
57
+ }
16
58
  function projectSlugForView(project, environment) {
17
59
  if (environment === undefined) {
18
60
  return project;
@@ -39,9 +81,7 @@ function metadataSourceLabel(source) {
39
81
  return safe ? labels[safe] ?? safe : null;
40
82
  }
41
83
  function formatDeploymentRevision(deployment) {
42
- const sha = (0, source_provenance_1.sanitizeDisplayText)(deployment.short_sha, 16)
43
- ?? (0, source_provenance_1.sanitizeDisplayText)(deployment.commit_sha, 64);
44
- if (!sha) {
84
+ if ((0, source_provenance_1.revisionSha)(deployment) === null) {
45
85
  const archiveHash = (0, source_provenance_1.sanitizeDisplayText)(deployment.source_hash, 64);
46
86
  return [
47
87
  'No source revision was reported.',
@@ -49,7 +89,7 @@ function formatDeploymentRevision(deployment) {
49
89
  ];
50
90
  }
51
91
  const lines = [
52
- `Revision (Client-reported): ${(0, source_provenance_1.formatRevisionSummary)(deployment)}`,
92
+ `Revision (Client-reported): ${(0, source_provenance_1.formatDetailedRevision)(deployment)}`,
53
93
  ];
54
94
  const source = metadataSourceLabel(deployment.metadata_source);
55
95
  if (source) {
@@ -112,8 +152,13 @@ async function projectViewWithConfig(project, options, config, writeLine = conso
112
152
  }
113
153
  try {
114
154
  const response = await axios_1.default.get(`${config.host}/api/v1/projects/${encodeURIComponent(slug)}?include=deployment`, { headers: (0, api_1.getApiHeaders)(config) });
115
- for (const line of formatProjectView(response.data)) {
116
- writeLine(line);
155
+ if (options.json) {
156
+ writeLine(JSON.stringify(projectViewJsonProjection(response.data), null, 2));
157
+ }
158
+ else {
159
+ for (const line of formatProjectView(response.data)) {
160
+ writeLine(line);
161
+ }
117
162
  }
118
163
  }
119
164
  catch (error) {
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatDetailedRevision = void 0;
6
7
  exports.buildRunListParams = buildRunListParams;
7
8
  exports.runs = runs;
8
9
  exports.summaryStatusLabel = summaryStatusLabel;
9
10
  exports.detailedOutcomeTag = detailedOutcomeTag;
10
11
  exports.formatRevisionCell = formatRevisionCell;
11
- exports.formatDetailedRevision = formatDetailedRevision;
12
12
  exports.displaySummaryTable = displaySummaryTable;
13
13
  exports.displayDetailedList = displayDetailedList;
14
14
  const axios_1 = __importDefault(require("axios"));
@@ -16,6 +16,8 @@ const chalk_1 = __importDefault(require("chalk"));
16
16
  const api_1 = require("../utils/api");
17
17
  const table_1 = require("../utils/table");
18
18
  const source_provenance_1 = require("../utils/source-provenance");
19
+ var source_provenance_2 = require("../utils/source-provenance");
20
+ Object.defineProperty(exports, "formatDetailedRevision", { enumerable: true, get: function () { return source_provenance_2.formatDetailedRevision; } });
19
21
  /**
20
22
  * Build the params object for GET /api/v1/runs.
21
23
  * Extracted as a pure function so it can be unit-tested without mocking axios.
@@ -126,14 +128,8 @@ function detailedOutcomeTag(run) {
126
128
  return ' [DEGRADED]';
127
129
  return '';
128
130
  }
129
- function revisionSha(revision) {
130
- if (!revision)
131
- return null;
132
- return (0, source_provenance_1.sanitizeDisplayText)(revision.short_sha, 16)
133
- ?? (0, source_provenance_1.sanitizeDisplayText)(revision.commit_sha, 64);
134
- }
135
131
  function formatRevisionCell(revision) {
136
- const sha = revisionSha(revision);
132
+ const sha = (0, source_provenance_1.revisionSha)(revision);
137
133
  if (!sha)
138
134
  return '-';
139
135
  const dirty = revision?.dirty === true ? '*' : revision?.dirty === false ? '' : '?';
@@ -144,20 +140,6 @@ function formatRevisionCell(revision) {
144
140
  : '';
145
141
  return (0, table_1.sanitizeCell)(`${sha}${dirty}${behind}`);
146
142
  }
147
- function formatDetailedRevision(revision) {
148
- const sha = revisionSha(revision);
149
- if (!sha)
150
- return 'unknown';
151
- const states = [revision?.dirty === true
152
- ? 'DIRTY'
153
- : revision?.dirty === false ? 'clean' : 'dirty state unknown'];
154
- const branch = (0, source_provenance_1.sanitizeDisplayText)(revision?.default_branch, 255);
155
- if (branch && typeof revision?.commits_behind === 'number'
156
- && Number.isSafeInteger(revision.commits_behind) && revision.commits_behind > 0) {
157
- states.push(`${revision.commits_behind} behind origin/${branch} at deploy`);
158
- }
159
- return (0, table_1.sanitizeCell)(`${sha} (${states.join(', ')})`);
160
- }
161
143
  function displaySummaryTable(runsList, projectName) {
162
144
  const header = projectName ? `Recent runs for "${projectName}":` : 'Recent runs:';
163
145
  console.log(chalk_1.default.blue(header));
@@ -208,7 +190,7 @@ function displayDetailedList(runsList, projectName) {
208
190
  console.log(` Status: ${statusColor(status)}${chalk_1.default.gray(exitStr)}`);
209
191
  console.log(` Trigger: ${chalk_1.default.gray(run.triggered_by || '-')}`);
210
192
  if (Object.prototype.hasOwnProperty.call(run, 'deployed_revision')) {
211
- console.log(` Revision (latest session): ${chalk_1.default.gray(formatDetailedRevision(run.deployed_revision))}`);
193
+ console.log(` Revision (latest session): ${chalk_1.default.gray((0, source_provenance_1.formatDetailedRevision)(run.deployed_revision))}`);
212
194
  }
213
195
  // Timeline
214
196
  if (run.timeline) {
@@ -11,6 +11,7 @@ exports.errorMessage = errorMessage;
11
11
  const axios_1 = __importDefault(require("axios"));
12
12
  const chalk_1 = __importDefault(require("chalk"));
13
13
  const api_1 = require("../utils/api");
14
+ const source_provenance_1 = require("../utils/source-provenance");
14
15
  async function runView(runId, options) {
15
16
  if (!/^\d+$/.test(runId)) {
16
17
  console.error(chalk_1.default.red(`Invalid run id: "${runId}" (run ids are numeric — see \`solidactions run list\`).`));
@@ -96,6 +97,9 @@ async function runView(runId, options) {
96
97
  steps: flatSteps,
97
98
  logs: logsResponse.data.logs || '',
98
99
  };
100
+ if (Object.prototype.hasOwnProperty.call(runData, 'deployed_revision')) {
101
+ output.deployed_revision = runData.deployed_revision;
102
+ }
99
103
  if (runData.output)
100
104
  output.output = runData.output;
101
105
  if (runData.error)
@@ -137,6 +141,9 @@ function displayFullView(runData, timeline, steps, logsData) {
137
141
  const exitStr = exitCode !== null && exitCode !== undefined ? ` (exit ${exitCode})` : '';
138
142
  console.log(` Status: ${statusColor(status)}${chalk_1.default.gray(exitStr)}`);
139
143
  console.log(` Trigger: ${chalk_1.default.gray(runData.triggered_by || '-')}`);
144
+ if (Object.prototype.hasOwnProperty.call(runData, 'deployed_revision')) {
145
+ console.log(` Revision (latest session): ${chalk_1.default.gray((0, source_provenance_1.formatDetailedRevision)(runData.deployed_revision))}`);
146
+ }
140
147
  // Timeline
141
148
  displayTimeline(runData, timeline, steps);
142
149
  // Steps
package/dist/index.js CHANGED
@@ -93,6 +93,7 @@ const crew_env_map_database_1 = require("./commands/crew-env-map-database");
93
93
  const state_1 = require("./commands/state");
94
94
  const workflow_view_1 = require("./commands/workflow-view");
95
95
  const database_1 = require("./commands/database");
96
+ const database_push_1 = require("./commands/database-push");
96
97
  const config_1 = require("./utils/config");
97
98
  // eslint-disable-next-line @typescript-eslint/no-var-requires
98
99
  const pkg = require('../package.json');
@@ -305,6 +306,22 @@ database
305
306
  .action(async (name, file, options) => {
306
307
  await (0, database_1.databaseImport)(name, file, options);
307
308
  });
309
+ database
310
+ .command('push')
311
+ .description('Replace from a private WAL/4096-byte/auto-vacuum NONE snapshot; source file is unchanged; countable rows exclude internal, virtual, and shadow tables')
312
+ .argument('<database>', 'Database name')
313
+ .argument('<file.db>', 'Complete SQLite database file')
314
+ .requiredOption('-y, --yes', 'Acknowledge destructive replacement')
315
+ .option('--allow-empty', 'Allow a database with zero countable rows')
316
+ .option('--idempotency-key <uuid>', 'Reuse a bulk-load operation UUID')
317
+ .addHelpText('after', `
318
+ The source file is unchanged. Push uploads a private normalized snapshot using
319
+ WAL mode, 4096-byte pages, and auto-vacuum NONE; its byte size can differ from
320
+ the source. Countable rows include ordinary user tables only. Internal,
321
+ virtual, and shadow tables are excluded from the count.`)
322
+ .action(async (name, file, options) => {
323
+ await (0, database_push_1.databasePush)(name, file, options);
324
+ });
308
325
  // =============================================================================
309
326
  // project <subcommand>
310
327
  // =============================================================================
@@ -314,6 +331,7 @@ project
314
331
  .description('View project status and the client-reported deployed revision')
315
332
  .argument('<project>', 'Project family slug or name')
316
333
  .option('-e, --env <environment>', 'Target environment (production/staging/dev). Defaults to dev.', 'dev')
334
+ .option('--json', 'Output as JSON')
317
335
  .addHelpText('after', `
318
336
  Defaults to dev: <project> is normalized as a project family and "-dev" is
319
337
  appended. Use --env staging for the "-staging" target. Use --env production to
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sanitizeDisplayText = sanitizeDisplayText;
7
7
  exports.formatRevisionSummary = formatRevisionSummary;
8
+ exports.revisionSha = revisionSha;
9
+ exports.formatDetailedRevision = formatDetailedRevision;
8
10
  exports.sanitizeRemoteUrl = sanitizeRemoteUrl;
9
11
  exports.collectSourceMetadata = collectSourceMetadata;
10
12
  exports.shouldCollectGitMetadata = shouldCollectGitMetadata;
@@ -16,6 +18,7 @@ const os_1 = __importDefault(require("os"));
16
18
  const path_1 = __importDefault(require("path"));
17
19
  const child_process_1 = require("child_process");
18
20
  const form_data_1 = __importDefault(require("form-data"));
21
+ const table_1 = require("./table");
19
22
  const DISPLAY_FORMATTING = /[\x00-\x1f\x7f\u061c\u200b-\u200f\u202a-\u202e\u2060\u2066-\u2069\ufeff]/g;
20
23
  const SHA_PATTERN = /^[0-9a-f]{7,64}$/i;
21
24
  const STRICT_ISO_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
@@ -46,6 +49,26 @@ function formatRevisionSummary(metadata) {
46
49
  }
47
50
  return `${sha} (${dirtyLabel(typeof metadata.dirty === 'boolean' ? metadata.dirty : null)})`;
48
51
  }
52
+ function revisionSha(revision) {
53
+ if (!revision)
54
+ return null;
55
+ return sanitizeDisplayText(revision.short_sha, 16)
56
+ ?? sanitizeDisplayText(revision.commit_sha, 64);
57
+ }
58
+ function formatDetailedRevision(revision) {
59
+ const sha = revisionSha(revision);
60
+ if (!sha)
61
+ return 'unknown';
62
+ const states = [revision?.dirty === true
63
+ ? 'DIRTY'
64
+ : revision?.dirty === false ? 'clean' : 'dirty state unknown'];
65
+ const branch = sanitizeDisplayText(revision?.default_branch, 255);
66
+ if (branch && typeof revision?.commits_behind === 'number'
67
+ && Number.isSafeInteger(revision.commits_behind) && revision.commits_behind > 0) {
68
+ states.push(`${revision.commits_behind} behind origin/${branch} at deploy`);
69
+ }
70
+ return (0, table_1.sanitizeCell)(`${sha} (${states.join(', ')})`);
71
+ }
49
72
  function shaValue(value) {
50
73
  const sanitized = displayValue(value, 64);
51
74
  return sanitized && SHA_PATTERN.test(sanitized) ? sanitized : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidactions/cli",
3
- "version": "3.10.2",
3
+ "version": "3.12.0",
4
4
  "description": "SolidActions CLI - Deploy and manage workflow automation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {