qwenpaw-data-cli 0.3.4__tar.gz → 0.4.0__tar.gz

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 (42) hide show
  1. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/.gitignore +5 -0
  2. qwenpaw_data_cli-0.4.0/PKG-INFO +425 -0
  3. qwenpaw_data_cli-0.4.0/README.md +396 -0
  4. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/pyproject.toml +8 -4
  5. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/commands/__init__.py +9 -0
  6. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/commands/chat.py +47 -0
  7. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/commands/doctor.py +56 -16
  8. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/commands/execute.py +41 -0
  9. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/commands/migration.py +529 -0
  10. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/commands/plan.py +46 -0
  11. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/commands/run.py +42 -0
  12. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/commands/semantic.py +94 -66
  13. qwenpaw_data_cli-0.4.0/src/qwenpaw_data/cli/host.py +177 -0
  14. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/logging_config.py +28 -6
  15. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/main.py +22 -7
  16. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/util.py +0 -17
  17. qwenpaw_data_cli-0.4.0/tests/test_cli_commands.py +22 -0
  18. qwenpaw_data_cli-0.4.0/tests/test_cli_host.py +135 -0
  19. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_cli_logging.py +2 -1
  20. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_cli_semantic.py +136 -29
  21. qwenpaw_data_cli-0.4.0/tests/test_cli_sop.py +143 -0
  22. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_doctor.py +82 -3
  23. qwenpaw_data_cli-0.4.0/tests/test_migration.py +407 -0
  24. qwenpaw_data_cli-0.3.4/PKG-INFO +0 -126
  25. qwenpaw_data_cli-0.3.4/README.md +0 -99
  26. qwenpaw_data_cli-0.3.4/src/qwenpaw_data/cli/commands/__init__.py +0 -9
  27. qwenpaw_data_cli-0.3.4/src/qwenpaw_data/cli/commands/chat.py +0 -56
  28. qwenpaw_data_cli-0.3.4/src/qwenpaw_data/cli/commands/execute.py +0 -54
  29. qwenpaw_data_cli-0.3.4/src/qwenpaw_data/cli/commands/plan.py +0 -62
  30. qwenpaw_data_cli-0.3.4/src/qwenpaw_data/cli/commands/run.py +0 -55
  31. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/LICENSE +0 -0
  32. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/NOTICE +0 -0
  33. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/__init__.py +0 -0
  34. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/commands/datasource.py +0 -0
  35. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/commands/mcp.py +0 -0
  36. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/src/qwenpaw_data/cli/env.py +0 -0
  37. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/.gitkeep +0 -0
  38. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/conftest.py +0 -0
  39. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_cli_datasource.py +0 -0
  40. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_cli_env.py +0 -0
  41. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_cli_mcp.py +0 -0
  42. {qwenpaw_data_cli-0.3.4 → qwenpaw_data_cli-0.4.0}/tests/test_permission_mode.py +0 -0
@@ -234,6 +234,11 @@ yarn-debug.log*
234
234
  yarn-error.log*
235
235
  .vite/
236
236
  dist-ssr/
237
+ dist-embedded/
238
+ *.chat-setup/
239
+ *.chat-setup.json
240
+ *.services.lock/
241
+ *.services.json
237
242
 
238
243
  # Common misspelling of AGENTS.md.
239
244
  AGENTS.md
