@octopi-agent/engine 0.98.4 → 0.102.10
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-schema/agent.d.ts +35 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +57 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +8 -1
- package/dist/config-schema/governance.js +8 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +24 -3
- package/dist/harness/agent/builder.js +131 -27
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +26 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +3 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +3 -6
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +14 -15
- package/dist/harness/context/layers.js +41 -11
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +9 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +2 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +6 -4
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +37 -4
- package/dist/harness/run/runner.d.ts +44 -29
- package/dist/harness/run/runner.js +320 -102
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +1 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/package.json +11 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -206,7 +206,7 @@ export interface WisdomEntry {
|
|
|
206
206
|
updatedAt: number;
|
|
207
207
|
}
|
|
208
208
|
/** 出生门控 reason */
|
|
209
|
-
export type WisdomGateReason = 'ok' | 'empty_statement' | 'statement_too_long' | 'empty_problem_types' | 'empty_effect' | 'secret_like' | 'persona_overwrite' | 'insufficient_support' | 'duplicate_statement' | 'semantic_conflict' | 'capacity_admit_stop' | 'invalid_status' | 'invalid_origin' | 'invalid_kind' | 'missing_derived_from' | 'unknown_derived_id' | 'supersedes_target_missing';
|
|
209
|
+
export type WisdomGateReason = 'ok' | 'empty_statement' | 'statement_too_long' | 'empty_problem_types' | 'empty_effect' | 'secret_like' | 'persona_overwrite' | 'insufficient_support' | 'duplicate_statement' | 'semantic_conflict' | 'capacity_admit_stop' | 'invalid_status' | 'invalid_origin' | 'invalid_kind' | 'missing_derived_from' | 'unknown_derived_id' | 'supersedes_target_missing' | 'supersedes_target_invalid';
|
|
210
210
|
export interface WisdomGateOutcome {
|
|
211
211
|
ok: boolean;
|
|
212
212
|
reason: WisdomGateReason;
|
|
@@ -244,14 +244,16 @@ export interface WisdomInjectQuery {
|
|
|
244
244
|
coreMaxItems?: number;
|
|
245
245
|
/** 场景条数硬顶 */
|
|
246
246
|
scenarioMaxItems?: number;
|
|
247
|
+
/** trial 轮转试用名额硬顶(默认 2——保证 trial 有机会积累 applied 以晋升;0 关闭轮转) */
|
|
248
|
+
trialMaxItems?: number;
|
|
247
249
|
/** 是否包含 trial(默认 true——trial 的意义就是被试用;显式 false 只注入已站稳条目) */
|
|
248
250
|
includeTrial?: boolean;
|
|
249
251
|
}
|
|
250
252
|
export interface WisdomInjectPick {
|
|
251
253
|
entry: WisdomEntry;
|
|
252
|
-
/** core = 常备小核心;scenario =
|
|
253
|
-
bucket: 'core' | 'scenario';
|
|
254
|
-
/** 场景匹配分(core 为 1) */
|
|
254
|
+
/** core = 常备小核心;scenario = 本轮匹配;trial = 轮转试用名额 */
|
|
255
|
+
bucket: 'core' | 'scenario' | 'trial';
|
|
256
|
+
/** 场景匹配分(core 为 1;trial 轮转为场景分,可为 0) */
|
|
255
257
|
score: number;
|
|
256
258
|
}
|
|
257
259
|
export type WisdomOutcomeSignal = 'applied' | 'cited' | 'assisted' | 'contested' | 'ignored';
|
|
@@ -24,6 +24,8 @@ export interface ParsedWisdomItem {
|
|
|
24
24
|
conceptIds?: string[];
|
|
25
25
|
exceptions?: string[];
|
|
26
26
|
kind: WisdomKind;
|
|
27
|
+
/** 取代已有范式(LLM 对照库内已有范式后给出;指向被取代条目 id) */
|
|
28
|
+
supersedesId?: string;
|
|
27
29
|
}
|
|
28
30
|
export interface ParsedWisdomFormation {
|
|
29
31
|
items: ParsedWisdomItem[];
|
|
@@ -72,15 +74,23 @@ export declare function formAndAdmit(llmText: string, store: WisdomStore, option
|
|
|
72
74
|
droppedNotes: string[];
|
|
73
75
|
}>;
|
|
74
76
|
/**
|
|
75
|
-
* 关键词/字面场景匹配分 +
|
|
77
|
+
* 关键词/字面场景匹配分 + 全字面命中标记 + anti 排除标记。
|
|
78
|
+
*
|
|
79
|
+
* 匹配单位是**分段**(长描述句切短语后逐段匹配):任一段全字面命中记 2 分,
|
|
80
|
+
* 仅 2-gram 弱重叠记 1 分。fullHit = 存在长度 ≥3 的分段全字面命中——
|
|
81
|
+
* trial 的 scenario 入场券只认 fullHit(弱重叠不算,2 字通用词也不够格)。
|
|
82
|
+
*
|
|
83
|
+
* antiScenarios 是排除条件(误触发会静默丢范式),要求更强证据才触发:
|
|
84
|
+
* 整串命中,或长度 ≥3 的分段命中(2 字碎片歧义大,如「越权」不应压制修越权 bug 的任务)。
|
|
76
85
|
*
|
|
77
86
|
* @param entry - 条目
|
|
78
87
|
* @param text - 本轮查询/任务文本
|
|
79
|
-
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals
|
|
88
|
+
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals ≥3 字分段全字面命中;excluded=anti 命中
|
|
80
89
|
*/
|
|
81
90
|
export declare function scenarioMatchDetail(entry: WisdomEntry, text: string): {
|
|
82
91
|
score: number;
|
|
83
92
|
fullHit: boolean;
|
|
93
|
+
excluded: boolean;
|
|
84
94
|
};
|
|
85
95
|
/**
|
|
86
96
|
* 关键词/字面场景匹配分。
|
|
@@ -103,12 +113,13 @@ export declare function isCoreEligible(entry: Pick<WisdomEntry, 'status' | 'orig
|
|
|
103
113
|
*
|
|
104
114
|
* @param entries - 可注入条目(store 已滤状态)
|
|
105
115
|
* @param text - 本轮文本
|
|
106
|
-
* @param options - 条数硬顶;includeTrial 缺省 true(trial 的意义就是被试用)
|
|
116
|
+
* @param options - 条数硬顶;trialMaxItems 缺省 2(trial 轮转保底曝光,打破晋升死锁);includeTrial 缺省 true(trial 的意义就是被试用)
|
|
107
117
|
* @returns 排序后的注入选择
|
|
108
118
|
*/
|
|
109
119
|
export declare function pickForInjection(entries: WisdomEntry[], text: string, options?: {
|
|
110
120
|
coreMaxItems?: number;
|
|
111
121
|
scenarioMaxItems?: number;
|
|
122
|
+
trialMaxItems?: number;
|
|
112
123
|
includeTrial?: boolean;
|
|
113
124
|
}): WisdomInjectPick[];
|
|
114
125
|
/**
|
|
@@ -79,6 +79,7 @@ export function normalizeWisdomFormation(raw) {
|
|
|
79
79
|
const memoryIds = asStringArray(derived.memoryIds ?? o.memoryIds);
|
|
80
80
|
const conceptIds = asStringArray(derived.conceptIds ?? o.conceptIds);
|
|
81
81
|
const kind = parseKind(o.kind);
|
|
82
|
+
const supersedesId = asString(o.supersedesId) || undefined;
|
|
82
83
|
if (!statement || pts.length === 0) {
|
|
83
84
|
droppedNotes.push(`incomplete:${statement.slice(0, 24) || 'empty'}`);
|
|
84
85
|
continue;
|
|
@@ -87,7 +88,7 @@ export function normalizeWisdomFormation(raw) {
|
|
|
87
88
|
droppedNotes.push(`no_effect:${statement.slice(0, 24)}`);
|
|
88
89
|
continue;
|
|
89
90
|
}
|
|
90
|
-
if (memoryIds.length === 0 && conceptIds.length === 0) {
|
|
91
|
+
if (memoryIds.length === 0 && conceptIds.length === 0 && !supersedesId) {
|
|
91
92
|
droppedNotes.push(`no_derived:${statement.slice(0, 24)}`);
|
|
92
93
|
continue;
|
|
93
94
|
}
|
|
@@ -110,6 +111,7 @@ export function normalizeWisdomFormation(raw) {
|
|
|
110
111
|
? asStringArray(o.exceptions)
|
|
111
112
|
: undefined,
|
|
112
113
|
kind,
|
|
114
|
+
supersedesId,
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
return { items, droppedNotes };
|
|
@@ -163,42 +165,84 @@ export async function formAndAdmit(llmText, store, options) {
|
|
|
163
165
|
}
|
|
164
166
|
const { items, droppedNotes } = normalizeWisdomFormation(raw);
|
|
165
167
|
const maxItems = options?.maxItems ?? 3;
|
|
168
|
+
// M4:dryRun 与真实 admit 的查重口径一致(全部存活条目参与 duplicate/near-dup/对立)
|
|
169
|
+
const existing = options?.dryRun
|
|
170
|
+
? (await store.listForGovern()).filter((w) => w.status !== 'retired' && w.status !== 'superseded')
|
|
171
|
+
: undefined;
|
|
166
172
|
const results = [];
|
|
167
173
|
for (const item of items.slice(0, maxItems)) {
|
|
168
|
-
|
|
174
|
+
let allowedIds = options?.allowedMemoryIds;
|
|
175
|
+
if (item.supersedesId) {
|
|
176
|
+
// supersede 继承被取代者的溯源:已覆盖语料被排除出证据包后,「同源精炼」
|
|
177
|
+
// 的自然溯源不在白名单里——并入目标 derivedFrom,取代主路径才通
|
|
178
|
+
const target = await store.get(item.supersedesId);
|
|
179
|
+
const inherited = target?.derivedFrom?.memoryIds ?? [];
|
|
180
|
+
if (!item.memoryIds.length && inherited.length) {
|
|
181
|
+
item.memoryIds = [...inherited];
|
|
182
|
+
}
|
|
183
|
+
if (options?.allowedMemoryIds && inherited.length) {
|
|
184
|
+
allowedIds = new Set([...options.allowedMemoryIds, ...inherited]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const input = toAdmitWisdomInput(item, {
|
|
188
|
+
origin: options?.origin,
|
|
189
|
+
supersedesId: item.supersedesId,
|
|
190
|
+
});
|
|
169
191
|
if (options?.dryRun) {
|
|
170
192
|
const gate = evaluateWisdomGate(input, {
|
|
171
|
-
allowedMemoryIds:
|
|
193
|
+
allowedMemoryIds: allowedIds,
|
|
194
|
+
existing,
|
|
172
195
|
});
|
|
173
196
|
results.push(gate.ok
|
|
174
197
|
? { action: 'created', message: 'dry_run' }
|
|
175
198
|
: { action: 'rejected', reason: gate.reason, message: gate.message });
|
|
176
199
|
continue;
|
|
177
200
|
}
|
|
178
|
-
results.push(await store.admit(input, { allowedMemoryIds:
|
|
201
|
+
results.push(await store.admit(input, { allowedMemoryIds: allowedIds }));
|
|
179
202
|
}
|
|
180
203
|
return { results, droppedNotes };
|
|
181
204
|
}
|
|
182
205
|
// ── 场景匹配(P0 keyword;embedding/llm 留给后续,不假装已实现) ──
|
|
206
|
+
/** 场景词分段:按空白/标点/符号(含 。.!?-_ 等)切碎成长描述句的短语碎片(≥2 字),使「任务快照」「system」等片段可独立命中。 */
|
|
207
|
+
function segmentScenarioWord(w) {
|
|
208
|
+
return w
|
|
209
|
+
.split(/[\s\p{P}\p{S}\\]+/u)
|
|
210
|
+
.map((s) => s.trim())
|
|
211
|
+
.filter((s) => s.length >= 2);
|
|
212
|
+
}
|
|
183
213
|
/**
|
|
184
|
-
* 关键词/字面场景匹配分 +
|
|
214
|
+
* 关键词/字面场景匹配分 + 全字面命中标记 + anti 排除标记。
|
|
215
|
+
*
|
|
216
|
+
* 匹配单位是**分段**(长描述句切短语后逐段匹配):任一段全字面命中记 2 分,
|
|
217
|
+
* 仅 2-gram 弱重叠记 1 分。fullHit = 存在长度 ≥3 的分段全字面命中——
|
|
218
|
+
* trial 的 scenario 入场券只认 fullHit(弱重叠不算,2 字通用词也不够格)。
|
|
219
|
+
*
|
|
220
|
+
* antiScenarios 是排除条件(误触发会静默丢范式),要求更强证据才触发:
|
|
221
|
+
* 整串命中,或长度 ≥3 的分段命中(2 字碎片歧义大,如「越权」不应压制修越权 bug 的任务)。
|
|
185
222
|
*
|
|
186
223
|
* @param entry - 条目
|
|
187
224
|
* @param text - 本轮查询/任务文本
|
|
188
|
-
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals
|
|
225
|
+
* @returns score∈[0,1](无命中为 0);fullHit=problemTypes/signals ≥3 字分段全字面命中;excluded=anti 命中
|
|
189
226
|
*/
|
|
190
227
|
export function scenarioMatchDetail(entry, text) {
|
|
191
228
|
const q = text.toLowerCase();
|
|
192
229
|
if (!q.trim())
|
|
193
|
-
return { score: 0, fullHit: false };
|
|
230
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
194
231
|
const anti = (entry.scenario.antiScenarios ?? []).map((s) => s.toLowerCase());
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
232
|
+
for (const a of anti) {
|
|
233
|
+
if (!a)
|
|
234
|
+
continue;
|
|
235
|
+
if (q.includes(a))
|
|
236
|
+
return { score: 0, fullHit: false, excluded: true };
|
|
237
|
+
if (segmentScenarioWord(a).some((seg) => seg.length >= 3 && q.includes(seg))) {
|
|
238
|
+
return { score: 0, fullHit: false, excluded: true };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const words = entry.scenario.problemTypes
|
|
242
|
+
.concat(entry.scenario.signals ?? [])
|
|
243
|
+
.flatMap((w) => segmentScenarioWord(w.toLowerCase()));
|
|
200
244
|
if (words.length === 0)
|
|
201
|
-
return { score: 0, fullHit: false };
|
|
245
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
202
246
|
let hit = 0;
|
|
203
247
|
let fullHit = false;
|
|
204
248
|
for (const w of words) {
|
|
@@ -206,14 +250,15 @@ export function scenarioMatchDetail(entry, text) {
|
|
|
206
250
|
continue;
|
|
207
251
|
if (q.includes(w)) {
|
|
208
252
|
hit += 2;
|
|
209
|
-
|
|
253
|
+
if (w.length >= 3)
|
|
254
|
+
fullHit = true;
|
|
210
255
|
}
|
|
211
256
|
else if (overlapChars(q, w))
|
|
212
257
|
hit += 1;
|
|
213
258
|
}
|
|
214
259
|
if (hit === 0)
|
|
215
|
-
return { score: 0, fullHit: false };
|
|
216
|
-
return { score: Math.min(1, hit / (words.length * 2)), fullHit };
|
|
260
|
+
return { score: 0, fullHit: false, excluded: false };
|
|
261
|
+
return { score: Math.min(1, hit / (words.length * 2)), fullHit, excluded: false };
|
|
217
262
|
}
|
|
218
263
|
/**
|
|
219
264
|
* 关键词/字面场景匹配分。
|
|
@@ -255,12 +300,13 @@ export function isCoreEligible(entry) {
|
|
|
255
300
|
*
|
|
256
301
|
* @param entries - 可注入条目(store 已滤状态)
|
|
257
302
|
* @param text - 本轮文本
|
|
258
|
-
* @param options - 条数硬顶;includeTrial 缺省 true(trial 的意义就是被试用)
|
|
303
|
+
* @param options - 条数硬顶;trialMaxItems 缺省 2(trial 轮转保底曝光,打破晋升死锁);includeTrial 缺省 true(trial 的意义就是被试用)
|
|
259
304
|
* @returns 排序后的注入选择
|
|
260
305
|
*/
|
|
261
306
|
export function pickForInjection(entries, text, options) {
|
|
262
307
|
const coreMax = options?.coreMaxItems ?? 8;
|
|
263
308
|
const scenarioMax = options?.scenarioMaxItems ?? 8;
|
|
309
|
+
const trialMax = options?.trialMaxItems ?? 2;
|
|
264
310
|
const includeTrial = options?.includeTrial ?? true;
|
|
265
311
|
const usable = entries.filter((e) => {
|
|
266
312
|
if (e.status === 'retired' || e.status === 'superseded' || e.status === 'candidate')
|
|
@@ -277,6 +323,7 @@ export function pickForInjection(entries, text, options) {
|
|
|
277
323
|
entry: e,
|
|
278
324
|
match: m.score,
|
|
279
325
|
fullHit: m.fullHit,
|
|
326
|
+
excluded: m.excluded,
|
|
280
327
|
score: wisdomInjectScore(e, 1),
|
|
281
328
|
scenarioScore: wisdomInjectScore(e, m.score),
|
|
282
329
|
};
|
|
@@ -295,7 +342,21 @@ export function pickForInjection(entries, text, options) {
|
|
|
295
342
|
.sort((a, b) => b.scenarioScore - a.scenarioScore)
|
|
296
343
|
.slice(0, scenarioMax)
|
|
297
344
|
.map((s) => ({ entry: s.entry, bucket: 'scenario', score: s.match }));
|
|
298
|
-
|
|
345
|
+
// trial 轮转试用名额:trial 进不了 core、scenario 又只有全字面命中一张入场券,
|
|
346
|
+
// 没有保底曝光就攒不出场景命中、永不晋升(trial→active 需 applied≥3+assisted)。
|
|
347
|
+
// 轮转规则:最少被试用者优先(applied 升序),同分旧者先出(createdAt 升序),逐轮清队列。
|
|
348
|
+
// anti 命中的条目不轮转(范式自陈不适用的任务不硬塞);轮转注入不计 applied
|
|
349
|
+
//(applied 语义保持「场景命中被使用」,防曝光污染 contest/zero-apply 治理)。
|
|
350
|
+
const pickedIds = new Set([...coreIds, ...scenario.map((s) => s.entry.id)]);
|
|
351
|
+
const trialRotation = trialMax > 0
|
|
352
|
+
? scored
|
|
353
|
+
.filter((s) => s.entry.status === 'trial' && !pickedIds.has(s.entry.id) && !s.excluded)
|
|
354
|
+
.sort((a, b) => a.entry.outcomes.applied - b.entry.outcomes.applied ||
|
|
355
|
+
a.entry.createdAt - b.entry.createdAt)
|
|
356
|
+
.slice(0, trialMax)
|
|
357
|
+
.map((s) => ({ entry: s.entry, bucket: 'trial', score: s.match }))
|
|
358
|
+
: [];
|
|
359
|
+
return [...coreCandidates, ...scenario, ...trialRotation];
|
|
299
360
|
}
|
|
300
361
|
// ── 注入排版 ──
|
|
301
362
|
/**
|
|
@@ -311,19 +372,21 @@ export function formatWisdomBody(picks) {
|
|
|
311
372
|
for (const p of picks) {
|
|
312
373
|
const key = p.entry.scenario.problemTypes[0] ?? '通用';
|
|
313
374
|
const list = byType.get(key) ?? [];
|
|
314
|
-
list.push(p.entry);
|
|
375
|
+
list.push({ entry: p.entry, bucket: p.bucket });
|
|
315
376
|
byType.set(key, list);
|
|
316
377
|
}
|
|
317
378
|
const blocks = [];
|
|
318
379
|
blocks.push('> 归因:若某条范式实质影响了你的决策,可在回复中引用其 id(如 [wis_xxx])以便事后验证。');
|
|
319
380
|
for (const [type, list] of byType) {
|
|
320
|
-
const lines = list.map((e) => formatWisdomBullet(e));
|
|
381
|
+
const lines = list.map((e) => formatWisdomBullet(e.entry, e.bucket));
|
|
321
382
|
blocks.push(`## 面对「${type}」\n\n${lines.join('\n\n')}`);
|
|
322
383
|
}
|
|
323
384
|
return blocks.join('\n\n');
|
|
324
385
|
}
|
|
325
|
-
function formatWisdomBullet(e) {
|
|
326
|
-
|
|
386
|
+
function formatWisdomBullet(e, bucket) {
|
|
387
|
+
// trial 轮转注入的条目未经场景验证,显式标记供模型降权采信
|
|
388
|
+
const marker = bucket === 'trial' ? '[试用] ' : '';
|
|
389
|
+
const parts = [`- ${marker}[${e.id}] ${e.statement}`];
|
|
327
390
|
const effectBits = [];
|
|
328
391
|
if (e.effect.posture)
|
|
329
392
|
effectBits.push(`推理姿态:${e.effect.posture}`);
|
|
@@ -40,6 +40,20 @@ export declare function resolveInitialWisdomStatus(input: AdmitWisdomInput): Wis
|
|
|
40
40
|
* @returns 去标点空白的小写串
|
|
41
41
|
*/
|
|
42
42
|
export declare function normalizeStatement(s: string): string;
|
|
43
|
+
/** 近重复 bigram 相似度阈值(真实重复对标定:同主题对最高 0.38/中位 0.16,跨主题对最高 0.06) */
|
|
44
|
+
export declare const NEAR_DUPLICATE_RATIO = 0.3;
|
|
45
|
+
/**
|
|
46
|
+
* 近重复兜底:陈述文本 bigram 相似度 ≥ 阈值视为重度换词复述。
|
|
47
|
+
*
|
|
48
|
+
* 双方陈述都必须 ≥ NEAR_DUPLICATE_MIN_CHARS(短陈述公式化重叠不可判语义);
|
|
49
|
+
* 阈值取保守高位(0.30)——语义去重主责在 formation LLM,此启发宁可漏拦不可误杀。
|
|
50
|
+
*
|
|
51
|
+
* @param a - 新陈述
|
|
52
|
+
* @param b - 既有陈述
|
|
53
|
+
* @param threshold - 相似度阈值(缺省 NEAR_DUPLICATE_RATIO)
|
|
54
|
+
* @returns 是否疑似近重复
|
|
55
|
+
*/
|
|
56
|
+
export declare function looksNearDuplicate(a: string, b: string, threshold?: number): boolean;
|
|
43
57
|
/**
|
|
44
58
|
* 保守对立启发:同主题词重叠 + 互斥义务词。宁可漏拦,不可误杀。
|
|
45
59
|
*
|
|
@@ -110,24 +110,38 @@ export function evaluateWisdomGate(input, options) {
|
|
|
110
110
|
if (options?.existing?.length) {
|
|
111
111
|
const norm = normalizeStatement(statement);
|
|
112
112
|
for (const ex of options.existing) {
|
|
113
|
-
//
|
|
114
|
-
if (ex.status
|
|
113
|
+
// 已被取代/退役的条目不参与查重(继任者已接管其主题)
|
|
114
|
+
if (ex.status === 'superseded' || ex.status === 'retired')
|
|
115
115
|
continue;
|
|
116
116
|
const exNorm = normalizeStatement(ex.statement);
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
117
|
+
if (!input.supersedesId) {
|
|
118
|
+
// 查重覆盖全部存活条目(含 trial——distilled 出生即 trial,同主题重复的主战场)
|
|
119
|
+
if (exNorm === norm) {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
reason: 'duplicate_statement',
|
|
123
|
+
message: `dup_of=${ex.id}`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// 对立检测先于近重:同词面但义务互斥是矛盾而非重复(reason 要区分两种处置)。
|
|
127
|
+
// 维持只对已站稳的范式检测;trial 不因疑似对立挡新条(两条都未验证时留给试用裁决)。
|
|
128
|
+
if ((ex.status === 'active' || ex.status === 'strengthened') &&
|
|
129
|
+
looksOpposed(statement, ex.statement)) {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
reason: 'semantic_conflict',
|
|
133
|
+
message: `conflict_with=${ex.id}`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// 近重复兜底(bigram 相似度,阈值 0.30 经真实重复对标定:同主题最高 0.38、跨主题最高 0.06)。
|
|
137
|
+
// 语义去重主责在 formation LLM(证据包附库内范式清单),此处只拦重度换词复述。
|
|
138
|
+
if (looksNearDuplicate(statement, ex.statement)) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
reason: 'duplicate_statement',
|
|
142
|
+
message: `near_dup_of=${ex.id}`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
147
|
}
|
|
@@ -163,10 +177,36 @@ export function normalizeStatement(s) {
|
|
|
163
177
|
.trim();
|
|
164
178
|
}
|
|
165
179
|
const OPPOSITE_PAIRS = [
|
|
166
|
-
[/(必须|应该|应当)/, /(
|
|
167
|
-
[/(
|
|
168
|
-
[/(优先|先)/, /(
|
|
180
|
+
[/(必须|应该|应当)/, /(禁止|不得|不要|不应|不必|无需)/],
|
|
181
|
+
[/(禁止|不得|不要|不应|不必|无需)/, /(必须|应该|应当)/],
|
|
182
|
+
[/(优先|先)/, /(禁止|不得|不必)/],
|
|
169
183
|
];
|
|
184
|
+
/** 近重复 bigram 相似度阈值(真实重复对标定:同主题对最高 0.38/中位 0.16,跨主题对最高 0.06) */
|
|
185
|
+
export const NEAR_DUPLICATE_RATIO = 0.3;
|
|
186
|
+
/**
|
|
187
|
+
* 近重复 bigram 长度下限(归一化后的大约字符数)。
|
|
188
|
+
* 短陈述共享公式化开头(「先验证」「面对 X 时先问」)时相似度虚高(可达 1.0),
|
|
189
|
+
* 会误杀同模板不同判断的合法范式——短陈述只走字面全等查重。
|
|
190
|
+
*/
|
|
191
|
+
const NEAR_DUPLICATE_MIN_CHARS = 12;
|
|
192
|
+
/**
|
|
193
|
+
* 近重复兜底:陈述文本 bigram 相似度 ≥ 阈值视为重度换词复述。
|
|
194
|
+
*
|
|
195
|
+
* 双方陈述都必须 ≥ NEAR_DUPLICATE_MIN_CHARS(短陈述公式化重叠不可判语义);
|
|
196
|
+
* 阈值取保守高位(0.30)——语义去重主责在 formation LLM,此启发宁可漏拦不可误杀。
|
|
197
|
+
*
|
|
198
|
+
* @param a - 新陈述
|
|
199
|
+
* @param b - 既有陈述
|
|
200
|
+
* @param threshold - 相似度阈值(缺省 NEAR_DUPLICATE_RATIO)
|
|
201
|
+
* @returns 是否疑似近重复
|
|
202
|
+
*/
|
|
203
|
+
export function looksNearDuplicate(a, b, threshold = NEAR_DUPLICATE_RATIO) {
|
|
204
|
+
const na = normalizeStatement(a);
|
|
205
|
+
const nb = normalizeStatement(b);
|
|
206
|
+
if (na.length < NEAR_DUPLICATE_MIN_CHARS || nb.length < NEAR_DUPLICATE_MIN_CHARS)
|
|
207
|
+
return false;
|
|
208
|
+
return sharedBigramRatio(a, b) >= threshold;
|
|
209
|
+
}
|
|
170
210
|
/**
|
|
171
211
|
* 保守对立启发:同主题词重叠 + 互斥义务词。宁可漏拦,不可误杀。
|
|
172
212
|
*
|
|
@@ -35,6 +35,14 @@ export class InMemoryWisdomStore {
|
|
|
35
35
|
message: `supersedesId=${input.supersedesId}`,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
// 与 SqliteWisdomStore 同规:目标必须存活;factory 出厂预设不许炼制回路静默取代
|
|
39
|
+
if (prev.status === 'retired' || prev.status === 'superseded' || prev.origin === 'factory') {
|
|
40
|
+
return {
|
|
41
|
+
action: 'rejected',
|
|
42
|
+
reason: 'supersedes_target_invalid',
|
|
43
|
+
message: `supersedes_target=${prev.status}/${prev.origin}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
38
46
|
this.entries.set(prev.id, {
|
|
39
47
|
...prev,
|
|
40
48
|
status: 'superseded',
|
|
@@ -70,6 +78,7 @@ export class InMemoryWisdomStore {
|
|
|
70
78
|
return pickForInjection(entries, query.text ?? '', {
|
|
71
79
|
coreMaxItems: query.coreMaxItems,
|
|
72
80
|
scenarioMaxItems: query.scenarioMaxItems,
|
|
81
|
+
trialMaxItems: query.trialMaxItems,
|
|
73
82
|
includeTrial: query.includeTrial,
|
|
74
83
|
});
|
|
75
84
|
}
|
|
@@ -52,8 +52,8 @@ const TIMELINE_TYPES = new Set([
|
|
|
52
52
|
'engine.error',
|
|
53
53
|
// 模型重试:排查「为什么等了这么久」时,时间线必须能看出重试发生与次数
|
|
54
54
|
'engine.model_retry',
|
|
55
|
-
'
|
|
56
|
-
'
|
|
55
|
+
'step.start',
|
|
56
|
+
'step.end',
|
|
57
57
|
'tool.exec.start',
|
|
58
58
|
'tool.exec.end',
|
|
59
59
|
'budget.exceeded',
|
|
@@ -63,6 +63,11 @@ const TIMELINE_TYPES = new Set([
|
|
|
63
63
|
'context.compact.end',
|
|
64
64
|
'context.compact.error',
|
|
65
65
|
'context.compact.summarize_fallback',
|
|
66
|
+
// m-2:progress 必须落 timeline——manual/慢请求的「已发出多少、等了多久」是
|
|
67
|
+
// 卡死归因的唯一线索(丢弃 = 观测静默失明)
|
|
68
|
+
'context.compact.progress',
|
|
69
|
+
// P3 红线 7:overflow 症状告警(proactive 失效 / 配置漂移缺失)——罕见异常信号必须落 timeline
|
|
70
|
+
'context.overflow.alert',
|
|
66
71
|
'context.layers.assembled',
|
|
67
72
|
'persona.resolve.failed',
|
|
68
73
|
'injection.detected',
|
|
@@ -191,7 +196,7 @@ export class ObserverHub {
|
|
|
191
196
|
? endedAt - record.lifecycle.startedAt
|
|
192
197
|
: undefined,
|
|
193
198
|
// timeline 事件缺失时从 Guard / messages 摘要回填,避免面板全空
|
|
194
|
-
|
|
199
|
+
steps: record.lifecycle.steps ?? g?.steps,
|
|
195
200
|
toolCalls: record.lifecycle.toolCalls ?? g?.totalToolCalls,
|
|
196
201
|
};
|
|
197
202
|
if (input.messages && this.config.channels['run.messages']) {
|
|
@@ -207,8 +212,8 @@ export class ObserverHub {
|
|
|
207
212
|
if (built.cloned) {
|
|
208
213
|
record.messageClones = { ...record.messageClones, final: built.cloned };
|
|
209
214
|
}
|
|
210
|
-
if (record.lifecycle.
|
|
211
|
-
record.lifecycle.
|
|
215
|
+
if (record.lifecycle.steps == null && record.guardMetrics?.steps != null) {
|
|
216
|
+
record.lifecycle.steps = record.guardMetrics.steps;
|
|
212
217
|
}
|
|
213
218
|
if (record.lifecycle.toolCalls == null && record.guardMetrics?.totalToolCalls != null) {
|
|
214
219
|
record.lifecycle.toolCalls = record.guardMetrics.totalToolCalls;
|
|
@@ -473,8 +478,8 @@ export class ObserverHub {
|
|
|
473
478
|
}
|
|
474
479
|
}
|
|
475
480
|
const life = record.lifecycle;
|
|
476
|
-
if (event.type === '
|
|
477
|
-
life.
|
|
481
|
+
if (event.type === 'step.end') {
|
|
482
|
+
life.steps = (life.steps ?? 0) + 1;
|
|
478
483
|
}
|
|
479
484
|
else if (event.type === 'tool.exec.end') {
|
|
480
485
|
life.toolCalls = (life.toolCalls ?? 0) + 1;
|
|
@@ -616,7 +621,7 @@ export class ObserverHub {
|
|
|
616
621
|
}
|
|
617
622
|
else if (d?.usageLedger) {
|
|
618
623
|
record.guardMetrics = {
|
|
619
|
-
|
|
624
|
+
steps: 0,
|
|
620
625
|
totalToolCalls: 0,
|
|
621
626
|
nominalTotalTokens: 0,
|
|
622
627
|
elapsedMs: 0,
|
|
@@ -636,7 +641,7 @@ export class ObserverHub {
|
|
|
636
641
|
if (event.type === 'budget.wrap_up') {
|
|
637
642
|
const d = event.data;
|
|
638
643
|
record.guardMetrics = {
|
|
639
|
-
|
|
644
|
+
steps: record.guardMetrics?.steps ?? 0,
|
|
640
645
|
totalToolCalls: record.guardMetrics?.totalToolCalls ?? 0,
|
|
641
646
|
nominalTotalTokens: record.guardMetrics?.nominalTotalTokens ?? 0,
|
|
642
647
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
@@ -651,13 +656,13 @@ export class ObserverHub {
|
|
|
651
656
|
...record.guardMetrics,
|
|
652
657
|
wrapUpActive: true,
|
|
653
658
|
wrapUpReason: d.reason,
|
|
654
|
-
|
|
659
|
+
wrapUpStepsRemaining: d.stepsRemaining,
|
|
655
660
|
};
|
|
656
661
|
}
|
|
657
662
|
if (event.type === 'budget.exceeded') {
|
|
658
663
|
const reason = event.data?.reason;
|
|
659
664
|
record.guardMetrics = {
|
|
660
|
-
|
|
665
|
+
steps: 0,
|
|
661
666
|
totalToolCalls: record.lifecycle.toolCalls ?? 0,
|
|
662
667
|
nominalTotalTokens: 0,
|
|
663
668
|
elapsedMs: record.lifecycle.durationMs ?? 0,
|
|
@@ -676,7 +681,7 @@ export class ObserverHub {
|
|
|
676
681
|
else if (event.type === 'run_guard.stopped') {
|
|
677
682
|
const reason = event.data?.reason;
|
|
678
683
|
record.guardMetrics = {
|
|
679
|
-
|
|
684
|
+
steps: record.guardMetrics?.steps ?? 0,
|
|
680
685
|
totalToolCalls: record.guardMetrics?.totalToolCalls ?? 0,
|
|
681
686
|
nominalTotalTokens: record.guardMetrics?.nominalTotalTokens ?? 0,
|
|
682
687
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
@@ -695,7 +700,7 @@ export class ObserverHub {
|
|
|
695
700
|
else if (event.type === 'run_guard.recovered') {
|
|
696
701
|
const d = event.data;
|
|
697
702
|
record.guardMetrics = {
|
|
698
|
-
|
|
703
|
+
steps: record.guardMetrics?.steps ?? 0,
|
|
699
704
|
totalToolCalls: record.guardMetrics?.totalToolCalls ?? 0,
|
|
700
705
|
nominalTotalTokens: record.guardMetrics?.nominalTotalTokens ?? 0,
|
|
701
706
|
elapsedMs: record.guardMetrics?.elapsedMs ?? 0,
|
|
@@ -797,7 +802,7 @@ export class ObserverHub {
|
|
|
797
802
|
const g = record.guardMetrics;
|
|
798
803
|
const lifecycle = {
|
|
799
804
|
...record.lifecycle,
|
|
800
|
-
|
|
805
|
+
steps: record.lifecycle.steps ?? g?.steps,
|
|
801
806
|
toolCalls: record.lifecycle.toolCalls ?? g?.totalToolCalls,
|
|
802
807
|
durationMs: record.lifecycle.durationMs ?? g?.elapsedMs,
|
|
803
808
|
};
|
|
@@ -936,7 +941,10 @@ function stripLayerPayload(snapshot, payload) {
|
|
|
936
941
|
}
|
|
937
942
|
function toTimelineNode(event) {
|
|
938
943
|
const data = (event.data ?? {});
|
|
939
|
-
//
|
|
944
|
+
// P3 告警可见性:symptom/message 原样带出(红线 7 展示层不得只剩裸 type)
|
|
945
|
+
const symptom = typeof data.symptom === 'string' ? data.symptom : undefined;
|
|
946
|
+
const message = typeof data.message === 'string' ? data.message : undefined;
|
|
947
|
+
// F3 计时段:step.end 带 llmTiming(LLM 调用计时);run.timing 带 wait/build/run_end 分段
|
|
940
948
|
const timing = data.llmTiming ??
|
|
941
949
|
(event.type === 'run.timing'
|
|
942
950
|
? {
|
|
@@ -962,5 +970,7 @@ function toTimelineNode(event) {
|
|
|
962
970
|
reason: (data.reason ?? data.fallbackError),
|
|
963
971
|
usage: data.usage,
|
|
964
972
|
timing,
|
|
973
|
+
symptom,
|
|
974
|
+
message,
|
|
965
975
|
};
|
|
966
976
|
}
|
|
@@ -169,7 +169,7 @@ export interface RunMessagesSummary {
|
|
|
169
169
|
export interface RunGuardMetricsView {
|
|
170
170
|
sessionId?: string;
|
|
171
171
|
agentId?: string;
|
|
172
|
-
|
|
172
|
+
steps: number;
|
|
173
173
|
totalToolCalls: number;
|
|
174
174
|
/** 诊断 nominal Σ(非 spend hard) */
|
|
175
175
|
nominalTotalTokens: number;
|
|
@@ -197,7 +197,7 @@ export interface RunGuardMetricsView {
|
|
|
197
197
|
/** P2 wrap-up 状态 */
|
|
198
198
|
wrapUpActive?: boolean;
|
|
199
199
|
wrapUpReason?: 'context' | 'policy';
|
|
200
|
-
|
|
200
|
+
wrapUpStepsRemaining?: number;
|
|
201
201
|
guardStoppedReason?: string;
|
|
202
202
|
guardRecovered?: {
|
|
203
203
|
reason: string;
|
|
@@ -265,14 +265,18 @@ export interface RunTimelineEventView {
|
|
|
265
265
|
hasError?: boolean;
|
|
266
266
|
durationMs?: number;
|
|
267
267
|
reason?: string;
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
/** P3 告警可见性:overflow 症状(红线 7 的 proactive 失效语义在展示层可见) */
|
|
269
|
+
symptom?: string;
|
|
270
|
+
/** 人类可读文本(告警/审计消息) */
|
|
271
|
+
message?: string;
|
|
272
|
+
usage?: import('@octopi-agent/core/types/step.js').TokenUsage;
|
|
273
|
+
/** F3 计时段(step.end 的 LLM 计时 / run.timing 的 wait/build/run_end 分段) */
|
|
270
274
|
timing?: {
|
|
271
275
|
stage?: string;
|
|
272
276
|
waitMs?: number;
|
|
273
277
|
buildMs?: number;
|
|
274
278
|
durMs?: number;
|
|
275
|
-
/** LLM 调用总耗时(
|
|
279
|
+
/** LLM 调用总耗时(step.end.llmTiming) */
|
|
276
280
|
durationMs?: number;
|
|
277
281
|
/** LLM 调用标识(可关联 model.call.end 行) */
|
|
278
282
|
callId?: string;
|
|
@@ -295,7 +299,7 @@ export interface RunLifecycleView {
|
|
|
295
299
|
endedAt?: number;
|
|
296
300
|
endReason?: string;
|
|
297
301
|
durationMs?: number;
|
|
298
|
-
|
|
302
|
+
steps?: number;
|
|
299
303
|
toolCalls?: number;
|
|
300
304
|
error?: string;
|
|
301
305
|
}
|