@xopcai/xopc 0.0.249 → 0.0.250
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/{activity-store-B759R_qf.js → activity-store-DfBjTSo9.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BUu7EnwM.js → agent-avatar-dicebear-BN6FJXkJ.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-C7rZH1A2.js +1 -0
- package/dist/gateway/static/root/assets/{agents-DK9HjHO0.js → agents-CgGaoo4z.js} +1 -1
- package/dist/gateway/static/root/assets/{api-Cg0v7Lpn.js → api-zxpcJfgj.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-C9DkCW_d.js → app-management-settings-panel-D2gMshuS.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-CFggS95Y.js → appearance-settings-wMu0jSKx.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-jOvT-fzU.js → apps-page-KF1Gnv36.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BQrilVVv.js → archive-plugin-u6EE3JV8.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-BG0BliqV.js → attachment-load-DbJurnv-.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-Bo4RiTkh.js → automations-page-Ew_e5HDn.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-Ch-ldu35.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-BCnyNU0C.js → binary-plugins-DtDFNfPM.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-Db8DlVvg.js → block-editor-CnAwmabq.js} +50 -50
- package/dist/gateway/static/root/assets/browser-settings-page-DtVhsHJW.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-C71vfl0b.js → browser-workflow-inputs-BX1-uM9L.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-vvmSYKsO.js → browser-workflows-page-CcbUOWDF.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel--sXeylhe.js +7 -0
- package/dist/gateway/static/root/assets/channels-settings-AXSBDujZ.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-CKyV3jY5.js → channels-status-swr-CX-yWwLD.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-B1Xd6OFB.js → chat-terminal-dock-CryTDNdD.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-HBHUWohz.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-D-F9vjtE.js → cron-expression-ji5aWrjG.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-B2OoYvic.js → date-picker-Dro_w3eX.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-BiGx9Sbj.js → dependency-picker-Ce19KKnX.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-BNMRqipe.js → desktop-pet-DsSi-3uZ.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-DeYbIV7A.js → desktop-pet-settings-8WQ4woJy.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-COyn05ub.js → extension-debug-page-CgvEBfLZ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-oH43chS2.js → extension-page-DkznBbMj.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BMO59994.js → extension-settings-page-BOjhchK2.js} +1 -1
- package/dist/gateway/static/root/assets/files-BArWTfr7.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-cimpViGk.js → gateway-config-api-OEruhhX3.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-BGdHwT4e.js → gateway-config-swr-CMNbl0FZ.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-BHJtnSic.js → gateway-settings-BgH3A0LO.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CuaM3b4c.js → gateway-startup-retry-CR7Xg8As.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-C97naDkO.js +1 -0
- package/dist/gateway/static/root/assets/home-page-BBKKme4G.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-D7duj7Uj.js → image-generation-api-C5mn73ca.js} +1 -1
- package/dist/gateway/static/root/assets/index-BcaF-dgQ.js +72 -0
- package/dist/gateway/static/root/assets/{index-DGeGmj4k.css → index-DAryGvZ7.css} +1 -1
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D8Zw_lYd.js → keyboard-shortcuts-settings-BYhfzsqe.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-eBFVWmtH.js → local-app-workbench-page-DNncc2tn.js} +2 -2
- package/dist/gateway/static/root/assets/{local-apps-page-CvPDPRwb.js → local-apps-page-vBlknU7C.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-zEL8bkwx.js → locale-store-CF4erhjB.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-ClvcWlL6.js → logs-page-CizZInrT.js} +2 -2
- package/dist/gateway/static/root/assets/{management-settings-D8moh99U.js → management-settings-Dnx6mSNe.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-D7V3j0vE.js → markdown-split-DtBtcHWi.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-DGRN-8wP.js → markdown-view-CQvzsE24.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BLaE5b1Y.js → media-plugins-DrMYeHe7.js} +1 -1
- package/dist/gateway/static/root/assets/messages-Cf5hpZE6.js +3 -0
- package/dist/gateway/static/root/assets/{mobile-pairing-wizard-DiVDuCxl.js → mobile-pairing-wizard-AKgGy3Kx.js} +1 -1
- package/dist/gateway/static/root/assets/note-detail-panel-Bw3jD9Jf.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-Dpqq7Z-J.js +8 -0
- package/dist/gateway/static/root/assets/{page-tabs-BFMGjA60.js → page-tabs-CX9T71by.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-DNEWZN7H.js → preview-open-alternatives-DvEHoimN.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-Co5u7asH.js → product-open-page-COcr_NUJ.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BuT6MCTs.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DXWMxOjf.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-Cg92zSod.js → registry-api-BsRBlji7.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-7rBCUWzZ.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-C0ByNmlV.js → runtime-tools-settings-panel-CQ13P-mS.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-Dq_VQpuY.js → schema-form-BUVyTpZj.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-gmEOYNb4.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DYYoJcl7.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-CZu6FX4k.js → settings-form-section-DVY-8_B9.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-S8ekeUZd.js → settings-page-CdiVYyTl.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-BdVmwXMv.js → setup-status-panel-BhenBnUj.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-D2fEidbn.js → share-preview-page-C88YLKm4.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-Dq7xIj0_.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-MDI9Lz6z.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-AYiPlgZE.js → skills-page-DLir1nM0.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-DGzl-ib-.js → skills-page.utils-BMZAfS3G.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-5Xd5mIiR.js → system-settings-panel-BM8ivYan.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-P0_RldWv.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-ZVClZKQ0.js → theme-store-BOgkc_9D.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-CdZN1Jin.js → tunnel-api-DemxChjo.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-czRI0NBc.js → use-autosave-CV3Ui5hu.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-CxfnoRVn.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-8YEvA3cU.js → voice-api-key-field-CUoCi4Sq.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-CopF64lY.js → voice-config-api-C-ryeIxj.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-keLtqYYJ.js → work-discovery-overlay-BhDlkCMB.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-Dy5WgYMO.js → workflow-run-setup-panel-D8CcPc_C.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-Bxn2Dc16.js +5 -0
- package/dist/gateway/static/root/index.html +11 -11
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/user-message-display.js +18 -0
- package/dist/src/agent/agent-instance-gateway.d.ts +1 -1
- package/dist/src/agent/agent-manager.d.ts +9 -9
- package/dist/src/agent/agent-manager.js +46 -28
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +11 -2
- package/dist/src/agent/context/audit.d.ts +3 -1
- package/dist/src/agent/context/audit.js +32 -6
- package/dist/src/agent/context/coordinator.d.ts +6 -1
- package/dist/src/agent/context/coordinator.js +14 -13
- package/dist/src/agent/context/execution-context.d.ts +6 -47
- package/dist/src/agent/context/execution-context.js +79 -15
- package/dist/src/agent/context/execution-context.types.d.ts +50 -0
- package/dist/src/agent/context/execution-context.types.js +1 -0
- package/dist/src/agent/context/execution-scope.d.ts +5 -1
- package/dist/src/agent/context/execution-scope.js +6 -2
- package/dist/src/agent/context/project-context.d.ts +3 -0
- package/dist/src/agent/context/project-context.js +5 -3
- package/dist/src/agent/external-tools/index.d.ts +1 -0
- package/dist/src/agent/external-tools/index.js +1 -0
- package/dist/src/agent/external-tools/memory-provider.d.ts +1 -0
- package/dist/src/agent/external-tools/memory-provider.js +1 -0
- package/dist/src/agent/inbound/attachment-pipeline.js +5 -1
- package/dist/src/agent/memory/compaction-promotion.d.ts +1 -0
- package/dist/src/agent/memory/compaction-promotion.js +7 -2
- package/dist/src/agent/memory/index.d.ts +1 -1
- package/dist/src/agent/memory/index.js +3 -3
- package/dist/src/agent/memory/memory-config.d.ts +0 -5
- package/dist/src/agent/memory/memory-config.js +1 -8
- package/dist/src/agent/orchestration/context-overflow.js +1 -0
- package/dist/src/agent/service/direct-turn-helpers.d.ts +2 -2
- package/dist/src/agent/service/direct-turn-helpers.js +2 -2
- package/dist/src/agent/service/process-direct-streaming.js +3 -4
- package/dist/src/agent/tools/factory.d.ts +1 -0
- package/dist/src/agent/tools/factory.js +37 -7
- package/dist/src/agent/tools/knowledge-memory-tool.d.ts +6 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +81 -26
- package/dist/src/agent/tools/session-search-tool.d.ts +1 -0
- package/dist/src/agent/tools/session-search-tool.js +7 -0
- package/dist/src/agent/tools/user-context-tool.d.ts +2 -0
- package/dist/src/agent/tools/user-context-tool.js +21 -4
- package/dist/src/automations/service/automation-service.d.ts +2 -1
- package/dist/src/automations/service/automation-service.js +6 -2
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/connectors/connection-recovery-service.d.ts +1 -0
- package/dist/src/connectors/connection-recovery-service.js +46 -22
- package/dist/src/files/file-service.js +4 -1
- package/dist/src/gateway/hono/routes/connectors.js +17 -3
- package/dist/src/gateway/hono/routes/files.js +23 -2
- package/dist/src/gateway/hono/routes/tasks.js +1 -1
- package/dist/src/gateway/security/gateway-scopes.js +2 -0
- package/dist/src/gateway/service/agent-runner.js +1 -1
- package/dist/src/gateway/service/run-gateway-agent.js +1 -1
- package/dist/src/gateway/service/session-input-coordinator.js +1 -1
- package/dist/src/gateway/service.js +8 -4
- package/dist/src/knowledge-memory/domain.d.ts +1 -0
- package/dist/src/knowledge-memory/index.js +2 -2
- package/dist/src/knowledge-memory/repository.d.ts +4 -1
- package/dist/src/knowledge-memory/repository.js +16 -2
- package/dist/src/notifications/planner.js +7 -3
- package/dist/src/proactive/actions/service.d.ts +0 -1
- package/dist/src/proactive/actions/service.js +1 -10
- package/dist/src/proactive/execution/context.d.ts +6 -8
- package/dist/src/proactive/execution/context.js +78 -32
- package/dist/src/proactive/execution/insight.d.ts +4 -1
- package/dist/src/proactive/execution/insight.js +5 -2
- package/dist/src/proactive/execution/repository.d.ts +1 -0
- package/dist/src/proactive/execution/repository.js +9 -1
- package/dist/src/proactive/execution/types.d.ts +0 -1
- package/dist/src/proactive/execution/worker.js +7 -5
- package/dist/src/proactive/inbox/repository.js +8 -2
- package/dist/src/proactive/inbox/service.js +2 -2
- package/dist/src/proactive/inbox/types.d.ts +1 -0
- package/dist/src/proactive/inbox/worker.d.ts +1 -0
- package/dist/src/proactive/inbox/worker.js +7 -0
- package/dist/src/proactive/index.d.ts +1 -0
- package/dist/src/proactive/index.js +2 -1
- package/dist/src/proactive/maintenance.d.ts +4 -0
- package/dist/src/proactive/maintenance.js +21 -0
- package/dist/src/proactive/scenarios/repository.d.ts +1 -1
- package/dist/src/proactive/scenarios/repository.js +10 -3
- package/dist/src/proactive/scenarios/types.d.ts +7 -0
- package/dist/src/proactive/service.d.ts +7 -0
- package/dist/src/proactive/service.js +17 -1
- package/dist/src/projects/project-service.d.ts +2 -1
- package/dist/src/projects/project-service.js +3 -2
- package/dist/src/session/index.js +1 -1
- package/dist/src/session/store.js +5 -2
- package/dist/src/storage/sqlite/collaboration-rule-repository.d.ts +3 -1
- package/dist/src/storage/sqlite/collaboration-rule-repository.js +1 -1
- package/dist/src/storage/sqlite/config-repository.js +1 -1
- package/dist/src/storage/sqlite/connection-wait-repository.js +2 -2
- package/dist/src/storage/sqlite/index.js +2 -2
- package/dist/src/storage/sqlite/migrations/151_proactive_scope_cleanup.sql +6 -0
- package/dist/src/storage/sqlite/migrations/152_proactive_scenario_contract.sql +140 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/row-mappers.js +2 -2
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/session-input-repository.js +1 -1
- package/dist/src/storage/sqlite/session-instance-repository.d.ts +2 -0
- package/dist/src/storage/sqlite/session-instance-repository.js +6 -0
- package/dist/src/storage/sqlite/session-repository.d.ts +1 -1
- package/dist/src/storage/sqlite/session-repository.js +3 -5
- package/dist/src/storage/sqlite/transcript-repository.js +2 -1
- package/dist/src/tasks/home-query-service.js +35 -13
- package/dist/src/tasks/project-monitoring-service.d.ts +2 -0
- package/dist/src/tasks/project-monitoring-service.js +4 -1
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/user-context/access-policy.d.ts +11 -0
- package/dist/src/user-context/access-policy.js +26 -0
- package/dist/src/user-model/capture/executor.d.ts +10 -0
- package/dist/src/user-model/capture/executor.js +99 -3
- package/dist/src/user-model/capture/semantic.d.ts +18 -0
- package/dist/src/user-model/capture/semantic.js +72 -6
- package/dist/src/user-model/goals.d.ts +4 -0
- package/dist/src/user-model/goals.js +4 -2
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-C1rXNUAG.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-BKjKTlW8.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-Dzq18pO1.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DW4SBQf4.js +0 -7
- package/dist/gateway/static/root/assets/channels-settings-57OGuewD.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-CT_I3kbR.js +0 -2
- package/dist/gateway/static/root/assets/files-D6vf3S30.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-DNhrZHqx.js +0 -1
- package/dist/gateway/static/root/assets/home-page-BiHwiBnQ.js +0 -1
- package/dist/gateway/static/root/assets/index-aBs0EfQB.js +0 -72
- package/dist/gateway/static/root/assets/messages-W5P19VTF.js +0 -11
- package/dist/gateway/static/root/assets/note-detail-panel-CEEvR-fV.js +0 -5
- package/dist/gateway/static/root/assets/notes-page-BLqgXNCx.js +0 -8
- package/dist/gateway/static/root/assets/project-detail-page-CIiFJ5tk.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-B3UF-Pfm.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BUtpkJPG.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-UgJmG-V4.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DDCzpdkl.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-BdsqnCYj.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-ghzAQKna.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-BQAUaCDD.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-W3GTm6nA.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-BbAV3h7n.js +0 -5
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { KnowledgeItem, KnowledgeSource, KnowledgeVisibilityContext } from '../../knowledge-memory/index.js';
|
|
2
|
+
import type { UserAssertion } from '../../user-model/domain.js';
|
|
3
|
+
export type RuleEnforcementLevel = 'prompt' | 'planner' | 'tool_gate';
|
|
4
|
+
export interface ExecutionRule {
|
|
5
|
+
id: string;
|
|
6
|
+
statement: string;
|
|
7
|
+
priority: number;
|
|
8
|
+
enforcementLevel: RuleEnforcementLevel;
|
|
9
|
+
conditions: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface RankedExecutionAssertion {
|
|
12
|
+
assertion: UserAssertion;
|
|
13
|
+
score: number;
|
|
14
|
+
reasons: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface ExecutionGoal {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
desiredOutcome: string;
|
|
20
|
+
status: string;
|
|
21
|
+
declaredImportance?: number;
|
|
22
|
+
targetAt?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ExecutionPriority {
|
|
25
|
+
id: string;
|
|
26
|
+
targetType: string;
|
|
27
|
+
targetId: string;
|
|
28
|
+
rank: 'primary' | 'secondary' | 'background';
|
|
29
|
+
urgency: number;
|
|
30
|
+
validTo: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ExecutionContext {
|
|
33
|
+
traceId: string;
|
|
34
|
+
asOf: number;
|
|
35
|
+
query: string;
|
|
36
|
+
rules: ExecutionRule[];
|
|
37
|
+
assertions: RankedExecutionAssertion[];
|
|
38
|
+
goals: ExecutionGoal[];
|
|
39
|
+
priorities: ExecutionPriority[];
|
|
40
|
+
knowledge: KnowledgeItem[];
|
|
41
|
+
}
|
|
42
|
+
export interface ExecutionContextRequest extends KnowledgeVisibilityContext {
|
|
43
|
+
query: string;
|
|
44
|
+
asOf?: number;
|
|
45
|
+
maxAssertions?: number;
|
|
46
|
+
maxKnowledge?: number;
|
|
47
|
+
includeUserModel?: boolean;
|
|
48
|
+
includeKnowledge?: boolean;
|
|
49
|
+
knowledgeSources?: readonly KnowledgeSource[];
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KnowledgeSource } from '../../knowledge-memory/index.js';
|
|
1
2
|
export type ExecutionObjective = {
|
|
2
3
|
kind: 'task';
|
|
3
4
|
id: string;
|
|
@@ -23,4 +24,7 @@ export interface ExecutionScope {
|
|
|
23
24
|
}
|
|
24
25
|
export declare function resolveExecutionScope(sessionKey: string): ExecutionScope;
|
|
25
26
|
export declare function formatCurrentWorkForPrompt(scope: ExecutionScope): string | undefined;
|
|
26
|
-
export declare function buildExecutionScopeContextForPrompt(sessionKey: string
|
|
27
|
+
export declare function buildExecutionScopeContextForPrompt(sessionKey: string, options?: {
|
|
28
|
+
includeKnowledge?: boolean;
|
|
29
|
+
knowledgeSources?: readonly KnowledgeSource[];
|
|
30
|
+
}): string | undefined;
|
|
@@ -77,9 +77,13 @@ function formatCurrentWorkForPrompt(scope) {
|
|
|
77
77
|
lines.push("", "Keep work inside this objective and its project scope. Treat the acceptance criteria and completion evidence as the definition of done.");
|
|
78
78
|
return lines.join("\n");
|
|
79
79
|
}
|
|
80
|
-
function buildExecutionScopeContextForPrompt(sessionKey) {
|
|
80
|
+
function buildExecutionScopeContextForPrompt(sessionKey, options = {}) {
|
|
81
81
|
const scope = resolveExecutionScope(sessionKey);
|
|
82
|
-
return [buildActiveProjectContextForPrompt(sessionKey, {
|
|
82
|
+
return [buildActiveProjectContextForPrompt(sessionKey, {
|
|
83
|
+
knowledgeQuery: scope.objective?.objective,
|
|
84
|
+
includeKnowledge: options.includeKnowledge,
|
|
85
|
+
knowledgeSources: options.knowledgeSources
|
|
86
|
+
}), formatCurrentWorkForPrompt(scope)].filter((section) => Boolean(section?.trim())).join("\n\n") || void 0;
|
|
83
87
|
}
|
|
84
88
|
//#endregion
|
|
85
89
|
export { buildExecutionScopeContextForPrompt, formatCurrentWorkForPrompt, resolveExecutionScope };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Project } from '../../projects/types.js';
|
|
2
|
+
import { type KnowledgeSource } from '../../knowledge-memory/index.js';
|
|
2
3
|
export interface ProjectTaskContext {
|
|
3
4
|
title: string;
|
|
4
5
|
state: string;
|
|
@@ -6,6 +7,8 @@ export interface ProjectTaskContext {
|
|
|
6
7
|
}
|
|
7
8
|
export declare function buildActiveProjectContextForPrompt(sessionKey: string, options?: {
|
|
8
9
|
knowledgeQuery?: string;
|
|
10
|
+
includeKnowledge?: boolean;
|
|
11
|
+
knowledgeSources?: readonly KnowledgeSource[];
|
|
9
12
|
}): string | undefined;
|
|
10
13
|
export declare function formatActiveProjectContextForPrompt(input: {
|
|
11
14
|
project: Project;
|
|
@@ -4,7 +4,7 @@ import { TaskReadModelProjector } from "../../tasks/task-read-model-projector.js
|
|
|
4
4
|
import { LocalAppStore } from "../../local-apps/store.js";
|
|
5
5
|
import { ProjectStore } from "../../projects/project-store.js";
|
|
6
6
|
import { getProjectForSession, getProjectWorkspacePathForSession } from "../../projects/workspace.js";
|
|
7
|
-
import { listKnowledgeItems, searchKnowledgeItems } from "../../knowledge-memory/repository.js";
|
|
7
|
+
import { knowledgeSourceAllowed, listKnowledgeItems, searchKnowledgeItems } from "../../knowledge-memory/repository.js";
|
|
8
8
|
import "../../knowledge-memory/index.js";
|
|
9
9
|
//#region src/agent/context/project-context.ts
|
|
10
10
|
const MAX_TEXT = 1200;
|
|
@@ -49,7 +49,7 @@ function buildActiveProjectContextForPrompt(sessionKey, options = {}) {
|
|
|
49
49
|
state: `${task.phase}/${new TaskReadModelProjector().project(task).operationalState}`
|
|
50
50
|
})),
|
|
51
51
|
recentSessions: new ProjectStore().getRecentSessions(project.id, MAX_SESSIONS),
|
|
52
|
-
knowledgeItems: selectProjectKnowledge({
|
|
52
|
+
knowledgeItems: options.includeKnowledge === false ? [] : selectProjectKnowledge({
|
|
53
53
|
relevant: options.knowledgeQuery?.trim() ? searchKnowledgeItems({
|
|
54
54
|
query: options.knowledgeQuery,
|
|
55
55
|
context: {
|
|
@@ -58,12 +58,14 @@ function buildActiveProjectContextForPrompt(sessionKey, options = {}) {
|
|
|
58
58
|
projectId: project.id,
|
|
59
59
|
sessionId: sessionKey
|
|
60
60
|
},
|
|
61
|
+
trustedOnly: true,
|
|
62
|
+
sources: options.knowledgeSources,
|
|
61
63
|
limit: MAX_RELEVANT_KNOWLEDGE
|
|
62
64
|
}) : [],
|
|
63
65
|
recent: listKnowledgeItems({
|
|
64
66
|
statuses: ["active"],
|
|
65
67
|
limit: 500
|
|
66
|
-
}).filter((item) => item.scope.type === "project" && item.scope.id === project.id).slice(0, MAX_RECENT_KNOWLEDGE)
|
|
68
|
+
}).filter((item) => item.scope.type === "project" && item.scope.id === project.id).filter((item) => item.originClass !== "untrusted").filter((item) => !options.knowledgeSources || knowledgeSourceAllowed(item, options.knowledgeSources)).slice(0, MAX_RECENT_KNOWLEDGE)
|
|
67
69
|
}),
|
|
68
70
|
localApp: localApp ? {
|
|
69
71
|
extensionId: localApp.extensionId,
|
|
@@ -16,6 +16,7 @@ export interface DefaultExternalToolGatewayDeps {
|
|
|
16
16
|
hookRunner?: ExtensionHookRunner;
|
|
17
17
|
toolExecutorConfig?: Partial<ToolExecutorConfig>;
|
|
18
18
|
getMemoryManager?: () => MemoryManager;
|
|
19
|
+
canAccessMemory: () => boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare function createDefaultExternalToolGatewayTools(deps: DefaultExternalToolGatewayDeps): import("@earendil-works/pi-agent-core").AgentTool<import("typebox").TSchema, any>[];
|
|
21
22
|
export { ExternalToolService } from './service.js';
|
|
@@ -32,6 +32,7 @@ function createDefaultExternalToolGatewayTools(deps) {
|
|
|
32
32
|
getMemoryManager: deps.getMemoryManager,
|
|
33
33
|
disabledTools: deps.disabledTools,
|
|
34
34
|
getSessionKey: () => deps.getCurrentContext()?.sessionKey,
|
|
35
|
+
canAccess: deps.canAccessMemory,
|
|
35
36
|
hookRunner: deps.hookRunner,
|
|
36
37
|
toolExecutorConfig: deps.toolExecutorConfig
|
|
37
38
|
})
|
|
@@ -6,6 +6,7 @@ export interface MemoryToolProviderDeps {
|
|
|
6
6
|
getMemoryManager?: () => MemoryManager;
|
|
7
7
|
disabledTools?: Set<string>;
|
|
8
8
|
getSessionKey: () => string | undefined;
|
|
9
|
+
canAccess: () => boolean;
|
|
9
10
|
hookRunner?: ExtensionHookRunner;
|
|
10
11
|
toolExecutorConfig?: Partial<ToolExecutorConfig>;
|
|
11
12
|
}
|
|
@@ -44,6 +44,7 @@ var MemoryToolProvider = class {
|
|
|
44
44
|
return executeToolWithProtection(resolved.tool, context.toolCallId, executionArgs, context.signal, context.onUpdate, this.deps.toolExecutorConfig);
|
|
45
45
|
}
|
|
46
46
|
entries() {
|
|
47
|
+
if (!this.deps.canAccess()) return [];
|
|
47
48
|
return (this.deps.getMemoryManager?.().getExternalToolEntries() ?? []).filter(({ tool }) => !this.deps.disabledTools?.has(tool.name));
|
|
48
49
|
}
|
|
49
50
|
resolve(toolRef) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stripRuntimeUserMessageEnvelope } from "../../../packages/gateway-contract/src/user-message-display.js";
|
|
1
2
|
import { extractProfileAgentId } from "../../config/agent-profile.js";
|
|
2
3
|
import { readAgentMessageContent } from "../memory/agent-message-access.js";
|
|
3
4
|
import { readMediaReferenceBase64 } from "../../media/media-reference.js";
|
|
@@ -134,7 +135,10 @@ function pendingMatchesMessage(pending, message) {
|
|
|
134
135
|
const actualText = messageTextForPendingCompare(message);
|
|
135
136
|
if (!pendingText) return true;
|
|
136
137
|
if (!actualText) return false;
|
|
137
|
-
|
|
138
|
+
if (actualText.includes(pendingText) || pendingText.includes(actualText)) return true;
|
|
139
|
+
const pendingUserText = stripRuntimeUserMessageEnvelope(pendingText).trim();
|
|
140
|
+
const actualUserText = stripRuntimeUserMessageEnvelope(actualText).trim();
|
|
141
|
+
return Boolean(pendingUserText) && (actualUserText === pendingUserText || actualUserText.includes(pendingUserText) || pendingUserText.includes(actualUserText));
|
|
138
142
|
}
|
|
139
143
|
function setPendingTranscriptUserMessage(sessionKey, message) {
|
|
140
144
|
assertTranscriptUserMessage(message);
|
|
@@ -9,6 +9,7 @@ export interface PromoteCompactionLedgerInput {
|
|
|
9
9
|
handover: CompactionHandover;
|
|
10
10
|
audit: CompactionAudit;
|
|
11
11
|
sourceEntries: readonly TranscriptSourceEntry[];
|
|
12
|
+
writePolicy: 'deny' | 'confirm' | 'allow';
|
|
12
13
|
}
|
|
13
14
|
export interface PromoteCompactionLedgerResult {
|
|
14
15
|
episodicRecordIds: string[];
|
|
@@ -84,6 +84,11 @@ function importanceFor(item) {
|
|
|
84
84
|
return .5;
|
|
85
85
|
}
|
|
86
86
|
function promoteCompactionLedger(input) {
|
|
87
|
+
if (input.writePolicy === "deny") return {
|
|
88
|
+
episodicRecordIds: [],
|
|
89
|
+
durableRecordIds: [],
|
|
90
|
+
rejectedRecordIds: []
|
|
91
|
+
};
|
|
87
92
|
const sourceById = new Map(input.sourceEntries.map((entry) => [entry.entryId, entry]));
|
|
88
93
|
const entriesByTurn = /* @__PURE__ */ new Map();
|
|
89
94
|
const entriesByRound = /* @__PURE__ */ new Map();
|
|
@@ -124,7 +129,7 @@ function promoteCompactionLedger(input) {
|
|
|
124
129
|
content: item.text,
|
|
125
130
|
canonicalKey: `compaction:${input.sessionId}:${item.id}`,
|
|
126
131
|
confidence: input.audit.status === "passed" ? .82 : .65,
|
|
127
|
-
status: active ? "candidate" : "archived",
|
|
132
|
+
status: active ? input.writePolicy === "allow" && originClass !== "untrusted" ? "active" : "candidate" : "archived",
|
|
128
133
|
importance: importanceFor(item),
|
|
129
134
|
originClass,
|
|
130
135
|
sourceAgentId: input.sourceAgentId,
|
|
@@ -158,7 +163,7 @@ function promoteCompactionLedger(input) {
|
|
|
158
163
|
content: item.text,
|
|
159
164
|
canonicalKey: `durable:${item.kind}:${stableId("fact", item.text)}`,
|
|
160
165
|
confidence: .82,
|
|
161
|
-
status: "active",
|
|
166
|
+
status: input.writePolicy === "allow" ? "active" : "candidate",
|
|
162
167
|
importance: importanceFor(item),
|
|
163
168
|
originClass: "agent",
|
|
164
169
|
sourceSessionId: input.sessionKey,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { buildUserContextBlock, sanitizeUserContextFenceEscapes, } from './context-fence.js';
|
|
2
2
|
export { createMemoryManagerFromConfig } from './create-memory-manager.js';
|
|
3
|
-
export { isMemorySubsystemEnabled
|
|
3
|
+
export { isMemorySubsystemEnabled } from './memory-config.js';
|
|
4
4
|
export { MemoryManager } from './manager.js';
|
|
5
5
|
export { discoverMemoryPlugins } from './plugin-discovery.js';
|
|
6
6
|
export type { MemoryPluginMetadata } from './plugin-discovery.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isMemorySubsystemEnabled
|
|
1
|
+
import { isMemorySubsystemEnabled } from "./memory-config.js";
|
|
2
2
|
import { extractAgentUserPlainText } from "./user-message-text.js";
|
|
3
|
+
import { buildUserContextBlock, sanitizeUserContextFenceEscapes } from "./context-fence.js";
|
|
3
4
|
import { MemoryManager } from "./manager.js";
|
|
4
5
|
import { discoverMemoryPlugins } from "./plugin-discovery.js";
|
|
5
6
|
import { createMemoryManagerFromConfig } from "./create-memory-manager.js";
|
|
6
|
-
import { buildUserContextBlock, sanitizeUserContextFenceEscapes } from "./context-fence.js";
|
|
7
7
|
import { StubMemoryProvider } from "./stub-memory-provider.js";
|
|
8
|
-
export { MemoryManager, StubMemoryProvider, buildUserContextBlock, createMemoryManagerFromConfig, discoverMemoryPlugins, extractAgentUserPlainText, isMemorySubsystemEnabled, sanitizeUserContextFenceEscapes
|
|
8
|
+
export { MemoryManager, StubMemoryProvider, buildUserContextBlock, createMemoryManagerFromConfig, discoverMemoryPlugins, extractAgentUserPlainText, isMemorySubsystemEnabled, sanitizeUserContextFenceEscapes };
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { Config } from '../../config/schema.js';
|
|
2
2
|
/** Whether generic workspace and provider-backed memory is available. */
|
|
3
3
|
export declare function isMemorySubsystemEnabled(config: Config | undefined): boolean;
|
|
4
|
-
/**
|
|
5
|
-
* Whether to prefix the user message with prefetched external memory this turn.
|
|
6
|
-
* `first-turn` only injects on turn 1. `contextCadence` N injects on turns 1, N+1, 2N+1, …
|
|
7
|
-
*/
|
|
8
|
-
export declare function shouldPlanUserContextThisTurn(_config: Config | undefined, turnNumber: number): boolean;
|
|
@@ -4,12 +4,5 @@ function isMemorySubsystemEnabled(config) {
|
|
|
4
4
|
if (!config) return true;
|
|
5
5
|
return config.userContext.enabled && config.userContext.knowledgeMemory.enabled;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Whether to prefix the user message with prefetched external memory this turn.
|
|
9
|
-
* `first-turn` only injects on turn 1. `contextCadence` N injects on turns 1, N+1, 2N+1, …
|
|
10
|
-
*/
|
|
11
|
-
function shouldPlanUserContextThisTurn(_config, turnNumber) {
|
|
12
|
-
return turnNumber >= 1;
|
|
13
|
-
}
|
|
14
7
|
//#endregion
|
|
15
|
-
export { isMemorySubsystemEnabled
|
|
8
|
+
export { isMemorySubsystemEnabled };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/agent/orchestration/context-overflow.ts
|
|
2
2
|
const CONTEXT_OVERFLOW_PATTERNS = [
|
|
3
3
|
/context(?:_|\s|-)*(?:length|window).*(?:exceed|limit|maximum|too (?:large|long))/i,
|
|
4
|
+
/\bexceed(?:s|ed)?\s+(?:the\s+)?context(?:_|\s|-)*(?:length|window)\b/i,
|
|
4
5
|
/maximum context length/i,
|
|
5
6
|
/max(?:imum)? tokens?.*(?:exceed|limit)/i,
|
|
6
7
|
/too many tokens/i,
|
|
@@ -78,7 +78,7 @@ export interface RunDirectAgentTurnResult {
|
|
|
78
78
|
lastAssistantText?: string;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Convert a user message into an embedded turn, including
|
|
82
|
-
*
|
|
81
|
+
* Convert a user message into an embedded turn, including structured context
|
|
82
|
+
* planning and background-review wiring used by every direct entry point.
|
|
83
83
|
*/
|
|
84
84
|
export declare function runDirectAgentTurn(deps: RunDirectAgentTurnDeps, input: RunDirectAgentTurnInput): Promise<RunDirectAgentTurnResult>;
|
|
@@ -81,8 +81,8 @@ async function tryRunSlashCommand(deps, ctx, content, options) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Convert a user message into an embedded turn, including
|
|
85
|
-
*
|
|
84
|
+
* Convert a user message into an embedded turn, including structured context
|
|
85
|
+
* planning and background-review wiring used by every direct entry point.
|
|
86
86
|
*/
|
|
87
87
|
async function runDirectAgentTurn(deps, input) {
|
|
88
88
|
const turnId = input.runId ?? crypto.randomUUID();
|
|
@@ -267,8 +267,7 @@ async function* runProcessDirectStreaming(deps, input) {
|
|
|
267
267
|
const skillTurn = deps.agentManager.prepareSkillTurn(sessionKey, mergedUserText);
|
|
268
268
|
const textForAgent = skillTurn.text;
|
|
269
269
|
const userMessage = await deps.buildTranscriptUserMessage(textForAgent, prepared, sessionKey);
|
|
270
|
-
const
|
|
271
|
-
const sourceContexts = [...turnSourceContexts];
|
|
270
|
+
const sourceContexts = [...input.sourceContexts ?? []];
|
|
272
271
|
if (deps.sourceContextResolver) {
|
|
273
272
|
const metadata = await deps.sessionStore.getMetadata(sessionKey).catch(() => null);
|
|
274
273
|
const sourceBinding = metadata?.customData && typeof metadata.customData === "object" ? metadata.customData.sourceBinding : void 0;
|
|
@@ -283,11 +282,11 @@ async function* runProcessDirectStreaming(deps, input) {
|
|
|
283
282
|
timestamp: userMessage.timestamp ?? Date.now(),
|
|
284
283
|
content: readAgentMessageContent(userMessage),
|
|
285
284
|
media: userMessage.media,
|
|
286
|
-
metadata:
|
|
285
|
+
metadata: sourceContexts.length > 0 ? { sourceContexts: sourceContexts.map(summarizeSourceContext) } : void 0
|
|
287
286
|
});
|
|
288
287
|
if (textForAgent.trim()) deps.enqueueProvisionalSessionTitle?.(sessionKey, textForAgent);
|
|
289
288
|
}
|
|
290
|
-
const pendingUserMessage =
|
|
289
|
+
const pendingUserMessage = sourceContexts.length > 0 ? injectSourceContextsIntoUserMessage(userMessage, sourceContexts) : userMessage;
|
|
291
290
|
if (!isConnectionResume) setPendingTranscriptUserMessage(sessionKey, pendingUserMessage);
|
|
292
291
|
try {
|
|
293
292
|
const result = await deps.agentManager.withSkillCapabilities(sessionKey, skillTurn.activatedCapabilityNames, () => runDirectAgentTurn({
|
|
@@ -92,6 +92,7 @@ export interface CreateCoreToolsOptions {
|
|
|
92
92
|
getPrimaryModel?: () => Model<Api>;
|
|
93
93
|
getMemoryManager?: () => MemoryManager;
|
|
94
94
|
agentId?: string;
|
|
95
|
+
sessionKey?: string;
|
|
95
96
|
/** When set, registers local skill tools plus marketplace discovery for this workspace. */
|
|
96
97
|
getSkillManager?: () => SkillManager;
|
|
97
98
|
}
|
|
@@ -2,6 +2,7 @@ import { init_paths_state, resolveStateDir } from "../../config/paths-state.js";
|
|
|
2
2
|
import { createLogger } from "../../utils/logger/index.js";
|
|
3
3
|
import { init_logger } from "../../utils/logger.js";
|
|
4
4
|
import { isXopcDatabaseOpen } from "../../storage/sqlite/connection.js";
|
|
5
|
+
import { getSessionMetadata } from "../../storage/sqlite/session-repository.js";
|
|
5
6
|
import { getSessionTaskPlan, setSessionTaskPlan } from "../../storage/sqlite/session-task-plan-repository.js";
|
|
6
7
|
import "../../storage/sqlite/index.js";
|
|
7
8
|
import { init_agent_scope, resolveDefaultAgentId } from "../agent-scope.js";
|
|
@@ -55,6 +56,7 @@ import { createManagedJobTool } from "./managed-job-tool.js";
|
|
|
55
56
|
import { createImageTool } from "./image-tool.js";
|
|
56
57
|
import { createImageGenerateTool } from "./image-generate-tool.js";
|
|
57
58
|
import "./index.js";
|
|
59
|
+
import { resolveUserContextSessionAccess } from "../../user-context/access-policy.js";
|
|
58
60
|
import { createBrowserUseTool } from "./browser/tool/browser-use-tool.js";
|
|
59
61
|
import { createReviewWorkspaceTool } from "./review-workspace.js";
|
|
60
62
|
import { createLanguageDiagnosticsTool } from "./language-diagnostics.js";
|
|
@@ -199,6 +201,13 @@ var AgentToolsFactory = class AgentToolsFactory {
|
|
|
199
201
|
});
|
|
200
202
|
const agentId = options?.agentId;
|
|
201
203
|
const resolvedAgentId = agentId ?? (cfg ? resolveDefaultAgentId(cfg) : "main");
|
|
204
|
+
const currentSessionKey = () => options?.sessionKey ?? this.deps.getCurrentContext?.()?.sessionKey;
|
|
205
|
+
const currentAccess = () => resolveUserContextSessionAccess(this.deps.getConfig?.(), currentSessionKey());
|
|
206
|
+
const knowledgeWritePolicy = () => this.deps.getConfig?.()?.userContext.knowledgeMemory.writePolicy ?? "deny";
|
|
207
|
+
const currentProjectId = () => {
|
|
208
|
+
const key = currentSessionKey();
|
|
209
|
+
return key ? getSessionMetadata(key)?.projectId : void 0;
|
|
210
|
+
};
|
|
202
211
|
const getCommandIsolation = () => {
|
|
203
212
|
const config = this.deps.getConfig?.();
|
|
204
213
|
return config ? resolveEffectiveAgentConfigForSession(config, this.deps.getCurrentContext()?.sessionKey ?? `agent:${agentId ?? "main"}:internal`).config.runtime.commandIsolation : void 0;
|
|
@@ -213,7 +222,8 @@ var AgentToolsFactory = class AgentToolsFactory {
|
|
|
213
222
|
disabledTools: disabled,
|
|
214
223
|
hookRunner: this.deps.hookRunner,
|
|
215
224
|
toolExecutorConfig: this.deps.toolExecutorConfig,
|
|
216
|
-
getMemoryManager: getMemMgr
|
|
225
|
+
getMemoryManager: getMemMgr,
|
|
226
|
+
canAccessMemory: () => currentAccess().knowledge
|
|
217
227
|
});
|
|
218
228
|
const optionalTools = [imageTool, imageGenerateTool].filter((t) => t != null);
|
|
219
229
|
const readTool = createReadFileTool(workspace, { profileMarkdownRoot: options?.profileMarkdownRoot });
|
|
@@ -314,27 +324,46 @@ var AgentToolsFactory = class AgentToolsFactory {
|
|
|
314
324
|
createUserContextSearchTool({
|
|
315
325
|
agentId: resolvedAgentId,
|
|
316
326
|
workspaceId: workspace,
|
|
317
|
-
getSessionId:
|
|
327
|
+
getSessionId: currentSessionKey,
|
|
328
|
+
getProjectId: currentProjectId,
|
|
329
|
+
canRead: () => currentAccess().userModel
|
|
318
330
|
}),
|
|
319
331
|
createUserContextGetTool({
|
|
320
332
|
agentId: resolvedAgentId,
|
|
321
333
|
workspaceId: workspace,
|
|
322
|
-
getSessionId:
|
|
334
|
+
getSessionId: currentSessionKey,
|
|
335
|
+
getProjectId: currentProjectId,
|
|
336
|
+
canRead: () => currentAccess().userModel
|
|
323
337
|
}),
|
|
324
338
|
createKnowledgeSearchTool({
|
|
325
339
|
agentId: resolvedAgentId,
|
|
326
340
|
workspaceId: workspace,
|
|
327
|
-
getSessionId:
|
|
341
|
+
getSessionId: currentSessionKey,
|
|
342
|
+
getProjectId: currentProjectId,
|
|
343
|
+
canRead: () => currentAccess().knowledge,
|
|
344
|
+
canWrite: () => currentAccess().knowledge,
|
|
345
|
+
getWritePolicy: knowledgeWritePolicy,
|
|
346
|
+
getSources: () => currentAccess().knowledgeSources
|
|
328
347
|
}),
|
|
329
348
|
createKnowledgeGetTool({
|
|
330
349
|
agentId: resolvedAgentId,
|
|
331
350
|
workspaceId: workspace,
|
|
332
|
-
getSessionId:
|
|
351
|
+
getSessionId: currentSessionKey,
|
|
352
|
+
getProjectId: currentProjectId,
|
|
353
|
+
canRead: () => currentAccess().knowledge,
|
|
354
|
+
canWrite: () => currentAccess().knowledge,
|
|
355
|
+
getWritePolicy: knowledgeWritePolicy,
|
|
356
|
+
getSources: () => currentAccess().knowledgeSources
|
|
333
357
|
}),
|
|
334
358
|
createKnowledgeWriteTool({
|
|
335
359
|
agentId: resolvedAgentId,
|
|
336
360
|
workspaceId: workspace,
|
|
337
|
-
getSessionId:
|
|
361
|
+
getSessionId: currentSessionKey,
|
|
362
|
+
getProjectId: currentProjectId,
|
|
363
|
+
canRead: () => currentAccess().knowledge,
|
|
364
|
+
canWrite: () => currentAccess().knowledge,
|
|
365
|
+
getWritePolicy: knowledgeWritePolicy,
|
|
366
|
+
getSources: () => currentAccess().knowledgeSources
|
|
338
367
|
}),
|
|
339
368
|
...this.deps.getSessionStore ? [createSessionRecallTool({
|
|
340
369
|
getSessionStore: this.deps.getSessionStore,
|
|
@@ -343,7 +372,8 @@ var AgentToolsFactory = class AgentToolsFactory {
|
|
|
343
372
|
...this.deps.getSessionStore && getPrimary ? [createSessionSearchTool({
|
|
344
373
|
getSessionStore: this.deps.getSessionStore,
|
|
345
374
|
getPrimaryModel: getPrimary,
|
|
346
|
-
getCurrentSessionKey: () => this.deps.getCurrentContext()?.sessionKey
|
|
375
|
+
getCurrentSessionKey: () => this.deps.getCurrentContext()?.sessionKey,
|
|
376
|
+
canAccess: () => currentAccess().crossSessionHistory
|
|
347
377
|
})] : [],
|
|
348
378
|
...this.deps.getAutomationService ? [createAutomationTool({ getAutomationService: this.deps.getAutomationService })] : [],
|
|
349
379
|
...browserEnabled && this.deps.getBrowserRecipeService ? [createBrowserRecipeTool({ getBrowserRecipeService: this.deps.getBrowserRecipeService })] : [],
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import { type KnowledgeSource } from '../../knowledge-memory/index.js';
|
|
2
3
|
export interface KnowledgeToolOptions {
|
|
3
4
|
agentId: string;
|
|
4
5
|
workspaceId: string;
|
|
5
6
|
getSessionId: () => string | undefined;
|
|
7
|
+
getProjectId?: () => string | undefined;
|
|
8
|
+
canRead: () => boolean;
|
|
9
|
+
canWrite: () => boolean;
|
|
10
|
+
getWritePolicy: () => 'deny' | 'confirm' | 'allow';
|
|
11
|
+
getSources: () => readonly KnowledgeSource[];
|
|
6
12
|
}
|
|
7
13
|
export declare function createKnowledgeSearchTool(options: KnowledgeToolOptions): AgentTool;
|
|
8
14
|
export declare function createKnowledgeGetTool(options: KnowledgeToolOptions): AgentTool;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getKnowledgeItem, searchKnowledgeItems, writeKnowledgeItem } from "../../knowledge-memory/repository.js";
|
|
1
|
+
import { getKnowledgeItem, knowledgeSourceAllowed, searchKnowledgeItems, writeKnowledgeItem } from "../../knowledge-memory/repository.js";
|
|
2
2
|
import "../../knowledge-memory/index.js";
|
|
3
3
|
import { Type } from "@sinclair/typebox";
|
|
4
4
|
//#region src/agent/tools/knowledge-memory-tool.ts
|
|
@@ -23,17 +23,23 @@ const WriteSchema = Type.Object({
|
|
|
23
23
|
]),
|
|
24
24
|
content: Type.String(),
|
|
25
25
|
canonicalKey: Type.String(),
|
|
26
|
-
scope: Type.Union([
|
|
26
|
+
scope: Type.Union([
|
|
27
|
+
Type.Literal("workspace"),
|
|
28
|
+
Type.Literal("project"),
|
|
29
|
+
Type.Literal("session")
|
|
30
|
+
]),
|
|
27
31
|
importance: Type.Optional(Type.Number({
|
|
28
32
|
minimum: 0,
|
|
29
33
|
maximum: 1
|
|
30
34
|
}))
|
|
31
35
|
});
|
|
32
36
|
function visibility(options) {
|
|
37
|
+
const projectId = options.getProjectId?.();
|
|
33
38
|
return {
|
|
34
39
|
agentId: options.agentId,
|
|
35
40
|
workspaceId: options.workspaceId,
|
|
36
|
-
sessionId: options.getSessionId() ?? ""
|
|
41
|
+
sessionId: options.getSessionId() ?? "",
|
|
42
|
+
...projectId ? { projectId } : {}
|
|
37
43
|
};
|
|
38
44
|
}
|
|
39
45
|
function createKnowledgeSearchTool(options) {
|
|
@@ -43,10 +49,18 @@ function createKnowledgeSearchTool(options) {
|
|
|
43
49
|
description: "Search project, workspace, and session knowledge for prior decisions, facts, lessons, and commitments.",
|
|
44
50
|
parameters: SearchSchema,
|
|
45
51
|
async execute(_toolCallId, raw) {
|
|
52
|
+
if (!options.canRead()) return {
|
|
53
|
+
content: [{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: "Knowledge memory is disabled for this session."
|
|
56
|
+
}],
|
|
57
|
+
details: { error: "knowledge_memory_disabled" }
|
|
58
|
+
};
|
|
46
59
|
const input = raw;
|
|
47
60
|
const results = searchKnowledgeItems({
|
|
48
61
|
query: input.query,
|
|
49
62
|
context: visibility(options),
|
|
63
|
+
sources: options.getSources(),
|
|
50
64
|
limit: input.maxResults ?? 12
|
|
51
65
|
});
|
|
52
66
|
return {
|
|
@@ -60,7 +74,7 @@ function createKnowledgeSearchTool(options) {
|
|
|
60
74
|
};
|
|
61
75
|
}
|
|
62
76
|
function visibleItem(options, item) {
|
|
63
|
-
return item.scope.type === "global" || item.scope.type === "agent" && item.scope.id === options.agentId || item.scope.type === "workspace" && item.scope.id === options.workspaceId || item.scope.type === "session" && item.scope.id === options.getSessionId();
|
|
77
|
+
return item.scope.type === "global" || item.scope.type === "agent" && item.scope.id === options.agentId || item.scope.type === "workspace" && item.scope.id === options.workspaceId || item.scope.type === "project" && item.scope.id === options.getProjectId?.() || item.scope.type === "session" && item.scope.id === options.getSessionId();
|
|
64
78
|
}
|
|
65
79
|
function createKnowledgeGetTool(options) {
|
|
66
80
|
return {
|
|
@@ -69,9 +83,16 @@ function createKnowledgeGetTool(options) {
|
|
|
69
83
|
description: "Read one knowledge item returned by knowledge_search.",
|
|
70
84
|
parameters: GetSchema,
|
|
71
85
|
async execute(_toolCallId, raw) {
|
|
86
|
+
if (!options.canRead()) return {
|
|
87
|
+
content: [{
|
|
88
|
+
type: "text",
|
|
89
|
+
text: "Knowledge memory is disabled for this session."
|
|
90
|
+
}],
|
|
91
|
+
details: { error: "knowledge_memory_disabled" }
|
|
92
|
+
};
|
|
72
93
|
const id = raw.id;
|
|
73
94
|
const item = getKnowledgeItem(id);
|
|
74
|
-
return item && visibleItem(options, item) ? {
|
|
95
|
+
return item && visibleItem(options, item) && knowledgeSourceAllowed(item, options.getSources()) ? {
|
|
75
96
|
content: [{
|
|
76
97
|
type: "text",
|
|
77
98
|
text: JSON.stringify(item, null, 2)
|
|
@@ -91,36 +112,70 @@ function createKnowledgeWriteTool(options) {
|
|
|
91
112
|
return {
|
|
92
113
|
name: "knowledge_write",
|
|
93
114
|
label: "Knowledge Write",
|
|
94
|
-
description: "Store
|
|
115
|
+
description: "Store scoped knowledge with provenance, subject to the configured write policy.",
|
|
95
116
|
parameters: WriteSchema,
|
|
96
117
|
async execute(_toolCallId, raw) {
|
|
118
|
+
if (!options.canWrite()) return {
|
|
119
|
+
content: [{
|
|
120
|
+
type: "text",
|
|
121
|
+
text: "Knowledge memory writes are disabled for this session."
|
|
122
|
+
}],
|
|
123
|
+
details: { error: "knowledge_memory_disabled" }
|
|
124
|
+
};
|
|
125
|
+
const writePolicy = options.getWritePolicy();
|
|
126
|
+
if (writePolicy === "deny") return {
|
|
127
|
+
content: [{
|
|
128
|
+
type: "text",
|
|
129
|
+
text: "Knowledge memory writes are denied by policy."
|
|
130
|
+
}],
|
|
131
|
+
details: { error: "knowledge_write_denied" }
|
|
132
|
+
};
|
|
97
133
|
const input = raw;
|
|
134
|
+
if (!options.getSources().includes(input.scope)) return {
|
|
135
|
+
content: [{
|
|
136
|
+
type: "text",
|
|
137
|
+
text: `Knowledge source is disabled: ${input.scope}`
|
|
138
|
+
}],
|
|
139
|
+
details: {
|
|
140
|
+
error: "knowledge_source_disabled",
|
|
141
|
+
source: input.scope
|
|
142
|
+
}
|
|
143
|
+
};
|
|
98
144
|
const sessionId = options.getSessionId();
|
|
99
145
|
if (input.scope === "session" && !sessionId) throw new Error("A current session is required for session knowledge.");
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
146
|
+
const projectId = options.getProjectId?.();
|
|
147
|
+
if (input.scope === "project" && !projectId) throw new Error("A current project is required for project knowledge.");
|
|
148
|
+
const details = {
|
|
149
|
+
...writeKnowledgeItem({
|
|
150
|
+
kind: input.kind,
|
|
151
|
+
scope: input.scope === "workspace" ? {
|
|
152
|
+
type: "workspace",
|
|
153
|
+
id: options.workspaceId
|
|
154
|
+
} : input.scope === "project" ? {
|
|
155
|
+
type: "project",
|
|
156
|
+
id: projectId
|
|
157
|
+
} : {
|
|
158
|
+
type: "session",
|
|
159
|
+
id: sessionId
|
|
160
|
+
},
|
|
161
|
+
content: input.content,
|
|
162
|
+
canonicalKey: input.canonicalKey,
|
|
163
|
+
status: writePolicy === "allow" ? "active" : "candidate",
|
|
164
|
+
confidence: .7,
|
|
165
|
+
importance: input.importance ?? .5,
|
|
166
|
+
originClass: "agent",
|
|
167
|
+
sourceAgentId: options.agentId,
|
|
168
|
+
...sessionId ? { sourceSessionId: sessionId } : {},
|
|
169
|
+
source: { tool: "knowledge_write" }
|
|
170
|
+
}),
|
|
171
|
+
writePolicy
|
|
172
|
+
};
|
|
118
173
|
return {
|
|
119
174
|
content: [{
|
|
120
175
|
type: "text",
|
|
121
|
-
text: JSON.stringify(
|
|
176
|
+
text: JSON.stringify(details, null, 2)
|
|
122
177
|
}],
|
|
123
|
-
details
|
|
178
|
+
details
|
|
124
179
|
};
|
|
125
180
|
}
|
|
126
181
|
};
|
|
@@ -5,5 +5,6 @@ export interface SessionSearchToolDeps {
|
|
|
5
5
|
getSessionStore: () => SessionStore;
|
|
6
6
|
getPrimaryModel: () => Model<Api>;
|
|
7
7
|
getCurrentSessionKey?: () => string | undefined;
|
|
8
|
+
canAccess?: () => boolean;
|
|
8
9
|
}
|
|
9
10
|
export declare function createSessionSearchTool(deps: SessionSearchToolDeps): AgentTool;
|