dsh-subagent-profile 0.3.4 → 0.4.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/README.md +1 -0
- package/README.zh.md +1 -0
- package/index.mjs +14 -5
- package/lib/client.js +948 -170
- package/lib/core/delegation.mjs +3 -2
- package/lib/core/evolution-advice.mjs +125 -26
- package/lib/core/evolution-assets.mjs +167 -0
- package/lib/core/evolution-draft.mjs +312 -0
- package/lib/core/evolution-engine.mjs +269 -0
- package/lib/core/evolution-generate.mjs +196 -0
- package/lib/core/evolution-ledger.mjs +131 -26
- package/lib/core/evolution-persistence.mjs +213 -0
- package/lib/core/evolution-renewal.mjs +64 -0
- package/lib/core/evolution-routes.mjs +109 -0
- package/lib/core/http-helpers.mjs +35 -0
- package/lib/core/http-routes.mjs +21 -36
- package/lib/core/profile-provider.mjs +2 -1
- package/lib/core/profiles-store.mjs +23 -5
- package/lib/core/session-read.mjs +17 -0
- package/lib/core/shims.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
|
|
7
7
|
<img alt="npm" src="https://img.shields.io/npm/v/dsh-subagent-profile.svg" />
|
|
8
8
|
<img alt="DSH" src="https://img.shields.io/badge/DSH-0.1.0--rc.6%20~%200.2.0-blue.svg" />
|
|
9
|
+
<img alt="awesome · DSH plugin" src="https://awesome-dsh-plugin.com/badge.svg" />
|
|
9
10
|
</div>
|
|
10
11
|
|
|
11
12
|
<div align="center">English · <a href="README.zh.md">中文</a></div>
|
package/README.zh.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
|
|
7
7
|
<img alt="npm" src="https://img.shields.io/npm/v/dsh-subagent-profile.svg" />
|
|
8
8
|
<img alt="DSH" src="https://img.shields.io/badge/DSH-0.1.0--rc.6%20~%200.2.0-blue.svg" />
|
|
9
|
+
<img alt="awesome · DSH plugin" src="https://awesome-dsh-plugin.com/badge.svg" />
|
|
9
10
|
</div>
|
|
10
11
|
|
|
11
12
|
<div align="center"><a href="README.md">English</a> · 中文</div>
|
package/index.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import { createEscapeStore, recordEscapeAllowProvider } from './lib/core/escape.
|
|
|
24
24
|
import { resolveWhitelist, FALLBACK_WHITELIST } from './lib/core/whitelist.mjs';
|
|
25
25
|
import { profileDirectoryRows, profileStatsFromSummaries, applyProfileStats } from './lib/core/profile-directory.mjs';
|
|
26
26
|
import { buildAdviceText, refreshSummaries, readSummaries } from './lib/core/evolution-advice.mjs';
|
|
27
|
+
import { createEvolutionAssembly } from './lib/core/evolution-engine.mjs';
|
|
27
28
|
|
|
28
29
|
export const name = 'dsh-subagent-profile';
|
|
29
30
|
export const inject = ['subagents', 'tools', 'agents'];
|
|
@@ -198,6 +199,13 @@ async function resolveAdviceWhitelist(ctx) {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
|
|
202
|
+
async function setupEvolution(ctx, home, store, catalog, evoLedger, getEvolutionAdvice) {
|
|
203
|
+
const adviceWhitelist = await resolveAdviceWhitelist(ctx);
|
|
204
|
+
const adviceEnv = { summariesFile: join(home, 'subagent-evolution', 'summaries.json'), dispatchFile: join(home, 'subagent-evolution', 'dispatch.jsonl'), whitelist: adviceWhitelist, logger: ctx.logger, onLoss: () => evoLedger.markMigrationLoss() };
|
|
205
|
+
const { adviceSource, evolution } = createEvolutionAssembly({ ctx, home, store, catalog, evoLedger, adviceWhitelist, getEvolutionAdvice, pluginVersion: readPluginVersion() });
|
|
206
|
+
return { adviceEnv, adviceSource, evolution };
|
|
207
|
+
}
|
|
208
|
+
|
|
201
209
|
// 系统提示各 section:门控经 sectionGatePasses;`enabled` 经 getter 实时读取。
|
|
202
210
|
function registerSystemPromptSections(ctx, store, getEnabled, getEvolutionAdvice, adviceEnv, guard) {
|
|
203
211
|
const pluginSystemPrompt = ctx.get('systemPrompt');
|
|
@@ -208,7 +216,7 @@ function registerSystemPromptSections(ctx, store, getEnabled, getEvolutionAdvice
|
|
|
208
216
|
order: 116.5,
|
|
209
217
|
text: (context) => {
|
|
210
218
|
let summaries = null;
|
|
211
|
-
try { summaries = readSummaries(adviceEnv.summariesFile, adviceEnv.logger); } catch { /* 统计只增强,不影响目录注入 */ }
|
|
219
|
+
try { summaries = readSummaries(adviceEnv.summariesFile, adviceEnv.logger, { onLoss: adviceEnv.onLoss }); } catch { /* 统计只增强,不影响目录注入 */ }
|
|
212
220
|
return profileSectionText(store, gate, context, summaries);
|
|
213
221
|
},
|
|
214
222
|
});
|
|
@@ -255,7 +263,7 @@ function registerSystemPromptSections(ctx, store, getEnabled, getEvolutionAdvice
|
|
|
255
263
|
// webServer 可选——无头部署保留 dispatch 工具、只丢设置页。webServer 的激活
|
|
256
264
|
// (listen)是异步的,可能晚于本插件 inject 依赖解析完成,故在等它的 inject
|
|
257
265
|
// 子 scope 内注册(apply 时 ctx.get 会读到 undefined)。
|
|
258
|
-
function registerSettingsRoutes(ctx, store, getEnabled, setEnabled, syncTool, catalog, ledger, backgroundLedger, draftsStore, applyDraft, getAudit, getEvolutionAdvice, setEvolutionAdvice, getEscapeEnabled, setEscapeEnabled, escape, refreshAdvice, summariesFile, dispatchFile, adviceWhitelist, previewDraft, reminderStore) {
|
|
266
|
+
function registerSettingsRoutes(ctx, store, getEnabled, setEnabled, syncTool, catalog, ledger, backgroundLedger, draftsStore, applyDraft, getAudit, getEvolutionAdvice, setEvolutionAdvice, getEscapeEnabled, setEscapeEnabled, escape, refreshAdvice, summariesFile, dispatchFile, adviceWhitelist, previewDraft, reminderStore, adviceSource, evolution) {
|
|
259
267
|
ctx.inject(['webServer'], (scope) => {
|
|
260
268
|
scope.effect(createHttpRoutes({
|
|
261
269
|
webServer: scope.webServer,
|
|
@@ -280,6 +288,8 @@ function registerSettingsRoutes(ctx, store, getEnabled, setEnabled, syncTool, ca
|
|
|
280
288
|
adviceWhitelist,
|
|
281
289
|
previewDraft,
|
|
282
290
|
reminderStore,
|
|
291
|
+
adviceSource,
|
|
292
|
+
evolution,
|
|
283
293
|
logger: ctx.logger,
|
|
284
294
|
}), 'dsh-subagent-profile: settings routes');
|
|
285
295
|
});
|
|
@@ -384,8 +394,7 @@ export async function apply(ctx) {
|
|
|
384
394
|
const adoptionTracker = setupAdoptionTracker(ctx, home, () => refreshAdvice, (rec) => mintUnadoptedReminder(reminderStore, evoLedger, rec));
|
|
385
395
|
const dispatch = createDispatch(ctx, store, catalog, ledger, guard, evoLedger, backgroundLedger, adoptionTracker, escapeCtl.getEscapeSet, () => enabled, () => evolutionAdvice);
|
|
386
396
|
provideProfileService(ctx, store);
|
|
387
|
-
const
|
|
388
|
-
const adviceEnv = { summariesFile: join(home, 'subagent-evolution', 'summaries.json'), dispatchFile: join(home, 'subagent-evolution', 'dispatch.jsonl'), whitelist: adviceWhitelist, logger: ctx.logger };
|
|
397
|
+
const { adviceEnv, adviceSource, evolution } = await setupEvolution(ctx, home, store, catalog, evoLedger, () => evolutionAdvice);
|
|
389
398
|
// 生产聚合触发点(T1 修复):/options/refresh 与 /list 触发的惰性重算;parent_adopted
|
|
390
399
|
// 的「已确认未采纳」计数经 opts 惰性 join 进 weighted_success(-0.3 惩罚)。
|
|
391
400
|
refreshAdvice = () => refreshSummaries({ dispatchFile: adviceEnv.dispatchFile, summariesFile: adviceEnv.summariesFile, logger: ctx.logger, opts: { parentAdoptedConfirmedFalse: adoptionTracker.confirmedFalseCounts() } });
|
|
@@ -407,6 +416,6 @@ export async function apply(ctx) {
|
|
|
407
416
|
},
|
|
408
417
|
});
|
|
409
418
|
// Client 设置 UI 的 HTTP loopback 路由 —— lib/core/http-routes.mjs。
|
|
410
|
-
registerSettingsRoutes(ctx, store, () => enabled, (next) => { enabled = next; }, dispatch.syncTool, catalog, ledger, backgroundLedger, draftsStore, applyDraft, () => evoLedger.auditState(), () => evolutionAdvice, (next) => { evolutionAdvice = next; }, escapeCtl.getEscapeEnabled, escapeCtl.setEscapeEnabled, escapeCtl.escape, refreshAdvice, join(home, 'subagent-evolution', 'summaries.json'), adviceEnv.dispatchFile, adviceEnv.whitelist, previewDraft, reminderStore);
|
|
419
|
+
registerSettingsRoutes(ctx, store, () => enabled, (next) => { enabled = next; }, dispatch.syncTool, catalog, ledger, backgroundLedger, draftsStore, applyDraft, () => evoLedger.auditState(), () => evolutionAdvice, (next) => { evolutionAdvice = next; }, escapeCtl.getEscapeEnabled, escapeCtl.setEscapeEnabled, escapeCtl.escape, refreshAdvice, join(home, 'subagent-evolution', 'summaries.json'), adviceEnv.dispatchFile, adviceEnv.whitelist, previewDraft, reminderStore, adviceSource, evolution);
|
|
411
420
|
registerTeardown(ctx, dispatch, ledger, guard, home, backgroundLedger, adoptionTracker);
|
|
412
421
|
}
|