@octopi-agent/engine 0.86.38 → 0.97.15
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-admin/agent-presets.d.ts +70 -0
- package/dist/config-admin/agent-presets.js +243 -0
- package/dist/config-admin/discover.d.ts +30 -0
- package/dist/config-admin/discover.js +48 -0
- package/dist/config-admin/env.d.ts +22 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/index.d.ts +20 -0
- package/dist/config-admin/index.js +15 -0
- package/dist/config-admin/model-presets.d.ts +75 -0
- package/dist/config-admin/model-presets.js +249 -0
- package/dist/config-admin/name-guard.d.ts +14 -0
- package/dist/config-admin/name-guard.js +24 -0
- package/dist/config-admin/patch.d.ts +56 -0
- package/dist/config-admin/patch.js +201 -0
- package/dist/config-admin/port.d.ts +68 -0
- package/dist/config-admin/port.js +21 -0
- package/dist/config-admin/redact.d.ts +39 -0
- package/dist/config-admin/redact.js +42 -0
- package/dist/config-schema/agent.d.ts +43 -1
- package/dist/config-schema/agent.js +12 -5
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +110 -8
- package/dist/config-schema/governance.d.ts +43 -1
- package/dist/config-schema/governance.js +160 -2
- package/dist/config-schema/models.d.ts +7 -4
- package/dist/config-schema/models.js +4 -1
- package/dist/config-schema/observability.d.ts +9 -0
- package/dist/config-schema/observability.js +29 -0
- package/dist/config-schema/run.d.ts +3 -0
- package/dist/config-schema/run.js +14 -0
- package/dist/config-schema/shared.d.ts +3 -0
- package/dist/config-schema/shared.js +12 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config.d.ts +60 -13
- package/dist/config.js +81 -78
- package/dist/harness/activation/dispatcher.d.ts +8 -2
- package/dist/harness/activation/dispatcher.js +33 -5
- package/dist/harness/activation/inbox.d.ts +87 -0
- package/dist/harness/activation/inbox.js +169 -0
- package/dist/harness/activation/runtime.d.ts +9 -8
- package/dist/harness/activation/runtime.js +100 -8
- package/dist/harness/activation/types.d.ts +19 -0
- package/dist/harness/activation/types.js +2 -0
- package/dist/harness/agent/builder.d.ts +18 -3
- package/dist/harness/agent/builder.js +42 -17
- package/dist/harness/agent/config-bridge.d.ts +5 -0
- package/dist/harness/agent/config-bridge.js +7 -1
- package/dist/harness/agent/config-integrity.d.ts +72 -0
- package/dist/harness/agent/config-integrity.js +146 -0
- package/dist/harness/agent/tool-purpose.d.ts +9 -1
- package/dist/harness/agent/tool-purpose.js +11 -2
- package/dist/harness/agent/wire-agent-builder.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +3 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
- package/dist/harness/collaboration/delegation/child-run.js +21 -5
- package/dist/harness/collaboration/delegation/notifier.js +4 -3
- package/dist/harness/collaboration/delegation/service.js +2 -3
- package/dist/harness/collaboration/delegation/wiring.js +6 -5
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
- package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
- package/dist/harness/context/capabilities/compact/engine.js +198 -46
- package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
- package/dist/harness/context/capabilities/compact/handover.js +107 -0
- package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
- package/dist/harness/context/capabilities/compact/index.js +2 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
- package/dist/harness/context/capabilities/summary/executor.js +2 -1
- package/dist/harness/context/capabilities/summary/policies.js +8 -5
- package/dist/harness/context/constitution/default-agents.md +11 -10
- package/dist/harness/context/default-context-engine.d.ts +34 -4
- package/dist/harness/context/default-context-engine.js +198 -53
- package/dist/harness/context/hybrid-compressor.js +6 -0
- package/dist/harness/context/layer-types.d.ts +36 -0
- package/dist/harness/context/layer-types.js +38 -0
- package/dist/harness/context/llm-summarizer.d.ts +2 -8
- package/dist/harness/context/llm-summarizer.js +69 -91
- package/dist/harness/context/message-selector.js +4 -3
- package/dist/harness/context/root-instructions.js +1 -1
- package/dist/harness/context/summarize.d.ts +2 -0
- package/dist/harness/context/summarize.js +7 -2
- package/dist/harness/context/system-prompt-assembler.js +10 -4
- package/dist/harness/context/tool-result-aging.js +2 -2
- package/dist/harness/context/truncate-compressor.js +7 -0
- package/dist/harness/context/turn-envelope.d.ts +4 -3
- package/dist/harness/context/turn-envelope.js +4 -3
- package/dist/harness/context/types.d.ts +33 -1
- package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
- package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +133 -4
- package/dist/harness/extension/execution-environment/effect-policy.js +263 -14
- package/dist/harness/extension/execution-environment/index.d.ts +4 -2
- package/dist/harness/extension/execution-environment/index.js +2 -1
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
- package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +200 -0
- package/dist/harness/extension/execution-environment/ops-audit.js +338 -0
- package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
- package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
- package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
- package/dist/harness/extension/execution-environment/process-info.js +466 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
- package/dist/harness/extension/execution-environment/sandbox.js +264 -29
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
- package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
- package/dist/harness/extension/execution-environment/types.d.ts +19 -0
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +50 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +53 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +10 -17
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +8 -8
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +9 -100
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
- package/dist/harness/governance/security/temp-path.d.ts +9 -0
- package/dist/harness/governance/security/temp-path.js +13 -2
- package/dist/harness/governance/session-acl/seed-roles.js +14 -0
- package/dist/harness/index.d.ts +4 -0
- package/dist/harness/index.js +3 -0
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/fts.js +1 -2
- package/dist/harness/knowledge/grounding.js +5 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +180 -48
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +150 -150
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- package/dist/harness/observability/observer/hub.js +38 -1
- package/dist/harness/observability/observer/run-snapshot.js +1 -0
- package/dist/harness/observability/observer/types.d.ts +27 -0
- package/dist/harness/run/agent/agent.d.ts +7 -0
- package/dist/harness/run/agent/agent.js +23 -1
- package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
- package/dist/harness/run/reliability/fallback-provider.js +262 -22
- package/dist/harness/run/reliability/harness-events.d.ts +24 -1
- package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
- package/dist/harness/run/reliability/model-error-policy.js +42 -0
- package/dist/harness/run/reliability/provider-wrapper.js +29 -2
- package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
- package/dist/harness/run/reliability/refusal-guard.js +102 -0
- package/dist/harness/run/reliability/run-agent.js +231 -33
- package/dist/harness/run/run-guard/default-run-guard.js +1 -1
- package/dist/harness/run/run-scope.d.ts +31 -0
- package/dist/harness/run/runner.d.ts +132 -2
- package/dist/harness/run/runner.js +679 -60
- package/dist/harness/session/attachments/llm-intent.js +2 -1
- package/dist/harness/session/history/port.js +15 -5
- package/dist/harness/session/in-memory-store.d.ts +5 -0
- package/dist/harness/session/in-memory-store.js +33 -2
- package/dist/harness/session/tasks/render.d.ts +4 -1
- package/dist/harness/session/tasks/render.js +10 -7
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/shared/events/agent-event-map.d.ts +92 -0
- package/dist/harness/shared/events/agent-event-map.js +7 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -3
- package/dist/integration/agent-runtime/channel-message-source.js +19 -1
- package/dist/integration/index.d.ts +2 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/observability/loop-watchdog.d.ts +56 -0
- package/dist/integration/observability/loop-watchdog.js +177 -0
- package/dist/integration/observability/metrics.d.ts +3 -0
- package/dist/integration/observability/metrics.js +18 -7
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +23 -0
- package/dist/integration/providers/anthropic.js +97 -12
- package/dist/integration/providers/fetch-timeout.d.ts +42 -0
- package/dist/integration/providers/fetch-timeout.js +51 -0
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -11
- package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
- package/dist/integration/providers/provider-diagnostics.js +89 -0
- package/dist/integration/providers/timeout-coherence.d.ts +52 -0
- package/dist/integration/providers/timeout-coherence.js +68 -0
- package/dist/integration/providers/wire-dump.d.ts +62 -0
- package/dist/integration/providers/wire-dump.js +111 -2
- package/dist/integration/storage/jsonl.d.ts +19 -1
- package/dist/integration/storage/jsonl.js +100 -4
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +1 -1
- package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
- package/package.json +3 -2
|
@@ -10,8 +10,31 @@ import { KnowledgeFts } from './fts.js';
|
|
|
10
10
|
import { vectorBucket } from './vector-ann.js';
|
|
11
11
|
import { toVecBlob } from '../memory/sqlite/sqlite-vec.js';
|
|
12
12
|
import { asChunkId, asSourceId } from './types.js';
|
|
13
|
-
import { normalizePathLexical } from './file-identity.js';
|
|
13
|
+
import { normalizePathLexical, realIdentitySync } from './file-identity.js';
|
|
14
14
|
const EMBEDDABLE_WHERE = "(f.adapter_id IS NULL OR f.adapter_id NOT IN ('code-tree'))";
|
|
15
|
+
/** B+ 匹配语义分界:2–3 字符纯 ASCII 字母数字词用词边界,其余用子串(语义细节见 search 兜底注释)。 */
|
|
16
|
+
const SUBSTRING_FALLBACK_MIN_CHARS = 4; // 3 字符(api/db)碰撞面大需边界保护;≥4 起子词召回价值高于碰撞成本
|
|
17
|
+
/**
|
|
18
|
+
* weak-only 命中的绝对相关性地板(scoreKeywordCoverage 口径)。
|
|
19
|
+
* 中文长段查询靠二元组重叠召回是本义(「会话签名校验」须命中「校验会话签名」,4/5 重叠 ≈ 0.57),
|
|
20
|
+
* 但 1–2 个虚词二元组擦边是噪音(≈ 0.14–0.29)——界线 0.3。
|
|
21
|
+
*/
|
|
22
|
+
const WEAK_ONLY_SCORE_FLOOR = 0.3;
|
|
23
|
+
/** B+ 分类单源:该 token 是否走词边界语义(兜底 SQL 子句与 JS 判定共用,防语义漂移)。 */
|
|
24
|
+
function isBoundaryToken(token) {
|
|
25
|
+
return token.length < SUBSTRING_FALLBACK_MIN_CHARS && /^[a-z0-9]+$/.test(token);
|
|
26
|
+
}
|
|
27
|
+
/** B+ 语义命中判定:token 是否命中 text/path(与兜底 SQL 子句同源的边界/子串语义)。 */
|
|
28
|
+
function tokenMatchesBPlus(token, text, path) {
|
|
29
|
+
const t = token.toLowerCase();
|
|
30
|
+
const textL = text.toLowerCase();
|
|
31
|
+
const pathL = path.toLowerCase();
|
|
32
|
+
if (isBoundaryToken(token)) {
|
|
33
|
+
const boundary = new RegExp(`(^|[^a-z0-9])${t}([^a-z0-9]|$)`);
|
|
34
|
+
return boundary.test(textL) || boundary.test(pathL);
|
|
35
|
+
}
|
|
36
|
+
return textL.includes(t) || pathL.includes(t);
|
|
37
|
+
}
|
|
15
38
|
function defaultIdentityKey(path) {
|
|
16
39
|
try {
|
|
17
40
|
return `path:${normalizePathLexical(path)}`;
|
|
@@ -494,42 +517,100 @@ export class KnowledgeIndexStore {
|
|
|
494
517
|
out = out.slice(0, filter.max);
|
|
495
518
|
return out;
|
|
496
519
|
}
|
|
497
|
-
/**
|
|
520
|
+
/**
|
|
521
|
+
* Membership 视图解析:query 的 logical 形态 → 该真实文件在本 source 下的全部 logical_path。
|
|
522
|
+
* 快路径字面命中;未命中再按真实文件身份(realpath)比对——symlink / `/var`↔`/private/var`
|
|
523
|
+
* 别名视为同一 path(合规 purge 不得因路径形态不同而漏删)。
|
|
524
|
+
*
|
|
525
|
+
* @param sourceId - 源 id
|
|
526
|
+
* @param logical - 查询路径(已 slash 归一)
|
|
527
|
+
* @returns 命中的存储字面 logical_path 列表(可能含多种拼写形态)
|
|
528
|
+
*/
|
|
529
|
+
resolveMembershipPaths(sourceId, logical) {
|
|
530
|
+
const exact = this.db.raw
|
|
531
|
+
.prepare(`SELECT logical_path FROM knowledge_memberships WHERE source_id = ? AND logical_path = ?`)
|
|
532
|
+
.all(sourceId, logical);
|
|
533
|
+
if (exact.length > 0)
|
|
534
|
+
return [...new Set(exact.map((r) => r.logical_path))];
|
|
535
|
+
const queryReal = realIdentitySync(logical);
|
|
536
|
+
if (queryReal === null)
|
|
537
|
+
return [];
|
|
538
|
+
const rows = this.db.raw
|
|
539
|
+
.prepare('SELECT DISTINCT logical_path FROM knowledge_memberships WHERE source_id = ?')
|
|
540
|
+
.all(sourceId);
|
|
541
|
+
const cache = new Map();
|
|
542
|
+
return rows
|
|
543
|
+
.filter((r) => {
|
|
544
|
+
let id = cache.get(r.logical_path);
|
|
545
|
+
if (id === undefined) {
|
|
546
|
+
id = realIdentitySync(r.logical_path);
|
|
547
|
+
cache.set(r.logical_path, id);
|
|
548
|
+
}
|
|
549
|
+
return id !== null && id === queryReal;
|
|
550
|
+
})
|
|
551
|
+
.map((r) => r.logical_path);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 解绑 path;File 仅在零认领时 purge(单文件同步语义,供测试/轻量路径)。
|
|
555
|
+
* 按真实文件身份匹配(见 resolveMembershipPaths)。
|
|
556
|
+
*
|
|
557
|
+
* @returns 实际解绑的存储字面 logical_path(供 hit log 按真实字面清痕)
|
|
558
|
+
*/
|
|
498
559
|
removeFile(sourceId, path) {
|
|
499
560
|
const logical = path.replace(/\\/g, '/');
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
.
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
.
|
|
511
|
-
|
|
512
|
-
|
|
561
|
+
const matched = this.resolveMembershipPaths(String(sourceId), logical);
|
|
562
|
+
if (matched.length === 0)
|
|
563
|
+
return [];
|
|
564
|
+
const fileIds = new Set();
|
|
565
|
+
for (const stored of matched) {
|
|
566
|
+
const row = this.db.raw
|
|
567
|
+
.prepare(`SELECT file_id FROM knowledge_memberships WHERE source_id = ? AND logical_path = ?`)
|
|
568
|
+
.get(String(sourceId), stored);
|
|
569
|
+
if (row)
|
|
570
|
+
fileIds.add(row.file_id);
|
|
571
|
+
this.db.raw
|
|
572
|
+
.prepare('DELETE FROM knowledge_memberships WHERE source_id = ? AND logical_path = ?')
|
|
573
|
+
.run(String(sourceId), stored);
|
|
574
|
+
}
|
|
575
|
+
for (const fileId of fileIds) {
|
|
576
|
+
const n = this.db.raw
|
|
577
|
+
.prepare('SELECT COUNT(*) AS n FROM knowledge_memberships WHERE file_id = ?')
|
|
578
|
+
.get(fileId).n;
|
|
579
|
+
if (n === 0)
|
|
580
|
+
this.purgeFileRow(fileId);
|
|
581
|
+
}
|
|
582
|
+
return matched;
|
|
513
583
|
}
|
|
514
584
|
/**
|
|
515
585
|
* 解绑 path + 可能的 purge(异步让出)。
|
|
516
586
|
* 单文件 purge 也可能删数千 chunk——必须让出,否则 Engine 调度不了 HTTP 回包。
|
|
587
|
+
*
|
|
588
|
+
* @returns 实际解绑的存储字面 logical_path(供 hit log 按真实字面清痕)
|
|
517
589
|
*/
|
|
518
590
|
async removeFileAsync(sourceId, path, opts) {
|
|
519
591
|
const logical = path.replace(/\\/g, '/');
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
.
|
|
531
|
-
|
|
532
|
-
|
|
592
|
+
const matched = this.resolveMembershipPaths(String(sourceId), logical);
|
|
593
|
+
if (matched.length === 0)
|
|
594
|
+
return [];
|
|
595
|
+
const fileIds = new Set();
|
|
596
|
+
for (const stored of matched) {
|
|
597
|
+
const row = this.db.raw
|
|
598
|
+
.prepare(`SELECT file_id FROM knowledge_memberships WHERE source_id = ? AND logical_path = ?`)
|
|
599
|
+
.get(String(sourceId), stored);
|
|
600
|
+
if (row)
|
|
601
|
+
fileIds.add(row.file_id);
|
|
602
|
+
this.db.raw
|
|
603
|
+
.prepare('DELETE FROM knowledge_memberships WHERE source_id = ? AND logical_path = ?')
|
|
604
|
+
.run(String(sourceId), stored);
|
|
605
|
+
}
|
|
606
|
+
for (const fileId of fileIds) {
|
|
607
|
+
const n = this.db.raw
|
|
608
|
+
.prepare('SELECT COUNT(*) AS n FROM knowledge_memberships WHERE file_id = ?')
|
|
609
|
+
.get(fileId).n;
|
|
610
|
+
if (n === 0)
|
|
611
|
+
await this.purgeFileRowAsync(fileId, opts);
|
|
612
|
+
}
|
|
613
|
+
return matched;
|
|
533
614
|
}
|
|
534
615
|
/**
|
|
535
616
|
* 批量解绑:每 `yieldEvery` 条让出事件循环。
|
|
@@ -552,24 +633,47 @@ export class KnowledgeIndexStore {
|
|
|
552
633
|
this.removeFile(sourceId, p);
|
|
553
634
|
}
|
|
554
635
|
/**
|
|
555
|
-
*
|
|
636
|
+
* 子树成员收集:前缀 SQL 命中 ∪ 真实身份落在子树内的别名形态
|
|
637
|
+
* (防 `/var`↔`/private/var`、symlink 前缀漏删)。
|
|
638
|
+
*
|
|
639
|
+
* @param sourceId - 源 id
|
|
640
|
+
* @param prefix - 子树前缀(已 slash 归一、去尾斜杠)
|
|
641
|
+
* @returns 命中的存储字面 logical_path 列表(去重)
|
|
556
642
|
*/
|
|
557
|
-
|
|
558
|
-
const prefix = path.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
643
|
+
collectTreeMembershipPaths(sourceId, prefix) {
|
|
559
644
|
const rows = this.db.raw
|
|
560
645
|
.prepare(`SELECT logical_path FROM knowledge_memberships
|
|
561
646
|
WHERE source_id = ? AND (logical_path = ? OR logical_path LIKE ? ESCAPE '\\')`)
|
|
562
647
|
.all(String(sourceId), prefix, `${prefix.replace(/[\\%_]/g, (c) => `\\${c}`)}/%`);
|
|
563
|
-
|
|
648
|
+
const found = new Set(rows.map((r) => r.logical_path));
|
|
649
|
+
const prefixReal = realIdentitySync(prefix);
|
|
650
|
+
if (prefixReal !== null) {
|
|
651
|
+
const all = this.db.raw
|
|
652
|
+
.prepare('SELECT DISTINCT logical_path FROM knowledge_memberships WHERE source_id = ?')
|
|
653
|
+
.all(String(sourceId));
|
|
654
|
+
for (const r of all) {
|
|
655
|
+
if (found.has(r.logical_path))
|
|
656
|
+
continue;
|
|
657
|
+
const id = realIdentitySync(r.logical_path);
|
|
658
|
+
if (id !== null && (id === prefixReal || id.startsWith(`${prefixReal}/`))) {
|
|
659
|
+
found.add(r.logical_path);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return [...found];
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* 删除 path 及子树:先收集 logical_path,再分批异步解绑 + purge。
|
|
667
|
+
*/
|
|
668
|
+
async removePathTreeAsync(sourceId, path, opts) {
|
|
669
|
+
const prefix = path.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
670
|
+
return this.removeFilesAsync(sourceId, this.collectTreeMembershipPaths(String(sourceId), prefix), opts);
|
|
564
671
|
}
|
|
565
672
|
removePathTree(sourceId, path) {
|
|
566
673
|
const prefix = path.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
567
|
-
const
|
|
568
|
-
.
|
|
569
|
-
|
|
570
|
-
.all(String(sourceId), prefix, `${prefix.replace(/[\\%_]/g, (c) => `\\${c}`)}/%`);
|
|
571
|
-
for (const r of rows)
|
|
572
|
-
this.removeFile(sourceId, r.logical_path);
|
|
674
|
+
for (const stored of this.collectTreeMembershipPaths(String(sourceId), prefix)) {
|
|
675
|
+
this.removeFile(sourceId, stored);
|
|
676
|
+
}
|
|
573
677
|
}
|
|
574
678
|
/**
|
|
575
679
|
* 清空源认领:分批 purge,避免一次清数千 File 堵死事件循环。
|
|
@@ -613,8 +717,9 @@ export class KnowledgeIndexStore {
|
|
|
613
717
|
this.purgeFileRow(r.file_id);
|
|
614
718
|
}
|
|
615
719
|
}
|
|
720
|
+
/** 单文件 purge:透传真实身份匹配到的存储字面(供 hit log 清痕) */
|
|
616
721
|
purgePath(sourceId, path) {
|
|
617
|
-
this.removeFile(sourceId, path);
|
|
722
|
+
return this.removeFile(sourceId, path);
|
|
618
723
|
}
|
|
619
724
|
/** 按 fileId 物理删除(membership 已清) */
|
|
620
725
|
purgeFile(fileId) {
|
|
@@ -793,14 +898,34 @@ export class KnowledgeIndexStore {
|
|
|
793
898
|
.all(...ftsIds, ...opts.sourceIds);
|
|
794
899
|
}
|
|
795
900
|
if (!rows || rows.length === 0) {
|
|
796
|
-
|
|
797
|
-
|
|
901
|
+
// 兜底匹配语义(B+):SQL 子串取候选、按 token 分类给精确判定——
|
|
902
|
+
// · 2–3 字符纯 ASCII 字母数字词:词边界命中(防跨词字母碰撞 be ⊂ obeswy)。
|
|
903
|
+
// GLOB 字符类回溯较 LIKE 慢约 10×(20k chunk 实测 235ms vs 23ms),故仅此小类承担,
|
|
904
|
+
// 且只在 FTS 零命中时触发。不用「LIKE 取候选 + JS 边界校验」:LIMIT 窗口会被子串噪音
|
|
905
|
+
// 占满而丢真命中,GLOB 在 SQL 侧精确过滤无此问题。
|
|
906
|
+
// · 其余 token(≥ SUBSTRING_FALLBACK_MIN_CHARS、非纯 ASCII 字母数字):子串命中——
|
|
907
|
+
// 长词保留子词/词干召回(assembly → contextAssembly;其边界命中是子串命中的子集,
|
|
908
|
+
// 词边界子句纯冗余);非 ASCII(CJK/韩/西里尔/混合)无词边界语义,显式并入子串。
|
|
909
|
+
// 边界 = 非 [a-z0-9] 字符(含 _/标点/CJK):_ 与 FTS unicode61 切分一致;CJK 作为边界是
|
|
910
|
+
// **有意放宽**(「api接口」须能命中 api),并非对齐 unicode61(其视 foo文bar 为单 token)。
|
|
911
|
+
// GLOB 不变式由 ^[a-z0-9]+$ 守门:将来 tokenizer 放行 `-`/`.`/`*`/`[`/`]` 等也不会进 GLOB 分支。
|
|
912
|
+
const matchClauses = [];
|
|
913
|
+
const matchParams = [];
|
|
798
914
|
for (const token of tokens) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
915
|
+
if (!isBoundaryToken(token)) {
|
|
916
|
+
const likePattern = `%${token.toLowerCase().replace(/[\\%_]/g, (c) => `\\${c}`)}%`;
|
|
917
|
+
matchClauses.push(`LOWER(c.text) LIKE ? ESCAPE '\\'`);
|
|
918
|
+
matchParams.push(likePattern);
|
|
919
|
+
matchClauses.push(`LOWER(m.logical_path) LIKE ? ESCAPE '\\'`);
|
|
920
|
+
matchParams.push(likePattern);
|
|
921
|
+
}
|
|
922
|
+
else {
|
|
923
|
+
const globPattern = `*[^a-z0-9]${token}[^a-z0-9]*`;
|
|
924
|
+
matchClauses.push(`(' ' || LOWER(c.text) || ' ') GLOB ?`);
|
|
925
|
+
matchParams.push(globPattern);
|
|
926
|
+
matchClauses.push(`(' ' || LOWER(m.logical_path) || ' ') GLOB ?`);
|
|
927
|
+
matchParams.push(globPattern);
|
|
928
|
+
}
|
|
804
929
|
}
|
|
805
930
|
rows = this.db.raw
|
|
806
931
|
.prepare(`SELECT c.id, c.file_id, c.ordinal, c.text, c.start_line, c.end_line,
|
|
@@ -809,9 +934,9 @@ export class KnowledgeIndexStore {
|
|
|
809
934
|
JOIN knowledge_files f ON f.id = c.file_id AND f.status <> 'indexing'
|
|
810
935
|
JOIN knowledge_memberships m ON m.file_id = c.file_id
|
|
811
936
|
WHERE m.source_id IN (${placeholders})
|
|
812
|
-
AND (${
|
|
937
|
+
AND (${matchClauses.join(' OR ')})
|
|
813
938
|
LIMIT ?`)
|
|
814
|
-
.all(...opts.sourceIds, ...
|
|
939
|
+
.all(...opts.sourceIds, ...matchParams, Math.max(limit * 8, 64));
|
|
815
940
|
}
|
|
816
941
|
const byChunk = new Map();
|
|
817
942
|
for (const r of rows) {
|
|
@@ -819,6 +944,8 @@ export class KnowledgeIndexStore {
|
|
|
819
944
|
if (!h) {
|
|
820
945
|
if (byChunk.size >= limit * 3)
|
|
821
946
|
continue;
|
|
947
|
+
// 打分仍是子串口径(scoreKeywordCoverage 共享 memory 域):与匹配语义的差异是有意留待统一的
|
|
948
|
+
// 已知项(见 v0.97.2 CHANGELOG 遗留),本层不改共享打分契约。
|
|
822
949
|
const score = scoreKeywordCoverage({ content: r.text, tags: r.logical_path }, tokenDetail);
|
|
823
950
|
h = {
|
|
824
951
|
chunkId: r.id,
|
|
@@ -838,7 +965,12 @@ export class KnowledgeIndexStore {
|
|
|
838
965
|
h.sourceIds.push(r.source_id);
|
|
839
966
|
h.logicalPaths[r.source_id] = r.logical_path;
|
|
840
967
|
}
|
|
968
|
+
// 弱命中地板(执行分词器既有契约:weak 滑窗二元组单独命中不足以过相关性地板):
|
|
969
|
+
// strong 命中直接过;weak-only 命中须过 WEAK_ONLY_SCORE_FLOOR——防中文虚词二元组
|
|
970
|
+
// (的时/是的…)擦边命中灌满结果集,同时保住长段复合查询的二元组重叠召回。
|
|
841
971
|
return [...byChunk.values()]
|
|
972
|
+
.filter((h) => tokenDetail.strong.some((t) => tokenMatchesBPlus(t, h.text, h.path)) ||
|
|
973
|
+
h.score >= WEAK_ONLY_SCORE_FLOOR)
|
|
842
974
|
.sort((a, b) => b.score - a.score)
|
|
843
975
|
.slice(0, limit)
|
|
844
976
|
.map((h) => ({
|