@ubercode/channelvault 0.1.0 → 0.2.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/CHANGELOG.md +9 -0
- package/README.md +23 -0
- package/dist/cli.js +111 -33
- package/dist/cli.js.map +1 -1
- package/docs/roadmap.md +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@ubercode/channelvault` are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the version follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
+
## [0.2.0] — 2026-09-29
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `--json` for `status`, `diff` and `push --plan-only`: one JSON document on stdout for scripts, CI and AI agents.
|
|
10
|
+
- `push --plan-only`: the plan and what would stop it, without a prompt, a backup or any change.
|
|
11
|
+
- README: a copy-paste guide for using channelvault with an AI agent.
|
|
12
|
+
|
|
5
13
|
## [0.1.0] — 2026-09-25
|
|
6
14
|
|
|
7
15
|
First release. Tested against Mirth Connect 4.5.2; the offline round trip is also tested on Mirth 3.8 and 4.0.1 exports.
|
|
@@ -15,4 +23,5 @@ First release. Tested against Mirth Connect 4.5.2; the offline round trip is als
|
|
|
15
23
|
- `backup` / `restore`: the server's own configuration XML saved as `.backup/<server>-<UTC time>.xml`, identified by Mirth's server ID, restored with a preview, an undo backup and a version check. `push` backs up first unless `--no-backup`.
|
|
16
24
|
- `diff` exits 0 when the tree matches the server, 1 when it differs, 2 on error.
|
|
17
25
|
|
|
26
|
+
[0.2.0]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.2.0
|
|
18
27
|
[0.1.0]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -76,6 +76,12 @@ channelvault restore [file] # backup -> live server (default: ne
|
|
|
76
76
|
|
|
77
77
|
`diff` exits 0 when the tree matches the server, 1 when they differ, and 2 on any error (including a bad flag), so a scheduled drift check can tell drift from an outage.
|
|
78
78
|
|
|
79
|
+
For scripts, CI and AI agents, `status`, `diff` and `push --plan-only` take `--json` and print one JSON document on stdout; errors still go to stderr with the usual exit code.
|
|
80
|
+
|
|
81
|
+
- `status --json`: `{ root, source, pulledAt, engineVersion, counts }`.
|
|
82
|
+
- `diff --json`: `{ clean, files: [{ path, change }], secretDrift, notes, patch }`, where `change` is `modified`, `only-in-tree` or `only-on-server` and `patch` is the redacted unified diff.
|
|
83
|
+
- `push --plan-only --json`: `{ target, mode, changes: [{ kind, op, id, label }], conflicts, serverOnly, notPushed, wouldStop }` (plus `redeploy` and `notRedeployed` with `--deploy`). `wouldStop` lists what would refuse a real push with the same flags, such as unconfirmed deletions or conflicts.
|
|
84
|
+
|
|
79
85
|
`pull` and `explode` replace `server/`, `channels/`, `codeTemplates/` and `channelGroups/` in `<dir>`, so they refuse a directory that has any of those but no `channelvault.json`, an unreadable `channelvault.json`, or a `--dotenv` file inside one of those directories. All of this is checked before anything is written.
|
|
80
86
|
|
|
81
87
|
## Secrets and per-environment values
|
|
@@ -114,6 +120,7 @@ channelvault push ./mirth --library Formatting --deploy # one library, then red
|
|
|
114
120
|
- A tree exploded from an XML backup is refused (its shape differs from the live API's); `--ignore-origin` overrides that.
|
|
115
121
|
- Before it changes anything, `push` backs up the server (see below) and prints the `restore` command that undoes it. `--no-backup` skips that.
|
|
116
122
|
- Without a terminal, `push` needs `--yes`.
|
|
123
|
+
- `--plan-only` shows the plan and what would stop it, and changes nothing: no prompt, no backup, no writes. It works without a terminal.
|
|
117
124
|
|
|
118
125
|
## Backups
|
|
119
126
|
|
|
@@ -139,6 +146,22 @@ channelvault restore .backup/vns-gov-20260925T143012Z.xml --deploy
|
|
|
139
146
|
- If the server changes while you confirm, nothing is restored; run it again to review the new state.
|
|
140
147
|
- `--deploy` redeploys every channel afterwards; `--overwrite-config-map` also replaces the configuration map.
|
|
141
148
|
|
|
149
|
+
## Using channelvault with an AI agent
|
|
150
|
+
|
|
151
|
+
An agent can safely edit a tree and check its work. Pushing, restoring and anything that needs `--force` should stay with a person, who reads the plan first. Paste this into the agent instructions of your configuration repository (`AGENTS.md`, `CLAUDE.md` or similar) and adjust the paths:
|
|
152
|
+
|
|
153
|
+
```markdown
|
|
154
|
+
## Mirth configuration (channelvault)
|
|
155
|
+
|
|
156
|
+
`mirth/` is a channelvault tree of our Mirth Connect server. Channel scripts are the `.js` files under `mirth/channels/<channel>/`, settings are in `channel.json`, and code templates are under `mirth/codeTemplates/<library>/`.
|
|
157
|
+
|
|
158
|
+
- Edit the `.js` and `.json` files; leave `id`, `revision`, `channelvault.json` and the `{"@file": …}` / `{"@ref": …}` markers alone. A new channel or template needs its own new UUID for `id`; a copied directory keeps the old one.
|
|
159
|
+
- Mirth runs these scripts in Rhino, not Node: no template literals, `async`/`await`, optional chaining (`?.`), classes, `require` or `import`.
|
|
160
|
+
- `{{env:NAME}}` is a placeholder for a secret kept outside git. Never replace one with a real value, and never read, print or copy `.env`, `.secrets/` or `.backup/`.
|
|
161
|
+
- Check your work with `channelvault diff mirth --json` (exit 0: matches the server, 1: differs) and `channelvault push mirth --plan-only --json`, which shows what a push would change and `wouldStop` reasons.
|
|
162
|
+
- Do not run `channelvault push` (other than with `--plan-only`), `restore` or `pull`, and never pass `--force`, `--allow-deletes` or `--yes`. Summarise the plan and let a person push.
|
|
163
|
+
```
|
|
164
|
+
|
|
142
165
|
## Local test server
|
|
143
166
|
|
|
144
167
|
```
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawnSync } from "child_process";
|
|
5
|
-
import { mkdir as mkdir4, mkdtemp, readFile as readFile5, realpath as realpath3, rename as rename3, rm as rm3, writeFile as writeFile5 } from "fs/promises";
|
|
5
|
+
import { mkdir as mkdir4, mkdtemp, readdir as readdir4, readFile as readFile5, realpath as realpath3, rename as rename3, rm as rm3, writeFile as writeFile5 } from "fs/promises";
|
|
6
6
|
import { existsSync as existsSync5 } from "fs";
|
|
7
7
|
import { tmpdir } from "os";
|
|
8
8
|
import { createRequire } from "module";
|
|
@@ -2360,6 +2360,13 @@ async function withClient(flags, fn) {
|
|
|
2360
2360
|
await client.close().catch(() => void 0);
|
|
2361
2361
|
}
|
|
2362
2362
|
}
|
|
2363
|
+
function addJsonFlag(cmd) {
|
|
2364
|
+
return cmd.option("--json", "print the result as one JSON document on stdout", false);
|
|
2365
|
+
}
|
|
2366
|
+
function writeJson2(value) {
|
|
2367
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
2368
|
+
`);
|
|
2369
|
+
}
|
|
2363
2370
|
function addBackupDirFlags(cmd) {
|
|
2364
2371
|
return cmd.option("--backup-dir <dir>", `where backups are kept (default ./${DEFAULT_BACKUP_DIR})`).option("--keep <n>", `backups kept per server (default ${DEFAULT_KEEP})`);
|
|
2365
2372
|
}
|
|
@@ -2662,9 +2669,10 @@ function printChanges(plan) {
|
|
|
2662
2669
|
for (const c of plan.changes) process.stdout.write(` ${c.op.padEnd(6)} ${`${kindLabel[c.kind]} ${c.label}`.trim()}
|
|
2663
2670
|
`);
|
|
2664
2671
|
}
|
|
2665
|
-
function
|
|
2672
|
+
function planProblems(plan, flags) {
|
|
2673
|
+
const problems = [];
|
|
2666
2674
|
if (plan.conflicts.length > 0 && !flags.force) {
|
|
2667
|
-
|
|
2675
|
+
problems.push(
|
|
2668
2676
|
`changed on the server since the last pull:
|
|
2669
2677
|
${plan.conflicts.join("\n ")}
|
|
2670
2678
|
pull (and merge) first, or pass --force to overwrite the server's version`
|
|
@@ -2672,8 +2680,37 @@ pull (and merge) first, or pass --force to overwrite the server's version`
|
|
|
2672
2680
|
}
|
|
2673
2681
|
const deletes = plan.changes.filter((c) => c.op === "delete").length;
|
|
2674
2682
|
if (deletes > 0 && !flags.allowDeletes) {
|
|
2675
|
-
|
|
2683
|
+
problems.push(`the plan deletes ${deletes} resource(s) from the server; pass --allow-deletes, or narrow with --channel/--library`);
|
|
2684
|
+
}
|
|
2685
|
+
return problems;
|
|
2686
|
+
}
|
|
2687
|
+
function wholeServerProblems(plan, flags) {
|
|
2688
|
+
const problems = [];
|
|
2689
|
+
if (plan.serverOnly.length > 0 && !flags.force) {
|
|
2690
|
+
problems.push("the replace would delete resources created on the server since the last pull; pull first, or pass --force (and --allow-deletes)");
|
|
2691
|
+
}
|
|
2692
|
+
const deletions = plan.changes.filter((c) => c.op === "delete").length + plan.serverOnly.length;
|
|
2693
|
+
if (deletions > 0 && !flags.allowDeletes) problems.push(`the replace deletes ${deletions} resource(s) from the server; pass --allow-deletes`);
|
|
2694
|
+
if (plan.conflicts.length > 0 && !flags.force) problems.push(...planProblems({ ...plan, changes: [] }, flags));
|
|
2695
|
+
return problems;
|
|
2696
|
+
}
|
|
2697
|
+
function reportPlanOnly(flags, plan, problems, extra) {
|
|
2698
|
+
if (flags.json) {
|
|
2699
|
+
writeJson2({
|
|
2700
|
+
target: extra.target,
|
|
2701
|
+
mode: extra.mode,
|
|
2702
|
+
changes: plan.changes,
|
|
2703
|
+
conflicts: plan.conflicts,
|
|
2704
|
+
serverOnly: plan.serverOnly,
|
|
2705
|
+
notPushed: plan.notPushed,
|
|
2706
|
+
...extra.redeploy ? { redeploy: extra.redeploy, notRedeployed: extra.notRedeployed ?? [] } : {},
|
|
2707
|
+
wouldStop: problems
|
|
2708
|
+
});
|
|
2709
|
+
return;
|
|
2676
2710
|
}
|
|
2711
|
+
for (const p of problems) process.stdout.write(`a push would stop: ${p}
|
|
2712
|
+
`);
|
|
2713
|
+
process.stdout.write("plan only: nothing was changed\n");
|
|
2677
2714
|
}
|
|
2678
2715
|
async function scopedPush(client, root, local, scope, target, flags) {
|
|
2679
2716
|
const remote = await client.getServerConfiguration();
|
|
@@ -2686,6 +2723,11 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2686
2723
|
const deployed = flags.deploy && plan.deployIds.length > 0 ? await client.getDeployedChannelIds() : /* @__PURE__ */ new Set();
|
|
2687
2724
|
const toDeploy = plan.deployIds.filter((id) => deployed.has(id));
|
|
2688
2725
|
const notDeployed = flags.deploy ? plan.deployIds.filter((id) => !deployed.has(id)) : [];
|
|
2726
|
+
if (flags.planOnly && flags.json) {
|
|
2727
|
+
const redeploy = flags.deploy ? { redeploy: toDeploy.map(nameOf2), notRedeployed: notDeployed.map(nameOf2) } : {};
|
|
2728
|
+
reportPlanOnly(flags, plan, planProblems(plan, flags), { target, mode: "scoped", ...redeploy });
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2689
2731
|
if (plan.changes.length === 0) {
|
|
2690
2732
|
process.stdout.write(`nothing to push: ${target} already matches the tree
|
|
2691
2733
|
`);
|
|
@@ -2708,8 +2750,13 @@ async function scopedPush(client, root, local, scope, target, flags) {
|
|
|
2708
2750
|
process.stdout.write(`left alone (created on the server since the last pull; pull to get them): ${plan.serverOnly.join(", ")}
|
|
2709
2751
|
`);
|
|
2710
2752
|
}
|
|
2753
|
+
if (flags.planOnly) {
|
|
2754
|
+
reportPlanOnly(flags, plan, planProblems(plan, flags), { target, mode: "scoped" });
|
|
2755
|
+
return;
|
|
2756
|
+
}
|
|
2711
2757
|
if (plan.changes.length === 0) return;
|
|
2712
|
-
|
|
2758
|
+
const problems = planProblems(plan, flags);
|
|
2759
|
+
if (problems.length > 0) fail(problems.join("\n"));
|
|
2713
2760
|
if (!flags.yes && !await confirm("Continue?")) {
|
|
2714
2761
|
process.stdout.write("aborted.\n");
|
|
2715
2762
|
return;
|
|
@@ -2755,6 +2802,10 @@ async function wholeServerPush(client, root, local, target, flags) {
|
|
|
2755
2802
|
const remote = await client.getServerConfiguration();
|
|
2756
2803
|
const known = await readKnown(root);
|
|
2757
2804
|
const plan = planPush(local, remote, {}, known, { wholeReplace: true });
|
|
2805
|
+
if (flags.planOnly && flags.json) {
|
|
2806
|
+
reportPlanOnly(flags, plan, wholeServerProblems(plan, flags), { target, mode: "whole-server" });
|
|
2807
|
+
return;
|
|
2808
|
+
}
|
|
2758
2809
|
const s = summarize(local);
|
|
2759
2810
|
process.stdout.write(
|
|
2760
2811
|
`Replace the ENTIRE server configuration at ${target} (${s.channels} channels, ${s.codeTemplates} code templates${flags.deploy ? ", then redeploy all channels" : ""}).
|
|
@@ -2772,14 +2823,12 @@ async function wholeServerPush(client, root, local, target, flags) {
|
|
|
2772
2823
|
if (replaced.length > 0) process.stdout.write(`also replaced: ${replaced.join(", ")}
|
|
2773
2824
|
`);
|
|
2774
2825
|
if (keptMap) process.stdout.write("configuration map differs but is kept (--overwrite-config-map replaces it)\n");
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
if (deletions > 0 && !flags.allowDeletes) {
|
|
2780
|
-
fail(`the replace deletes ${deletions} resource(s) from the server; pass --allow-deletes`);
|
|
2826
|
+
const problems = wholeServerProblems(plan, flags);
|
|
2827
|
+
if (flags.planOnly) {
|
|
2828
|
+
reportPlanOnly(flags, plan, problems, { target, mode: "whole-server" });
|
|
2829
|
+
return;
|
|
2781
2830
|
}
|
|
2782
|
-
|
|
2831
|
+
if (problems.length > 0) fail(problems.join("\n"));
|
|
2783
2832
|
if (!flags.yes && !await confirm("Continue?")) {
|
|
2784
2833
|
process.stdout.write("aborted.\n");
|
|
2785
2834
|
return;
|
|
@@ -2844,7 +2893,7 @@ addExtractFlag(addEnvFlag(addConnectionFlags(
|
|
|
2844
2893
|
`);
|
|
2845
2894
|
});
|
|
2846
2895
|
addBackupDirFlags(addEnvFlag(addConnectionFlags(
|
|
2847
|
-
program.command("push").description("Push changed channels, code templates and global scripts to the live server").argument("<dir>", "working-tree directory").option("--channel <name>", "only this channel (name or id); repeatable", collect).option("--library <name>", "only this code template library (name or id); repeatable", collect).option("--global-scripts", "with --channel/--library: also push global scripts").option("--allow-deletes", "delete server resources that are missing from the tree", false).option("--deploy", "redeploy the changed channels and the channels using changed code templates", false).option("--force", "push even if the server changed since the last pull (overwrites the server's version)", false).option("--ignore-origin", "push a tree that was exploded from an XML backup (normally refused)", false).option("--whole-server", "replace the entire server configuration instead (settings, config map, groups too)", false).option("--overwrite-config-map", "with --whole-server: also overwrite the configuration map", false).option("--no-backup", "skip the backup of the server taken before anything changes").option("-y, --yes", "skip the confirmation prompt", false)
|
|
2896
|
+
program.command("push").description("Push changed channels, code templates and global scripts to the live server").argument("<dir>", "working-tree directory").option("--channel <name>", "only this channel (name or id); repeatable", collect).option("--library <name>", "only this code template library (name or id); repeatable", collect).option("--global-scripts", "with --channel/--library: also push global scripts").option("--allow-deletes", "delete server resources that are missing from the tree", false).option("--deploy", "redeploy the changed channels and the channels using changed code templates", false).option("--force", "push even if the server changed since the last pull (overwrites the server's version)", false).option("--ignore-origin", "push a tree that was exploded from an XML backup (normally refused)", false).option("--whole-server", "replace the entire server configuration instead (settings, config map, groups too)", false).option("--overwrite-config-map", "with --whole-server: also overwrite the configuration map", false).option("--no-backup", "skip the backup of the server taken before anything changes").option("--plan-only", "show what would be pushed and what would stop it; change nothing (no prompt)", false).option("--json", "with --plan-only: print the plan as one JSON document", false).option("-y, --yes", "skip the confirmation prompt", false)
|
|
2848
2897
|
))).action(
|
|
2849
2898
|
async (dir, flags) => {
|
|
2850
2899
|
if (flags.wholeServer && (flags.channel || flags.library || flags.globalScripts)) {
|
|
@@ -2856,8 +2905,9 @@ addBackupDirFlags(addEnvFlag(addConnectionFlags(
|
|
|
2856
2905
|
await assertCompatibleOrigin(root, config, "live", flags.ignoreOrigin === true);
|
|
2857
2906
|
const cfg = resolveClientConfig(flags);
|
|
2858
2907
|
const target = `${cfg.https === false ? "http" : "https"}://${cfg.host}:${cfg.port}`;
|
|
2859
|
-
if (
|
|
2860
|
-
|
|
2908
|
+
if (flags.json && !flags.planOnly) fail("--json needs --plan-only");
|
|
2909
|
+
if (!flags.yes && !flags.planOnly && !process.stdin.isTTY) {
|
|
2910
|
+
fail("no terminal to confirm on; review with `push --plan-only` or `diff`, and pass --yes");
|
|
2861
2911
|
}
|
|
2862
2912
|
if (flags.wholeServer) {
|
|
2863
2913
|
await withClient(flags, (client) => wholeServerPush(client, root, config, target, flags));
|
|
@@ -2971,35 +3021,31 @@ to ${target}, replacing its ENTIRE configuration${flags.deploy ? ", then redeplo
|
|
|
2971
3021
|
`);
|
|
2972
3022
|
});
|
|
2973
3023
|
});
|
|
2974
|
-
addEnvFlag(addConnectionFlags(
|
|
3024
|
+
addJsonFlag(addEnvFlag(addConnectionFlags(
|
|
2975
3025
|
program.command("diff").description("Diff a working tree against the live server configuration (exit 0 = same, 1 = differences, 2 = error)").argument("<dir>", "working-tree directory").exitOverride((err) => {
|
|
2976
3026
|
process.exitCode = err.exitCode === 0 ? 0 : 2;
|
|
2977
3027
|
throw err;
|
|
2978
3028
|
})
|
|
2979
|
-
)).action(async (dir, flags) => {
|
|
3029
|
+
))).action(async (dir, flags) => {
|
|
2980
3030
|
errorExitCode = 2;
|
|
2981
3031
|
const root = path5.resolve(dir);
|
|
2982
3032
|
assertTree(root);
|
|
2983
3033
|
const fetched = await withClient(flags, (client) => client.getServerConfiguration());
|
|
2984
3034
|
const tree = await engine.implode({ root });
|
|
2985
3035
|
const { config: templatedRemote, envUpdates, notes } = templatize(fetched, tree, await loadEnv(envFilePath(root, flags)));
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
for (const note of notes) process.stderr.write(`note: ${note}
|
|
2991
|
-
`);
|
|
3036
|
+
const messages = [
|
|
3037
|
+
...Object.keys(envUpdates).map((name) => `${name} differs between the server and the env file`),
|
|
3038
|
+
...notes
|
|
3039
|
+
];
|
|
2992
3040
|
const allow = await readAllow(root);
|
|
2993
3041
|
const treeView = scanSecrets(redactKnownSecrets(normalizeEolDeep(tree)), { mode: "redact", allow });
|
|
2994
3042
|
const serverView = scanSecrets(redactKnownSecrets(normalizeEolDeep(templatedRemote)), { mode: "redact", allow });
|
|
2995
3043
|
if (treeView.findings.length > 0) {
|
|
2996
|
-
|
|
2997
|
-
`);
|
|
3044
|
+
messages.push(`the tree holds ${treeView.findings.length} unextracted secret(s), redacted below; pull --extract-secrets`);
|
|
2998
3045
|
}
|
|
2999
|
-
if (serverView.findings.length > 0) {
|
|
3000
|
-
|
|
3046
|
+
if (serverView.findings.length > 0) messages.push(`${serverView.findings.length} possible secret(s) on the server are redacted below`);
|
|
3047
|
+
if (!flags.json) for (const m of messages) process.stderr.write(`note: ${m}
|
|
3001
3048
|
`);
|
|
3002
|
-
}
|
|
3003
3049
|
const tmp = await mkdtemp(path5.join(tmpdir(), "channelvault-diff-"));
|
|
3004
3050
|
try {
|
|
3005
3051
|
await engine.explode(treeView.config, { root: path5.join(tmp, "tree") });
|
|
@@ -3027,7 +3073,12 @@ addEnvFlag(addConnectionFlags(
|
|
|
3027
3073
|
}
|
|
3028
3074
|
const out = chunks.join("\n");
|
|
3029
3075
|
const secretDrift = Object.keys(envUpdates);
|
|
3030
|
-
|
|
3076
|
+
const clean = out === "" && secretDrift.length === 0;
|
|
3077
|
+
if (!clean) process.exitCode = 1;
|
|
3078
|
+
if (flags.json) {
|
|
3079
|
+
const files = await changedFiles(path5.join(tmp, "tree"), path5.join(tmp, "server"));
|
|
3080
|
+
writeJson2({ clean, files, secretDrift, notes: messages, patch: out });
|
|
3081
|
+
} else if (clean) {
|
|
3031
3082
|
process.stdout.write("no differences \u2014 working tree matches the server.\n");
|
|
3032
3083
|
} else {
|
|
3033
3084
|
if (out !== "") process.stdout.write(out + "\n");
|
|
@@ -3035,20 +3086,47 @@ addEnvFlag(addConnectionFlags(
|
|
|
3035
3086
|
process.stdout.write(`secret values differ between the server and the env file: ${secretDrift.join(", ")}
|
|
3036
3087
|
`);
|
|
3037
3088
|
}
|
|
3038
|
-
process.exitCode = 1;
|
|
3039
3089
|
}
|
|
3040
3090
|
} finally {
|
|
3041
3091
|
await rm3(tmp, RM_OPTS);
|
|
3042
3092
|
}
|
|
3043
3093
|
});
|
|
3044
|
-
|
|
3094
|
+
async function changedFiles(treeDir, serverDir) {
|
|
3095
|
+
const list2 = async (base) => {
|
|
3096
|
+
const out = [];
|
|
3097
|
+
for (const d of MANAGED_DIRS) {
|
|
3098
|
+
if (!existsSync5(path5.join(base, d))) continue;
|
|
3099
|
+
for (const entry of await readdir4(path5.join(base, d), { recursive: true, withFileTypes: true })) {
|
|
3100
|
+
if (entry.isFile()) out.push(path5.relative(base, path5.join(entry.parentPath, entry.name)).split(path5.sep).join("/"));
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
return out;
|
|
3104
|
+
};
|
|
3105
|
+
const [local, remote] = await Promise.all([list2(treeDir), list2(serverDir)]);
|
|
3106
|
+
const remoteSet = new Set(remote);
|
|
3107
|
+
const files = [];
|
|
3108
|
+
for (const p of local) {
|
|
3109
|
+
if (!remoteSet.has(p)) files.push({ path: p, change: "only-in-tree" });
|
|
3110
|
+
else if (await readFile5(path5.join(treeDir, p), "utf8") !== await readFile5(path5.join(serverDir, p), "utf8")) files.push({ path: p, change: "modified" });
|
|
3111
|
+
}
|
|
3112
|
+
const localSet = new Set(local);
|
|
3113
|
+
for (const p of remote) if (!localSet.has(p)) files.push({ path: p, change: "only-on-server" });
|
|
3114
|
+
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
3115
|
+
}
|
|
3116
|
+
addJsonFlag(
|
|
3117
|
+
program.command("status").description("Summarize a working tree").argument("<dir>", "working-tree directory")
|
|
3118
|
+
).action(async (dir, flags) => {
|
|
3045
3119
|
const root = path5.resolve(dir);
|
|
3046
3120
|
assertTree(root);
|
|
3047
3121
|
const config = await engine.implode({ root });
|
|
3048
3122
|
const s = summarize(config);
|
|
3049
3123
|
const metaPath = path5.join(root, "channelvault.json");
|
|
3050
|
-
|
|
3051
|
-
|
|
3124
|
+
const meta = existsSync5(metaPath) ? await readJson(metaPath) : null;
|
|
3125
|
+
if (flags.json) {
|
|
3126
|
+
writeJson2({ root, source: meta?.source ?? null, pulledAt: meta?.pulledAt ?? null, engineVersion: meta?.engineVersion ?? null, counts: s });
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
if (meta) {
|
|
3052
3130
|
process.stdout.write(`source: ${meta.source}
|
|
3053
3131
|
`);
|
|
3054
3132
|
process.stdout.write(`pulled: ${meta.pulledAt}
|