@openclawbrain/openclaw 0.1.0 → 0.1.2
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 +201 -0
- package/README.md +120 -5
- package/dist/src/cli.d.ts +12 -0
- package/dist/src/cli.js +152 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/index.d.ts +692 -4
- package/dist/src/index.js +2243 -8
- package/dist/src/index.js.map +1 -1
- package/package.json +15 -11
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 2026 Jonathan Gu (jonathangu@gmail.com)
|
|
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
CHANGED
|
@@ -1,16 +1,66 @@
|
|
|
1
1
|
# @openclawbrain/openclaw
|
|
2
2
|
|
|
3
|
-
OpenClaw
|
|
3
|
+
OpenClaw integration helpers for promoted-pack compile consumption and normalized event emission.
|
|
4
4
|
|
|
5
|
-
Use this package when OpenClaw needs a narrow, typed bridge over promoted packs
|
|
5
|
+
Use this package when OpenClaw needs a narrow, typed bridge over promoted packs:
|
|
6
6
|
|
|
7
|
+
- bootstrap an initial attach pack from a normalized export and activate it
|
|
7
8
|
- resolve the active promoted pack from activation pointers
|
|
8
|
-
- consume `runtime_compile.v1` through
|
|
9
|
+
- consume `runtime_compile.v1` through an activation-aware serve-path helper
|
|
10
|
+
- surface compact attach status over activation health, active pack freshness, and compile/handoff evidence
|
|
11
|
+
- surface learned-route diagnostics alongside compiled context
|
|
9
12
|
- emit normalized interaction and feedback events for learner handoff
|
|
10
13
|
- optionally write learner-facing event-export bundles on disk
|
|
14
|
+
- run a bounded async teacher loop that converts normalized exports into canonical supervision artifacts and future learner inputs
|
|
15
|
+
- feed learner-side PG route refreshes only with explicit collected labels rather than heuristic learned-label propagation
|
|
16
|
+
- keep the post-attach loop real with canonical supervision, bounded learner refresh, candidate promotion, and later compile freshness
|
|
17
|
+
|
|
18
|
+
The post-attach loop stays off the hot path: it exports turns, builds candidate packs, and promotes them later rather than mutating the current active pack in place.
|
|
11
19
|
|
|
12
20
|
```ts
|
|
13
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
bootstrapRuntimeAttach,
|
|
23
|
+
compileRuntimeContext,
|
|
24
|
+
describeAttachStatus,
|
|
25
|
+
rollbackRuntimeAttach,
|
|
26
|
+
runContinuousProductLoopTurn,
|
|
27
|
+
runRuntimeTurn
|
|
28
|
+
} from "@openclawbrain/openclaw";
|
|
29
|
+
|
|
30
|
+
const attach = bootstrapRuntimeAttach({
|
|
31
|
+
activationRoot: "/var/openclawbrain/activation",
|
|
32
|
+
packRoot: "/var/openclawbrain/packs/bootstrap",
|
|
33
|
+
packLabel: "customer-launch-attach",
|
|
34
|
+
workspace: {
|
|
35
|
+
workspaceId: "workspace-1",
|
|
36
|
+
snapshotId: "workspace-1@snapshot-1",
|
|
37
|
+
capturedAt: "2026-03-07T16:59:00.000Z",
|
|
38
|
+
rootDir: "/workspace/openclawbrain",
|
|
39
|
+
revision: "attach-rev-1"
|
|
40
|
+
},
|
|
41
|
+
interactionEvents: [],
|
|
42
|
+
feedbackEvents: []
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log(attach.status.successSignals);
|
|
46
|
+
|
|
47
|
+
const attachStatus = describeAttachStatus({
|
|
48
|
+
activationRoot: "/var/openclawbrain/activation"
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log(attachStatus.inspection.active?.packId);
|
|
52
|
+
console.log(attachStatus.compile?.handoffState);
|
|
53
|
+
console.log(attachStatus.landingBoundaries.compileBoundary.activationSlot);
|
|
54
|
+
console.log(attachStatus.landingBoundaries.failOpenSemantics.eventExportWriteFailurePreservesCompile);
|
|
55
|
+
|
|
56
|
+
const rollbackPreview = rollbackRuntimeAttach({
|
|
57
|
+
activationRoot: "/var/openclawbrain/activation",
|
|
58
|
+
dryRun: true
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log(rollbackPreview.allowed);
|
|
62
|
+
console.log(rollbackPreview.before.activePackId);
|
|
63
|
+
console.log(rollbackPreview.after?.activePackId);
|
|
14
64
|
|
|
15
65
|
const compileResult = compileRuntimeContext({
|
|
16
66
|
activationRoot: "/var/openclawbrain/activation",
|
|
@@ -18,6 +68,11 @@ const compileResult = compileRuntimeContext({
|
|
|
18
68
|
runtimeHints: ["feedback scanner"]
|
|
19
69
|
});
|
|
20
70
|
|
|
71
|
+
if (compileResult.ok) {
|
|
72
|
+
console.log(compileResult.compileResponse.diagnostics.usedLearnedRouteFn);
|
|
73
|
+
console.log(compileResult.compileResponse.diagnostics.routerIdentity);
|
|
74
|
+
}
|
|
75
|
+
|
|
21
76
|
const turnResult = runRuntimeTurn(
|
|
22
77
|
{
|
|
23
78
|
sessionId: "session-123",
|
|
@@ -38,6 +93,66 @@ const turnResult = runRuntimeTurn(
|
|
|
38
93
|
activationRoot: "/var/openclawbrain/activation"
|
|
39
94
|
}
|
|
40
95
|
);
|
|
96
|
+
|
|
97
|
+
const productLoopTurn = runContinuousProductLoopTurn({
|
|
98
|
+
activationRoot: "/var/openclawbrain/activation",
|
|
99
|
+
loopRoot: "/var/openclawbrain/runtime-loop",
|
|
100
|
+
packLabel: "post-attach-loop",
|
|
101
|
+
workspace: {
|
|
102
|
+
workspaceId: "workspace-1",
|
|
103
|
+
snapshotId: "workspace-1@snapshot-2",
|
|
104
|
+
capturedAt: "2026-03-07T18:00:30.000Z",
|
|
105
|
+
rootDir: "/workspace/openclawbrain",
|
|
106
|
+
revision: "runtime-loop-rev-2"
|
|
107
|
+
},
|
|
108
|
+
turn: {
|
|
109
|
+
sessionId: "session-123",
|
|
110
|
+
channel: "whatsapp",
|
|
111
|
+
userMessage: "Compile the fresher learned route artifact after promotion.",
|
|
112
|
+
feedback: [{ content: "Prefer the fresher learned route artifact after promotion." }]
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
console.log(productLoopTurn.compileActiveVersion);
|
|
117
|
+
console.log(productLoopTurn.learning.promoted);
|
|
118
|
+
console.log(productLoopTurn.state.currentActivePack?.routerIdentity);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
This package stays fail-open for non-learned-required compile misses, and event-export write failures do not erase successful compile output.
|
|
122
|
+
|
|
123
|
+
## Boundary truth
|
|
124
|
+
|
|
125
|
+
`describeAttachStatus()` now returns `landingBoundaries`, a compact runtime-facing statement of the actual OpenClaw handoff:
|
|
126
|
+
|
|
127
|
+
- `compileBoundary`: OpenClaw compiles only from activation's `active` slot through `compileRuntimeContext()` / `runtime_compile.v1`
|
|
128
|
+
- `eventExportBoundary`: `runRuntimeTurn()` emits normalized interaction/feedback exports for later learning handoff, and bundle-write failure does not erase successful compile output
|
|
129
|
+
- `activePackBoundary`: `active` is the only serve-visible slot; `candidate` and `previous` stay inspectable until promotion or rollback changes pointers
|
|
130
|
+
- `promotionBoundary`: learner refresh lands in `candidate`, activation promotion flips pointers, and only later compiles can see the fresher pack
|
|
131
|
+
- `failOpenSemantics`: missing active packs fail open, but learned-required route-artifact drift hard-fails instead of silently serving static context
|
|
132
|
+
- `runtimeResponsibilities`: OpenClaw remains responsible for runtime orchestration, prompt assembly, response delivery, and guarded serve-path decisions
|
|
133
|
+
|
|
134
|
+
Operator-facing CLI:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pnpm exec openclawbrain-ops status --activation-root /var/openclawbrain/activation --event-export /var/openclawbrain/exports/latest --teacher-snapshot /var/openclawbrain/runtime/teacher-snapshot.json
|
|
138
|
+
pnpm exec openclawbrain-ops doctor --activation-root /var/openclawbrain/activation --event-export /var/openclawbrain/exports/latest --teacher-snapshot /var/openclawbrain/runtime/teacher-snapshot.json
|
|
139
|
+
pnpm exec openclawbrain-ops rollback --activation-root /var/openclawbrain/activation --dry-run
|
|
41
140
|
```
|
|
42
141
|
|
|
43
|
-
|
|
142
|
+
- `status` prints a compressed one-screen summary of active/candidate pack truth, brain handoff state, serve-path fail-open status, route freshness, supervision flow, live-vs-backfill learning mode, the last async no-op reason, and rollback readiness
|
|
143
|
+
- `doctor` prints explicit `PASS` / `WARN` / `FAIL` findings and exits `1` only when a hard serve-path failure exists
|
|
144
|
+
- `rollback --dry-run` previews the exact `active <- previous` and `active -> candidate` move before you apply rollback for real
|
|
145
|
+
- `--event-export` accepts either a runtime event-export bundle root or a normalized-export JSON payload
|
|
146
|
+
- `--teacher-snapshot` accepts JSON from `teacherLoop.snapshot()` or `await teacherLoop.flush()` when you want the last duplicate/no-op reason plus learner bootstrapped/mode/next-lane backlog truth kept visible
|
|
147
|
+
|
|
148
|
+
Programmatic rollback is available too:
|
|
149
|
+
|
|
150
|
+
- `rollbackRuntimeAttach({ activationRoot, dryRun: true })` previews the move without changing activation pointers
|
|
151
|
+
- `rollbackRuntimeAttach({ activationRoot })` applies the rollback and reports which pack was restored to `active`
|
|
152
|
+
|
|
153
|
+
The learned-required serve path is stricter:
|
|
154
|
+
|
|
155
|
+
- `compileRuntimeContext()` now forwards the active-slot diagnostics from `@openclawbrain/compiler.compileRuntimeFromActivation()`
|
|
156
|
+
- learned-required active packs return `hardRequirementViolated=true` and `fallbackToStaticContext=false` when route artifacts drift or disappear
|
|
157
|
+
- `runRuntimeTurn()` throws instead of silently serving through those learned-required failures
|
|
158
|
+
- event-export write failures still do not erase successful compile output
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type OperatorSurfaceInput } from "./index.js";
|
|
3
|
+
interface ParsedOperatorCliArgs {
|
|
4
|
+
command: "status" | "doctor" | "rollback";
|
|
5
|
+
input: OperatorSurfaceInput;
|
|
6
|
+
json: boolean;
|
|
7
|
+
help: boolean;
|
|
8
|
+
dryRun: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseOperatorCliArgs(argv: readonly string[]): ParsedOperatorCliArgs;
|
|
11
|
+
export declare function runOperatorCli(argv?: readonly string[]): number;
|
|
12
|
+
export {};
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { buildOperatorSurfaceReport, formatOperatorDoctorReport, formatOperatorRollbackReport, formatOperatorStatusReport, rollbackRuntimeAttach } from "./index.js";
|
|
5
|
+
function operatorCliHelp() {
|
|
6
|
+
return [
|
|
7
|
+
"Usage:",
|
|
8
|
+
" openclawbrain-ops <status|doctor|rollback> --activation-root <path> [options]",
|
|
9
|
+
"",
|
|
10
|
+
"Options:",
|
|
11
|
+
" --activation-root <path> Activation root to inspect.",
|
|
12
|
+
" --event-export <path> Event-export bundle root or normalized export JSON payload.",
|
|
13
|
+
" --teacher-snapshot <path> Async teacher snapshot JSON from teacherLoop.snapshot()/flush().",
|
|
14
|
+
" --updated-at <iso> Observation time to use for freshness checks.",
|
|
15
|
+
" --dry-run Preview rollback pointer movement without writing activation state.",
|
|
16
|
+
" --json Emit machine-readable JSON instead of text.",
|
|
17
|
+
" --help Show this help.",
|
|
18
|
+
"",
|
|
19
|
+
"Common flow:",
|
|
20
|
+
" 1. status quick attach / first-value / rollback summary",
|
|
21
|
+
" 2. doctor explicit PASS / WARN / FAIL findings",
|
|
22
|
+
" 3. rollback --dry-run preview active <- previous, active -> candidate",
|
|
23
|
+
" 4. rollback apply the rollback when the preview says ready",
|
|
24
|
+
"",
|
|
25
|
+
"Exit codes:",
|
|
26
|
+
" status: 0 on successful inspection, 1 on input/read failure.",
|
|
27
|
+
" doctor: 0 when no FAIL findings are present, 1 otherwise.",
|
|
28
|
+
" rollback: 0 when ready/applied, 1 when blocked or on input/read failure."
|
|
29
|
+
].join("\n");
|
|
30
|
+
}
|
|
31
|
+
export function parseOperatorCliArgs(argv) {
|
|
32
|
+
let command = "status";
|
|
33
|
+
let activationRoot = null;
|
|
34
|
+
let eventExportPath = null;
|
|
35
|
+
let teacherSnapshotPath = null;
|
|
36
|
+
let updatedAt = null;
|
|
37
|
+
let json = false;
|
|
38
|
+
let help = false;
|
|
39
|
+
let dryRun = false;
|
|
40
|
+
const args = [...argv];
|
|
41
|
+
if (args[0] === "status" || args[0] === "doctor" || args[0] === "rollback") {
|
|
42
|
+
command = args.shift();
|
|
43
|
+
}
|
|
44
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
45
|
+
const arg = args[index];
|
|
46
|
+
if (arg === "--help" || arg === "-h") {
|
|
47
|
+
help = true;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (arg === "--json") {
|
|
51
|
+
json = true;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (arg === "--dry-run") {
|
|
55
|
+
dryRun = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const next = args[index + 1];
|
|
59
|
+
if (arg === "--activation-root") {
|
|
60
|
+
if (next === undefined) {
|
|
61
|
+
throw new Error("--activation-root requires a value");
|
|
62
|
+
}
|
|
63
|
+
activationRoot = next;
|
|
64
|
+
index += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--event-export") {
|
|
68
|
+
if (next === undefined) {
|
|
69
|
+
throw new Error("--event-export requires a value");
|
|
70
|
+
}
|
|
71
|
+
eventExportPath = next;
|
|
72
|
+
index += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (arg === "--teacher-snapshot") {
|
|
76
|
+
if (next === undefined) {
|
|
77
|
+
throw new Error("--teacher-snapshot requires a value");
|
|
78
|
+
}
|
|
79
|
+
teacherSnapshotPath = next;
|
|
80
|
+
index += 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (arg === "--updated-at") {
|
|
84
|
+
if (next === undefined) {
|
|
85
|
+
throw new Error("--updated-at requires a value");
|
|
86
|
+
}
|
|
87
|
+
updatedAt = next;
|
|
88
|
+
index += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`unknown argument: ${arg}`);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
command,
|
|
95
|
+
input: {
|
|
96
|
+
activationRoot: activationRoot ?? "",
|
|
97
|
+
eventExportPath,
|
|
98
|
+
teacherSnapshotPath,
|
|
99
|
+
updatedAt
|
|
100
|
+
},
|
|
101
|
+
json,
|
|
102
|
+
help,
|
|
103
|
+
dryRun
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function runOperatorCli(argv = process.argv.slice(2)) {
|
|
107
|
+
const parsed = parseOperatorCliArgs(argv);
|
|
108
|
+
if (parsed.help) {
|
|
109
|
+
console.log(operatorCliHelp());
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
const activationRoot = path.resolve(parsed.input.activationRoot);
|
|
113
|
+
if (parsed.command === "rollback") {
|
|
114
|
+
const result = rollbackRuntimeAttach({
|
|
115
|
+
activationRoot,
|
|
116
|
+
...(parsed.input.updatedAt === null ? {} : { updatedAt: parsed.input.updatedAt }),
|
|
117
|
+
dryRun: parsed.dryRun
|
|
118
|
+
});
|
|
119
|
+
if (parsed.json) {
|
|
120
|
+
console.log(JSON.stringify(result, null, 2));
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
console.log(formatOperatorRollbackReport(result));
|
|
124
|
+
}
|
|
125
|
+
return result.allowed ? 0 : 1;
|
|
126
|
+
}
|
|
127
|
+
const report = buildOperatorSurfaceReport({
|
|
128
|
+
...parsed.input,
|
|
129
|
+
activationRoot
|
|
130
|
+
});
|
|
131
|
+
if (parsed.json) {
|
|
132
|
+
console.log(JSON.stringify(report, null, 2));
|
|
133
|
+
}
|
|
134
|
+
else if (parsed.command === "doctor") {
|
|
135
|
+
console.log(formatOperatorDoctorReport(report));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
console.log(formatOperatorStatusReport(report));
|
|
139
|
+
}
|
|
140
|
+
return parsed.command === "doctor" && report.status === "fail" ? 1 : 0;
|
|
141
|
+
}
|
|
142
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
143
|
+
try {
|
|
144
|
+
process.exitCode = runOperatorCli();
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error("[openclawbrain-ops] failed");
|
|
148
|
+
console.error(error instanceof Error ? error.stack ?? error.message : String(error));
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AAUpB,SAAS,eAAe;IACtB,OAAO;QACL,QAAQ;QACR,iFAAiF;QACjF,EAAE;QACF,UAAU;QACV,2DAA2D;QAC3D,2FAA2F;QAC3F,gGAAgG;QAChG,6EAA6E;QAC7E,mGAAmG;QACnG,2EAA2E;QAC3E,+CAA+C;QAC/C,EAAE;QACF,cAAc;QACd,6DAA6D;QAC7D,oDAAoD;QACpD,2EAA2E;QAC3E,0EAA0E;QAC1E,EAAE;QACF,aAAa;QACb,gEAAgE;QAChE,6DAA6D;QAC7D,4EAA4E;KAC7E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAuB;IAC1D,IAAI,OAAO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