@pi-chamber/web 0.7.1 → 0.8.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/README.md +2 -1
- package/bin/cli.js +2 -2
- package/bin/cli.test.js +98 -1
- package/bin/lib/DOCUMENTATION.md +2 -1
- package/bin/lib/cli-args.js +8 -5
- package/bin/lib/cli-startup.js +10 -7
- package/bin/lib/cli-startup.test.js +28 -0
- package/bin/lib/commands-startup.js +152 -6
- package/dist/assets/{DiagramEditor-C7xe1Brl.js → DiagramEditor-YPSKccgo.js} +1 -1
- package/dist/assets/DiagramView-C-PbBHce.js +1 -0
- package/dist/assets/DiffView-DfltyfN2.js +18 -0
- package/dist/assets/FilesView-BEjbLiK2.js +6 -0
- package/dist/assets/GitView-B_zTaXX4.js +8 -0
- package/dist/assets/JsonTreeView-9p4txyB_.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CbRPLK2x.js +12 -0
- package/dist/assets/PatchDiff-rKjeUBRl.js +1 -0
- package/dist/assets/SessionSwitcherContent-C_VxKFJy.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-_k4P32o9.js +2 -0
- package/dist/assets/SessionUnreadDot-bT_0MixU.js +1 -0
- package/dist/assets/SettingsView-CqZ1ZAWG.js +2 -0
- package/dist/assets/SettingsWindow-C7vVE35-.js +1 -0
- package/dist/assets/ToolOutputDialog-GBbzATa6.js +8 -0
- package/dist/assets/ToolPartDiffPreview-Bdb9p5uS.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-DFx8xsmh.js → VirtualizedFileDiff-CA8hQyz9.js} +4 -4
- package/dist/assets/{Virtualizer-BxW2CJGB.js → Virtualizer-BSHVMKgK.js} +1 -1
- package/dist/assets/{appThemeRegistry-BK0dHKa6.js → appThemeRegistry-gegrE2dq.js} +1 -1
- package/dist/assets/collapsible-uwSKBy-K.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-9LNCLvAG.js +3 -0
- package/dist/assets/contextFileOpenGuard-CZSqdEHk.js +1 -0
- package/dist/assets/gitStatusPredicates-CRmbLl-x.js +134 -0
- package/dist/assets/index-BeJEipxi.js +1 -0
- package/dist/assets/index-CaP8oFLB.js +8 -0
- package/dist/assets/index-Dq8CnRYM.css +1 -0
- package/dist/assets/isDiffPlainText-YYyZNTdb.js +1 -0
- package/dist/assets/isFilePlainText-C70Z71bG.js +1 -0
- package/dist/assets/main-CsdVAKy_.js +135 -0
- package/dist/assets/main-GMQIZjuQ.js +2 -0
- package/dist/assets/{markdownCore-CzWR_p3k.js → markdownCore-BgVcDt0q.js} +2 -2
- package/dist/assets/miniChat-W6YsdiWR.js +2 -0
- package/dist/assets/mobile-BFR9CR5w.js +2 -0
- package/dist/assets/{permissionStore-BRcQ9Jgt.js → permissionStore-iKN1K2_x.js} +1 -1
- package/dist/assets/registerCustomTheme-DmolaWWZ.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-B8ZiW-3E.js +2 -0
- package/dist/assets/renderMobileApp-C5CdsYP6.js +11 -0
- package/dist/assets/runtimeEndpointReset-D3AZYuoF.js +54 -0
- package/dist/assets/{runtimeSurface-OhCUGSKg.js → runtimeSurface-B818u-_c.js} +1 -1
- package/dist/assets/themeResolver-yJ9XpNMI.js +1 -0
- package/dist/assets/{WindowsWindowControls-DIqnZ2uU.js → useAppFontEffects-CYzYRbLp.js} +126 -499
- package/dist/assets/useFilesViewSearch-C--GWtn-.js +7 -0
- package/dist/assets/usePushVisibilityBeacon-D9lajdAc.js +10 -0
- package/dist/assets/useSwitcherItems-DOoi3x_8.js +1 -0
- package/dist/assets/vendor-base-ui-vkqQ2P9o.js +1 -0
- package/dist/assets/{vendor-beautiful-mermaid-r4GK_usS.js → vendor-beautiful-mermaid-DneUawHp.js} +1 -1
- package/dist/assets/{vendor-cmdk-BCEUzcHE.js → vendor-cmdk-zXx6sGnS.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-BS2SpSAZ.js → vendor-codemirror-autocomplete-wd6iRebq.js} +1 -1
- package/dist/assets/{vendor-codemirror-commands-RrgJ8H_6.js → vendor-codemirror-commands-DYppkHEk.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-ADhO_TUK.js → vendor-codemirror-lang-angular-DU_4KiiW.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-BGCWj7Om.js → vendor-codemirror-lang-cpp-CmIT9Z5_.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-Ba8JZ6fp.js → vendor-codemirror-lang-css-djiuoTi8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-DyTiHXo4.js → vendor-codemirror-lang-go-COZSwZYW.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-DK27qQri.js → vendor-codemirror-lang-html-CKHqhW5R.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CvFfnhPQ.js → vendor-codemirror-lang-java-CNMP5hyC.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-BUlYhQ3o.js → vendor-codemirror-lang-javascript-DuOEwJ3f.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-wBMtAEvT.js → vendor-codemirror-lang-jinja-DaKn_b1k.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-CqayksDf.js → vendor-codemirror-lang-json-CZ07HmNC.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-Ct3-H1PB.js → vendor-codemirror-lang-less-wJdQiDBf.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-XspREksq.js → vendor-codemirror-lang-liquid-0z48Roi8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-CvO36Y1p.js → vendor-codemirror-lang-markdown-DtcZDGqe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BlUF9cCe.js → vendor-codemirror-lang-php-W8plS-JQ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-_2bIYTiJ.js → vendor-codemirror-lang-python-DzzokVau.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-BdTYih_U.js → vendor-codemirror-lang-rust-C4ulBVpf.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-E6MhfOFk.js → vendor-codemirror-lang-sass-BkZJYEwS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-B1BRhQSF.js → vendor-codemirror-lang-sql-HpQWHJjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BYQJRa1Q.js → vendor-codemirror-lang-vue-DiBPljCc.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-D706yuyC.js → vendor-codemirror-lang-wast-DoABsogh.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml--MfWU6Dj.js → vendor-codemirror-lang-xml-BhLJhOCH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-CRUFIbRX.js → vendor-codemirror-lang-yaml-D95i1Y5R.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-E2vgV9K3.js → vendor-codemirror-language-BByA_dGF.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-Dv4zaHRN.js → vendor-codemirror-language-data-DS_4W5G4.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-8kyQdB3f.js → vendor-codemirror-search-BV44140v.js} +1 -1
- package/dist/assets/{vendor-codemirror-view-DSzLbZiS.js → vendor-codemirror-view-Ct4T37Ue.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-accessibility-Cv52zwWT.js → vendor-dnd-kit-accessibility-DZKKhs9S.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-core-GipZW2tY.js → vendor-dnd-kit-core-CP8ck10N.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-sortable-Ct2QxIHb.js → vendor-dnd-kit-sortable-B-Icjoj4.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-utilities-CrOcp0Bp.js → vendor-dnd-kit-utilities-DTY1C6ST.js} +1 -1
- package/dist/assets/{vendor-elkjs-CRCLNXjf.js → vendor-elkjs-mzfkf0ML.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-Bkw82kL9.js → vendor-floating-ui-dom-WyXykhNi.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-sVFnuruh.js → vendor-floating-ui-react-dom-BZOGXAGe.js} +1 -1
- package/dist/assets/{vendor-framer-motion-DJASDzNt.js → vendor-framer-motion-BUygY0oN.js} +1 -1
- package/dist/assets/{vendor-heic2any-L8hyfc24.js → vendor-heic2any-BHsbokcA.js} +1 -1
- package/dist/assets/{vendor-lru_map-B-cPXHXW.js → vendor-lru_map-Cy8fTs3_.js} +1 -1
- package/dist/assets/{vendor-pierre-theming-C6Z4M5_u.js → vendor-pierre-theming-Dgp7B_O4.js} +1 -1
- package/dist/assets/{vendor-qrcode-COsmt6jn.js → vendor-qrcode-B0KNSajT.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-compose-refs-D1GnwnP9.js → vendor-radix-ui-react-compose-refs-8xy6TJML.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-context-CM4yFQ2I.js → vendor-radix-ui-react-context-CFsX-AUC.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-dialog-jX3Dld8c.js → vendor-radix-ui-react-dialog-D2yhEu2p.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-dismissable-layer-M7LsH3yL.js → vendor-radix-ui-react-dismissable-layer-DrorBNg9.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-focus-guards-D5MZ0nQs.js → vendor-radix-ui-react-focus-guards-BfdFmL7c.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-focus-scope-C2K7lNPv.js → vendor-radix-ui-react-focus-scope-D2BkImwt.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-id-BcxRjnbX.js → vendor-radix-ui-react-id-D2kS9K1j.js} +1 -1
- package/dist/assets/vendor-radix-ui-react-portal-YgCRIyi7.js +1 -0
- package/dist/assets/{vendor-radix-ui-react-presence-Btn-Dp7L.js → vendor-radix-ui-react-presence-D432pCMB.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-primitive-CfpW6_IT.js → vendor-radix-ui-react-primitive-DkH8dMOR.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-slot-BxUc3Pvz.js → vendor-radix-ui-react-slot-BIDFZX0-.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-use-callback-ref-UKEWHtoP.js → vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js} +1 -1
- package/dist/assets/{vendor-radix-ui-react-use-controllable-state-C_ecoh35.js → vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js} +1 -1
- package/dist/assets/vendor-radix-ui-react-use-effect-event-D94va83M.js +1 -0
- package/dist/assets/{vendor-radix-ui-react-use-escape-keydown-Co13lHGj.js → vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js} +1 -1
- package/dist/assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js +1 -0
- package/dist/assets/{vendor-react-DYyjh7Q0.js → vendor-react-B5Z1Mdn3.js} +1 -1
- package/dist/assets/{vendor-react-drawio-Boqanm0j.js → vendor-react-drawio-BYDptOsj.js} +1 -1
- package/dist/assets/{vendor-react-remove-scroll-bar-C9YRs2nU.js → vendor-react-remove-scroll-bar-CSAHp1YF.js} +1 -1
- package/dist/assets/{vendor-react-remove-scroll-CfeMe0DL.js → vendor-react-remove-scroll-vR1dy1aP.js} +1 -1
- package/dist/assets/{vendor-react-style-singleton-B1H4bWSG.js → vendor-react-style-singleton-Ctw6HnYx.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-BJY5fGLS.js → vendor-replit-codemirror-vim-CGHHNQxC.js} +1 -1
- package/dist/assets/{vendor-sonner-CW8w438f.js → vendor-sonner-BDtm25td.js} +1 -1
- package/dist/assets/{vendor-tanstack-react-virtual-IrbCBGJ4.js → vendor-tanstack-react-virtual-2skouoFw.js} +1 -1
- package/dist/assets/{vendor-use-callback-ref-CJB0R85I.js → vendor-use-callback-ref-CVVuCyLj.js} +1 -1
- package/dist/assets/{vendor-use-sidecar-C-AuTczP.js → vendor-use-sidecar-Vv4V8Nd1.js} +1 -1
- package/dist/assets/{vendor-use-sync-external-store-B7OScDIw.js → vendor-use-sync-external-store-D0AXkdQC.js} +1 -1
- package/dist/assets/{vendor-zustand-CnsBKjP5.js → vendor-zustand-GVb4H8HE.js} +1 -1
- package/dist/assets/{web-components-BOt08OHk.js → web-components-C2cMNPqE.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +1 -1
- package/server/lib/git/DOCUMENTATION.md +3 -2
- package/server/lib/git/routes.js +27 -0
- package/server/lib/git/routes.test.js +41 -0
- package/server/lib/git/service.js +7 -1
- package/server/lib/git/service.test.js +23 -0
- package/server/lib/package-manager.js +32 -1
- package/server/lib/package-manager.test.js +21 -0
- package/server/lib/pi/attachment-store.js +95 -22
- package/server/lib/pi/attachment-store.test.js +23 -0
- package/server/lib/pi/routes.js +383 -49
- package/server/lib/pi/routes.test.js +377 -3
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +3 -3
- package/server/lib/pi/session-daemon/prompt-operations.test.js +318 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +2 -0
- package/server/lib/pi/session-daemon/session-daemon.js +316 -25
- package/server/lib/pi/session-daemon/session-daemon.test.js +137 -0
- package/server/lib/pi/session-daemon/supervisor.test.js +1 -1
- package/server/lib/pi/snippets-store.js +400 -0
- package/server/lib/pi/snippets-store.test.js +252 -0
- package/server/lib/relay/host-client.test.js +79 -15
- package/server/lib/server/cors.js +2 -0
- package/server/lib/server/cors.test.js +6 -5
- package/dist/assets/CommitSection-DuGkZ_bm.js +0 -1
- package/dist/assets/DiagramView-BTqROEWP.js +0 -1
- package/dist/assets/DiffView-hcqXTjEc.js +0 -18
- package/dist/assets/FilesView-GadyKxta.js +0 -14
- package/dist/assets/GitView-BKy-hYUN.js +0 -6
- package/dist/assets/JsonTreeView-CGc4eTGI.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CqfEAhPM.js +0 -12
- package/dist/assets/PatchDiff-P17-Byb8.js +0 -1
- package/dist/assets/PierreDiffViewer-BbUCO4IF.js +0 -136
- package/dist/assets/SessionSwitcherContent-j6KFBSe0.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-DSVeuuVL.js +0 -2
- package/dist/assets/SessionUnreadDot-BVBBEBTg.js +0 -1
- package/dist/assets/SettingsView-FnmtcWZc.js +0 -4
- package/dist/assets/SettingsWindow-Bascj0V3.js +0 -1
- package/dist/assets/ToolOutputDialog-CPMzJ27S.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BZSRKHHM.js +0 -8
- package/dist/assets/collapsible-DlqZyxEY.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-elCbdk6U.js +0 -3
- package/dist/assets/contextFileOpenGuard-BmQ7Zu-L.js +0 -1
- package/dist/assets/index-BerHSX92.js +0 -1
- package/dist/assets/index-ChFxkws4.js +0 -8
- package/dist/assets/index-DZ-f_hCQ.css +0 -1
- package/dist/assets/isDiffPlainText-CvfRfc7h.js +0 -1
- package/dist/assets/isFilePlainText-_vq9Ghu3.js +0 -1
- package/dist/assets/main-DTCOwPr3.js +0 -2
- package/dist/assets/main-DYs-nZO6.js +0 -133
- package/dist/assets/miniChat-C2XxEA3N.js +0 -2
- package/dist/assets/mobile-BQhAOqV7.js +0 -2
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-M2bY1WKA.js +0 -2
- package/dist/assets/renderMobileApp-BnpHUUhY.js +0 -14
- package/dist/assets/themeResolver-BmJyTmjJ.js +0 -1
- package/dist/assets/useInlineCommentController-DC0iNSYX.js +0 -2
- package/dist/assets/usePanelSlide-aeAIo1cp.js +0 -56
- package/dist/assets/usePushVisibilityBeacon-om5Qlrt6.js +0 -10
- package/dist/assets/useSwitcherItems-Bln2r_Q2.js +0 -1
- package/dist/assets/vendor-base-ui-DL8r2fgQ.js +0 -1
- package/dist/assets/vendor-radix-ui-react-portal-xlJWBfDg.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-effect-event-DkJl_Rn_.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-layout-effect-0fyGwS2_.js +0 -1
- package/dist/assets/vendor-remixicon-react-CzPq62YO.js +0 -1
- /package/dist/assets/{usePanelSlide-BV3KOtdA.css → runtimeEndpointReset-BV3KOtdA.css} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { createServer } from 'node:net';
|
|
3
|
-
import { chmod, mkdir, lstat, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { chmod, link, mkdir, lstat, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { createReadStream, existsSync, readFileSync } from 'node:fs';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { createInterface } from 'node:readline';
|
|
8
|
-
import { basename, dirname, isAbsolute, join } from 'node:path';
|
|
8
|
+
import { basename, dirname, isAbsolute, join, relative } from 'node:path';
|
|
9
9
|
import { hasTrustRequiringProjectResources } from '@earendil-works/pi-coding-agent';
|
|
10
10
|
import { StringDecoder } from 'node:string_decoder';
|
|
11
11
|
import {
|
|
@@ -205,6 +205,28 @@ export function createSessionDaemon({
|
|
|
205
205
|
const activeRunStartedAt = new Map();
|
|
206
206
|
const sendGenerationBySession = new Map();
|
|
207
207
|
const settledSendGenerationBySession = new Map();
|
|
208
|
+
// Pi emits each user message start before its persisted entry is readable.
|
|
209
|
+
// Keep prompt metadata in send order so queued follow-ups cannot attach the
|
|
210
|
+
// next prompt's files to an earlier user message.
|
|
211
|
+
const pendingUserStartsBySession = new Map();
|
|
212
|
+
const enqueueUserStart = (sessionId, generation, files) => {
|
|
213
|
+
const pending = pendingUserStartsBySession.get(sessionId) ?? [];
|
|
214
|
+
pending.push({ generation, files });
|
|
215
|
+
pendingUserStartsBySession.set(sessionId, pending);
|
|
216
|
+
};
|
|
217
|
+
const takeUserStart = (sessionId) => {
|
|
218
|
+
const pending = pendingUserStartsBySession.get(sessionId);
|
|
219
|
+
const next = pending?.shift();
|
|
220
|
+
if (!pending?.length) pendingUserStartsBySession.delete(sessionId);
|
|
221
|
+
return next;
|
|
222
|
+
};
|
|
223
|
+
const removeUserStart = (sessionId, generation) => {
|
|
224
|
+
const pending = pendingUserStartsBySession.get(sessionId);
|
|
225
|
+
if (!pending) return;
|
|
226
|
+
const remaining = pending.filter((entry) => entry.generation !== generation);
|
|
227
|
+
if (remaining.length > 0) pendingUserStartsBySession.set(sessionId, remaining);
|
|
228
|
+
else pendingUserStartsBySession.delete(sessionId);
|
|
229
|
+
};
|
|
208
230
|
const shutdownRequestedBySession = new Set();
|
|
209
231
|
const disposingSessionIds = new Set();
|
|
210
232
|
const streamingRedactionBuffers = new Map();
|
|
@@ -922,13 +944,48 @@ export function createSessionDaemon({
|
|
|
922
944
|
const timestamp = Date.parse(entry.timestamp);
|
|
923
945
|
const createdAt = Number.isFinite(timestamp) ? timestamp : 0;
|
|
924
946
|
if (entry.message.role === 'user') {
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
947
|
+
const userParts = [];
|
|
948
|
+
let rawText = '';
|
|
949
|
+
if (typeof entry.message.content === 'string') {
|
|
950
|
+
rawText = entry.message.content;
|
|
951
|
+
} else if (Array.isArray(entry.message.content)) {
|
|
952
|
+
for (let index = 0; index < entry.message.content.length; index += 1) {
|
|
953
|
+
const part = entry.message.content[index];
|
|
954
|
+
if (part?.type === 'text') {
|
|
955
|
+
rawText += (rawText ? '\n\n' : '') + (part.text || '');
|
|
956
|
+
} else if (part?.type === 'image' && typeof part.data === 'string') {
|
|
957
|
+
const mime = part.mimeType || 'image/png';
|
|
958
|
+
userParts.push({
|
|
959
|
+
type: 'file',
|
|
960
|
+
id: `${entry.id}:image:${index}`,
|
|
961
|
+
index,
|
|
962
|
+
mime,
|
|
963
|
+
url: `data:${mime};base64,${part.data}`,
|
|
964
|
+
filename: 'image.png',
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
const attachmentNamedRegex = /\[Attachment\s+(.+?)\s+is available at\s+([^\]]+)\]/gi;
|
|
971
|
+
let match;
|
|
972
|
+
while ((match = attachmentNamedRegex.exec(rawText)) !== null) {
|
|
973
|
+
const filename = match[1].trim();
|
|
974
|
+
userParts.push({
|
|
975
|
+
type: 'file',
|
|
976
|
+
id: `${entry.id}:attachment:${userParts.length}`,
|
|
977
|
+
index: userParts.length,
|
|
978
|
+
filename,
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
let text = rawText.replace(/(\r?\n)*\s*\[Attachment\s+.+?\s+is available at\s+[^\]]+\]/gi, '');
|
|
983
|
+
text = redactAttachmentPaths(text).trim();
|
|
930
984
|
latestUserMessageId = entry.id;
|
|
931
|
-
return [{
|
|
985
|
+
return [{
|
|
986
|
+
message: { id: entry.id, sessionId: session.sessionId, directory: targetDir, role: 'user', text, createdAt },
|
|
987
|
+
parts: userParts,
|
|
988
|
+
}];
|
|
932
989
|
}
|
|
933
990
|
if (entry.message.role !== 'assistant' || !Array.isArray(entry.message.content)) return [];
|
|
934
991
|
const text = redactAttachmentPaths(textFromContent(entry.message.content));
|
|
@@ -998,6 +1055,7 @@ export function createSessionDaemon({
|
|
|
998
1055
|
const isStreaming = session.isStreaming === true;
|
|
999
1056
|
const retry = retryStateBySession.get(session.sessionId);
|
|
1000
1057
|
const compaction = compactionStateFor(session);
|
|
1058
|
+
const extensionSnapshot = extensionBridge.getSnapshotState(session.sessionId);
|
|
1001
1059
|
return {
|
|
1002
1060
|
session: {
|
|
1003
1061
|
id: session.sessionId, directory: targetDir, createdAt, updatedAt: createdAt,
|
|
@@ -1014,6 +1072,12 @@ export function createSessionDaemon({
|
|
|
1014
1072
|
...(compaction ? { compaction } : {}),
|
|
1015
1073
|
...(activeRunStartedAt.has(session.sessionId) ? { runStartedAt: activeRunStartedAt.get(session.sessionId) } : {}),
|
|
1016
1074
|
serverNow: Date.now(),
|
|
1075
|
+
...(extensionSnapshot.statuses ? { extensionStatuses: extensionSnapshot.statuses } : {}),
|
|
1076
|
+
...(extensionSnapshot.widgets ? { extensionWidgets: extensionSnapshot.widgets } : {}),
|
|
1077
|
+
...(extensionSnapshot.dialogs ? { extensionDialogs: extensionSnapshot.dialogs } : {}),
|
|
1078
|
+
...(extensionSnapshot.panels ? { extensionPanels: extensionSnapshot.panels } : {}),
|
|
1079
|
+
...(extensionSnapshot.apps ? { extensionApps: extensionSnapshot.apps } : {}),
|
|
1080
|
+
...(extensionSnapshot.title ? { extensionTitle: extensionSnapshot.title } : {}),
|
|
1017
1081
|
};
|
|
1018
1082
|
};
|
|
1019
1083
|
|
|
@@ -1485,6 +1549,11 @@ export function createSessionDaemon({
|
|
|
1485
1549
|
|
|
1486
1550
|
const resourceId = (kind, filePath) => `${kind}:${createHash('sha256').update(filePath).digest('base64url')}`;
|
|
1487
1551
|
|
|
1552
|
+
const isPathInside = (parent, candidate) => {
|
|
1553
|
+
const child = relative(parent, candidate);
|
|
1554
|
+
return child.length > 0 && !child.startsWith('..') && !isAbsolute(child);
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1488
1557
|
const resourceLocation = (sourceInfo) => {
|
|
1489
1558
|
if (sourceInfo?.scope === 'project') return 'project';
|
|
1490
1559
|
if (sourceInfo?.origin === 'package') return 'package';
|
|
@@ -1546,6 +1615,13 @@ export function createSessionDaemon({
|
|
|
1546
1615
|
if (runtime?.session?.isStreaming) throw new SessionDaemonProtocolError('SESSION_BUSY', 'Resources cannot change during an active session.');
|
|
1547
1616
|
};
|
|
1548
1617
|
|
|
1618
|
+
let resourceMutation = Promise.resolve();
|
|
1619
|
+
const transactResourceMutation = (operation) => {
|
|
1620
|
+
const pending = resourceMutation.then(operation);
|
|
1621
|
+
resourceMutation = pending.catch(() => {});
|
|
1622
|
+
return pending;
|
|
1623
|
+
};
|
|
1624
|
+
|
|
1549
1625
|
const writeResourceFile = async (filePath, content) => {
|
|
1550
1626
|
const temporary = `${filePath}.${randomUUID()}.tmp`;
|
|
1551
1627
|
await mkdir(dirname(filePath), { recursive: true, mode: 0o700 });
|
|
@@ -1558,6 +1634,22 @@ export function createSessionDaemon({
|
|
|
1558
1634
|
}
|
|
1559
1635
|
};
|
|
1560
1636
|
|
|
1637
|
+
const writeNewResourceFile = async (filePath, content) => {
|
|
1638
|
+
const temporary = `${filePath}.${randomUUID()}.tmp`;
|
|
1639
|
+
await mkdir(dirname(filePath), { recursive: true, mode: 0o700 });
|
|
1640
|
+
try {
|
|
1641
|
+
await writeFile(temporary, content, { encoding: 'utf8', mode: 0o600 });
|
|
1642
|
+
await link(temporary, filePath);
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
1645
|
+
if (error?.code === 'EEXIST') {
|
|
1646
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template already exists.');
|
|
1647
|
+
}
|
|
1648
|
+
throw error;
|
|
1649
|
+
}
|
|
1650
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1561
1653
|
const refreshResources = async (targetDir) => {
|
|
1562
1654
|
servicesCache.delete(targetDir || activeDirectory || cwd);
|
|
1563
1655
|
if (runtime) {
|
|
@@ -1586,13 +1678,16 @@ export function createSessionDaemon({
|
|
|
1586
1678
|
return refreshResources(targetDir);
|
|
1587
1679
|
};
|
|
1588
1680
|
|
|
1589
|
-
const createPrompt = async (
|
|
1681
|
+
const createPrompt = (payload) => transactResourceMutation(async () => {
|
|
1590
1682
|
if (!payload || !['global', 'project'].includes(payload.location) || typeof payload.name !== 'string' || typeof payload.content !== 'string'
|
|
1591
1683
|
|| typeof payload.description !== 'string' || payload.content.length > 200_000 || payload.description.length > 4_000
|
|
1592
1684
|
|| !/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(payload.name)) {
|
|
1593
1685
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template is invalid.');
|
|
1594
1686
|
}
|
|
1595
1687
|
requireIdleResourceMutation();
|
|
1688
|
+
if (payload.location === 'project' && !payload.directory) {
|
|
1689
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'Project prompt templates require an explicit directory.');
|
|
1690
|
+
}
|
|
1596
1691
|
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (activeDirectory || cwd);
|
|
1597
1692
|
const trust = createTrustStore(agentDir).get(targetDir);
|
|
1598
1693
|
if (payload.location === 'project' && trust !== true) throw new SessionDaemonProtocolError('PROJECT_UNTRUSTED', 'The project is not trusted.');
|
|
@@ -1603,21 +1698,152 @@ export function createSessionDaemon({
|
|
|
1603
1698
|
} catch (error) {
|
|
1604
1699
|
if (error?.code !== 'ENOENT') throw error;
|
|
1605
1700
|
}
|
|
1606
|
-
await
|
|
1701
|
+
await writeNewResourceFile(filePath, `---\ndescription: ${JSON.stringify(payload.description)}\n---\n${payload.content}`);
|
|
1607
1702
|
return refreshResources(targetDir);
|
|
1608
|
-
};
|
|
1703
|
+
});
|
|
1609
1704
|
|
|
1610
|
-
const deletePrompt = async (
|
|
1705
|
+
const deletePrompt = (payload) => transactResourceMutation(async () => {
|
|
1611
1706
|
if (!payload || typeof payload.resourceId !== 'string') throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template is invalid.');
|
|
1612
1707
|
requireIdleResourceMutation();
|
|
1613
1708
|
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (activeDirectory || cwd);
|
|
1614
1709
|
const catalog = await resourceCatalog(targetDir);
|
|
1615
1710
|
const resource = catalog.prompts.find((item) => item.id === payload.resourceId && item.editable === true);
|
|
1616
1711
|
if (!resource?.filePath) throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
1712
|
+
const expectedDeletePrefix =
|
|
1713
|
+
resource.location === 'global'
|
|
1714
|
+
? join(agentDir, 'prompts')
|
|
1715
|
+
: join(targetDir, '.pi', 'prompts');
|
|
1716
|
+
if (typeof resource.filePath !== 'string' || !isPathInside(expectedDeletePrefix, resource.filePath)) {
|
|
1717
|
+
throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
1718
|
+
}
|
|
1719
|
+
if (resource.location === 'project') {
|
|
1720
|
+
if (!payload.directory) throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'Project prompt templates require an explicit directory.');
|
|
1721
|
+
const trust = createTrustStore(agentDir).get(targetDir);
|
|
1722
|
+
if (trust !== true) throw new SessionDaemonProtocolError('PROJECT_UNTRUSTED', 'The project is not trusted.');
|
|
1723
|
+
}
|
|
1617
1724
|
await rm(resource.filePath);
|
|
1618
1725
|
return refreshResources(targetDir);
|
|
1726
|
+
});
|
|
1727
|
+
|
|
1728
|
+
const PROMPT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
|
|
1729
|
+
|
|
1730
|
+
const splitPromptFile = (raw) => {
|
|
1731
|
+
const match = typeof raw === 'string' ? raw.match(/^(---\r?\n[\s\S]*?\r?\n---\r?\n?)/) : null;
|
|
1732
|
+
if (match) {
|
|
1733
|
+
return { frontmatter: match[1], body: raw.slice(match[1].length) };
|
|
1734
|
+
}
|
|
1735
|
+
return { frontmatter: '', body: typeof raw === 'string' ? raw : '' };
|
|
1619
1736
|
};
|
|
1620
1737
|
|
|
1738
|
+
const withUpdatedDescription = (frontmatter, description) => {
|
|
1739
|
+
if (description === undefined) return frontmatter;
|
|
1740
|
+
const serialized = `description: ${JSON.stringify(description)}`;
|
|
1741
|
+
if (!frontmatter) {
|
|
1742
|
+
return `---\n${serialized}\n---\n`;
|
|
1743
|
+
}
|
|
1744
|
+
const lines = frontmatter.split(/\r?\n/);
|
|
1745
|
+
let replaced = false;
|
|
1746
|
+
const nextLines = lines.map((line) => {
|
|
1747
|
+
if (!replaced && /^description\s*:/.test(line)) {
|
|
1748
|
+
replaced = true;
|
|
1749
|
+
return serialized;
|
|
1750
|
+
}
|
|
1751
|
+
return line;
|
|
1752
|
+
});
|
|
1753
|
+
if (!replaced) {
|
|
1754
|
+
const closingIndex = nextLines.lastIndexOf('---');
|
|
1755
|
+
const insertAt = closingIndex > 0 ? closingIndex : 1;
|
|
1756
|
+
nextLines.splice(insertAt, 0, serialized);
|
|
1757
|
+
}
|
|
1758
|
+
return nextLines.join('\n');
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
const updatePrompt = (payload) => transactResourceMutation(async () => {
|
|
1762
|
+
if (!payload || typeof payload.resourceId !== 'string') {
|
|
1763
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template update is invalid.');
|
|
1764
|
+
}
|
|
1765
|
+
const hasName = payload.name !== undefined;
|
|
1766
|
+
const hasDescription = payload.description !== undefined;
|
|
1767
|
+
const hasContent = payload.content !== undefined;
|
|
1768
|
+
const hasLocation = payload.location !== undefined;
|
|
1769
|
+
if (!hasName && !hasDescription && !hasContent && !hasLocation) {
|
|
1770
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template update is invalid.');
|
|
1771
|
+
}
|
|
1772
|
+
if (hasName && (typeof payload.name !== 'string' || !PROMPT_NAME_PATTERN.test(payload.name))) {
|
|
1773
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template name is invalid.');
|
|
1774
|
+
}
|
|
1775
|
+
if (hasDescription && (typeof payload.description !== 'string' || payload.description.length > 4_000)) {
|
|
1776
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template description is invalid.');
|
|
1777
|
+
}
|
|
1778
|
+
if (hasContent && (typeof payload.content !== 'string' || payload.content.length > 200_000)) {
|
|
1779
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template content is invalid.');
|
|
1780
|
+
}
|
|
1781
|
+
if (hasLocation && payload.location !== 'global' && payload.location !== 'project') {
|
|
1782
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template location is invalid.');
|
|
1783
|
+
}
|
|
1784
|
+
requireIdleResourceMutation();
|
|
1785
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (activeDirectory || cwd);
|
|
1786
|
+
const catalog = await resourceCatalog(targetDir);
|
|
1787
|
+
const resource = catalog.prompts.find((item) => item.id === payload.resourceId && item.editable === true);
|
|
1788
|
+
if (!resource?.filePath) throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
1789
|
+
const sourceLocation = resource.location;
|
|
1790
|
+
const expectedPrefix =
|
|
1791
|
+
sourceLocation === 'global'
|
|
1792
|
+
? join(agentDir, 'prompts')
|
|
1793
|
+
: join(targetDir, '.pi', 'prompts');
|
|
1794
|
+
const normalizedFilePath = resource.filePath;
|
|
1795
|
+
if (typeof normalizedFilePath !== 'string' || !isPathInside(expectedPrefix, normalizedFilePath)) {
|
|
1796
|
+
throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
1797
|
+
}
|
|
1798
|
+
const destLocation = hasLocation ? payload.location : sourceLocation;
|
|
1799
|
+
if (destLocation !== 'global' && destLocation !== 'project') {
|
|
1800
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template location is invalid.');
|
|
1801
|
+
}
|
|
1802
|
+
const destName = hasName ? payload.name : resource.name;
|
|
1803
|
+
const isRename = destName !== resource.name;
|
|
1804
|
+
const isLocationMove = destLocation !== sourceLocation;
|
|
1805
|
+
const needsNewFile = isRename || isLocationMove;
|
|
1806
|
+
if (destLocation === 'project' || sourceLocation === 'project') {
|
|
1807
|
+
if (!payload.directory) throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'Project prompt templates require an explicit directory.');
|
|
1808
|
+
const trust = createTrustStore(agentDir).get(targetDir);
|
|
1809
|
+
if (trust !== true) throw new SessionDaemonProtocolError('PROJECT_UNTRUSTED', 'The project is not trusted.');
|
|
1810
|
+
}
|
|
1811
|
+
const previousRaw = await readFile(resource.filePath, 'utf8').catch((error) => {
|
|
1812
|
+
if (error?.code === 'ENOENT') throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
1813
|
+
throw error;
|
|
1814
|
+
});
|
|
1815
|
+
const { frontmatter, body } = splitPromptFile(previousRaw);
|
|
1816
|
+
const nextFrontmatter = withUpdatedDescription(frontmatter, hasDescription ? payload.description : undefined);
|
|
1817
|
+
const nextBody = hasContent ? payload.content : body;
|
|
1818
|
+
const nextFileContent = `${nextFrontmatter}${nextBody}`;
|
|
1819
|
+
if (!needsNewFile) {
|
|
1820
|
+
await writeResourceFile(resource.filePath, nextFileContent);
|
|
1821
|
+
return refreshResources(targetDir);
|
|
1822
|
+
}
|
|
1823
|
+
if (!PROMPT_NAME_PATTERN.test(destName)) {
|
|
1824
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template name is invalid.');
|
|
1825
|
+
}
|
|
1826
|
+
const destPath = join(destLocation === 'global' ? agentDir : join(targetDir, '.pi'), 'prompts', `${destName}.md`);
|
|
1827
|
+
if (destPath === resource.filePath) {
|
|
1828
|
+
await writeResourceFile(resource.filePath, nextFileContent);
|
|
1829
|
+
return refreshResources(targetDir);
|
|
1830
|
+
}
|
|
1831
|
+
try {
|
|
1832
|
+
await readFile(destPath, 'utf8');
|
|
1833
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template already exists.');
|
|
1834
|
+
} catch (error) {
|
|
1835
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
1836
|
+
}
|
|
1837
|
+
await writeNewResourceFile(destPath, nextFileContent);
|
|
1838
|
+
try {
|
|
1839
|
+
await rm(resource.filePath);
|
|
1840
|
+
} catch (error) {
|
|
1841
|
+
await rm(destPath, { force: true }).catch(() => {});
|
|
1842
|
+
throw error;
|
|
1843
|
+
}
|
|
1844
|
+
return refreshResources(targetDir);
|
|
1845
|
+
});
|
|
1846
|
+
|
|
1621
1847
|
const setSessionModel = async (activeRuntime, model) => {
|
|
1622
1848
|
if (!model || typeof model.providerId !== 'string' || typeof model.modelId !== 'string') {
|
|
1623
1849
|
throw new SessionDaemonProtocolError('INVALID_MODEL', 'The requested Pi model is invalid.');
|
|
@@ -1861,15 +2087,17 @@ export function createSessionDaemon({
|
|
|
1861
2087
|
};
|
|
1862
2088
|
|
|
1863
2089
|
const prepareAttachmentContent = async (attachments) => {
|
|
1864
|
-
if (attachments === undefined) return { text: '', images: [] };
|
|
2090
|
+
if (attachments === undefined) return { text: '', images: [], files: [] };
|
|
1865
2091
|
if (!Array.isArray(attachments) || attachments.length > 32) throw new SessionDaemonProtocolError('INVALID_PROMPT', 'The session attachments are invalid.');
|
|
1866
2092
|
const text = [];
|
|
1867
2093
|
const images = [];
|
|
2094
|
+
const files = [];
|
|
1868
2095
|
for (const attachment of attachments) {
|
|
1869
2096
|
if (!attachment || typeof attachment.path !== 'string' || typeof attachment.name !== 'string'
|
|
1870
2097
|
|| typeof attachment.mime !== 'string' || !Number.isSafeInteger(attachment.size) || attachment.size <= 0) {
|
|
1871
2098
|
throw new SessionDaemonProtocolError('INVALID_PROMPT', 'The session attachments are invalid.');
|
|
1872
2099
|
}
|
|
2100
|
+
files.push({ mime: attachment.mime, filename: attachment.name });
|
|
1873
2101
|
try {
|
|
1874
2102
|
if (attachment.mime.startsWith('image/') && attachment.size <= 20 * 1024 * 1024) {
|
|
1875
2103
|
const data = await readFile(attachment.path);
|
|
@@ -1885,7 +2113,7 @@ export function createSessionDaemon({
|
|
|
1885
2113
|
throw err;
|
|
1886
2114
|
}
|
|
1887
2115
|
}
|
|
1888
|
-
return { text: text.join('\n'), images };
|
|
2116
|
+
return { text: text.join('\n'), images, files };
|
|
1889
2117
|
};
|
|
1890
2118
|
|
|
1891
2119
|
const sessionInput = async (payload, delivery) => {
|
|
@@ -1909,9 +2137,26 @@ export function createSessionDaemon({
|
|
|
1909
2137
|
applyThinking(activeRuntime, payload.thinking, payload.sessionId, activeRuntime.cwd);
|
|
1910
2138
|
}
|
|
1911
2139
|
|
|
1912
|
-
//
|
|
2140
|
+
// Extension commands can configure an otherwise empty session. They are
|
|
2141
|
+
// not conversation prompts, so leave the session unnamed until the first
|
|
2142
|
+
// input that actually enters the transcript. Resolve this from Pi's live
|
|
2143
|
+
// registered-command catalog rather than trusting a browser hint.
|
|
1913
2144
|
const manager = activeRuntime.session?.sessionManager;
|
|
1914
|
-
|
|
2145
|
+
const slashInvocation = typeof payload.text === 'string'
|
|
2146
|
+
? /^\/([^\s]+)/.exec(payload.text.trim())?.[1]
|
|
2147
|
+
: undefined;
|
|
2148
|
+
const registeredExtensionCommands = typeof activeRuntime.session?.extensionRunner?.getRegisteredCommands === 'function'
|
|
2149
|
+
? activeRuntime.session.extensionRunner.getRegisteredCommands()
|
|
2150
|
+
: [];
|
|
2151
|
+
const isExtensionCommand = Boolean(
|
|
2152
|
+
slashInvocation
|
|
2153
|
+
&& Array.isArray(registeredExtensionCommands)
|
|
2154
|
+
&& registeredExtensionCommands.some((command) => typeof command?.invocationName === 'string'
|
|
2155
|
+
&& command.invocationName.toLowerCase() === slashInvocation.toLowerCase()),
|
|
2156
|
+
);
|
|
2157
|
+
// Auto-assign deterministic title on the first conversation prompt if the
|
|
2158
|
+
// session manager still has no explicit or extension-owned name.
|
|
2159
|
+
if (!isExtensionCommand && typeof payload.text === 'string' && payload.text.trim().length > 0 && !manager?.getSessionName?.()) {
|
|
1915
2160
|
const derived = deriveSessionTitle(payload.text);
|
|
1916
2161
|
if (derived && typeof manager?.appendSessionInfo === 'function') {
|
|
1917
2162
|
manager.appendSessionInfo(derived);
|
|
@@ -1936,15 +2181,40 @@ export function createSessionDaemon({
|
|
|
1936
2181
|
// Slash-prefixed input dispatches extension commands and skill/template
|
|
1937
2182
|
// expansion exactly like the pi CLI and RPC modes; plain text keeps the
|
|
1938
2183
|
// sendUserMessage path so it is never expanded.
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2184
|
+
enqueueUserStart(payload.sessionId, generation, attachments.files);
|
|
2185
|
+
// Pi's `session.setModel()` notifies extensions (`model_select`) but not
|
|
2186
|
+
// session subscribers, so an extension-driven model switch would otherwise
|
|
2187
|
+
// never publish `session.model`. Snapshot the live model to reconcile
|
|
2188
|
+
// below from authoritative runtime state. Thinking does emit
|
|
2189
|
+
// `thinking_level_changed` to subscribers, so it needs no reconciliation.
|
|
2190
|
+
const prevModel = activeRuntime.session?.model
|
|
2191
|
+
? { provider: activeRuntime.session.model.provider, id: activeRuntime.session.model.id }
|
|
2192
|
+
: null;
|
|
2193
|
+
let sendCall;
|
|
2194
|
+
try {
|
|
2195
|
+
sendCall = typeof content === 'string' && content.startsWith('/')
|
|
2196
|
+
? activeRuntime.session.prompt(content, {
|
|
2197
|
+
source: 'rpc',
|
|
2198
|
+
...(deliverAs ? { streamingBehavior: deliverAs } : {}),
|
|
2199
|
+
})
|
|
2200
|
+
: activeRuntime.session.sendUserMessage(content, deliverAs ? { deliverAs } : undefined);
|
|
2201
|
+
} catch (error) {
|
|
2202
|
+
removeUserStart(payload.sessionId, generation);
|
|
2203
|
+
throw error;
|
|
2204
|
+
}
|
|
1945
2205
|
Promise.resolve(sendCall).then(() => {
|
|
2206
|
+
removeUserStart(payload.sessionId, generation);
|
|
1946
2207
|
if (sendGenerationBySession.get(payload.sessionId) !== generation) return;
|
|
1947
2208
|
if (settledSendGenerationBySession.get(payload.sessionId) === generation) return;
|
|
2209
|
+
const curModel = activeRuntime.session?.model;
|
|
2210
|
+
if (
|
|
2211
|
+
curModel?.provider && curModel?.id
|
|
2212
|
+
&& (curModel.provider !== prevModel?.provider || curModel.id !== prevModel?.id)
|
|
2213
|
+
) {
|
|
2214
|
+
publish('session.model', {
|
|
2215
|
+
model: { providerId: curModel.provider, modelId: curModel.id },
|
|
2216
|
+
}, payload.sessionId, activeRuntime.cwd);
|
|
2217
|
+
}
|
|
1948
2218
|
if (activeRuntime.session?.isStreaming) return;
|
|
1949
2219
|
settledSendGenerationBySession.set(payload.sessionId, generation);
|
|
1950
2220
|
// Extension commands can complete without starting an agent turn, so Pi
|
|
@@ -1953,6 +2223,7 @@ export function createSessionDaemon({
|
|
|
1953
2223
|
publish('session.lifecycle', { state: 'idle', serverNow: Date.now() }, payload.sessionId, activeRuntime.cwd);
|
|
1954
2224
|
completeRequestedShutdown(payload.sessionId);
|
|
1955
2225
|
}).catch((error) => {
|
|
2226
|
+
removeUserStart(payload.sessionId, generation);
|
|
1956
2227
|
if (sendGenerationBySession.get(payload.sessionId) !== generation) return;
|
|
1957
2228
|
publish('session.error', {
|
|
1958
2229
|
code: 'ASSISTANT_ERROR',
|
|
@@ -2008,6 +2279,7 @@ export function createSessionDaemon({
|
|
|
2008
2279
|
shutdownRequestedBySession.delete(sessionId);
|
|
2009
2280
|
sendGenerationBySession.delete(sessionId);
|
|
2010
2281
|
settledSendGenerationBySession.delete(sessionId);
|
|
2282
|
+
pendingUserStartsBySession.delete(sessionId);
|
|
2011
2283
|
latestUserMessageIds.delete(sessionId);
|
|
2012
2284
|
latestAssistantMessageIds.delete(sessionId);
|
|
2013
2285
|
toolInputBySession.delete(sessionId);
|
|
@@ -2019,11 +2291,15 @@ export function createSessionDaemon({
|
|
|
2019
2291
|
case 'message_start': {
|
|
2020
2292
|
if (event.message?.role === 'user') {
|
|
2021
2293
|
const content = event.message.content;
|
|
2022
|
-
const
|
|
2294
|
+
const rawText = typeof content === 'string'
|
|
2023
2295
|
? content
|
|
2024
2296
|
: Array.isArray(content)
|
|
2025
2297
|
? textFromContent(content)
|
|
2026
|
-
: ''
|
|
2298
|
+
: '';
|
|
2299
|
+
const text = redactAttachmentPaths(
|
|
2300
|
+
rawText.replace(/(\r?\n)*\s*\[Attachment\s+.+?\s+is available at\s+[^\]]+\]/gi, ''),
|
|
2301
|
+
).trim();
|
|
2302
|
+
const files = takeUserStart(sessionId)?.files ?? [];
|
|
2027
2303
|
const messageId = `user-${sessionId}-${sequence + 1}`;
|
|
2028
2304
|
messageEntryAliases.retain({ cwd: directory, sessionId, syntheticMessageId: messageId, message: event.message });
|
|
2029
2305
|
latestUserMessageIds.set(sessionId, messageId);
|
|
@@ -2031,6 +2307,15 @@ export function createSessionDaemon({
|
|
|
2031
2307
|
messageId,
|
|
2032
2308
|
role: 'user',
|
|
2033
2309
|
text,
|
|
2310
|
+
...(files.length > 0 ? {
|
|
2311
|
+
files: files.map((file, index) => ({
|
|
2312
|
+
type: 'file',
|
|
2313
|
+
id: `${messageId}:file:${index}`,
|
|
2314
|
+
index,
|
|
2315
|
+
mime: file.mime,
|
|
2316
|
+
filename: file.filename,
|
|
2317
|
+
})),
|
|
2318
|
+
} : {}),
|
|
2034
2319
|
startedAt: Number.isFinite(event.message.timestamp) ? event.message.timestamp : Date.now(),
|
|
2035
2320
|
}, sessionId, directory);
|
|
2036
2321
|
} else if (event.message?.role === 'assistant') {
|
|
@@ -2325,7 +2610,7 @@ export function createSessionDaemon({
|
|
|
2325
2610
|
'sessions.steer', 'sessions.followUp', 'sessions.abort', 'sessions.setModel',
|
|
2326
2611
|
'sessions.setThinking', 'sessions.compact', 'providers.list', 'providers.refresh', 'providers.config.get', 'providers.models.set', 'providers.status', 'providers.login',
|
|
2327
2612
|
'providers.login.respond', 'providers.login.status', 'providers.logout', 'settings.get', 'settings.set',
|
|
2328
|
-
'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.delete',
|
|
2613
|
+
'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.update', 'resources.prompts.delete',
|
|
2329
2614
|
'extensions.list', 'extensions.respond',
|
|
2330
2615
|
],
|
|
2331
2616
|
...(Number.isInteger(healthMetadata.daemonPid) ? { daemonPid: healthMetadata.daemonPid } : {}),
|
|
@@ -2425,6 +2710,11 @@ export function createSessionDaemon({
|
|
|
2425
2710
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
2426
2711
|
return;
|
|
2427
2712
|
}
|
|
2713
|
+
case 'resources.prompts.update': {
|
|
2714
|
+
const result = await updatePrompt(message.payload);
|
|
2715
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2428
2718
|
case 'resources.prompts.delete': {
|
|
2429
2719
|
const result = await deletePrompt(message.payload);
|
|
2430
2720
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
@@ -2747,6 +3037,7 @@ export function createSessionDaemon({
|
|
|
2747
3037
|
disposingSessionIds.clear();
|
|
2748
3038
|
sendGenerationBySession.clear();
|
|
2749
3039
|
settledSendGenerationBySession.clear();
|
|
3040
|
+
pendingUserStartsBySession.clear();
|
|
2750
3041
|
latestUserMessageIds.clear();
|
|
2751
3042
|
latestAssistantMessageIds.clear();
|
|
2752
3043
|
for (const client of clients) client.destroy();
|