omp-config-crypt 0.0.0-stage → 0.1.1

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/index.js +150 -0
  4. package/package.json +28 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 omp-config-crypt contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # omp-config-crypt
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Encrypted export/import of omp user config and instruction files. Secrets are
4
+ included as-is; the archive itself is the only protection.
5
+
6
+ ## Archive
7
+
8
+ - AES-256-GCM, key = scrypt(passphrase, random salt)
9
+ - gzip payload, single binary file (`OMPCFG1\0` magic)
10
+ - written with mode `0600`
11
+
12
+ Included: `config.yml`, `models.yml`, `mcp.json`, `AGENTS.md`, `STYLE.md`,
13
+ `RULES.md`, and everything under `memories/`.
14
+
15
+ ## Commands
16
+
17
+ ```
18
+ /config-export [out.enc]
19
+ /config-import <file.enc>
20
+ ```
21
+
22
+ Passphrase: `OMP_CONFIG_PASS`, or the prompt shown by the command.
23
+
24
+ Import backs up every overwritten file to `<agent-dir>/.import-backup-<ts>/`
25
+ and asks for a restart so settings reload.
26
+
27
+ ## Install
28
+
29
+ ```
30
+ omp plugin install /root/omp-config-crypt
31
+ ```
32
+
33
+ Requires a new session before the commands appear.
package/index.js ADDED
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Encrypted portability for omp user config and instruction files.
3
+ * Exports a single AES-256-GCM blob (scrypt-derived key); import restores files
4
+ * and keeps a backup of whatever it overwrites.
5
+ */
6
+ import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";
7
+ import { gzipSync, gunzipSync } from "node:zlib";
8
+ import fs from "node:fs";
9
+ import os from "node:os";
10
+ import path from "node:path";
11
+
12
+ const MAGIC = Buffer.from("OMPCFG1\0", "latin1");
13
+ const FILES = ["config.yml", "models.yml", "mcp.json", "AGENTS.md", "STYLE.md", "RULES.md"];
14
+ const DIRS = ["memories"];
15
+
16
+ /** User agent directory, or OMP_CFG_ROOT for tests. */
17
+ export function configRoot() {
18
+ return process.env.OMP_CFG_ROOT || path.join(os.homedir(), ".omp", "agent");
19
+ }
20
+
21
+ function walk(dir, prefix = "") {
22
+ const out = [];
23
+ for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
24
+ const rel = prefix ? `${prefix}/${ent.name}` : ent.name;
25
+ if (ent.isDirectory()) out.push(...walk(path.join(dir, ent.name), rel));
26
+ else if (ent.isFile()) out.push(rel);
27
+ }
28
+ return out;
29
+ }
30
+
31
+ function collect(root) {
32
+ const out = [];
33
+ for (const f of FILES) {
34
+ const p = path.join(root, f);
35
+ if (fs.existsSync(p) && fs.statSync(p).isFile()) out.push(f);
36
+ }
37
+ for (const d of DIRS) {
38
+ const base = path.join(root, d);
39
+ if (fs.existsSync(base)) for (const rel of walk(base)) out.push(`${d}/${rel}`);
40
+ }
41
+ return out;
42
+ }
43
+
44
+ /** Write an encrypted archive of the config tree. */
45
+ export function exportEncrypted(outFile, pass, root = configRoot()) {
46
+ if (!pass) throw new Error("empty passphrase");
47
+ const files = collect(root).map((rel) => {
48
+ const abs = path.join(root, rel);
49
+ return { path: rel, data: fs.readFileSync(abs).toString("base64"), mode: fs.statSync(abs).mode & 0o777 };
50
+ });
51
+ const payload = { v: 1, createdAt: new Date().toISOString(), files };
52
+ const plain = gzipSync(Buffer.from(JSON.stringify(payload)), { level: 9 });
53
+ const salt = randomBytes(16);
54
+ const iv = randomBytes(12);
55
+ const key = scryptSync(pass, salt, 32);
56
+ const cipher = createCipheriv("aes-256-gcm", key, iv);
57
+ const ct = Buffer.concat([cipher.update(plain), cipher.final()]);
58
+ const blob = Buffer.concat([MAGIC, salt, iv, cipher.getAuthTag(), ct]);
59
+ const abs = path.resolve(outFile);
60
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
61
+ fs.writeFileSync(abs, blob, { mode: 0o600 });
62
+ return { outFile: abs, files: files.length, bytes: blob.length };
63
+ }
64
+
65
+ /** Restore files from an encrypted archive, backing up overwritten ones. */
66
+ export function importEncrypted(srcFile, pass, root = configRoot()) {
67
+ if (!pass) throw new Error("empty passphrase");
68
+ const blob = fs.readFileSync(srcFile);
69
+ if (!blob.subarray(0, MAGIC.length).equals(MAGIC)) throw new Error("not an omp-config-crypt archive");
70
+ let o = MAGIC.length;
71
+ const salt = blob.subarray(o, (o += 16));
72
+ const iv = blob.subarray(o, (o += 12));
73
+ const tag = blob.subarray(o, (o += 16));
74
+ const ct = blob.subarray(o);
75
+ const key = scryptSync(pass, salt, 32);
76
+ const decipher = createDecipheriv("aes-256-gcm", key, iv);
77
+ decipher.setAuthTag(tag);
78
+ const payload = JSON.parse(gunzipSync(Buffer.concat([decipher.update(ct), decipher.final()])).toString("utf8"));
79
+ if (payload.v !== 1 || !Array.isArray(payload.files)) throw new Error("unsupported archive payload");
80
+ const backupDir = path.join(root, `.import-backup-${Date.now()}`);
81
+ let restored = 0;
82
+ for (const f of payload.files) {
83
+ const rel = String(f.path || "");
84
+ if (!rel || rel.includes("..") || path.isAbsolute(rel)) throw new Error(`unsafe path in archive: ${rel}`);
85
+ const dst = path.join(root, rel);
86
+ if (fs.existsSync(dst)) {
87
+ const b = path.join(backupDir, rel);
88
+ fs.mkdirSync(path.dirname(b), { recursive: true });
89
+ fs.copyFileSync(dst, b);
90
+ }
91
+ fs.mkdirSync(path.dirname(dst), { recursive: true });
92
+ fs.writeFileSync(dst, Buffer.from(f.data, "base64"), { mode: f.mode || 0o600 });
93
+ restored++;
94
+ }
95
+ return { files: restored, backupDir: fs.existsSync(backupDir) ? backupDir : null };
96
+ }
97
+
98
+ async function askPass(ctx, title) {
99
+ if (process.env.OMP_CONFIG_PASS) return process.env.OMP_CONFIG_PASS;
100
+ const input = ctx?.ui?.input;
101
+ if (typeof input === "function") {
102
+ let value;
103
+ try {
104
+ value = await input.call(ctx.ui, { title, prompt: title, placeholder: "passphrase" });
105
+ } catch {
106
+ try {
107
+ value = await input.call(ctx.ui, title);
108
+ } catch {
109
+ value = undefined;
110
+ }
111
+ }
112
+ if (typeof value === "string" && value) return value;
113
+ }
114
+ throw new Error("no passphrase: set OMP_CONFIG_PASS or answer the prompt");
115
+ }
116
+
117
+ /** Plugin entry: /config-export and /config-import. */
118
+ export default function (pi) {
119
+ pi.registerCommand("config-export", {
120
+ description: "Encrypt omp config + instructions to a file",
121
+ handler: async (args, ctx) => {
122
+ const out = (args || "").trim() || path.join(os.homedir(), `omp-config-${Date.now()}.enc`);
123
+ try {
124
+ const pass = await askPass(ctx, "Export passphrase");
125
+ const r = exportEncrypted(out, pass);
126
+ ctx.ui.notify(`exported ${r.files} files (${r.bytes} B) → ${r.outFile}`, "info");
127
+ } catch (error) {
128
+ ctx.ui.notify(`config-export failed: ${error?.message ?? error}`, "error");
129
+ }
130
+ },
131
+ });
132
+
133
+ pi.registerCommand("config-import", {
134
+ description: "Decrypt and restore an omp config archive",
135
+ handler: async (args, ctx) => {
136
+ const src = (args || "").trim();
137
+ if (!src) {
138
+ ctx.ui.notify("usage: /config-import <file.enc>", "error");
139
+ return;
140
+ }
141
+ try {
142
+ const pass = await askPass(ctx, "Import passphrase");
143
+ const r = importEncrypted(src, pass);
144
+ ctx.ui.notify(`restored ${r.files} files${r.backupDir ? ` (backup: ${r.backupDir})` : ""}; restart omp`, "info");
145
+ } catch (error) {
146
+ ctx.ui.notify(`config-import failed: ${error?.message ?? error}`, "error");
147
+ }
148
+ },
149
+ });
150
+ }
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "omp-config-crypt",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Encrypted export/import of omp config and instructions",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "omp",
9
+ "oh-my-pi",
10
+ "plugin",
11
+ "config",
12
+ "sync",
13
+ "encryption"
14
+ ],
15
+ "files": [
16
+ "index.js",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "omp": {
21
+ "extensions": [
22
+ "./index.js"
23
+ ]
24
+ },
25
+ "pi": {
26
+ "extensions": [
27
+ "./index.js"
28
+ ]
29
+ }
30
+ }