@@ -0,0 +1,425 @@
1
+ Metadata-Version: 2.5
2
+ Name: qwenpaw-data-cli
3
+ Version: 0.4.0
4
+ Summary: Standalone command-line interface for QwenPaw-Data.
5
+ Project-URL: Homepage, https://github.com/agentscope-ai/QwenPaw-Data
6
+ Project-URL: Documentation, https://github.com/agentscope-ai/QwenPaw-Data/tree/main/packages/qwenpaw-data-cli
7
+ Project-URL: Repository, https://github.com/agentscope-ai/QwenPaw-Data
8
+ Project-URL: Issues, https://github.com/agentscope-ai/QwenPaw-Data/issues
9
+ Project-URL: Changelog, https://github.com/agentscope-ai/QwenPaw-Data/blob/main/CHANGELOG.md
10
+ Author: QwenPaw-Data Contributors
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Keywords: ai-agents,automation,cli,data-analysis
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Environment :: Console
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Database
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Requires-Python: >=3.11
26
+ Requires-Dist: python-dotenv<2.0,>=1.2.2
27
+ Requires-Dist: qwenpaw-data-host-core<0.5,>=0.4
28
+ Description-Content-Type: text/markdown
29
+
30
+ # qwenpaw-data-cli
31
+
32
+ Standalone command-line interface for QwenPaw Data.
33
+
34
+ This package provides the `qwenpaw-data` command for datasource administration,
35
+ semantic configuration, deployment diagnostics, and remote Host conversations.
36
+ The [Console](../qwenpaw-data-console/README.md) remains the full interactive UI.
37
+
38
+ The command automatically loads `QWENPAW_DATA_ENV_FILE` when set. Otherwise, an
39
+ editable checkout is discovered from the CLI package location and the
40
+ repository root `.env` is loaded. Existing process environment variables take
41
+ precedence over dotenv values. Outside an editable checkout, the current
42
+ working directory is used as the fallback configuration root.
43
+
44
+ Available command groups:
45
+
46
+ - `datasource`
47
+ - `semantic`
48
+ - `doctor`
49
+ - `run` / `chat` (explicit Host-service connection)
50
+ - `plan` (prompt-only SOP generation through Host, without execution)
51
+ - `execute` (client-scheduled SOP DAG execution through Host)
52
+ - `migration` (offline JSON inspection, verified backup and read-only preparation)
53
+
54
+ `run` and `chat` now use the current Host API, not the legacy in-process DAG
55
+ runtime. Select an already-running Host explicitly:
56
+
57
+ ```bash
58
+ qwenpaw-data run --host-url http://127.0.0.1:8000 "Summarize sales"
59
+ qwenpaw-data chat --host-url http://127.0.0.1:8000
60
+ qwenpaw-data run --host-url http://127.0.0.1:8000 --session-id <id> --no-stream "Continue"
61
+ ```
62
+
63
+ `QWENPAW_DATA_HOST_URL` can supply the origin; `QWENPAW_DATA_HOST_TOKEN` supplies
64
+ the Host API token or user JWT without putting it in command-line arguments.
65
+ Use HTTPS for remote hosts. The client does not follow redirects or inherit HTTP
66
+ proxy settings. It does not forward DataBridge credentials or caller-selected
67
+ user identities. Model, sandbox and permission policies belong to the server;
68
+ the old `--workspace` / `--permission-mode` flags are not supported in this mode.
69
+
70
+ Session IDs are printed to stderr and retained on the server for continuation.
71
+ New CLI sessions disable clarification; an existing session requiring it must
72
+ be continued in Console. Tool approval prompts default to deny, and non-TTY
73
+ input always denies. Ctrl+C or an interrupted event stream requests cancellation
74
+ of the admitted turn; a disconnected stream is never reported as success.
75
+ If admission itself loses its response, the client cannot know the new chat ID;
76
+ inspect the session in Console before retrying to avoid duplicate work.
77
+
78
+ `plan` returns the OSS SOP YAML contract (`name`, `description`,
79
+ `expected_outcome`, and `nodes` with stable IDs and acyclic `deps`):
80
+
81
+ ```bash
82
+ qwenpaw-data plan --host-url http://127.0.0.1:8000 "Plan a sales analysis" -o sales.yaml
83
+ ```
84
+
85
+ Planning uses the authorized session's model preferences, but does not start an
86
+ agent, allocate an execution workspace, query a datasource, or run tools. Supply
87
+ schema/facts in the prompt if needed; otherwise the generated plan must include
88
+ discovery steps. The datasource ID is context, not proof of schema inspection.
89
+ `--output` exclusively creates a new file and refuses to overwrite existing data.
90
+ This does not restore the legacy tool-assisted planner.
91
+
92
+ Execute a validated SOP using a deterministic dependency scheduler:
93
+
94
+ ```bash
95
+ qwenpaw-data execute --host-url http://127.0.0.1:8000 sales.yaml
96
+ ```
97
+
98
+ The client starts one Host turn per node, sequentially in topological order.
99
+ A successor cannot start until all predecessors have successful terminal
100
+ responses. Failed, cancelled or truncated turns abort execution; Ctrl+C stops
101
+ the active turn. Node IDs and the session ID are printed to stderr. Tool approval
102
+ uses the same deny-by-default handling as `run`. Validate malformed/cyclic SOPs
103
+ before any session creation. A new dedicated session is the default;
104
+ `--session-id` uses that session's existing datasource and rejects an accompanying
105
+ `--datasource-id` override.
106
+
107
+ This schedules turns, not every tool action within them; a successful terminal
108
+ response is not independent verification of the business outcome. Completed
109
+ turns remain in Host history, but DAG checkpoint/resume, automatic retries,
110
+ parallel execution and rollback of tool side effects are not implemented.
111
+ Rerunning the file executes every node again; inspect history before retrying.
112
+
113
+ **Remaining compatibility gaps:** the old in-process
114
+ `QwenPawDataHost` interface is not restored. Remote `run` is a normal agent turn,
115
+ not a claim of legacy plan-and-execute SOP equivalence.
116
+
117
+ Run `qwenpaw-data doctor` before the first task to check supported Python/Node
118
+ versions, uv, model and authentication configuration, QwenPaw Data Home, DataBridge
119
+ MCP, Docker, Neo4j, and the DataBridge API. `qwenpaw-data doctor --json` emits a
120
+ machine-readable report that reports whether credentials are set without
121
+ printing their values.
122
+
123
+ `datasource` manages the datasources configured in DataBridge:
124
+
125
+ ```bash
126
+ qwenpaw-data datasource list
127
+ qwenpaw-data datasource get <datasource_id> [--show-config]
128
+ qwenpaw-data datasource create --name <n> --type <t> \
129
+ (--config-file <f.json> | --config '<json>') [--test]
130
+ qwenpaw-data datasource update <datasource_id> [--name <n>] [--type <t>] [--config-file <f>]
131
+ qwenpaw-data datasource delete <datasource_id> [--yes]
132
+ qwenpaw-data datasource test (<datasource_id> | --type <t> --config-file <f>)
133
+ ```
134
+
135
+ Set `QWENPAW_DATA_CM_BASE_URL` to the DataBridge origin. It defaults to
136
+ `http://127.0.0.1:8765`. Every command emits JSON and masks saved passwords,
137
+ AccessKeys, and STS tokens before writing anything to stdout; there is no
138
+ option that prints stored credentials. `list` uses the credential-free
139
+ discovery endpoint, while the management subcommands call the
140
+ `/api/semantic-config` routes and need an API key with the
141
+ `credentials:manage` scope when scoped keys are configured
142
+ (`QWENPAW_DATA_CLIENT_API_TOKEN` or `QWENPAW_DATA_API_TOKEN`).
143
+
144
+ `semantic` manages the DataBridge semantic configuration layer. The seven
145
+ resources `domain`, `dataset`, `column`, `dimension`, `binding`, `metric`,
146
+ and `formula` share the same verbs:
147
+
148
+ ```bash
149
+ qwenpaw-data semantic <resource> list [filters] [--page N --size N | --all]
150
+ qwenpaw-data semantic <resource> get <id>
151
+ qwenpaw-data semantic <resource> create (field flags | --file payload.json)
152
+ qwenpaw-data semantic <resource> update <id> (field flags | --file payload.json)
153
+ qwenpaw-data semantic <resource> delete <id> [--yes]
154
+ ```
155
+
156
+ `binding` and `formula` also support dataset-level batch deletion with
157
+ `delete --dataset-id <id>`. Reads require the `query` scope and writes the
158
+ `manage` scope. Two more subcommands cover import and publishing:
159
+
160
+ ```bash
161
+ # Import a semantic configuration workbook into the draft store
162
+ qwenpaw-data semantic import --file demo_semantic_config.xlsx
163
+
164
+ # Publish (weave) the configuration into the graph store
165
+ qwenpaw-data semantic weave submit --datasource-id <id> [--mode FULL] [--wait]
166
+ qwenpaw-data semantic weave list [--datasource-name <n>] [--task-name <n>]
167
+ qwenpaw-data semantic weave kill <task_id>
168
+ ```
169
+
170
+ With `--wait` the CLI polls until the task reaches a terminal state
171
+ (`success`, `failed`, `killed`), printing progress to stderr and the final
172
+ task record as JSON to stdout; the exit code is `0` only for `success`.
173
+
174
+ Remote agent commands use the models configured in Host preferences. The CLI
175
+ does not forward local model credentials or override the server's model selection.
176
+
177
+ ## Find a pre-upgrade local SQLite store
178
+
179
+ `qwenpaw-data migration discover` checks the current runtime home, or pass
180
+ `--source-home /absolute/old-home`. It reports known candidate paths (including
181
+ the v0.3 Host default `host/host.db`) alongside the current local default
182
+ `control_plane.db`, even when both exist. It does not open either database,
183
+ search arbitrary directories, inspect rows, or claim that an import has run.
184
+ With an explicit DB URL, the reported default is not necessarily your active DB.
185
+
186
+ For now, stop the old writers and preserve the **whole old home**, including
187
+ SQLite sidecars, workspace files and encryption keys. To access old records,
188
+ use the matching older release on a backup. Do not rename the old database or
189
+ point the new Host at it: old owner IDs and credentials need an explicit
190
+ conversion. The JSON workflow below is not a SQLite importer.
191
+
192
+ ### Requirements for a future SQLite importer
193
+
194
+ Only discovery is implemented for the `oss-host-sqlite-v0.3` layout. New layouts
195
+ get their own ID; do not change the meaning of an existing one. Before shipping
196
+ a conversion for any layout, the [OSS adapter decision](../../docs/adr/0001-internal-baseline-and-oss-adapters.md)
197
+ requires this sequence:
198
+
199
+ 1. Stop source and target writers. Verify recoverable backups and retain any externally supplied encryption keys separately.
200
+ 2. Dry-run against a copy. Bind the plan to the source, target and layout ID; show the mapping from old owners to users, tenants and workspaces, and report unreadable credentials or unmapped records. Do not print secrets.
201
+ 3. Require explicit approval of that plan. Import into the specified target without rewriting the source or running historical cron jobs. Track progress so a restart cannot duplicate records.
202
+ 4. Verify through the new Host after restart: read sessions and files as the intended owner, check masked model settings and confirm job state. Demonstrate recovery or rollback on a copy before offering the importer. A target file's existence is not a migration receipt.
203
+
204
+ ## Legacy JSON migration
205
+
206
+ `migration inspect`, `backup`, `plan`, `provision-key`, `prepare`, `apply`,
207
+ `recover`, `check-rollback` and `rollback` provide an explicit offline workflow.
208
+ Writes currently require POSIX, an initialized SQLite/PostgreSQL target and all
209
+ application writers stopped. Use separate source, backup and target homes;
210
+ source data is never overwritten. Begin with read-only preparation:
211
+
212
+ ```bash
213
+ qwenpaw-data migration inspect --source-home /absolute/old-home --identity-map identities.json
214
+ qwenpaw-data migration backup --source-home /absolute/old-home --destination /absolute/backup --source-stopped
215
+ qwenpaw-data migration plan --source-home /absolute/old-home --backup /absolute/backup \
216
+ --target-home /absolute/new-home --identity-map identities.json --source-stopped \
217
+ --target-key-env MIGRATION_TARGET_KEY --source-key-env MIGRATION_SOURCE_KEY \
218
+ --context-trigger-ratio 0.8 --context-reserve-ratio 0.1
219
+ ```
220
+
221
+ Set the named key variables securely before invoking the command; arguments are
222
+ variable **names**, never secret values. The target key is 32 bytes encoded as
223
+ hex; the old key accepts at least 32 bytes. Omit `--source-key-env` only if old
224
+ credentials are plaintext. Keep both keys separately: backups do not capture
225
+ environment secrets, and planning does not provision the target master key.
226
+ Use the actual target runtime ratio defaults, not necessarily the example values.
227
+
228
+ Identity mapping format:
229
+
230
+ ```json
231
+ {"version":1,"users":{"old-user":{"user_id":"new-user","tenant_id":"tenant","workspace_id":"workspace"}}}
232
+ ```
233
+
234
+ For extra models missing context size, supply `--model-context-sizes models.json`
235
+ with `{"version":1,"users":{"old-user":{"provider/model":12345}}}`. Values must
236
+ be correct for the selected model; unknown or unused additions are rejected.
237
+ `--disable-cron` explicitly consents to **propose** imported jobs as disabled.
238
+ Planning never runs them. Removed catalog models, old DAG data, agent state and
239
+ unassigned shared workspace files remain explicit blockers. Known CLI logs and
240
+ recognized empty lock files are retained only in the verified backup and listed
241
+ as notices; unknown/nonempty lock files require explicit disposition.
242
+
243
+ Optionally add `--target-db-env MIGRATION_TARGET_DB --target-stopped` to `plan`
244
+ after stopping target writers. Set that variable securely to the **already
245
+ initialized target control-plane/Host database** URL. No ambient database setting
246
+ is used. Supported URLs are file `sqlite:////absolute/target.sqlite` (no query
247
+ options) or synchronous `postgresql+psycopg://.../database` (the existing
248
+ `qwenpaw-data-auth[postgres]` optional driver; host, user and database must be
249
+ explicit). The check validates
250
+ required columns/primary keys, active users/tenants/workspaces and native Auth
251
+ roles, then checks all prepared primary keys for existing rows. Conflicts block
252
+ even if values are identical. Preference-only users also require authorization.
253
+ It does not create accounts, tables, files, keys, or overwrite/merge rows.
254
+
255
+ SQLite must be an existing regular file, with no `-wal`, `-shm` or `-journal`
256
+ sidecars; checkpoint/close it through its owning application first. The checker
257
+ never deletes or recovers journals. Its [immutable read-only connection](https://www.sqlite.org/uri.html)
258
+ requires the stopped-writer acknowledgement and checks for file changes.
259
+ PostgreSQL checks use a [read-only repeatable-read transaction](https://www.postgresql.org/docs/current/sql-set-transaction.html)
260
+ with query timeouts and rollback; this is not a promise of zero server-side disk
261
+ activity. PostgreSQL-compatible/Hologres services are not yet accepted as tested
262
+ targets. The selected database must be the one the target deployment will use.
263
+
264
+ Exit `0` means conversion and any requested target checks passed, `2` means there
265
+ are reported blockers, and `1` means the command failed (including unavailable
266
+ or incompatible target schema). Even with `conversion_complete: true` and
267
+ `target_validation.target_checks_passed: true`, the plan reports `import_ready:
268
+ false`: this read-only command does not save an executable plan or reserve the
269
+ target. Use the explicit saved-plan workflow below; import revalidates mutable state.
270
+ Reports contain counts/paths and safe errors, not source payloads or credentials.
271
+
272
+ ### Explicit local master-key configuration
273
+
274
+ For a **local key-file deployment on POSIX**, stop target writers and explicitly
275
+ configure the selected key in an existing target home:
276
+
277
+ ```bash
278
+ qwenpaw-data migration provision-key --target-home /absolute/new-home \
279
+ --target-key-env MIGRATION_TARGET_KEY --target-db-env MIGRATION_TARGET_DB \
280
+ --target-stopped
281
+ ```
282
+
283
+ Unlike `plan`, this command **writes a private `preferences.key` file**. It first
284
+ authenticates all existing encrypted provider credentials in the explicitly
285
+ selected target database, including other users, using that key. Malformed,
286
+ wrong-key or oversized credentials and missing schema block publication; existing
287
+ plaintext credentials are counted, not rewritten. The current scan limit is
288
+ 100,000 records and 64 KiB per credential. SQLite/PostgreSQL selection and stopped
289
+ writer requirements are the same as for target preflight.
290
+
291
+ The home must exist, be owned by the current user and not be group/world writable.
292
+ The command publishes a complete, synced, mode-0600 key without replacement.
293
+ An identical private existing key is verified without modification; different,
294
+ malformed, public, symlinked or hard-linked keys are refused, not repaired. On an
295
+ interrupted operation, inspect the target before retrying; an already-published
296
+ key is retained. Keep a separate secure backup of this key.
297
+
298
+ This does **not** configure deployment environment variables or verify that other
299
+ services use this home/key. Host runtime variables
300
+ `QWENPAW_DATA_PREFERENCES_MASTER_SECRET` / `QWENPAW_DATA_PREFS_MASTER_SECRET` take
301
+ precedence over the local file; production requires environment provisioning.
302
+ Configure those secrets consistently outside the CLI for every service sharing
303
+ the database. Native Windows ACL acceptance and automatic deployment-secret
304
+ provisioning are not implemented. No SQL rows are written, and `import_ready`
305
+ remains false.
306
+
307
+ ### Save, apply and recover the exact plan
308
+
309
+ Initialize accounts, memberships and the current Host schema separately, including
310
+ `legacy_import_targets`, `legacy_import_runs` and `legacy_import_rollbacks`.
311
+ Migration never creates accounts, repairs schema or changes the runtime database
312
+ selection. Stop **all** target writers, including services on other machines.
313
+ Provision the target key first. `prepare`/`apply`/`recover` check Host environment
314
+ key precedence or the already provisioned key in the explicit target home, without
315
+ generating a key. `--deployment-config-confirmed` additionally acknowledges that
316
+ every service will use the selected home, database and key; the CLI cannot attest
317
+ another process's environment. Production requires an environment-provisioned key.
318
+
319
+ Create a private mode-0700 plan directory outside source, backup and target. Choose
320
+ one unique lowercase 32-hex-character run ID and retain it. Example Bash workflow
321
+ (named key/DB variables must already be securely configured):
322
+
323
+ ```bash
324
+ MIGRATION_RUN_ID="$(python -c 'import uuid; print(uuid.uuid4().hex)')"
325
+ migration_target=(--target-home /absolute/new-home --target-db-env MIGRATION_TARGET_DB
326
+ --target-key-env MIGRATION_TARGET_KEY --target-stopped)
327
+
328
+ qwenpaw-data migration prepare "${migration_target[@]}" \
329
+ --source-home /absolute/old-home --backup /absolute/backup --source-stopped \
330
+ --identity-map identities.json --source-key-env MIGRATION_SOURCE_KEY \
331
+ --context-trigger-ratio 0.8 --context-reserve-ratio 0.1 \
332
+ --recovery-plan /absolute/private/plan.enc --run-id "$MIGRATION_RUN_ID" \
333
+ --deployment-config-confirmed
334
+
335
+ qwenpaw-data migration apply "${migration_target[@]}" \
336
+ --recovery-plan /absolute/private/plan.enc --confirm-run-id "$MIGRATION_RUN_ID" \
337
+ --deployment-config-confirmed
338
+
339
+ # After an interrupted/ambiguous import, keep writers stopped and use the SAME plan:
340
+ qwenpaw-data migration recover "${migration_target[@]}" \
341
+ --recovery-plan /absolute/private/plan.enc --confirm-run-id "$MIGRATION_RUN_ID" \
342
+ --deployment-config-confirmed
343
+ ```
344
+
345
+ Add the same model-size and explicit cron-disabling flags used during `plan`.
346
+ `prepare` revalidates conversion, Auth, conflicts and all existing credentials;
347
+ it writes only a persistent database identity token, lock file and private
348
+ authenticated encrypted plan, not business rows or workspace files. Existing
349
+ plans are refused rather than regenerated: randomized ciphertext and timestamps
350
+ must remain exact. If preparation fails, inspect its output before retrying.
351
+ The saved plan is bound to the home inode, database selection and recorded token.
352
+ Database clones/restores require operator review, even at the same URL.
353
+
354
+ `apply` and `recover` share the same idempotent coordinator. Source may be offline;
355
+ an uncommitted import requires the independent backup online and verified. SQL
356
+ rows and their receipt commit together around file publication; SQLite recovery
357
+ uses its engine, never manual journal deletion. Files are mode-0600 non-overwriting
358
+ hard links from verified staging, requiring the same filesystem. Already committed
359
+ imports only verify, never repair changed rows, moved files or modified bytes.
360
+ Both commands require the exact run ID; connection errors never justify cleanup.
361
+
362
+ ### Check and roll back an unchanged import
363
+
364
+ ```bash
365
+ qwenpaw-data migration check-rollback "${migration_target[@]}" \
366
+ --recovery-plan /absolute/private/plan.enc
367
+ qwenpaw-data migration rollback "${migration_target[@]}" \
368
+ --recovery-plan /absolute/private/plan.enc --confirm-run-id "$MIGRATION_RUN_ID"
369
+ ```
370
+
371
+ `check-rollback` verifies backup, unchanged SQL and file evidence, then scans known
372
+ native and conservative JSON references. Exit `2` reports dependencies. Unknown
373
+ tables/columns, triggers, added foreign keys and scan-budget excesses refuse the
374
+ operation. This does not prove external dependencies or arbitrary references in
375
+ prose/code; review those before confirming rollback. It may create the home lock
376
+ file but does not change business rows or workspace files.
377
+
378
+ `rollback` repeats dependency checks inside its deletion transaction. It records
379
+ encrypted local intent before SQL commit, then requires a durable SQL rollback
380
+ receipt before unlinking only unchanged, originally owned published files. An
381
+ ambiguous response retains files; retry **rollback**, not `recover`, with the same
382
+ plan and run ID. Crashes between unlinks are resumable; a replaced, moved, modified
383
+ or additionally linked file is never adopted or removed. Original and rollback
384
+ SQL receipts remain permanently; pending rollback intent and committed rollback
385
+ both forbid forward replay. Rollback uses the original selected key even if the
386
+ runtime key configuration was subsequently changed.
387
+
388
+ ### Retention and acceptance boundary
389
+
390
+ Keep source, independent backup, original keys, encrypted plan, private staging,
391
+ publication/rollback journals and SQL receipts. No automatic staging or directory
392
+ cleanup is provided: directories are only observed, never claimed as removable.
393
+ The retained staging copy shares an inode with a published file, so it is **not an
394
+ independent backup**; application changes cause later verification/rollback to
395
+ refuse. Do not unlink the migration lock. Interrupted initial journal creation,
396
+ unexpected links or eight incomplete staging attempts require operator inspection.
397
+
398
+ Fresh-process SQLite/PostgreSQL acceptance covers 15 tables and two files through
399
+ the actual CLI workflow, plus coordinator crash drills at copy, publication, SQL
400
+ commit, rollback intent, every unlink and completion. Native Host reads across
401
+ restart were verified separately. This does not prove external backends, remote
402
+ deployment configuration or native Windows support. The home lock excludes only
403
+ cooperating migration invocations; applications must remain stopped throughout.
404
+
405
+ ## Output and logs
406
+
407
+ The CLI writes streamed agent events, final answers, and execution summaries to
408
+ stdout. Interactive prompts and concise command errors remain explicit CLI
409
+ output on the terminal rather than raw log records. Python logging is written
410
+ to `${QWENPAW_DATA_HOME}/host/qwenpaw_data.log` at `INFO` level and above;
411
+ `QWENPAW_DATA_HOME` defaults to `~/.qwenpaw-data`.
412
+
413
+ The log rotates at 50 MB and keeps two backups as `qwenpaw_data.log.1` and
414
+ `qwenpaw_data.log.2`. Rotation assumes one active CLI process per `QWENPAW_DATA_HOME`.
415
+ Direct users of `qwenpaw-data-host-core` continue to own their process logging
416
+ configuration.
417
+
418
+ Migration commands do not configure persistent CLI logging and temporarily
419
+ suspend existing CLI-owned file handlers, including on failure, so selecting
420
+ the old home as `QWENPAW_DATA_HOME` does not append or rotate its logs. They still
421
+ print JSON reports and concise errors; external handlers installed by an
422
+ in-process caller remain that caller's responsibility.
423
+
424
+ This package intentionally omits `serve` and local initialization helpers from
425
+ the public CLI help.