ronds_ai 0.13.1 → 0.14.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/bin/ronds_ai.js +658 -649
- package/lib/archive.js +88 -88
- package/lib/auto-bootstrap.js +544 -544
- package/lib/doctor.js +247 -247
- package/lib/migration.js +1640 -1640
- package/lib/org-config.js +464 -464
- package/lib/release.js +193 -193
- package/lib/route.js +86 -86
- package/package.json +20 -20
package/bin/ronds_ai.js
CHANGED
|
@@ -1,649 +1,658 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// ronds_ai 管理器 CLI。只读命令无副作用;写命令仅按显式参数操作,不联网除非命令本身需要。
|
|
5
|
-
// 命令集与协议见 docs/design/manager-component-handoff.md §5。
|
|
6
|
-
|
|
7
|
-
const MANAGER_VERSION = require('../package.json').version;
|
|
8
|
-
const paths = require('../lib/paths');
|
|
9
|
-
const consent = require('../lib/consent');
|
|
10
|
-
const release = require('../lib/release');
|
|
11
|
-
const store = require('../lib/component-store');
|
|
12
|
-
const route = require('../lib/route');
|
|
13
|
-
const mstore = require('../lib/manager-store');
|
|
14
|
-
const updateManager = require('../lib/update-manager');
|
|
15
|
-
const gateway = require('../lib/gateway');
|
|
16
|
-
const orgConfig = require('../lib/org-config');
|
|
17
|
-
|
|
18
|
-
const PROTOCOL_VERSION = store.PROTOCOL_VERSION; // 稳定入口协议常量(单一来源,与网关一致)
|
|
19
|
-
|
|
20
|
-
function writeHelp(stream) {
|
|
21
|
-
const lines = [
|
|
22
|
-
'ronds_ai manager',
|
|
23
|
-
'',
|
|
24
|
-
'用法:ronds_ai <command> [options]',
|
|
25
|
-
'',
|
|
26
|
-
'已实现:',
|
|
27
|
-
' help 显示本帮助(无参数时默认)',
|
|
28
|
-
' version 显示管理器与协议版本',
|
|
29
|
-
' status 以 JSON 输出配置、授权与组件安装状态',
|
|
30
|
-
' setup [--config <组织配置文件>]',
|
|
31
|
-
' 保存组织配置;缺省使用内置默认组织源(零填写,§7)',
|
|
32
|
-
' consent show 显示九项授权的当前状态',
|
|
33
|
-
' consent grant <字段1,字段2,...>',
|
|
34
|
-
' 显式授予权限(只接受已知字段,未知字段拒绝)',
|
|
35
|
-
' component install [--source <本地目录|URL>]',
|
|
36
|
-
' 从组织配置的发布源安装组件(验签→对账→隔离自检→原子激活)',
|
|
37
|
-
' component status 显示组件安装状态',
|
|
38
|
-
' update manager [--force]',
|
|
39
|
-
' 检查并安装管理器新版本(npm 链,独立限频退避,显式命令)',
|
|
40
|
-
' update component [--force]',
|
|
41
|
-
' 检查并安装组件新版本(签名清单链,禁止降级)',
|
|
42
|
-
' maintenance 一轮维护:两条更新链检查 + 业务维护(自动更新需对应授权,未授权部分跳过)',
|
|
43
|
-
' manager rollback --previous',
|
|
44
|
-
' 回退到最近可用管理器版本(原子交换指针,目录保留)',
|
|
45
|
-
' schedule install|status|disable|uninstall',
|
|
46
|
-
' 转发系统定时任务生命周期到组件(需 schedule 授权)',
|
|
47
|
-
' hooks install [--scope user|project] [--tool claude,cursor,codex,hermes] [--entry gateway|adapter]',
|
|
48
|
-
' 转发组件安装受管工具 Hook,指向 manager/dispatch.cjs 网关',
|
|
49
|
-
' (--entry adapter 指向 runtime/launch.cjs 迁移兼容入口;需 hookRepair 授权)',
|
|
50
|
-
' hooks repair [--scope user|project] [--tool ...]',
|
|
51
|
-
' 转发组件修复/补齐缺失的受管 Hook 条目,保留用户自定义命令(需 hookRepair 授权)',
|
|
52
|
-
' hooks uninstall [--scope user|project] [--tool ...]',
|
|
53
|
-
' 转发组件移除受管 Hook 条目与旧版遗留脚本(无需授权,停用后仍可执行)',
|
|
54
|
-
' disable 写入持久停用标记,阻断后续安装与自动维护',
|
|
55
|
-
' legacy inspect 只读盘点旧 .35 数据目录(不读正文、不上传、不改部署)',
|
|
56
|
-
' legacy plan 生成数据迁移计划(存量迁移规范 §5 源→目标映射)',
|
|
57
|
-
' legacy apply --confirm 执行数据迁移(事务式、幂等续跑,需显式确认)',
|
|
58
|
-
' legacy release --confirm 把 legacy-pending 隔离数据移回活动队列补发(授权复核+账本)',
|
|
59
|
-
' migration status 只读查看接管迁移事务状态、迁移门与可迁移性检查结果',
|
|
60
|
-
' migration apply --confirm 执行接管迁移事务(prepare→gate→quiesce→commit,幂等续跑)',
|
|
61
|
-
' doctor [--network] 只读诊断安装/配置/更新链/迁移状态(--network 才测远端连通)',
|
|
62
|
-
' uninstall [--confirm] 停用→任务→Hook→组件→入口的分步卸载,保留 config/state/data',
|
|
63
|
-
' (零接触引导:未配置组织的机器上业务/兼容命令首次触发时自动后台初始化,本次调用跳过)',
|
|
64
|
-
'',
|
|
65
|
-
'已实现(校验授权和协议后透传给本地组件,见 §5 兼容命令行):',
|
|
66
|
-
' record <tool> 转发代码编辑事件(需 codeMetrics)',
|
|
67
|
-
' analyze claude 转发 Prompt/Skill 事件(需 promptContent)',
|
|
68
|
-
' scan run|backfill|status [...]',
|
|
69
|
-
' 转发会话扫描(backfill 额外需 historyScan)',
|
|
70
|
-
' flush 转发数据队列发送(需任一数据权限)',
|
|
71
|
-
' maintenance run 转发业务维护(需任一数据权限)',
|
|
72
|
-
' skills install <name> [...]',
|
|
73
|
-
' 转发技能安装(无权限门控)',
|
|
74
|
-
'',
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'',
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
//
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
//
|
|
253
|
-
release.acceptVerifiedManifest
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (begin.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
//
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
//
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
if (!
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
report.organizationConfig =
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
if (!
|
|
409
|
-
const
|
|
410
|
-
if (!
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
//
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
if (command === '
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
process.
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
return
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
if (
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
process.stderr.write('用法:
|
|
546
|
-
return 2;
|
|
547
|
-
}
|
|
548
|
-
if (command === '
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
process.
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// ronds_ai 管理器 CLI。只读命令无副作用;写命令仅按显式参数操作,不联网除非命令本身需要。
|
|
5
|
+
// 命令集与协议见 docs/design/manager-component-handoff.md §5。
|
|
6
|
+
|
|
7
|
+
const MANAGER_VERSION = require('../package.json').version;
|
|
8
|
+
const paths = require('../lib/paths');
|
|
9
|
+
const consent = require('../lib/consent');
|
|
10
|
+
const release = require('../lib/release');
|
|
11
|
+
const store = require('../lib/component-store');
|
|
12
|
+
const route = require('../lib/route');
|
|
13
|
+
const mstore = require('../lib/manager-store');
|
|
14
|
+
const updateManager = require('../lib/update-manager');
|
|
15
|
+
const gateway = require('../lib/gateway');
|
|
16
|
+
const orgConfig = require('../lib/org-config');
|
|
17
|
+
|
|
18
|
+
const PROTOCOL_VERSION = store.PROTOCOL_VERSION; // 稳定入口协议常量(单一来源,与网关一致)
|
|
19
|
+
|
|
20
|
+
function writeHelp(stream) {
|
|
21
|
+
const lines = [
|
|
22
|
+
'ronds_ai manager',
|
|
23
|
+
'',
|
|
24
|
+
'用法:ronds_ai <command> [options]',
|
|
25
|
+
'',
|
|
26
|
+
'已实现:',
|
|
27
|
+
' help 显示本帮助(无参数时默认)',
|
|
28
|
+
' version 显示管理器与协议版本',
|
|
29
|
+
' status 以 JSON 输出配置、授权与组件安装状态',
|
|
30
|
+
' setup [--config <组织配置文件>]',
|
|
31
|
+
' 保存组织配置;缺省使用内置默认组织源(零填写,§7)',
|
|
32
|
+
' consent show 显示九项授权的当前状态',
|
|
33
|
+
' consent grant <字段1,字段2,...>',
|
|
34
|
+
' 显式授予权限(只接受已知字段,未知字段拒绝)',
|
|
35
|
+
' component install [--source <本地目录|URL>]',
|
|
36
|
+
' 从组织配置的发布源安装组件(验签→对账→隔离自检→原子激活)',
|
|
37
|
+
' component status 显示组件安装状态',
|
|
38
|
+
' update manager [--force]',
|
|
39
|
+
' 检查并安装管理器新版本(npm 链,独立限频退避,显式命令)',
|
|
40
|
+
' update component [--force]',
|
|
41
|
+
' 检查并安装组件新版本(签名清单链,禁止降级)',
|
|
42
|
+
' maintenance 一轮维护:两条更新链检查 + 业务维护(自动更新需对应授权,未授权部分跳过)',
|
|
43
|
+
' manager rollback --previous',
|
|
44
|
+
' 回退到最近可用管理器版本(原子交换指针,目录保留)',
|
|
45
|
+
' schedule install|status|disable|uninstall',
|
|
46
|
+
' 转发系统定时任务生命周期到组件(需 schedule 授权)',
|
|
47
|
+
' hooks install [--scope user|project] [--tool claude,cursor,codex,hermes] [--entry gateway|adapter]',
|
|
48
|
+
' 转发组件安装受管工具 Hook,指向 manager/dispatch.cjs 网关',
|
|
49
|
+
' (--entry adapter 指向 runtime/launch.cjs 迁移兼容入口;需 hookRepair 授权)',
|
|
50
|
+
' hooks repair [--scope user|project] [--tool ...]',
|
|
51
|
+
' 转发组件修复/补齐缺失的受管 Hook 条目,保留用户自定义命令(需 hookRepair 授权)',
|
|
52
|
+
' hooks uninstall [--scope user|project] [--tool ...]',
|
|
53
|
+
' 转发组件移除受管 Hook 条目与旧版遗留脚本(无需授权,停用后仍可执行)',
|
|
54
|
+
' disable 写入持久停用标记,阻断后续安装与自动维护',
|
|
55
|
+
' legacy inspect 只读盘点旧 .35 数据目录(不读正文、不上传、不改部署)',
|
|
56
|
+
' legacy plan 生成数据迁移计划(存量迁移规范 §5 源→目标映射)',
|
|
57
|
+
' legacy apply --confirm 执行数据迁移(事务式、幂等续跑,需显式确认)',
|
|
58
|
+
' legacy release --confirm 把 legacy-pending 隔离数据移回活动队列补发(授权复核+账本)',
|
|
59
|
+
' migration status 只读查看接管迁移事务状态、迁移门与可迁移性检查结果',
|
|
60
|
+
' migration apply --confirm 执行接管迁移事务(prepare→gate→quiesce→commit,幂等续跑)',
|
|
61
|
+
' doctor [--network] 只读诊断安装/配置/更新链/迁移状态(--network 才测远端连通)',
|
|
62
|
+
' uninstall [--confirm] 停用→任务→Hook→组件→入口的分步卸载,保留 config/state/data',
|
|
63
|
+
' (零接触引导:未配置组织的机器上业务/兼容命令首次触发时自动后台初始化,本次调用跳过)',
|
|
64
|
+
'',
|
|
65
|
+
'已实现(校验授权和协议后透传给本地组件,见 §5 兼容命令行):',
|
|
66
|
+
' record <tool> 转发代码编辑事件(需 codeMetrics)',
|
|
67
|
+
' analyze claude 转发 Prompt/Skill 事件(需 promptContent)',
|
|
68
|
+
' scan run|backfill|status [...]',
|
|
69
|
+
' 转发会话扫描(backfill 额外需 historyScan)',
|
|
70
|
+
' flush 转发数据队列发送(需任一数据权限)',
|
|
71
|
+
' maintenance run 转发业务维护(需任一数据权限)',
|
|
72
|
+
' skills install <name> [...]',
|
|
73
|
+
' 转发技能安装(无权限门控)',
|
|
74
|
+
' skills list | sync | update [--force] | inventory | remove <name>',
|
|
75
|
+
' 转发技能查询、平台/组织分发更新、资产采集与移除',
|
|
76
|
+
'',
|
|
77
|
+
'以下命令未实现,见 docs/design/manager-component-handoff.md §5:',
|
|
78
|
+
' component rollback / manager repair-entrypoints',
|
|
79
|
+
'',
|
|
80
|
+
];
|
|
81
|
+
stream.write(lines.join('\n'));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function writeVersion() {
|
|
85
|
+
process.stdout.write(`ronds_ai manager ${MANAGER_VERSION} (protocol ${PROTOCOL_VERSION})\n`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function writeStatus() {
|
|
89
|
+
const org = consent.loadOrganization();
|
|
90
|
+
const comp = store.componentStatus();
|
|
91
|
+
const c = consent.loadConsent();
|
|
92
|
+
const cur = mstore.currentManager();
|
|
93
|
+
process.stdout.write(JSON.stringify({
|
|
94
|
+
managerVersion: MANAGER_VERSION,
|
|
95
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
96
|
+
configured: !!org,
|
|
97
|
+
organizationId: org ? org.organizationId : null,
|
|
98
|
+
sourceType: org ? org.source.type : null,
|
|
99
|
+
componentInstalled: comp.installed,
|
|
100
|
+
componentVersion: comp.version,
|
|
101
|
+
bootstrapInstalled: require('fs').existsSync(require('path').join(paths.managerDir(), 'launch.cjs')),
|
|
102
|
+
managerStatus: cur ? cur.status : null, // §9.1:pending-start 待 READY 确认;confirmed 已确认;旧版 active 视为已确认
|
|
103
|
+
quarantinedCount: mstore.listQuarantined().length,
|
|
104
|
+
disabled: consent.isDisabled(),
|
|
105
|
+
consentRevision: c.consentRevision,
|
|
106
|
+
unknownConsentFields: c.unknownFields,
|
|
107
|
+
}, null, 2) + '\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function runSetup(args) {
|
|
111
|
+
const value = argValue(args, '--config');
|
|
112
|
+
let input;
|
|
113
|
+
let fromDefault = false;
|
|
114
|
+
if (!value) {
|
|
115
|
+
// §7 零填写:无 --config 时使用内置默认组织源(可被显式配置覆盖)
|
|
116
|
+
input = require('../lib/default-org').DEFAULT_ORGANIZATION;
|
|
117
|
+
fromDefault = true;
|
|
118
|
+
} else {
|
|
119
|
+
try { input = JSON.parse(require('fs').readFileSync(value, 'utf8')); }
|
|
120
|
+
catch (e) { process.stderr.write(`读取配置失败:${e.message}\n`); return 2; }
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
// F11:记录组件源来源——内置默认(零填写,可被新版 npm 默认入口恢复/迁移)或
|
|
124
|
+
// 显式 setup --config(不被包内默认覆盖)
|
|
125
|
+
const org = consent.saveOrganization(input, { sourceProvenance: fromDefault ? 'builtin' : 'explicit' });
|
|
126
|
+
// R13:保存基础组织后尝试拉取公司签名配置;失败不阻塞 setup(使用基础源)
|
|
127
|
+
const orgConfigReport = await trySetupOrganizationConfig(org);
|
|
128
|
+
process.stdout.write(JSON.stringify({
|
|
129
|
+
saved: true,
|
|
130
|
+
fromDefault,
|
|
131
|
+
organizationId: org.organizationId,
|
|
132
|
+
componentId: org.componentId,
|
|
133
|
+
source: org.source,
|
|
134
|
+
...(org.configUrl ? { configUrl: org.configUrl } : {}),
|
|
135
|
+
...(orgConfigReport ? { organizationConfig: orgConfigReport } : {}),
|
|
136
|
+
}, null, 2) + '\n');
|
|
137
|
+
return 0;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
process.stderr.write(`组织配置无效:${e.message}\n`);
|
|
140
|
+
return 2;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// R13:setup 保存基础组织后尝试拉取公司签名配置;失败不阻塞(使用基础源)。
|
|
145
|
+
async function trySetupOrganizationConfig(org) {
|
|
146
|
+
if (!org.configUrl) return null;
|
|
147
|
+
try {
|
|
148
|
+
const report = await orgConfig.refreshOrganizationConfig({ organization: org });
|
|
149
|
+
return report.ok ? report : { ...report, hint: '公司配置不可达,使用基础源' };
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return { ok: false, checked: true, error: e.message, hint: '公司配置不可达,使用基础源' };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function runConsent(args) {
|
|
156
|
+
const sub = args[0];
|
|
157
|
+
if (sub === 'show') {
|
|
158
|
+
const c = consent.loadConsent();
|
|
159
|
+
process.stdout.write(JSON.stringify(c, null, 2) + '\n');
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
if (sub === 'grant') {
|
|
163
|
+
if (args.length < 2 || !args[1].trim()) { process.stderr.write('consent grant 需要 <字段1,字段2,...>\n'); return 2; }
|
|
164
|
+
try {
|
|
165
|
+
const next = consent.grantConsent(args[1].split(',').map((s) => s.trim()).filter(Boolean));
|
|
166
|
+
process.stdout.write(JSON.stringify({ granted: true, consentRevision: next.consentRevision, grants: next.grants }, null, 2) + '\n');
|
|
167
|
+
return 0;
|
|
168
|
+
} catch (e) { process.stderr.write(`${e.message}\n`); return 2; }
|
|
169
|
+
}
|
|
170
|
+
process.stderr.write('用法:consent show | consent grant <字段,...>\n');
|
|
171
|
+
return 2;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function resolveSource(override, org) {
|
|
175
|
+
if (override) {
|
|
176
|
+
if (/^https?:\/\//.test(override)) return { type: 'http', url: override };
|
|
177
|
+
if (require('fs').existsSync(require('path').resolve(override))) return { type: 'local', dir: require('path').resolve(override) };
|
|
178
|
+
throw new Error(`--source 既不是可访问 URL 也不是存在的目录:${override}`);
|
|
179
|
+
}
|
|
180
|
+
return org.source;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function runComponentInstall(args) {
|
|
184
|
+
const override = argValue(args, '--source');
|
|
185
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。安装被阻断。\n'); return 1; }
|
|
186
|
+
const org = consent.loadOrganization();
|
|
187
|
+
if (!org) { process.stderr.write('未配置组织。先运行 setup --config <组织配置文件>。\n'); return 1; }
|
|
188
|
+
let source;
|
|
189
|
+
try { source = resolveSource(override, org); }
|
|
190
|
+
catch (e) { process.stderr.write(`${e.message}\n`); return 2; }
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
const envelope = source.type === 'local' ? release.readEnvelopeLocal(source.dir) : await release.fetchEnvelopeHttp(source.url);
|
|
194
|
+
const result = await installVerifiedComponent(org, source, envelope);
|
|
195
|
+
if (result.kind === 'upToDate') {
|
|
196
|
+
process.stdout.write(JSON.stringify({ upToDate: true, version: result.payload.version, sequence: result.payload.sequence }, null, 2) + '\n');
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
gateway.ensureDispatchEntry(); // 受管 Hook 指向的单进程网关稳定入口(§5.1/§10);ensureBootstrap 已在锁内完成
|
|
200
|
+
process.stdout.write(JSON.stringify({ installed: true, version: result.payload.version, versionId: result.installed.versionId, sequence: result.payload.sequence }, null, 2) + '\n');
|
|
201
|
+
return 0;
|
|
202
|
+
} catch (e) {
|
|
203
|
+
process.stderr.write(`组件安装失败:${e.message}\n`);
|
|
204
|
+
return 1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---- 组件更新链(§9):限频退避 + 禁止降级 + 链路记账 ----
|
|
209
|
+
// state/component-update.json 同时承载水位字段(release.saveAcceptedWatermark/
|
|
210
|
+
// saveInstalledWatermark 合并写)与链路字段(recordChain 合并写)。链路时间字段
|
|
211
|
+
// 一律 epoch 毫秒数字(R04),读取兼容旧 ISO 字符串(parseChainTimeMs)。
|
|
212
|
+
|
|
213
|
+
function recordChain(result, error) {
|
|
214
|
+
const file = paths.componentUpdateJson();
|
|
215
|
+
if (require('fs').existsSync(file) && !release.loadWatermark(file)) {
|
|
216
|
+
return; // §8.1:状态文件损坏 → 挂起链路记账,保留现场待人工处理(错误经报告返回)
|
|
217
|
+
}
|
|
218
|
+
const existing = release.loadWatermark(file) || {};
|
|
219
|
+
const failureCount = error ? (existing.failureCount || 0) + 1 : 0;
|
|
220
|
+
const now = Date.now();
|
|
221
|
+
consent.atomicWrite(file, {
|
|
222
|
+
...existing,
|
|
223
|
+
checkedAt: now,
|
|
224
|
+
nextCheckAt: now + updateManager.backoffMs(failureCount),
|
|
225
|
+
failureCount,
|
|
226
|
+
lastError: error || null,
|
|
227
|
+
lastResult: result,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* 验签后的组件安装核心(component install / update component / maintenance 共用,R03/R05):
|
|
233
|
+
* 验签+结构校验(N04:身份/结构/时效通过即"合法清单")→ 锁①内 acceptVerifiedManifest
|
|
234
|
+
* 原子记 accepted 水位(先于下载与任何本机兼容判定——高序合法清单被观察即抬升水位,
|
|
235
|
+
* 高序下载失败/不兼容后低序回放被拒;同序同摘要=幂等重试继续下载)→ 锁①内本机兼容
|
|
236
|
+
* 预检(F05/N04:nodeRange/managerRange/protocol/schema 不兼容 → 保留原组合不安装,
|
|
237
|
+
* 但水位已推进,升级本机后同序同摘要可续试)→ 下载/校验归档 → 锁②按"最新 accepted
|
|
238
|
+
* 水位 + 本清单确切摘要"重验防回放(F04:下载期间更高序清单可能已被接受——低序拒绝、
|
|
239
|
+
* 同序异摘要拒绝、同序同摘要放行)并复核版本规则(拒绝降级/同版本异内容)→
|
|
240
|
+
* 安装激活(installComponent 内再次本机兼容把关)→ 写 installed 字段。
|
|
241
|
+
* 维护锁为同步回调,分两段临界区,下载在两段之间进行(不持锁联网)。
|
|
242
|
+
* @returns {{kind:'installed', payload:object, installed:object}|{kind:'upToDate', payload:object, current:object|null}}
|
|
243
|
+
* @throws 低序/同序异摘要/水位损坏挂起/锁占用/版本规则拒绝/本机不兼容/归档不符
|
|
244
|
+
*/
|
|
245
|
+
async function installVerifiedComponent(org, source, envelope) {
|
|
246
|
+
const stateFile = paths.componentUpdateJson();
|
|
247
|
+
const { payloadBytes, payload } = release.verifyEnvelope(envelope, org.publicKeyPem);
|
|
248
|
+
release.validatePayload(payload, org);
|
|
249
|
+
|
|
250
|
+
const begin = mstore.withMaintenanceLock(() => {
|
|
251
|
+
const cur = store.loadCurrent();
|
|
252
|
+
// N04:合法清单锁内先记 accepted 水位(防回放判定+原子写),本机兼容判定随后——
|
|
253
|
+
// 不兼容只保留原组合,水位不回退。顺序规则见 release.acceptVerifiedManifest 注释
|
|
254
|
+
// (auto-bootstrap installComponentCore 与本函数共用同一助手,语义不分叉)。
|
|
255
|
+
release.acceptVerifiedManifest(stateFile, payload, envelope, payloadBytes, { installed: !!cur });
|
|
256
|
+
store.checkLocalCompatibility(payload); // F05:本机兼容预检(协议/范围/schema;激活前 installComponent 内再把关)
|
|
257
|
+
return { cur, plan: updateManager.decideVersionAction(cur, payload) };
|
|
258
|
+
});
|
|
259
|
+
if (!begin.ok) throw new Error(`维护锁被占用(${begin.reason}),稍后重试`);
|
|
260
|
+
if (begin.result.plan.action === 'reject') throw new Error(begin.result.plan.reason);
|
|
261
|
+
if (begin.result.plan.action === 'skip') {
|
|
262
|
+
return { kind: 'upToDate', payload, current: begin.result.cur };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const tgz = source.type === 'local'
|
|
266
|
+
? release.readArchiveLocal(source.dir, payload.archive.url)
|
|
267
|
+
: await release.fetchArchiveHttp(payload.archive.url);
|
|
268
|
+
if (tgz.length !== payload.archive.size) throw new Error(`归档大小不符:${tgz.length} != ${payload.archive.size}`);
|
|
269
|
+
if (release.sha512Base64(tgz) !== payload.archive.sha512) throw new Error('归档 sha512 不符');
|
|
270
|
+
|
|
271
|
+
const done = mstore.withMaintenanceLock(() => {
|
|
272
|
+
const cur = store.loadCurrent(); // 复核:下载期间 current 可能已变
|
|
273
|
+
// F04 锁②水位重验:下载期间更高序清单可能已被接受(其下载失败或仍在进行),按
|
|
274
|
+
// 最新 accepted 水位 + 本清单确切摘要重跑防回放判定(与锁①共用 release.checkWatermark)。
|
|
275
|
+
// seq9 下载完成时 seq10 已被接受 → 此处低序拒绝,不得安装旧候选。
|
|
276
|
+
release.checkWatermark(release.loadWatermark(stateFile), payload, payloadBytes, { installed: !!cur });
|
|
277
|
+
const plan = updateManager.decideVersionAction(cur, payload);
|
|
278
|
+
if (plan.action === 'reject') throw new Error(plan.reason);
|
|
279
|
+
if (plan.action === 'skip') return { kind: 'upToDate', payload, current: cur };
|
|
280
|
+
const installed = store.installComponent(tgz, payload); // F05:内含激活前本机兼容把关
|
|
281
|
+
release.saveInstalledWatermark(stateFile, payload, installed);
|
|
282
|
+
mstore.ensureBootstrap();
|
|
283
|
+
return { kind: 'installed', payload, installed };
|
|
284
|
+
});
|
|
285
|
+
if (!done.ok) throw new Error(`维护锁被占用(${done.reason}),稍后重试`);
|
|
286
|
+
return done.result;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// F11:组件清单源 Git 单入口恢复——现网入口不可达时尝试当前管理器发行版内置的默认
|
|
290
|
+
// 组织入口(同组织、非显式配置;显式 setup --config 不被包内默认覆盖)。仅当恢复入口
|
|
291
|
+
// 通过验签+水位并完成安装链后才持久化切换(见 componentUpdateCore),失败保留旧配置。
|
|
292
|
+
async function fetchEnvelopeForUpdate(org) {
|
|
293
|
+
try {
|
|
294
|
+
const envelope = org.source.type === 'local'
|
|
295
|
+
? release.readEnvelopeLocal(org.source.dir)
|
|
296
|
+
: await release.fetchEnvelopeHttp(org.source.url);
|
|
297
|
+
return { envelope, source: org.source, recovered: false };
|
|
298
|
+
} catch (primaryError) {
|
|
299
|
+
const def = orgConfig.defaultRecoveryEntry(org);
|
|
300
|
+
const url = def && def.source && def.source.type === 'http' && typeof def.source.url === 'string'
|
|
301
|
+
&& (org.source.type !== 'http' || org.source.url !== def.source.url) ? def.source.url : null;
|
|
302
|
+
if (!url) throw primaryError;
|
|
303
|
+
let envelope;
|
|
304
|
+
try {
|
|
305
|
+
envelope = await release.fetchEnvelopeHttp(url);
|
|
306
|
+
} catch (recoveryError) {
|
|
307
|
+
throw new Error(`组件源不可达(${primaryError.message});内置默认恢复入口也不可达(${recoveryError.message})`);
|
|
308
|
+
}
|
|
309
|
+
return { envelope, source: { type: 'http', url }, recovered: true };
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function componentUpdateCore(force) {
|
|
314
|
+
const org = consent.loadOrganization();
|
|
315
|
+
if (!org) return { report: { error: '未配置组织' }, exitCode: 1 };
|
|
316
|
+
const state = release.loadWatermark(paths.componentUpdateJson()) || {};
|
|
317
|
+
if (!force) {
|
|
318
|
+
let due;
|
|
319
|
+
try { due = updateManager.shouldCheck(state, { force }); }
|
|
320
|
+
catch (e) { return { report: { error: e.message }, exitCode: 1 }; }
|
|
321
|
+
if (!due) {
|
|
322
|
+
// shouldCheck 已通过,必然可解析;统一输出 epoch 数字(R04)
|
|
323
|
+
return { report: { checked: false, nextCheckAt: updateManager.parseChainTimeMs(state.nextCheckAt, 'nextCheckAt'), reason: 'backoff(限频退避中,可 --force)' }, exitCode: 0 };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
const fetched = await fetchEnvelopeForUpdate(org);
|
|
328
|
+
const result = await installVerifiedComponent(org, fetched.source, fetched.envelope);
|
|
329
|
+
let recoveryNote = null;
|
|
330
|
+
if (fetched.recovered) {
|
|
331
|
+
// F11:恢复入口已通过验签+水位且安装链成功 → 持久化切换(失败路径已抛错到不了这);
|
|
332
|
+
// 切换失败不回滚安装,下轮仍经恢复入口自愈
|
|
333
|
+
try { orgConfig.persistRecoveredSource(fetched.source); } catch (e) { recoveryNote = `源切换未持久化:${e.message}`; }
|
|
334
|
+
}
|
|
335
|
+
if (result.kind === 'upToDate') {
|
|
336
|
+
recordChain('up-to-date', null);
|
|
337
|
+
return { report: { checked: true, upToDate: true, installed: result.current ? result.current.version : null, latest: result.payload.version, ...(recoveryNote ? { recoveryNote } : {}), ...(fetched.recovered ? { sourceRecovered: true } : {}) }, exitCode: 0 };
|
|
338
|
+
}
|
|
339
|
+
recordChain('installed', null);
|
|
340
|
+
return { report: { checked: true, installed: true, version: result.payload.version, versionId: result.installed.versionId, sequence: result.payload.sequence, ...(recoveryNote ? { recoveryNote } : {}), ...(fetched.recovered ? { sourceRecovered: true } : {}) }, exitCode: 0 };
|
|
341
|
+
} catch (e) {
|
|
342
|
+
recordChain('error', e.message);
|
|
343
|
+
return { report: { checked: true, error: e.message }, exitCode: 1 };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function runComponentUpdate(args) {
|
|
348
|
+
const rest = args.filter((a) => a !== '--force');
|
|
349
|
+
if (rest.length) { process.stderr.write('用法:update component [--force]\n'); return 2; }
|
|
350
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。更新被阻断。\n'); return 1; }
|
|
351
|
+
const { report, exitCode } = await componentUpdateCore(args.includes('--force'));
|
|
352
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
353
|
+
return exitCode;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async function runManagerUpdateCmd(args) {
|
|
357
|
+
const rest = args.filter((a) => a !== '--force');
|
|
358
|
+
if (rest.length) { process.stderr.write('用法:update manager [--force]\n'); return 2; }
|
|
359
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。更新被阻断。\n'); return 1; }
|
|
360
|
+
const report = await updateManager.runManagerUpdate({ force: args.includes('--force') });
|
|
361
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
362
|
+
return report.error ? 1 : 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 一轮维护(§9 简化版):两条更新链 + 业务维护;自动更新按授权跳过,业务转发按数据权限跳过。
|
|
366
|
+
async function runMaintenanceCycle(args) {
|
|
367
|
+
if (args.length) { process.stderr.write('命令 maintenance 不接受额外参数\n'); return 2; }
|
|
368
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。维护被阻断。\n'); return 1; }
|
|
369
|
+
if (!consent.loadOrganization()) { process.stderr.write('未配置组织。先运行 setup --config <组织配置文件>。\n'); return 1; }
|
|
370
|
+
const grants = consent.loadConsent().grants;
|
|
371
|
+
const report = { managerUpdate: null, organizationConfig: null, componentUpdate: null, businessRun: null };
|
|
372
|
+
report.managerUpdate = grants.managerAutoUpdate
|
|
373
|
+
? await updateManager.runManagerUpdate({ force: false })
|
|
374
|
+
: { skipped: 'managerAutoUpdate 未授权' };
|
|
375
|
+
// R13:组件检查前刷新公司签名配置(每轮一次尝试;失败计数入 state/org-config.json,
|
|
376
|
+
// 不阻塞本轮——基础源继续可用,退避由 maintenance 周期自然限频)
|
|
377
|
+
try {
|
|
378
|
+
report.organizationConfig = await orgConfig.refreshOrganizationConfig();
|
|
379
|
+
} catch (e) {
|
|
380
|
+
report.organizationConfig = { ok: false, checked: true, error: e.message };
|
|
381
|
+
}
|
|
382
|
+
report.componentUpdate = grants.componentAutoUpdate
|
|
383
|
+
? (await componentUpdateCore(false)).report
|
|
384
|
+
: { skipped: 'componentAutoUpdate 未授权' };
|
|
385
|
+
const entry = route.resolveComponentEntry();
|
|
386
|
+
if (!entry) report.businessRun = { skipped: '组件未安装' };
|
|
387
|
+
else {
|
|
388
|
+
const check = route.checkGrants('maintenance', ['run'], grants);
|
|
389
|
+
report.businessRun = check.ok
|
|
390
|
+
? { exitCode: route.forward(entry, ['maintenance', 'run']) }
|
|
391
|
+
: { skipped: check.error };
|
|
392
|
+
}
|
|
393
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
394
|
+
return 0;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function argValue(args, flag) {
|
|
398
|
+
const i = args.indexOf(flag);
|
|
399
|
+
return i !== -1 && i + 1 < args.length ? args[i + 1] : null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function hasFlag(args, flag) { return args.includes(flag); }
|
|
403
|
+
|
|
404
|
+
// 固定转发路由(§5):停用/未配置/未安装/未授权在管理器侧拦截并明确报错,
|
|
405
|
+
// 通过后透传给本地组件;转发前不重复拉 capabilities(安装时已隔离自检)。
|
|
406
|
+
function runForwarded(action, args) {
|
|
407
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。命令被阻断。\n'); return 1; }
|
|
408
|
+
if (!consent.loadOrganization()) { process.stderr.write('未配置组织。先运行 setup --config <组织配置文件>。\n'); return 1; }
|
|
409
|
+
const entry = route.resolveComponentEntry();
|
|
410
|
+
if (!entry) { process.stderr.write('组件未安装或入口无效。先运行 component install。\n'); return 1; }
|
|
411
|
+
const check = route.checkGrants(action, args, consent.loadConsent().grants);
|
|
412
|
+
if (!check.ok) { process.stderr.write(`${check.error}\n`); return 1; }
|
|
413
|
+
return route.forward(entry, [action, ...args]);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ---- 受管 Hook 生命周期(§10,迁自本文件):改写逻辑在组件内执行,管理器仅转发 ----
|
|
417
|
+
// install/repair 经 runForwarded(停用/组织/安装/授权检查后透传,组件侧再复核
|
|
418
|
+
// hookRepair);uninstall 清理自身免授权,且停用后仍须可执行——直接 spawn 组件
|
|
419
|
+
// 入口,绕过 runForwarded 的停用拦截(对齐组件语义,机制同 uninstall.js 步骤 2)。
|
|
420
|
+
|
|
421
|
+
function runHooksCommand(rest) {
|
|
422
|
+
const sub = rest[0];
|
|
423
|
+
if (!['install', 'repair', 'uninstall'].includes(sub)) {
|
|
424
|
+
process.stderr.write('用法:hooks install|repair|uninstall [--scope user|project] [--tool claude,cursor,codex,hermes]\n');
|
|
425
|
+
return 2;
|
|
426
|
+
}
|
|
427
|
+
if (sub === 'uninstall') {
|
|
428
|
+
const entry = route.resolveComponentEntry();
|
|
429
|
+
if (!entry) { process.stderr.write('组件未安装或入口无效。先运行 component install。\n'); return 1; }
|
|
430
|
+
return route.forward(entry, ['hooks', ...rest]);
|
|
431
|
+
}
|
|
432
|
+
return runForwarded('hooks', rest);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async function run(argv) {
|
|
436
|
+
const command = argv[2];
|
|
437
|
+
const rest = argv.slice(3);
|
|
438
|
+
// 零接触自动引导(lib/auto-bootstrap):业务/兼容命令在组织未配置(或组件未装、
|
|
439
|
+
// 引导进行中)时后台派生一次完整初始化(setup→组件→数据迁移→接管迁移),本次调用
|
|
440
|
+
// 按宿主协议 fail-open 跳过;__bootstrap 为后台子进程内部入口(不进 help);
|
|
441
|
+
// 管理命令与 §9.1 READY 探测不受门控。
|
|
442
|
+
if (command === '__bootstrap') return require('../lib/auto-bootstrap').runChildProcess();
|
|
443
|
+
const bootstrapGate = require('../lib/auto-bootstrap').gateForCommand(command);
|
|
444
|
+
if (bootstrapGate) {
|
|
445
|
+
if (bootstrapGate.start) require('../lib/auto-bootstrap').startBackgroundBootstrap();
|
|
446
|
+
process.stderr.write(`[ronds_ai] 初始化中(${bootstrapGate.reason}),本次调用跳过\n`);
|
|
447
|
+
return 0;
|
|
448
|
+
}
|
|
449
|
+
if (command === undefined || command === 'help') {
|
|
450
|
+
if (rest.length) { process.stderr.write('命令 help 不接受额外参数\n'); return 2; }
|
|
451
|
+
writeHelp(process.stderr);
|
|
452
|
+
return 0;
|
|
453
|
+
}
|
|
454
|
+
if (command === 'version') {
|
|
455
|
+
if (rest.length) { process.stderr.write('命令 version 不接受额外参数\n'); return 2; }
|
|
456
|
+
writeVersion();
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
459
|
+
if (command === 'status') {
|
|
460
|
+
if (rest.length) { process.stderr.write('命令 status 不接受额外参数\n'); return 2; }
|
|
461
|
+
writeStatus();
|
|
462
|
+
return 0;
|
|
463
|
+
}
|
|
464
|
+
if (command === 'setup') return runSetup(rest); // async,run 统一 await
|
|
465
|
+
if (command === 'consent') return runConsent(rest);
|
|
466
|
+
if (command === 'disable') {
|
|
467
|
+
if (rest.length) { process.stderr.write('命令 disable 不接受额外参数\n'); return 2; }
|
|
468
|
+
consent.setDisabled('user-disable');
|
|
469
|
+
process.stdout.write(JSON.stringify({ disabled: true }, null, 2) + '\n');
|
|
470
|
+
return 0;
|
|
471
|
+
}
|
|
472
|
+
if (command === 'component') {
|
|
473
|
+
const sub = rest[0];
|
|
474
|
+
if (sub === 'install') return runComponentInstall(rest.slice(1));
|
|
475
|
+
if (sub === 'status') {
|
|
476
|
+
if (rest.length > 1) { process.stderr.write('命令 component status 不接受额外参数\n'); return 2; }
|
|
477
|
+
process.stdout.write(JSON.stringify(store.componentStatus(), null, 2) + '\n');
|
|
478
|
+
return 0;
|
|
479
|
+
}
|
|
480
|
+
process.stderr.write('用法:component install [--source <dir|url>] | component status\n');
|
|
481
|
+
return 2;
|
|
482
|
+
}
|
|
483
|
+
if (command === 'record') {
|
|
484
|
+
if (rest.length !== 1 || !rest[0]) { process.stderr.write('用法:record <tool>\n'); return 2; }
|
|
485
|
+
return runForwarded('record', rest);
|
|
486
|
+
}
|
|
487
|
+
if (command === 'analyze') {
|
|
488
|
+
if (rest.length !== 1 || rest[0] !== 'claude') { process.stderr.write('用法:analyze claude\n'); return 2; }
|
|
489
|
+
return runForwarded('analyze', rest);
|
|
490
|
+
}
|
|
491
|
+
if (command === 'scan') {
|
|
492
|
+
if (!['run', 'backfill', 'status'].includes(rest[0])) {
|
|
493
|
+
process.stderr.write('用法:scan run|backfill|status [--tool ...] [--since <date>] ...\n');
|
|
494
|
+
return 2;
|
|
495
|
+
}
|
|
496
|
+
return runForwarded('scan', rest);
|
|
497
|
+
}
|
|
498
|
+
if (command === 'flush') {
|
|
499
|
+
if (rest.length) { process.stderr.write('命令 flush 不接受额外参数\n'); return 2; }
|
|
500
|
+
return runForwarded('flush', rest);
|
|
501
|
+
}
|
|
502
|
+
if (command === 'skills') {
|
|
503
|
+
const sub = rest[0];
|
|
504
|
+
const valid = (sub === 'install' && rest.length >= 2)
|
|
505
|
+
|| (sub === 'remove' && rest.length === 2)
|
|
506
|
+
|| (['list', 'sync', 'update', 'inventory'].includes(sub));
|
|
507
|
+
if (!valid) {
|
|
508
|
+
process.stderr.write('用法:skills install <name> [...] | list | sync | update [--force|--hook] | inventory | remove <name>\n');
|
|
509
|
+
return 2;
|
|
510
|
+
}
|
|
511
|
+
return runForwarded('skills', rest);
|
|
512
|
+
}
|
|
513
|
+
if (command === 'schedule') {
|
|
514
|
+
if (!['install', 'status', 'disable', 'uninstall'].includes(rest[0]) || rest.length !== 1) {
|
|
515
|
+
process.stderr.write('用法:schedule install|status|disable|uninstall\n');
|
|
516
|
+
return 2;
|
|
517
|
+
}
|
|
518
|
+
return runForwarded('schedule', rest);
|
|
519
|
+
}
|
|
520
|
+
if (command === 'hooks') return runHooksCommand(rest);
|
|
521
|
+
if (command === 'update') {
|
|
522
|
+
if (rest[0] === 'manager') return runManagerUpdateCmd(rest.slice(1));
|
|
523
|
+
if (rest[0] === 'component') return runComponentUpdate(rest.slice(1));
|
|
524
|
+
process.stderr.write('用法:update manager [--force] | update component [--force]\n');
|
|
525
|
+
return 2;
|
|
526
|
+
}
|
|
527
|
+
if (command === 'maintenance') {
|
|
528
|
+
// §9.1 READY 回执契约:稳定引导器监督启动时经 env 传 RONDS_AI_READY_NONCE(本次随机
|
|
529
|
+
// nonce)与 RONDS_AI_CANDIDATE_VERSION(候选 versionId = 版本+内容摘要);本命令在任何
|
|
530
|
+
// 更新/业务动作之前把 {nonce, versionId, at} 原子写到 state/manager-ready.json。
|
|
531
|
+
// --ready-check 仅回执即退出(引导器探测新管理器可启动,不执行业务动作)。
|
|
532
|
+
let effective = rest;
|
|
533
|
+
if (process.env.RONDS_AI_READY_NONCE) {
|
|
534
|
+
require('fs').mkdirSync(paths.stateDir(), { recursive: true });
|
|
535
|
+
consent.atomicWrite(require('path').join(paths.stateDir(), 'manager-ready.json'), {
|
|
536
|
+
nonce: process.env.RONDS_AI_READY_NONCE,
|
|
537
|
+
versionId: process.env.RONDS_AI_CANDIDATE_VERSION || null,
|
|
538
|
+
at: new Date().toISOString(),
|
|
539
|
+
});
|
|
540
|
+
if (rest.includes('--ready-check')) return 0;
|
|
541
|
+
effective = rest.filter((a) => a !== '--ready-check'); // 带 nonce 的正常 maintenance:回执后继续本轮
|
|
542
|
+
}
|
|
543
|
+
if (effective.length === 1 && effective[0] === 'run') return runForwarded('maintenance', effective);
|
|
544
|
+
if (effective.length === 0) return runMaintenanceCycle(effective);
|
|
545
|
+
process.stderr.write('用法:maintenance(一轮维护)| maintenance run(业务维护转发)\n');
|
|
546
|
+
return 2;
|
|
547
|
+
}
|
|
548
|
+
if (command === 'manager') {
|
|
549
|
+
if (rest[0] === 'rollback' && rest[1] === '--previous' && rest.length === 2) {
|
|
550
|
+
const result = mstore.rollbackPrevious();
|
|
551
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
552
|
+
return result.ok ? 0 : 1;
|
|
553
|
+
}
|
|
554
|
+
process.stderr.write('用法:manager rollback --previous\n');
|
|
555
|
+
return 2;
|
|
556
|
+
}
|
|
557
|
+
if (command === 'legacy') {
|
|
558
|
+
const legacy = require('../lib/legacy');
|
|
559
|
+
const sub = rest[0];
|
|
560
|
+
if (sub === 'inspect') {
|
|
561
|
+
if (rest.length !== 1) { process.stderr.write('命令 legacy inspect 不接受额外参数\n'); return 2; }
|
|
562
|
+
process.stdout.write(JSON.stringify(legacy.inspectLegacy(), null, 2) + '\n');
|
|
563
|
+
return 0;
|
|
564
|
+
}
|
|
565
|
+
if (sub === 'plan') {
|
|
566
|
+
if (rest.length !== 1) { process.stderr.write('命令 legacy plan 不接受额外参数\n'); return 2; }
|
|
567
|
+
process.stdout.write(JSON.stringify(legacy.planDataMigration(), null, 2) + '\n');
|
|
568
|
+
return 0;
|
|
569
|
+
}
|
|
570
|
+
if (sub === 'apply') {
|
|
571
|
+
const flags = rest.slice(1);
|
|
572
|
+
if (flags.length > 1 || (flags.length === 1 && flags[0] !== '--confirm')) {
|
|
573
|
+
process.stderr.write('用法:legacy apply [--confirm]\n');
|
|
574
|
+
return 2;
|
|
575
|
+
}
|
|
576
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。迁移被阻断。\n'); return 1; }
|
|
577
|
+
if (!flags.includes('--confirm')) {
|
|
578
|
+
process.stderr.write('legacy apply 拒绝执行:需要 --confirm 显式确认(会移动本地业务数据文件)\n');
|
|
579
|
+
return 2;
|
|
580
|
+
}
|
|
581
|
+
try {
|
|
582
|
+
const report = legacy.runLegacyApply();
|
|
583
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
584
|
+
return report.status === 'interrupted' ? 1 : 0;
|
|
585
|
+
} catch (e) {
|
|
586
|
+
process.stderr.write(`迁移失败:${e.message}\n`);
|
|
587
|
+
return 1;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (sub === 'release') {
|
|
591
|
+
const flags = rest.slice(1);
|
|
592
|
+
if (flags.length > 1 || (flags.length === 1 && flags[0] !== '--confirm')) {
|
|
593
|
+
process.stderr.write('用法:legacy release [--confirm]\n');
|
|
594
|
+
return 2;
|
|
595
|
+
}
|
|
596
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。存量补发被阻断。\n'); return 1; }
|
|
597
|
+
if (!flags.includes('--confirm')) {
|
|
598
|
+
process.stderr.write('legacy release 拒绝执行:需要 --confirm 显式确认(会把隔离队列移回活动队列外发)\n');
|
|
599
|
+
return 2;
|
|
600
|
+
}
|
|
601
|
+
const report = legacy.runLegacyRelease({ confirm: true });
|
|
602
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
603
|
+
return report.status === 'partial' ? 1 : 0;
|
|
604
|
+
}
|
|
605
|
+
process.stderr.write('用法:legacy inspect | legacy plan | legacy apply --confirm | legacy release --confirm\n');
|
|
606
|
+
return 2;
|
|
607
|
+
}
|
|
608
|
+
if (command === 'migration') {
|
|
609
|
+
const migration = require('../lib/migration');
|
|
610
|
+
const sub = rest[0];
|
|
611
|
+
if (sub === 'status') {
|
|
612
|
+
if (rest.length !== 1) { process.stderr.write('命令 migration status 不接受额外参数\n'); return 2; }
|
|
613
|
+
process.stdout.write(JSON.stringify(migration.migrationStatus(), null, 2) + '\n');
|
|
614
|
+
return 0;
|
|
615
|
+
}
|
|
616
|
+
if (sub === 'apply') {
|
|
617
|
+
const flags = rest.slice(1);
|
|
618
|
+
if (flags.length > 1 || (flags.length === 1 && flags[0] !== '--confirm')) {
|
|
619
|
+
process.stderr.write('用法:migration apply [--confirm]\n');
|
|
620
|
+
return 2;
|
|
621
|
+
}
|
|
622
|
+
if (consent.isDisabled()) { process.stderr.write('已停用(disable)。迁移被阻断。\n'); return 1; }
|
|
623
|
+
if (!flags.includes('--confirm')) {
|
|
624
|
+
process.stderr.write('migration apply 拒绝执行:需要 --confirm 显式确认(接管迁移会改写旧入口与受管 Hook)\n');
|
|
625
|
+
return 2;
|
|
626
|
+
}
|
|
627
|
+
const report = migration.runMigrationApply({ confirm: true });
|
|
628
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
629
|
+
if (report.status === 'rejected') process.stderr.write(`${report.message}\n`);
|
|
630
|
+
return report.exitCode;
|
|
631
|
+
}
|
|
632
|
+
process.stderr.write('用法:migration status | migration apply --confirm\n');
|
|
633
|
+
return 2;
|
|
634
|
+
}
|
|
635
|
+
if (command === 'doctor') {
|
|
636
|
+
const rest2 = rest.filter((a) => a !== '--network');
|
|
637
|
+
if (rest2.length) { process.stderr.write('用法:doctor [--network]\n'); return 2; }
|
|
638
|
+
const { report, exitCode } = await require('../lib/doctor').runDoctor({ network: rest.includes('--network') });
|
|
639
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
640
|
+
return exitCode;
|
|
641
|
+
}
|
|
642
|
+
if (command === 'uninstall') {
|
|
643
|
+
const rest2 = rest.filter((a) => a !== '--confirm');
|
|
644
|
+
if (rest2.length) { process.stderr.write('用法:uninstall [--confirm]\n'); return 2; }
|
|
645
|
+
const result = require('../lib/uninstall').runUninstall({ confirm: rest.includes('--confirm') });
|
|
646
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
647
|
+
if (result.message && result.exitCode !== 0) process.stderr.write(`${result.message}\n`);
|
|
648
|
+
if (result.recovery && result.exitCode !== 0) process.stderr.write(`${result.recovery}\n`);
|
|
649
|
+
return result.exitCode;
|
|
650
|
+
}
|
|
651
|
+
process.stderr.write(`未知命令或组件未安装:${command}(见 ronds_ai help)\n`);
|
|
652
|
+
return 2;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
(async () => { process.exitCode = await run(process.argv); })().catch((e) => {
|
|
656
|
+
process.stderr.write(`${e && e.stack ? e.stack : e}\n`);
|
|
657
|
+
process.exitCode = 1;
|
|
658
|
+
});
|