@octopi-agent/engine 0.58.0 → 0.70.7
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/context.d.ts +1 -1
- package/dist/config-schema/context.js +1 -1
- package/dist/config-schema/engine.d.ts +122 -1
- package/dist/config-schema/engine.js +4 -1
- package/dist/config-schema/substrate.d.ts +123 -0
- package/dist/config-schema/substrate.js +161 -0
- package/dist/config.d.ts +101 -1
- package/dist/harness/agent/builder.d.ts +15 -1
- package/dist/harness/agent/builder.js +41 -4
- package/dist/harness/agent/config-bridge.js +17 -4
- package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.js +13 -3
- package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.js +13 -4
- package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.js +25 -5
- package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/errors.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/errors.js +1 -1
- package/dist/harness/capabilities/document/factory.d.ts +33 -0
- package/dist/harness/capabilities/document/factory.js +37 -0
- package/dist/harness/{context/capabilities → capabilities}/document/format.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/format.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/index.d.ts +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/index.js +2 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.d.ts +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.js +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.d.ts +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.js +44 -1
- package/dist/harness/{context/capabilities → capabilities}/document/port.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/port.js +4 -4
- package/dist/harness/{context/capabilities → capabilities}/document/types.d.ts +11 -1
- package/dist/harness/{context/capabilities → capabilities}/document/types.js +1 -1
- package/dist/harness/capabilities/document/worker-port.d.ts +13 -0
- package/dist/harness/capabilities/document/worker-port.js +78 -0
- package/dist/harness/context/capabilities/index.d.ts +2 -2
- package/dist/harness/context/capabilities/index.js +2 -2
- package/dist/harness/context/capabilities/summary/gate.js +2 -2
- package/dist/harness/context/capabilities/summary/policies.js +5 -5
- package/dist/harness/context/capabilities/summary/registry.js +29 -24
- package/dist/harness/context/layer-health.js +3 -2
- package/dist/harness/context/layers.d.ts +27 -13
- package/dist/harness/context/layers.js +76 -66
- package/dist/harness/context/system-prompt-assembler.d.ts +3 -0
- package/dist/harness/context/system-prompt-assembler.js +11 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +109 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.d.ts +10 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +102 -5
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +14 -0
- package/dist/harness/index.d.ts +8 -5
- package/dist/harness/index.js +4 -2
- package/dist/harness/knowledge/adapters.d.ts +8 -5
- package/dist/harness/knowledge/adapters.js +53 -13
- package/dist/harness/knowledge/client.d.ts +197 -0
- package/dist/harness/knowledge/client.js +237 -0
- package/dist/harness/knowledge/connector-fetcher.d.ts +2 -2
- package/dist/harness/knowledge/connectors.d.ts +3 -3
- package/dist/harness/knowledge/connectors.js +14 -8
- package/dist/harness/knowledge/db.d.ts +40 -5
- package/dist/harness/knowledge/db.js +441 -113
- package/dist/harness/knowledge/document-extract-worker.js +55 -12
- package/dist/harness/knowledge/embed-runner.d.ts +53 -0
- package/dist/harness/knowledge/embed-runner.js +171 -0
- package/dist/harness/knowledge/engine-thread.d.ts +1 -0
- package/dist/harness/knowledge/engine-thread.js +302 -0
- package/dist/harness/knowledge/extract-document.d.ts +21 -5
- package/dist/harness/knowledge/extract-document.js +32 -8
- package/dist/harness/knowledge/fetchers.d.ts +14 -3
- package/dist/harness/knowledge/fetchers.js +52 -16
- package/dist/harness/knowledge/file-identity.d.ts +53 -0
- package/dist/harness/knowledge/file-identity.js +172 -0
- package/dist/harness/knowledge/file-index-store.d.ts +50 -0
- package/dist/harness/knowledge/file-index-store.js +132 -0
- package/dist/harness/knowledge/file-limits.d.ts +86 -0
- package/dist/harness/knowledge/file-limits.js +175 -0
- package/dist/harness/knowledge/fts.d.ts +60 -0
- package/dist/harness/knowledge/fts.js +218 -0
- package/dist/harness/knowledge/grounding.d.ts +3 -2
- package/dist/harness/knowledge/http-app.d.ts +50 -0
- package/dist/harness/knowledge/http-app.js +652 -0
- package/dist/harness/knowledge/http-bridge.d.ts +49 -0
- package/dist/harness/knowledge/http-bridge.js +17 -0
- package/dist/harness/knowledge/index-store.d.ts +158 -93
- package/dist/harness/knowledge/index-store.js +982 -441
- package/dist/harness/knowledge/index.d.ts +45 -5
- package/dist/harness/knowledge/index.js +23 -2
- package/dist/harness/knowledge/ingest.d.ts +262 -87
- package/dist/harness/knowledge/ingest.js +1072 -480
- package/dist/harness/knowledge/job-control-state.d.ts +29 -0
- package/dist/harness/knowledge/job-control-state.js +44 -0
- package/dist/harness/knowledge/job-control.d.ts +35 -0
- package/dist/harness/knowledge/job-control.js +86 -0
- package/dist/harness/knowledge/job-queue.d.ts +62 -0
- package/dist/harness/knowledge/job-queue.js +173 -0
- package/dist/harness/knowledge/knowledge-serve-child.d.ts +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +100 -0
- package/dist/harness/knowledge/local-stack.d.ts +27 -0
- package/dist/harness/knowledge/local-stack.js +63 -0
- package/dist/harness/knowledge/membership-store.d.ts +65 -0
- package/dist/harness/knowledge/membership-store.js +198 -0
- package/dist/harness/knowledge/network-guard.d.ts +11 -2
- package/dist/harness/knowledge/network-guard.js +130 -85
- package/dist/harness/knowledge/parse-text-in-worker.d.ts +32 -0
- package/dist/harness/knowledge/parse-text-in-worker.js +158 -0
- package/dist/harness/knowledge/query-service.d.ts +272 -0
- package/dist/harness/knowledge/query-service.js +326 -0
- package/dist/harness/knowledge/query-worker-client.d.ts +96 -0
- package/dist/harness/knowledge/query-worker-client.js +207 -0
- package/dist/harness/knowledge/query-worker.d.ts +1 -0
- package/dist/harness/knowledge/query-worker.js +186 -0
- package/dist/harness/knowledge/read-http.d.ts +35 -0
- package/dist/harness/knowledge/read-http.js +373 -0
- package/dist/harness/knowledge/retriever.d.ts +22 -5
- package/dist/harness/knowledge/retriever.js +66 -35
- package/dist/harness/knowledge/secret-scan.d.ts +13 -2
- package/dist/harness/knowledge/secret-scan.js +25 -2
- package/dist/harness/knowledge/serve.d.ts +48 -0
- package/dist/harness/knowledge/serve.js +336 -0
- package/dist/harness/knowledge/source-store.d.ts +97 -19
- package/dist/harness/knowledge/source-store.js +166 -94
- package/dist/harness/knowledge/start-service-process.d.ts +49 -0
- package/dist/harness/knowledge/start-service-process.js +158 -0
- package/dist/harness/knowledge/text-parse-worker.d.ts +1 -0
- package/dist/harness/knowledge/text-parse-worker.js +54 -0
- package/dist/harness/knowledge/types.d.ts +1 -1
- package/dist/harness/knowledge/types.js +1 -1
- package/dist/harness/knowledge/vector-ann.d.ts +42 -0
- package/dist/harness/knowledge/vector-ann.js +68 -0
- package/dist/harness/knowledge/writer-lock.d.ts +13 -0
- package/dist/harness/knowledge/writer-lock.js +71 -0
- package/dist/harness/knowledge/writer-service.d.ts +194 -0
- package/dist/harness/knowledge/writer-service.js +355 -0
- package/dist/harness/knowledge/writer-worker-client.d.ts +102 -0
- package/dist/harness/knowledge/writer-worker-client.js +381 -0
- package/dist/harness/knowledge/writer-worker.d.ts +1 -0
- package/dist/harness/knowledge/writer-worker.js +189 -0
- package/dist/harness/memory/cognition-decay.d.ts +36 -0
- package/dist/harness/memory/cognition-decay.js +55 -0
- package/dist/harness/memory/cognition-gates.d.ts +60 -0
- package/dist/harness/memory/cognition-gates.js +191 -0
- package/dist/harness/memory/cognition-trigger.d.ts +30 -0
- package/dist/harness/memory/cognition-trigger.js +41 -0
- package/dist/harness/memory/cognition-types.d.ts +1 -1
- package/dist/harness/memory/cognition.d.ts +40 -8
- package/dist/harness/memory/cognition.js +432 -79
- package/dist/harness/memory/conceptualizer.d.ts +66 -0
- package/dist/harness/memory/conceptualizer.js +246 -0
- package/dist/harness/memory/index.d.ts +16 -2
- package/dist/harness/memory/index.js +11 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
- package/dist/harness/memory/sqlite/agent-db.js +118 -15
- package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
- package/dist/harness/memory/sqlite/cognition-store.js +591 -144
- package/dist/harness/memory/sqlite/embedding.d.ts +5 -2
- package/dist/harness/memory/sqlite/embedding.js +109 -16
- package/dist/harness/memory/sqlite/keyword-search.d.ts +21 -0
- package/dist/harness/memory/sqlite/keyword-search.js +64 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
- package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
- package/dist/harness/memory/types.d.ts +331 -16
- package/dist/harness/memory/types.js +49 -0
- package/dist/harness/memory/wisdom-formation.d.ts +101 -0
- package/dist/harness/memory/wisdom-formation.js +304 -0
- package/dist/harness/memory/wisdom-gates.d.ts +50 -0
- package/dist/harness/memory/wisdom-gates.js +204 -0
- package/dist/harness/memory/wisdom-policy.d.ts +107 -0
- package/dist/harness/memory/wisdom-policy.js +220 -0
- package/dist/harness/memory/wisdom-types.d.ts +3 -2
- package/dist/harness/memory/wisdom-types.js +2 -2
- package/dist/harness/memory/wisdom.d.ts +27 -0
- package/dist/harness/memory/wisdom.js +181 -0
- package/dist/harness/run/agent/agent.d.ts +9 -0
- package/dist/harness/run/agent/agent.js +19 -0
- package/dist/harness/run/reliability/run-agent.js +6 -2
- package/dist/harness/run/runner.js +2 -1
- package/dist/harness/session/attachments/service.d.ts +1 -1
- package/dist/harness/session/attachments/service.js +1 -1
- package/dist/harness/session/index.d.ts +1 -0
- package/dist/harness/session/index.js +1 -0
- package/dist/harness/session/title.d.ts +86 -0
- package/dist/harness/session/title.js +268 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +8 -0
- package/dist/harness/shared/events/agent-event-map.js +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
- package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
- package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
- package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
- package/dist/worker-path.d.ts +8 -0
- package/dist/worker-path.js +15 -0
- package/package.json +2 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognition gates — 概念/关系准入执法(结构,不猜语义)
|
|
3
|
+
*
|
|
4
|
+
* 意图判断(是否可复用单元、关系假设)归 LLM;本模块只做:
|
|
5
|
+
* cue 校验、证据等级、保守降级、MDL 出生门槛、伪概念/密钥形态。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/cognition-gates
|
|
8
|
+
*/
|
|
9
|
+
import type { AdmitConceptInput, ConceptGateReason, ConceptRelationType, EdgeBasis, EvidenceClass } from './types.js';
|
|
10
|
+
export interface ConceptGateOutcome {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
reason: ConceptGateReason;
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
15
|
+
/** 归一化空白,用于 cue ⊆ evidence 子串校验 */
|
|
16
|
+
export declare function normalizeForCue(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* 概念结构门控。
|
|
19
|
+
*
|
|
20
|
+
* @param input - 候选概念
|
|
21
|
+
* @param options - capacityAdmitStop 时禁止新生
|
|
22
|
+
* @returns 是否准入与 reason code
|
|
23
|
+
*/
|
|
24
|
+
export declare function evaluateConceptGate(input: AdmitConceptInput, options?: {
|
|
25
|
+
capacityAdmitStop?: boolean;
|
|
26
|
+
}): ConceptGateOutcome;
|
|
27
|
+
export interface EdgeLicenseInput {
|
|
28
|
+
relationType: ConceptRelationType;
|
|
29
|
+
evidenceClass: EvidenceClass;
|
|
30
|
+
cue: string;
|
|
31
|
+
/** evidence + contextSlice 全文;用于 cue 子串校验 */
|
|
32
|
+
evidenceText?: string;
|
|
33
|
+
memoryIds: string[];
|
|
34
|
+
/** 对应 memory 的 status;用于「1 条 strengthened + 失败→修复」例外 */
|
|
35
|
+
memoryStatuses?: Array<'shadow' | 'active' | 'strengthened'>;
|
|
36
|
+
/** 对应 memory 的 channel;strengthened 例外要求 fail_fix */
|
|
37
|
+
memoryChannels?: Array<'user_directive' | 'decision' | 'fail_fix' | 'model_inference' | 'admin'>;
|
|
38
|
+
/** 配置:causes 最少独立命题(默认 2) */
|
|
39
|
+
causesMinIndependentMemories?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface EdgeLicenseOutcome {
|
|
42
|
+
ok: boolean;
|
|
43
|
+
/** 实际应入库的关系类型(可能已降级) */
|
|
44
|
+
relationType: ConceptRelationType;
|
|
45
|
+
status: 'active' | 'shadow' | 'demoted' | 'candidate_only' | 'rejected';
|
|
46
|
+
reason: ConceptGateReason;
|
|
47
|
+
message?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 关系持证门:强边需 cue ⊆ 证据 ∧ 证据形态匹配 ∧ 独立多证据。
|
|
51
|
+
* 任何不满足 → 保守降级为 `related` 或 candidate_only / rejected。
|
|
52
|
+
* **禁止** 共现升格为强类型。
|
|
53
|
+
*/
|
|
54
|
+
export declare function licenseEdge(input: EdgeLicenseInput): EdgeLicenseOutcome;
|
|
55
|
+
/**
|
|
56
|
+
* 校验 basis 与许可结果一致;不一致时强制保守。
|
|
57
|
+
*/
|
|
58
|
+
export declare function edgeBasisFromLicense(license: EdgeLicenseOutcome, basis: Omit<EdgeBasis, 'licensedAt'> & {
|
|
59
|
+
licensedAt?: number;
|
|
60
|
+
}): EdgeBasis;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognition gates — 概念/关系准入执法(结构,不猜语义)
|
|
3
|
+
*
|
|
4
|
+
* 意图判断(是否可复用单元、关系假设)归 LLM;本模块只做:
|
|
5
|
+
* cue 校验、证据等级、保守降级、MDL 出生门槛、伪概念/密钥形态。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/cognition-gates
|
|
8
|
+
*/
|
|
9
|
+
import { CONCEPT_KINDS, CONCEPT_RELATION_TYPES, STRONG_RELATION_TYPES, } from './types.js';
|
|
10
|
+
const SECRET_LIKE = /(?:api[_-]?key|secret|password|token)\s*[:=]\s*\S{8,}/i;
|
|
11
|
+
const STOPWORD = /^(?:the|a|an|this|that|it|is|are|was|were|and|or|of|to|in|for)$/i;
|
|
12
|
+
const CJK = /[一-鿿]/;
|
|
13
|
+
/** 归一化空白,用于 cue ⊆ evidence 子串校验 */
|
|
14
|
+
export function normalizeForCue(text) {
|
|
15
|
+
return text.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 概念结构门控。
|
|
19
|
+
*
|
|
20
|
+
* @param input - 候选概念
|
|
21
|
+
* @param options - capacityAdmitStop 时禁止新生
|
|
22
|
+
* @returns 是否准入与 reason code
|
|
23
|
+
*/
|
|
24
|
+
export function evaluateConceptGate(input, options) {
|
|
25
|
+
const name = (input.name ?? '').trim();
|
|
26
|
+
if (!name)
|
|
27
|
+
return { ok: false, reason: 'empty_name' };
|
|
28
|
+
if (!CONCEPT_KINDS.includes(input.kind)) {
|
|
29
|
+
return { ok: false, reason: 'invalid_kind', message: `kind=${input.kind}` };
|
|
30
|
+
}
|
|
31
|
+
if (SECRET_LIKE.test(name) || SECRET_LIKE.test(input.description ?? '')) {
|
|
32
|
+
return { ok: false, reason: 'secret_like' };
|
|
33
|
+
}
|
|
34
|
+
if (STOPWORD.test(name) || /^\d+$/.test(name)) {
|
|
35
|
+
return { ok: false, reason: 'pseudo_concept', message: 'stopword or numeric' };
|
|
36
|
+
}
|
|
37
|
+
// 非 CJK 拉丁名至少 2 字符;CJK 允许单字(锁、库…)
|
|
38
|
+
if (name.length < 2 && !CJK.test(name)) {
|
|
39
|
+
return { ok: false, reason: 'pseudo_concept', message: 'name too short' };
|
|
40
|
+
}
|
|
41
|
+
const support = input.supportCount ?? input.memoryIds?.length ?? 0;
|
|
42
|
+
const highValueKind = ['method', 'constraint', 'construct'];
|
|
43
|
+
if (support < 2 && !(support >= 1 && highValueKind.includes(input.kind))) {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
reason: 'mdl_insufficient',
|
|
47
|
+
message: `support=${support} kind=${input.kind}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (options?.capacityAdmitStop) {
|
|
51
|
+
return { ok: false, reason: 'capacity_admit_stop' };
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, reason: 'ok' };
|
|
54
|
+
}
|
|
55
|
+
// ── 关系持证 ──
|
|
56
|
+
/** relationType → 允许的 evidenceClass */
|
|
57
|
+
const RELATION_EVIDENCE = {
|
|
58
|
+
causes: ['causal'],
|
|
59
|
+
part_of: ['mereonymy'],
|
|
60
|
+
opposes: ['negation'],
|
|
61
|
+
similar_to: ['analogy'],
|
|
62
|
+
evolves_to: ['evolution'],
|
|
63
|
+
related: ['cooccur', 'causal', 'mereonymy', 'negation', 'analogy', 'evolution'],
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 关系持证门:强边需 cue ⊆ 证据 ∧ 证据形态匹配 ∧ 独立多证据。
|
|
67
|
+
* 任何不满足 → 保守降级为 `related` 或 candidate_only / rejected。
|
|
68
|
+
* **禁止** 共现升格为强类型。
|
|
69
|
+
*/
|
|
70
|
+
export function licenseEdge(input) {
|
|
71
|
+
const rel = input.relationType;
|
|
72
|
+
if (!CONCEPT_RELATION_TYPES.includes(rel)) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
relationType: rel,
|
|
76
|
+
status: 'rejected',
|
|
77
|
+
reason: 'invalid_relation',
|
|
78
|
+
message: `relationType=${rel}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const allowed = RELATION_EVIDENCE[rel] ?? [];
|
|
82
|
+
const classOk = allowed.includes(input.evidenceClass);
|
|
83
|
+
const isStrong = STRONG_RELATION_TYPES.includes(rel);
|
|
84
|
+
// cue 校验(有 evidenceText 时强制)
|
|
85
|
+
if (input.evidenceText != null && input.evidenceText !== '') {
|
|
86
|
+
const hay = normalizeForCue(input.evidenceText);
|
|
87
|
+
const needle = normalizeForCue(input.cue ?? '');
|
|
88
|
+
if (!needle || !hay.includes(needle)) {
|
|
89
|
+
if (isStrong) {
|
|
90
|
+
return {
|
|
91
|
+
ok: true,
|
|
92
|
+
relationType: 'related',
|
|
93
|
+
status: 'demoted',
|
|
94
|
+
reason: 'cue_mismatch',
|
|
95
|
+
message: 'strong relation cue not in evidence; demoted to related',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
relationType: 'related',
|
|
101
|
+
status: 'rejected',
|
|
102
|
+
reason: 'cue_mismatch',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!classOk) {
|
|
107
|
+
if (isStrong) {
|
|
108
|
+
return {
|
|
109
|
+
ok: true,
|
|
110
|
+
relationType: 'related',
|
|
111
|
+
status: 'demoted',
|
|
112
|
+
reason: 'demoted_related',
|
|
113
|
+
message: `evidenceClass=${input.evidenceClass} cannot license ${rel}`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
ok: false,
|
|
118
|
+
relationType: 'related',
|
|
119
|
+
status: 'rejected',
|
|
120
|
+
reason: 'demoted_related',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// 强边多证据(调用方应传入同 pair 累积 memoryIds)
|
|
124
|
+
const min = input.causesMinIndependentMemories ?? 2;
|
|
125
|
+
const memCount = new Set(input.memoryIds ?? []).size;
|
|
126
|
+
const hasStrengthened = (input.memoryStatuses ?? []).includes('strengthened');
|
|
127
|
+
const hasFailFix = (input.memoryChannels ?? []).includes('fail_fix');
|
|
128
|
+
if (rel === 'causes') {
|
|
129
|
+
// 2 条独立,或 1 条 strengthened + 失败→修复闭环(fail_fix)
|
|
130
|
+
const closedLoop = memCount >= 1 && hasStrengthened && hasFailFix && input.evidenceClass === 'causal';
|
|
131
|
+
const licensed = memCount >= min || closedLoop;
|
|
132
|
+
if (!licensed) {
|
|
133
|
+
return {
|
|
134
|
+
ok: true,
|
|
135
|
+
relationType: 'related',
|
|
136
|
+
status: 'candidate_only',
|
|
137
|
+
reason: memCount < 1 ? 'cue_mismatch' : 'multi_evidence_required',
|
|
138
|
+
message: `causes needs ≥${min} independent memories (have ${memCount}) or strengthened+fail_fix`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (rel === 'opposes') {
|
|
143
|
+
// 2 条独立,或 supersede/否定极性(negation 类 1 条可 shadow 持证,2 条才 active)
|
|
144
|
+
if (memCount < 2) {
|
|
145
|
+
return {
|
|
146
|
+
ok: true,
|
|
147
|
+
relationType: rel,
|
|
148
|
+
status: 'shadow',
|
|
149
|
+
reason: 'multi_evidence_required',
|
|
150
|
+
message: `opposes needs ≥2 independent memories (have ${memCount})`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (isStrong) {
|
|
155
|
+
// part_of / evolves_to:至少 1 条持证件
|
|
156
|
+
if (memCount < 1) {
|
|
157
|
+
return {
|
|
158
|
+
ok: true,
|
|
159
|
+
relationType: 'related',
|
|
160
|
+
status: 'shadow',
|
|
161
|
+
reason: 'multi_evidence_required',
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// related / 共现:永远 shadow,不得因强度升格
|
|
166
|
+
if (rel === 'related' || input.evidenceClass === 'cooccur') {
|
|
167
|
+
return {
|
|
168
|
+
ok: true,
|
|
169
|
+
relationType: 'related',
|
|
170
|
+
status: isStrong ? 'demoted' : 'shadow',
|
|
171
|
+
reason: input.evidenceClass === 'cooccur' && rel !== 'related' ? 'cooccur_no_escalation' : 'ok',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
ok: true,
|
|
176
|
+
relationType: rel,
|
|
177
|
+
status: 'active',
|
|
178
|
+
reason: 'ok',
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 校验 basis 与许可结果一致;不一致时强制保守。
|
|
183
|
+
*/
|
|
184
|
+
export function edgeBasisFromLicense(license, basis) {
|
|
185
|
+
return {
|
|
186
|
+
memoryIds: basis.memoryIds ?? [],
|
|
187
|
+
cue: basis.cue ?? '',
|
|
188
|
+
evidenceClass: basis.evidenceClass,
|
|
189
|
+
licensedAt: basis.licensedAt ?? Date.now(),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognition 触发 — 命题落库后 emit 概念化请求
|
|
3
|
+
*
|
|
4
|
+
* 事件类型必须真实存在于 EventBus;sense.source=`eventBus` 才会挂监听。
|
|
5
|
+
*
|
|
6
|
+
* @module harness/memory/cognition-trigger
|
|
7
|
+
*/
|
|
8
|
+
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
9
|
+
import type { MemoryChannel, MemoryStatus, MemoryType } from './types.js';
|
|
10
|
+
/** 概念化请求(cognition.steward.conceptualize 监听) */
|
|
11
|
+
export declare const COGNITIZE_REQUEST_EVENT = "cognition.conceptualize.request";
|
|
12
|
+
export interface ConceptualizeRequestPayload {
|
|
13
|
+
memoryId: string;
|
|
14
|
+
proposition: string;
|
|
15
|
+
evidence: string;
|
|
16
|
+
memoryType: MemoryType;
|
|
17
|
+
memoryStatus?: MemoryStatus;
|
|
18
|
+
channel?: MemoryChannel;
|
|
19
|
+
/** 证据周边语境;缺省由 handler 从 session 补 */
|
|
20
|
+
contextSlice?: string;
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
agentId?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 发射概念化请求。失败静默(不得阻断 memory 写路径)。
|
|
26
|
+
*
|
|
27
|
+
* @param events - EventBus
|
|
28
|
+
* @param payload - 请求载荷
|
|
29
|
+
*/
|
|
30
|
+
export declare function emitConceptualizeRequest(events: EventBus | undefined, payload: ConceptualizeRequestPayload): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognition 触发 — 命题落库后 emit 概念化请求
|
|
3
|
+
*
|
|
4
|
+
* 事件类型必须真实存在于 EventBus;sense.source=`eventBus` 才会挂监听。
|
|
5
|
+
*
|
|
6
|
+
* @module harness/memory/cognition-trigger
|
|
7
|
+
*/
|
|
8
|
+
/** 概念化请求(cognition.steward.conceptualize 监听) */
|
|
9
|
+
export const COGNITIZE_REQUEST_EVENT = 'cognition.conceptualize.request';
|
|
10
|
+
/**
|
|
11
|
+
* 发射概念化请求。失败静默(不得阻断 memory 写路径)。
|
|
12
|
+
*
|
|
13
|
+
* @param events - EventBus
|
|
14
|
+
* @param payload - 请求载荷
|
|
15
|
+
*/
|
|
16
|
+
export function emitConceptualizeRequest(events, payload) {
|
|
17
|
+
if (!events)
|
|
18
|
+
return;
|
|
19
|
+
try {
|
|
20
|
+
events.emit({
|
|
21
|
+
type: COGNITIZE_REQUEST_EVENT,
|
|
22
|
+
timestamp: Date.now(),
|
|
23
|
+
agentId: payload.agentId,
|
|
24
|
+
sessionId: payload.sessionId,
|
|
25
|
+
data: {
|
|
26
|
+
memoryId: payload.memoryId,
|
|
27
|
+
proposition: payload.proposition,
|
|
28
|
+
evidence: payload.evidence,
|
|
29
|
+
memoryType: payload.memoryType,
|
|
30
|
+
memoryStatus: payload.memoryStatus,
|
|
31
|
+
channel: payload.channel,
|
|
32
|
+
contextSlice: payload.contextSlice,
|
|
33
|
+
sessionId: payload.sessionId,
|
|
34
|
+
agentId: payload.agentId,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// 总线异常不得拖垮 Memory 写入
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cognition 类型 — 规范定义在 ./types.ts
|
|
3
3
|
*/
|
|
4
|
-
export type { ConceptNode, ConceptEdge, ConceptGraph, ConceptGraphStore, } from './types.js';
|
|
4
|
+
export type { ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, EdgeAux, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './types.js';
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* InMemoryConceptGraph —
|
|
2
|
+
* InMemoryConceptGraph — 内存认知图谱(测试/轻量)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 实现与 SqliteConceptGraph 同一 `ConceptGraphStore` 契约:
|
|
5
|
+
* 结构同一性合并、持证边、衰减、扩散激活。无正则 extractFromText。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/memory/cognition
|
|
6
8
|
*/
|
|
7
|
-
import type {
|
|
9
|
+
import type { ActivatedGraph, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGraph, ConceptGraphStats, ConceptGraphStore, DecayResult, MergeCandidate, SpreadingActivateOptions } from './cognition-types.js';
|
|
8
10
|
export declare class InMemoryConceptGraph implements ConceptGraphStore {
|
|
9
11
|
private nodes;
|
|
10
12
|
private edges;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
private mergeCandidates;
|
|
14
|
+
private causalCandidates;
|
|
15
|
+
private get capacityStop();
|
|
16
|
+
admitConcept(input: AdmitConceptInput): Promise<AdmitConceptResult>;
|
|
17
|
+
private insertNode;
|
|
18
|
+
/** 义项指纹冲突:kind 不同或论域无交集且双方皆非空 */
|
|
19
|
+
private fingerprintConflict;
|
|
20
|
+
private pushMergeCandidate;
|
|
21
|
+
private collectPairMemoryIds;
|
|
22
|
+
admitEdge(input: AdmitEdgeInput): Promise<AdmitEdgeResult>;
|
|
23
|
+
addCausalCandidate(input: {
|
|
24
|
+
sourceId: string;
|
|
25
|
+
targetId: string;
|
|
26
|
+
memoryIds: string[];
|
|
27
|
+
cue: string;
|
|
28
|
+
note?: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
listMergeCandidates(limit?: number): Promise<MergeCandidate[]>;
|
|
31
|
+
resolveMerge(id: string, action: 'merge' | 'keep_split' | 'drop'): Promise<void>;
|
|
32
|
+
reinforce(input: {
|
|
33
|
+
nodeIds?: string[];
|
|
34
|
+
edgeIds?: string[];
|
|
35
|
+
evidenceStrength?: number;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
counterEvidence(input: {
|
|
38
|
+
edgeId: string;
|
|
39
|
+
memoryId?: string;
|
|
40
|
+
markOpposes?: boolean;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
promote(ids: string[], to: 'active' | 'strengthened'): Promise<void>;
|
|
43
|
+
demote(ids: string[], to: 'shadow'): Promise<void>;
|
|
44
|
+
applyDecay(now?: number): Promise<DecayResult>;
|
|
45
|
+
spreadingActivate(seeds: string[], options?: SpreadingActivateOptions): Promise<ActivatedGraph>;
|
|
15
46
|
getFullGraph(): Promise<ConceptGraph>;
|
|
47
|
+
stats(): Promise<ConceptGraphStats>;
|
|
16
48
|
}
|