@clawkeepers/cli 0.1.0-beta.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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +206 -0
  3. package/README.md +52 -0
  4. package/dist/bin/clawos.js +2 -0
  5. package/dist/bin/config-transaction.mjs +56 -0
  6. package/dist/bin/gateway-rpc.mjs +57 -0
  7. package/dist/index.d.ts +8 -0
  8. package/dist/index.js +6709 -0
  9. package/dist/templates/blueprints/LICENSE +21 -0
  10. package/dist/templates/blueprints/NOTICE +206 -0
  11. package/dist/templates/blueprints/assistant/AGENTS.md +7 -0
  12. package/dist/templates/blueprints/assistant/README.md +11 -0
  13. package/dist/templates/blueprints/assistant/SOUL.md +3 -0
  14. package/dist/templates/blueprints/assistant/blueprint.json +27 -0
  15. package/dist/templates/blueprints/blueprint.schema.json +148 -0
  16. package/dist/templates/blueprints/coder/AGENTS.md +7 -0
  17. package/dist/templates/blueprints/coder/README.md +11 -0
  18. package/dist/templates/blueprints/coder/SOUL.md +3 -0
  19. package/dist/templates/blueprints/coder/blueprint.json +30 -0
  20. package/dist/templates/blueprints/ops/AGENTS.md +7 -0
  21. package/dist/templates/blueprints/ops/README.md +11 -0
  22. package/dist/templates/blueprints/ops/SOUL.md +3 -0
  23. package/dist/templates/blueprints/ops/blueprint.json +27 -0
  24. package/dist/templates/blueprints/package.json +22 -0
  25. package/dist/templates/blueprints/researcher/AGENTS.md +7 -0
  26. package/dist/templates/blueprints/researcher/README.md +11 -0
  27. package/dist/templates/blueprints/researcher/SOUL.md +3 -0
  28. package/dist/templates/blueprints/researcher/blueprint.json +30 -0
  29. package/dist/templates/clawos.conf +10 -0
  30. package/dist/templates/clawos.lock.json +19 -0
  31. package/dist/templates/config.d/00-baseline.json5 +26 -0
  32. package/dist/templates/config.d/05-policy-runtime.json5 +18 -0
  33. package/dist/templates/config.d/10-plugins.json5 +4 -0
  34. package/dist/templates/config.d/20-sandbox.json5 +8 -0
  35. package/dist/templates/config.d/30-agents.json5 +4 -0
  36. package/dist/templates/config.d/90-local.json5 +2 -0
  37. package/dist/templates/gatekeepers.json +13 -0
  38. package/dist/templates/plugins/THIRD-PARTY-NOTICES +23 -0
  39. package/dist/templates/plugins/catalog.json +1 -0
  40. package/dist/templates/plugins/clawos-kernel/LICENSE +21 -0
  41. package/dist/templates/plugins/clawos-kernel/NOTICE +206 -0
  42. package/dist/templates/plugins/clawos-kernel/THIRD-PARTY-NOTICES +23 -0
  43. package/dist/templates/plugins/clawos-kernel/config.schema.json +14 -0
  44. package/dist/templates/plugins/clawos-kernel/dist/index.js +9847 -0
  45. package/dist/templates/plugins/clawos-kernel/openclaw.plugin.json +137 -0
  46. package/dist/templates/plugins/clawos-kernel/package.json +1 -0
  47. package/dist/templates/plugins/gatekeeper-fs/LICENSE +21 -0
  48. package/dist/templates/plugins/gatekeeper-fs/NOTICE +206 -0
  49. package/dist/templates/plugins/gatekeeper-fs/THIRD-PARTY-NOTICES +23 -0
  50. package/dist/templates/plugins/gatekeeper-fs/dist/index.js +9581 -0
  51. package/dist/templates/plugins/gatekeeper-fs/openclaw.plugin.json +30 -0
  52. package/dist/templates/plugins/gatekeeper-fs/package.json +1 -0
  53. package/dist/templates/plugins/install-policy.mjs +4734 -0
  54. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ControlStackAI
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/NOTICE ADDED
@@ -0,0 +1,206 @@
1
+ OpenClaw OS
2
+ Copyright (c) 2026 ControlStackAI
3
+ Original project contributions are licensed under the MIT License; see LICENSE.
4
+ Third-party and adapted material retains its applicable license terms.
5
+
6
+ OpenClaw (https://github.com/openclaw/openclaw) provides the separately installed,
7
+ unmodified agent runtime, Gateway and public plugin interfaces. Its pinned
8
+ v2026.9.2 license is MIT, copyright (c) 2026 OpenClaw Foundation; its own
9
+ THIRD_PARTY_NOTICES.md applies to incorporated upstream dependencies.
10
+
11
+ Cloudflare OS (https://github.com/cloudflare/cloudflare-os), by Cloudflare and
12
+ its contributors, provides architectural foundations and adapted material:
13
+ capability introductions, gatekeepers, approval/simulation contracts, observers,
14
+ and kernel review/authoring guidance. OpenClaw OS contributors modified these
15
+ contracts and documents for a self-hosted, single-process, tool-calling plugin
16
+ runtime. Cloudflare OS Starter (https://github.com/cloudflare/cloudflare-os-starter)
17
+ informed wrapper-owned customization and the upgrade discipline.
18
+
19
+ Cloudflare OS and Cloudflare OS Starter are Apache-2.0 licensed. Their retained
20
+ material is not relicensed by the project's MIT license. The applicable Apache
21
+ License 2.0 text is reproduced below. The original source distribution includes
22
+ further provenance in docs/acknowledgments.md. Other dependencies retain their
23
+ respective licenses and notices, including generated THIRD-PARTY-NOTICES for
24
+ bundled dependencies.
25
+
26
+ This is an independent project, not an upstream-endorsed product. No affiliation,
27
+ endorsement or rights to upstream trademarks are implied.
28
+
29
+ --- Apache License 2.0: retained Cloudflare material ---
30
+
31
+ Apache License
32
+ Version 2.0, January 2004
33
+ http://www.apache.org/licenses/
34
+
35
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
36
+
37
+ 1. Definitions.
38
+
39
+ "License" shall mean the terms and conditions for use, reproduction,
40
+ and distribution as defined by Sections 1 through 9 of this document.
41
+
42
+ "Licensor" shall mean the copyright owner or entity authorized by
43
+ the copyright owner that is granting the License.
44
+
45
+ "Legal Entity" shall mean the union of the acting entity and all
46
+ other entities that control, are controlled by, or are under common
47
+ control with that entity. For the purposes of this definition,
48
+ "control" means (i) the power, direct or indirect, to cause the
49
+ direction or management of such entity, whether by contract or
50
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
51
+ outstanding shares, or (iii) beneficial ownership of such entity.
52
+
53
+ "You" (or "Your") shall mean an individual or Legal Entity
54
+ exercising permissions granted by this License.
55
+
56
+ "Source" form shall mean the preferred form for making modifications,
57
+ including but not limited to software source code, documentation
58
+ source, and configuration files.
59
+
60
+ "Object" form shall mean any form resulting from mechanical
61
+ transformation or translation of a Source form, including but
62
+ not limited to compiled object code, generated documentation,
63
+ and conversions to other media types.
64
+
65
+ "Work" shall mean the work of authorship, whether in Source or
66
+ Object form, made available under the License, as indicated by a
67
+ copyright notice that is included in or attached to the work
68
+ (an example is provided in the Appendix below).
69
+
70
+ "Derivative Works" shall mean any work, whether in Source or Object
71
+ form, that is based on (or derived from) the Work and for which the
72
+ editorial revisions, annotations, elaborations, or other modifications
73
+ represent, as a whole, an original work of authorship. For the purposes
74
+ of this License, Derivative Works shall not include works that remain
75
+ separable from, or merely link (or bind by name) to the interfaces of,
76
+ the Work and Derivative Works thereof.
77
+
78
+ "Contribution" shall mean any work of authorship, including
79
+ the original version of the Work and any modifications or additions
80
+ to that Work or Derivative Works thereof, that is intentionally
81
+ submitted to Licensor for inclusion in the Work by the copyright owner
82
+ or by an individual or Legal Entity authorized to submit on behalf of
83
+ the copyright owner. For the purposes of this definition, "submitted"
84
+ means any form of electronic, verbal, or written communication sent
85
+ to the Licensor or its representatives, including but not limited to
86
+ communication on electronic mailing lists, source code control systems,
87
+ and issue tracking systems that are managed by, or on behalf of, the
88
+ Licensor for the purpose of discussing and improving the Work, but
89
+ excluding communication that is conspicuously marked or otherwise
90
+ designated in writing by the copyright owner as "Not a Contribution."
91
+
92
+ "Contributor" shall mean Licensor and any individual or Legal Entity
93
+ on behalf of whom a Contribution has been received by Licensor and
94
+ subsequently incorporated within the Work.
95
+
96
+ 2. Grant of Copyright License. Subject to the terms and conditions of
97
+ this License, each Contributor hereby grants to You a perpetual,
98
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
99
+ copyright license to reproduce, prepare Derivative Works of,
100
+ publicly display, publicly perform, sublicense, and distribute the
101
+ Work and such Derivative Works in Source or Object form.
102
+
103
+ 3. Grant of Patent License. Subject to the terms and conditions of
104
+ this License, each Contributor hereby grants to You a perpetual,
105
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
106
+ (except as stated in this section) patent license to make, have made,
107
+ use, offer to sell, sell, import, and otherwise transfer the Work,
108
+ where such license applies only to those patent claims licensable
109
+ by such Contributor that are necessarily infringed by their
110
+ Contribution(s) alone or by combination of their Contribution(s)
111
+ with the Work to which such Contribution(s) was submitted. If You
112
+ institute patent litigation against any entity (including a
113
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
114
+ or a Contribution incorporated within the Work constitutes direct
115
+ or contributory patent infringement, then any patent licenses
116
+ granted to You under this License for that Work shall terminate
117
+ as of the date such litigation is filed.
118
+
119
+ 4. Redistribution. You may reproduce and distribute copies of the
120
+ Work or Derivative Works thereof in any medium, with or without
121
+ modifications, and in Source or Object form, provided that You
122
+ meet the following conditions:
123
+
124
+ (a) You must give any other recipients of the Work or
125
+ Derivative Works a copy of this License; and
126
+
127
+ (b) You must cause any modified files to carry prominent notices
128
+ stating that You changed the files; and
129
+
130
+ (c) You must retain, in the Source form of any Derivative Works
131
+ that You distribute, all copyright, patent, trademark, and
132
+ attribution notices from the Source form of the Work,
133
+ excluding those notices that do not pertain to any part of
134
+ the Derivative Works; and
135
+
136
+ (d) If the Work includes a "NOTICE" text file as part of its
137
+ distribution, then any Derivative Works that You distribute must
138
+ include a readable copy of the attribution notices contained
139
+ within such NOTICE file, excluding those notices that do not
140
+ pertain to any part of the Derivative Works, in at least one
141
+ of the following places: within a NOTICE text file distributed
142
+ as part of the Derivative Works; within the Source form or
143
+ documentation, if provided along with the Derivative Works; or,
144
+ within a display generated by the Derivative Works, if and
145
+ wherever such third-party notices normally appear. The contents
146
+ of the NOTICE file are for informational purposes only and
147
+ do not modify the License. You may add Your own attribution
148
+ notices within Derivative Works that You distribute, alongside
149
+ or as an addendum to the NOTICE text from the Work, provided
150
+ that such additional attribution notices cannot be construed
151
+ as modifying the License.
152
+
153
+ You may add Your own copyright statement to Your modifications and
154
+ may provide additional or different license terms and conditions
155
+ for use, reproduction, or distribution of Your modifications, or
156
+ for any such Derivative Works as a whole, provided Your use,
157
+ reproduction, and distribution of the Work otherwise complies with
158
+ the conditions stated in this License.
159
+
160
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
161
+ any Contribution intentionally submitted for inclusion in the Work
162
+ by You to the Licensor shall be under the terms and conditions of
163
+ this License, without any additional terms or conditions.
164
+ Notwithstanding the above, nothing herein shall supersede or modify
165
+ the terms of any separate license agreement you may have executed
166
+ with Licensor regarding such Contributions.
167
+
168
+ 6. Trademarks. This License does not grant permission to use the trade
169
+ names, trademarks, service marks, or product names of the Licensor,
170
+ except as required for reasonable and customary use in describing the
171
+ origin of the Work and reproducing the content of the NOTICE file.
172
+
173
+ 7. Disclaimer of Warranty. Unless required by applicable law or
174
+ agreed to in writing, Licensor provides the Work (and each
175
+ Contributor provides its Contributions) on an "AS IS" BASIS,
176
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
177
+ implied, including, without limitation, any warranties or conditions
178
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
179
+ PARTICULAR PURPOSE. You are solely responsible for determining the
180
+ appropriateness of using or redistributing the Work and assume any
181
+ risks associated with Your exercise of permissions under this License.
182
+
183
+ 8. Limitation of Liability. In no event and under no legal theory,
184
+ whether in tort (including negligence), contract, or otherwise,
185
+ unless required by applicable law (such as deliberate and grossly
186
+ negligent acts) or agreed to in writing, shall any Contributor be
187
+ liable to You for damages, including any direct, indirect, special,
188
+ incidental, or consequential damages of any character arising as a
189
+ result of this License or out of the use or inability to use the
190
+ Work (including but not limited to damages for loss of goodwill,
191
+ work stoppage, computer failure or malfunction, or any and all
192
+ other commercial damages or losses), even if such Contributor
193
+ has been advised of the possibility of such damages.
194
+
195
+ 9. Accepting Warranty or Additional Liability. While redistributing
196
+ the Work or Derivative Works thereof, You may choose to offer,
197
+ and charge a fee for, acceptance of support, warranty, indemnity,
198
+ or other liability obligations and/or rights consistent with this
199
+ License. However, in accepting such obligations, You may act only
200
+ on Your own behalf and on Your sole responsibility, not on behalf
201
+ of any other Contributor, and only if You agree to indemnify,
202
+ defend, and hold each Contributor harmless for any liability
203
+ incurred by, or claims asserted against, such Contributor by reason
204
+ of your accepting any such warranty or additional liability.
205
+
206
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @clawkeepers/cli — `clawos`
2
+
3
+ Host orchestration uses upstream CLI/config APIs. Capability operations use the live
4
+ Gateway's paired-device operator RPCs; the CLI never opens the kernel database.
5
+
6
+ Implemented commands:
7
+
8
+ ```text
9
+ clawos install [--yes] clawos cell create|list
10
+ clawos status clawos doctor
11
+ clawos config apply [--dry-run] clawos backup create|restore
12
+ clawos kernel status clawos gatekeeper list|connect <vendor>
13
+ clawos grant add --agent <id> <url> [--title <title>] [--audience owner-only]
14
+ clawos grant list [--agent <id>] clawos grant revoke <handle>
15
+ clawos approvals list clawos approvals apply|reject|revert <id,id|all>
16
+ clawos approvals grant|reject-request <id,id|all>
17
+ clawos audit tail [--limit 1–1000]
18
+ ```
19
+
20
+ All accept `--cell <name>` (default: `default`) and `--json`. `audit tail` is a
21
+ bounded, newest-first snapshot, not a follow stream; time filtering is not yet
22
+ implemented and unsupported options are rejected. Approval commands expose the
23
+ kernel's existing decisions, not a promise that a driver can apply or revert:
24
+ real filesystem writes remain disabled. These mutating commands are not all
25
+ idempotent.
26
+
27
+ The cell registry selects the loopback port; cell naming selects both state and
28
+ config paths. No arbitrary endpoint, token, or operator-identity option is accepted.
29
+ The installed public SDK runs in a separate explicitly cell-scoped process. It
30
+ bootstraps using the cell's local token, closes that connection, reconnects with the
31
+ SDK-issued device credential, and only then sends the operator request. Pairing
32
+ failure, invalid input, an absent Gateway, or a malformed response fails closed.
33
+ The client resolves installer-created `CLAWOS_GATEWAY_TOKEN` env SecretRefs from the
34
+ cell's `.env`, or a directly configured local token; other authentication providers
35
+ are not yet supported. Credentials remain in process memory and never enter argv,
36
+ stdout, or error messages. RPC parameters travel to the helper on stdin.
37
+
38
+ With the kernel plugin enabled, `openclaw os status|grants|approvals|audit --json`
39
+ forwards to this same client. Both the CLI package and a registered cell are required.
40
+ Static plugin manifest metadata owns the `os` root command discovery.
41
+
42
+ The source installer projects the bundled kernel/filesystem plugins and configures
43
+ the cell-local install policy. `clawos install-policy` evaluates installation
44
+ requests for upstream; it is not a general plugin-management interface.
45
+
46
+ `clawos gatekeeper connect <vendor>` starts the kernel's single-use connection
47
+ flow. Static filesystem account connection has live Phase 3 evidence; real GitHub
48
+ OAuth and effects require Phase 4 acceptance. No connection grants resources by
49
+ itself. Shared grants are rejected under the owner-only beta boundary.
50
+
51
+ Blueprint application, the full update/rollback pipeline and general gatekeeper
52
+ installation commands remain later-phase work; they are not successful stubs.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import("../index.js").then((m) => m.main(process.argv.slice(2))).catch((e) => { console.error(e?.message ?? e); process.exit(1); });
@@ -0,0 +1,56 @@
1
+ // Runs only in the target cell process. Resolve the PUBLIC SDK from the installed upstream binary;
2
+ // never bundle upstream, use a private subpath, or load it into the development-host test process.
3
+ import { createRequire } from "node:module";
4
+ import { realpathSync, readFileSync } from "node:fs";
5
+ import { pathToFileURL } from "node:url";
6
+
7
+ const [upstreamBin, patchFile, baseHash] = process.argv.slice(2);
8
+ const object = v => v !== null && typeof v === "object" && !Array.isArray(v);
9
+ function merge(base, patch) {
10
+ const out = object(base) ? structuredClone(base) : {};
11
+ for (const [key, value] of Object.entries(patch)) {
12
+ if (["__proto__", "prototype", "constructor"].includes(key)) throw new Error("invalid key");
13
+ if (value === null) delete out[key];
14
+ else out[key] = object(value) ? merge(out[key], value) : structuredClone(value);
15
+ }
16
+ return out;
17
+ }
18
+ function paths(value, prefix = []) {
19
+ return Object.entries(value).flatMap(([key, val]) => {
20
+ const path = [...prefix, key];
21
+ return object(val) && Object.keys(val).length ? paths(val, path) : [path];
22
+ });
23
+ }
24
+ try {
25
+ if (!/^[a-f0-9]{64}$/.test(baseHash ?? "")) throw new Error("missing snapshot");
26
+ const require = createRequire(realpathSync(upstreamBin));
27
+ const { mutateConfigFile } = await import(pathToFileURL(require.resolve("openclaw/plugin-sdk/config-mutation")).href);
28
+ const patch = JSON.parse(readFileSync(patchFile, "utf8"));
29
+ if (!object(patch)) throw new Error("invalid patch");
30
+ const leafPaths = paths(patch);
31
+ const unsetPaths = leafPaths.filter(path => path.reduce((v, k) => v[k], patch) === null);
32
+ const result = await mutateConfigFile({
33
+ base: "source",
34
+ baseHash,
35
+ writeOptions: {
36
+ auditOrigin: "cli",
37
+ skipOutputLogs: true,
38
+ explicitSetPaths: leafPaths.filter(path => !unsetPaths.includes(path)),
39
+ explicitSetValueSource: patch,
40
+ unsetPaths,
41
+ // Require upstream's guarded atomic root publication; redirected includes fail closed.
42
+ beforeCommit: () => {},
43
+ },
44
+ mutate(draft) {
45
+ const next = merge(draft, patch);
46
+ for (const key of Object.keys(draft)) delete draft[key];
47
+ Object.assign(draft, next);
48
+ },
49
+ });
50
+ if (!result.persistedHash) throw new Error("missing persisted snapshot");
51
+ process.stdout.write(JSON.stringify({ persistedHash: result.persistedHash }));
52
+ } catch {
53
+ // SDK errors may contain source values. Never relay them, even through a pattern redactor.
54
+ process.stderr.write("transaction refused: config changed or upstream validation failed; no checkpoint recorded\n");
55
+ process.exitCode = 1;
56
+ }
@@ -0,0 +1,57 @@
1
+ // Target-cell subprocess: only the installed public SDK is imported. No tokens or RPC bodies in argv/logs.
2
+ import { createRequire } from 'node:module';
3
+ import { realpathSync, readFileSync } from 'node:fs';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { join } from 'node:path';
6
+ const [upstreamBin] = process.argv.slice(2);
7
+ let client;
8
+ try {
9
+ const state = process.env.OPENCLAW_STATE_DIR;
10
+ if (!state || process.env.OPENCLAW_CONFIG_PATH !== join(state, 'openclaw.json')) throw new Error();
11
+ const port = Number(process.env.OPENCLAW_GATEWAY_PORT);
12
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error();
13
+ let input = '';
14
+ for await (const chunk of process.stdin) { input += chunk; if (input.length > 65536) throw new Error(); }
15
+ const { method, params } = JSON.parse(input);
16
+ if (!['os.maintenance.set', 'os.status', 'os.grants.list', 'os.grants.introduce', 'os.grants.revoke', 'os.audit.query', 'os.approvals.list', 'os.approvals.apply', 'os.approvals.reject', 'os.approvals.revert', 'os.gatekeepers.list', 'os.gatekeepers.connect', 'os.requests.approve', 'os.requests.reject'].includes(method)) throw new Error();
17
+ // Installer-created cells use an env SecretRef. Resolve only that exact local field, never arbitrary providers.
18
+ const config = JSON.parse(readFileSync(process.env.OPENCLAW_CONFIG_PATH, 'utf8'));
19
+ const auth = config.gateway?.auth;
20
+ let token;
21
+ if (auth?.mode !== 'token') throw new Error();
22
+ if (typeof auth.token === 'string') token = auth.token;
23
+ else if (auth.token?.source === 'env' && auth.token.provider === 'default' && auth.token.id === 'CLAWOS_GATEWAY_TOKEN') {
24
+ token = readFileSync(join(state, '.env'), 'utf8').split('\n').find(line => line.startsWith('CLAWOS_GATEWAY_TOKEN='))?.slice('CLAWOS_GATEWAY_TOKEN='.length);
25
+ }
26
+ if (!token) throw new Error();
27
+ const require = createRequire(realpathSync(upstreamBin));
28
+ const { GatewayClient } = await import(pathToFileURL(require.resolve('openclaw/plugin-sdk/gateway-runtime')).href);
29
+ async function connect(credentials) {
30
+ let timer;
31
+ try {
32
+ return await new Promise((resolve, reject) => {
33
+ timer = setTimeout(() => reject(new Error()), 30000);
34
+ client = new GatewayClient({ url: `ws://127.0.0.1:${port}`, ...credentials, env: process.env,
35
+ clientName: 'cli', mode: 'cli', role: 'operator', scopes: ['operator.admin'], requestTimeoutMs: 30000,
36
+ hostDeps: { logDebug() {}, logError() {} }, onHelloOk: resolve,
37
+ onConnectError: () => reject(new Error()), onClose: () => reject(new Error()) });
38
+ client.start();
39
+ });
40
+ } finally { clearTimeout(timer); }
41
+ }
42
+ const hello = await connect({ token });
43
+ if (!hello.auth?.deviceToken) throw new Error();
44
+ await client.stopAndWait({ timeoutMs: 5000 });
45
+ await connect({ deviceToken: hello.auth.deviceToken });
46
+ let result = await client.request(method, params);
47
+ if (method === 'os.gatekeepers.connect') {
48
+ if (typeof result?.url !== 'string' || !/^\/os\/gatekeeper\/[a-z][a-z0-9_]{0,63}\/oauth\/start\?state=[A-Za-z0-9_-]{32}$/.test(result.url)) throw new Error();
49
+ result = { url: new URL(result.url, `http://127.0.0.1:${port}`).href };
50
+ }
51
+ process.stdout.write(JSON.stringify({ ok: true, result }));
52
+ } catch {
53
+ process.stderr.write('Kernel RPC unavailable or unauthorized; verify this cell and its device pairing.\n');
54
+ process.exitCode = 1;
55
+ } finally {
56
+ try { await client?.stopAndWait({ timeoutMs: 5000 }); } catch { process.exitCode = 1; }
57
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `clawos` CLI entry point.
3
+ *
4
+ * Host layer: install, cell, status, doctor, config apply, backup. Kernel administration uses paired operator RPC. Blueprints provision versioned agent workspaces. Update and rollback remain separate-phase work.
5
+ */
6
+ declare function main(argv: string[]): Promise<void>;
7
+
8
+ export { main };