dotkc-openclaw 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.
package/LICENSE ADDED
@@ -0,0 +1,153 @@
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
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor.
137
+
138
+ 7. Disclaimer of Warranty. Unless required by applicable law or
139
+ agreed to in writing, Licensor provides the Work (and each
140
+ Contributor provides its Contributions) on an "AS IS" BASIS,
141
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
142
+
143
+ 8. Limitation of Liability. In no event and under no legal theory,
144
+ whether in tort (including negligence), contract, or otherwise,
145
+ unless required by applicable law, shall any Contributor be liable
146
+ for damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing
149
+ the Work or Derivative Works thereof, You may choose to offer,
150
+ and charge a fee for, acceptance of support, warranty, indemnity,
151
+ or other liability obligations.
152
+
153
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # dotkc OpenClaw plugin (L2)
2
+
3
+ This plugin exposes **typed OpenClaw tools** for dotkc so agents can interact with dotkc via a constrained interface.
4
+
5
+ Docs: https://openclaw-dotkc.hczhang.com/
6
+
7
+ dotkc manual: https://dotkc.hczhang.com/
8
+
9
+ ## Tools
10
+
11
+ - `dotkc_status` (required)
12
+ - `dotkc_doctor` (optional)
13
+ - `dotkc_inspect` (optional, redacted by default)
14
+
15
+ ## Install (dev / local path)
16
+
17
+ ```bash
18
+ # from the OpenClaw host
19
+ openclaw plugins install -l /path/to/dotkc-openclaw
20
+ openclaw gateway restart
21
+ ```
22
+
23
+ ## Configure (~/.openclaw/openclaw.json)
24
+
25
+ ```json5
26
+ {
27
+ plugins: {
28
+ entries: {
29
+ "dotkc-openclaw-plugin": {
30
+ enabled: true,
31
+ config: {
32
+ dotkcBin: "dotkc",
33
+ specFile: "./dotkc.spec",
34
+ // vaultPath: "/path/to/dotkc.vault",
35
+ // keyPath: "~/.dotkc/key",
36
+ allowUnsafe: false
37
+ }
38
+ }
39
+ }
40
+ },
41
+
42
+ // Allow optional plugin tools (choose a profile and then opt-in)
43
+ tools: {
44
+ // profile: "coding",
45
+ allow: ["dotkc"]
46
+ }
47
+ }
48
+ ```
49
+
50
+ ## Security stance
51
+
52
+ - This plugin is designed to **avoid secrets entering model context**.
53
+ - `dotkc_inspect` uses `dotkc run --openclaw` and is expected to be **redacted**.
54
+ - Do not enable `allowUnsafe` unless you fully understand the leakage risk.
55
+
56
+ ## Notes
57
+
58
+ - Plugins run in-process with the OpenClaw Gateway. Treat this as trusted code.
59
+ - This repo is an MVP skeleton; we should add tests + stricter output filtering.
package/ROADMAP.md ADDED
@@ -0,0 +1,70 @@
1
+ # openclaw-plugin-dotkc roadmap (L2)
2
+
3
+ This roadmap focuses on the **OpenClaw plugin** (typed tools + policy + safe responses).
4
+
5
+ ## Principles
6
+
7
+ - Tools are **typed** (schema-driven), predictable, and minimal.
8
+ - Plugin is **fail-closed** on suspected leakage.
9
+ - Default stance: **never return secrets to the model**.
10
+
11
+ ## P0 — Safety guardrails
12
+
13
+ ### 1) Leak detection + fail-closed (in addition to redaction)
14
+ **Goal:** even if dotkc (or an integration) accidentally emits plaintext, do not return it to the LLM.
15
+
16
+ Add a detector pass on tool output before returning:
17
+ - Block `KEY=VALUE` patterns
18
+ - Block common token prefixes (`sk-`, `ghp_`, etc.) (configurable)
19
+ - Block high-entropy long strings (heuristic)
20
+
21
+ On match:
22
+ - Return an error like `LEAK_BLOCKED`
23
+ - Provide a short hint (inspect on host manually)
24
+
25
+ ### 2) Path restrictions
26
+ - Ensure `specFile` is within workspace (no `~`, no `/etc/...`)
27
+ - Reject traversal (`..`) unless explicitly allowed
28
+
29
+ ### 3) Config hardening
30
+ - `allowUnsafe` should require explicit opt-in + loud warning
31
+ - Consider a second "break glass" flag (two keys) for unsafe values
32
+
33
+ ## P1 — Real integration value
34
+
35
+ ### 4) Add `dotkc_run` tool (safe execution)
36
+ **Goal:** replace `exec "dotkc run ..."` patterns with a constrained tool.
37
+
38
+ Inputs:
39
+ - `specFile`
40
+ - `command[]` (argv)
41
+ - optional `cwd`
42
+
43
+ Policies:
44
+ - Require `specFile` (no ad-hoc specs)
45
+ - Enforce command allowlist (exact or regex)
46
+ - Return only:
47
+ - `exitCode`
48
+ - `durationMs`
49
+ - `stderrTail` (capped)
50
+ - optionally `stdoutTail` (capped)
51
+
52
+ ### 5) Approvals integration
53
+ - First time a command is run, require approval (optional mode)
54
+
55
+ ## P2 — Quality
56
+
57
+ ### 6) Tests
58
+ - Golden tests for JSON parse
59
+ - Failure modes for missing dotkc / bad spec file
60
+ - Leak detector tests
61
+
62
+ ### 7) Better UX
63
+ - Structured tool errors (code + hint + suggested commands)
64
+ - Better docs examples by scenario
65
+
66
+ ## P3 — Distribution
67
+
68
+ ### 8) Publish to npm
69
+ - `openclaw plugins install @hcz/openclaw-plugin-dotkc`
70
+ - Versioning + release notes
package/index.ts ADDED
@@ -0,0 +1,169 @@
1
+ import { Type } from '@sinclair/typebox';
2
+ import { spawn } from 'node:child_process';
3
+
4
+ // Prefer a stable plugin id (over package-derived ids).
5
+ export const id = 'dotkc';
6
+
7
+ function runDotkc({ dotkcBin, args, stdinText }: { dotkcBin: string; args: string[]; stdinText?: string }) {
8
+ return new Promise<{ code: number; out: string; err: string }>((resolve) => {
9
+ const p = spawn(dotkcBin, args, {
10
+ stdio: ['pipe', 'pipe', 'pipe'],
11
+ env: process.env,
12
+ });
13
+
14
+ let out = '';
15
+ let err = '';
16
+
17
+ p.stdout.on('data', (b) => (out += b.toString('utf8')));
18
+ p.stderr.on('data', (b) => (err += b.toString('utf8')));
19
+ p.on('close', (code) => resolve({ code: code ?? 1, out, err }));
20
+
21
+ if (stdinText != null) p.stdin.write(stdinText);
22
+ p.stdin.end();
23
+ });
24
+ }
25
+
26
+ function buildVaultArgs(cfg: any) {
27
+ const a: string[] = [];
28
+ if (cfg?.vaultPath) a.push('--vault', cfg.vaultPath);
29
+ if (cfg?.keyPath) a.push('--key', cfg.keyPath);
30
+ return a;
31
+ }
32
+
33
+ function tryParseOpenClawJson(text: string) {
34
+ // dotkc --openclaw returns a single JSON object to stdout.
35
+ // Be tolerant if there is trailing whitespace.
36
+ const t = String(text ?? '').trim();
37
+ if (!t) return null;
38
+ try {
39
+ return JSON.parse(t);
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Defensive redaction: keep structure, but never allow obvious value-bearing fields
47
+ * to pass through unless explicitly allowed.
48
+ *
49
+ * This is a best-effort guardrail. The primary guarantee should still come from:
50
+ * - dotkc default redaction
51
+ * - never enabling unsafe value output in agent workflows
52
+ */
53
+ function deepRedact(value: any, { allowUnsafe }: { allowUnsafe: boolean }) {
54
+ if (value == null) return value;
55
+
56
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
57
+
58
+ if (Array.isArray(value)) return value.map((v) => deepRedact(v, { allowUnsafe }));
59
+
60
+ const out: any = {};
61
+ for (const [k, v] of Object.entries(value)) {
62
+ const key = String(k);
63
+
64
+ const isEnvMap = key === 'env' || key === 'dotenv' || key === 'values';
65
+ const looksSensitiveKey = /(^|_)(value|secret|token|apikey|api_key|password)(_|$)/i.test(key);
66
+
67
+ if (!allowUnsafe && looksSensitiveKey && typeof v === 'string') {
68
+ out[key] = '[REDACTED_BY_PLUGIN]';
69
+ continue;
70
+ }
71
+
72
+ if (!allowUnsafe && isEnvMap && v && typeof v === 'object' && !Array.isArray(v)) {
73
+ const m: any = {};
74
+ for (const [ek, ev] of Object.entries(v as any)) {
75
+ m[String(ek)] = typeof ev === 'string' ? '[REDACTED_BY_PLUGIN]' : deepRedact(ev, { allowUnsafe });
76
+ }
77
+ out[key] = m;
78
+ continue;
79
+ }
80
+
81
+ out[key] = deepRedact(v, { allowUnsafe });
82
+ }
83
+ return out;
84
+ }
85
+
86
+ function toolErrorPayload({ code, error, stderr }: { code: number; error: string; stderr: string }) {
87
+ return {
88
+ ok: false,
89
+ code,
90
+ error,
91
+ stderr: (stderr ?? '').slice(0, 2000),
92
+ };
93
+ }
94
+
95
+ export default function dotkcPlugin(api: any) {
96
+ const cfg =
97
+ api?.config?.plugins?.entries?.['dotkc-openclaw-plugin']?.config ??
98
+ api?.config?.plugins?.entries?.dotkc?.config ??
99
+ api?.config?.plugins?.entries?.['dotkc']?.config;
100
+
101
+ const dotkcBin = cfg?.dotkcBin || 'dotkc';
102
+
103
+ api.registerTool({
104
+ name: 'dotkc_status',
105
+ description: 'dotkc status as OpenClaw JSON (paths + canDecrypt).',
106
+ parameters: Type.Object({}),
107
+ async execute(_id: string, _params: any) {
108
+ const args = ['status', '--openclaw', ...buildVaultArgs(cfg)];
109
+ const res = await runDotkc({ dotkcBin, args });
110
+ const parsed = tryParseOpenClawJson(res.out);
111
+ if (!parsed || parsed.format !== 'openclaw') {
112
+ return { content: [{ type: 'text', text: JSON.stringify(toolErrorPayload({ code: res.code, error: 'dotkc_status: failed to parse dotkc --openclaw JSON', stderr: res.err }), null, 2) }] };
113
+ }
114
+ const safe = deepRedact(parsed, { allowUnsafe: false });
115
+ return { content: [{ type: 'text', text: JSON.stringify(safe, null, 2) }] };
116
+ },
117
+ });
118
+
119
+ api.registerTool(
120
+ {
121
+ name: 'dotkc_doctor',
122
+ description: 'dotkc doctor as OpenClaw JSON diagnostics.',
123
+ parameters: Type.Object({}),
124
+ async execute(_id: string, _params: any) {
125
+ const args = ['doctor', '--openclaw', ...buildVaultArgs(cfg)];
126
+ const res = await runDotkc({ dotkcBin, args });
127
+ const parsed = tryParseOpenClawJson(res.out);
128
+ if (!parsed || parsed.format !== 'openclaw') {
129
+ return { content: [{ type: 'text', text: JSON.stringify(toolErrorPayload({ code: res.code, error: 'dotkc_doctor: failed to parse dotkc --openclaw JSON', stderr: res.err }), null, 2) }] };
130
+ }
131
+ const safe = deepRedact(parsed, { allowUnsafe: false });
132
+ return { content: [{ type: 'text', text: JSON.stringify(safe, null, 2) }] };
133
+ },
134
+ },
135
+ { optional: true },
136
+ );
137
+
138
+ api.registerTool(
139
+ {
140
+ name: 'dotkc_inspect',
141
+ description: 'Resolve allowlisted specs and return a redacted env preview (OpenClaw JSON).',
142
+ parameters: Type.Object({
143
+ specFile: Type.Optional(Type.String({ description: 'Path to spec allowlist file (defaults to plugin config specFile).' })),
144
+ }),
145
+ async execute(_id: string, params: any) {
146
+ const specFile = params?.specFile || cfg?.specFile || './dotkc.spec';
147
+
148
+ // Security posture: never allow unsafe values through this tool by default.
149
+ const allowUnsafe = Boolean(cfg?.allowUnsafe);
150
+
151
+ const args = ['run', '--spec-file', specFile, '--openclaw', ...buildVaultArgs(cfg)];
152
+ if (allowUnsafe) args.splice(1, 0, '--unsafe-values');
153
+
154
+ const res = await runDotkc({ dotkcBin, args });
155
+ const parsed = tryParseOpenClawJson(res.out);
156
+ if (!parsed || parsed.format !== 'openclaw') {
157
+ return { content: [{ type: 'text', text: JSON.stringify(toolErrorPayload({ code: res.code, error: 'dotkc_inspect: failed to parse dotkc --openclaw JSON', stderr: res.err }), null, 2) }] };
158
+ }
159
+
160
+ // Defensive redaction: even if dotkc (or a wrapper) accidentally includes cleartext values,
161
+ // never return suspicious value-like fields to the model unless allowUnsafe is explicitly enabled.
162
+ const safe = deepRedact(parsed, { allowUnsafe });
163
+
164
+ return { content: [{ type: 'text', text: JSON.stringify(safe, null, 2) }] };
165
+ },
166
+ },
167
+ { optional: true },
168
+ );
169
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "id": "dotkc",
3
+ "label": "dotkc",
4
+ "description": "dotkc integration: safe secrets inspection + env-injection workflows for OpenClaw",
5
+ "kind": "tools",
6
+ "configSchema": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "dotkcBin": { "type": "string", "default": "dotkc" },
11
+ "vaultPath": { "type": "string" },
12
+ "keyPath": { "type": "string" },
13
+ "specFile": { "type": "string", "default": "./dotkc.spec" },
14
+ "allowUnsafe": { "type": "boolean", "default": false }
15
+ }
16
+ },
17
+ "uiHints": {
18
+ "dotkcBin": { "label": "dotkc binary", "placeholder": "dotkc" },
19
+ "vaultPath": { "label": "Vault path (optional)", "placeholder": "/path/to/dotkc.vault" },
20
+ "keyPath": { "label": "Key path (optional)", "placeholder": "~/.dotkc/key", "sensitive": true },
21
+ "specFile": { "label": "Spec allowlist file", "placeholder": "./dotkc.spec" },
22
+ "allowUnsafe": { "label": "Allow unsafe values", "help": "If enabled, dotkc_inspect may return raw values. Strongly discouraged." }
23
+ },
24
+ "tools": [
25
+ {
26
+ "name": "dotkc_status",
27
+ "description": "dotkc status as OpenClaw JSON (paths + canDecrypt).",
28
+ "optional": false
29
+ },
30
+ {
31
+ "name": "dotkc_doctor",
32
+ "description": "dotkc doctor as OpenClaw JSON diagnostics.",
33
+ "optional": true
34
+ },
35
+ {
36
+ "name": "dotkc_inspect",
37
+ "description": "Resolve allowlisted specs and return redacted env preview (never prints values by default).",
38
+ "optional": true
39
+ }
40
+ ]
41
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "dotkc-openclaw",
3
+ "version": "0.1.0",
4
+ "description": "OpenClaw plugin: dotkc integration (typed tools + safe secrets inspection)",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/steven-zhc/dotkc-openclaw.git"
9
+ },
10
+ "homepage": "https://openclaw-dotkc.hczhang.com/",
11
+ "type": "module",
12
+ "main": "index.ts",
13
+ "files": [
14
+ "index.ts",
15
+ "openclaw.plugin.json",
16
+ "README.md",
17
+ "LICENSE",
18
+ "ROADMAP.md"
19
+ ],
20
+ "openclaw": {
21
+ "extensions": ["./index.ts"]
22
+ },
23
+ "dependencies": {
24
+ "@sinclair/typebox": "^0.34.41"
25
+ }
26
+ }