@xopcai/xopc 0.0.455 → 0.0.456
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{automations-page-Dt_Z1UTT.js → automations-page-CgQDpSpK.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-BhHgruhH.js → automations-workspace-CWEDraTP.js} +2 -2
- package/dist/gateway/static/root/assets/{chat-page-dY6aCCRx.js → chat-page-BjYumhaI.js} +19 -19
- package/dist/gateway/static/root/assets/{desktop-pet-DlTuGzZ2.js → desktop-pet-Cn1TfGz4.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-narrative-cBFIPXzR.js → desktop-pet-narrative-JqMsz4rn.js} +1 -1
- package/dist/gateway/static/root/assets/{index-CZI3VGGW.js → index-DBlVVXOA.js} +5 -5
- package/dist/gateway/static/root/assets/index-DpkEeFEQ.css +1 -0
- package/dist/gateway/static/root/assets/{note-detail-panel-anM38aV6.js → note-detail-panel-C6s0WlNL.js} +2 -2
- package/dist/gateway/static/root/assets/{notes-page-BsZmT7Zw.js → notes-page-CR7dNVDi.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-page-BSCNuRMT.js → personal-page-C89kLOIL.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-ibZZ_w51.js → project-detail-page-sHcdluTm.js} +1 -1
- package/dist/gateway/static/root/assets/{route-preload-anuckzRl.js → route-preload-DrfQJkmW.js} +2 -2
- package/dist/gateway/static/root/assets/{settings-page-DAc5n-mM.js → settings-page-C4CYw21O.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-BJok6V1K.js → task-detail-page-DBnkT1Nj.js} +1 -1
- package/dist/gateway/static/root/assets/tool-friendly-title-CP35P4VA.js +2 -0
- package/dist/gateway/static/root/assets/understanding-refresh-store-CIpGYSl0.js +1 -0
- package/dist/gateway/static/root/assets/user-model-page-Bbi2MpIS.js +2 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +7 -2
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +8 -1
- package/dist/src/agent/background-review/run-background-review.js +48 -4
- package/dist/src/agent/context/audit.js +18 -0
- package/dist/src/agent/context/coordinator.d.ts +4 -0
- package/dist/src/agent/context/coordinator.js +33 -7
- package/dist/src/agent/context/deep-recall.d.ts +33 -0
- package/dist/src/agent/context/deep-recall.js +190 -0
- package/dist/src/agent/context/execution-context.js +29 -5
- package/dist/src/agent/context/execution-context.types.d.ts +2 -0
- package/dist/src/agent/context/memory-claim-grounding.d.ts +2 -0
- package/dist/src/agent/context/memory-claim-grounding.js +20 -0
- package/dist/src/agent/context/recall-grounding.d.ts +3 -0
- package/dist/src/agent/context/recall-grounding.js +31 -0
- package/dist/src/agent/embedded/run-turn.js +46 -0
- package/dist/src/agent/external-tools/cliProvider.js +2 -2
- package/dist/src/agent/external-tools/composio-provider.js +2 -2
- package/dist/src/agent/external-tools/endpoint-provider.js +3 -3
- package/dist/src/agent/memory/context-recovery.d.ts +1 -1
- package/dist/src/agent/memory/index.js +1 -1
- package/dist/src/agent/service/process-direct-streaming.js +1 -1
- package/dist/src/agent/service.d.ts +1 -0
- package/dist/src/agent/service.js +6 -3
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/tools/factory.js +22 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +7 -1
- package/dist/src/agent/tools/personal-memory-tool.d.ts +11 -0
- package/dist/src/agent/tools/personal-memory-tool.js +387 -0
- package/dist/src/agent/tools/personal-read-tool.js +1 -1
- package/dist/src/agent/tools/session-search-tool.d.ts +2 -0
- package/dist/src/agent/tools/session-search-tool.js +21 -7
- package/dist/src/agent/tools/user-context-tool.js +11 -1
- package/dist/src/agent/tools/xopc-use-tool.js +2 -2
- package/dist/src/agent-catalog/capabilities.js +2 -2
- package/dist/src/agent-catalog/repository.js +1 -1
- package/dist/src/automations/api/routes.js +2 -2
- package/dist/src/automations/capabilities/drafts.js +1 -1
- package/dist/src/automations/capabilities/write.js +1 -1
- package/dist/src/automations/configuration-conversation.js +1 -1
- package/dist/src/browser/providers/browser-ext-install.js +1 -1
- package/dist/src/capabilities/runtime/dispatcher.js +1 -1
- package/dist/src/capabilities/runtime/product.js +1 -1
- package/dist/src/cli/commands/agents.js +1 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard/model.js +1 -1
- package/dist/src/cli/utils/init-workspace-core.js +1 -1
- package/dist/src/computer/endpoint-transport.js +1 -1
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/config/schema.d.ts +6 -0
- package/dist/src/config/schema.js +6 -0
- package/dist/src/execution-environments/local-worktree-manager.js +1 -1
- package/dist/src/extensions/agent-plugins/skill-catalog.js +1 -1
- package/dist/src/extensions/agent-plugins/validation.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agents-admin.js +2 -2
- package/dist/src/gateway/global-defaults-admin.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +6 -0
- package/dist/src/gateway/hono/routes/agents.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
- package/dist/src/gateway/hono/routes/local-app-run-streams.js +1 -1
- package/dist/src/gateway/hono/routes/notes.js +2 -2
- package/dist/src/gateway/hono/routes/phone-setup.js +1 -1
- package/dist/src/gateway/hono/routes/projects.js +2 -2
- package/dist/src/gateway/hono/routes/session-input-handler.js +1 -1
- package/dist/src/gateway/hono/routes/tasks.js +2 -2
- package/dist/src/gateway/hono/routes/user-model.js +47 -7
- package/dist/src/gateway/image-generation-setup.js +1 -1
- package/dist/src/gateway/service/config-coordinator.d.ts +6 -0
- package/dist/src/gateway/service.js +4 -4
- package/dist/src/gateway/xopc-cloud-capability-setup.js +1 -1
- package/dist/src/home-intelligence/host.js +2 -2
- package/dist/src/imports/importService.js +1 -1
- package/dist/src/knowledge-memory/index.js +2 -2
- package/dist/src/knowledge-memory/repository.d.ts +6 -0
- package/dist/src/knowledge-memory/repository.js +49 -1
- package/dist/src/knowledge-memory/usage-policy.js +7 -7
- package/dist/src/local-apps/automation-proposals.js +1 -1
- package/dist/src/local-apps/capabilities/automation-policy.js +1 -1
- package/dist/src/local-apps/capabilities/delegate.js +3 -3
- package/dist/src/local-apps/p1-services.js +1 -1
- package/dist/src/local-apps/service.js +1 -1
- package/dist/src/memory-learning/work-capture.js +3 -1
- package/dist/src/personal-agent/policy.d.ts +1 -1
- package/dist/src/personal-agent/policy.js +2 -1
- package/dist/src/personal-agent/prompts.js +7 -1
- package/dist/src/personal-agent/service.js +1 -1
- package/dist/src/providers/model-catalog-persistence.js +1 -1
- package/dist/src/runtime-tools/archive.js +1 -1
- package/dist/src/session/history-recall-policy.d.ts +6 -0
- package/dist/src/session/history-recall-policy.js +48 -0
- package/dist/src/tasks/capabilities/read.js +2 -2
- package/dist/src/tasks/capabilities/write.js +1 -1
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/user-context/config.d.ts +12 -0
- package/dist/src/user-context/config.js +14 -1
- package/dist/src/user-context/memory-version.d.ts +2 -0
- package/dist/src/user-context/memory-version.js +12 -0
- package/dist/src/user-model/capture/evidence-policy.d.ts +45 -0
- package/dist/src/user-model/capture/evidence-policy.js +143 -0
- package/dist/src/user-model/capture/executor.d.ts +1 -0
- package/dist/src/user-model/capture/executor.js +68 -8
- package/dist/src/user-model/capture/semantic.d.ts +16 -0
- package/dist/src/user-model/capture/semantic.js +66 -12
- package/dist/src/user-model/repository.js +11 -0
- package/dist/src/user-model/usage-policy.js +5 -5
- package/dist/src/voice/realtime/persona-context.js +1 -1
- package/dist/src/work-discovery/service.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/index-Bj5exyow.css +0 -1
- package/dist/gateway/static/root/assets/tool-friendly-title-DC8_9-Lo.js +0 -2
- package/dist/gateway/static/root/assets/understanding-refresh-store-Ihz2p9Vg.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-1eYattnk.js +0 -2
|
@@ -13,6 +13,7 @@ import { getSessionConfig } from "../../storage/sqlite/config-repository.js";
|
|
|
13
13
|
import "../../storage/sqlite/index.js";
|
|
14
14
|
import { normalizeAgentId } from "../../agent-catalog/id.js";
|
|
15
15
|
import { init_agent_scope, listAgentEntries } from "../../agent/agent-scope.js";
|
|
16
|
+
import { AgentCatalogService } from "../../agent-catalog/service.js";
|
|
16
17
|
import { init_paths } from "../../config/paths.js";
|
|
17
18
|
import { getAgentDefaultModelRef, init_schema } from "../../config/schema.js";
|
|
18
19
|
import { resolveEffectiveAgentProfile } from "../../config/agent-profile.js";
|
|
@@ -24,7 +25,6 @@ import { getSessionInteractionPolicy, setSessionInteractionPolicy } from "../../
|
|
|
24
25
|
import { ProjectService } from "../../projects/project-service.js";
|
|
25
26
|
import { inferSuggestedProjectDefaultAgentId } from "../../projects/project-agent-suggestion.js";
|
|
26
27
|
import "../../projects/index.js";
|
|
27
|
-
import { AgentCatalogService } from "../../agent-catalog/service.js";
|
|
28
28
|
import { buildSessionTimeline } from "../../session/transcript-outline.js";
|
|
29
29
|
import { transcriptRowsToClientHistory } from "../../session/client-history.js";
|
|
30
30
|
import { createCreateShareTool, isShareToolAvailable } from "../../agent/tools/create-share-tool.js";
|
|
@@ -156,6 +156,12 @@ export declare const ContextPlanningConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
156
156
|
maxAssertions: z.ZodDefault<z.ZodNumber>;
|
|
157
157
|
maxKnowledge: z.ZodDefault<z.ZodNumber>;
|
|
158
158
|
maxChars: z.ZodDefault<z.ZodNumber>;
|
|
159
|
+
deepRecall: z.ZodDefault<z.ZodObject<{
|
|
160
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
161
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
162
|
+
maxSessions: z.ZodDefault<z.ZodNumber>;
|
|
163
|
+
maxEvidence: z.ZodDefault<z.ZodNumber>;
|
|
164
|
+
}, z.core.$strict>>;
|
|
159
165
|
compaction: z.ZodDefault<z.ZodObject<{
|
|
160
166
|
personalIdle: z.ZodDefault<z.ZodObject<{
|
|
161
167
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -290,6 +296,12 @@ export declare const UserContextConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
290
296
|
maxAssertions: z.ZodDefault<z.ZodNumber>;
|
|
291
297
|
maxKnowledge: z.ZodDefault<z.ZodNumber>;
|
|
292
298
|
maxChars: z.ZodDefault<z.ZodNumber>;
|
|
299
|
+
deepRecall: z.ZodDefault<z.ZodObject<{
|
|
300
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
301
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
302
|
+
maxSessions: z.ZodDefault<z.ZodNumber>;
|
|
303
|
+
maxEvidence: z.ZodDefault<z.ZodNumber>;
|
|
304
|
+
}, z.core.$strict>>;
|
|
293
305
|
compaction: z.ZodDefault<z.ZodObject<{
|
|
294
306
|
personalIdle: z.ZodDefault<z.ZodObject<{
|
|
295
307
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -16,7 +16,7 @@ function resolveKnowledgeReadPolicy(config) {
|
|
|
16
16
|
contentSources: config.contentSources
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
var DEFAULT_PERSONAL_IDLE_COMPACTION, DEFAULT_CONTEXT_COMPACTION_POLICY, ContextCompactionPolicySchema, WritePolicySchema, MaintenanceTimeSchema, UserModelConfigSchema, KnowledgeMemoryConfigSchema, ContextPlanningConfigSchema, HomeIntelligenceConfigSchema, UserContextConfigSchema;
|
|
19
|
+
var DEFAULT_PERSONAL_IDLE_COMPACTION, DEFAULT_CONTEXT_COMPACTION_POLICY, ContextCompactionPolicySchema, WritePolicySchema, MaintenanceTimeSchema, UserModelConfigSchema, KnowledgeMemoryConfigSchema, DeepRecallConfigSchema, ContextPlanningConfigSchema, HomeIntelligenceConfigSchema, UserContextConfigSchema;
|
|
20
20
|
var init_config = __esmMin((() => {
|
|
21
21
|
init_response_language();
|
|
22
22
|
DEFAULT_PERSONAL_IDLE_COMPACTION = {
|
|
@@ -207,17 +207,30 @@ var init_config = __esmMin((() => {
|
|
|
207
207
|
writeStrategy: "local-first",
|
|
208
208
|
allowExternalWrites: false
|
|
209
209
|
});
|
|
210
|
+
DeepRecallConfigSchema = z.object({
|
|
211
|
+
enabled: z.boolean().default(true),
|
|
212
|
+
timeoutMs: z.number().int().min(100).max(3e4).default(8e3),
|
|
213
|
+
maxSessions: z.number().int().min(1).max(200).default(60),
|
|
214
|
+
maxEvidence: z.number().int().min(2).max(12).default(6)
|
|
215
|
+
}).strict().default({
|
|
216
|
+
enabled: true,
|
|
217
|
+
timeoutMs: 8e3,
|
|
218
|
+
maxSessions: 60,
|
|
219
|
+
maxEvidence: 6
|
|
220
|
+
});
|
|
210
221
|
ContextPlanningConfigSchema = z.object({
|
|
211
222
|
enabled: z.boolean().default(true),
|
|
212
223
|
maxAssertions: z.number().int().min(1).max(100).default(20),
|
|
213
224
|
maxKnowledge: z.number().int().min(0).max(100).default(12),
|
|
214
225
|
maxChars: z.number().int().min(500).max(5e4).default(6e3),
|
|
226
|
+
deepRecall: DeepRecallConfigSchema,
|
|
215
227
|
compaction: ContextCompactionPolicySchema
|
|
216
228
|
}).strict().default({
|
|
217
229
|
enabled: true,
|
|
218
230
|
maxAssertions: 20,
|
|
219
231
|
maxKnowledge: 12,
|
|
220
232
|
maxChars: 6e3,
|
|
233
|
+
deepRecall: DeepRecallConfigSchema.parse({}),
|
|
221
234
|
compaction: DEFAULT_CONTEXT_COMPACTION_POLICY
|
|
222
235
|
});
|
|
223
236
|
HomeIntelligenceConfigSchema = z.object({
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
//#region src/user-context/memory-version.ts
|
|
3
|
+
/** Opaque revision for optimistic chat edits; includes scope and lifecycle changes. */
|
|
4
|
+
function memoryVersion(value) {
|
|
5
|
+
if (value && typeof value === "object" && "retrievalSnippet" in value) {
|
|
6
|
+
const { retrievalSnippet: _snippet, ...record } = value;
|
|
7
|
+
value = record;
|
|
8
|
+
}
|
|
9
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { memoryVersion };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AssertionAuthority, AssertionKind, AssertionVolatility } from '../domain.js';
|
|
2
|
+
export interface OwnerSupport {
|
|
3
|
+
allowed: boolean;
|
|
4
|
+
direct: boolean;
|
|
5
|
+
reason?: 'non_owner_content' | 'temporary_context' | 'local_instruction' | 'unsupported_attribution';
|
|
6
|
+
fingerprint: string;
|
|
7
|
+
}
|
|
8
|
+
/** Extraction can only name operations supported by the execution-context consumer. */
|
|
9
|
+
export declare function supportsResponseApplicability(applicability?: Record<string, unknown>): boolean;
|
|
10
|
+
/** Inspect the source clause, not merely the extractor's chosen substring or authority label. */
|
|
11
|
+
export declare function assessOwnerSupport(input: {
|
|
12
|
+
text: string;
|
|
13
|
+
quote: string;
|
|
14
|
+
kind?: AssertionKind;
|
|
15
|
+
authority?: AssertionAuthority;
|
|
16
|
+
volatility?: AssertionVolatility;
|
|
17
|
+
validTo?: number;
|
|
18
|
+
observedAt?: number;
|
|
19
|
+
}): OwnerSupport;
|
|
20
|
+
export declare function hasOwnerMemoryDirective(text: string, command: 'remember' | 'correct' | 'forget' | 'confirm'): boolean;
|
|
21
|
+
/** Re-evaluate authority and independent support at both parse and commit boundaries. */
|
|
22
|
+
export declare function assessAssertionSupport(input: {
|
|
23
|
+
kind: AssertionKind;
|
|
24
|
+
authority: AssertionAuthority;
|
|
25
|
+
volatility: AssertionVolatility;
|
|
26
|
+
validTo?: number;
|
|
27
|
+
observedAt: number;
|
|
28
|
+
action: 'create' | 'merge' | 'replace';
|
|
29
|
+
sources: Array<{
|
|
30
|
+
ref: string;
|
|
31
|
+
role: string;
|
|
32
|
+
text: string;
|
|
33
|
+
quote: string;
|
|
34
|
+
}>;
|
|
35
|
+
}): {
|
|
36
|
+
allowed: boolean;
|
|
37
|
+
authority: AssertionAuthority;
|
|
38
|
+
reasonCode?: string;
|
|
39
|
+
};
|
|
40
|
+
/** Source attribution for work facts does not require a first-person user statement. */
|
|
41
|
+
export declare function isOwnerAuthoredSpan(text: string, quote: string): boolean;
|
|
42
|
+
/** A bounded repair hint; these clauses remain subject to normal model and host admission. */
|
|
43
|
+
export declare function directPreferenceClauses(text: string): string[];
|
|
44
|
+
/** Choices remain observations; these hints never authorize an explicit user fact. */
|
|
45
|
+
export declare function observedChoiceClauses(text: string): string[];
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
//#region src/user-model/capture/evidence-policy.ts
|
|
2
|
+
/** Extraction can only name operations supported by the execution-context consumer. */
|
|
3
|
+
function supportsResponseApplicability(applicability = {}) {
|
|
4
|
+
const operation = applicability.operation;
|
|
5
|
+
return operation === void 0 || operation === "response" || Array.isArray(operation) && operation.length > 0 && operation.every((value) => value === "response");
|
|
6
|
+
}
|
|
7
|
+
const SELF = /(?:我(?:自己|本人|平时|一般|通常|长期|一直|一贯|更|比较|还是|现在|最|特别|主要|也|其实|的|经常|习惯|倾向|偏好|喜欢|希望|需要|是|叫|住|会|用|选)|对我来说)|\b(?:i|my|me|mine)\b/iu;
|
|
8
|
+
const DIRECT_PREFERENCE = /我(?:自己|本人)?(?:一直|长期|一贯|平时|通常|一般|也|更|比较|最|特别)?(?:不|不太|并不|不再)?(?:喜欢|偏好|习惯|倾向|希望)|(?:我|我的).{0,12}(?:长期习惯|阅读习惯|沟通习惯|固定偏好)|以后|今后|从现在起|from now on|\bi (?:prefer|like|always|usually)\b|\b(?:works? (?:best|better) for me|my preference|keep (?:answers|responses) concise)\b/iu;
|
|
9
|
+
const FOREIGN = /客户|同事|别人|他人|朋友说|原话|原文|引用|引文|翻译|润色|改写|示例|台词|角色|假设|假如|虚构|不是我的|并非我的|\b(?:quote|quoted|translate|rewrite|example|fiction|hypothetical|suppose|customer|colleague)\b/iu;
|
|
10
|
+
const HYPOTHETICAL = /假设|假如|如果我|要是我|倘若|虚构|角色设定|(?:不是|并非).{0,8}(?:我|自述|事实)|\b(?:hypothetical|suppose|if i|fictional|role.?play)\b/iu;
|
|
11
|
+
const TEMPORARY = /这次|本次|今天|今晚|暂时|临时|现在先|目前先|这一轮|这周|本周|\b(?:this time|today|tonight|for now|just for|this week|this turn)\b/iu;
|
|
12
|
+
const LOCAL_INSTRUCTION = /(?:只|仅)(?:需|要)?(?:回复|回答|输出)|这(?:个|张|次).{0,12}(?:标题|海报|按钮|改成)|\b(?:reply|answer|output) (?:only|just)|\b(?:this title|this button)\b/iu;
|
|
13
|
+
const CHOICE = /我选|我还是选|选.{0,12}(?:版|种|项)|这版|更顺|更好读|容易扫读|\b(?:i (?:choose|pick)|option|version|easier to (?:read|scan))\b/iu;
|
|
14
|
+
function maskNonOwnerSpans(raw) {
|
|
15
|
+
let result = raw.normalize("NFKC");
|
|
16
|
+
const mask = (match) => match.replace(/[^\r\n]/gu, " ");
|
|
17
|
+
result = result.replace(/```[\s\S]*?```|~~~[\s\S]*?~~~/gu, mask).replace(/^\s*>[^\n]*/gmu, mask).replace(/<(?:quote|blockquote|untrusted_text)\b[^>]*>[\s\S]*?<\/(?:quote|blockquote|untrusted_text)>/giu, mask);
|
|
18
|
+
const original = result;
|
|
19
|
+
result = result.replace(/“[^”]*”|「[^」]*」|『[^』]*』|‘[^’]*’|"[^"\n]+"|(?<!\p{L})'[^'\n]+'(?!\p{L})/gu, (match, offset) => {
|
|
20
|
+
const prefix = original.slice(Math.max(0, offset - 100), offset).split(/[。.;;!?!?\n]/u).at(-1) ?? "";
|
|
21
|
+
return SELF.test(prefix) && !FOREIGN.test(prefix) ? match : mask(match);
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/** Inspect the source clause, not merely the extractor's chosen substring or authority label. */
|
|
26
|
+
function assessOwnerSupport(input) {
|
|
27
|
+
const source = input.text.normalize("NFKC");
|
|
28
|
+
const quote = input.quote.normalize("NFKC");
|
|
29
|
+
const masked = maskNonOwnerSpans(source);
|
|
30
|
+
const at = source.toLocaleLowerCase().indexOf(quote.toLocaleLowerCase());
|
|
31
|
+
if (at < 0) return {
|
|
32
|
+
allowed: false,
|
|
33
|
+
direct: false,
|
|
34
|
+
reason: "unsupported_attribution",
|
|
35
|
+
fingerprint: ""
|
|
36
|
+
};
|
|
37
|
+
const segment = masked.slice(at, at + quote.length).trim();
|
|
38
|
+
const left = source.slice(0, at).search(/[^。.;;!?!?\n]*$/u);
|
|
39
|
+
const tail = source.slice(at + quote.length).search(/[。.;;!?!?\n]/u);
|
|
40
|
+
const end = tail < 0 ? source.length : at + quote.length + tail;
|
|
41
|
+
const clause = masked.slice(left < 0 ? 0 : left, end).trim();
|
|
42
|
+
const reject = (reason) => ({
|
|
43
|
+
allowed: false,
|
|
44
|
+
direct: false,
|
|
45
|
+
reason,
|
|
46
|
+
fingerprint: ""
|
|
47
|
+
});
|
|
48
|
+
if (masked.slice(at, at + quote.length).replace(/\s+/gu, "") !== source.slice(at, at + quote.length).replace(/\s+/gu, "")) return reject("non_owner_content");
|
|
49
|
+
if (!segment || !clause) return reject("non_owner_content");
|
|
50
|
+
const before = source.slice(left < 0 ? 0 : left, at);
|
|
51
|
+
if (/(?:翻译|润色|改写|客户说|同事说|别人说|\b(?:translate|rewrite|customer said|colleague said)\b)/iu.test(before) && !/(?:另外|而我|我自己|我本人|but i|personally)/iu.test(before)) return reject("non_owner_content");
|
|
52
|
+
if (/^(?:(?:请|帮我|麻烦|把).{0,35}(?:翻译|润色|改写|原话|引用|示例)|(?:translate|rewrite|customer said|colleague said)\b)/iu.test(clause) && !/(?:另外|而我|but i|personally)/iu.test(clause)) return reject("non_owner_content");
|
|
53
|
+
if (HYPOTHETICAL.test(clause)) return reject("non_owner_content");
|
|
54
|
+
if (LOCAL_INSTRUCTION.test(clause) && !DIRECT_PREFERENCE.test(clause)) return reject("local_instruction");
|
|
55
|
+
if (TEMPORARY.test(clause) && !/从今天起|从现在起|from (?:today|now) on/iu.test(clause) && (input.kind !== "current_state" || !Number.isFinite(input.validTo) || input.validTo <= (input.observedAt ?? 0))) return reject("temporary_context");
|
|
56
|
+
if (input.kind === "current_state" && !Number.isFinite(input.validTo)) return reject("temporary_context");
|
|
57
|
+
const direct = input.kind === "preference" || input.kind === "routine" ? DIRECT_PREFERENCE.test(segment) || DIRECT_PREFERENCE.test(clause) || hasOwnerMemoryDirective(clause, "remember") : SELF.test(clause) || DIRECT_PREFERENCE.test(clause);
|
|
58
|
+
if (!direct && !SELF.test(segment) && !CHOICE.test(segment)) return reject("unsupported_attribution");
|
|
59
|
+
return {
|
|
60
|
+
allowed: true,
|
|
61
|
+
direct,
|
|
62
|
+
fingerprint: segment.toLocaleLowerCase().replace(/\s+/gu, " ").trim()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function hasOwnerMemoryDirective(text, command) {
|
|
66
|
+
const owned = maskNonOwnerSpans(text);
|
|
67
|
+
const pattern = {
|
|
68
|
+
remember: /记住|记下|保存.{0,12}(?:偏好|习惯|事实|记忆)|\bremember\b/iu,
|
|
69
|
+
correct: /纠正|更正|修正|改成|改为|\b(?:correct|instead|change to)\b/iu,
|
|
70
|
+
forget: /忘记|忘掉|删除.{0,12}(?:偏好|习惯|事实|记忆)|\bforget\b/iu,
|
|
71
|
+
confirm: /确认.{0,12}(?:偏好|习惯|事实|记忆|这条)|\b(?:confirm|that is correct)\b/iu
|
|
72
|
+
}[command];
|
|
73
|
+
return owned.split(/[。.;;!?!?\n]/u).some((clause) => pattern.test(clause) && !HYPOTHETICAL.test(clause) && !/(?:不要|别|不必|并非|不是).{0,6}(?:记住|保存|删除|忘记|确认)|\b(?:don't|do not|never)\b/iu.test(clause));
|
|
74
|
+
}
|
|
75
|
+
/** Re-evaluate authority and independent support at both parse and commit boundaries. */
|
|
76
|
+
function assessAssertionSupport(input) {
|
|
77
|
+
const reject = (reasonCode) => ({
|
|
78
|
+
allowed: false,
|
|
79
|
+
authority: input.authority,
|
|
80
|
+
reasonCode
|
|
81
|
+
});
|
|
82
|
+
if (!input.sources.length || input.sources.some((source) => source.role !== "user")) return reject("owner_evidence_missing");
|
|
83
|
+
const supports = input.sources.map((source) => assessOwnerSupport({
|
|
84
|
+
...input,
|
|
85
|
+
text: source.text,
|
|
86
|
+
quote: source.quote
|
|
87
|
+
}));
|
|
88
|
+
const invalid = supports.find((support) => !support.allowed);
|
|
89
|
+
if (invalid) return reject(invalid.reason ?? "unsupported_attribution");
|
|
90
|
+
const direct = supports.some((support, index) => support.direct || hasOwnerMemoryDirective(input.sources[index].text, "remember"));
|
|
91
|
+
const authority = input.authority === "user_explicit" && !direct ? "user_observed" : input.authority;
|
|
92
|
+
if (authority === "user_observed" || authority === "system_inferred") {
|
|
93
|
+
const distinctSources = new Set(input.sources.map((source) => source.text.normalize("NFKC").toLocaleLowerCase().replace(/\s+/gu, " ").trim())).size;
|
|
94
|
+
const independentQuotes = new Set(supports.map((support) => support.fingerprint)).size;
|
|
95
|
+
if (input.action !== "merge" && Math.min(distinctSources, independentQuotes) < 2) return reject("independent_owner_support_required");
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
allowed: true,
|
|
99
|
+
authority
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Source attribution for work facts does not require a first-person user statement. */
|
|
103
|
+
function isOwnerAuthoredSpan(text, quote) {
|
|
104
|
+
const source = text.normalize("NFKC");
|
|
105
|
+
const at = source.indexOf(quote.normalize("NFKC"));
|
|
106
|
+
if (at < 0) return false;
|
|
107
|
+
const owned = maskNonOwnerSpans(source).slice(at, at + quote.normalize("NFKC").length).trim();
|
|
108
|
+
return Boolean(owned) && !HYPOTHETICAL.test(owned);
|
|
109
|
+
}
|
|
110
|
+
/** A bounded repair hint; these clauses remain subject to normal model and host admission. */
|
|
111
|
+
function directPreferenceClauses(text) {
|
|
112
|
+
const result = [];
|
|
113
|
+
for (const match of text.matchAll(/[^。.;;!?!?\n]+/gu)) {
|
|
114
|
+
const quote = match[0].trim();
|
|
115
|
+
if (!DIRECT_PREFERENCE.test(quote)) continue;
|
|
116
|
+
const support = assessOwnerSupport({
|
|
117
|
+
text,
|
|
118
|
+
quote,
|
|
119
|
+
kind: "preference"
|
|
120
|
+
});
|
|
121
|
+
if (support.allowed && support.direct) result.push(quote);
|
|
122
|
+
if (result.length === 4) break;
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
/** Choices remain observations; these hints never authorize an explicit user fact. */
|
|
127
|
+
function observedChoiceClauses(text) {
|
|
128
|
+
const result = [];
|
|
129
|
+
for (const match of text.matchAll(/[^。.;;!?!?\n]+/gu)) {
|
|
130
|
+
const quote = match[0].trim();
|
|
131
|
+
if (!CHOICE.test(quote)) continue;
|
|
132
|
+
const support = assessOwnerSupport({
|
|
133
|
+
text,
|
|
134
|
+
quote,
|
|
135
|
+
kind: "preference"
|
|
136
|
+
});
|
|
137
|
+
if (support.allowed && !support.direct) result.push(quote);
|
|
138
|
+
if (result.length === 2) break;
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { assessAssertionSupport, assessOwnerSupport, directPreferenceClauses, hasOwnerMemoryDirective, isOwnerAuthoredSpan, observedChoiceClauses, supportsResponseApplicability };
|
|
@@ -36,6 +36,7 @@ export interface UserModelCaptureResult {
|
|
|
36
36
|
candidateKey: string;
|
|
37
37
|
assertionId?: string;
|
|
38
38
|
outcome: 'created' | 'deduplicated' | 'superseded' | 'conflicted' | 'rejected';
|
|
39
|
+
reasonCode?: string;
|
|
39
40
|
}>;
|
|
40
41
|
}
|
|
41
42
|
export declare function emptyUserModelCaptureResult(): UserModelCaptureResult;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createCollaborationRule, listCollaborationRules } from "../../storage/sqlite/collaboration-rule-repository.js";
|
|
2
2
|
import { createContextEvidence } from "../../storage/sqlite/context-evidence-repository.js";
|
|
3
|
+
import { assessAssertionSupport, assessOwnerSupport, hasOwnerMemoryDirective, supportsResponseApplicability } from "./evidence-policy.js";
|
|
3
4
|
import { createUserGoal, listUserGoals } from "../goals.js";
|
|
4
5
|
import { deleteUserAssertion, getAssertionSlot, getUserAssertion, linkAssertionEvidence, mergeAssertionObservation, reconcileAssertion, setAssertionStatus } from "../repository.js";
|
|
5
6
|
import { createHash } from "node:crypto";
|
|
@@ -30,8 +31,18 @@ function candidateKey(predicate, scopeType, scopeId) {
|
|
|
30
31
|
}
|
|
31
32
|
function executeUserModelInterpretation(input) {
|
|
32
33
|
const result = emptyUserModelCaptureResult();
|
|
34
|
+
for (const rejected of input.interpretation.rejectedCandidates ?? []) {
|
|
35
|
+
result.proposed++;
|
|
36
|
+
result.rejected++;
|
|
37
|
+
result.outputs.push({
|
|
38
|
+
...rejected,
|
|
39
|
+
outcome: "rejected"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const commandAllowed = (command) => input.evidence.some((source) => source.role === "user" && hasOwnerMemoryDirective(source.text, command));
|
|
33
43
|
const targets = input.interpretation.targetAssertionIds.flatMap((id) => getUserAssertion(id) ?? []);
|
|
34
44
|
if (input.interpretation.intent === "forget") {
|
|
45
|
+
if (!commandAllowed("forget")) return result;
|
|
35
46
|
for (const target of targets) {
|
|
36
47
|
deleteUserAssertion(target.id);
|
|
37
48
|
result.outputs.push({
|
|
@@ -43,7 +54,7 @@ function executeUserModelInterpretation(input) {
|
|
|
43
54
|
}
|
|
44
55
|
return result;
|
|
45
56
|
}
|
|
46
|
-
if (input.interpretation.intent === "confirm" && input.policy.write !== "deny") for (const target of targets) {
|
|
57
|
+
if (input.interpretation.intent === "confirm" && commandAllowed("confirm") && input.policy.write !== "deny") for (const target of targets) {
|
|
47
58
|
const confirmed = setAssertionStatus(target.id, "active", {
|
|
48
59
|
actor: "user",
|
|
49
60
|
reason: "Explicit user confirmation."
|
|
@@ -61,7 +72,7 @@ function executeUserModelInterpretation(input) {
|
|
|
61
72
|
});
|
|
62
73
|
result.deduplicated += 1;
|
|
63
74
|
}
|
|
64
|
-
if (input.interpretation.intent === "correct" && targets.length && input.interpretation.assertions.length === 0) {
|
|
75
|
+
if (input.interpretation.intent === "correct" && commandAllowed("correct") && targets.length && input.interpretation.assertions.length === 0) {
|
|
65
76
|
for (const target of targets) setAssertionStatus(target.id, "needs_review", {
|
|
66
77
|
actor: "user",
|
|
67
78
|
reason: "Correction requested without a grounded replacement."
|
|
@@ -98,10 +109,47 @@ function executeUserModelInterpretation(input) {
|
|
|
98
109
|
evidenceIds.set(ref, evidence.id);
|
|
99
110
|
}
|
|
100
111
|
const latestUserRef = input.evidence.filter((item) => item.role === "user").sort((a, b) => b.createdAt - a.createdAt)[0]?.ref;
|
|
101
|
-
for (const
|
|
112
|
+
for (const original of input.interpretation.assertions) {
|
|
113
|
+
if (!supportsResponseApplicability(original.applicability)) {
|
|
114
|
+
result.proposed++;
|
|
115
|
+
result.rejected++;
|
|
116
|
+
result.outputs.push({
|
|
117
|
+
candidateKey: candidateKey(original.predicate, original.scope.type, original.scope.id),
|
|
118
|
+
outcome: "rejected",
|
|
119
|
+
reasonCode: "unsupported_applicability_operation"
|
|
120
|
+
});
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const support = assessAssertionSupport({
|
|
124
|
+
...original,
|
|
125
|
+
sources: original.evidenceRefs.flatMap((ref) => {
|
|
126
|
+
const evidence = evidenceByRef.get(ref);
|
|
127
|
+
if (!evidence) return [];
|
|
128
|
+
return [{
|
|
129
|
+
...evidence,
|
|
130
|
+
quote: original.evidenceQuotes?.find((claim) => claim.ref === ref)?.quote ?? evidence.text
|
|
131
|
+
}];
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
if (!support.allowed) {
|
|
135
|
+
result.proposed++;
|
|
136
|
+
result.rejected++;
|
|
137
|
+
result.outputs.push({
|
|
138
|
+
candidateKey: candidateKey(original.predicate, original.scope.type, original.scope.id),
|
|
139
|
+
outcome: "rejected",
|
|
140
|
+
reasonCode: support.reasonCode
|
|
141
|
+
});
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const source = {
|
|
145
|
+
...original,
|
|
146
|
+
authority: support.authority,
|
|
147
|
+
confidence: ["user_observed", "system_inferred"].includes(support.authority) ? Math.min(.85, original.confidence) : original.confidence
|
|
148
|
+
};
|
|
102
149
|
result.proposed += 1;
|
|
103
150
|
const key = candidateKey(source.predicate, source.scope.type, source.scope.id);
|
|
104
|
-
const
|
|
151
|
+
const command = source.intent ?? input.interpretation.intent;
|
|
152
|
+
const sourceExplicitCommand = (command === "remember" || command === "correct") && source.evidenceRefs.some((ref) => hasOwnerMemoryDirective(evidenceByRef.get(ref)?.text ?? "", command));
|
|
105
153
|
const sensitive = source.sensitivity !== "normal";
|
|
106
154
|
if (input.policy.write === "deny" || sensitive && (source.authority !== "user_explicit" || input.policy.sensitiveWrite === "deny") || !scopeAllowed(source.scope.type, source.scope.id, input.scopeContext)) {
|
|
107
155
|
result.rejected += 1;
|
|
@@ -221,10 +269,20 @@ function executeUserModelInterpretation(input) {
|
|
|
221
269
|
if (applied.action === "deduplicated") result.deduplicated += 1;
|
|
222
270
|
else result.created += 1;
|
|
223
271
|
}
|
|
272
|
+
const structuredSupported = (source, kind) => source.evidenceRefs.length > 0 && source.evidenceRefs.every((ref) => {
|
|
273
|
+
const evidence = evidenceByRef.get(ref);
|
|
274
|
+
return evidence?.role === "user" && assessOwnerSupport({
|
|
275
|
+
text: evidence.text,
|
|
276
|
+
quote: source.evidenceQuotes?.find((claim) => claim.ref === ref)?.quote ?? evidence.text,
|
|
277
|
+
kind: kind ?? (source.targetAt ? "current_state" : void 0),
|
|
278
|
+
validTo: source.targetAt,
|
|
279
|
+
observedAt: evidence.createdAt
|
|
280
|
+
}).allowed;
|
|
281
|
+
});
|
|
224
282
|
for (const source of goals) {
|
|
225
283
|
result.proposed += 1;
|
|
226
284
|
const key = candidateKey(`goal:${source.title.toLocaleLowerCase()}`, source.scope.type, source.scope.id);
|
|
227
|
-
if (input.policy.write === "deny" || !scopeAllowed(source.scope.type, source.scope.id, input.scopeContext)) {
|
|
285
|
+
if (input.policy.write === "deny" || !structuredSupported(source) || !scopeAllowed(source.scope.type, source.scope.id, input.scopeContext)) {
|
|
228
286
|
result.rejected += 1;
|
|
229
287
|
result.outputs.push({
|
|
230
288
|
candidateKey: key,
|
|
@@ -240,7 +298,8 @@ function executeUserModelInterpretation(input) {
|
|
|
240
298
|
});
|
|
241
299
|
continue;
|
|
242
300
|
}
|
|
243
|
-
const
|
|
301
|
+
const intent = source.intent ?? input.interpretation.intent;
|
|
302
|
+
const active = (intent === "remember" || intent === "correct") && source.evidenceRefs.some((ref) => hasOwnerMemoryDirective(evidenceByRef.get(ref)?.text ?? "", intent));
|
|
244
303
|
const goal = createUserGoal({
|
|
245
304
|
title: source.title,
|
|
246
305
|
desiredOutcome: source.desiredOutcome,
|
|
@@ -266,7 +325,7 @@ function executeUserModelInterpretation(input) {
|
|
|
266
325
|
for (const source of collaborationRules) {
|
|
267
326
|
result.proposed += 1;
|
|
268
327
|
const key = candidateKey(`rule:${source.category}:${source.statement.toLocaleLowerCase()}`, source.scope.type, source.scope.id);
|
|
269
|
-
if (input.policy.write === "deny" || !scopeAllowed(source.scope.type, source.scope.id, input.scopeContext) || source.scope.type === "agent") {
|
|
328
|
+
if (input.policy.write === "deny" || !structuredSupported(source, "preference") || !scopeAllowed(source.scope.type, source.scope.id, input.scopeContext) || source.scope.type === "agent") {
|
|
270
329
|
result.rejected += 1;
|
|
271
330
|
result.outputs.push({
|
|
272
331
|
candidateKey: key,
|
|
@@ -282,7 +341,8 @@ function executeUserModelInterpretation(input) {
|
|
|
282
341
|
});
|
|
283
342
|
continue;
|
|
284
343
|
}
|
|
285
|
-
const
|
|
344
|
+
const intent = source.intent ?? input.interpretation.intent;
|
|
345
|
+
const active = (intent === "remember" || intent === "correct") && source.evidenceRefs.some((ref) => hasOwnerMemoryDirective(evidenceByRef.get(ref)?.text ?? "", intent));
|
|
286
346
|
const rule = createCollaborationRule({
|
|
287
347
|
category: source.category,
|
|
288
348
|
priority: source.priority,
|
|
@@ -14,6 +14,10 @@ export interface ParsedAssertionOperation extends AssertionCandidate {
|
|
|
14
14
|
action: AssertionMaintenanceAction;
|
|
15
15
|
targetAssertionId?: string;
|
|
16
16
|
evidenceRefs: string[];
|
|
17
|
+
evidenceQuotes?: Array<{
|
|
18
|
+
ref: string;
|
|
19
|
+
quote: string;
|
|
20
|
+
}>;
|
|
17
21
|
temporalResolution: 'exact' | 'relative_resolved' | 'unresolved';
|
|
18
22
|
originalTimePhrase?: string;
|
|
19
23
|
}
|
|
@@ -25,6 +29,10 @@ export interface ParsedGoalCandidate {
|
|
|
25
29
|
declaredImportance?: number;
|
|
26
30
|
targetAt?: number;
|
|
27
31
|
evidenceRefs: string[];
|
|
32
|
+
evidenceQuotes?: Array<{
|
|
33
|
+
ref: string;
|
|
34
|
+
quote: string;
|
|
35
|
+
}>;
|
|
28
36
|
}
|
|
29
37
|
export interface ParsedCollaborationRuleCandidate {
|
|
30
38
|
intent?: UserModelCaptureIntent;
|
|
@@ -34,6 +42,10 @@ export interface ParsedCollaborationRuleCandidate {
|
|
|
34
42
|
conditions: Record<string, unknown>;
|
|
35
43
|
statement: string;
|
|
36
44
|
evidenceRefs: string[];
|
|
45
|
+
evidenceQuotes?: Array<{
|
|
46
|
+
ref: string;
|
|
47
|
+
quote: string;
|
|
48
|
+
}>;
|
|
37
49
|
}
|
|
38
50
|
export interface UserModelInterpretation {
|
|
39
51
|
knowledge?: WorkCandidate[];
|
|
@@ -60,6 +72,10 @@ export interface UserModelInterpretation {
|
|
|
60
72
|
collaborationRules?: ParsedCollaborationRuleCandidate[];
|
|
61
73
|
targetAssertionIds: string[];
|
|
62
74
|
abstentionReason?: string;
|
|
75
|
+
rejectedCandidates?: Array<{
|
|
76
|
+
candidateKey: string;
|
|
77
|
+
reasonCode: string;
|
|
78
|
+
}>;
|
|
63
79
|
}
|
|
64
80
|
export interface InterpretationParseFailure {
|
|
65
81
|
reason: 'empty_output' | 'invalid_json' | 'schema_validation';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assessAssertionSupport, assessOwnerSupport, hasOwnerMemoryDirective, supportsResponseApplicability } from "./evidence-policy.js";
|
|
1
2
|
import { WorkCandidateSchema } from "../../memory-learning/work-candidate.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
//#region src/user-model/capture/semantic.ts
|
|
@@ -97,7 +98,7 @@ const AssertionOperationSchema = z.object({
|
|
|
97
98
|
"referenceable",
|
|
98
99
|
"ask_before_reference"
|
|
99
100
|
]),
|
|
100
|
-
applicability: z.record(z.string(), z.unknown()).default({}),
|
|
101
|
+
applicability: z.record(z.string(), z.unknown()).refine(supportsResponseApplicability, { message: "operation must be response (or an array containing only response), or omitted" }).default({}),
|
|
101
102
|
validFrom: z.string().datetime({ offset: true }).optional(),
|
|
102
103
|
validTo: z.string().datetime({ offset: true }).optional(),
|
|
103
104
|
reviewAt: z.string().datetime({ offset: true }).optional(),
|
|
@@ -171,7 +172,7 @@ const InterpretationSchema = z.object({
|
|
|
171
172
|
goals: z.array(GoalSchema).max(4).default([]),
|
|
172
173
|
collaborationRules: z.array(CollaborationRuleSchema).max(4).default([]),
|
|
173
174
|
targetAssertionIds: z.array(z.string().min(1)).max(8),
|
|
174
|
-
abstentionReason: z.string().
|
|
175
|
+
abstentionReason: z.string().transform((value) => value.slice(0, 500)).optional()
|
|
175
176
|
}).strict();
|
|
176
177
|
function extractJson(raw) {
|
|
177
178
|
const fenced = /```(?:json)?\s*([\s\S]*?)```/i.exec(raw)?.[1];
|
|
@@ -229,6 +230,15 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
229
230
|
return null;
|
|
230
231
|
}
|
|
231
232
|
const parsed = result.data;
|
|
233
|
+
const rejectedCandidates = [];
|
|
234
|
+
if ([
|
|
235
|
+
"forget",
|
|
236
|
+
"confirm",
|
|
237
|
+
"correct"
|
|
238
|
+
].includes(parsed.intent) && !evidence.some((source) => source.role === "user" && hasOwnerMemoryDirective(source.text, parsed.intent))) {
|
|
239
|
+
parsed.intent = "none";
|
|
240
|
+
parsed.targetAssertionIds = [];
|
|
241
|
+
}
|
|
232
242
|
const evidenceByRef = new Map(evidence.map((item) => [item.ref, item]));
|
|
233
243
|
const assertionIntents = new Set([
|
|
234
244
|
"remember",
|
|
@@ -240,12 +250,42 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
240
250
|
const assertions = [];
|
|
241
251
|
for (const item of parsed.assertions) {
|
|
242
252
|
const intent = operationIntent(item.intent, parsed.intent);
|
|
243
|
-
if (!assertionIntents.has(intent))
|
|
253
|
+
if (!assertionIntents.has(intent)) {
|
|
254
|
+
rejectedCandidates.push({
|
|
255
|
+
candidateKey: `${item.scope.type}:${item.scope.id ?? ""}:${item.predicate}`,
|
|
256
|
+
reasonCode: "non_assertion_intent"
|
|
257
|
+
});
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
244
260
|
const evidenceRefs = groundedEvidenceRefs(item, evidenceByRef);
|
|
245
|
-
if (!evidenceRefs)
|
|
246
|
-
|
|
261
|
+
if (!evidenceRefs) {
|
|
262
|
+
rejectedCandidates.push({
|
|
263
|
+
candidateKey: `${item.scope.type}:${item.scope.id ?? ""}:${item.predicate}`,
|
|
264
|
+
reasonCode: "owner_quote_not_grounded"
|
|
265
|
+
});
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
247
268
|
if (item.action !== "create" && (!item.targetAssertionId || !allowed.has(item.targetAssertionId))) continue;
|
|
248
269
|
const observedAt = Math.max(...item.evidence.map((claim) => evidenceByRef.get(claim.ref).createdAt));
|
|
270
|
+
const support = assessAssertionSupport({
|
|
271
|
+
kind: item.kind,
|
|
272
|
+
authority: effectiveAuthority(intent, item.authority),
|
|
273
|
+
volatility: item.volatility,
|
|
274
|
+
validTo: item.temporalResolution === "unresolved" ? void 0 : parseTime(item.validTo),
|
|
275
|
+
observedAt,
|
|
276
|
+
action: item.action,
|
|
277
|
+
sources: item.evidence.map((claim) => ({
|
|
278
|
+
...evidenceByRef.get(claim.ref),
|
|
279
|
+
quote: claim.quote
|
|
280
|
+
}))
|
|
281
|
+
});
|
|
282
|
+
if (!support.allowed) {
|
|
283
|
+
rejectedCandidates.push({
|
|
284
|
+
candidateKey: `${item.scope.type}:${item.scope.id ?? ""}:${item.predicate}`,
|
|
285
|
+
reasonCode: support.reasonCode
|
|
286
|
+
});
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
249
289
|
assertions.push({
|
|
250
290
|
intent,
|
|
251
291
|
action: item.action,
|
|
@@ -258,8 +298,8 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
258
298
|
value: item.value,
|
|
259
299
|
normalizedValue: item.normalizedValue,
|
|
260
300
|
statement: item.statement,
|
|
261
|
-
authority:
|
|
262
|
-
confidence: item.confidence,
|
|
301
|
+
authority: support.authority,
|
|
302
|
+
confidence: support.authority === "user_observed" || support.authority === "system_inferred" ? Math.min(.85, item.confidence) : item.confidence,
|
|
263
303
|
...item.declaredImportance === void 0 ? {} : { declaredImportance: item.declaredImportance },
|
|
264
304
|
inferredImportance: item.inferredImportance,
|
|
265
305
|
consequence: item.consequence,
|
|
@@ -277,7 +317,8 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
277
317
|
...item.originalTimePhrase ? { originalTimePhrase: item.originalTimePhrase } : {},
|
|
278
318
|
observedAt,
|
|
279
319
|
createdBy: "runtime",
|
|
280
|
-
evidenceRefs
|
|
320
|
+
evidenceRefs,
|
|
321
|
+
evidenceQuotes: item.evidence
|
|
281
322
|
});
|
|
282
323
|
}
|
|
283
324
|
const structuredIntents = new Set([
|
|
@@ -290,7 +331,13 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
290
331
|
const intent = operationIntent(item.intent, parsed.intent);
|
|
291
332
|
if (!structuredIntents.has(intent)) return [];
|
|
292
333
|
const evidenceRefs = groundedEvidenceRefs(item, evidenceByRef);
|
|
293
|
-
if (!evidenceRefs)
|
|
334
|
+
if (!evidenceRefs || !item.evidence.every((claim) => assessOwnerSupport({
|
|
335
|
+
text: evidenceByRef.get(claim.ref).text,
|
|
336
|
+
quote: claim.quote,
|
|
337
|
+
kind: item.targetAt ? "current_state" : void 0,
|
|
338
|
+
validTo: item.targetAt ? parseTime(item.targetAt) : void 0,
|
|
339
|
+
observedAt: evidenceByRef.get(claim.ref).createdAt
|
|
340
|
+
}).allowed)) return [];
|
|
294
341
|
return [{
|
|
295
342
|
intent,
|
|
296
343
|
title: item.title,
|
|
@@ -298,14 +345,19 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
298
345
|
scope: item.scope,
|
|
299
346
|
...item.declaredImportance === void 0 ? {} : { declaredImportance: item.declaredImportance },
|
|
300
347
|
...item.targetAt === void 0 ? {} : { targetAt: parseTime(item.targetAt) },
|
|
301
|
-
evidenceRefs
|
|
348
|
+
evidenceRefs,
|
|
349
|
+
evidenceQuotes: item.evidence
|
|
302
350
|
}];
|
|
303
351
|
});
|
|
304
352
|
const collaborationRules = parsed.collaborationRules.flatMap((item) => {
|
|
305
353
|
const intent = operationIntent(item.intent, parsed.intent);
|
|
306
354
|
if (!structuredIntents.has(intent)) return [];
|
|
307
355
|
const evidenceRefs = groundedEvidenceRefs(item, evidenceByRef);
|
|
308
|
-
if (!evidenceRefs || item.scope.type === "agent")
|
|
356
|
+
if (!evidenceRefs || item.scope.type === "agent" || !item.evidence.every((claim) => assessOwnerSupport({
|
|
357
|
+
text: evidenceByRef.get(claim.ref).text,
|
|
358
|
+
quote: claim.quote,
|
|
359
|
+
kind: "preference"
|
|
360
|
+
}).allowed)) return [];
|
|
309
361
|
return [{
|
|
310
362
|
intent,
|
|
311
363
|
category: item.category,
|
|
@@ -313,10 +365,12 @@ function parseUserModelInterpretation(raw, evidence, allowedTargetIds = [], onIn
|
|
|
313
365
|
scope: item.scope,
|
|
314
366
|
conditions: item.conditions,
|
|
315
367
|
statement: item.statement,
|
|
316
|
-
evidenceRefs
|
|
368
|
+
evidenceRefs,
|
|
369
|
+
evidenceQuotes: item.evidence
|
|
317
370
|
}];
|
|
318
371
|
});
|
|
319
372
|
return {
|
|
373
|
+
rejectedCandidates,
|
|
320
374
|
knowledge: parsed.knowledge,
|
|
321
375
|
knowledgeDeletions: parsed.knowledgeDeletions.flatMap((item) => {
|
|
322
376
|
const evidenceRefs = groundedEvidenceRefs(item, evidenceByRef);
|
|
@@ -499,6 +499,17 @@ function setUserAssertionScope(assertionId, nextScope) {
|
|
|
499
499
|
if (db.prepare(`SELECT slot_id FROM user_assertion_slots
|
|
500
500
|
WHERE principal_id = ? AND subject_type = ? AND subject_id = ? AND predicate = ?
|
|
501
501
|
AND scope_type = ? AND COALESCE(scope_id, '') = COALESCE(?, '') AND slot_id != ?`).get(slot.principalId, slot.subject.type, slot.subject.id, slot.predicate, nextScope.type, nextScopeId, slot.id)) throw new Error("An understanding with this scope already exists.");
|
|
502
|
+
for (const assertion of listSlotAssertions(slot.id)) suppressMemory(db, assertionFingerprints({
|
|
503
|
+
...assertion,
|
|
504
|
+
...slot,
|
|
505
|
+
principalId: slot.principalId
|
|
506
|
+
}), Date.now());
|
|
507
|
+
restoreMemory(db, assertionFingerprints({
|
|
508
|
+
...current,
|
|
509
|
+
...slot,
|
|
510
|
+
scope: nextScope,
|
|
511
|
+
principalId: slot.principalId
|
|
512
|
+
}));
|
|
502
513
|
db.prepare("UPDATE user_assertion_slots SET scope_type = ?, scope_id = ? WHERE slot_id = ?").run(nextScope.type, nextScopeId, slot.id);
|
|
503
514
|
return getUserAssertion(assertionId);
|
|
504
515
|
});
|