@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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { init_transaction, runSqliteWriteTransaction } from "../../../storage/sqlite/transaction.js";
|
|
2
2
|
import { createCollaborationRule, getCollaborationRule, listCollaborationRules, setCollaborationRuleStatus } from "../../../storage/sqlite/collaboration-rule-repository.js";
|
|
3
3
|
import { getActiveUnderstandingConsent } from "../../../user-context/sources/consent-repository.js";
|
|
4
|
-
import { KnowledgeReviewConflictError, deleteKnowledgeItem, getKnowledgeItem, listKnowledgeItems, reviewKnowledgeItem, searchKnowledgeItems } from "../../../knowledge-memory/repository.js";
|
|
4
|
+
import { KnowledgeReviewConflictError, deleteKnowledgeItem, getKnowledgeItem, listKnowledgeItems, reviewKnowledgeItem, searchKnowledgeItems, setKnowledgeScope } from "../../../knowledge-memory/repository.js";
|
|
5
5
|
import "../../../knowledge-memory/index.js";
|
|
6
6
|
import { createPriorityWindow, createUserGoal, listPriorityWindows, listUserGoals, setUserGoalStatus, updatePriorityWindow, updateUserGoal } from "../../../user-model/goals.js";
|
|
7
7
|
import { deleteUserAssertion, getAssertionSlot, getUserAssertion, listUserAssertionSources, listUserAssertions, reconcileAssertion, setAssertionStatus, setUserAssertionScope } from "../../../user-model/repository.js";
|
|
8
8
|
import { canUseAssertion } from "../../../user-model/usage-policy.js";
|
|
9
9
|
import { applyUserProfilePatch, getUserProfileSnapshot } from "../../../user-model/profile.js";
|
|
10
|
+
import { memoryVersion } from "../../../user-context/memory-version.js";
|
|
10
11
|
import { listActionRuleSuggestions } from "../../../user-model/action-rule-suggestions.js";
|
|
11
12
|
import { listUserAssertionEdges, listUserModelObservations } from "../../../user-model/observation-repository.js";
|
|
12
13
|
import { bootstrapUserModel } from "../../../user-model/bootstrap.js";
|
|
@@ -137,6 +138,10 @@ function assertionView(assertion, sources = listUserAssertionSources([assertion.
|
|
|
137
138
|
predicate: slot.predicate,
|
|
138
139
|
subject: slot.subject,
|
|
139
140
|
scope: slot.scope,
|
|
141
|
+
version: memoryVersion({
|
|
142
|
+
assertion,
|
|
143
|
+
scope: slot.scope
|
|
144
|
+
}),
|
|
140
145
|
sources,
|
|
141
146
|
usable: canUseAssertion(assertion, Date.now(), {
|
|
142
147
|
use: "answer",
|
|
@@ -257,7 +262,10 @@ function registerUserModelRoutes(authenticated, deps) {
|
|
|
257
262
|
priorities,
|
|
258
263
|
rules: listCollaborationRules(),
|
|
259
264
|
ruleSuggestions: listActionRuleSuggestions(),
|
|
260
|
-
knowledge
|
|
265
|
+
knowledge: knowledge.map((item) => ({
|
|
266
|
+
...item,
|
|
267
|
+
version: memoryVersion(item)
|
|
268
|
+
})),
|
|
261
269
|
maintenance: { lastRun: listMemoryMaintenanceRuns(1)[0] ?? null },
|
|
262
270
|
profile,
|
|
263
271
|
sources,
|
|
@@ -518,11 +526,21 @@ function registerUserModelRoutes(authenticated, deps) {
|
|
|
518
526
|
}
|
|
519
527
|
});
|
|
520
528
|
authenticated.patch("/api/user-model/assertions/:id/scope", write, async (c) => {
|
|
521
|
-
const
|
|
522
|
-
|
|
529
|
+
const input = await body(c);
|
|
530
|
+
const nextScope = scope(input?.scope);
|
|
531
|
+
if (!nextScope || typeof input?.version !== "string") return c.json({ error: "scope and version are required" }, 400);
|
|
523
532
|
try {
|
|
524
|
-
|
|
525
|
-
|
|
533
|
+
return runSqliteWriteTransaction(() => {
|
|
534
|
+
const current = getUserAssertion(c.req.param("id"));
|
|
535
|
+
if (!current) return c.json({ error: "Assertion not found" }, 404);
|
|
536
|
+
const currentScope = getAssertionSlot(current.slotId)?.scope;
|
|
537
|
+
if (memoryVersion({
|
|
538
|
+
assertion: current,
|
|
539
|
+
scope: currentScope
|
|
540
|
+
}) !== input.version) return c.json({ error: "Memory changed; refresh before changing scope" }, 409);
|
|
541
|
+
const assertion = setUserAssertionScope(current.id, nextScope);
|
|
542
|
+
return c.json({ assertion: assertionView(assertion) });
|
|
543
|
+
});
|
|
526
544
|
} catch (error) {
|
|
527
545
|
return c.json({ error: errorMessage(error) }, 400);
|
|
528
546
|
}
|
|
@@ -736,7 +754,29 @@ function registerUserModelRoutes(authenticated, deps) {
|
|
|
736
754
|
});
|
|
737
755
|
authenticated.get("/api/knowledge-memory/:id", (c) => {
|
|
738
756
|
const item = getKnowledgeItem(c.req.param("id"));
|
|
739
|
-
return item ? c.json({ item
|
|
757
|
+
return item ? c.json({ item: {
|
|
758
|
+
...item,
|
|
759
|
+
version: memoryVersion(item)
|
|
760
|
+
} }) : c.json({ error: "Knowledge item not found" }, 404);
|
|
761
|
+
});
|
|
762
|
+
authenticated.patch("/api/knowledge-memory/:id/scope", write, async (c) => {
|
|
763
|
+
const input = await body(c);
|
|
764
|
+
const nextScope = scope(input?.scope);
|
|
765
|
+
if (!nextScope || typeof input?.version !== "string") return c.json({ error: "scope and version are required" }, 400);
|
|
766
|
+
try {
|
|
767
|
+
return runSqliteWriteTransaction(() => {
|
|
768
|
+
const current = getKnowledgeItem(c.req.param("id"));
|
|
769
|
+
if (!current) return c.json({ error: "Knowledge item not found" }, 404);
|
|
770
|
+
if (memoryVersion(current) !== input.version) return c.json({ error: "Memory changed; refresh before changing scope" }, 409);
|
|
771
|
+
const item = setKnowledgeScope(current.id, nextScope);
|
|
772
|
+
return c.json({ item: {
|
|
773
|
+
...item,
|
|
774
|
+
version: memoryVersion(item)
|
|
775
|
+
} });
|
|
776
|
+
});
|
|
777
|
+
} catch (error) {
|
|
778
|
+
return c.json({ error: errorMessage(error) }, 400);
|
|
779
|
+
}
|
|
740
780
|
});
|
|
741
781
|
authenticated.delete("/api/knowledge-memory/:id", write, (c) => {
|
|
742
782
|
return deleteKnowledgeItem(c.req.param("id")) ? c.json({ ok: true }) : c.json({ error: "Knowledge item not found" }, 404);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { normalizeAgentId } from "../agent-catalog/id.js";
|
|
2
2
|
import { AgentCatalogRepository, init_repository } from "../agent-catalog/repository.js";
|
|
3
3
|
import { init_agent_scope } from "../agent/agent-scope.js";
|
|
4
|
+
import { AgentCatalogService } from "../agent-catalog/service.js";
|
|
4
5
|
import { ConfigSchema, init_schema } from "../config/schema.js";
|
|
5
6
|
import { resolveEffectiveAgentConfigForAgent } from "../config/agent-profile.js";
|
|
6
7
|
import { fetchWithTimeoutGuarded } from "../media-shared/http/provider-http.js";
|
|
7
8
|
import "../media-shared/http/index.js";
|
|
8
|
-
import { AgentCatalogService } from "../agent-catalog/service.js";
|
|
9
9
|
import { getImageGenerationProvider, listImageGenerationProvidersSummary } from "../agent/image/generation/provider-registry.js";
|
|
10
10
|
//#region src/gateway/image-generation-setup.ts
|
|
11
11
|
init_repository();
|
|
@@ -86,6 +86,12 @@ export declare class GatewayConfigCoordinator {
|
|
|
86
86
|
maxAssertions: number;
|
|
87
87
|
maxKnowledge: number;
|
|
88
88
|
maxChars: number;
|
|
89
|
+
deepRecall: {
|
|
90
|
+
enabled: boolean;
|
|
91
|
+
timeoutMs: number;
|
|
92
|
+
maxSessions: number;
|
|
93
|
+
maxEvidence: number;
|
|
94
|
+
};
|
|
89
95
|
compaction: {
|
|
90
96
|
personalIdle: {
|
|
91
97
|
enabled: boolean;
|
|
@@ -106,6 +106,10 @@ import { DiscussionSealer } from "../discussions/sealer.js";
|
|
|
106
106
|
import "../discussions/index.js";
|
|
107
107
|
import { EndpointToolRuntime } from "../endpoint-tools/runtime.js";
|
|
108
108
|
import "../endpoint-tools/index.js";
|
|
109
|
+
import { HomeCapabilityPreflightService } from "../home-intelligence/capability-preflight.js";
|
|
110
|
+
import { HomeAdviceGenerator } from "../home-intelligence/generator.js";
|
|
111
|
+
import { HomeIntelligenceHost } from "../home-intelligence/host.js";
|
|
112
|
+
import { HomeSnapshotBuilder } from "../home-intelligence/snapshot.js";
|
|
109
113
|
import { assertGatewayAuthConfigured, extractToken, resolveGatewayAuth, validateToken } from "./auth.js";
|
|
110
114
|
import { prepareAutomationAgentSession } from "./automation-agent-session.js";
|
|
111
115
|
import { deliverAutomationCompletion } from "./automation-completion-delivery.js";
|
|
@@ -168,10 +172,6 @@ import { TaskMainUpdateDecisionService } from "../tasks/task-main-update-decisio
|
|
|
168
172
|
import { selectTaskMainUpdateAttempt, submitAndConfirmTaskMainUpdate } from "../tasks/task-main-update-input.js";
|
|
169
173
|
import { checkAppContextAccess, prepareAppContext } from "./service/app-context-access.js";
|
|
170
174
|
import { applyAutomaticVoiceLanguage, inferProductLanguageFromEnvironment, initializeVoiceDefaults } from "../voice/language-profile.js";
|
|
171
|
-
import { HomeAdviceGenerator } from "../home-intelligence/generator.js";
|
|
172
|
-
import { HomeIntelligenceHost } from "../home-intelligence/host.js";
|
|
173
|
-
import { HomeSnapshotBuilder } from "../home-intelligence/snapshot.js";
|
|
174
|
-
import { HomeCapabilityPreflightService } from "../home-intelligence/capability-preflight.js";
|
|
175
175
|
import crypto from "node:crypto";
|
|
176
176
|
//#region src/gateway/service.ts
|
|
177
177
|
init_session_repository();
|
|
@@ -3,13 +3,13 @@ import { init_voice } from "../../packages/realtime-protocol/src/voice.js";
|
|
|
3
3
|
import "../agent-config/schema.js";
|
|
4
4
|
import { init_agent_config } from "../agent-config/index.js";
|
|
5
5
|
import { AgentCatalogRepository, init_repository } from "../agent-catalog/repository.js";
|
|
6
|
+
import { AgentCatalogService } from "../agent-catalog/service.js";
|
|
6
7
|
import { ConfigSchema, init_schema } from "../config/schema.js";
|
|
7
8
|
import { phoneModelProfile } from "../phone/model-policy.js";
|
|
8
9
|
import { init_model_policy, isComputerModel, isDedicatedComputerProfile } from "../computer/model-policy.js";
|
|
9
10
|
import { getModelCatalogStore, init_model_catalog_store } from "../providers/model-catalog-store.js";
|
|
10
11
|
import { compareCatalogModels } from "../providers/model-catalog-ranking.js";
|
|
11
12
|
import "../phone/model-adapter.js";
|
|
12
|
-
import { AgentCatalogService } from "../agent-catalog/service.js";
|
|
13
13
|
import { prepareUpdateGlobalDefaults } from "./global-defaults-admin.js";
|
|
14
14
|
//#region src/gateway/xopc-cloud-capability-setup.ts
|
|
15
15
|
init_voice();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createLogger } from "../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
|
-
import { HomeAdviceBudgetExceededError, isHomeProseLocalized } from "./generator.js";
|
|
4
3
|
import { homePatternKey } from "./strategy.js";
|
|
5
|
-
import { HomeAdvicePolicy } from "./policy.js";
|
|
6
4
|
import { HomeIntelligenceRepository } from "./repository.js";
|
|
7
5
|
import { HomeOpportunityApplicationService } from "./application-service.js";
|
|
6
|
+
import { HomeAdvicePolicy } from "./policy.js";
|
|
7
|
+
import { HomeAdviceBudgetExceededError, isHomeProseLocalized } from "./generator.js";
|
|
8
8
|
import { buildHomeOpportunityNotification } from "./notification.js";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
//#region src/home-intelligence/host.ts
|
|
@@ -11,8 +11,8 @@ import { scanLocal } from "./scanner.js";
|
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
12
12
|
import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
14
|
-
import lockfile from "proper-lockfile";
|
|
15
14
|
import yaml from "js-yaml";
|
|
15
|
+
import lockfile from "proper-lockfile";
|
|
16
16
|
//#region src/imports/importService.ts
|
|
17
17
|
init_write_file_atomic();
|
|
18
18
|
init_logger();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { canUseKnowledge, knowledgeContentSources, knowledgeExclusion } from "./usage-policy.js";
|
|
2
|
-
import { KnowledgeReviewConflictError, classifyKnowledgeContentSource, deleteKnowledgeItem, getKnowledgeItem, isKnowledgeCurrent, knowledgeItemAllowed, listKnowledgeItems, listKnowledgeStatusEvents, reviewKnowledgeItem, searchKnowledgeItems, transitionKnowledgeStatus, writeKnowledgeItem } from "./repository.js";
|
|
3
|
-
export { KnowledgeReviewConflictError, canUseKnowledge, classifyKnowledgeContentSource, deleteKnowledgeItem, getKnowledgeItem, isKnowledgeCurrent, knowledgeContentSources, knowledgeExclusion, knowledgeItemAllowed, listKnowledgeItems, listKnowledgeStatusEvents, reviewKnowledgeItem, searchKnowledgeItems, transitionKnowledgeStatus, writeKnowledgeItem };
|
|
2
|
+
import { KnowledgeReviewConflictError, classifyKnowledgeContentSource, deleteKnowledgeItem, getKnowledgeItem, isKnowledgeCurrent, knowledgeItemAllowed, listKnowledgeItems, listKnowledgeStatusEvents, reviewKnowledgeItem, searchKnowledgeItems, setKnowledgeScope, transitionKnowledgeStatus, writeKnowledgeItem } from "./repository.js";
|
|
3
|
+
export { KnowledgeReviewConflictError, canUseKnowledge, classifyKnowledgeContentSource, deleteKnowledgeItem, getKnowledgeItem, isKnowledgeCurrent, knowledgeContentSources, knowledgeExclusion, knowledgeItemAllowed, listKnowledgeItems, listKnowledgeStatusEvents, reviewKnowledgeItem, searchKnowledgeItems, setKnowledgeScope, transitionKnowledgeStatus, writeKnowledgeItem };
|
|
@@ -59,6 +59,8 @@ export declare function transitionKnowledgeStatus(input: {
|
|
|
59
59
|
reason: string;
|
|
60
60
|
expectedStatus?: KnowledgeStatus;
|
|
61
61
|
content?: string;
|
|
62
|
+
evidence?: WriteKnowledgeInput['evidence'];
|
|
63
|
+
source?: Record<string, unknown>;
|
|
62
64
|
now?: number;
|
|
63
65
|
}): KnowledgeItem | undefined;
|
|
64
66
|
export declare function reviewKnowledgeItem(input: {
|
|
@@ -68,6 +70,8 @@ export declare function reviewKnowledgeItem(input: {
|
|
|
68
70
|
reason: string;
|
|
69
71
|
expectedStatus?: KnowledgeStatus;
|
|
70
72
|
content?: string;
|
|
73
|
+
evidence?: WriteKnowledgeInput['evidence'];
|
|
74
|
+
source?: Record<string, unknown>;
|
|
71
75
|
now?: number;
|
|
72
76
|
}): KnowledgeItem | undefined;
|
|
73
77
|
export declare function listKnowledgeStatusEvents(knowledgeId: string): KnowledgeStatusEvent[];
|
|
@@ -83,6 +87,8 @@ export declare function searchKnowledgeItems(input: {
|
|
|
83
87
|
}): KnowledgeItem[];
|
|
84
88
|
export declare function classifyKnowledgeContentSource(item: KnowledgeItem): KnowledgeContentSource;
|
|
85
89
|
export declare function knowledgeItemAllowed(item: KnowledgeItem, policy: KnowledgeReadPolicy): boolean;
|
|
90
|
+
/** Move memory without allowing source replay to restore its former scope. */
|
|
91
|
+
export declare function setKnowledgeScope(id: string, scope: UserModelScope): KnowledgeItem;
|
|
86
92
|
export declare function deleteKnowledgeItem(id: string, now?: number, options?: {
|
|
87
93
|
includeRelated?: boolean;
|
|
88
94
|
}): boolean;
|
|
@@ -159,6 +159,7 @@ function listKnowledgeItems(input = {}) {
|
|
|
159
159
|
ORDER BY importance DESC, updated_at DESC LIMIT ?`).all(input.principalId ?? "local-owner", ...statuses, ...input.recordClass ? [input.recordClass] : [], ...input.scope ? [input.scope.type, input.scope.id ?? null] : [], ...input.canonicalKey ? [input.canonicalKey] : [], Math.max(1, Math.min(2e3, input.limit ?? 200))).map(fromRow);
|
|
160
160
|
}
|
|
161
161
|
function transitionKnowledgeStatus(input) {
|
|
162
|
+
if (input.evidence && input.actor !== "user") throw new Error("Only a user review can replace explicit evidence.");
|
|
162
163
|
const reason = input.reason.trim();
|
|
163
164
|
if (!reason) throw new Error("A knowledge status change reason is required.");
|
|
164
165
|
const content = input.content?.trim();
|
|
@@ -177,6 +178,18 @@ function transitionKnowledgeStatus(input) {
|
|
|
177
178
|
db.prepare("DELETE FROM knowledge_evidence_links WHERE knowledge_id = ?").run(input.id);
|
|
178
179
|
db.prepare("UPDATE knowledge_items SET claim_mode = 'explicit', verification = 'supported', source_json = '{}' WHERE knowledge_id = ?").run(input.id);
|
|
179
180
|
}
|
|
181
|
+
if (input.evidence) {
|
|
182
|
+
writeEvidence(db, input.id, {
|
|
183
|
+
...fromRow(current),
|
|
184
|
+
content: content ?? current.content,
|
|
185
|
+
originClass: "owner",
|
|
186
|
+
claimMode: "explicit",
|
|
187
|
+
verification: "supported",
|
|
188
|
+
sensitivity: inferMemorySensitivity(content ?? current.content),
|
|
189
|
+
evidence: input.evidence
|
|
190
|
+
});
|
|
191
|
+
db.prepare("UPDATE knowledge_items SET source_json = ? WHERE knowledge_id = ?").run(JSON.stringify(input.source ?? {}), input.id);
|
|
192
|
+
}
|
|
180
193
|
if (input.actor === "user" && (input.status === "rejected" || input.status === "archived")) suppressMemory(db, knowledgeFingerprints(fromRow(current)), now);
|
|
181
194
|
insertStatusEvent(db, {
|
|
182
195
|
knowledgeId: input.id,
|
|
@@ -239,6 +252,10 @@ function reviewKnowledgeItem(input) {
|
|
|
239
252
|
reason: input.reason,
|
|
240
253
|
expectedStatus: input.expectedStatus ?? current.status,
|
|
241
254
|
...input.content === void 0 ? {} : { content: input.content },
|
|
255
|
+
...input.evidence ? {
|
|
256
|
+
evidence: input.evidence,
|
|
257
|
+
source: input.source
|
|
258
|
+
} : {},
|
|
242
259
|
...input.now === void 0 ? {} : { now: input.now }
|
|
243
260
|
});
|
|
244
261
|
}
|
|
@@ -349,6 +366,37 @@ function knowledgeFingerprints(input) {
|
|
|
349
366
|
input.content
|
|
350
367
|
])];
|
|
351
368
|
}
|
|
369
|
+
/** Move memory without allowing source replay to restore its former scope. */
|
|
370
|
+
function setKnowledgeScope(id, scope) {
|
|
371
|
+
validateScope(scope);
|
|
372
|
+
return runSqliteWriteTransaction((db) => {
|
|
373
|
+
const item = getKnowledgeItem(id);
|
|
374
|
+
if (!item || item.recordClass !== "memory") throw new Error("Work memory not found.");
|
|
375
|
+
if (JSON.stringify(item.scope) === JSON.stringify(scope)) return item;
|
|
376
|
+
if (db.prepare(`SELECT 1 FROM knowledge_items WHERE principal_id = ? AND canonical_key = ?
|
|
377
|
+
AND scope_type = ? AND COALESCE(scope_id, '') = ? AND knowledge_id != ?`).get(item.principalId, item.canonicalKey, scope.type, scope.id ?? "", id)) throw new Error("A memory with this scope already exists.");
|
|
378
|
+
const now = Date.now();
|
|
379
|
+
suppressMemory(db, knowledgeFingerprints(item), now);
|
|
380
|
+
restoreMemory(db, knowledgeFingerprints({
|
|
381
|
+
...item,
|
|
382
|
+
scope
|
|
383
|
+
}));
|
|
384
|
+
db.prepare("INSERT INTO knowledge_revisions(revision_id, knowledge_id, content, source_json, created_at) VALUES (?, ?, ?, ?, ?)").run(randomUUID(), id, item.content, JSON.stringify({
|
|
385
|
+
...item.source,
|
|
386
|
+
previousScope: item.scope
|
|
387
|
+
}), now);
|
|
388
|
+
db.prepare("UPDATE knowledge_items SET scope_type = ?, scope_id = ?, origin_class = 'owner', updated_at = ? WHERE knowledge_id = ?").run(scope.type, scope.id ?? null, now, id);
|
|
389
|
+
insertStatusEvent(db, {
|
|
390
|
+
knowledgeId: id,
|
|
391
|
+
fromStatus: item.status,
|
|
392
|
+
toStatus: item.status,
|
|
393
|
+
actor: "user",
|
|
394
|
+
reason: "Memory scope changed by user.",
|
|
395
|
+
now
|
|
396
|
+
});
|
|
397
|
+
return getKnowledgeItem(id);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
352
400
|
function deleteKnowledgeItem(id, now = Date.now(), options = {}) {
|
|
353
401
|
return runSqliteWriteTransaction((db) => {
|
|
354
402
|
const rows = db.prepare(`WITH RECURSIVE deleted(id) AS (
|
|
@@ -389,4 +437,4 @@ function writeEvidence(db, id, input) {
|
|
|
389
437
|
for (const evidence of links.values()) db.prepare("INSERT INTO knowledge_evidence_links(knowledge_id, evidence_id, content_hash, consent_receipt_id) VALUES (?, ?, ?, ?)").run(id, evidence.id, evidence.contentHash ?? null, evidence.consentReceiptId ?? null);
|
|
390
438
|
}
|
|
391
439
|
//#endregion
|
|
392
|
-
export { KnowledgeReviewConflictError, classifyKnowledgeContentSource, deleteKnowledgeItem, getKnowledgeItem, isKnowledgeCurrent, knowledgeItemAllowed, listKnowledgeItems, listKnowledgeStatusEvents, reviewKnowledgeItem, searchKnowledgeItems, transitionKnowledgeStatus, writeKnowledgeItem };
|
|
440
|
+
export { KnowledgeReviewConflictError, classifyKnowledgeContentSource, deleteKnowledgeItem, getKnowledgeItem, isKnowledgeCurrent, knowledgeItemAllowed, listKnowledgeItems, listKnowledgeStatusEvents, reviewKnowledgeItem, searchKnowledgeItems, setKnowledgeScope, transitionKnowledgeStatus, writeKnowledgeItem };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getSqliteDatabase, init_transaction } from "../storage/sqlite/transaction.js";
|
|
2
|
-
import { getSessionMetadata } from "../storage/sqlite/session-read-repository.js";
|
|
3
|
-
import { init_session_repository } from "../storage/sqlite/session-repository.js";
|
|
4
2
|
import { isOwnerIdentity } from "../user-context/identity-bindings.js";
|
|
3
|
+
import { getConversationRouting } from "../storage/sqlite/conversation-repository.js";
|
|
4
|
+
import { init_session_key } from "../routing/session-key.js";
|
|
5
5
|
import { getUnderstandingConsent } from "../user-context/sources/consent-repository.js";
|
|
6
6
|
//#region src/knowledge-memory/usage-policy.ts
|
|
7
|
+
init_session_key();
|
|
7
8
|
init_transaction();
|
|
8
|
-
init_session_repository();
|
|
9
9
|
function knowledgeContentSources(item) {
|
|
10
10
|
if (item.source.kind === "product_import") return ["local_import"];
|
|
11
11
|
if (typeof item.source.sourceInstanceId === "string" && item.source.sourceInstanceId.startsWith("local-folder:")) return item.recordClass === "memory" ? ["memory", "local_import"] : ["local_import"];
|
|
@@ -26,8 +26,8 @@ function knowledgeExclusion(item, context, policy, asOf = Date.now()) {
|
|
|
26
26
|
if (item.verification === "conflicted" || item.verification === "tentative") return "conflicted";
|
|
27
27
|
if (item.sensitivity === "secret" || item.sensitivity === "regulated") return "sensitive";
|
|
28
28
|
if (item.originClass !== "owner" && item.sourceConversationId) {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
29
|
+
const routing = getConversationRouting(item.sourceConversationId);
|
|
30
|
+
if (!routing || routing.peerKind !== "direct" || !isOwnerIdentity(routing)) return "source_revoked";
|
|
31
31
|
}
|
|
32
32
|
const db = getSqliteDatabase();
|
|
33
33
|
const links = db.prepare(`SELECT e.*, l.content_hash AS linked_hash, l.consent_receipt_id
|
|
@@ -36,8 +36,8 @@ function knowledgeExclusion(item, context, policy, asOf = Date.now()) {
|
|
|
36
36
|
if (item.originClass === "untrusted" && !links.length) return "evidence_missing";
|
|
37
37
|
for (const link of links) {
|
|
38
38
|
if (link.conversation_id) {
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
39
|
+
const routing = getConversationRouting(link.conversation_id);
|
|
40
|
+
if (!routing || routing.peerKind !== "direct" || !isOwnerIdentity(routing)) return "source_revoked";
|
|
41
41
|
}
|
|
42
42
|
if (link.linked_hash && link.linked_hash !== link.content_hash) return "source_changed";
|
|
43
43
|
if (link.source_item_id) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DurableState } from "../storage/sqlite/durable-state.js";
|
|
2
2
|
import { CapabilityError } from "../capabilities/runtime/errors.js";
|
|
3
|
+
import { canonicalCapabilityJson, defineAtomicCapability, defineReadCapability } from "../capabilities/runtime/dispatcher.js";
|
|
3
4
|
import { CreateAutomationSchema } from "../automations/domain/validation.js";
|
|
4
5
|
import { getAutomation } from "../automations/storage/automation-repository.js";
|
|
5
6
|
import "../automations/storage/index.js";
|
|
6
|
-
import { canonicalCapabilityJson, defineAtomicCapability, defineReadCapability } from "../capabilities/runtime/dispatcher.js";
|
|
7
7
|
import { automationReadable } from "./capabilities/automation-policy.js";
|
|
8
8
|
import { AutomationCreateCapabilityInputSchema, AutomationUpdatePatchSchema, materializeAutomationTrigger } from "../automations/capabilities/write.js";
|
|
9
9
|
import { simulateAutomation } from "../automations/draft/automation-draft-validator.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DurableState } from "../../storage/sqlite/durable-state.js";
|
|
2
|
+
import { canonicalCapabilityJson } from "../../capabilities/runtime/dispatcher.js";
|
|
2
3
|
import { getAutomation } from "../../automations/storage/automation-repository.js";
|
|
3
4
|
import { getAutomationRun } from "../../automations/storage/automation-run-repository.js";
|
|
4
5
|
import "../../automations/storage/index.js";
|
|
5
|
-
import { canonicalCapabilityJson } from "../../capabilities/runtime/dispatcher.js";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
//#region src/local-apps/capabilities/automation-policy.ts
|
|
8
8
|
/** Runtime state changes do not widen execution authority; definition changes require fresh review. */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LocalAppDelegateInputSchema, LocalAppDelegateOutputSchema } from "../../../packages/gateway-contract/src/local-app-delegation.js";
|
|
2
2
|
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
3
3
|
import { DurableState } from "../../storage/sqlite/durable-state.js";
|
|
4
|
+
import { CapabilityError } from "../../capabilities/runtime/errors.js";
|
|
5
|
+
import { ExternalEffectNotAppliedError } from "../../capabilities/runtime/external-operations.js";
|
|
6
|
+
import { defineExternalCapability } from "../../capabilities/runtime/dispatcher.js";
|
|
4
7
|
import { getDefaultAgentId, init_resolve_route } from "../../routing/resolve-route.js";
|
|
5
8
|
import { resolveEffectiveAgentProfile } from "../../config/agent-profile.js";
|
|
6
9
|
import { init_providers, resolveModel } from "../../providers/index.js";
|
|
7
10
|
import { completeWithResolvedCredentials } from "../../providers/model-call.js";
|
|
8
|
-
import { CapabilityError } from "../../capabilities/runtime/errors.js";
|
|
9
|
-
import { ExternalEffectNotAppliedError } from "../../capabilities/runtime/external-operations.js";
|
|
10
|
-
import { defineExternalCapability } from "../../capabilities/runtime/dispatcher.js";
|
|
11
11
|
import { localAppResourceAllowed } from "./resource-policy.js";
|
|
12
12
|
//#region src/local-apps/capabilities/delegate.ts
|
|
13
13
|
init_src();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DurableState } from "../storage/sqlite/durable-state.js";
|
|
2
2
|
import { getConnectorAccount, init_connector_account_repository } from "../storage/sqlite/connector-account-repository.js";
|
|
3
3
|
import { decideConnectorApproval, getConnectorApproval, getConnectorConnection, init_connector_repository, listConnectorActionMetadata, listConnectorConnections } from "../storage/sqlite/connector-repository.js";
|
|
4
|
-
import { getDefaultAgentId, init_resolve_route } from "../routing/resolve-route.js";
|
|
5
4
|
import { CapabilityError } from "../capabilities/runtime/errors.js";
|
|
6
5
|
import { ExternalEffectNotAppliedError, executeExternalOperation } from "../capabilities/runtime/external-operations.js";
|
|
7
6
|
import { canonicalCapabilityJson, defineAtomicCapability, defineReadCapability } from "../capabilities/runtime/dispatcher.js";
|
|
7
|
+
import { getDefaultAgentId, init_resolve_route } from "../routing/resolve-route.js";
|
|
8
8
|
import { getCliAdapter } from "../connectors/cli/adapterRegistry.js";
|
|
9
9
|
import { listConnectorInstances } from "../connectors/instances.js";
|
|
10
10
|
import { parseExternalToolRef } from "../agent/external-tools/refs.js";
|
|
@@ -10,10 +10,10 @@ import { getConnectorAccount, init_connector_account_repository } from "../stora
|
|
|
10
10
|
import { getConnectorConnection, init_connector_repository } from "../storage/sqlite/connector-repository.js";
|
|
11
11
|
import { getSessionMetadata } from "../storage/sqlite/session-read-repository.js";
|
|
12
12
|
import { init_session_repository } from "../storage/sqlite/session-repository.js";
|
|
13
|
+
import { CapabilityError } from "../capabilities/runtime/errors.js";
|
|
13
14
|
import { init_paths, resolveExtensionsDir } from "../config/paths.js";
|
|
14
15
|
import { createConversation, init_conversation_repository } from "../storage/sqlite/conversation-repository.js";
|
|
15
16
|
import { slugifyProjectName } from "../projects/project-store.js";
|
|
16
|
-
import { CapabilityError } from "../capabilities/runtime/errors.js";
|
|
17
17
|
import { getAutomation } from "../automations/storage/automation-repository.js";
|
|
18
18
|
import { LocalAppStore } from "./store.js";
|
|
19
19
|
import "../automations/storage/index.js";
|
|
@@ -4,6 +4,7 @@ import { createContextEvidence } from "../storage/sqlite/context-evidence-reposi
|
|
|
4
4
|
import { inferMemorySensitivity } from "../agent/memory/sensitivity.js";
|
|
5
5
|
import { listKnowledgeItems, writeKnowledgeItem } from "../knowledge-memory/repository.js";
|
|
6
6
|
import "../knowledge-memory/index.js";
|
|
7
|
+
import { isOwnerAuthoredSpan } from "../user-model/capture/evidence-policy.js";
|
|
7
8
|
import { projectUnadmittedForgottenFields } from "./forgotten-history.js";
|
|
8
9
|
import { WorkCandidateSchema } from "./work-candidate.js";
|
|
9
10
|
import { createHash } from "node:crypto";
|
|
@@ -34,6 +35,7 @@ function applyWorkCandidates(input) {
|
|
|
34
35
|
if (candidate.evidence.some((claim) => !input.evidence.some((entry) => entry.ref === claim.ref))) return reject("evidence_ref_missing");
|
|
35
36
|
const sources = candidate.evidence.map((claim) => input.evidence.find((entry) => entry.ref === claim.ref && entry.text.normalize("NFKC").includes(claim.quote.normalize("NFKC"))));
|
|
36
37
|
if (sources.some((source) => !source)) return reject("evidence_quote_mismatch");
|
|
38
|
+
if (/^(?:偏好|习惯|倾向|喜欢|长期偏好|prefers?\b|likes?\b|tends? to\b)/iu.test(candidate.statement) || /(?:用户|主人|\b(?:the user|owner)\b).{0,35}(?:喜欢|偏好|习惯|职业|身份|(?:可能|也许)?.{0,2}是|prefer|likes|habit|profession|works? as|(?:is|might be|could be|may be)\b)/iu.test(candidate.statement)) return reject("personal_profile_requires_assertion");
|
|
37
39
|
if (candidate.scope === "project" && !input.projectId) return reject("missing_project_scope");
|
|
38
40
|
const scope = candidate.scope === "project" ? {
|
|
39
41
|
type: "project",
|
|
@@ -45,7 +47,7 @@ function applyWorkCandidates(input) {
|
|
|
45
47
|
type: "session",
|
|
46
48
|
id: input.conversationId
|
|
47
49
|
};
|
|
48
|
-
const independentSupport = sources.some((source) => source?.role === "
|
|
50
|
+
const independentSupport = sources.some((source, index) => source?.role === "toolResult" || source?.role === "user" && isOwnerAuthoredSpan(source.text, candidate.evidence[index].quote));
|
|
49
51
|
const evidence = sources.map((source) => {
|
|
50
52
|
const contentHash = createHash("sha256").update(source.text).digest("hex");
|
|
51
53
|
return {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const PERSONAL_MAIN_TOOL_IDS: readonly ["personal_task", "personal_attention", "personal_capability", "personal_request", "session_recall", "read_media", "read_file", "session_search", "personal_read", "personal_result", "user_context_read", "knowledge_read"];
|
|
1
|
+
export declare const PERSONAL_MAIN_TOOL_IDS: readonly ["personal_task", "personal_attention", "personal_capability", "personal_request", "session_recall", "read_media", "read_file", "session_search", "personal_read", "personal_result", "user_context_read", "knowledge_read", "personal_memory"];
|
|
2
2
|
export declare const PERSONAL_TOOL_DESCRIPTIONS: Readonly<Record<string, string>>;
|
|
3
3
|
export declare const PERSONAL_READ_TOOL_ALIASES: Readonly<Record<string, string>>;
|
|
@@ -11,7 +11,8 @@ const PERSONAL_MAIN_TOOL_IDS = [
|
|
|
11
11
|
"personal_read",
|
|
12
12
|
"personal_result",
|
|
13
13
|
"user_context_read",
|
|
14
|
-
"knowledge_read"
|
|
14
|
+
"knowledge_read",
|
|
15
|
+
"personal_memory"
|
|
15
16
|
];
|
|
16
17
|
const PERSONAL_TOOL_DESCRIPTIONS = {
|
|
17
18
|
session_recall: "Find exact facts in this conversation, including compacted history. Cannot access other chats.",
|
|
@@ -28,6 +28,7 @@ function personalInstructions() {
|
|
|
28
28
|
TASK_BRIEF_RULE,
|
|
29
29
|
TASK_CONTROL_RULE,
|
|
30
30
|
LOCAL_READ_RULE,
|
|
31
|
+
PERSONAL_MEMORY_RULE,
|
|
31
32
|
TOOL_BOUNDARY_RULE,
|
|
32
33
|
FAST_CONVERSATION_RULE,
|
|
33
34
|
CONVERSATION_INTERRUPTION_RULE,
|
|
@@ -46,7 +47,7 @@ function personalInstructions() {
|
|
|
46
47
|
PERSONAL_ATTENTION_VERIFICATION_RULE,
|
|
47
48
|
PERSONAL_GROWTH_RULE
|
|
48
49
|
];
|
|
49
|
-
rules.push("When the user requests an exact brief acknowledgement or literal reply, return only the requested text immediately, without tools, progress checks, planning or extra commentary. Do not treat this as permission to change a Task.");
|
|
50
|
+
rules.push("When the user requests an exact brief acknowledgement or literal reply without a persistent change, return only the requested text immediately, without tools, progress checks, planning or extra commentary. If they also request a memory change, commit it first and acknowledge only its actual outcome. Do not treat this as permission to change a Task.");
|
|
50
51
|
rules.push(USER_NAME_RULE);
|
|
51
52
|
rules.push(...PERSONAL_DEFAULT_STYLE_RULES);
|
|
52
53
|
return rules.join("\n");
|
|
@@ -73,6 +74,10 @@ function projectPersonalInstructions(instructions, toolNames) {
|
|
|
73
74
|
requires: ["personal_result"],
|
|
74
75
|
rules: [LOCAL_READ_RULE]
|
|
75
76
|
},
|
|
77
|
+
{
|
|
78
|
+
requires: ["personal_memory"],
|
|
79
|
+
rules: [PERSONAL_MEMORY_RULE]
|
|
80
|
+
},
|
|
76
81
|
{
|
|
77
82
|
requires: ["personal_request", "personal_capability"],
|
|
78
83
|
rules: [CONNECTED_APP_RULE, READ_AUTONOMY_RULE]
|
|
@@ -97,6 +102,7 @@ function projectPersonalInstructions(instructions, toolNames) {
|
|
|
97
102
|
}
|
|
98
103
|
return projected;
|
|
99
104
|
}
|
|
105
|
+
const PERSONAL_MEMORY_RULE = "A self-description or preference without a request to persist it is handled by background learning; adapt to it in the current reply, do not call personal_memory or claim it has already been saved. For an explicit request to remember, correct, forget, or limit saved memory, use personal_memory directly instead of delegating or promising background learning. Quote the current owner request in userEvidence. User identity/preferences use target=user; project facts, decisions and lessons use target=knowledge. Before changing an existing item read its id and version using the matching read tool. Resolve scope from what the user asks: global, current agent, workspace, project or session. Never broaden a local request. Missing current project is an error, not permission to fall back globally. Only say saved after status=saved with usable=true; pending means saved for review but not in use. A receipt records a past commit; available/usable describe current state on retries. Forgotten means future automatic recall stops, while originals and already running prompts may retain content. Keep acknowledgements short, name the actual scope, and offer correction only when useful. Memory cannot authorize external actions.";
|
|
100
106
|
const PERSONAL_ATTENTION_RULE = "Use personal_attention to save explicit requests to check again later and proactively tell the user about useful developments, including requests phrased without the word follow-up. The running Gateway checks saved attention automatically while the user is away and can post in this chat; do not ask the user to return or create a separate scheduler. Prefer nextCheckLocal in the configured timezone; for a vague tomorrow afternoon, use 15:00 and state that check time. A check is not a guaranteed notification or action authorization. Only claim follow-up saved after a successful tool result, and only claim memory written after a successful write; user_context_read is read-only. If a tool fails, explain the actual failure without inventing missing product capabilities. When there is no useful development, stay silent rather than posting no progress. Do not duplicate an existing scheduled automation or create attention from your own suggestions. For feedback, respect the smallest stated scope; silence is not rejection.";
|
|
101
107
|
const PERSONAL_ATTENTION_VERIFICATION_RULE = "For follow-up capability, use current system rules and tool descriptions, never prior assistant claims. When asked whether a follow-up is arranged or still active, query personal_attention(command=\"list\"); query command=\"settings\" when proactive settings are needed. Base status answers on current tool results. Do not substitute memory or notes for saved attention.";
|
|
102
108
|
const PERSONAL_GROWTH_RULE = "Topic feedback such as prepare fully next time changes only that attention thread: query personal_attention(list) to identify it, then feedback, never a global style change. If the topic is ambiguous, clarify. Use rollback only on an explicit undo request and the latest version ID. interests returns inferred, silent candidates with user evidence; do not treat confidence as confirmation or activate them without explicit follow-up. Keep growth state in the durable store, not personality files.";
|
|
@@ -2,11 +2,11 @@ import { getSessionMetadata } from "../storage/sqlite/session-read-repository.js
|
|
|
2
2
|
import { init_session_repository, patchSessionMetadata } from "../storage/sqlite/session-repository.js";
|
|
3
3
|
import { setSessionConfig } from "../storage/sqlite/config-repository.js";
|
|
4
4
|
import { AgentCatalogRepository, init_repository } from "../agent-catalog/repository.js";
|
|
5
|
+
import { AgentCatalogService } from "../agent-catalog/service.js";
|
|
5
6
|
import { createConversation, init_conversation_repository } from "../storage/sqlite/conversation-repository.js";
|
|
6
7
|
import { getAvailableModels, init_providers } from "../providers/index.js";
|
|
7
8
|
import { getPersonalAgent, personalAgentId } from "./repository.js";
|
|
8
9
|
import { PERSONAL_MAIN_TOOL_IDS, PERSONAL_READ_TOOL_ALIASES } from "./policy.js";
|
|
9
|
-
import { AgentCatalogService } from "../agent-catalog/service.js";
|
|
10
10
|
import { getModelThinking } from "../providers/model-thinking.js";
|
|
11
11
|
import { personalInstructions } from "./prompts.js";
|
|
12
12
|
import { completePersonalOnboarding } from "./onboarding.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { init_paths_state, resolveXopcCloudCatalogCachePath } from "../config/paths-state.js";
|
|
3
|
-
import { init_write_file_atomic, writeTextAtomic } from "../infra/write-file-atomic.js";
|
|
4
3
|
import { voiceManifestSchema } from "../../packages/realtime-protocol/src/voice-catalog.js";
|
|
5
4
|
import { init_voice } from "../../packages/realtime-protocol/src/voice.js";
|
|
5
|
+
import { init_write_file_atomic, writeTextAtomic } from "../infra/write-file-atomic.js";
|
|
6
6
|
import { PhoneModelMetadataSchema, init_contracts } from "../phone/contracts.js";
|
|
7
7
|
import { ComputerProfileSchema, init_src } from "../../packages/computer-control-contract/src/index.js";
|
|
8
8
|
import { ImageGenerationCapabilitiesSchema, init_models_json } from "../config/models-json.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RuntimeError } from "./errors.js";
|
|
2
2
|
import { isAbsolute, join, posix, relative, resolve } from "node:path";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
-
import AdmZip from "adm-zip";
|
|
5
4
|
import { lstat, mkdir, readdir, readlink, rename, rm, stat } from "node:fs/promises";
|
|
5
|
+
import AdmZip from "adm-zip";
|
|
6
6
|
//#region src/runtime-tools/archive.ts
|
|
7
7
|
const MAX_ARCHIVE_ENTRIES = 5e4;
|
|
8
8
|
const MAX_TAR_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Config } from '../config/schema.js';
|
|
2
|
+
import type { CaptureScopeContext } from '../user-model/capture/executor.js';
|
|
3
|
+
/** History tools and automatic recall share the same host-owned source boundary. */
|
|
4
|
+
export declare function canRecallConversation(config: Config | undefined, context: CaptureScopeContext, conversationId: string): boolean;
|
|
5
|
+
/** Reading raw evidence cannot widen the scope of its associated saved fact. */
|
|
6
|
+
export declare function canRecallHistoryEntry(context: CaptureScopeContext, conversationId: string, entryId: string | null, text: string): boolean;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getSqliteDatabase, init_transaction } from "../storage/sqlite/transaction.js";
|
|
2
|
+
import { getSessionConfig } from "../storage/sqlite/config-repository.js";
|
|
3
|
+
import { isOwnerIdentity } from "../user-context/identity-bindings.js";
|
|
4
|
+
import { getConversationRouting } from "../storage/sqlite/conversation-repository.js";
|
|
5
|
+
import { init_session_key } from "../routing/session-key.js";
|
|
6
|
+
import { resolveUserContextSessionAccess } from "../user-context/access-policy.js";
|
|
7
|
+
import { OWNER_LEARNING_SESSION_SQL } from "../memory-learning/transcript-source.js";
|
|
8
|
+
import { canonicalWorkspacePath } from "../projects/workspace-project.js";
|
|
9
|
+
//#region src/session/history-recall-policy.ts
|
|
10
|
+
init_transaction();
|
|
11
|
+
init_session_key();
|
|
12
|
+
/** History tools and automatic recall share the same host-owned source boundary. */
|
|
13
|
+
function canRecallConversation(config, context, conversationId) {
|
|
14
|
+
if (!config || !resolveUserContextSessionAccess(config, context.conversationId).crossSessionHistory) return false;
|
|
15
|
+
const row = getSqliteDatabase().prepare(`SELECT s.agent_id, s.project_id, t.cwd FROM sessions s
|
|
16
|
+
JOIN transcripts t ON t.transcript_id = s.active_transcript_id
|
|
17
|
+
WHERE s.conversation_id = ? AND ${OWNER_LEARNING_SESSION_SQL}`).get(conversationId);
|
|
18
|
+
if (!row || row.agent_id !== context.agentId || (row.project_id ?? "") !== (context.projectId ?? "")) return false;
|
|
19
|
+
if (canonicalWorkspacePath(row.cwd) !== canonicalWorkspacePath(context.workspaceId)) return false;
|
|
20
|
+
const cwd = getSessionConfig(conversationId)?.workingDirectoryOverride;
|
|
21
|
+
if (cwd && canonicalWorkspacePath(cwd) !== canonicalWorkspacePath(context.workspaceId)) return false;
|
|
22
|
+
if (conversationId !== context.conversationId) {
|
|
23
|
+
if (!canRecallHistoryEntry(context, conversationId, null, "")) return false;
|
|
24
|
+
if (getSqliteDatabase().prepare(`SELECT 1 FROM transcript_fts f JOIN transcript_entries e ON e.entry_id = f.entry_id
|
|
25
|
+
WHERE f.conversation_id = ? AND e.role = 'user' AND
|
|
26
|
+
(f.content LIKE '%仅%当前会话%' OR f.content LIKE '%只%当前会话%' OR f.content LIKE '%仅%本次会话%'
|
|
27
|
+
OR lower(f.content) LIKE '%only%this%chat%' OR lower(f.content) LIKE '%only%this%session%') LIMIT 1`).get(conversationId)) return false;
|
|
28
|
+
}
|
|
29
|
+
const route = getConversationRouting(conversationId);
|
|
30
|
+
return route?.peerKind === "direct" && isOwnerIdentity(route) && resolveUserContextSessionAccess(config, conversationId).crossSessionHistory;
|
|
31
|
+
}
|
|
32
|
+
/** Reading raw evidence cannot widen the scope of its associated saved fact. */
|
|
33
|
+
function canRecallHistoryEntry(context, conversationId, entryId, text) {
|
|
34
|
+
if (conversationId !== context.conversationId && /仅.{0,8}(?:当前|本次|这个)(?:会话|对话)|只.{0,8}(?:当前|本次|这个)(?:会话|对话)/u.test(text)) return false;
|
|
35
|
+
return getSqliteDatabase().prepare(`SELECT s.scope_type, s.scope_id FROM context_evidence e
|
|
36
|
+
JOIN user_assertion_evidence l ON l.evidence_id = e.evidence_id
|
|
37
|
+
JOIN user_assertions a ON a.assertion_id = l.assertion_id JOIN user_assertion_slots s ON s.slot_id = a.slot_id
|
|
38
|
+
WHERE e.conversation_id = ? AND (? IS NULL OR e.message_id = ?)
|
|
39
|
+
UNION ALL SELECT k.scope_type, k.scope_id FROM context_evidence e
|
|
40
|
+
JOIN knowledge_evidence_links l ON l.evidence_id = e.evidence_id JOIN knowledge_items k ON k.knowledge_id = l.knowledge_id
|
|
41
|
+
WHERE e.conversation_id = ? AND (? IS NULL OR e.message_id = ?)`).all(conversationId, entryId, entryId, conversationId, entryId, entryId).every((scope) => scope.scope_type === "global" || (scope.scope_type === "workspace" && scope.scope_id ? canonicalWorkspacePath(scope.scope_id) === canonicalWorkspacePath(context.workspaceId) : Boolean(scope.scope_id && scope.scope_id === {
|
|
42
|
+
agent: context.agentId,
|
|
43
|
+
project: context.projectId,
|
|
44
|
+
session: context.conversationId
|
|
45
|
+
}[scope.scope_type])));
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { canRecallConversation, canRecallHistoryEntry };
|
|
@@ -2,10 +2,10 @@ import { ProductReadContracts } from "../../../packages/gateway-contract/src/cap
|
|
|
2
2
|
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
3
3
|
import { TaskRepository, init_task_repository } from "../task-repository.js";
|
|
4
4
|
import { TaskRunRepository, init_task_run_repository } from "../task-run-repository.js";
|
|
5
|
-
import { TaskReadModelProjector } from "../task-read-model-projector.js";
|
|
6
|
-
import { TaskConversationRepository } from "../task-conversation-repository.js";
|
|
7
5
|
import { CapabilityError } from "../../capabilities/runtime/errors.js";
|
|
8
6
|
import { defineReadCapability } from "../../capabilities/runtime/dispatcher.js";
|
|
7
|
+
import { TaskReadModelProjector } from "../task-read-model-projector.js";
|
|
8
|
+
import { TaskConversationRepository } from "../task-conversation-repository.js";
|
|
9
9
|
import { LocalAppTaskListSchema, LocalAppTaskOutputSchema } from "../../local-apps/capabilities/projections.js";
|
|
10
10
|
import { TaskContextRepository } from "../task-context-repository.js";
|
|
11
11
|
import { TaskDependencyService } from "../task-dependency-service.js";
|
|
@@ -3,9 +3,9 @@ import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
|
3
3
|
import { DurableState } from "../../storage/sqlite/durable-state.js";
|
|
4
4
|
import { TaskRepository, init_task_repository } from "../task-repository.js";
|
|
5
5
|
import { TaskRunRepository, init_task_run_repository } from "../task-run-repository.js";
|
|
6
|
-
import { resolveTaskLocale } from "../task-language.js";
|
|
7
6
|
import { CapabilityError } from "../../capabilities/runtime/errors.js";
|
|
8
7
|
import { defineAtomicCapability } from "../../capabilities/runtime/dispatcher.js";
|
|
8
|
+
import { resolveTaskLocale } from "../task-language.js";
|
|
9
9
|
import { LocalAppTaskMutationSchema } from "../../local-apps/capabilities/projections.js";
|
|
10
10
|
import { resolveProjectAgentId } from "../../projects/project-agent.js";
|
|
11
11
|
import { TaskApplicationService } from "../task-application-service.js";
|