dotkc 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +125 -0
  3. package/bin/dotkc.mjs +267 -0
  4. package/package.json +28 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # dotkc
2
+
3
+ Keychain-backed secrets with a dotenv-style CLI runner.
4
+
5
+ `dotkc` stores secrets in your OS credential store (macOS Keychain), which can be synced across Macs via **iCloud Keychain**.
6
+
7
+ ## Security & threat model (read first)
8
+
9
+ - `dotkc` does **not** upload secrets anywhere.
10
+ - Secrets live in your OS credential store. Access control and syncing are managed by your OS (e.g. iCloud Keychain on macOS).
11
+ - Prefer stdin for `set` (use `-`) to avoid secrets in shell history and process listings.
12
+ - Avoid printing environment variables in logs.
13
+
14
+ ## Why dotkc (core value)
15
+
16
+ `dotkc` was built for **OpenClaw-style local agents** and developer workflows where you want to safely use API keys/tokens **without pasting secrets into chats** or committing them to git.
17
+
18
+ ### The problem
19
+
20
+ - `.env` files are convenient, but secrets end up **on disk**, can be copied around, and sometimes get committed by accident.
21
+ - Sending tokens to an assistant (or any remote system) can create unwanted **logs/history** and accidental disclosure.
22
+
23
+ ### The approach
24
+
25
+ `dotkc` keeps secrets in **macOS Keychain** and injects them into a command environment *only at runtime*:
26
+ - **Never commit secrets to AI**: you store them locally and run commands that fetch secrets from Keychain.
27
+ - **Sync across Macs** via iCloud Keychain (MacBook ↔ Mac mini, etc.).
28
+ - **Dotenv-like ergonomics**: `dotkc run ... -- <cmd>`.
29
+ - Organize secrets with 3 dimensions: **service (SaaS) + category (project/env) + key (ENV name)**.
30
+
31
+ ### Practical use cases
32
+
33
+ - OpenClaw: keep provider tokens in Keychain and inject only for the specific agent/gateway command that needs them.
34
+ - Multi-machine dev: define secrets once, then reuse on another Mac after iCloud Keychain sync.
35
+ - Personal projects: keep secrets off-disk but still easy to run locally.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ npm i -g dotkc
41
+ ```
42
+
43
+ > Note: `keytar` is a native module. You need build tooling for your platform.
44
+
45
+ ## Data model
46
+
47
+ A secret is identified by:
48
+ - `service` — SaaS name (e.g. `vercel`, `stripe`, `openai`)
49
+ - `category` — project/env/free-form group (e.g. `acme-app-dev`, `acme-app-prod`)
50
+ - `KEY` — environment variable name (e.g. `GITHUB_TOKEN`, `DEPLOY_TOKEN`)
51
+
52
+ Storage convention:
53
+ - stored as Keychain entry `(service, "<category>:<KEY>")`
54
+ - injected into environment as `KEY=<value>`
55
+
56
+ Recommendation: keep `category` free of `:` (use `-` or `/`) so prefix matching is unambiguous.
57
+
58
+ ## Usage
59
+
60
+ ### Set a secret
61
+
62
+ Prefer stdin (`-`) to avoid shell history leaks:
63
+
64
+ ```bash
65
+ (echo -n '...') | dotkc set vercel acme-app-dev GITHUB_TOKEN -
66
+ (echo -n '...') | dotkc set vercel acme-app-dev DEPLOY_TOKEN -
67
+ ```
68
+
69
+ ### Get / delete
70
+
71
+ ```bash
72
+ dotkc get vercel acme-app-dev GITHUB_TOKEN
73
+ dotkc del vercel acme-app-dev GITHUB_TOKEN
74
+ ```
75
+
76
+ ### List (categories and keys, no values)
77
+
78
+ ```bash
79
+ # list categories under a SaaS
80
+ dotkc list vercel
81
+
82
+ # list keys under a category
83
+ dotkc list vercel acme-app-dev
84
+ ```
85
+
86
+ ### Run a command with secrets injected
87
+
88
+ Wildcard (load *all* secrets under a category):
89
+
90
+ ```bash
91
+ dotkc run vercel:acme-app-dev -- node ./my-app.mjs
92
+ ```
93
+
94
+ Exact selection (pick specific keys):
95
+
96
+ ```bash
97
+ dotkc run vercel:acme-app-dev:GITHUB_TOKEN,vercel:acme-app-dev:DEPLOY_TOKEN -- node ./my-app.mjs
98
+ ```
99
+
100
+ ### Run with dotenv files (optional)
101
+
102
+ If your project already uses `.env` / `.env.local`, you can load them first, then override with Keychain:
103
+
104
+ ```bash
105
+ # loads .env then .env.local (if present)
106
+ dotkc run --dotenv vercel:acme-app-dev -- node ./my-app.mjs
107
+
108
+ # load a specific file (repeatable)
109
+ dotkc run --dotenv-file .env.staging vercel:acme-app-dev -- node ./my-app.mjs
110
+
111
+ # allow dotenv to override existing process.env (default is: do NOT override)
112
+ dotkc run --dotenv --dotenv-override vercel:acme-app-dev -- node ./my-app.mjs
113
+ ```
114
+
115
+ #### Recommended env precedence order
116
+
117
+ 1) Existing `process.env` (e.g. CI, shell exports)
118
+ 2) Dotenv files (`.env`, `.env.local`, and any `--dotenv-file`)
119
+ 3) Keychain secrets injected by `dotkc` (**always override**)
120
+
121
+ This keeps explicit environment exports in control, but guarantees the Keychain secrets win last.
122
+
123
+ ## License
124
+
125
+ Apache-2.0
package/bin/dotkc.mjs ADDED
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dotkc — Keychain-backed secrets + dotenv-style runner
4
+ *
5
+ * Storage model (3 dimensions):
6
+ * service (SaaS) + category (project/env) + key (ENV name)
7
+ * Stored in OS credential store under:
8
+ * (service, `${category}:${KEY}`)
9
+ */
10
+
11
+ import keytar from 'keytar';
12
+ import dotenv from 'dotenv';
13
+ import { spawn } from 'node:child_process';
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+
17
+ function die(msg, code = 1) {
18
+ console.error(msg);
19
+ process.exit(code);
20
+ }
21
+
22
+ function usage(code = 0) {
23
+ const txt = `
24
+ Usage:
25
+ dotkc set <service> <category> <KEY> <value|->
26
+ dotkc get <service> <category> <KEY>
27
+ dotkc del <service> <category> <KEY>
28
+
29
+ dotkc list <service> [category]
30
+
31
+ # Compatibility aliases:
32
+ dotkc categories <service>
33
+ dotkc keys <service> <category>
34
+
35
+ # Run a command with secrets injected:
36
+ # - exact: <service>:<category>:<KEY>
37
+ # - wildcard: <service>:<category>
38
+ dotkc run [options] <spec>[,<spec>...] -- <cmd> [args...]
39
+
40
+ Run options:
41
+ --dotenv Load dotenv files if present (.env then .env.local)
42
+ --dotenv-file <path> Load a specific dotenv file (can repeat)
43
+ --dotenv-override Allow dotenv to override existing process.env
44
+
45
+ Examples:
46
+ (echo -n '...') | dotkc set vercel acme-app-dev GITHUB_TOKEN -
47
+ dotkc list vercel
48
+ dotkc list vercel acme-app-dev
49
+
50
+ dotkc run vercel:acme-app-dev -- node ./app.mjs
51
+ dotkc run --dotenv vercel:acme-app-dev -- node ./app.mjs
52
+ dotkc run vercel:acme-app-dev:GITHUB_TOKEN,vercel:acme-app-dev:DEPLOY_TOKEN -- node ./app.mjs
53
+
54
+ Notes:
55
+ - Prefer '-' (stdin) for values to avoid shell history.
56
+ - 'list <service>' shows categories; 'list <service> <category>' shows keys (no values).
57
+ - Wildcard run loads ALL secrets whose account starts with "<category>:".
58
+ - Category should avoid ':' to keep parsing unambiguous.
59
+ - Env load order for run: existing process.env → dotenv files → Keychain (dotkc) overrides.
60
+ `;
61
+ console.error(txt.trimStart());
62
+ process.exit(code);
63
+ }
64
+
65
+ async function readAllStdin() {
66
+ const chunks = [];
67
+ for await (const c of process.stdin) chunks.push(c);
68
+ return Buffer.concat(chunks).toString('utf8');
69
+ }
70
+
71
+ function parseSpec(s) {
72
+ const parts = s.split(':');
73
+ if (parts.length < 2) throw new Error(`Invalid spec: ${s}`);
74
+ if (parts.length === 2) {
75
+ const [service, category] = parts;
76
+ return { kind: 'wildcard', service, category };
77
+ }
78
+ const key = parts.pop();
79
+ const category = parts.pop();
80
+ const service = parts.join(':');
81
+ return { kind: 'exact', service, category, key };
82
+ }
83
+
84
+ const argv = process.argv.slice(2);
85
+ if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') usage(argv.length ? 0 : 1);
86
+
87
+ const cmd = argv[0];
88
+
89
+ if (cmd === 'set') {
90
+ const [service, category, key, value] = argv.slice(1);
91
+ if (!service || !category || !key || typeof value !== 'string') usage(1);
92
+ let secret = value;
93
+ if (value === '-') {
94
+ if (process.stdin.isTTY) die('Refusing to read from TTY. Pipe the value into stdin.', 2);
95
+ secret = (await readAllStdin()).replace(/\r?\n$/, '');
96
+ }
97
+ if (!secret) die('Empty value; nothing stored.', 2);
98
+ await keytar.setPassword(service, `${category}:${key}`, secret);
99
+ console.log('OK');
100
+ process.exit(0);
101
+ }
102
+
103
+ if (cmd === 'get') {
104
+ const [service, category, key] = argv.slice(1);
105
+ if (!service || !category || !key) usage(1);
106
+ const v = await keytar.getPassword(service, `${category}:${key}`);
107
+ if (v == null) die('NOT_FOUND', 3);
108
+ process.stdout.write(v);
109
+ process.exit(0);
110
+ }
111
+
112
+ if (cmd === 'del') {
113
+ const [service, category, key] = argv.slice(1);
114
+ if (!service || !category || !key) usage(1);
115
+ const ok = await keytar.deletePassword(service, `${category}:${key}`);
116
+ console.log(ok ? 'OK' : 'NOT_FOUND');
117
+ process.exit(ok ? 0 : 3);
118
+ }
119
+
120
+ async function listCategories(service) {
121
+ const creds = await keytar.findCredentials(service);
122
+ const cats = Array.from(new Set(creds.map(c => c.account.split(':')[0]).filter(Boolean))).sort((a, b) => a.localeCompare(b));
123
+ for (const c of cats) console.log(c);
124
+ }
125
+
126
+ async function listKeys(service, category) {
127
+ const prefix = `${category}:`;
128
+ const creds = await keytar.findCredentials(service);
129
+ const keys = creds
130
+ .map(c => c.account)
131
+ .filter(a => a.startsWith(prefix))
132
+ .map(a => a.slice(prefix.length))
133
+ .filter(Boolean)
134
+ .sort((a, b) => a.localeCompare(b));
135
+ for (const k of keys) console.log(k);
136
+ }
137
+
138
+ if (cmd === 'list') {
139
+ const [service, category] = argv.slice(1);
140
+ if (!service) usage(1);
141
+ if (!category) {
142
+ await listCategories(service);
143
+ } else {
144
+ await listKeys(service, category);
145
+ }
146
+ process.exit(0);
147
+ }
148
+
149
+ // Aliases
150
+ if (cmd === 'categories') {
151
+ const [service] = argv.slice(1);
152
+ if (!service) usage(1);
153
+ await listCategories(service);
154
+ process.exit(0);
155
+ }
156
+
157
+ if (cmd === 'keys') {
158
+ const [service, category] = argv.slice(1);
159
+ if (!service || !category) usage(1);
160
+ await listKeys(service, category);
161
+ process.exit(0);
162
+ }
163
+
164
+ function loadDotenvIntoEnv(env, filePath, override) {
165
+ if (!fs.existsSync(filePath)) return;
166
+ const r = dotenv.config({ path: filePath, override });
167
+ if (r.error) throw r.error;
168
+ // dotenv.config writes into process.env; copy into our env object.
169
+ // We purposely re-copy from process.env to keep behavior consistent.
170
+ for (const [k, v] of Object.entries(process.env)) {
171
+ if (typeof v === 'string') env[k] = v;
172
+ }
173
+ }
174
+
175
+ if (cmd === 'run') {
176
+ const sep = argv.indexOf('--');
177
+ if (sep === -1) usage(1);
178
+
179
+ // parse options (between 'run' and '--')
180
+ const pre = argv.slice(1, sep);
181
+ const execCmd = argv[sep + 1];
182
+ const execArgs = argv.slice(sep + 2);
183
+ if (!execCmd) usage(1);
184
+
185
+ let enableDotenv = false;
186
+ const dotenvFiles = [];
187
+ let dotenvOverride = false;
188
+
189
+ const specParts = [];
190
+ for (let i = 0; i < pre.length; i++) {
191
+ const a = pre[i];
192
+ if (a === '--dotenv') {
193
+ enableDotenv = true;
194
+ continue;
195
+ }
196
+ if (a === '--dotenv-override') {
197
+ dotenvOverride = true;
198
+ continue;
199
+ }
200
+ if (a === '--dotenv-file') {
201
+ const p = pre[++i];
202
+ if (!p) die('Missing value for --dotenv-file', 2);
203
+ dotenvFiles.push(p);
204
+ enableDotenv = true;
205
+ continue;
206
+ }
207
+ // everything else is spec text
208
+ specParts.push(a);
209
+ }
210
+
211
+ const specStr = specParts.join(' ').trim();
212
+ if (!specStr) usage(1);
213
+
214
+ const specs = specStr
215
+ .split(',')
216
+ .map(s => s.trim())
217
+ .filter(Boolean)
218
+ .map(parseSpec);
219
+
220
+ // Env load order:
221
+ // 1) existing process.env
222
+ // 2) dotenv files
223
+ // 3) Keychain secrets (dotkc) override
224
+ const env = { ...process.env };
225
+
226
+ if (enableDotenv) {
227
+ // default conventional files, relative to cwd
228
+ const cwd = process.cwd();
229
+ const defaults = [path.join(cwd, '.env'), path.join(cwd, '.env.local')];
230
+ for (const f of defaults) loadDotenvIntoEnv(env, f, dotenvOverride);
231
+ for (const f of dotenvFiles) loadDotenvIntoEnv(env, path.isAbsolute(f) ? f : path.join(cwd, f), dotenvOverride);
232
+ }
233
+
234
+ for (const sp of specs) {
235
+ if (sp.kind === 'exact') {
236
+ const v = await keytar.getPassword(sp.service, `${sp.category}:${sp.key}`);
237
+ if (v == null) die(`Missing secret: ${sp.service}:${sp.category}:${sp.key}`, 3);
238
+ env[sp.key] = v;
239
+ continue;
240
+ }
241
+
242
+ const prefix = `${sp.category}:`;
243
+ const creds = await keytar.findCredentials(sp.service);
244
+ const matches = creds.filter(c => c.account.startsWith(prefix));
245
+ if (matches.length === 0) die(`No secrets matched: ${sp.service}:${sp.category}`, 3);
246
+
247
+ for (const m of matches) {
248
+ const k = m.account.slice(prefix.length);
249
+ if (!/^[A-Z_][A-Z0-9_]*$/.test(k)) continue;
250
+ env[k] = m.password;
251
+ }
252
+ }
253
+
254
+ const child = spawn(execCmd, execArgs, { stdio: 'inherit', env, shell: false });
255
+ child.on('exit', (code, signal) => {
256
+ if (signal) process.kill(process.pid, signal);
257
+ process.exit(code ?? 1);
258
+ });
259
+ // keep parent alive until child exits
260
+ process.on('SIGINT', () => child.kill('SIGINT'));
261
+ process.on('SIGTERM', () => child.kill('SIGTERM'));
262
+ process.exitCode = 0;
263
+ } else {
264
+ usage(1);
265
+ }
266
+
267
+ usage(1);
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "dotkc",
3
+ "version": "0.1.0",
4
+ "description": "Keychain-backed secrets + dotenv-style runner for OpenClaw/local-agent security (macOS/iCloud)",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "bin": {
8
+ "dotkc": "bin/dotkc.mjs"
9
+ },
10
+ "files": [
11
+ "bin/"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "dependencies": {
17
+ "dotenv": "^16.6.1",
18
+ "keytar": "^7.9.0"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/steven-zhc/dotkc.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/steven-zhc/dotkc/issues"
26
+ },
27
+ "homepage": "https://github.com/steven-zhc/dotkc#readme"
28
+ }