pi-web-ui 0.114.3 → 0.116.0
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/CHANGELOG.md +62 -1
- package/bin/pi-web-ui.mjs +90 -8
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +522 -32
- package/dist/server/agent-service.js +954 -402
- package/dist/server/canvas/canvas-dispatch.js +13 -1
- package/dist/server/client-state.js +42 -2
- package/dist/server/communicate-tool.js +2 -0
- package/dist/server/conversation-communication.js +14 -0
- package/dist/server/conversation-identity.js +27 -0
- package/dist/server/device-center/approval-summary.js +31 -0
- package/dist/server/device-center/bot-catalog.js +21 -7
- package/dist/server/device-center/bot-execution.js +100 -9
- package/dist/server/device-center/bot-presets.js +46 -0
- package/dist/server/device-center/collab-service.js +362 -13
- package/dist/server/device-center/collab-tool.js +824 -13
- package/dist/server/device-center/connector.js +359 -23
- package/dist/server/device-center/desktop-page.js +22 -16
- package/dist/server/device-center/device-integration.js +595 -0
- package/dist/server/device-center/execution-guides.js +32 -0
- package/dist/server/device-center/execution-instructions.js +20 -0
- package/dist/server/device-center/execution-settings.js +213 -0
- package/dist/server/device-center/execution-system-prompt.js +38 -0
- package/dist/server/device-center/execution-workspace.js +20 -0
- package/dist/server/device-center/executor.js +392 -40
- package/dist/server/device-center/file-sync-paths.js +171 -0
- package/dist/server/device-center/file-sync.js +186 -96
- package/dist/server/device-center/group-context-delta.js +37 -0
- package/dist/server/device-center/group-context-message.js +210 -0
- package/dist/server/device-center/group-context.js +179 -0
- package/dist/server/device-center/group-events.js +136 -0
- package/dist/server/device-center/group-plan-guard.js +138 -0
- package/dist/server/device-center/hub-conversations.js +233 -0
- package/dist/server/device-center/hub-deliveries.js +277 -0
- package/dist/server/device-center/hub-integration.js +451 -0
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +13 -33
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +2379 -107
- package/dist/server/device-center/human-interaction.js +232 -0
- package/dist/server/device-center/integration-errors.js +25 -0
- package/dist/server/device-center/local-hub.js +20 -1
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +430 -41
- package/dist/server/device-center/main.js +11 -1
- package/dist/server/device-center/partition-log.js +293 -0
- package/dist/server/device-center/path-portal.js +11 -3
- package/dist/server/device-center/relay.js +364 -35
- package/dist/server/device-center/report-metadata.js +66 -0
- package/dist/server/device-center/report-upload.js +63 -0
- package/dist/server/device-center/runtime.js +598 -41
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +203 -41
- package/dist/server/device-center/task-context-budget.js +161 -0
- package/dist/server/device-center/task-journal.js +385 -0
- package/dist/server/device-center/task-plan.js +33 -0
- package/dist/server/device-center/task-progress.js +141 -0
- package/dist/server/device-center/task-recovery.js +452 -0
- package/dist/server/device-center/task-report-outbox.js +216 -0
- package/dist/server/device-center/task-report.js +384 -0
- package/dist/server/device-center/task-scheduler.js +445 -0
- package/dist/server/device-center/task-state.js +333 -0
- package/dist/server/device-center/transfer-stream.js +1006 -0
- package/dist/server/device-center/transfers.js +841 -8
- package/dist/server/dispatch-domain-handlers.js +35 -6
- package/dist/server/dsh/dsh-agent-service.js +6 -0
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/goal-service.js +10 -5
- package/dist/server/index.js +222 -29
- package/dist/server/managed.js +2 -0
- package/dist/server/markers/builtins/services.js +123 -0
- package/dist/server/markers/builtins/todo.js +189 -0
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/message-deletion.js +40 -0
- package/dist/server/message-window.js +9 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/orchestrator.js +109 -0
- package/dist/server/patch-executable-lookup.js +396 -0
- package/dist/server/payload-limits.js +2 -0
- package/dist/server/plugin-llm.js +100 -9
- package/dist/server/plugins.js +65 -7
- package/dist/server/preset-fields.js +24 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/prompt-base-store.js +85 -0
- package/dist/server/prompt-composer.js +44 -2
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/protocol.js +2 -2
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/remote-ssh-service.js +22 -9
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/session-search.js +1 -1
- package/dist/server/settings-service.js +90 -39
- package/dist/server/skill-content-filler.js +29 -8
- package/dist/server/skill-tool.js +12 -3
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagents.js +52 -37
- package/dist/server/system-prompt-soul.js +41 -0
- package/dist/server/tool-host-factories.js +1 -0
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/dsh-driver.js +379 -0
- package/dist/server/universal/universal-session.js +5 -0
- package/dist/server/webui-context.js +25 -5
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/README.md +94 -0
- package/docs/architecture-plugins.md +946 -0
- package/docs/device-center.md +106 -12
- package/docs/dsh-engine.md +10 -10
- package/extensions/webui.ts +43 -1
- package/package.json +2 -1
- package/themes/aetheris.css +5 -0
- package/themes/ayu-light.css +6 -0
- package/themes/bases/flow-base.css +68 -68
- package/themes/catppuccin-latte.css +6 -0
- package/themes/catppuccin.css +6 -0
- package/themes/claude-code-dark.css +5 -0
- package/themes/codex.css +6 -0
- package/themes/cyberpunk.css +6 -0
- package/themes/dark-teal.css +6 -1
- package/themes/dazzle.css +6 -0
- package/themes/everforest-light.css +6 -0
- package/themes/flow-light.css +8 -1
- package/themes/flow.css +6 -1
- package/themes/geist.css +6 -0
- package/themes/gruvbox-light.css +6 -0
- package/themes/kanagawa-lotus.css +6 -0
- package/themes/md-preview.css +6 -0
- package/themes/mist.css +6 -0
- package/themes/nord.css +6 -0
- package/themes/one-dark.css +6 -0
- package/themes/paper.css +6 -0
- package/themes/rose-pine-dawn.css +6 -0
- package/themes/sakura.css +6 -0
- package/themes/solarized-light.css +6 -0
- package/themes/tokyo-night.css +6 -0
- package/themes/translucent.css +6 -0
- package/themes/transparent.css +6 -0
- package/themes/vs-code-dark.css +5 -0
- package/themes/wallpaper-flow.css +5 -1
- package/themes/wallpaper-obsidian.css +6 -0
- package/themes/white.css +6 -0
- package/themes/zhujian-dark.css +6 -1
- package/themes/zhujian.css +6 -1
- package/themes/zhupi-dark.css +6 -1
- package/themes/zhupi.css +6 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BDoOpj-F.js +1 -0
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +1 -0
- package/web/dist/assets/{CanvasStudio-BSg9ghPV.js → CanvasStudio-B8thymBN.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DxW7C3Sz.js → CanvasStudio-zSxyIx1R.js} +3 -3
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +3 -0
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +1 -0
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +1 -0
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +1 -0
- package/web/dist/assets/Dropdown-C4LIhshN.js +1 -0
- package/web/dist/assets/FilePreview-BgGongmv.js +2 -0
- package/web/dist/assets/FilePreview-D4NrhF-U.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +1 -0
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +1 -0
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +17 -0
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +17 -0
- package/web/dist/assets/HintTip-c6d0TJoh.js +1 -0
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +2 -0
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +2 -0
- package/web/dist/assets/PiSetupModal-BmMrrgB9.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +1 -0
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +2 -0
- package/web/dist/assets/SCMPanel-BU58qk3T.js +2 -0
- package/web/dist/assets/SettingsModal-CMUybq3J.js +32 -0
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +32 -0
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +3 -0
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +3 -0
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +1 -0
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +1 -0
- package/web/dist/assets/app-globals-CZxzGvIo.js +123 -0
- package/web/dist/assets/canvas-client-CUnXlQYX.js +1 -0
- package/web/dist/assets/{desktop-7EvUHhKQ.js → desktop-aAKpvKJV.js} +1 -1
- package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
- package/web/dist/assets/index-C6DwztqE.css +1 -0
- package/web/dist/assets/index-CuN802Sj.js +93 -0
- package/web/dist/assets/index-EH5Fw9fa.js +93 -0
- package/web/dist/assets/plugin-host-BRWib9DF.js +1 -0
- package/web/dist/assets/remote-ssh-client-CfYSMEZg.js +1 -0
- package/web/dist/assets/theme-D2l_mLNo.js +1 -0
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-BvnUHjFe.js +0 -1
- package/web/dist/assets/BgTasksModal-DSC8ncW3.js +0 -1
- package/web/dist/assets/DeviceCenter-Bmgr-Bwm.js +0 -3
- package/web/dist/assets/DeviceCenter-Cl9MBXaH.js +0 -3
- package/web/dist/assets/DeviceGroups-aeLD2msl.js +0 -1
- package/web/dist/assets/Dropdown-D1Jl35dw.js +0 -1
- package/web/dist/assets/FilePreview-6CqoDF_P.js +0 -2
- package/web/dist/assets/FilePreview-CJa27G_Q.js +0 -2
- package/web/dist/assets/GlobalSearchModal-CJX35rZL.js +0 -1
- package/web/dist/assets/GlobalSearchModal-CMW0xz0P.js +0 -1
- package/web/dist/assets/GroupConversation-Cq4daBFb.js +0 -1
- package/web/dist/assets/GroupConversation-DoELa83U.js +0 -1
- package/web/dist/assets/ModelConfigModal-Bp7tfKYh.js +0 -2
- package/web/dist/assets/PiSetupModal-DD8srwBJ.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-C6tfXb88.js +0 -1
- package/web/dist/assets/SCMPanel-CghgsyBN.js +0 -2
- package/web/dist/assets/SCMPanel-D8-8aqwC.js +0 -2
- package/web/dist/assets/SettingsModal-BbBe2rYo.js +0 -20
- package/web/dist/assets/SettingsModal-qETiVPKj.js +0 -20
- package/web/dist/assets/TerminalPanel-Da-Xs4Wk.js +0 -3
- package/web/dist/assets/TerminalPanel-DnS4tFQO.js +0 -3
- package/web/dist/assets/TuiOverlayModal-CGyGkKYl.js +0 -1
- package/web/dist/assets/TuiOverlayModal-CpBKjG6x.js +0 -1
- package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
- package/web/dist/assets/fi-NyN-ZrgD.js +0 -325
- package/web/dist/assets/index-DK3F5ZJo.js +0 -85
- package/web/dist/assets/index-DQMii2he.js +0 -85
- package/web/dist/assets/index-vwBnwzkr.css +0 -1
- package/web/dist/assets/plugin-host-BCnX3P8U.js +0 -1
- package/web/dist/assets/theme-D2DMH6tH.js +0 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { writeJsonAtomicSync } from "../atomic-file.js";
|
|
4
|
+
export const DEFAULT_EXECUTION_SETTINGS = {
|
|
5
|
+
maxActiveTasks: 4,
|
|
6
|
+
maxWaitingTasks: 32,
|
|
7
|
+
starvationThresholdMs: 8000,
|
|
8
|
+
maxSkipsBeforeStarvation: 3,
|
|
9
|
+
maxDispatchDepth: 8,
|
|
10
|
+
maxDispatchBudget: 16,
|
|
11
|
+
allowBotMentions: false,
|
|
12
|
+
groupContextBytes: 262144,
|
|
13
|
+
groupRetentionLimit: 2000,
|
|
14
|
+
fileSyncMaxBytes: 104857600,
|
|
15
|
+
fileSyncMaxFiles: 1000,
|
|
16
|
+
fileSyncStagedBytes: 1073741824,
|
|
17
|
+
resourceLockDefaultTtlMs: 1800000,
|
|
18
|
+
blackboardMaxBytes: 262144,
|
|
19
|
+
taskReportExcerptBytes: 131072,
|
|
20
|
+
maxResourceLocksPerTask: 128,
|
|
21
|
+
botMentionBudgetPerTurn: 3,
|
|
22
|
+
};
|
|
23
|
+
export const EXECUTION_SETTINGS_LIMITS = {
|
|
24
|
+
minActiveTasks: 1,
|
|
25
|
+
maxActiveTasks: 64,
|
|
26
|
+
minWaitingTasks: 0,
|
|
27
|
+
maxWaitingTasks: 1024,
|
|
28
|
+
minStarvationThresholdMs: 1000,
|
|
29
|
+
maxStarvationThresholdMs: 60000,
|
|
30
|
+
minSkipsBeforeStarvation: 1,
|
|
31
|
+
maxSkipsBeforeStarvation: 20,
|
|
32
|
+
minDispatchDepth: 1,
|
|
33
|
+
maxDispatchDepth: 64,
|
|
34
|
+
minDispatchBudget: 1,
|
|
35
|
+
maxDispatchBudget: 256,
|
|
36
|
+
minGroupContextBytes: 4096,
|
|
37
|
+
maxGroupContextBytes: 2097152,
|
|
38
|
+
minGroupRetentionLimit: 50,
|
|
39
|
+
maxGroupRetentionLimit: 20000,
|
|
40
|
+
minFileSyncMaxBytes: 1048576,
|
|
41
|
+
maxFileSyncMaxBytes: 10737418240,
|
|
42
|
+
minFileSyncMaxFiles: 10,
|
|
43
|
+
maxFileSyncMaxFiles: 10000,
|
|
44
|
+
minFileSyncStagedBytes: 4194304,
|
|
45
|
+
maxFileSyncStagedBytes: 53687091200,
|
|
46
|
+
minResourceLockDefaultTtlMs: 60000,
|
|
47
|
+
maxResourceLockDefaultTtlMs: 86400000,
|
|
48
|
+
minBlackboardMaxBytes: 4096,
|
|
49
|
+
maxBlackboardMaxBytes: 4194304,
|
|
50
|
+
minTaskReportExcerptBytes: 4096,
|
|
51
|
+
maxTaskReportExcerptBytes: 524288,
|
|
52
|
+
minMaxResourceLocksPerTask: 1,
|
|
53
|
+
maxMaxResourceLocksPerTask: 256,
|
|
54
|
+
minBotMentionBudgetPerTurn: 1,
|
|
55
|
+
maxBotMentionBudgetPerTurn: 10,
|
|
56
|
+
};
|
|
57
|
+
const NUMBER_RULES = {
|
|
58
|
+
maxActiveTasks: {
|
|
59
|
+
min: EXECUTION_SETTINGS_LIMITS.minActiveTasks,
|
|
60
|
+
max: EXECUTION_SETTINGS_LIMITS.maxActiveTasks,
|
|
61
|
+
},
|
|
62
|
+
maxWaitingTasks: {
|
|
63
|
+
min: EXECUTION_SETTINGS_LIMITS.minWaitingTasks,
|
|
64
|
+
max: EXECUTION_SETTINGS_LIMITS.maxWaitingTasks,
|
|
65
|
+
},
|
|
66
|
+
starvationThresholdMs: {
|
|
67
|
+
min: EXECUTION_SETTINGS_LIMITS.minStarvationThresholdMs,
|
|
68
|
+
max: EXECUTION_SETTINGS_LIMITS.maxStarvationThresholdMs,
|
|
69
|
+
},
|
|
70
|
+
maxSkipsBeforeStarvation: {
|
|
71
|
+
min: EXECUTION_SETTINGS_LIMITS.minSkipsBeforeStarvation,
|
|
72
|
+
max: EXECUTION_SETTINGS_LIMITS.maxSkipsBeforeStarvation,
|
|
73
|
+
},
|
|
74
|
+
maxDispatchDepth: {
|
|
75
|
+
min: EXECUTION_SETTINGS_LIMITS.minDispatchDepth,
|
|
76
|
+
max: EXECUTION_SETTINGS_LIMITS.maxDispatchDepth,
|
|
77
|
+
},
|
|
78
|
+
maxDispatchBudget: {
|
|
79
|
+
min: EXECUTION_SETTINGS_LIMITS.minDispatchBudget,
|
|
80
|
+
max: EXECUTION_SETTINGS_LIMITS.maxDispatchBudget,
|
|
81
|
+
},
|
|
82
|
+
groupContextBytes: {
|
|
83
|
+
min: EXECUTION_SETTINGS_LIMITS.minGroupContextBytes,
|
|
84
|
+
max: EXECUTION_SETTINGS_LIMITS.maxGroupContextBytes,
|
|
85
|
+
},
|
|
86
|
+
groupRetentionLimit: {
|
|
87
|
+
min: EXECUTION_SETTINGS_LIMITS.minGroupRetentionLimit,
|
|
88
|
+
max: EXECUTION_SETTINGS_LIMITS.maxGroupRetentionLimit,
|
|
89
|
+
},
|
|
90
|
+
fileSyncMaxBytes: {
|
|
91
|
+
min: EXECUTION_SETTINGS_LIMITS.minFileSyncMaxBytes,
|
|
92
|
+
max: EXECUTION_SETTINGS_LIMITS.maxFileSyncMaxBytes,
|
|
93
|
+
},
|
|
94
|
+
fileSyncMaxFiles: {
|
|
95
|
+
min: EXECUTION_SETTINGS_LIMITS.minFileSyncMaxFiles,
|
|
96
|
+
max: EXECUTION_SETTINGS_LIMITS.maxFileSyncMaxFiles,
|
|
97
|
+
},
|
|
98
|
+
fileSyncStagedBytes: {
|
|
99
|
+
min: EXECUTION_SETTINGS_LIMITS.minFileSyncStagedBytes,
|
|
100
|
+
max: EXECUTION_SETTINGS_LIMITS.maxFileSyncStagedBytes,
|
|
101
|
+
},
|
|
102
|
+
resourceLockDefaultTtlMs: {
|
|
103
|
+
min: EXECUTION_SETTINGS_LIMITS.minResourceLockDefaultTtlMs,
|
|
104
|
+
max: EXECUTION_SETTINGS_LIMITS.maxResourceLockDefaultTtlMs,
|
|
105
|
+
},
|
|
106
|
+
blackboardMaxBytes: {
|
|
107
|
+
min: EXECUTION_SETTINGS_LIMITS.minBlackboardMaxBytes,
|
|
108
|
+
max: EXECUTION_SETTINGS_LIMITS.maxBlackboardMaxBytes,
|
|
109
|
+
},
|
|
110
|
+
taskReportExcerptBytes: {
|
|
111
|
+
min: EXECUTION_SETTINGS_LIMITS.minTaskReportExcerptBytes,
|
|
112
|
+
max: EXECUTION_SETTINGS_LIMITS.maxTaskReportExcerptBytes,
|
|
113
|
+
},
|
|
114
|
+
maxResourceLocksPerTask: {
|
|
115
|
+
min: EXECUTION_SETTINGS_LIMITS.minMaxResourceLocksPerTask,
|
|
116
|
+
max: EXECUTION_SETTINGS_LIMITS.maxMaxResourceLocksPerTask,
|
|
117
|
+
},
|
|
118
|
+
botMentionBudgetPerTurn: {
|
|
119
|
+
min: EXECUTION_SETTINGS_LIMITS.minBotMentionBudgetPerTurn,
|
|
120
|
+
max: EXECUTION_SETTINGS_LIMITS.maxBotMentionBudgetPerTurn,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
const ALLOWED_KEYS = new Set([...Object.keys(NUMBER_RULES), "allowBotMentions"]);
|
|
124
|
+
export class DeviceExecutionSettingsError extends Error {
|
|
125
|
+
code = "INVALID_EXECUTION_SETTINGS";
|
|
126
|
+
constructor(message, cause) {
|
|
127
|
+
super(message, { cause });
|
|
128
|
+
this.name = "DeviceExecutionSettingsError";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function validateExecutionSettings(input) {
|
|
132
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
133
|
+
return { valid: false, error: "Settings must be an object" };
|
|
134
|
+
}
|
|
135
|
+
const candidate = input;
|
|
136
|
+
// Strict rejection of unknown/extra keys to prevent spelling mistakes
|
|
137
|
+
for (const key of Object.keys(candidate)) {
|
|
138
|
+
if (!ALLOWED_KEYS.has(key)) {
|
|
139
|
+
return { valid: false, error: `Unknown configuration key: ${key}` };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const result = {};
|
|
143
|
+
for (const [key, rule] of Object.entries(NUMBER_RULES)) {
|
|
144
|
+
const raw = candidate[key];
|
|
145
|
+
if (raw === undefined) {
|
|
146
|
+
result[key] = DEFAULT_EXECUTION_SETTINGS[key];
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (typeof raw !== "number" || !Number.isInteger(raw)) {
|
|
150
|
+
return { valid: false, error: `${key} must be an integer` };
|
|
151
|
+
}
|
|
152
|
+
if (raw < rule.min || raw > rule.max) {
|
|
153
|
+
return {
|
|
154
|
+
valid: false,
|
|
155
|
+
error: `${key} must be between ${rule.min} and ${rule.max}`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
result[key] = raw;
|
|
159
|
+
}
|
|
160
|
+
const rawBotMentions = candidate.allowBotMentions;
|
|
161
|
+
if (rawBotMentions === undefined) {
|
|
162
|
+
result.allowBotMentions = DEFAULT_EXECUTION_SETTINGS.allowBotMentions;
|
|
163
|
+
}
|
|
164
|
+
else if (typeof rawBotMentions !== "boolean") {
|
|
165
|
+
return { valid: false, error: "allowBotMentions must be a boolean" };
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
result.allowBotMentions = rawBotMentions;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
valid: true,
|
|
172
|
+
value: result,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function executionSettingsFilePath(dataDir) {
|
|
176
|
+
return join(dataDir, "execution-settings.json");
|
|
177
|
+
}
|
|
178
|
+
export function loadExecutionSettings(dataDir) {
|
|
179
|
+
if (!dataDir)
|
|
180
|
+
return { ...DEFAULT_EXECUTION_SETTINGS };
|
|
181
|
+
const file = executionSettingsFilePath(dataDir);
|
|
182
|
+
let raw;
|
|
183
|
+
try {
|
|
184
|
+
raw = readFileSync(file, "utf8");
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (error.code === "ENOENT") {
|
|
188
|
+
return { ...DEFAULT_EXECUTION_SETTINGS };
|
|
189
|
+
}
|
|
190
|
+
throw new DeviceExecutionSettingsError("Failed to read execution settings file", error);
|
|
191
|
+
}
|
|
192
|
+
let parsed;
|
|
193
|
+
try {
|
|
194
|
+
parsed = JSON.parse(raw);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
throw new DeviceExecutionSettingsError("Execution settings file contains corrupted JSON", error);
|
|
198
|
+
}
|
|
199
|
+
const validated = validateExecutionSettings(parsed);
|
|
200
|
+
if (!validated.valid) {
|
|
201
|
+
throw new DeviceExecutionSettingsError(`Invalid execution settings: ${validated.error}`);
|
|
202
|
+
}
|
|
203
|
+
return validated.value;
|
|
204
|
+
}
|
|
205
|
+
export function saveExecutionSettings(dataDir, settings) {
|
|
206
|
+
const validated = validateExecutionSettings(settings);
|
|
207
|
+
if (!validated.valid) {
|
|
208
|
+
throw new DeviceExecutionSettingsError(validated.error);
|
|
209
|
+
}
|
|
210
|
+
const file = executionSettingsFilePath(dataDir);
|
|
211
|
+
writeJsonAtomicSync(file, validated.value);
|
|
212
|
+
return validated.value;
|
|
213
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { splitAgentStartPrompt } from "../persona-chain.js";
|
|
2
|
+
const ownedSections = ["device_bot", "device_execution"];
|
|
3
|
+
/** Keep execution authority in SDK sections, including when a renderer forces opaque text. */
|
|
4
|
+
export function prepareBotExecutionSystemPrompt(event, execution) {
|
|
5
|
+
// Split before adding sections: earlier extensions wrapped the previous SDK baseline.
|
|
6
|
+
const { pre, core, post } = splitAgentStartPrompt(event);
|
|
7
|
+
if (!execution)
|
|
8
|
+
return { core, rewrap: (next) => pre + next + post };
|
|
9
|
+
const sections = {};
|
|
10
|
+
if (execution.bot.systemPrompt?.trim())
|
|
11
|
+
sections.device_bot = execution.bot.systemPrompt.trim();
|
|
12
|
+
if (execution.instructions.trim())
|
|
13
|
+
sections.device_execution = execution.instructions.trim();
|
|
14
|
+
if (event.systemPromptOptions) {
|
|
15
|
+
const target = (event.systemPromptOptions.sections ??= {});
|
|
16
|
+
for (const name of ownedSections)
|
|
17
|
+
delete target[name];
|
|
18
|
+
Object.assign(target, sections);
|
|
19
|
+
}
|
|
20
|
+
const stripOwnedSections = (text) => {
|
|
21
|
+
for (const name of ownedSections) {
|
|
22
|
+
text = text.replace(new RegExp(`<${name}>\\n[\\s\\S]*?\\n</${name}>`, "g"), "");
|
|
23
|
+
}
|
|
24
|
+
return text;
|
|
25
|
+
};
|
|
26
|
+
const rendered = Object.entries(sections)
|
|
27
|
+
.map(([name, content]) => `<${name}>\n${content}\n</${name}>`)
|
|
28
|
+
.join("\n\n");
|
|
29
|
+
const rewrap = (next) => {
|
|
30
|
+
const wrapped = stripOwnedSections(pre + next + post);
|
|
31
|
+
return rendered ? `${wrapped.trimEnd()}\n\n${rendered}` : wrapped;
|
|
32
|
+
};
|
|
33
|
+
// SDK ignores sections when an earlier extension has already forced the prompt.
|
|
34
|
+
if (typeof event.systemPromptOptions?.forceSystemPrompt === "string") {
|
|
35
|
+
event.systemPromptOptions.forceSystemPrompt = rewrap(core);
|
|
36
|
+
}
|
|
37
|
+
return { core: stripOwnedSections(core), rewrap };
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
/** Canonical roots prevent symlink aliases from bypassing execution isolation. */
|
|
4
|
+
export function executionRoot(path) {
|
|
5
|
+
let root = resolve(path);
|
|
6
|
+
try {
|
|
7
|
+
root = realpathSync.native(root);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
/* Admission validates missing roots separately. */
|
|
11
|
+
}
|
|
12
|
+
return process.platform === "win32" ? root.toLowerCase() : root;
|
|
13
|
+
}
|
|
14
|
+
export function executionRootsOverlap(left, right) {
|
|
15
|
+
const contains = (a, b) => {
|
|
16
|
+
const path = relative(a, b);
|
|
17
|
+
return !path || (!isAbsolute(path) && path !== ".." && !path.startsWith("../") && !path.startsWith("..\\"));
|
|
18
|
+
};
|
|
19
|
+
return contains(left, right) || contains(right, left);
|
|
20
|
+
}
|