@ai-setting/roy-agent-core 1.7.77 → 1.7.85
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/dist/config/config-protection.d.ts +89 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +16 -0
- package/dist/env/agent/agent-component.d.ts +42 -21
- package/dist/env/agent/agent-component.js +2 -2
- package/dist/env/agent/index.js +2 -2
- package/dist/env/agent/types.d.ts +32 -12
- package/dist/env/error-reply.d.ts +6 -0
- package/dist/env/error-reply.js +1 -1
- package/dist/env/event-source/bounty-im-handler.d.ts +8 -0
- package/dist/env/event-source/es-command.d.ts +39 -0
- package/dist/env/event-source/es-plugins.d.ts +68 -0
- package/dist/env/event-source/event-source-component.d.ts +15 -0
- package/dist/env/event-source/event-source-handlers.d.ts +68 -0
- package/dist/env/event-source/event-source-handlers.js +20 -8
- package/dist/env/event-source/index.d.ts +5 -1
- package/dist/env/event-source/index.js +57 -8
- package/dist/env/event-source/types.d.ts +101 -1
- package/dist/env/event-source/wecom-card-action-handler.d.ts +141 -0
- package/dist/env/event-source/wecom-card-builder.d.ts +220 -0
- package/dist/env/event-source/wecom-cli-handler.d.ts +266 -0
- package/dist/env/event-source/wecom-cli-sender.d.ts +88 -0
- package/dist/env/event-source/wecom-media.d.ts +130 -0
- package/dist/env/event-source/wecom-respond-registry.d.ts +151 -0
- package/dist/env/event-source/wecom-ws-bridge.d.ts +213 -0
- package/dist/env/index.js +16 -14
- package/dist/env/task/delegate/delegate-tool.d.ts +62 -2
- package/dist/env/task/delegate/delegate-tool.js +3 -1
- package/dist/env/task/delegate/index.js +1 -1
- package/dist/env/task/index.js +2 -2
- package/dist/env/task/plugins/index.d.ts +2 -0
- package/dist/env/task/plugins/index.js +23 -2
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +41 -2
- package/dist/env/task/plugins/lark-card-patch-notifier.js +1 -1
- package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +16 -0
- package/dist/env/task/plugins/wecom-card-state-store.d.ts +121 -0
- package/dist/env/task/plugins/wecom-task-notify-plugin.d.ts +224 -0
- package/dist/env/tool/built-in/index.d.ts +2 -0
- package/dist/env/tool/built-in/index.js +6 -1
- package/dist/env/tool/index.js +3 -2
- package/dist/env/workflow/index.js +3 -3
- package/dist/env/workflow/plugins/index.js +2 -2
- package/dist/env/workflow/tools/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +68 -17
- package/dist/shared/@ai-setting/{roy-agent-core-v87njmq7.js → roy-agent-core-0dh8npnz.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-2stt4rp5.js +134 -0
- package/dist/shared/@ai-setting/{roy-agent-core-mww0mnd9.js → roy-agent-core-7bpj859q.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-w0qjeq2v.js → roy-agent-core-7dd0s3xb.js} +14 -4
- package/dist/shared/@ai-setting/{roy-agent-core-rsn44n9y.js → roy-agent-core-b31v3qpv.js} +851 -46
- package/dist/shared/@ai-setting/{roy-agent-core-0v27y99n.js → roy-agent-core-begm7ytz.js} +63 -2
- package/dist/shared/@ai-setting/{roy-agent-core-aa2j7bk9.js → roy-agent-core-cha0jc7n.js} +40 -26
- package/dist/shared/@ai-setting/{roy-agent-core-hd3n57zs.js → roy-agent-core-d1n4jbza.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9vhq7fvv.js → roy-agent-core-dkrvmjsh.js} +12 -74
- package/dist/shared/@ai-setting/{roy-agent-core-99nwgj84.js → roy-agent-core-fzw9xzm1.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-m3vjepzz.js +544 -0
- package/dist/shared/@ai-setting/{roy-agent-core-ew6qb5yx.js → roy-agent-core-p6ks90tb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rhtdspx6.js → roy-agent-core-qk9hd89p.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-6cy43nss.js → roy-agent-core-rykf7c04.js} +49 -9
- package/dist/shared/@ai-setting/{roy-agent-core-8ez6mccb.js → roy-agent-core-tk98f92b.js} +4 -0
- package/dist/shared/@ai-setting/{roy-agent-core-bxkjk7zx.js → roy-agent-core-vx8zc847.js} +4 -1
- package/dist/shared/@ai-setting/roy-agent-core-vyr6svt6.js +31 -0
- package/dist/shared/@ai-setting/{roy-agent-core-3gpygqcx.js → roy-agent-core-xf6z96qy.js} +2086 -163
- package/package.json +10 -1
- /package/dist/shared/@ai-setting/{roy-agent-core-b4x6x4k2.js → roy-agent-core-m1fgtnrc.js} +0 -0
- /package/dist/shared/@ai-setting/{roy-agent-core-v85n42ve.js → roy-agent-core-ze5cqpf2.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
grepTool,
|
|
22
22
|
readFileTool,
|
|
23
23
|
writeFileTool
|
|
24
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
24
|
+
} from "./shared/@ai-setting/roy-agent-core-tk98f92b.js";
|
|
25
25
|
import {
|
|
26
26
|
getUnderstandImageLLMProvider,
|
|
27
27
|
resetUnderstandImageLLMProvider,
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
SkillComponent
|
|
54
54
|
} from "./shared/@ai-setting/roy-agent-core-5pr4zp88.js";
|
|
55
55
|
import"./shared/@ai-setting/roy-agent-core-psvxt4c9.js";
|
|
56
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
56
|
+
import"./shared/@ai-setting/roy-agent-core-m1fgtnrc.js";
|
|
57
57
|
import {
|
|
58
58
|
closeDatabase
|
|
59
59
|
} from "./shared/@ai-setting/roy-agent-core-r5wt1h3c.js";
|
|
@@ -62,13 +62,13 @@ import {
|
|
|
62
62
|
BaseEnvironment,
|
|
63
63
|
generateDescendingId,
|
|
64
64
|
generateId
|
|
65
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
65
|
+
} from "./shared/@ai-setting/roy-agent-core-p6ks90tb.js";
|
|
66
66
|
import {
|
|
67
67
|
TaskComponent
|
|
68
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
68
|
+
} from "./shared/@ai-setting/roy-agent-core-qk9hd89p.js";
|
|
69
69
|
import"./shared/@ai-setting/roy-agent-core-2akfd64z.js";
|
|
70
70
|
import"./shared/@ai-setting/roy-agent-core-jm136jzh.js";
|
|
71
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
71
|
+
import"./shared/@ai-setting/roy-agent-core-cha0jc7n.js";
|
|
72
72
|
import"./shared/@ai-setting/roy-agent-core-fttgm52a.js";
|
|
73
73
|
import"./shared/@ai-setting/roy-agent-core-q813vafd.js";
|
|
74
74
|
import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
@@ -76,7 +76,7 @@ import"./shared/@ai-setting/roy-agent-core-vffccgf6.js";
|
|
|
76
76
|
import"./shared/@ai-setting/roy-agent-core-p5cz9m8v.js";
|
|
77
77
|
import {
|
|
78
78
|
EventSourceComponent
|
|
79
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
79
|
+
} from "./shared/@ai-setting/roy-agent-core-begm7ytz.js";
|
|
80
80
|
import {
|
|
81
81
|
BountyIMInstance,
|
|
82
82
|
COMMAND_PREFIX,
|
|
@@ -84,10 +84,23 @@ import {
|
|
|
84
84
|
DEFAULT_CONFIG_PATH,
|
|
85
85
|
FALLBACK_MODEL_ACTIONS,
|
|
86
86
|
FALLBACK_MODEL_ACTION_NS,
|
|
87
|
+
LARK_CHANNEL_PROMPT_SECTION_TITLE,
|
|
88
|
+
LARK_PROMPT_LENGTH_BUDGET,
|
|
87
89
|
TimerInstance,
|
|
90
|
+
WECOM_CHANNEL_PROMPT_SECTION_TITLE,
|
|
91
|
+
WECOM_CHAT_ID_PREFIX,
|
|
92
|
+
WECOM_CLI_ES_TYPE,
|
|
93
|
+
WECOM_CREDENTIALS_DEFAULT_PATH,
|
|
94
|
+
WECOM_WS_DEFAULT_URL,
|
|
88
95
|
bountyIMHandler,
|
|
89
96
|
buildDefaultBountyIMSystemPrompt,
|
|
97
|
+
buildLarkChannelSystemPrompt,
|
|
98
|
+
buildLarkRecommendedAction,
|
|
99
|
+
buildWecomChannelSystemPrompt,
|
|
100
|
+
buildWecomNotifyPrompt,
|
|
101
|
+
buildWecomReplyChannel,
|
|
90
102
|
builtInHandlers,
|
|
103
|
+
esCommand,
|
|
91
104
|
extractCommandInvocation,
|
|
92
105
|
extractMetadata,
|
|
93
106
|
fallbackModelCommand,
|
|
@@ -100,15 +113,25 @@ import {
|
|
|
100
113
|
isFallbackModelCard,
|
|
101
114
|
larkCliHandler,
|
|
102
115
|
listCommand,
|
|
116
|
+
parseWecomFrame,
|
|
117
|
+
probeCommandBinary,
|
|
103
118
|
readFallbackModelList,
|
|
104
119
|
readRawFallbackModelArray,
|
|
120
|
+
readWecomCliConfig,
|
|
121
|
+
readWecomCredentialsFile,
|
|
105
122
|
renderFallbackModelCard,
|
|
106
123
|
renderTextCard,
|
|
107
124
|
resolveBountyIMSystemPrompt,
|
|
125
|
+
resolveEsFilePath,
|
|
126
|
+
resolveLarkChannelSystemPrompt,
|
|
127
|
+
resolveWecomBinary,
|
|
128
|
+
resolveWecomCredentials,
|
|
129
|
+
sanitizeWecomFrame,
|
|
108
130
|
timerHandler,
|
|
109
131
|
translateCardActionToCommand,
|
|
132
|
+
wecomCliHandler,
|
|
110
133
|
writeFallbackModelList
|
|
111
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
134
|
+
} from "./shared/@ai-setting/roy-agent-core-xf6z96qy.js";
|
|
112
135
|
import {
|
|
113
136
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
114
137
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -117,7 +140,7 @@ import {
|
|
|
117
140
|
isBuiltInEventSourceType,
|
|
118
141
|
isValidEventSourceType,
|
|
119
142
|
validateEventSourceConfig
|
|
120
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
143
|
+
} from "./shared/@ai-setting/roy-agent-core-vx8zc847.js";
|
|
121
144
|
import {
|
|
122
145
|
CLI_COMMAND_ES_TYPE,
|
|
123
146
|
CLI_SESSION_CHAT_ID_PREFIX,
|
|
@@ -129,10 +152,12 @@ import {
|
|
|
129
152
|
LogTraceComponent,
|
|
130
153
|
LogTraceConfigSchema
|
|
131
154
|
} from "./shared/@ai-setting/roy-agent-core-tm1mxttk.js";
|
|
155
|
+
import"./shared/@ai-setting/roy-agent-core-2stt4rp5.js";
|
|
132
156
|
import {
|
|
133
157
|
TaskTagPlugin,
|
|
134
158
|
createAutoTaskPlugin
|
|
135
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
159
|
+
} from "./shared/@ai-setting/roy-agent-core-b31v3qpv.js";
|
|
160
|
+
import"./shared/@ai-setting/roy-agent-core-m3vjepzz.js";
|
|
136
161
|
import {
|
|
137
162
|
EventStoreImpl,
|
|
138
163
|
getSharedEventStore,
|
|
@@ -164,11 +189,11 @@ import {
|
|
|
164
189
|
TASK_COMPLETED_STATUS_WORD,
|
|
165
190
|
TASK_DELIVERABLE_RECORDED
|
|
166
191
|
} from "./shared/@ai-setting/roy-agent-core-4rtg69cn.js";
|
|
167
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
168
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
192
|
+
import"./shared/@ai-setting/roy-agent-core-d1n4jbza.js";
|
|
193
|
+
import"./shared/@ai-setting/roy-agent-core-7dd0s3xb.js";
|
|
169
194
|
import {
|
|
170
195
|
WorkflowComponent
|
|
171
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
196
|
+
} from "./shared/@ai-setting/roy-agent-core-0dh8npnz.js";
|
|
172
197
|
import {
|
|
173
198
|
init_node_registry_helper,
|
|
174
199
|
registerDecoratorNodeType
|
|
@@ -181,7 +206,7 @@ import {
|
|
|
181
206
|
createWorkflowFromClass
|
|
182
207
|
} from "./shared/@ai-setting/roy-agent-core-h0x19xgn.js";
|
|
183
208
|
import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
184
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
209
|
+
import"./shared/@ai-setting/roy-agent-core-7bpj859q.js";
|
|
185
210
|
import {
|
|
186
211
|
SessionComponent
|
|
187
212
|
} from "./shared/@ai-setting/roy-agent-core-ddyk1rc0.js";
|
|
@@ -190,7 +215,7 @@ import {
|
|
|
190
215
|
} from "./shared/@ai-setting/roy-agent-core-0qyrk5k0.js";
|
|
191
216
|
import"./shared/@ai-setting/roy-agent-core-hhrg314p.js";
|
|
192
217
|
import"./shared/@ai-setting/roy-agent-core-12n08pg5.js";
|
|
193
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
218
|
+
import"./shared/@ai-setting/roy-agent-core-rykf7c04.js";
|
|
194
219
|
import"./shared/@ai-setting/roy-agent-core-6rh8k6ba.js";
|
|
195
220
|
import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
196
221
|
import"./shared/@ai-setting/roy-agent-core-dqxec05w.js";
|
|
@@ -212,12 +237,12 @@ import"./shared/@ai-setting/roy-agent-core-jagkferh.js";
|
|
|
212
237
|
import {
|
|
213
238
|
AgentComponent,
|
|
214
239
|
AgentComponentConfigSchema
|
|
215
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
240
|
+
} from "./shared/@ai-setting/roy-agent-core-dkrvmjsh.js";
|
|
216
241
|
import {
|
|
217
242
|
ToolComponent,
|
|
218
243
|
ToolRegistry,
|
|
219
244
|
ToolValidator
|
|
220
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
245
|
+
} from "./shared/@ai-setting/roy-agent-core-ze5cqpf2.js";
|
|
221
246
|
import"./shared/@ai-setting/roy-agent-core-jvv2h3d6.js";
|
|
222
247
|
import {
|
|
223
248
|
AgentRegistry
|
|
@@ -322,7 +347,8 @@ import {
|
|
|
322
347
|
resetTracerProvider,
|
|
323
348
|
setConfigComponent,
|
|
324
349
|
setLogDirOverride,
|
|
325
|
-
setQuietMode
|
|
350
|
+
setQuietMode,
|
|
351
|
+
setStdoutStrictMode
|
|
326
352
|
} from "./shared/@ai-setting/roy-agent-core-7f7t9wwp.js";
|
|
327
353
|
import {
|
|
328
354
|
SQLiteSpanStorage
|
|
@@ -565,6 +591,8 @@ export {
|
|
|
565
591
|
writeFileTool,
|
|
566
592
|
writeFallbackModelList,
|
|
567
593
|
wrapFunction,
|
|
594
|
+
wecomCliHandler as wecomCliHandlerDirect,
|
|
595
|
+
wecomCliHandler,
|
|
568
596
|
validateEventSourceConfig,
|
|
569
597
|
understandImageTool,
|
|
570
598
|
translateCardActionToCommand,
|
|
@@ -574,10 +602,16 @@ export {
|
|
|
574
602
|
timerHandler,
|
|
575
603
|
sniffMimeType,
|
|
576
604
|
setUnderstandImageLLMProvider,
|
|
605
|
+
setStdoutStrictMode,
|
|
577
606
|
setSharedEventStore,
|
|
578
607
|
setQuietMode,
|
|
579
608
|
setConfigComponent as setLoggerConfigComponent,
|
|
580
609
|
setLogDirOverride,
|
|
610
|
+
sanitizeWecomFrame,
|
|
611
|
+
resolveWecomCredentials,
|
|
612
|
+
resolveWecomBinary,
|
|
613
|
+
resolveLarkChannelSystemPrompt,
|
|
614
|
+
resolveEsFilePath,
|
|
581
615
|
resolveBountyIMSystemPrompt,
|
|
582
616
|
resetUnderstandImageLLMProvider,
|
|
583
617
|
resetTracerProvider,
|
|
@@ -587,10 +621,14 @@ export {
|
|
|
587
621
|
renderFallbackModelCard,
|
|
588
622
|
registerDecoratorNodeType,
|
|
589
623
|
recordSessionMessagesParamFilter,
|
|
624
|
+
readWecomCredentialsFile,
|
|
625
|
+
readWecomCliConfig,
|
|
590
626
|
readRawFallbackModelArray,
|
|
591
627
|
readFileTool,
|
|
592
628
|
readFallbackModelList,
|
|
593
629
|
propagation,
|
|
630
|
+
probeCommandBinary,
|
|
631
|
+
parseWecomFrame,
|
|
594
632
|
parseModelString,
|
|
595
633
|
parseImageInput,
|
|
596
634
|
parseCliSessionChatId,
|
|
@@ -639,6 +677,7 @@ export {
|
|
|
639
677
|
fallbackModelCommand,
|
|
640
678
|
extractMetadata,
|
|
641
679
|
extractCommandInvocation,
|
|
680
|
+
esCommand,
|
|
642
681
|
envQueryParamFilter,
|
|
643
682
|
embedResultFilter,
|
|
644
683
|
embedParamFilter,
|
|
@@ -655,7 +694,12 @@ export {
|
|
|
655
694
|
cliCommandHandler,
|
|
656
695
|
cascadeStopSessionTree,
|
|
657
696
|
builtInHandlers,
|
|
697
|
+
buildWecomReplyChannel,
|
|
698
|
+
buildWecomNotifyPrompt,
|
|
699
|
+
buildWecomChannelSystemPrompt,
|
|
658
700
|
buildOpencodeHeaders,
|
|
701
|
+
buildLarkRecommendedAction,
|
|
702
|
+
buildLarkChannelSystemPrompt,
|
|
659
703
|
buildDefaultBountyIMSystemPrompt,
|
|
660
704
|
buildCliReplyChannel,
|
|
661
705
|
bountyIMHandler,
|
|
@@ -665,6 +709,11 @@ export {
|
|
|
665
709
|
WorkflowEdges,
|
|
666
710
|
WorkflowComponent,
|
|
667
711
|
Workflow,
|
|
712
|
+
WECOM_WS_DEFAULT_URL,
|
|
713
|
+
WECOM_CREDENTIALS_DEFAULT_PATH,
|
|
714
|
+
WECOM_CLI_ES_TYPE,
|
|
715
|
+
WECOM_CHAT_ID_PREFIX,
|
|
716
|
+
WECOM_CHANNEL_PROMPT_SECTION_TITLE,
|
|
668
717
|
TreeFormatter,
|
|
669
718
|
TracedLightweight,
|
|
670
719
|
TracedAs,
|
|
@@ -713,6 +762,8 @@ export {
|
|
|
713
762
|
LLMDefaultConfigSchema,
|
|
714
763
|
LLMConfigSchema,
|
|
715
764
|
LLMComponent,
|
|
765
|
+
LARK_PROMPT_LENGTH_BUDGET,
|
|
766
|
+
LARK_CHANNEL_PROMPT_SECTION_TITLE,
|
|
716
767
|
HookManager,
|
|
717
768
|
FALLBACK_MODEL_ACTION_NS,
|
|
718
769
|
FALLBACK_MODEL_ACTIONS,
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/config/config-protection.ts
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, appendFileSync, rmSync, chmodSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
var PROTECTED_CONFIG_FILES = [
|
|
5
|
+
"config.jsonc",
|
|
6
|
+
"auth.json",
|
|
7
|
+
"event-sources.json",
|
|
8
|
+
"wecom-credentials.json"
|
|
9
|
+
];
|
|
10
|
+
var SNAPSHOT_KEEP = 10;
|
|
11
|
+
var SNAPSHOTS_DIRNAME = "snapshots";
|
|
12
|
+
var AUDIT_LOG_FILENAME = "audit.log";
|
|
13
|
+
var SNAP_META_FILENAME = ".snapshot-meta.json";
|
|
14
|
+
var SNAPSHOT_DIR_MODE = 448;
|
|
15
|
+
var SNAPSHOT_FILE_MODE = 384;
|
|
16
|
+
function pad2(n) {
|
|
17
|
+
return String(n).padStart(2, "0");
|
|
18
|
+
}
|
|
19
|
+
function snapshotTimestamp(d = new Date) {
|
|
20
|
+
return d.getUTCFullYear() + pad2(d.getUTCMonth() + 1) + pad2(d.getUTCDate()) + "T" + pad2(d.getUTCHours()) + "-" + pad2(d.getUTCMinutes()) + "-" + pad2(d.getUTCSeconds()) + "-" + String(d.getUTCMilliseconds()).padStart(3, "0") + "Z";
|
|
21
|
+
}
|
|
22
|
+
function snapshotsDir(configDir) {
|
|
23
|
+
return join(configDir, SNAPSHOTS_DIRNAME);
|
|
24
|
+
}
|
|
25
|
+
function snapshotConfigDir(configDir, now = new Date) {
|
|
26
|
+
if (!existsSync(configDir))
|
|
27
|
+
return null;
|
|
28
|
+
const snapRoot = snapshotsDir(configDir);
|
|
29
|
+
mkdirSync(snapRoot, { recursive: true });
|
|
30
|
+
const ts = snapshotTimestamp(now);
|
|
31
|
+
const snapDir = join(snapRoot, ts);
|
|
32
|
+
mkdirSync(snapDir, { recursive: true, mode: SNAPSHOT_DIR_MODE });
|
|
33
|
+
try {
|
|
34
|
+
chmodSync(snapDir, SNAPSHOT_DIR_MODE);
|
|
35
|
+
} catch {}
|
|
36
|
+
for (const file of PROTECTED_CONFIG_FILES) {
|
|
37
|
+
const src = join(configDir, file);
|
|
38
|
+
if (!existsSync(src))
|
|
39
|
+
continue;
|
|
40
|
+
try {
|
|
41
|
+
writeFileSync(join(snapDir, file), readFileSync(src), { mode: SNAPSHOT_FILE_MODE });
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
writeFileSync(join(snapDir, SNAP_META_FILENAME), JSON.stringify({ ts: now.toISOString(), source: configDir, pid: process.pid }));
|
|
45
|
+
pruneSnapshots(snapRoot, SNAPSHOT_KEEP);
|
|
46
|
+
return snapDir;
|
|
47
|
+
}
|
|
48
|
+
function pruneSnapshots(snapRoot, keep) {
|
|
49
|
+
const all = readdirSync(snapRoot).filter((n) => !n.startsWith(".")).sort();
|
|
50
|
+
const excess = all.length - keep;
|
|
51
|
+
for (let i = 0;i < excess; i++) {
|
|
52
|
+
try {
|
|
53
|
+
rmSync(join(snapRoot, all[i]), { recursive: true, force: true });
|
|
54
|
+
} catch {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function appendAuditLog(configDir, entry) {
|
|
58
|
+
try {
|
|
59
|
+
const full = {
|
|
60
|
+
ts: new Date().toISOString(),
|
|
61
|
+
pid: process.pid,
|
|
62
|
+
...entry
|
|
63
|
+
};
|
|
64
|
+
appendFileSync(join(configDir, AUDIT_LOG_FILENAME), JSON.stringify(full) + `
|
|
65
|
+
`);
|
|
66
|
+
} catch {}
|
|
67
|
+
}
|
|
68
|
+
function readAuditLog(configDir) {
|
|
69
|
+
const p = join(configDir, AUDIT_LOG_FILENAME);
|
|
70
|
+
if (!existsSync(p))
|
|
71
|
+
return [];
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const line of readFileSync(p, "utf-8").split(`
|
|
74
|
+
`)) {
|
|
75
|
+
if (!line.trim())
|
|
76
|
+
continue;
|
|
77
|
+
try {
|
|
78
|
+
out.push(JSON.parse(line));
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function checkSourceCountDrop(previousCount, newCount) {
|
|
84
|
+
if (previousCount <= 0)
|
|
85
|
+
return { allowed: true };
|
|
86
|
+
if (newCount >= previousCount)
|
|
87
|
+
return { allowed: true };
|
|
88
|
+
const dropRatio = (previousCount - newCount) / previousCount;
|
|
89
|
+
if (dropRatio > 0.3) {
|
|
90
|
+
return {
|
|
91
|
+
allowed: false,
|
|
92
|
+
reason: `source count drop ${(dropRatio * 100).toFixed(0)}% (${previousCount} -> ${newCount}) exceeds 30% threshold; refusing to overwrite (ROY_AGENT_ES_FORCE_SAVE=1 to override)`
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return { allowed: true };
|
|
96
|
+
}
|
|
97
|
+
function readSourceCountFromDisk(configPath) {
|
|
98
|
+
try {
|
|
99
|
+
if (!existsSync(configPath))
|
|
100
|
+
return -1;
|
|
101
|
+
const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
102
|
+
if (!cfg || !Array.isArray(cfg.sources))
|
|
103
|
+
return -1;
|
|
104
|
+
return cfg.sources.length;
|
|
105
|
+
} catch {
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function guardConfigWrite(configDir, file, writeFn) {
|
|
110
|
+
try {
|
|
111
|
+
const snapDir = snapshotConfigDir(configDir);
|
|
112
|
+
if (snapDir) {
|
|
113
|
+
appendAuditLog(configDir, {
|
|
114
|
+
file,
|
|
115
|
+
action: "pre-save-snapshot",
|
|
116
|
+
detail: `snapshot=${snapDir}`
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
} catch {}
|
|
120
|
+
try {
|
|
121
|
+
writeFn();
|
|
122
|
+
} catch (err) {
|
|
123
|
+
appendAuditLog(configDir, {
|
|
124
|
+
file,
|
|
125
|
+
action: "write-failed",
|
|
126
|
+
detail: err?.message ?? String(err)
|
|
127
|
+
});
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
appendAuditLog(configDir, { file, action: "save" });
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { PROTECTED_CONFIG_FILES, snapshotConfigDir, appendAuditLog, readAuditLog, checkSourceCountDrop, readSourceCountFromDisk, guardConfigWrite };
|
|
@@ -21,7 +21,8 @@ var HEADER_TEMPLATE = {
|
|
|
21
21
|
failed: "red",
|
|
22
22
|
stopped: "grey",
|
|
23
23
|
cancelled: "grey",
|
|
24
|
-
deleted: "grey"
|
|
24
|
+
deleted: "grey",
|
|
25
|
+
to_validate: "turquoise"
|
|
25
26
|
};
|
|
26
27
|
var STATUS_PHRASE = {
|
|
27
28
|
running: "实时同步中",
|
|
@@ -29,7 +30,8 @@ var STATUS_PHRASE = {
|
|
|
29
30
|
failed: "\uD83D\uDEA8 任务失败",
|
|
30
31
|
stopped: "⏹️ 已停止",
|
|
31
32
|
cancelled: "\uD83D\uDEAB 已取消",
|
|
32
|
-
deleted: "\uD83D\uDDD1️ 已删除"
|
|
33
|
+
deleted: "\uD83D\uDDD1️ 已删除",
|
|
34
|
+
to_validate: "\uD83D\uDD0D 待验证"
|
|
33
35
|
};
|
|
34
36
|
var FINAL_MILESTONE_TITLE = {
|
|
35
37
|
running: "Task 进行中",
|
|
@@ -37,7 +39,8 @@ var FINAL_MILESTONE_TITLE = {
|
|
|
37
39
|
failed: "Task 失败",
|
|
38
40
|
stopped: "Task 已暂停",
|
|
39
41
|
cancelled: "Task 已取消",
|
|
40
|
-
deleted: "Task 已删除"
|
|
42
|
+
deleted: "Task 已删除",
|
|
43
|
+
to_validate: "Task 待验证"
|
|
41
44
|
};
|
|
42
45
|
var SPINNER_EMOJIS = ["⏳", "\uD83D\uDD04", "\uD83D\uDD03", "⌛", "⏰", "\uD83D\uDD01"];
|
|
43
46
|
var PROGRESS_BAR_CELLS = 20;
|
|
@@ -629,7 +632,7 @@ class LarkCardPatchNotifier {
|
|
|
629
632
|
constructor(options = {}) {
|
|
630
633
|
this.options = {
|
|
631
634
|
pinOnStart: true,
|
|
632
|
-
unpinOnFinish:
|
|
635
|
+
unpinOnFinish: false,
|
|
633
636
|
...options
|
|
634
637
|
};
|
|
635
638
|
}
|
|
@@ -885,6 +888,10 @@ class LarkCardPatchNotifier {
|
|
|
885
888
|
});
|
|
886
889
|
}
|
|
887
890
|
finalisedCards = new Set;
|
|
891
|
+
unfinaliseCard(messageId) {
|
|
892
|
+
this.finalisedCards.delete(messageId);
|
|
893
|
+
}
|
|
894
|
+
testRunner;
|
|
888
895
|
trackedCardCount() {
|
|
889
896
|
return this.states.size;
|
|
890
897
|
}
|
|
@@ -1119,6 +1126,9 @@ class LarkCardPatchNotifier {
|
|
|
1119
1126
|
return args;
|
|
1120
1127
|
}
|
|
1121
1128
|
runLarkCli(argv, op) {
|
|
1129
|
+
if (this.testRunner) {
|
|
1130
|
+
return this.testRunner(argv, op);
|
|
1131
|
+
}
|
|
1122
1132
|
return new Promise((resolve, reject) => {
|
|
1123
1133
|
if (process.env.ROY_HOOK_DEBUG === "1") {
|
|
1124
1134
|
console.error(`[DEBUG LarkCardPatchNotifier.runLarkCli] op=${op} args=${JSON.stringify(argv).slice(0, 300)}`);
|