dsh-punky-swarm 0.3.6
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/CHANGELOG.md +120 -0
- package/LICENSE +661 -0
- package/README.en.md +281 -0
- package/README.md +281 -0
- package/cordis.patch.yml +59 -0
- package/lib/acps/certs.js +310 -0
- package/lib/acps/discovery-client.js +283 -0
- package/lib/acps/registry-client.js +527 -0
- package/lib/acps/server.js +302 -0
- package/lib/aip/agent-descriptor.js +170 -0
- package/lib/aip/identity.js +469 -0
- package/lib/aip/tool-descriptor.js +93 -0
- package/lib/api.js +266 -0
- package/lib/artifact-types.js +48 -0
- package/lib/assembly/audit-blind-review.js +170 -0
- package/lib/assembly/schema.js +253 -0
- package/lib/assembly.js +41 -0
- package/lib/assets.js +103 -0
- package/lib/bridge/trajectory.js +202 -0
- package/lib/client.js +704 -0
- package/lib/comms/acps-bridge.js +219 -0
- package/lib/comms/aip-format.js +141 -0
- package/lib/comms/budget.js +124 -0
- package/lib/comms/mailbox.js +221 -0
- package/lib/comms/topic-runtime.js +76 -0
- package/lib/comms/topic.js +115 -0
- package/lib/discovery/filter.js +199 -0
- package/lib/discovery/schema.js +157 -0
- package/lib/discovery/service.js +251 -0
- package/lib/hot/config-watch.js +252 -0
- package/lib/index.js +433 -0
- package/lib/lock.js +69 -0
- package/lib/panel/batch-detail.js +163 -0
- package/lib/panel/batch-list.js +84 -0
- package/lib/panel/locales.js +93 -0
- package/lib/panel/main.js +270 -0
- package/lib/panel/stream.js +348 -0
- package/lib/panel/theme.js +103 -0
- package/lib/panel/widgets.js +63 -0
- package/lib/schema.d.ts +192 -0
- package/lib/schema.js +259 -0
- package/lib/schema.ts +398 -0
- package/lib/state/archive.js +174 -0
- package/lib/state/command-exec.js +148 -0
- package/lib/state/constants.js +37 -0
- package/lib/state/corrupt-registry.js +103 -0
- package/lib/state/event-types.js +65 -0
- package/lib/state/gates.d.ts +226 -0
- package/lib/state/gates.js +428 -0
- package/lib/state/gates.ts +348 -0
- package/lib/state/machine-rules.d.ts +14 -0
- package/lib/state/machine-rules.js +76 -0
- package/lib/state/machine-rules.ts +88 -0
- package/lib/state/machine.js +68 -0
- package/lib/state/resume.js +201 -0
- package/lib/state/schema-v3.d.ts +10 -0
- package/lib/state/schema-v3.js +57 -0
- package/lib/state/schema-v3.ts +80 -0
- package/lib/state/store.js +607 -0
- package/lib/state/task-utils.js +40 -0
- package/lib/tools/core.js +323 -0
- package/lib/tools/git-utils.js +44 -0
- package/lib/tools/lane-tools.js +455 -0
- package/lib/tools/log-tools.js +173 -0
- package/lib/tools/mailbox-tools.js +121 -0
- package/lib/tools/merge-agent.js +127 -0
- package/lib/tools/register.js +85 -0
- package/lib/tools/shared.js +32 -0
- package/lib/types/contracts.d.ts +277 -0
- package/lib/types/contracts.js +17 -0
- package/lib/types/contracts.ts +279 -0
- package/lib/verify/evidence.js +249 -0
- package/lib/verify/gate.js +161 -0
- package/lib/verify/mount.js +48 -0
- package/lib/verify/selector.js +101 -0
- package/lib/watch/lane-heartbeat.js +333 -0
- package/lib/wave-plan.d.ts +48 -0
- package/lib/wave-plan.js +473 -0
- package/lib/wave-plan.ts +465 -0
- package/package.json +71 -0
- package/presets/jiufeng/NOTICE +5 -0
- package/presets/jiufeng/agent.cordis.yml +275 -0
- package/presets/jiufeng/preset.yml +3 -0
- package/skills/jiufeng-team/SKILL.md +214 -0
- package/skills/jiufeng-team/references/constitution.md +62 -0
- package/skills/jiufeng-team/references/roles/coder.md +17 -0
- package/skills/jiufeng-team/references/roles/coordinator.md +13 -0
- package/skills/jiufeng-team/references/roles/designer.md +14 -0
- package/skills/jiufeng-team/references/roles/doc-manager.md +13 -0
- package/skills/jiufeng-team/references/roles/manager.md +22 -0
- package/skills/jiufeng-team/references/roles/reviewer.md +19 -0
- package/skills/jiufeng-team/references/roles/supervisor.md +13 -0
- package/skills/jiufeng-team/references/roles/tester.md +13 -0
- package/skills/jiufeng-team/references/templates/call-chain-matrix-template.md +121 -0
- package/skills/jiufeng-team/references/templates/endpoint-behavior-template.md +60 -0
- package/skills/jiufeng-team/references/templates/gap-list.json +33 -0
- package/skills/jiufeng-team/references/templates/leader-decision-pack.md +92 -0
- package/skills/jiufeng-team/references/templates/plan-template.md +61 -0
- package/skills/jiufeng-team/references/templates/success-pattern-seeds.md +126 -0
- package/skills/jiufeng-team/references/workflow.md +98 -0
- package/skills/jiufeng-team/scripts/check-v3-density.mjs +98 -0
package/lib/schema.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export declare const MEMBER_STATES: readonly ["pending", "running", "review", "merged", "failed", "skipped", "conflict", "idle"];
|
|
2
|
+
export type MemberState = typeof MEMBER_STATES[number];
|
|
3
|
+
export declare const BATCH_PHASES: readonly ["planning", "running", "paused", "aborted", "complete"];
|
|
4
|
+
export type BatchPhase = typeof BATCH_PHASES[number];
|
|
5
|
+
export declare const SETTLE_STATES: readonly ["merged", "failed", "skipped"];
|
|
6
|
+
export type SettleState = typeof SETTLE_STATES[number];
|
|
7
|
+
export declare const MEMBER_TRANSITIONS: {
|
|
8
|
+
readonly pending: readonly ["running", "failed", "skipped"];
|
|
9
|
+
readonly running: readonly ["review", "failed", "skipped"];
|
|
10
|
+
readonly review: readonly ["merged", "conflict", "failed", "running"];
|
|
11
|
+
readonly idle: readonly ["running"];
|
|
12
|
+
readonly merged: readonly [];
|
|
13
|
+
readonly failed: readonly [];
|
|
14
|
+
readonly skipped: readonly [];
|
|
15
|
+
readonly conflict: readonly [];
|
|
16
|
+
};
|
|
17
|
+
export declare const BATCH_TRANSITIONS: {
|
|
18
|
+
readonly planning: readonly ["running", "aborted"];
|
|
19
|
+
readonly running: readonly ["paused", "complete", "aborted"];
|
|
20
|
+
readonly paused: readonly ["running", "aborted"];
|
|
21
|
+
readonly aborted: readonly [];
|
|
22
|
+
readonly complete: readonly [];
|
|
23
|
+
};
|
|
24
|
+
export declare function isMemberState(s: unknown): s is MemberState;
|
|
25
|
+
export declare function isBatchPhase(p: unknown): p is BatchPhase;
|
|
26
|
+
export declare function isMemberTerminal(s: unknown): s is MemberState;
|
|
27
|
+
export declare function isBatchTerminal(p: unknown): p is BatchPhase;
|
|
28
|
+
export declare function canTransitionMember(from: MemberState, to: MemberState): boolean;
|
|
29
|
+
export declare function canTransitionBatch(from: BatchPhase, to: BatchPhase): boolean;
|
|
30
|
+
export declare function assertMemberTransition(from: MemberState, to: MemberState): void;
|
|
31
|
+
export declare function assertBatchTransition(from: BatchPhase, to: BatchPhase): void;
|
|
32
|
+
export declare function assertMemberState(s: MemberState): void;
|
|
33
|
+
export declare function assertBatchPhase(p: BatchPhase): void;
|
|
34
|
+
export declare const TRAJECTORY_DEFAULTS: {
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
autoFail: boolean;
|
|
37
|
+
failConfidence: number;
|
|
38
|
+
poll: {
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
baseUrl: null;
|
|
41
|
+
intervalMs: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export declare const WATCH_DEFAULTS: Readonly<{
|
|
45
|
+
enabled: true;
|
|
46
|
+
intervalsMinutes: number[];
|
|
47
|
+
maxMissed: 3;
|
|
48
|
+
scanIntervalMinutes: 1;
|
|
49
|
+
probeTemplate: null;
|
|
50
|
+
}>;
|
|
51
|
+
interface ConfigWatchInput {
|
|
52
|
+
enabled?: unknown;
|
|
53
|
+
intervalsMinutes?: unknown[];
|
|
54
|
+
maxMissed?: unknown;
|
|
55
|
+
scanIntervalMinutes?: unknown;
|
|
56
|
+
probeTemplate?: unknown;
|
|
57
|
+
}
|
|
58
|
+
interface ConfigVerifyInput {
|
|
59
|
+
enabled?: unknown;
|
|
60
|
+
mode?: unknown;
|
|
61
|
+
}
|
|
62
|
+
interface ConfigDiscoveryInput {
|
|
63
|
+
enabled?: unknown;
|
|
64
|
+
nodes?: unknown;
|
|
65
|
+
}
|
|
66
|
+
interface ConfigAcpsDiscoveryInput {
|
|
67
|
+
enabled?: unknown;
|
|
68
|
+
baseUrl?: unknown;
|
|
69
|
+
timeout?: unknown;
|
|
70
|
+
limit?: unknown;
|
|
71
|
+
scope?: unknown;
|
|
72
|
+
}
|
|
73
|
+
interface ConfigBridgeInput {
|
|
74
|
+
enabled?: unknown;
|
|
75
|
+
mode?: unknown;
|
|
76
|
+
inbound?: unknown;
|
|
77
|
+
}
|
|
78
|
+
interface ConfigAcpsEndpointInput {
|
|
79
|
+
enabled?: unknown;
|
|
80
|
+
port?: unknown;
|
|
81
|
+
host?: unknown;
|
|
82
|
+
cert?: unknown;
|
|
83
|
+
key?: unknown;
|
|
84
|
+
ca?: unknown;
|
|
85
|
+
certDir?: unknown;
|
|
86
|
+
aic?: unknown;
|
|
87
|
+
agentName?: unknown;
|
|
88
|
+
minVersion?: unknown;
|
|
89
|
+
devInsecure?: unknown;
|
|
90
|
+
}
|
|
91
|
+
interface ConfigCapabilitiesInput {
|
|
92
|
+
watch?: ConfigWatchInput;
|
|
93
|
+
verify?: ConfigVerifyInput;
|
|
94
|
+
discovery?: ConfigDiscoveryInput;
|
|
95
|
+
}
|
|
96
|
+
interface ConfigAcpsInput {
|
|
97
|
+
enabled?: unknown;
|
|
98
|
+
discovery?: ConfigAcpsDiscoveryInput;
|
|
99
|
+
bridge?: ConfigBridgeInput;
|
|
100
|
+
endpoint?: ConfigAcpsEndpointInput;
|
|
101
|
+
}
|
|
102
|
+
interface ConfigInput {
|
|
103
|
+
capabilities?: ConfigCapabilitiesInput;
|
|
104
|
+
acps?: ConfigAcpsInput;
|
|
105
|
+
}
|
|
106
|
+
interface ResolvedWatchConfig {
|
|
107
|
+
enabled: boolean;
|
|
108
|
+
intervalsMinutes: readonly number[];
|
|
109
|
+
maxMissed: number;
|
|
110
|
+
scanIntervalMinutes: number;
|
|
111
|
+
probeTemplate: string | null;
|
|
112
|
+
}
|
|
113
|
+
interface ResolvedVerifyConfig {
|
|
114
|
+
enabled: boolean;
|
|
115
|
+
mode: 'advisory' | 'enforce';
|
|
116
|
+
}
|
|
117
|
+
interface ResolvedDiscoveryConfig {
|
|
118
|
+
enabled: boolean;
|
|
119
|
+
nodes: object;
|
|
120
|
+
}
|
|
121
|
+
interface ResolvedAcpsDiscoveryConfig {
|
|
122
|
+
enabled: boolean;
|
|
123
|
+
baseUrl: string;
|
|
124
|
+
timeout: number;
|
|
125
|
+
limit: number;
|
|
126
|
+
scope: 'local' | 'external' | 'both';
|
|
127
|
+
}
|
|
128
|
+
interface ResolvedBridgeConfig {
|
|
129
|
+
enabled: boolean;
|
|
130
|
+
mode: 'inprocess' | 'http';
|
|
131
|
+
inbound: boolean;
|
|
132
|
+
}
|
|
133
|
+
interface ResolvedAcpsEndpointConfig {
|
|
134
|
+
enabled: boolean;
|
|
135
|
+
port: number;
|
|
136
|
+
host: string;
|
|
137
|
+
cert: string | null;
|
|
138
|
+
key: string | null;
|
|
139
|
+
ca: string | null;
|
|
140
|
+
certDir: string | null;
|
|
141
|
+
aic: string | null;
|
|
142
|
+
agentName: string;
|
|
143
|
+
minVersion: 'TLSv1.2' | 'TLSv1.3';
|
|
144
|
+
devInsecure: boolean;
|
|
145
|
+
}
|
|
146
|
+
interface ResolvedAcpsConfig {
|
|
147
|
+
enabled: boolean;
|
|
148
|
+
endpoint: ResolvedAcpsEndpointConfig;
|
|
149
|
+
}
|
|
150
|
+
export declare function resolveWatchConfig(config: ConfigInput | null | undefined): ResolvedWatchConfig;
|
|
151
|
+
export declare const VERIFY_DEFAULTS: Readonly<{
|
|
152
|
+
readonly enabled: true;
|
|
153
|
+
readonly mode: "advisory";
|
|
154
|
+
}>;
|
|
155
|
+
export declare function resolveVerifyConfig(config: ConfigInput | null | undefined): ResolvedVerifyConfig;
|
|
156
|
+
export declare const DISCOVERY_DEFAULTS: Readonly<{
|
|
157
|
+
enabled: true;
|
|
158
|
+
nodes: {};
|
|
159
|
+
}>;
|
|
160
|
+
export declare function resolveDiscoveryConfig(config: ConfigInput | null | undefined): ResolvedDiscoveryConfig;
|
|
161
|
+
export declare const ACPS_DISCOVERY_DEFAULTS: Readonly<{
|
|
162
|
+
readonly enabled: false;
|
|
163
|
+
readonly baseUrl: "";
|
|
164
|
+
readonly timeout: 10000;
|
|
165
|
+
readonly limit: 5;
|
|
166
|
+
readonly scope: "local";
|
|
167
|
+
}>;
|
|
168
|
+
export declare function resolveAcpsDiscoveryConfig(config: ConfigInput | null | undefined): ResolvedAcpsDiscoveryConfig;
|
|
169
|
+
export declare const BRIDGE_DEFAULTS: Readonly<{
|
|
170
|
+
readonly enabled: false;
|
|
171
|
+
readonly mode: "inprocess";
|
|
172
|
+
readonly inbound: false;
|
|
173
|
+
}>;
|
|
174
|
+
export declare function resolveBridgeConfig(config: ConfigInput | null | undefined): ResolvedBridgeConfig;
|
|
175
|
+
export declare const ACPS_DEFAULTS: Readonly<{
|
|
176
|
+
readonly enabled: false;
|
|
177
|
+
readonly endpoint: {
|
|
178
|
+
readonly enabled: false;
|
|
179
|
+
readonly port: 9443;
|
|
180
|
+
readonly host: "127.0.0.1";
|
|
181
|
+
readonly cert: null;
|
|
182
|
+
readonly key: null;
|
|
183
|
+
readonly ca: null;
|
|
184
|
+
readonly certDir: null;
|
|
185
|
+
readonly aic: null;
|
|
186
|
+
readonly agentName: "dsh-punky-swarm";
|
|
187
|
+
readonly minVersion: "TLSv1.3";
|
|
188
|
+
readonly devInsecure: false;
|
|
189
|
+
};
|
|
190
|
+
}>;
|
|
191
|
+
export declare function resolveAcpsConfig(config: ConfigInput | null | undefined): ResolvedAcpsConfig;
|
|
192
|
+
export {};
|
package/lib/schema.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2025-2026 Punky
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
export const MEMBER_STATES = [
|
|
18
|
+
'pending', 'running', 'review', 'merged', 'failed', 'skipped', 'conflict', 'idle',
|
|
19
|
+
];
|
|
20
|
+
// 批次阶段:planning -> running -> paused -> aborted | complete
|
|
21
|
+
export const BATCH_PHASES = ['planning', 'running', 'paused', 'aborted', 'complete'];
|
|
22
|
+
export const SETTLE_STATES = ['merged', 'failed', 'skipped'];
|
|
23
|
+
export const MEMBER_TRANSITIONS = {
|
|
24
|
+
pending: ['running', 'failed', 'skipped'],
|
|
25
|
+
running: ['review', 'failed', 'skipped'],
|
|
26
|
+
review: ['merged', 'conflict', 'failed', 'running'], // running = REWORK 返工(attempt+1,由事件计数)
|
|
27
|
+
idle: ['running'],
|
|
28
|
+
merged: [],
|
|
29
|
+
failed: [],
|
|
30
|
+
skipped: [],
|
|
31
|
+
conflict: [],
|
|
32
|
+
};
|
|
33
|
+
export const BATCH_TRANSITIONS = {
|
|
34
|
+
planning: ['running', 'aborted'],
|
|
35
|
+
running: ['paused', 'complete', 'aborted'],
|
|
36
|
+
paused: ['running', 'aborted'],
|
|
37
|
+
aborted: [],
|
|
38
|
+
complete: [],
|
|
39
|
+
};
|
|
40
|
+
// 守卫函数:unknown 入参 + 类型谓词(下游收窄);内部 includes 单点断言——
|
|
41
|
+
// 运行期等价:Array.includes 接受任意值,断言仅类型层。
|
|
42
|
+
export function isMemberState(s) {
|
|
43
|
+
return MEMBER_STATES.includes(s);
|
|
44
|
+
}
|
|
45
|
+
export function isBatchPhase(p) {
|
|
46
|
+
return BATCH_PHASES.includes(p);
|
|
47
|
+
}
|
|
48
|
+
export function isMemberTerminal(s) {
|
|
49
|
+
return SETTLE_STATES.includes(s) || s === 'conflict';
|
|
50
|
+
}
|
|
51
|
+
export function isBatchTerminal(p) {
|
|
52
|
+
return p === 'aborted' || p === 'complete';
|
|
53
|
+
}
|
|
54
|
+
// 参数类型化为 MemberState/BatchPhase;内部运行时守卫(isMemberState 等)保留不动
|
|
55
|
+
// (防御 JS 调用方非法值——类型只约束编译期)。
|
|
56
|
+
export function canTransitionMember(from, to) {
|
|
57
|
+
if (!isMemberState(from) || !isMemberState(to))
|
|
58
|
+
return false;
|
|
59
|
+
// 中间变量标注:satisfies 保留字面量类型,联合键索引得元组联合 → 统一为通用只读数组后再 includes(运行期零变更)
|
|
60
|
+
const tos = MEMBER_TRANSITIONS[from];
|
|
61
|
+
return tos.includes(to);
|
|
62
|
+
}
|
|
63
|
+
export function canTransitionBatch(from, to) {
|
|
64
|
+
if (!isBatchPhase(from) || !isBatchPhase(to))
|
|
65
|
+
return false;
|
|
66
|
+
const tos = BATCH_TRANSITIONS[from];
|
|
67
|
+
return tos.includes(to);
|
|
68
|
+
}
|
|
69
|
+
export function assertMemberTransition(from, to) {
|
|
70
|
+
if (!canTransitionMember(from, to)) {
|
|
71
|
+
throw new Error('invalid member transition: ' + from + ' -> ' + to);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function assertBatchTransition(from, to) {
|
|
75
|
+
if (!canTransitionBatch(from, to)) {
|
|
76
|
+
throw new Error('invalid batch phase transition: ' + from + ' -> ' + to);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function assertMemberState(s) {
|
|
80
|
+
if (!isMemberState(s))
|
|
81
|
+
throw new Error('unknown member state: ' + String(s));
|
|
82
|
+
}
|
|
83
|
+
export function assertBatchPhase(p) {
|
|
84
|
+
if (!isBatchPhase(p))
|
|
85
|
+
throw new Error('unknown batch phase: ' + String(p));
|
|
86
|
+
}
|
|
87
|
+
// ── 可选配置键默认值(装配默认开——AIP 为主线 + 治理能力全开;
|
|
88
|
+
// 显式 enabled:false 可逐键关闭。缺省 = 全能力启用,行为按各能力语义)──
|
|
89
|
+
// capabilities.trajectory:诊断桥接(lib/bridge/trajectory.js)——订阅 trajectory 异常 → sessionId→lane 映射 → notify;
|
|
90
|
+
// enabled=true(默认):桥接挂载;autoFail=false(默认):异常只 notify,不自动 member_settle failed;
|
|
91
|
+
// failConfidence:loop_deadlock 自动 failed 的置信阈值(默认 0.85,可配);
|
|
92
|
+
// poll:可选 HTTP 轮询 fallback(默认关,插件未装/无事件时静默降级)
|
|
93
|
+
export const TRAJECTORY_DEFAULTS = {
|
|
94
|
+
enabled: true,
|
|
95
|
+
autoFail: false,
|
|
96
|
+
failConfidence: 0.85,
|
|
97
|
+
poll: { enabled: false, baseUrl: null, intervalMs: 60_000 },
|
|
98
|
+
};
|
|
99
|
+
// ── capabilities.watch:lane 过期检测(lib/watch/lane-heartbeat.js)──
|
|
100
|
+
// enabled=true(默认)时 watchdog 挂载、lane_heartbeat 注册
|
|
101
|
+
export const WATCH_DEFAULTS = Object.freeze({
|
|
102
|
+
enabled: true,
|
|
103
|
+
intervalsMinutes: [10, 20, 30], // 退避档位(分钟):冷场越久追问间隔越长
|
|
104
|
+
maxMissed: 3, // 硬停拍数:连续 N 拍无活动 → lane.stalled 事件,停止追问
|
|
105
|
+
scanIntervalMinutes: 1, // watchdog 扫描间隔(index.js 挂载 setInterval 用)
|
|
106
|
+
probeTemplate: null, // 追问模板(可选覆写;缺省用内置 ≤5 句模板,支持 {lane}/{batchId}/{missed} 占位)
|
|
107
|
+
});
|
|
108
|
+
export function resolveWatchConfig(config) {
|
|
109
|
+
const c = config?.capabilities?.watch ?? {};
|
|
110
|
+
const intervals = Array.isArray(c.intervalsMinutes) && c.intervalsMinutes.length > 0
|
|
111
|
+
? c.intervalsMinutes.map((m) => (Number.isFinite(Number(m)) && Number(m) >= 0 ? Number(m) : null)).filter((x) => x !== null)
|
|
112
|
+
: null;
|
|
113
|
+
return {
|
|
114
|
+
// P1-01 等价默认合并:缺省 = WATCH_DEFAULTS.enabled(true)(与 readCapability 对注册表 default 的
|
|
115
|
+
// deepMerge 语义等价——显式 enabled:false 才关)。不直接 import readCapability 以避免
|
|
116
|
+
// lib/schema.ts ⟷ lib/assembly/schema.ts 顶层循环依赖(assembly 顶层初始化需本文件常量,静态 import 会 TDZ)。
|
|
117
|
+
enabled: c.enabled !== false,
|
|
118
|
+
intervalsMinutes: intervals && intervals.length > 0 ? intervals : WATCH_DEFAULTS.intervalsMinutes,
|
|
119
|
+
maxMissed: Number.isFinite(Number(c.maxMissed)) && Number(c.maxMissed) >= 1 ? Math.floor(Number(c.maxMissed)) : WATCH_DEFAULTS.maxMissed,
|
|
120
|
+
scanIntervalMinutes: Number.isFinite(Number(c.scanIntervalMinutes)) && Number(c.scanIntervalMinutes) >= 0.1
|
|
121
|
+
? Number(c.scanIntervalMinutes)
|
|
122
|
+
: WATCH_DEFAULTS.scanIntervalMinutes,
|
|
123
|
+
probeTemplate: typeof c.probeTemplate === 'string' && c.probeTemplate.length > 0
|
|
124
|
+
? c.probeTemplate
|
|
125
|
+
: WATCH_DEFAULTS.probeTemplate,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// ── capabilities.verify:验收证据(lib/verify/evidence.js + lib/verify/gate.js)──
|
|
129
|
+
// enabled=true(默认)捕获 hook 挂载;
|
|
130
|
+
// mode=advisory(默认)只记录不拦截;mode=enforce 显式启用则审计裁决拦截(createCompletionGate 读本键)
|
|
131
|
+
// as const:mode 字面量派生返回类型('advisory'|'enforce'),纯类型层、运行期等价。
|
|
132
|
+
export const VERIFY_DEFAULTS = Object.freeze({
|
|
133
|
+
enabled: true,
|
|
134
|
+
mode: 'advisory',
|
|
135
|
+
});
|
|
136
|
+
export function resolveVerifyConfig(config) {
|
|
137
|
+
const c = config?.capabilities?.verify ?? {};
|
|
138
|
+
return {
|
|
139
|
+
// P1-01 等价默认合并:缺省 = VERIFY_DEFAULTS.enabled(true),显式 enabled:false 才关(同 resolveWatchConfig 注释)
|
|
140
|
+
enabled: c.enabled !== false,
|
|
141
|
+
mode: c.mode === 'enforce' ? 'enforce' : VERIFY_DEFAULTS.mode,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// ── capabilities.discovery:发现服务(lib/discovery/service.js)──
|
|
145
|
+
// ADP(Agent Discovery Protocol)统一 POST /discover + /.well-known/aip 预置;
|
|
146
|
+
// enabled=true(默认):webServer 存在时挂载发现服务(消费 tool catalog + agent-descriptor 目录);
|
|
147
|
+
// nodes:节点级 active 覆写——{ <aic|name>: { active: false } } 时该节点不出现在查询结果(默认 active=true)。
|
|
148
|
+
export const DISCOVERY_DEFAULTS = Object.freeze({
|
|
149
|
+
enabled: true,
|
|
150
|
+
nodes: {},
|
|
151
|
+
});
|
|
152
|
+
export function resolveDiscoveryConfig(config) {
|
|
153
|
+
const c = config?.capabilities?.discovery ?? {};
|
|
154
|
+
return {
|
|
155
|
+
// P1-01 等价默认合并:缺省 = DISCOVERY_DEFAULTS.enabled(true),显式 enabled:false 才关(同 resolveWatchConfig 注释)
|
|
156
|
+
enabled: c.enabled !== false,
|
|
157
|
+
nodes: (c.nodes && typeof c.nodes === 'object' && !Array.isArray(c.nodes)) ? c.nodes : {},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// ── acps.discovery:外部 ADP 发现客户端(lib/acps/discovery-client.js)──
|
|
161
|
+
// 插件 Leader 经外部 discovery-server 发现 partner(POST {baseUrl}/discover);
|
|
162
|
+
// 默认关(对外能力显式开启)——enabled=false 不创建客户端实例,零运行时路径。
|
|
163
|
+
// baseUrl:外部 discovery-server 根地址(空 = 未配置,discover 调用抛错)
|
|
164
|
+
// timeout/limit:单次请求超时 ms(默认 10000)与默认返回上限(默认 5)
|
|
165
|
+
// scope:查询范围 local(仅既有本地目录)/ external(仅外部)/ both(本地+外部合并)
|
|
166
|
+
// as const:scope 字面量派生返回类型('local'|'external'|'both'),纯类型层、运行期等价。
|
|
167
|
+
export const ACPS_DISCOVERY_DEFAULTS = Object.freeze({
|
|
168
|
+
enabled: false,
|
|
169
|
+
baseUrl: '',
|
|
170
|
+
timeout: 10_000,
|
|
171
|
+
limit: 5,
|
|
172
|
+
scope: 'local',
|
|
173
|
+
});
|
|
174
|
+
export function resolveAcpsDiscoveryConfig(config) {
|
|
175
|
+
const c = config?.acps?.discovery ?? {};
|
|
176
|
+
// 单点断言:includes 命中即 c.scope 必为三值之一(运行期 includes 语义不变,断言仅类型层)
|
|
177
|
+
const scope = ['local', 'external', 'both'].includes(c.scope)
|
|
178
|
+
? c.scope
|
|
179
|
+
: ACPS_DISCOVERY_DEFAULTS.scope;
|
|
180
|
+
return {
|
|
181
|
+
enabled: c.enabled === true,
|
|
182
|
+
baseUrl: typeof c.baseUrl === 'string' ? c.baseUrl : ACPS_DISCOVERY_DEFAULTS.baseUrl,
|
|
183
|
+
timeout: Number.isFinite(Number(c.timeout)) && Number(c.timeout) > 0
|
|
184
|
+
? Number(c.timeout)
|
|
185
|
+
: ACPS_DISCOVERY_DEFAULTS.timeout,
|
|
186
|
+
limit: Number.isFinite(Number(c.limit)) && Number(c.limit) >= 1
|
|
187
|
+
? Math.floor(Number(c.limit))
|
|
188
|
+
: ACPS_DISCOVERY_DEFAULTS.limit,
|
|
189
|
+
scope,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// ── config.acps.bridge:内部 ACPs 桥接(lib/comms/acps-bridge.js,进程内双向)──
|
|
193
|
+
// 桥只经 mailbox.js 公共接口投递/投影,绝不绕过;enabled=false 时不加载不实例化(零路径)。
|
|
194
|
+
// inbound 默认关:外部 ACPs 消息写 mailbox 需显式开启。
|
|
195
|
+
// as const:mode 字面量派生返回类型('inprocess'|'http'),纯类型层、运行期等价。
|
|
196
|
+
export const BRIDGE_DEFAULTS = Object.freeze({
|
|
197
|
+
enabled: false,
|
|
198
|
+
mode: 'inprocess', // 进程内双向(本机 HTTP 桥不实现)
|
|
199
|
+
inbound: false, // inbound 默认关:外部 ACPs 消息写 mailbox 需显式开启
|
|
200
|
+
});
|
|
201
|
+
export function resolveBridgeConfig(config) {
|
|
202
|
+
const c = config?.acps?.bridge ?? {};
|
|
203
|
+
return {
|
|
204
|
+
enabled: c.enabled === true,
|
|
205
|
+
mode: c.mode === 'http' ? 'http' : BRIDGE_DEFAULTS.mode,
|
|
206
|
+
inbound: c.inbound === true,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// ── config.acps:ACPs 通讯能力 ──
|
|
210
|
+
// 默认关(acps.enabled 与 acps.endpoint.enabled 均默认 false——显式开启才加载监听,关闭时零运行时路径)。
|
|
211
|
+
// endpoint:对外 mTLS 服务端点(lib/acps/server.js)——
|
|
212
|
+
// port 9443;host 默认 127.0.0.1(config 可配);
|
|
213
|
+
// cert/key/ca:三路径(null=自动生成到 certDir,默认 <root>/acps/certs);aic:ACS 身份码
|
|
214
|
+
// (缺省=agent-descriptor 派生占位,注册后经 config 覆盖);minVersion TLSv1.3;
|
|
215
|
+
// devInsecure:显式开发开关(默认 false,生产不允许降级)。
|
|
216
|
+
// 消费方:lib/index.js 装配(enabled 双真才实例化 createAcpsServer);lib/assembly/schema.js CAPABILITY_REGISTRY。
|
|
217
|
+
// as const:minVersion 字面量派生返回类型('TLSv1.2'|'TLSv1.3'),纯类型层、运行期等价。
|
|
218
|
+
export const ACPS_DEFAULTS = Object.freeze({
|
|
219
|
+
enabled: false, // 能力总开关(默认关)
|
|
220
|
+
endpoint: {
|
|
221
|
+
enabled: false, // 对外端点开关(默认关)
|
|
222
|
+
port: 9443, // 对外监听端口
|
|
223
|
+
host: '127.0.0.1',
|
|
224
|
+
cert: null, // 三路径(null=自动生成 certDir)
|
|
225
|
+
key: null,
|
|
226
|
+
ca: null,
|
|
227
|
+
certDir: null, // 缺省 <root>/acps/certs(index.js 注入 root)
|
|
228
|
+
aic: null, // ACS aic(缺省=agent-descriptor 派生占位)
|
|
229
|
+
agentName: 'dsh-punky-swarm',
|
|
230
|
+
minVersion: 'TLSv1.3', // TLS 最低版本
|
|
231
|
+
devInsecure: false, // 开发模式开关(默认关)
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
export function resolveAcpsConfig(config) {
|
|
235
|
+
const c = config?.acps ?? {};
|
|
236
|
+
const e = (c.endpoint && typeof c.endpoint === 'object' && !Array.isArray(c.endpoint)) ? c.endpoint : {};
|
|
237
|
+
return {
|
|
238
|
+
enabled: c.enabled === true,
|
|
239
|
+
endpoint: {
|
|
240
|
+
enabled: e.enabled === true,
|
|
241
|
+
port: Number.isInteger(Number(e.port)) && Number(e.port) > 0 ? Number(e.port) : ACPS_DEFAULTS.endpoint.port,
|
|
242
|
+
host: typeof e.host === 'string' && e.host.length > 0 ? e.host : ACPS_DEFAULTS.endpoint.host,
|
|
243
|
+
cert: typeof e.cert === 'string' && e.cert.length > 0 ? e.cert : null,
|
|
244
|
+
key: typeof e.key === 'string' && e.key.length > 0 ? e.key : null,
|
|
245
|
+
ca: typeof e.ca === 'string' && e.ca.length > 0 ? e.ca : null,
|
|
246
|
+
certDir: typeof e.certDir === 'string' && e.certDir.length > 0 ? e.certDir : null,
|
|
247
|
+
aic: typeof e.aic === 'string' && e.aic.length > 0 ? e.aic : null,
|
|
248
|
+
agentName: typeof e.agentName === 'string' && e.agentName.length > 0 ? e.agentName : ACPS_DEFAULTS.endpoint.agentName,
|
|
249
|
+
// 单点断言:双条件命中即 e.minVersion 必为二值之一(运行期比较语义不变,断言仅类型层)
|
|
250
|
+
minVersion: e.minVersion === 'TLSv1.2' || e.minVersion === 'TLSv1.3' ? e.minVersion : ACPS_DEFAULTS.endpoint.minVersion,
|
|
251
|
+
devInsecure: e.devInsecure === true,
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
// ── config.ratchet:棘轮规则表配置键(可选;缺省 = 默认规则 = 本文件 MEMBER_TRANSITIONS/BATCH_TRANSITIONS,零运行时开销)──
|
|
256
|
+
// 消费方 lib/state/machine-rules.ts(loadRules):
|
|
257
|
+
// { ratchet: { memberRules?: { from: [to...] }, batchRules?: { from: [to...] }, allowRelax?: false } }
|
|
258
|
+
// 棘轮语义:配置覆盖只许删(收紧)不许增(放宽)——覆盖表出现本文件默认表不存在的迁移 → loadRules throw(fail-closed);
|
|
259
|
+
// allowRelax: true 为显式逃生门(默认 false,仅在部署侧明确授权时可用,不推荐)。
|