pybao-cli 1.5.3 → 1.5.5
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/REPL-QYABP7JW.js +49 -0
- package/dist/{acp-DXNZZBYP.js → acp-5ATLRHLF.js} +30 -30
- package/dist/{agentsValidate-TMUIF7RL.js → agentsValidate-DZS6QRHL.js} +7 -7
- package/dist/{ask-7WBPXXRW.js → ask-4737XORX.js} +29 -29
- package/dist/{autoUpdater-FASENJNG.js → autoUpdater-N3ZBYLEL.js} +3 -3
- package/dist/{chunk-SMLLIGJI.js → chunk-334FYYPK.js} +2 -2
- package/dist/{chunk-KO22LAIF.js → chunk-3EXYSVHB.js} +4 -4
- package/dist/{chunk-IF53E332.js → chunk-5SIMKDX4.js} +2 -2
- package/dist/{chunk-R35OPNFM.js → chunk-5UMUKAAM.js} +1 -1
- package/dist/{chunk-RHDW7BWR.js → chunk-5XJMA67J.js} +1 -1
- package/dist/{chunk-MAF3SKT6.js → chunk-6LPSL7BE.js} +1 -1
- package/dist/{chunk-CHLNVDSF.js → chunk-CHIAWBUA.js} +3 -3
- package/dist/{chunk-PISK6U5J.js → chunk-DRHHYVCW.js} +16 -16
- package/dist/{chunk-4NW34B7Y.js → chunk-DXRP66I5.js} +1 -1
- package/dist/{chunk-OHQETPDH.js → chunk-GR4JDEVQ.js} +3 -3
- package/dist/{chunk-YNHS2JAI.js → chunk-HE7KJ6UH.js} +4 -4
- package/dist/{chunk-KW4PMRDR.js → chunk-HOPQEHPL.js} +1 -1
- package/dist/{chunk-OYYWTXJC.js → chunk-K6JHXMXN.js} +3 -3
- package/dist/{chunk-QBLRERUX.js → chunk-K6NWBOPY.js} +1 -1
- package/dist/{chunk-D6677VAG.js → chunk-K7WUKXHI.js} +2 -2
- package/dist/{chunk-OYC2QR54.js → chunk-LIWSSSFH.js} +2 -2
- package/dist/{chunk-SPC2RSUA.js → chunk-LJ5LSGNH.js} +3 -3
- package/dist/{chunk-DGP7LO7K.js → chunk-NVE4LCWO.js} +1 -1
- package/dist/{chunk-S5JM4TXZ.js → chunk-OD44XENK.js} +1 -1
- package/dist/{chunk-S5JM4TXZ.js.map → chunk-OD44XENK.js.map} +1 -1
- package/dist/{chunk-EHQQTP7E.js → chunk-RAGFOLYJ.js} +1 -1
- package/dist/{chunk-VJ3ZH6XK.js → chunk-RGKCFZJC.js} +1 -1
- package/dist/{chunk-UI4EDGQP.js → chunk-SIERUHXD.js} +1337 -291
- package/dist/{chunk-UI4EDGQP.js.map → chunk-SIERUHXD.js.map} +4 -4
- package/dist/{chunk-XZDNNAOG.js → chunk-SSJEKON3.js} +4 -4
- package/dist/{chunk-SXZ3VQNN.js → chunk-TEC2E3XN.js} +2 -2
- package/dist/{chunk-NYDZHCDE.js → chunk-UOMNQX6X.js} +1 -1
- package/dist/{chunk-OUECTNP5.js → chunk-WABSMUT4.js} +3 -3
- package/dist/{chunk-QEVQWEYU.js → chunk-WZMYF3UX.js} +2 -2
- package/dist/{chunk-HM43Y2CP.js → chunk-XYTFEOBP.js} +4 -4
- package/dist/{chunk-4NDXPOTT.js → chunk-YPKIYICA.js} +2 -2
- package/dist/{chunk-53SGWVRR.js → chunk-YVAHZVKG.js} +3 -3
- package/dist/{chunk-IIUYGVCI.js → chunk-ZRKIN5IB.js} +3 -3
- package/dist/{cli-DTSQZFF5.js → cli-7LQML4MU.js} +89 -89
- package/dist/commands-5NMEFJO5.js +53 -0
- package/dist/{config-R5OJR4XK.js → config-75TKJIF7.js} +4 -4
- package/dist/{context-IQR6KZZG.js → context-DKI4ZOCF.js} +6 -6
- package/dist/{conversationTracker-LT4FZ2TE.js → conversationTracker-NB2PCUQP.js} +3 -3
- package/dist/{customCommands-37VLCSFB.js → customCommands-4D5NYHQV.js} +4 -4
- package/dist/{env-PIM6NMWB.js → env-YOGE2U3I.js} +2 -2
- package/dist/{file-2QFJYC3P.js → file-S4Y77ZDB.js} +4 -4
- package/dist/index.js +3 -3
- package/dist/{llm-BV3ZXLUQ.js → llm-Q23IAP4O.js} +30 -30
- package/dist/{llmLazy-TU4RPL2G.js → llmLazy-7DJ3Z3D6.js} +1 -1
- package/dist/{loader-GI7TV6A6.js → loader-XVITQOFP.js} +4 -4
- package/dist/{lsp-PPMZSL4Y.js → lsp-F773RHZL.js} +6 -6
- package/dist/{lspAnchor-LB2NFDKB.js → lspAnchor-UJC5DJXX.js} +6 -6
- package/dist/{mcp-ESFRIVSV.js → mcp-CQWFQULD.js} +7 -7
- package/dist/{mentionProcessor-SGRO3JHT.js → mentionProcessor-MNKP2G6P.js} +5 -5
- package/dist/{messages-GQ6FETYN.js → messages-HMXQVAKG.js} +1 -1
- package/dist/{model-GFLLFKZX.js → model-OGMQRRY5.js} +5 -5
- package/dist/{openai-DSFJ7BDF.js → openai-ZLOMELLL.js} +5 -5
- package/dist/{outputStyles-55WG42CM.js → outputStyles-TNK5GPGG.js} +4 -4
- package/dist/{pluginRuntime-XUB6KZMQ.js → pluginRuntime-C6QS67LQ.js} +6 -6
- package/dist/{pluginValidation-L2MN57D2.js → pluginValidation-4SGPUOSV.js} +6 -6
- package/dist/prompts-RUCL6EM6.js +55 -0
- package/dist/{pybAgentSessionLoad-CHKBBFKM.js → pybAgentSessionLoad-NHZ7Y2UJ.js} +4 -4
- package/dist/{pybAgentSessionResume-IAHZMV3H.js → pybAgentSessionResume-3XYFO2NO.js} +4 -4
- package/dist/{pybAgentStreamJsonSession-OSSUE2KR.js → pybAgentStreamJsonSession-H3AVVLPA.js} +1 -1
- package/dist/{pybHooks-7HVWU6ZV.js → pybHooks-JWJOTOPE.js} +4 -4
- package/dist/query-U7X4LZ6Z.js +57 -0
- package/dist/{registry-WU6HV5MK.js → registry-ZSUU43XZ.js} +5 -5
- package/dist/{ripgrep-KWOKWKDZ.js → ripgrep-K52QYYMD.js} +3 -3
- package/dist/{skillMarketplace-77YJ6UGU.js → skillMarketplace-JZDP6BFA.js} +3 -3
- package/dist/{state-FUNN2BQL.js → state-I4ULG2ZQ.js} +2 -2
- package/dist/{theme-ZTXKDDNY.js → theme-AZT4CHJW.js} +5 -5
- package/dist/{toolPermissionSettings-JPH4VWNJ.js → toolPermissionSettings-KPHZJ4NQ.js} +6 -6
- package/dist/tools-J3ZR5NYG.js +54 -0
- package/dist/{userInput-EVSLUMYP.js → userInput-Y4I3F2FW.js} +31 -31
- package/package.json +1 -1
- package/dist/REPL-2NKO3DDR.js +0 -49
- package/dist/commands-EFJBRLOX.js +0 -53
- package/dist/prompts-SNTE6VEN.js +0 -55
- package/dist/query-YB5HN4QQ.js +0 -57
- package/dist/tools-7YC25SS4.js +0 -54
- /package/dist/{REPL-2NKO3DDR.js.map → REPL-QYABP7JW.js.map} +0 -0
- /package/dist/{acp-DXNZZBYP.js.map → acp-5ATLRHLF.js.map} +0 -0
- /package/dist/{agentsValidate-TMUIF7RL.js.map → agentsValidate-DZS6QRHL.js.map} +0 -0
- /package/dist/{ask-7WBPXXRW.js.map → ask-4737XORX.js.map} +0 -0
- /package/dist/{autoUpdater-FASENJNG.js.map → autoUpdater-N3ZBYLEL.js.map} +0 -0
- /package/dist/{chunk-SMLLIGJI.js.map → chunk-334FYYPK.js.map} +0 -0
- /package/dist/{chunk-KO22LAIF.js.map → chunk-3EXYSVHB.js.map} +0 -0
- /package/dist/{chunk-IF53E332.js.map → chunk-5SIMKDX4.js.map} +0 -0
- /package/dist/{chunk-R35OPNFM.js.map → chunk-5UMUKAAM.js.map} +0 -0
- /package/dist/{chunk-RHDW7BWR.js.map → chunk-5XJMA67J.js.map} +0 -0
- /package/dist/{chunk-MAF3SKT6.js.map → chunk-6LPSL7BE.js.map} +0 -0
- /package/dist/{chunk-CHLNVDSF.js.map → chunk-CHIAWBUA.js.map} +0 -0
- /package/dist/{chunk-PISK6U5J.js.map → chunk-DRHHYVCW.js.map} +0 -0
- /package/dist/{chunk-4NW34B7Y.js.map → chunk-DXRP66I5.js.map} +0 -0
- /package/dist/{chunk-OHQETPDH.js.map → chunk-GR4JDEVQ.js.map} +0 -0
- /package/dist/{chunk-YNHS2JAI.js.map → chunk-HE7KJ6UH.js.map} +0 -0
- /package/dist/{chunk-KW4PMRDR.js.map → chunk-HOPQEHPL.js.map} +0 -0
- /package/dist/{chunk-OYYWTXJC.js.map → chunk-K6JHXMXN.js.map} +0 -0
- /package/dist/{chunk-QBLRERUX.js.map → chunk-K6NWBOPY.js.map} +0 -0
- /package/dist/{chunk-D6677VAG.js.map → chunk-K7WUKXHI.js.map} +0 -0
- /package/dist/{chunk-OYC2QR54.js.map → chunk-LIWSSSFH.js.map} +0 -0
- /package/dist/{chunk-SPC2RSUA.js.map → chunk-LJ5LSGNH.js.map} +0 -0
- /package/dist/{chunk-DGP7LO7K.js.map → chunk-NVE4LCWO.js.map} +0 -0
- /package/dist/{chunk-EHQQTP7E.js.map → chunk-RAGFOLYJ.js.map} +0 -0
- /package/dist/{chunk-VJ3ZH6XK.js.map → chunk-RGKCFZJC.js.map} +0 -0
- /package/dist/{chunk-XZDNNAOG.js.map → chunk-SSJEKON3.js.map} +0 -0
- /package/dist/{chunk-SXZ3VQNN.js.map → chunk-TEC2E3XN.js.map} +0 -0
- /package/dist/{chunk-NYDZHCDE.js.map → chunk-UOMNQX6X.js.map} +0 -0
- /package/dist/{chunk-OUECTNP5.js.map → chunk-WABSMUT4.js.map} +0 -0
- /package/dist/{chunk-QEVQWEYU.js.map → chunk-WZMYF3UX.js.map} +0 -0
- /package/dist/{chunk-HM43Y2CP.js.map → chunk-XYTFEOBP.js.map} +0 -0
- /package/dist/{chunk-4NDXPOTT.js.map → chunk-YPKIYICA.js.map} +0 -0
- /package/dist/{chunk-53SGWVRR.js.map → chunk-YVAHZVKG.js.map} +0 -0
- /package/dist/{chunk-IIUYGVCI.js.map → chunk-ZRKIN5IB.js.map} +0 -0
- /package/dist/{cli-DTSQZFF5.js.map → cli-7LQML4MU.js.map} +0 -0
- /package/dist/{commands-EFJBRLOX.js.map → commands-5NMEFJO5.js.map} +0 -0
- /package/dist/{config-R5OJR4XK.js.map → config-75TKJIF7.js.map} +0 -0
- /package/dist/{context-IQR6KZZG.js.map → context-DKI4ZOCF.js.map} +0 -0
- /package/dist/{conversationTracker-LT4FZ2TE.js.map → conversationTracker-NB2PCUQP.js.map} +0 -0
- /package/dist/{customCommands-37VLCSFB.js.map → customCommands-4D5NYHQV.js.map} +0 -0
- /package/dist/{env-PIM6NMWB.js.map → env-YOGE2U3I.js.map} +0 -0
- /package/dist/{file-2QFJYC3P.js.map → file-S4Y77ZDB.js.map} +0 -0
- /package/dist/{llm-BV3ZXLUQ.js.map → llm-Q23IAP4O.js.map} +0 -0
- /package/dist/{llmLazy-TU4RPL2G.js.map → llmLazy-7DJ3Z3D6.js.map} +0 -0
- /package/dist/{loader-GI7TV6A6.js.map → loader-XVITQOFP.js.map} +0 -0
- /package/dist/{lsp-PPMZSL4Y.js.map → lsp-F773RHZL.js.map} +0 -0
- /package/dist/{lspAnchor-LB2NFDKB.js.map → lspAnchor-UJC5DJXX.js.map} +0 -0
- /package/dist/{mcp-ESFRIVSV.js.map → mcp-CQWFQULD.js.map} +0 -0
- /package/dist/{mentionProcessor-SGRO3JHT.js.map → mentionProcessor-MNKP2G6P.js.map} +0 -0
- /package/dist/{messages-GQ6FETYN.js.map → messages-HMXQVAKG.js.map} +0 -0
- /package/dist/{model-GFLLFKZX.js.map → model-OGMQRRY5.js.map} +0 -0
- /package/dist/{openai-DSFJ7BDF.js.map → openai-ZLOMELLL.js.map} +0 -0
- /package/dist/{outputStyles-55WG42CM.js.map → outputStyles-TNK5GPGG.js.map} +0 -0
- /package/dist/{pluginRuntime-XUB6KZMQ.js.map → pluginRuntime-C6QS67LQ.js.map} +0 -0
- /package/dist/{pluginValidation-L2MN57D2.js.map → pluginValidation-4SGPUOSV.js.map} +0 -0
- /package/dist/{prompts-SNTE6VEN.js.map → prompts-RUCL6EM6.js.map} +0 -0
- /package/dist/{pybAgentSessionLoad-CHKBBFKM.js.map → pybAgentSessionLoad-NHZ7Y2UJ.js.map} +0 -0
- /package/dist/{pybAgentSessionResume-IAHZMV3H.js.map → pybAgentSessionResume-3XYFO2NO.js.map} +0 -0
- /package/dist/{pybAgentStreamJsonSession-OSSUE2KR.js.map → pybAgentStreamJsonSession-H3AVVLPA.js.map} +0 -0
- /package/dist/{pybHooks-7HVWU6ZV.js.map → pybHooks-JWJOTOPE.js.map} +0 -0
- /package/dist/{query-YB5HN4QQ.js.map → query-U7X4LZ6Z.js.map} +0 -0
- /package/dist/{registry-WU6HV5MK.js.map → registry-ZSUU43XZ.js.map} +0 -0
- /package/dist/{ripgrep-KWOKWKDZ.js.map → ripgrep-K52QYYMD.js.map} +0 -0
- /package/dist/{skillMarketplace-77YJ6UGU.js.map → skillMarketplace-JZDP6BFA.js.map} +0 -0
- /package/dist/{state-FUNN2BQL.js.map → state-I4ULG2ZQ.js.map} +0 -0
- /package/dist/{theme-ZTXKDDNY.js.map → theme-AZT4CHJW.js.map} +0 -0
- /package/dist/{toolPermissionSettings-JPH4VWNJ.js.map → toolPermissionSettings-KPHZJ4NQ.js.map} +0 -0
- /package/dist/{tools-7YC25SS4.js.map → tools-J3ZR5NYG.js.map} +0 -0
- /package/dist/{userInput-EVSLUMYP.js.map → userInput-Y4I3F2FW.js.map} +0 -0
|
@@ -2,11 +2,11 @@ import { createRequire as __pybCreateRequire } from "node:module";
|
|
|
2
2
|
const require = __pybCreateRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
listPybAgentSessions
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-DXRP66I5.js";
|
|
6
6
|
import {
|
|
7
7
|
formatValidationResult,
|
|
8
8
|
validatePluginOrMarketplacePath
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-K6JHXMXN.js";
|
|
10
10
|
import {
|
|
11
11
|
ConversationTracker,
|
|
12
12
|
appendFinishState,
|
|
@@ -14,18 +14,18 @@ import {
|
|
|
14
14
|
getConversationTrackerForContext,
|
|
15
15
|
isFinishComplete,
|
|
16
16
|
mapFinishReason
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-5XJMA67J.js";
|
|
18
18
|
import {
|
|
19
19
|
beginReplSessionScope
|
|
20
20
|
} from "./chunk-F4AXICO7.js";
|
|
21
21
|
import {
|
|
22
22
|
loadPybAgentSessionMessages
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-HOPQEHPL.js";
|
|
24
24
|
import {
|
|
25
25
|
appendSessionCustomTitleRecord,
|
|
26
26
|
appendSessionJsonlFromMessage,
|
|
27
27
|
appendSessionTagRecord
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-LIWSSSFH.js";
|
|
29
29
|
import {
|
|
30
30
|
drainHookSystemPromptAdditions,
|
|
31
31
|
getHookTranscriptPath,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
runStopHooks,
|
|
38
38
|
runUserPromptSubmitHooks,
|
|
39
39
|
updateHookTranscriptForMessages
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-LJ5LSGNH.js";
|
|
41
41
|
import {
|
|
42
42
|
DEFAULT_OUTPUT_STYLE,
|
|
43
43
|
getAvailableOutputStyles,
|
|
@@ -46,11 +46,11 @@ import {
|
|
|
46
46
|
getOutputStyleSystemPromptAdditions,
|
|
47
47
|
resolveOutputStyleName,
|
|
48
48
|
setCurrentOutputStyle
|
|
49
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-K7WUKXHI.js";
|
|
50
50
|
import {
|
|
51
51
|
fetchCustomModels,
|
|
52
52
|
getModelFeatures
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-WZMYF3UX.js";
|
|
54
54
|
import {
|
|
55
55
|
getSessionState
|
|
56
56
|
} from "./chunk-XKYHFZEC.js";
|
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
queryLLM,
|
|
59
59
|
queryQuick,
|
|
60
60
|
verifyApiKey
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-SSJEKON3.js";
|
|
62
62
|
import {
|
|
63
63
|
DEFAULT_TIMEOUT_MS,
|
|
64
64
|
FallbackToolUseRejectedMessage,
|
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
listMCPServers,
|
|
73
73
|
loadMergedSettings,
|
|
74
74
|
normalizeSandboxRuntimeConfigFromSettings
|
|
75
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-HE7KJ6UH.js";
|
|
76
76
|
import {
|
|
77
77
|
addMarketplace,
|
|
78
78
|
disableSkillPlugin,
|
|
@@ -85,11 +85,11 @@ import {
|
|
|
85
85
|
refreshMarketplaceAsync,
|
|
86
86
|
removeMarketplace,
|
|
87
87
|
uninstallSkillPlugin
|
|
88
|
-
} from "./chunk-
|
|
88
|
+
} from "./chunk-6LPSL7BE.js";
|
|
89
89
|
import {
|
|
90
90
|
loadToolPermissionContextFromDisk,
|
|
91
91
|
persistToolPermissionUpdateToDisk
|
|
92
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-ZRKIN5IB.js";
|
|
93
93
|
import {
|
|
94
94
|
applyToolPermissionContextUpdate,
|
|
95
95
|
applyToolPermissionContextUpdates,
|
|
@@ -100,13 +100,13 @@ import {
|
|
|
100
100
|
generateSystemReminders,
|
|
101
101
|
resetReminderSession,
|
|
102
102
|
systemReminderService
|
|
103
|
-
} from "./chunk-
|
|
103
|
+
} from "./chunk-5SIMKDX4.js";
|
|
104
104
|
import {
|
|
105
105
|
clearAgentCache,
|
|
106
106
|
getActiveAgents,
|
|
107
107
|
getAgentByType,
|
|
108
108
|
getAllAgents
|
|
109
|
-
} from "./chunk-
|
|
109
|
+
} from "./chunk-TEC2E3XN.js";
|
|
110
110
|
import {
|
|
111
111
|
API_ERROR_MESSAGE_PREFIX,
|
|
112
112
|
CANCEL_MESSAGE,
|
|
@@ -137,7 +137,7 @@ import {
|
|
|
137
137
|
processUserInput,
|
|
138
138
|
reorderMessages,
|
|
139
139
|
stripSystemMessages
|
|
140
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-RAGFOLYJ.js";
|
|
141
141
|
import {
|
|
142
142
|
getRequestStatus,
|
|
143
143
|
setRequestStatus,
|
|
@@ -167,7 +167,7 @@ import {
|
|
|
167
167
|
normalizeFilePath,
|
|
168
168
|
readTextContent,
|
|
169
169
|
writeTextContent
|
|
170
|
-
} from "./chunk-
|
|
170
|
+
} from "./chunk-334FYYPK.js";
|
|
171
171
|
import {
|
|
172
172
|
parseBlockEdits
|
|
173
173
|
} from "./chunk-QWIBSCDN.js";
|
|
@@ -177,18 +177,18 @@ import {
|
|
|
177
177
|
ParserRegistry,
|
|
178
178
|
initParser,
|
|
179
179
|
loadLanguage
|
|
180
|
-
} from "./chunk-
|
|
180
|
+
} from "./chunk-XYTFEOBP.js";
|
|
181
181
|
import {
|
|
182
182
|
getSettingsFileCandidates,
|
|
183
183
|
loadSettingsWithLegacyFallback,
|
|
184
184
|
readSettingsFile
|
|
185
|
-
} from "./chunk-
|
|
185
|
+
} from "./chunk-K6NWBOPY.js";
|
|
186
186
|
import {
|
|
187
187
|
getCustomCommandDirectories,
|
|
188
188
|
hasCustomCommands,
|
|
189
189
|
loadCustomCommands,
|
|
190
190
|
reloadCustomCommands
|
|
191
|
-
} from "./chunk-
|
|
191
|
+
} from "./chunk-YPKIYICA.js";
|
|
192
192
|
import {
|
|
193
193
|
getSessionPlugins
|
|
194
194
|
} from "./chunk-BJSWTHRM.js";
|
|
@@ -197,7 +197,7 @@ import {
|
|
|
197
197
|
buildModelProfileKey,
|
|
198
198
|
getModelManager,
|
|
199
199
|
isDefaultSlowAndCapableModel
|
|
200
|
-
} from "./chunk-
|
|
200
|
+
} from "./chunk-CHIAWBUA.js";
|
|
201
201
|
import {
|
|
202
202
|
getCodeStyle,
|
|
203
203
|
getContext,
|
|
@@ -205,16 +205,16 @@ import {
|
|
|
205
205
|
getIsGit,
|
|
206
206
|
getProjectDocs,
|
|
207
207
|
getProjectStructureStatisticsBlock
|
|
208
|
-
} from "./chunk-
|
|
208
|
+
} from "./chunk-3EXYSVHB.js";
|
|
209
209
|
import {
|
|
210
210
|
getRipgrepPath,
|
|
211
211
|
getRipgrepPolicyMode,
|
|
212
212
|
resolveRipgrepPolicy,
|
|
213
213
|
ripGrep
|
|
214
|
-
} from "./chunk-
|
|
214
|
+
} from "./chunk-NVE4LCWO.js";
|
|
215
215
|
import {
|
|
216
216
|
getTheme
|
|
217
|
-
} from "./chunk-
|
|
217
|
+
} from "./chunk-5UMUKAAM.js";
|
|
218
218
|
import {
|
|
219
219
|
DEFAULT_GLOBAL_CONFIG,
|
|
220
220
|
enableConfigs,
|
|
@@ -227,7 +227,7 @@ import {
|
|
|
227
227
|
saveGlobalConfig,
|
|
228
228
|
setAllPointersToModel,
|
|
229
229
|
setModelPointer
|
|
230
|
-
} from "./chunk-
|
|
230
|
+
} from "./chunk-WABSMUT4.js";
|
|
231
231
|
import {
|
|
232
232
|
AbortError
|
|
233
233
|
} from "./chunk-RQVLBMP7.js";
|
|
@@ -236,7 +236,7 @@ import {
|
|
|
236
236
|
getCurrentRequest,
|
|
237
237
|
logUserFriendly,
|
|
238
238
|
markPhase
|
|
239
|
-
} from "./chunk-
|
|
239
|
+
} from "./chunk-UOMNQX6X.js";
|
|
240
240
|
import {
|
|
241
241
|
ASCII_LOGO,
|
|
242
242
|
BunShell,
|
|
@@ -277,10 +277,10 @@ import {
|
|
|
277
277
|
setCwd,
|
|
278
278
|
shouldApplyToolOutputTruncation,
|
|
279
279
|
truncateToolOutput
|
|
280
|
-
} from "./chunk-
|
|
280
|
+
} from "./chunk-RGKCFZJC.js";
|
|
281
281
|
import {
|
|
282
282
|
MACRO
|
|
283
|
-
} from "./chunk-
|
|
283
|
+
} from "./chunk-OD44XENK.js";
|
|
284
284
|
import {
|
|
285
285
|
__export
|
|
286
286
|
} from "./chunk-I3J4JYES.js";
|
|
@@ -461,7 +461,7 @@ var getCommandSubcommandPrefix = memoize(
|
|
|
461
461
|
var getCommandPrefix = memoize(
|
|
462
462
|
async (command4, abortSignal) => {
|
|
463
463
|
const { systemPrompt, userPrompt } = buildBashCommandPrefixDetectionPrompt(command4);
|
|
464
|
-
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryQuick: queryQuick2 } = await import("./llm-
|
|
464
|
+
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryQuick: queryQuick2 } = await import("./llm-Q23IAP4O.js");
|
|
465
465
|
const response = await queryQuick2({
|
|
466
466
|
systemPrompt,
|
|
467
467
|
userPrompt,
|
|
@@ -4263,7 +4263,7 @@ function formatParseError(error) {
|
|
|
4263
4263
|
return error instanceof Error ? error.message : String(error);
|
|
4264
4264
|
}
|
|
4265
4265
|
async function defaultGateQuery(args) {
|
|
4266
|
-
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryLLM: queryLLM2 } = await import("./llm-
|
|
4266
|
+
const { API_ERROR_MESSAGE_PREFIX: API_ERROR_MESSAGE_PREFIX2, queryLLM: queryLLM2 } = await import("./llm-Q23IAP4O.js");
|
|
4267
4267
|
const queryLLMFn = args.queryLLMOverride ?? queryLLM2;
|
|
4268
4268
|
const messages = [
|
|
4269
4269
|
{
|
|
@@ -6624,7 +6624,7 @@ var FileEditTool = {
|
|
|
6624
6624
|
const originalFileContent = currentFileContent;
|
|
6625
6625
|
let totalPatch = [];
|
|
6626
6626
|
const { SmartEdit } = await import("./smart-edit-AWHJDSU6.js");
|
|
6627
|
-
const { findLspAnchor } = await import("./lspAnchor-
|
|
6627
|
+
const { findLspAnchor } = await import("./lspAnchor-UJC5DJXX.js");
|
|
6628
6628
|
for (const op of editOperations) {
|
|
6629
6629
|
const normalizedSearch = normalizeLineEndings(op.search);
|
|
6630
6630
|
const normalizedReplace = normalizeLineEndings(op.replace);
|
|
@@ -11926,7 +11926,7 @@ async function createAndStoreApiKey(accessToken) {
|
|
|
11926
11926
|
}
|
|
11927
11927
|
saveGlobalConfig(config2);
|
|
11928
11928
|
try {
|
|
11929
|
-
const { resetAnthropicClient } = await import("./llm-
|
|
11929
|
+
const { resetAnthropicClient } = await import("./llm-Q23IAP4O.js");
|
|
11930
11930
|
resetAnthropicClient();
|
|
11931
11931
|
} catch {
|
|
11932
11932
|
}
|
|
@@ -16350,7 +16350,7 @@ async function refreshPluginRuntimeFromInstalls() {
|
|
|
16350
16350
|
const existingRoots = getSessionPlugins().map((p) => p.rootDir);
|
|
16351
16351
|
const dirs = Array.from(/* @__PURE__ */ new Set([...existingRoots, ...installedRoots]));
|
|
16352
16352
|
if (dirs.length === 0) return [];
|
|
16353
|
-
const { configureSessionPlugins } = await import("./pluginRuntime-
|
|
16353
|
+
const { configureSessionPlugins } = await import("./pluginRuntime-C6QS67LQ.js");
|
|
16354
16354
|
const { errors } = await configureSessionPlugins({ pluginDirs: dirs });
|
|
16355
16355
|
return errors;
|
|
16356
16356
|
}
|
|
@@ -17025,7 +17025,7 @@ async function call(onDone, context) {
|
|
|
17025
17025
|
ModelConfig,
|
|
17026
17026
|
{
|
|
17027
17027
|
onClose: () => {
|
|
17028
|
-
import("./model-
|
|
17028
|
+
import("./model-OGMQRRY5.js").then(({ reloadModelManager: reloadModelManager2 }) => {
|
|
17029
17029
|
reloadModelManager2();
|
|
17030
17030
|
triggerModelConfigChange();
|
|
17031
17031
|
onDone();
|
|
@@ -25229,7 +25229,7 @@ function useStatusLine() {
|
|
|
25229
25229
|
// src/ui/components/PromptInput.tsx
|
|
25230
25230
|
async function interpretHashCommand(input) {
|
|
25231
25231
|
try {
|
|
25232
|
-
const { queryQuick: queryQuick2 } = await import("./llm-
|
|
25232
|
+
const { queryQuick: queryQuick2 } = await import("./llm-Q23IAP4O.js");
|
|
25233
25233
|
const systemPrompt = [
|
|
25234
25234
|
"You're helping the user structure notes that will be added to their PYB.md file.",
|
|
25235
25235
|
"Format the user's input into a well-structured note that will be useful for later reference.",
|
|
@@ -25542,7 +25542,7 @@ function PromptInput({
|
|
|
25542
25542
|
if (messages2.length) {
|
|
25543
25543
|
if (mode === "bash") {
|
|
25544
25544
|
onQuery(messages2, newAbortController).then(async () => {
|
|
25545
|
-
const { getCwd: getCwd2 } = await import("./state-
|
|
25545
|
+
const { getCwd: getCwd2 } = await import("./state-I4ULG2ZQ.js");
|
|
25546
25546
|
setCurrentPwd(getCwd2());
|
|
25547
25547
|
});
|
|
25548
25548
|
} else {
|
|
@@ -26801,6 +26801,344 @@ function startWatchingTaskList(listId) {
|
|
|
26801
26801
|
startFallbackWatcher(entry);
|
|
26802
26802
|
}
|
|
26803
26803
|
|
|
26804
|
+
// src/services/ai/streamTyped/partStore.ts
|
|
26805
|
+
import { appendFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, readFileSync as readFileSync13 } from "fs";
|
|
26806
|
+
import { dirname as dirname9 } from "path";
|
|
26807
|
+
|
|
26808
|
+
// src/services/ai/streamTyped/partTypes.ts
|
|
26809
|
+
import { z as z11 } from "zod";
|
|
26810
|
+
var SOURCE_VALUES = ["auto_compact", "query_main"];
|
|
26811
|
+
var TOOL_STATUS_VALUES = ["pending", "running", "completed", "failed", "interrupted"];
|
|
26812
|
+
var textPayloadSchema = z11.object({
|
|
26813
|
+
text: z11.string().min(1)
|
|
26814
|
+
});
|
|
26815
|
+
var reasoningPayloadSchema = z11.object({
|
|
26816
|
+
text: z11.string().min(1)
|
|
26817
|
+
});
|
|
26818
|
+
var toolPayloadSchema = z11.object({
|
|
26819
|
+
toolName: z11.string().min(1),
|
|
26820
|
+
toolCallId: z11.string().min(1),
|
|
26821
|
+
status: z11.enum(TOOL_STATUS_VALUES),
|
|
26822
|
+
outputText: z11.string().optional()
|
|
26823
|
+
});
|
|
26824
|
+
var streamTypedPartBaseSchema = z11.object({
|
|
26825
|
+
id: z11.string().min(1),
|
|
26826
|
+
requestId: z11.string().min(1),
|
|
26827
|
+
source: z11.enum(SOURCE_VALUES),
|
|
26828
|
+
timestamp: z11.number().int().positive()
|
|
26829
|
+
});
|
|
26830
|
+
var streamTypedPartSchema = z11.discriminatedUnion("partType", [
|
|
26831
|
+
streamTypedPartBaseSchema.extend({
|
|
26832
|
+
partType: z11.literal("text"),
|
|
26833
|
+
payload: textPayloadSchema
|
|
26834
|
+
}),
|
|
26835
|
+
streamTypedPartBaseSchema.extend({
|
|
26836
|
+
partType: z11.literal("reasoning"),
|
|
26837
|
+
payload: reasoningPayloadSchema
|
|
26838
|
+
}),
|
|
26839
|
+
streamTypedPartBaseSchema.extend({
|
|
26840
|
+
partType: z11.literal("tool"),
|
|
26841
|
+
payload: toolPayloadSchema
|
|
26842
|
+
})
|
|
26843
|
+
]);
|
|
26844
|
+
function createId() {
|
|
26845
|
+
return `stp_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
26846
|
+
}
|
|
26847
|
+
function createBase(input) {
|
|
26848
|
+
return {
|
|
26849
|
+
id: createId(),
|
|
26850
|
+
requestId: input.requestId,
|
|
26851
|
+
source: input.source ?? "auto_compact",
|
|
26852
|
+
timestamp: Date.now()
|
|
26853
|
+
};
|
|
26854
|
+
}
|
|
26855
|
+
function createTextPart(input) {
|
|
26856
|
+
return streamTypedPartSchema.parse({
|
|
26857
|
+
...createBase(input),
|
|
26858
|
+
partType: "text",
|
|
26859
|
+
payload: {
|
|
26860
|
+
text: input.text.trim()
|
|
26861
|
+
}
|
|
26862
|
+
});
|
|
26863
|
+
}
|
|
26864
|
+
function createReasoningPart(input) {
|
|
26865
|
+
return streamTypedPartSchema.parse({
|
|
26866
|
+
...createBase(input),
|
|
26867
|
+
partType: "reasoning",
|
|
26868
|
+
payload: {
|
|
26869
|
+
text: input.text.trim()
|
|
26870
|
+
}
|
|
26871
|
+
});
|
|
26872
|
+
}
|
|
26873
|
+
function createToolPart(input) {
|
|
26874
|
+
return streamTypedPartSchema.parse({
|
|
26875
|
+
...createBase(input),
|
|
26876
|
+
partType: "tool",
|
|
26877
|
+
payload: {
|
|
26878
|
+
toolName: input.toolName,
|
|
26879
|
+
toolCallId: input.toolCallId,
|
|
26880
|
+
status: input.status,
|
|
26881
|
+
...input.outputText ? { outputText: input.outputText } : {}
|
|
26882
|
+
}
|
|
26883
|
+
});
|
|
26884
|
+
}
|
|
26885
|
+
|
|
26886
|
+
// src/services/ai/streamTyped/partStore.ts
|
|
26887
|
+
function getStreamTypedOutputFilePath() {
|
|
26888
|
+
return resolveXdgCachePath("telemetry/stream-typed-parts.jsonl");
|
|
26889
|
+
}
|
|
26890
|
+
function validateTypedPartRecord(record) {
|
|
26891
|
+
return streamTypedPartSchema.safeParse(record).success;
|
|
26892
|
+
}
|
|
26893
|
+
function readAllValidParts(outputFilePath) {
|
|
26894
|
+
if (!existsSync17(outputFilePath)) return [];
|
|
26895
|
+
const raw = readFileSync13(outputFilePath, "utf8");
|
|
26896
|
+
const lines = raw.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
26897
|
+
const parts = [];
|
|
26898
|
+
for (const line of lines) {
|
|
26899
|
+
try {
|
|
26900
|
+
const parsed = JSON.parse(line);
|
|
26901
|
+
if (!validateTypedPartRecord(parsed)) continue;
|
|
26902
|
+
parts.push(parsed);
|
|
26903
|
+
} catch {
|
|
26904
|
+
continue;
|
|
26905
|
+
}
|
|
26906
|
+
}
|
|
26907
|
+
return parts;
|
|
26908
|
+
}
|
|
26909
|
+
function appendTypedParts(options) {
|
|
26910
|
+
if (!Array.isArray(options.parts) || options.parts.length === 0) {
|
|
26911
|
+
return { appended: 0 };
|
|
26912
|
+
}
|
|
26913
|
+
const outputFilePath = options.outputFilePath ?? getStreamTypedOutputFilePath();
|
|
26914
|
+
if (!existsSync17(dirname9(outputFilePath))) {
|
|
26915
|
+
mkdirSync7(dirname9(outputFilePath), { recursive: true });
|
|
26916
|
+
}
|
|
26917
|
+
const existingIds = new Set(readAllValidParts(outputFilePath).map((item) => item.id));
|
|
26918
|
+
const toAppend = options.parts.filter(
|
|
26919
|
+
(item) => validateTypedPartRecord(item) && !existingIds.has(item.id)
|
|
26920
|
+
);
|
|
26921
|
+
if (toAppend.length === 0) return { appended: 0 };
|
|
26922
|
+
appendFileSync(
|
|
26923
|
+
outputFilePath,
|
|
26924
|
+
`${toAppend.map((item) => JSON.stringify(item)).join("\n")}
|
|
26925
|
+
`
|
|
26926
|
+
);
|
|
26927
|
+
return { appended: toAppend.length };
|
|
26928
|
+
}
|
|
26929
|
+
|
|
26930
|
+
// src/services/ai/streamTyped/index.ts
|
|
26931
|
+
var streamTypedBuffer = /* @__PURE__ */ new Map();
|
|
26932
|
+
function emitTypedPart(event) {
|
|
26933
|
+
const requestId = String(event.requestId || "").trim();
|
|
26934
|
+
if (!requestId) return;
|
|
26935
|
+
const current = streamTypedBuffer.get(requestId) ?? [];
|
|
26936
|
+
current.push(event.part);
|
|
26937
|
+
streamTypedBuffer.set(requestId, current);
|
|
26938
|
+
}
|
|
26939
|
+
function flushTypedPartBuffer(options) {
|
|
26940
|
+
const requestId = String(options.requestId || "").trim();
|
|
26941
|
+
if (!requestId) return { appended: 0 };
|
|
26942
|
+
const parts = streamTypedBuffer.get(requestId) ?? [];
|
|
26943
|
+
streamTypedBuffer.delete(requestId);
|
|
26944
|
+
return appendTypedParts({
|
|
26945
|
+
outputFilePath: options.outputFilePath,
|
|
26946
|
+
parts
|
|
26947
|
+
});
|
|
26948
|
+
}
|
|
26949
|
+
|
|
26950
|
+
// src/services/ai/streamTyped/eventAssembler.ts
|
|
26951
|
+
function createAssemblerState(requestId, source = "auto_compact") {
|
|
26952
|
+
return {
|
|
26953
|
+
requestId,
|
|
26954
|
+
parts: [],
|
|
26955
|
+
textBuffer: {},
|
|
26956
|
+
reasoningBuffer: {},
|
|
26957
|
+
toolMap: {},
|
|
26958
|
+
source
|
|
26959
|
+
};
|
|
26960
|
+
}
|
|
26961
|
+
function onTextStart(event, state) {
|
|
26962
|
+
state.textBuffer[event.textId] = "";
|
|
26963
|
+
}
|
|
26964
|
+
function onTextDelta(event, state) {
|
|
26965
|
+
const current = state.textBuffer[event.textId] ?? "";
|
|
26966
|
+
state.textBuffer[event.textId] = `${current}${event.text}`;
|
|
26967
|
+
}
|
|
26968
|
+
function onTextEnd(event, state) {
|
|
26969
|
+
const text = String(state.textBuffer[event.textId] ?? "").trim();
|
|
26970
|
+
delete state.textBuffer[event.textId];
|
|
26971
|
+
if (!text) return;
|
|
26972
|
+
state.parts.push(
|
|
26973
|
+
createTextPart({
|
|
26974
|
+
requestId: state.requestId,
|
|
26975
|
+
text,
|
|
26976
|
+
source: state.source
|
|
26977
|
+
})
|
|
26978
|
+
);
|
|
26979
|
+
}
|
|
26980
|
+
function onReasoningStart(event, state) {
|
|
26981
|
+
state.reasoningBuffer[event.reasoningId] = "";
|
|
26982
|
+
}
|
|
26983
|
+
function onReasoningDelta(event, state) {
|
|
26984
|
+
const current = state.reasoningBuffer[event.reasoningId] ?? "";
|
|
26985
|
+
state.reasoningBuffer[event.reasoningId] = `${current}${event.text}`;
|
|
26986
|
+
}
|
|
26987
|
+
function onReasoningEnd(event, state) {
|
|
26988
|
+
const text = String(state.reasoningBuffer[event.reasoningId] ?? "").trim();
|
|
26989
|
+
delete state.reasoningBuffer[event.reasoningId];
|
|
26990
|
+
if (!text) return;
|
|
26991
|
+
state.parts.push(
|
|
26992
|
+
createReasoningPart({
|
|
26993
|
+
requestId: state.requestId,
|
|
26994
|
+
text,
|
|
26995
|
+
source: state.source
|
|
26996
|
+
})
|
|
26997
|
+
);
|
|
26998
|
+
}
|
|
26999
|
+
function onToolCall(event, state) {
|
|
27000
|
+
state.toolMap[event.toolCallId] = { toolName: event.toolName };
|
|
27001
|
+
}
|
|
27002
|
+
function onToolResult(event, state) {
|
|
27003
|
+
const toolName = state.toolMap[event.toolCallId]?.toolName ?? "unknown";
|
|
27004
|
+
state.parts.push(
|
|
27005
|
+
createToolPart({
|
|
27006
|
+
requestId: state.requestId,
|
|
27007
|
+
toolName,
|
|
27008
|
+
toolCallId: event.toolCallId,
|
|
27009
|
+
status: event.status,
|
|
27010
|
+
outputText: event.outputText,
|
|
27011
|
+
source: state.source
|
|
27012
|
+
})
|
|
27013
|
+
);
|
|
27014
|
+
if (event.status === "completed" || event.status === "failed" || event.status === "interrupted") {
|
|
27015
|
+
delete state.toolMap[event.toolCallId];
|
|
27016
|
+
}
|
|
27017
|
+
}
|
|
27018
|
+
function flushTypedParts(state) {
|
|
27019
|
+
const parts = state.parts.slice();
|
|
27020
|
+
state.parts.length = 0;
|
|
27021
|
+
return parts;
|
|
27022
|
+
}
|
|
27023
|
+
|
|
27024
|
+
// src/services/ai/streamTyped/projector.ts
|
|
27025
|
+
function supportsRichToolResultByProvider(provider) {
|
|
27026
|
+
return String(provider ?? "").trim().toLowerCase() === "anthropic";
|
|
27027
|
+
}
|
|
27028
|
+
function extractToolResultText(content) {
|
|
27029
|
+
if (typeof content === "string") return { text: content, hasNonTextBlock: false };
|
|
27030
|
+
if (!Array.isArray(content)) return { text: "", hasNonTextBlock: false };
|
|
27031
|
+
let hasNonTextBlock = false;
|
|
27032
|
+
const text = content.filter((block) => {
|
|
27033
|
+
if (!block || typeof block !== "object") return false;
|
|
27034
|
+
if (block.type === "text") return true;
|
|
27035
|
+
hasNonTextBlock = true;
|
|
27036
|
+
return false;
|
|
27037
|
+
}).map((block) => String(block.text ?? "")).join("\n");
|
|
27038
|
+
return { text, hasNonTextBlock };
|
|
27039
|
+
}
|
|
27040
|
+
function projectAssistantMessage(state, message) {
|
|
27041
|
+
const content = message?.message?.content;
|
|
27042
|
+
if (!Array.isArray(content)) return;
|
|
27043
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
27044
|
+
const block = content[i];
|
|
27045
|
+
if (!block || typeof block !== "object") continue;
|
|
27046
|
+
const type3 = String(block.type ?? "");
|
|
27047
|
+
if (type3 === "text") {
|
|
27048
|
+
const text = String(block.text ?? "");
|
|
27049
|
+
onTextStart({ textId: `text-${i}` }, state);
|
|
27050
|
+
onTextDelta({ textId: `text-${i}`, text }, state);
|
|
27051
|
+
onTextEnd({ textId: `text-${i}` }, state);
|
|
27052
|
+
continue;
|
|
27053
|
+
}
|
|
27054
|
+
if (type3 === "thinking" || type3 === "reasoning") {
|
|
27055
|
+
const text = String(block.thinking ?? block.reasoning ?? "");
|
|
27056
|
+
onReasoningStart({ reasoningId: `reasoning-${i}` }, state);
|
|
27057
|
+
onReasoningDelta({ reasoningId: `reasoning-${i}`, text }, state);
|
|
27058
|
+
onReasoningEnd({ reasoningId: `reasoning-${i}` }, state);
|
|
27059
|
+
continue;
|
|
27060
|
+
}
|
|
27061
|
+
if (type3 === "tool_use" || type3 === "server_tool_use" || type3 === "mcp_tool_use") {
|
|
27062
|
+
const toolCallId = String(block.id ?? `tool-${i}`);
|
|
27063
|
+
const toolName = String(block.name ?? "unknown");
|
|
27064
|
+
onToolCall({ toolCallId, toolName }, state);
|
|
27065
|
+
}
|
|
27066
|
+
}
|
|
27067
|
+
}
|
|
27068
|
+
function projectUserToolResult(projector, message) {
|
|
27069
|
+
const state = projector.state;
|
|
27070
|
+
const content = message?.message?.content;
|
|
27071
|
+
if (!Array.isArray(content)) return;
|
|
27072
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
27073
|
+
const block = content[i];
|
|
27074
|
+
if (!block || typeof block !== "object") continue;
|
|
27075
|
+
if (block.type !== "tool_result") continue;
|
|
27076
|
+
const toolCallId = String(block.tool_use_id ?? `tool-${i}`);
|
|
27077
|
+
const extracted = extractToolResultText(block.content);
|
|
27078
|
+
if (extracted.hasNonTextBlock) {
|
|
27079
|
+
projector.richToolResultBlockCount += 1;
|
|
27080
|
+
if (!projector.supportsRichToolResult) {
|
|
27081
|
+
projector.downgradedToolResultCount += 1;
|
|
27082
|
+
}
|
|
27083
|
+
}
|
|
27084
|
+
onToolResult(
|
|
27085
|
+
{
|
|
27086
|
+
toolCallId,
|
|
27087
|
+
status: block.is_error ? "failed" : "completed",
|
|
27088
|
+
outputText: extracted.text
|
|
27089
|
+
},
|
|
27090
|
+
state
|
|
27091
|
+
);
|
|
27092
|
+
}
|
|
27093
|
+
}
|
|
27094
|
+
function projectProgressMessage(state, message) {
|
|
27095
|
+
const toolCallId = String(message?.toolUseID ?? "").trim();
|
|
27096
|
+
if (!toolCallId) return;
|
|
27097
|
+
const content = String(
|
|
27098
|
+
message?.content?.message?.content?.find?.((block) => block?.type === "text")?.text ?? ""
|
|
27099
|
+
);
|
|
27100
|
+
onToolResult(
|
|
27101
|
+
{
|
|
27102
|
+
toolCallId,
|
|
27103
|
+
status: "running",
|
|
27104
|
+
outputText: content || void 0
|
|
27105
|
+
},
|
|
27106
|
+
state
|
|
27107
|
+
);
|
|
27108
|
+
}
|
|
27109
|
+
function createStreamTypedProjector(options) {
|
|
27110
|
+
const provider = String(options.provider ?? "").trim().toLowerCase();
|
|
27111
|
+
return {
|
|
27112
|
+
state: createAssemblerState(options.requestId, options.source ?? "query_main"),
|
|
27113
|
+
provider,
|
|
27114
|
+
supportsRichToolResult: typeof options.supportsRichToolResult === "boolean" ? options.supportsRichToolResult : supportsRichToolResultByProvider(provider),
|
|
27115
|
+
richToolResultBlockCount: 0,
|
|
27116
|
+
downgradedToolResultCount: 0
|
|
27117
|
+
};
|
|
27118
|
+
}
|
|
27119
|
+
function consumeProjectorCompatibilityMetrics(projector) {
|
|
27120
|
+
const snapshot = {
|
|
27121
|
+
provider: projector.provider || "unknown",
|
|
27122
|
+
supportsRichToolResult: projector.supportsRichToolResult,
|
|
27123
|
+
richToolResultBlockCount: projector.richToolResultBlockCount,
|
|
27124
|
+
downgradedToolResultCount: projector.downgradedToolResultCount
|
|
27125
|
+
};
|
|
27126
|
+
projector.richToolResultBlockCount = 0;
|
|
27127
|
+
projector.downgradedToolResultCount = 0;
|
|
27128
|
+
return snapshot;
|
|
27129
|
+
}
|
|
27130
|
+
function projectMessageToTypedParts(projector, message) {
|
|
27131
|
+
if (!message || typeof message !== "object") return [];
|
|
27132
|
+
if (message.type === "assistant") {
|
|
27133
|
+
projectAssistantMessage(projector.state, message);
|
|
27134
|
+
} else if (message.type === "user") {
|
|
27135
|
+
projectUserToolResult(projector, message);
|
|
27136
|
+
} else if (message.type === "progress") {
|
|
27137
|
+
projectProgressMessage(projector.state, message);
|
|
27138
|
+
}
|
|
27139
|
+
return flushTypedParts(projector.state);
|
|
27140
|
+
}
|
|
27141
|
+
|
|
26804
27142
|
// src/utils/session/fileRecoveryCore.ts
|
|
26805
27143
|
var MAX_FILES_TO_RECOVER = 5;
|
|
26806
27144
|
var MAX_TOKENS_PER_FILE = 1e4;
|
|
@@ -26889,6 +27227,34 @@ function computeAutoCompactMetrics(events) {
|
|
|
26889
27227
|
crossReplayErrors,
|
|
26890
27228
|
crossReplayTotal
|
|
26891
27229
|
);
|
|
27230
|
+
const sessionTypedPathEvents = events.filter(
|
|
27231
|
+
(event) => event.phase === "SESSION_TYPED_PATH_APPLIED"
|
|
27232
|
+
);
|
|
27233
|
+
const sessionFallbackEvents = events.filter(
|
|
27234
|
+
(event) => event.phase === "SESSION_CANONICAL_FALLBACK_APPLIED"
|
|
27235
|
+
);
|
|
27236
|
+
const typed_primary_path_rate = sessionTypedPathEvents.length + sessionFallbackEvents.length > 0 ? safeDivide(
|
|
27237
|
+
sessionTypedPathEvents.length,
|
|
27238
|
+
sessionTypedPathEvents.length + sessionFallbackEvents.length
|
|
27239
|
+
) : void 0;
|
|
27240
|
+
const boundaryEvents = events.filter(
|
|
27241
|
+
(event) => event.phase === "COMPACTION_BOUNDARY_APPLIED"
|
|
27242
|
+
);
|
|
27243
|
+
const compaction_boundary_hit_rate = boundaryEvents.length > 0 ? safeDivide(
|
|
27244
|
+
boundaryEvents.filter((event) => event.data?.applied === true).length,
|
|
27245
|
+
boundaryEvents.length
|
|
27246
|
+
) : void 0;
|
|
27247
|
+
const replayOutcomeEvents = boundaryEvents.filter(
|
|
27248
|
+
(event) => ["replayed_latest_user_task", "synthetic_continue_prompt"].includes(
|
|
27249
|
+
String(event.data?.replayMode ?? "")
|
|
27250
|
+
)
|
|
27251
|
+
);
|
|
27252
|
+
const overflow_replay_success_rate = replayOutcomeEvents.length > 0 ? safeDivide(
|
|
27253
|
+
replayOutcomeEvents.filter(
|
|
27254
|
+
(event) => event.data?.replayMode === "replayed_latest_user_task"
|
|
27255
|
+
).length,
|
|
27256
|
+
replayOutcomeEvents.length
|
|
27257
|
+
) : void 0;
|
|
26892
27258
|
const sanitizerEvents = events.filter(
|
|
26893
27259
|
(event) => event.phase === "AUTO_COMPACT_SANITIZER_APPLIED"
|
|
26894
27260
|
);
|
|
@@ -26940,6 +27306,9 @@ function computeAutoCompactMetrics(events) {
|
|
|
26940
27306
|
compact_retry_success_rate,
|
|
26941
27307
|
thinking_first_ratio,
|
|
26942
27308
|
cross_model_replay_error_rate,
|
|
27309
|
+
typed_primary_path_rate,
|
|
27310
|
+
compaction_boundary_hit_rate,
|
|
27311
|
+
overflow_replay_success_rate,
|
|
26943
27312
|
noise_ratio_after_compaction,
|
|
26944
27313
|
task_goal_retention_rate,
|
|
26945
27314
|
result_fidelity_rate,
|
|
@@ -26975,7 +27344,13 @@ var AUTO_COMPACT_TELEMETRY_PHASES = /* @__PURE__ */ new Set([
|
|
|
26975
27344
|
"MESSAGE_TRANSFORM_APPLIED",
|
|
26976
27345
|
"AUTO_COMPACT_SANITIZER_APPLIED",
|
|
26977
27346
|
"AUTO_COMPACT_SUMMARY_QUALITY",
|
|
26978
|
-
"AUTO_COMPACT_BUDGET_APPLIED"
|
|
27347
|
+
"AUTO_COMPACT_BUDGET_APPLIED",
|
|
27348
|
+
"COMPACTION_BOUNDARY_APPLIED",
|
|
27349
|
+
"SESSION_TYPED_PATH_APPLIED",
|
|
27350
|
+
"SESSION_CANONICAL_FALLBACK_APPLIED",
|
|
27351
|
+
"SESSION_TYPED_PATH_CONSISTENCY_FAILED",
|
|
27352
|
+
"SESSION_TYPED_PATH_POLICY_APPLIED",
|
|
27353
|
+
"SESSION_TYPED_PATH_AUTO_DEGRADED"
|
|
26979
27354
|
]);
|
|
26980
27355
|
var AUTO_COMPACT_SINK_LISTENER_ID = "auto-compact-metrics-sink";
|
|
26981
27356
|
var autoCompactSink = createAutoCompactMetricsSink();
|
|
@@ -27226,35 +27601,35 @@ function getModelCapabilities(modelName) {
|
|
|
27226
27601
|
}
|
|
27227
27602
|
|
|
27228
27603
|
// src/services/ai/policyDispatch/policyConfigLoader.ts
|
|
27229
|
-
import { existsSync as
|
|
27604
|
+
import { existsSync as existsSync18, readFileSync as readFileSync14 } from "fs";
|
|
27230
27605
|
import { join as join14, resolve as resolve11 } from "path";
|
|
27231
27606
|
|
|
27232
27607
|
// src/services/ai/policyDispatch/policyConfigSchema.ts
|
|
27233
|
-
import { z as
|
|
27234
|
-
var policyConfigSchema =
|
|
27235
|
-
version:
|
|
27236
|
-
defaults:
|
|
27237
|
-
reasoningPolicy:
|
|
27608
|
+
import { z as z12 } from "zod";
|
|
27609
|
+
var policyConfigSchema = z12.object({
|
|
27610
|
+
version: z12.string().min(1),
|
|
27611
|
+
defaults: z12.object({
|
|
27612
|
+
reasoningPolicy: z12.enum([
|
|
27238
27613
|
"preserve_reasoning_blocks",
|
|
27239
27614
|
"map_to_provider_options",
|
|
27240
27615
|
"flatten_to_text_fallback"
|
|
27241
27616
|
]).optional(),
|
|
27242
|
-
normalizeProviderContent:
|
|
27243
|
-
trimCrossModelMetadata:
|
|
27617
|
+
normalizeProviderContent: z12.boolean().optional(),
|
|
27618
|
+
trimCrossModelMetadata: z12.boolean().optional()
|
|
27244
27619
|
}).optional(),
|
|
27245
|
-
overrides:
|
|
27246
|
-
|
|
27247
|
-
model:
|
|
27248
|
-
modelFamily:
|
|
27249
|
-
provider:
|
|
27250
|
-
scenario:
|
|
27251
|
-
reasoningPolicy:
|
|
27620
|
+
overrides: z12.array(
|
|
27621
|
+
z12.object({
|
|
27622
|
+
model: z12.string().min(1).optional(),
|
|
27623
|
+
modelFamily: z12.string().min(1).optional(),
|
|
27624
|
+
provider: z12.string().min(1).optional(),
|
|
27625
|
+
scenario: z12.enum(["query", "auto_compact", "other"]).optional(),
|
|
27626
|
+
reasoningPolicy: z12.enum([
|
|
27252
27627
|
"preserve_reasoning_blocks",
|
|
27253
27628
|
"map_to_provider_options",
|
|
27254
27629
|
"flatten_to_text_fallback"
|
|
27255
27630
|
]).optional(),
|
|
27256
|
-
normalizeProviderContent:
|
|
27257
|
-
trimCrossModelMetadata:
|
|
27631
|
+
normalizeProviderContent: z12.boolean().optional(),
|
|
27632
|
+
trimCrossModelMetadata: z12.boolean().optional()
|
|
27258
27633
|
})
|
|
27259
27634
|
).optional().default([])
|
|
27260
27635
|
});
|
|
@@ -27273,9 +27648,9 @@ function getDefaultPolicyConfigPath() {
|
|
|
27273
27648
|
}
|
|
27274
27649
|
function loadAutoCompactPolicyConfig(options) {
|
|
27275
27650
|
const filePath = resolve11(options?.filePath ?? getDefaultPolicyConfigPath());
|
|
27276
|
-
if (!
|
|
27651
|
+
if (!existsSync18(filePath)) return null;
|
|
27277
27652
|
try {
|
|
27278
|
-
const raw =
|
|
27653
|
+
const raw = readFileSync14(filePath, "utf8");
|
|
27279
27654
|
const parsed = JSON.parse(raw);
|
|
27280
27655
|
return policyConfigSchema.parse(parsed);
|
|
27281
27656
|
} catch {
|
|
@@ -27361,218 +27736,6 @@ function resolveModelResponsePolicy(input) {
|
|
|
27361
27736
|
};
|
|
27362
27737
|
}
|
|
27363
27738
|
|
|
27364
|
-
// src/services/ai/streamTyped/partTypes.ts
|
|
27365
|
-
import { z as z12 } from "zod";
|
|
27366
|
-
var SOURCE_VALUES = ["auto_compact"];
|
|
27367
|
-
var TOOL_STATUS_VALUES = ["pending", "running", "completed", "failed", "interrupted"];
|
|
27368
|
-
var textPayloadSchema = z12.object({
|
|
27369
|
-
text: z12.string().min(1)
|
|
27370
|
-
});
|
|
27371
|
-
var reasoningPayloadSchema = z12.object({
|
|
27372
|
-
text: z12.string().min(1)
|
|
27373
|
-
});
|
|
27374
|
-
var toolPayloadSchema = z12.object({
|
|
27375
|
-
toolName: z12.string().min(1),
|
|
27376
|
-
toolCallId: z12.string().min(1),
|
|
27377
|
-
status: z12.enum(TOOL_STATUS_VALUES),
|
|
27378
|
-
outputText: z12.string().optional()
|
|
27379
|
-
});
|
|
27380
|
-
var streamTypedPartBaseSchema = z12.object({
|
|
27381
|
-
id: z12.string().min(1),
|
|
27382
|
-
requestId: z12.string().min(1),
|
|
27383
|
-
source: z12.enum(SOURCE_VALUES),
|
|
27384
|
-
timestamp: z12.number().int().positive()
|
|
27385
|
-
});
|
|
27386
|
-
var streamTypedPartSchema = z12.discriminatedUnion("partType", [
|
|
27387
|
-
streamTypedPartBaseSchema.extend({
|
|
27388
|
-
partType: z12.literal("text"),
|
|
27389
|
-
payload: textPayloadSchema
|
|
27390
|
-
}),
|
|
27391
|
-
streamTypedPartBaseSchema.extend({
|
|
27392
|
-
partType: z12.literal("reasoning"),
|
|
27393
|
-
payload: reasoningPayloadSchema
|
|
27394
|
-
}),
|
|
27395
|
-
streamTypedPartBaseSchema.extend({
|
|
27396
|
-
partType: z12.literal("tool"),
|
|
27397
|
-
payload: toolPayloadSchema
|
|
27398
|
-
})
|
|
27399
|
-
]);
|
|
27400
|
-
function createId() {
|
|
27401
|
-
return `stp_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
27402
|
-
}
|
|
27403
|
-
function createBase(input) {
|
|
27404
|
-
return {
|
|
27405
|
-
id: createId(),
|
|
27406
|
-
requestId: input.requestId,
|
|
27407
|
-
source: "auto_compact",
|
|
27408
|
-
timestamp: Date.now()
|
|
27409
|
-
};
|
|
27410
|
-
}
|
|
27411
|
-
function createTextPart(input) {
|
|
27412
|
-
return streamTypedPartSchema.parse({
|
|
27413
|
-
...createBase(input),
|
|
27414
|
-
partType: "text",
|
|
27415
|
-
payload: {
|
|
27416
|
-
text: input.text.trim()
|
|
27417
|
-
}
|
|
27418
|
-
});
|
|
27419
|
-
}
|
|
27420
|
-
function createReasoningPart(input) {
|
|
27421
|
-
return streamTypedPartSchema.parse({
|
|
27422
|
-
...createBase(input),
|
|
27423
|
-
partType: "reasoning",
|
|
27424
|
-
payload: {
|
|
27425
|
-
text: input.text.trim()
|
|
27426
|
-
}
|
|
27427
|
-
});
|
|
27428
|
-
}
|
|
27429
|
-
function createToolPart(input) {
|
|
27430
|
-
return streamTypedPartSchema.parse({
|
|
27431
|
-
...createBase(input),
|
|
27432
|
-
partType: "tool",
|
|
27433
|
-
payload: {
|
|
27434
|
-
toolName: input.toolName,
|
|
27435
|
-
toolCallId: input.toolCallId,
|
|
27436
|
-
status: input.status,
|
|
27437
|
-
...input.outputText ? { outputText: input.outputText } : {}
|
|
27438
|
-
}
|
|
27439
|
-
});
|
|
27440
|
-
}
|
|
27441
|
-
|
|
27442
|
-
// src/services/ai/streamTyped/eventAssembler.ts
|
|
27443
|
-
function createAssemblerState(requestId) {
|
|
27444
|
-
return {
|
|
27445
|
-
requestId,
|
|
27446
|
-
parts: [],
|
|
27447
|
-
textBuffer: {},
|
|
27448
|
-
reasoningBuffer: {},
|
|
27449
|
-
toolMap: {}
|
|
27450
|
-
};
|
|
27451
|
-
}
|
|
27452
|
-
function onTextStart(event, state) {
|
|
27453
|
-
state.textBuffer[event.textId] = "";
|
|
27454
|
-
}
|
|
27455
|
-
function onTextDelta(event, state) {
|
|
27456
|
-
const current = state.textBuffer[event.textId] ?? "";
|
|
27457
|
-
state.textBuffer[event.textId] = `${current}${event.text}`;
|
|
27458
|
-
}
|
|
27459
|
-
function onTextEnd(event, state) {
|
|
27460
|
-
const text = String(state.textBuffer[event.textId] ?? "").trim();
|
|
27461
|
-
delete state.textBuffer[event.textId];
|
|
27462
|
-
if (!text) return;
|
|
27463
|
-
state.parts.push(
|
|
27464
|
-
createTextPart({
|
|
27465
|
-
requestId: state.requestId,
|
|
27466
|
-
text
|
|
27467
|
-
})
|
|
27468
|
-
);
|
|
27469
|
-
}
|
|
27470
|
-
function onReasoningStart(event, state) {
|
|
27471
|
-
state.reasoningBuffer[event.reasoningId] = "";
|
|
27472
|
-
}
|
|
27473
|
-
function onReasoningDelta(event, state) {
|
|
27474
|
-
const current = state.reasoningBuffer[event.reasoningId] ?? "";
|
|
27475
|
-
state.reasoningBuffer[event.reasoningId] = `${current}${event.text}`;
|
|
27476
|
-
}
|
|
27477
|
-
function onReasoningEnd(event, state) {
|
|
27478
|
-
const text = String(state.reasoningBuffer[event.reasoningId] ?? "").trim();
|
|
27479
|
-
delete state.reasoningBuffer[event.reasoningId];
|
|
27480
|
-
if (!text) return;
|
|
27481
|
-
state.parts.push(
|
|
27482
|
-
createReasoningPart({
|
|
27483
|
-
requestId: state.requestId,
|
|
27484
|
-
text
|
|
27485
|
-
})
|
|
27486
|
-
);
|
|
27487
|
-
}
|
|
27488
|
-
function onToolCall(event, state) {
|
|
27489
|
-
state.toolMap[event.toolCallId] = { toolName: event.toolName };
|
|
27490
|
-
}
|
|
27491
|
-
function onToolResult(event, state) {
|
|
27492
|
-
const toolName = state.toolMap[event.toolCallId]?.toolName ?? "unknown";
|
|
27493
|
-
state.parts.push(
|
|
27494
|
-
createToolPart({
|
|
27495
|
-
requestId: state.requestId,
|
|
27496
|
-
toolName,
|
|
27497
|
-
toolCallId: event.toolCallId,
|
|
27498
|
-
status: event.status,
|
|
27499
|
-
outputText: event.outputText
|
|
27500
|
-
})
|
|
27501
|
-
);
|
|
27502
|
-
delete state.toolMap[event.toolCallId];
|
|
27503
|
-
}
|
|
27504
|
-
function flushTypedParts(state) {
|
|
27505
|
-
const parts = state.parts.slice();
|
|
27506
|
-
state.parts.length = 0;
|
|
27507
|
-
return parts;
|
|
27508
|
-
}
|
|
27509
|
-
|
|
27510
|
-
// src/services/ai/streamTyped/partStore.ts
|
|
27511
|
-
import { appendFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, readFileSync as readFileSync14 } from "fs";
|
|
27512
|
-
import { dirname as dirname9 } from "path";
|
|
27513
|
-
function getStreamTypedOutputFilePath() {
|
|
27514
|
-
return resolveXdgCachePath("telemetry/stream-typed-parts.jsonl");
|
|
27515
|
-
}
|
|
27516
|
-
function validateTypedPartRecord(record) {
|
|
27517
|
-
return streamTypedPartSchema.safeParse(record).success;
|
|
27518
|
-
}
|
|
27519
|
-
function readAllValidParts(outputFilePath) {
|
|
27520
|
-
if (!existsSync18(outputFilePath)) return [];
|
|
27521
|
-
const raw = readFileSync14(outputFilePath, "utf8");
|
|
27522
|
-
const lines = raw.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
27523
|
-
const parts = [];
|
|
27524
|
-
for (const line of lines) {
|
|
27525
|
-
try {
|
|
27526
|
-
const parsed = JSON.parse(line);
|
|
27527
|
-
if (!validateTypedPartRecord(parsed)) continue;
|
|
27528
|
-
parts.push(parsed);
|
|
27529
|
-
} catch {
|
|
27530
|
-
continue;
|
|
27531
|
-
}
|
|
27532
|
-
}
|
|
27533
|
-
return parts;
|
|
27534
|
-
}
|
|
27535
|
-
function appendTypedParts(options) {
|
|
27536
|
-
if (!Array.isArray(options.parts) || options.parts.length === 0) {
|
|
27537
|
-
return { appended: 0 };
|
|
27538
|
-
}
|
|
27539
|
-
const outputFilePath = options.outputFilePath ?? getStreamTypedOutputFilePath();
|
|
27540
|
-
if (!existsSync18(dirname9(outputFilePath))) {
|
|
27541
|
-
mkdirSync7(dirname9(outputFilePath), { recursive: true });
|
|
27542
|
-
}
|
|
27543
|
-
const existingIds = new Set(readAllValidParts(outputFilePath).map((item) => item.id));
|
|
27544
|
-
const toAppend = options.parts.filter(
|
|
27545
|
-
(item) => validateTypedPartRecord(item) && !existingIds.has(item.id)
|
|
27546
|
-
);
|
|
27547
|
-
if (toAppend.length === 0) return { appended: 0 };
|
|
27548
|
-
appendFileSync(
|
|
27549
|
-
outputFilePath,
|
|
27550
|
-
`${toAppend.map((item) => JSON.stringify(item)).join("\n")}
|
|
27551
|
-
`
|
|
27552
|
-
);
|
|
27553
|
-
return { appended: toAppend.length };
|
|
27554
|
-
}
|
|
27555
|
-
|
|
27556
|
-
// src/services/ai/streamTyped/index.ts
|
|
27557
|
-
var streamTypedBuffer = /* @__PURE__ */ new Map();
|
|
27558
|
-
function emitTypedPart(event) {
|
|
27559
|
-
const requestId = String(event.requestId || "").trim();
|
|
27560
|
-
if (!requestId) return;
|
|
27561
|
-
const current = streamTypedBuffer.get(requestId) ?? [];
|
|
27562
|
-
current.push(event.part);
|
|
27563
|
-
streamTypedBuffer.set(requestId, current);
|
|
27564
|
-
}
|
|
27565
|
-
function flushTypedPartBuffer(options) {
|
|
27566
|
-
const requestId = String(options.requestId || "").trim();
|
|
27567
|
-
if (!requestId) return { appended: 0 };
|
|
27568
|
-
const parts = streamTypedBuffer.get(requestId) ?? [];
|
|
27569
|
-
streamTypedBuffer.delete(requestId);
|
|
27570
|
-
return appendTypedParts({
|
|
27571
|
-
outputFilePath: options.outputFilePath,
|
|
27572
|
-
parts
|
|
27573
|
-
});
|
|
27574
|
-
}
|
|
27575
|
-
|
|
27576
27739
|
// src/services/ai/streamTyped/replay.ts
|
|
27577
27740
|
function toNonEmptyText(value) {
|
|
27578
27741
|
const text = String(value ?? "").trim();
|
|
@@ -28164,6 +28327,7 @@ var CONVERSATION_SUMMARY_LIMITS = {
|
|
|
28164
28327
|
};
|
|
28165
28328
|
var MAX_COMPACTED_QUERY_IDS = 10;
|
|
28166
28329
|
var AUTO_COMPACT_CHAIN_RETRY_DELAY_MS = 250;
|
|
28330
|
+
var MAX_DEBUG_SUMMARY_LOG_CHARS = 2400;
|
|
28167
28331
|
function wait(ms) {
|
|
28168
28332
|
return new Promise((resolve14) => setTimeout(resolve14, ms));
|
|
28169
28333
|
}
|
|
@@ -28229,6 +28393,21 @@ function computeSummaryQualitySignals(sourceText, summaryText) {
|
|
|
28229
28393
|
taskGoalRetained
|
|
28230
28394
|
};
|
|
28231
28395
|
}
|
|
28396
|
+
function buildSummaryDebugPreview(summary) {
|
|
28397
|
+
if (summary.length <= MAX_DEBUG_SUMMARY_LOG_CHARS) {
|
|
28398
|
+
return {
|
|
28399
|
+
summaryPreview: summary,
|
|
28400
|
+
summaryLength: summary.length,
|
|
28401
|
+
truncated: false
|
|
28402
|
+
};
|
|
28403
|
+
}
|
|
28404
|
+
return {
|
|
28405
|
+
summaryPreview: `${summary.slice(0, MAX_DEBUG_SUMMARY_LOG_CHARS)}
|
|
28406
|
+
...[truncated]...`,
|
|
28407
|
+
summaryLength: summary.length,
|
|
28408
|
+
truncated: true
|
|
28409
|
+
};
|
|
28410
|
+
}
|
|
28232
28411
|
async function calculateThresholds(tokenCount) {
|
|
28233
28412
|
const contextLimit = await getMainConversationContextLimit();
|
|
28234
28413
|
return calculateAutoCompactThresholds(tokenCount, contextLimit);
|
|
@@ -28262,7 +28441,7 @@ function getSummaryContentDiagnostics(content) {
|
|
|
28262
28441
|
value: content
|
|
28263
28442
|
};
|
|
28264
28443
|
}
|
|
28265
|
-
function
|
|
28444
|
+
function extractToolResultText2(content) {
|
|
28266
28445
|
if (typeof content === "string") return content;
|
|
28267
28446
|
if (!Array.isArray(content)) return "";
|
|
28268
28447
|
return content.filter((block) => block && typeof block === "object" && block.type === "text").map((block) => String(block.text ?? "")).join("\n");
|
|
@@ -28273,27 +28452,75 @@ function parseBooleanFlag(value) {
|
|
|
28273
28452
|
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
28274
28453
|
return null;
|
|
28275
28454
|
}
|
|
28455
|
+
function parseNumberFlag(value) {
|
|
28456
|
+
const parsed = Number(value);
|
|
28457
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
28458
|
+
return parsed;
|
|
28459
|
+
}
|
|
28276
28460
|
function resolveTypedReadPathConfig(toolUseContext) {
|
|
28277
28461
|
const envValue = parseBooleanFlag(
|
|
28278
28462
|
process.env.PYB_AUTO_COMPACT_TYPED_READ_PATH_ENABLED
|
|
28279
28463
|
);
|
|
28280
28464
|
if (envValue !== null) {
|
|
28281
28465
|
return {
|
|
28282
|
-
enabled: envValue,
|
|
28283
|
-
source: "env"
|
|
28466
|
+
enabled: envValue,
|
|
28467
|
+
source: "env"
|
|
28468
|
+
};
|
|
28469
|
+
}
|
|
28470
|
+
if (typeof toolUseContext?.typedPathEnabled === "boolean") {
|
|
28471
|
+
return {
|
|
28472
|
+
enabled: toolUseContext.typedPathEnabled,
|
|
28473
|
+
source: "context"
|
|
28474
|
+
};
|
|
28475
|
+
}
|
|
28476
|
+
return {
|
|
28477
|
+
enabled: true,
|
|
28478
|
+
source: "default"
|
|
28479
|
+
};
|
|
28480
|
+
}
|
|
28481
|
+
function resolveTypedPathPolicyConfig(toolUseContext) {
|
|
28482
|
+
const policy = toolUseContext?.typedPathPolicy ?? {};
|
|
28483
|
+
const envMinPrimaryPathRate = parseNumberFlag(
|
|
28484
|
+
process.env.PYB_AUTO_COMPACT_TYPED_PATH_MIN_PRIMARY_RATE
|
|
28485
|
+
);
|
|
28486
|
+
const envMaxFallbackAnomalyStreak = parseNumberFlag(
|
|
28487
|
+
process.env.PYB_AUTO_COMPACT_TYPED_PATH_MAX_FALLBACK_STREAK
|
|
28488
|
+
);
|
|
28489
|
+
const minPrimaryPathRate = Number.isFinite(envMinPrimaryPathRate) ? Math.min(1, Math.max(0, Number(envMinPrimaryPathRate))) : Number.isFinite(policy?.minPrimaryPathRate) ? Math.min(1, Math.max(0, Number(policy.minPrimaryPathRate))) : void 0;
|
|
28490
|
+
const observedPrimaryPathRate = Number.isFinite(policy?.observedPrimaryPathRate) ? Math.min(1, Math.max(0, Number(policy.observedPrimaryPathRate))) : void 0;
|
|
28491
|
+
const maxFallbackAnomalyStreak = Number.isFinite(envMaxFallbackAnomalyStreak) ? Math.max(1, Math.floor(Number(envMaxFallbackAnomalyStreak))) : Number.isFinite(policy?.maxFallbackAnomalyStreak) ? Math.max(1, Math.floor(Number(policy.maxFallbackAnomalyStreak))) : void 0;
|
|
28492
|
+
const currentFallbackAnomalyStreak = Number.isFinite(
|
|
28493
|
+
policy?.currentFallbackAnomalyStreak
|
|
28494
|
+
) ? Math.max(0, Math.floor(Number(policy.currentFallbackAnomalyStreak))) : 0;
|
|
28495
|
+
return {
|
|
28496
|
+
minPrimaryPathRate,
|
|
28497
|
+
observedPrimaryPathRate,
|
|
28498
|
+
maxFallbackAnomalyStreak,
|
|
28499
|
+
currentFallbackAnomalyStreak
|
|
28500
|
+
};
|
|
28501
|
+
}
|
|
28502
|
+
function evaluateTypedPathPolicyDecision(config2) {
|
|
28503
|
+
if (Number.isFinite(config2.minPrimaryPathRate) && Number.isFinite(config2.observedPrimaryPathRate) && Number(config2.observedPrimaryPathRate) < Number(config2.minPrimaryPathRate)) {
|
|
28504
|
+
return {
|
|
28505
|
+
forceFallback: true,
|
|
28506
|
+
reason: "promotion_threshold_not_met"
|
|
28284
28507
|
};
|
|
28285
28508
|
}
|
|
28286
|
-
if (
|
|
28509
|
+
if (Number.isFinite(config2.maxFallbackAnomalyStreak) && config2.currentFallbackAnomalyStreak >= Number(config2.maxFallbackAnomalyStreak)) {
|
|
28287
28510
|
return {
|
|
28288
|
-
|
|
28289
|
-
|
|
28511
|
+
forceFallback: true,
|
|
28512
|
+
reason: "fallback_anomaly_streak"
|
|
28290
28513
|
};
|
|
28291
28514
|
}
|
|
28292
28515
|
return {
|
|
28293
|
-
|
|
28294
|
-
|
|
28516
|
+
forceFallback: false,
|
|
28517
|
+
reason: "policy_not_triggered"
|
|
28295
28518
|
};
|
|
28296
28519
|
}
|
|
28520
|
+
function emitSessionReadPathEvent(phase, payload) {
|
|
28521
|
+
debug.warn(phase, payload);
|
|
28522
|
+
emitAutoCompactTelemetryEvent(phase, payload);
|
|
28523
|
+
}
|
|
28297
28524
|
function emitStreamTypedPartsFromContent(content, requestId) {
|
|
28298
28525
|
const state = createAssemblerState(requestId);
|
|
28299
28526
|
if (typeof content === "string") {
|
|
@@ -28329,7 +28556,7 @@ function emitStreamTypedPartsFromContent(content, requestId) {
|
|
|
28329
28556
|
}
|
|
28330
28557
|
if (type3 === "tool_result") {
|
|
28331
28558
|
const toolCallId = String(block.tool_use_id ?? `tool-${i}`);
|
|
28332
|
-
const outputText =
|
|
28559
|
+
const outputText = extractToolResultText2(block.content);
|
|
28333
28560
|
onToolResult(
|
|
28334
28561
|
{
|
|
28335
28562
|
toolCallId,
|
|
@@ -28474,9 +28701,24 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28474
28701
|
enabled: typedPath.enabled,
|
|
28475
28702
|
parts: emittedTypedParts
|
|
28476
28703
|
});
|
|
28704
|
+
const typedPathPolicyConfig = resolveTypedPathPolicyConfig(toolUseContext);
|
|
28705
|
+
const typedPathPolicyDecision = evaluateTypedPathPolicyDecision(
|
|
28706
|
+
typedPathPolicyConfig
|
|
28707
|
+
);
|
|
28708
|
+
const hasTypedPolicy = Number.isFinite(typedPathPolicyConfig.minPrimaryPathRate) || Number.isFinite(typedPathPolicyConfig.maxFallbackAnomalyStreak);
|
|
28709
|
+
if (typedPath.enabled && hasTypedPolicy) {
|
|
28710
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_POLICY_APPLIED", {
|
|
28711
|
+
forceFallback: typedPathPolicyDecision.forceFallback,
|
|
28712
|
+
reason: typedPathPolicyDecision.reason,
|
|
28713
|
+
minPrimaryPathRate: typedPathPolicyConfig.minPrimaryPathRate,
|
|
28714
|
+
observedPrimaryPathRate: typedPathPolicyConfig.observedPrimaryPathRate,
|
|
28715
|
+
maxFallbackAnomalyStreak: typedPathPolicyConfig.maxFallbackAnomalyStreak,
|
|
28716
|
+
currentFallbackAnomalyStreak: typedPathPolicyConfig.currentFallbackAnomalyStreak
|
|
28717
|
+
});
|
|
28718
|
+
}
|
|
28477
28719
|
let canonicalResult = null;
|
|
28478
28720
|
let summary = null;
|
|
28479
|
-
if (typedPath.enabled && typedReplay.isComplete && typedReplay.summaryText) {
|
|
28721
|
+
if (typedPath.enabled && typedReplay.isComplete && typedReplay.summaryText && !typedPathPolicyDecision.forceFallback) {
|
|
28480
28722
|
summary = typedReplay.summaryText;
|
|
28481
28723
|
const typedAppliedPayload = {
|
|
28482
28724
|
mode: "typed",
|
|
@@ -28490,7 +28732,30 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28490
28732
|
"AUTO_COMPACT_TYPED_PATH_APPLIED",
|
|
28491
28733
|
typedAppliedPayload
|
|
28492
28734
|
);
|
|
28735
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_APPLIED", typedAppliedPayload);
|
|
28736
|
+
if (toolUseContext) {
|
|
28737
|
+
toolUseContext.typedPathPolicy = {
|
|
28738
|
+
...toolUseContext.typedPathPolicy ?? {},
|
|
28739
|
+
currentFallbackAnomalyStreak: 0
|
|
28740
|
+
};
|
|
28741
|
+
}
|
|
28493
28742
|
} else {
|
|
28743
|
+
if (typedPath.enabled && typedPathPolicyDecision.forceFallback && typedPathPolicyDecision.reason === "fallback_anomaly_streak") {
|
|
28744
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_AUTO_DEGRADED", {
|
|
28745
|
+
reason: typedPathPolicyDecision.reason,
|
|
28746
|
+
currentFallbackAnomalyStreak: typedPathPolicyConfig.currentFallbackAnomalyStreak,
|
|
28747
|
+
maxFallbackAnomalyStreak: typedPathPolicyConfig.maxFallbackAnomalyStreak
|
|
28748
|
+
});
|
|
28749
|
+
}
|
|
28750
|
+
if (typedPath.enabled && typedReplay.isComplete && !typedReplay.summaryText) {
|
|
28751
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_CONSISTENCY_FAILED", {
|
|
28752
|
+
mode: "typed_incomplete_payload",
|
|
28753
|
+
pathSource: typedPath.source,
|
|
28754
|
+
reason: typedReplay.reason,
|
|
28755
|
+
textPartCount: typedReplay.textPartCount,
|
|
28756
|
+
reasoningPartCount: typedReplay.reasoningPartCount
|
|
28757
|
+
});
|
|
28758
|
+
}
|
|
28494
28759
|
canonicalResult = normalizeModelResponseContent(content, {
|
|
28495
28760
|
source: "auto_compact",
|
|
28496
28761
|
model: activeModelName,
|
|
@@ -28503,7 +28768,7 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28503
28768
|
mode: typedPath.enabled ? "canonical_fallback" : "canonical_disabled",
|
|
28504
28769
|
pathSource: typedPath.source,
|
|
28505
28770
|
...typedPath.enabled ? {
|
|
28506
|
-
reason: typedReplay.reason,
|
|
28771
|
+
reason: typedPathPolicyDecision.forceFallback ? typedPathPolicyDecision.reason : typedReplay.reason,
|
|
28507
28772
|
textPartCount: typedReplay.textPartCount,
|
|
28508
28773
|
reasoningPartCount: typedReplay.reasoningPartCount
|
|
28509
28774
|
} : {}
|
|
@@ -28513,6 +28778,18 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28513
28778
|
"AUTO_COMPACT_TYPED_PATH_APPLIED",
|
|
28514
28779
|
typedAppliedPayload
|
|
28515
28780
|
);
|
|
28781
|
+
if (typedPath.enabled) {
|
|
28782
|
+
emitSessionReadPathEvent(
|
|
28783
|
+
"SESSION_CANONICAL_FALLBACK_APPLIED",
|
|
28784
|
+
typedAppliedPayload
|
|
28785
|
+
);
|
|
28786
|
+
if (toolUseContext) {
|
|
28787
|
+
toolUseContext.typedPathPolicy = {
|
|
28788
|
+
...toolUseContext.typedPathPolicy ?? {},
|
|
28789
|
+
currentFallbackAnomalyStreak: typedPathPolicyConfig.currentFallbackAnomalyStreak + 1
|
|
28790
|
+
};
|
|
28791
|
+
}
|
|
28792
|
+
}
|
|
28516
28793
|
}
|
|
28517
28794
|
if (!summary) {
|
|
28518
28795
|
debug.warn("AUTO_COMPACT_SUMMARY_CONTENT_INVALID", {
|
|
@@ -28531,6 +28808,11 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28531
28808
|
);
|
|
28532
28809
|
}
|
|
28533
28810
|
summaryResponse = summaryCandidate;
|
|
28811
|
+
debug.warn("AUTO_COMPACT_SUMMARY_GENERATED", {
|
|
28812
|
+
...buildSummaryDebugPreview(summary),
|
|
28813
|
+
model: activeModelPointer,
|
|
28814
|
+
attempt: attempts
|
|
28815
|
+
});
|
|
28534
28816
|
emitAutoCompactTelemetryEvent("AUTO_COMPACT_SUMMARY_QUALITY", {
|
|
28535
28817
|
...computeSummaryQualitySignals(compactionSourceText, summary)
|
|
28536
28818
|
});
|
|
@@ -28687,6 +28969,637 @@ ${contentWithLines}
|
|
|
28687
28969
|
return budgetApplied.messages;
|
|
28688
28970
|
}
|
|
28689
28971
|
|
|
28972
|
+
// src/utils/session/compactionBoundary.ts
|
|
28973
|
+
function parseBooleanFlag2(value) {
|
|
28974
|
+
const raw = String(value ?? "").trim().toLowerCase();
|
|
28975
|
+
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
28976
|
+
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
28977
|
+
return null;
|
|
28978
|
+
}
|
|
28979
|
+
function resolveCompactionBoundaryConfig(toolUseContext) {
|
|
28980
|
+
const envValue = parseBooleanFlag2(process.env.PYB_COMPACTION_BOUNDARY_ENABLED);
|
|
28981
|
+
if (envValue !== null) {
|
|
28982
|
+
return {
|
|
28983
|
+
enabled: envValue,
|
|
28984
|
+
source: "env"
|
|
28985
|
+
};
|
|
28986
|
+
}
|
|
28987
|
+
if (typeof toolUseContext?.compactionBoundaryEnabled === "boolean") {
|
|
28988
|
+
return {
|
|
28989
|
+
enabled: toolUseContext.compactionBoundaryEnabled,
|
|
28990
|
+
source: "context"
|
|
28991
|
+
};
|
|
28992
|
+
}
|
|
28993
|
+
return {
|
|
28994
|
+
enabled: false,
|
|
28995
|
+
source: "default"
|
|
28996
|
+
};
|
|
28997
|
+
}
|
|
28998
|
+
function findLastCompactionBoundaryIndex(messages) {
|
|
28999
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
29000
|
+
const message = messages[i];
|
|
29001
|
+
if (message?.type === "assistant" && message?.compaction?.type === "compaction") {
|
|
29002
|
+
return i;
|
|
29003
|
+
}
|
|
29004
|
+
}
|
|
29005
|
+
return -1;
|
|
29006
|
+
}
|
|
29007
|
+
function filterAfterCompactionBoundary(messages, options) {
|
|
29008
|
+
const getMessageText4 = (message) => {
|
|
29009
|
+
if (message.type !== "user") return "";
|
|
29010
|
+
const content = message?.message?.content;
|
|
29011
|
+
if (typeof content === "string") return content.trim();
|
|
29012
|
+
if (!Array.isArray(content)) return "";
|
|
29013
|
+
return content.filter(
|
|
29014
|
+
(block) => block && typeof block === "object" && block.type === "text"
|
|
29015
|
+
).map((block) => String(block.text ?? "")).join("\n").trim();
|
|
29016
|
+
};
|
|
29017
|
+
const isAutoCompactNotice2 = (message) => getMessageText4(message).includes("Context automatically compressed due to token limit.");
|
|
29018
|
+
const isRecoveredFileMessage2 = (message) => getMessageText4(message).includes("**Recovered File:");
|
|
29019
|
+
const isReplayableUserTask = (message) => {
|
|
29020
|
+
const text = getMessageText4(message);
|
|
29021
|
+
if (!text) return false;
|
|
29022
|
+
if (isAutoCompactNotice2(message)) return false;
|
|
29023
|
+
if (isRecoveredFileMessage2(message)) return false;
|
|
29024
|
+
return true;
|
|
29025
|
+
};
|
|
29026
|
+
if (!options.enabled) {
|
|
29027
|
+
return {
|
|
29028
|
+
messages,
|
|
29029
|
+
applied: false,
|
|
29030
|
+
droppedMessageCount: 0,
|
|
29031
|
+
preservedMessageCount: messages.length,
|
|
29032
|
+
lastCompactionIndex: -1,
|
|
29033
|
+
replayMode: "not_applied"
|
|
29034
|
+
};
|
|
29035
|
+
}
|
|
29036
|
+
const lastCompactionIndex = findLastCompactionBoundaryIndex(messages);
|
|
29037
|
+
if (lastCompactionIndex < 0) {
|
|
29038
|
+
return {
|
|
29039
|
+
messages,
|
|
29040
|
+
applied: false,
|
|
29041
|
+
droppedMessageCount: 0,
|
|
29042
|
+
preservedMessageCount: messages.length,
|
|
29043
|
+
lastCompactionIndex: -1,
|
|
29044
|
+
replayMode: "not_applied"
|
|
29045
|
+
};
|
|
29046
|
+
}
|
|
29047
|
+
const filtered = messages.slice(lastCompactionIndex);
|
|
29048
|
+
const hasUserTask = filtered.some((item) => isReplayableUserTask(item));
|
|
29049
|
+
if (hasUserTask) {
|
|
29050
|
+
return {
|
|
29051
|
+
messages: filtered,
|
|
29052
|
+
applied: true,
|
|
29053
|
+
droppedMessageCount: Math.max(0, messages.length - filtered.length),
|
|
29054
|
+
preservedMessageCount: filtered.length,
|
|
29055
|
+
lastCompactionIndex,
|
|
29056
|
+
replayMode: "already_has_user_task"
|
|
29057
|
+
};
|
|
29058
|
+
}
|
|
29059
|
+
let replayText = "";
|
|
29060
|
+
for (let i = lastCompactionIndex - 1; i >= 0; i -= 1) {
|
|
29061
|
+
const message = messages[i];
|
|
29062
|
+
if (!isReplayableUserTask(message)) continue;
|
|
29063
|
+
replayText = getMessageText4(message);
|
|
29064
|
+
break;
|
|
29065
|
+
}
|
|
29066
|
+
const replayMessage = replayText ? createUserMessage(replayText) : createUserMessage(
|
|
29067
|
+
"Continue from compressed context and ask a brief clarifying question if the task objective is missing."
|
|
29068
|
+
);
|
|
29069
|
+
const withReplay = [...filtered, replayMessage];
|
|
29070
|
+
return {
|
|
29071
|
+
messages: withReplay,
|
|
29072
|
+
applied: true,
|
|
29073
|
+
droppedMessageCount: Math.max(0, messages.length - withReplay.length),
|
|
29074
|
+
preservedMessageCount: withReplay.length,
|
|
29075
|
+
lastCompactionIndex,
|
|
29076
|
+
replayMode: replayText ? "replayed_latest_user_task" : "synthetic_continue_prompt"
|
|
29077
|
+
};
|
|
29078
|
+
}
|
|
29079
|
+
|
|
29080
|
+
// src/utils/session/toolOutputLifecycle.ts
|
|
29081
|
+
function parseBooleanFlag3(value) {
|
|
29082
|
+
const raw = String(value ?? "").trim().toLowerCase();
|
|
29083
|
+
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
29084
|
+
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
29085
|
+
return null;
|
|
29086
|
+
}
|
|
29087
|
+
function resolveToolOutputLifecycleConfig(toolUseContext) {
|
|
29088
|
+
const envValue = parseBooleanFlag3(process.env.PYB_TOOL_OUTPUT_LIFECYCLE_ENABLED);
|
|
29089
|
+
const enabled = envValue !== null ? envValue : typeof toolUseContext?.toolOutputLifecycleEnabled === "boolean" ? toolUseContext.toolOutputLifecycleEnabled : false;
|
|
29090
|
+
const source = envValue !== null ? "env" : typeof toolUseContext?.toolOutputLifecycleEnabled === "boolean" ? "context" : "default";
|
|
29091
|
+
const maxAgeTurnsRaw = toolUseContext?.toolOutputLifecycleConfig?.maxAgeTurns ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_MAX_AGE_TURNS;
|
|
29092
|
+
const protectFailedRaw = toolUseContext?.toolOutputLifecycleConfig?.protectFailedResultTurns ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_PROTECT_FAILED_TURNS;
|
|
29093
|
+
const maxAgeTurns = Number.isFinite(Number(maxAgeTurnsRaw)) ? Math.max(1, Number(maxAgeTurnsRaw)) : 3;
|
|
29094
|
+
const protectFailedResultTurns = Number.isFinite(Number(protectFailedRaw)) ? Math.max(1, Number(protectFailedRaw)) : 6;
|
|
29095
|
+
const l3AgeTurnsRaw = toolUseContext?.toolOutputLifecycleConfig?.l3AgeTurns ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_L3_AGE_TURNS;
|
|
29096
|
+
const l1MinCharsRaw = toolUseContext?.toolOutputLifecycleConfig?.l1MinChars ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_L1_MIN_CHARS;
|
|
29097
|
+
const l3MinCharsRaw = toolUseContext?.toolOutputLifecycleConfig?.l3MinChars ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_L3_MIN_CHARS;
|
|
29098
|
+
const l3AgeTurns = Number.isFinite(Number(l3AgeTurnsRaw)) ? Math.max(maxAgeTurns + 1, Number(l3AgeTurnsRaw)) : Math.max(maxAgeTurns + 2, 6);
|
|
29099
|
+
const l1MinChars = Number.isFinite(Number(l1MinCharsRaw)) ? Math.max(120, Number(l1MinCharsRaw)) : 500;
|
|
29100
|
+
const l3MinChars = Number.isFinite(Number(l3MinCharsRaw)) ? Math.max(l1MinChars, Number(l3MinCharsRaw)) : 1800;
|
|
29101
|
+
return {
|
|
29102
|
+
enabled,
|
|
29103
|
+
source,
|
|
29104
|
+
maxAgeTurns,
|
|
29105
|
+
protectFailedResultTurns,
|
|
29106
|
+
l3AgeTurns,
|
|
29107
|
+
l1MinChars,
|
|
29108
|
+
l3MinChars
|
|
29109
|
+
};
|
|
29110
|
+
}
|
|
29111
|
+
function getMessageText3(message) {
|
|
29112
|
+
const content = message?.message?.content;
|
|
29113
|
+
if (typeof content === "string") return content.trim();
|
|
29114
|
+
if (!Array.isArray(content)) return "";
|
|
29115
|
+
return content.filter((block) => block && typeof block === "object" && block.type === "text").map((block) => String(block.text ?? "")).join("\n").trim();
|
|
29116
|
+
}
|
|
29117
|
+
function isNaturalUserMessage(message) {
|
|
29118
|
+
if (message.type !== "user") return false;
|
|
29119
|
+
const content = message?.message?.content;
|
|
29120
|
+
if (typeof content === "string") return content.trim().length > 0;
|
|
29121
|
+
if (!Array.isArray(content)) return false;
|
|
29122
|
+
const hasToolResultOnly = content.every(
|
|
29123
|
+
(block) => block && typeof block === "object" && block.type === "tool_result"
|
|
29124
|
+
);
|
|
29125
|
+
if (hasToolResultOnly) return false;
|
|
29126
|
+
const text = getMessageText3(message);
|
|
29127
|
+
return text.length > 0;
|
|
29128
|
+
}
|
|
29129
|
+
function extractLifecycleSignals(text) {
|
|
29130
|
+
const lines = text.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
29131
|
+
const fields = ["targets:", "keyfacts:", "errors:"];
|
|
29132
|
+
return lines.filter(
|
|
29133
|
+
(line) => fields.some((field) => line.toLowerCase().startsWith(field))
|
|
29134
|
+
);
|
|
29135
|
+
}
|
|
29136
|
+
function extractStatusSignal(text) {
|
|
29137
|
+
const line = text.split("\n").map((item) => item.trim()).find((item) => item.toLowerCase().startsWith("status:"));
|
|
29138
|
+
return line || "status: unknown";
|
|
29139
|
+
}
|
|
29140
|
+
function estimateTokens2(text) {
|
|
29141
|
+
return Math.max(1, Math.ceil(String(text ?? "").length * 0.25));
|
|
29142
|
+
}
|
|
29143
|
+
function estimateMessageTokens(message) {
|
|
29144
|
+
const content = message?.message?.content;
|
|
29145
|
+
if (typeof content === "string") {
|
|
29146
|
+
return estimateTokens2(content);
|
|
29147
|
+
}
|
|
29148
|
+
if (Array.isArray(content)) {
|
|
29149
|
+
const text = content.map((block) => {
|
|
29150
|
+
if (!block || typeof block !== "object") return "";
|
|
29151
|
+
if (typeof block.text === "string") return block.text;
|
|
29152
|
+
if (typeof block.content === "string") return block.content;
|
|
29153
|
+
return "";
|
|
29154
|
+
}).filter(Boolean).join("\n");
|
|
29155
|
+
return estimateTokens2(text);
|
|
29156
|
+
}
|
|
29157
|
+
return 1;
|
|
29158
|
+
}
|
|
29159
|
+
function estimateMessagesTokens(messages) {
|
|
29160
|
+
return messages.reduce((sum, message) => sum + estimateMessageTokens(message), 0);
|
|
29161
|
+
}
|
|
29162
|
+
function countToolResultBlocks(messages) {
|
|
29163
|
+
return messages.reduce((sum, message) => {
|
|
29164
|
+
if (message.type !== "user") return sum;
|
|
29165
|
+
const content = message?.message?.content;
|
|
29166
|
+
if (!Array.isArray(content)) return sum;
|
|
29167
|
+
return sum + content.filter(
|
|
29168
|
+
(block) => block && typeof block === "object" && block.type === "tool_result"
|
|
29169
|
+
).length;
|
|
29170
|
+
}, 0);
|
|
29171
|
+
}
|
|
29172
|
+
function buildDanglingClosureMessage(toolUseId) {
|
|
29173
|
+
return {
|
|
29174
|
+
type: "user",
|
|
29175
|
+
uuid: `dangling_${toolUseId}_${Date.now()}`,
|
|
29176
|
+
message: {
|
|
29177
|
+
role: "user",
|
|
29178
|
+
content: [
|
|
29179
|
+
{
|
|
29180
|
+
type: "tool_result",
|
|
29181
|
+
tool_use_id: toolUseId,
|
|
29182
|
+
is_error: true,
|
|
29183
|
+
error_class: "fatal",
|
|
29184
|
+
content: "status: interrupted\nerrors: dangling tool_use closed before replay\nkeyFacts: replay-safe closure applied\ntargets: none"
|
|
29185
|
+
}
|
|
29186
|
+
]
|
|
29187
|
+
}
|
|
29188
|
+
};
|
|
29189
|
+
}
|
|
29190
|
+
function closeDanglingToolUseBeforeReplay(messages) {
|
|
29191
|
+
const used = /* @__PURE__ */ new Set();
|
|
29192
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
29193
|
+
for (const message of messages) {
|
|
29194
|
+
if (message.type === "assistant") {
|
|
29195
|
+
const content = message?.message?.content;
|
|
29196
|
+
if (Array.isArray(content)) {
|
|
29197
|
+
for (const block of content) {
|
|
29198
|
+
if (!block || typeof block !== "object") continue;
|
|
29199
|
+
if (block.type === "tool_use" || block.type === "server_tool_use" || block.type === "mcp_tool_use") {
|
|
29200
|
+
const id = String(block.id ?? "").trim();
|
|
29201
|
+
if (id) used.add(id);
|
|
29202
|
+
}
|
|
29203
|
+
}
|
|
29204
|
+
}
|
|
29205
|
+
} else if (message.type === "user") {
|
|
29206
|
+
const content = message?.message?.content;
|
|
29207
|
+
if (!Array.isArray(content)) continue;
|
|
29208
|
+
for (const block of content) {
|
|
29209
|
+
if (!block || typeof block !== "object" || block.type !== "tool_result") continue;
|
|
29210
|
+
const id = String(block.tool_use_id ?? "").trim();
|
|
29211
|
+
if (id) resolved.add(id);
|
|
29212
|
+
}
|
|
29213
|
+
}
|
|
29214
|
+
}
|
|
29215
|
+
const dangling = Array.from(used).filter((id) => !resolved.has(id));
|
|
29216
|
+
if (dangling.length === 0) {
|
|
29217
|
+
return { messages, detected: 0, closed: 0 };
|
|
29218
|
+
}
|
|
29219
|
+
const closures = dangling.map((id) => buildDanglingClosureMessage(id));
|
|
29220
|
+
return {
|
|
29221
|
+
messages: [...messages, ...closures],
|
|
29222
|
+
detected: dangling.length,
|
|
29223
|
+
closed: closures.length
|
|
29224
|
+
};
|
|
29225
|
+
}
|
|
29226
|
+
function applyToolOutputLifecycle(messages, options) {
|
|
29227
|
+
const l3AgeTurns = Math.max(
|
|
29228
|
+
options.maxAgeTurns + 1,
|
|
29229
|
+
options.l3AgeTurns ?? Math.max(options.maxAgeTurns + 2, 6)
|
|
29230
|
+
);
|
|
29231
|
+
const l1MinChars = Math.max(120, options.l1MinChars ?? 500);
|
|
29232
|
+
const l3MinChars = Math.max(l1MinChars, options.l3MinChars ?? 1800);
|
|
29233
|
+
const shouldCloseDangling = options.closeDanglingToolUseBeforeReplay ?? true;
|
|
29234
|
+
const closureResult = shouldCloseDangling ? closeDanglingToolUseBeforeReplay(messages) : { messages, detected: 0, closed: 0 };
|
|
29235
|
+
const messagesForAging = closureResult.messages;
|
|
29236
|
+
const beforeTokens = estimateMessagesTokens(messagesForAging);
|
|
29237
|
+
const totalToolResultBlocksBefore = countToolResultBlocks(messagesForAging);
|
|
29238
|
+
if (!options.enabled) {
|
|
29239
|
+
return {
|
|
29240
|
+
messages: messagesForAging,
|
|
29241
|
+
report: {
|
|
29242
|
+
applied: false,
|
|
29243
|
+
agedBlocks: 0,
|
|
29244
|
+
skippedFailedBlocks: 0,
|
|
29245
|
+
protectedBlocks: 0,
|
|
29246
|
+
totalToolResultBlocksBefore,
|
|
29247
|
+
totalToolResultBlocksAfter: totalToolResultBlocksBefore,
|
|
29248
|
+
l1Blocks: 0,
|
|
29249
|
+
l2Blocks: 0,
|
|
29250
|
+
l3Blocks: 0,
|
|
29251
|
+
danglingDetected: closureResult.detected,
|
|
29252
|
+
danglingClosed: closureResult.closed,
|
|
29253
|
+
beforeTokens,
|
|
29254
|
+
afterTokens: beforeTokens,
|
|
29255
|
+
tokenDelta: 0
|
|
29256
|
+
}
|
|
29257
|
+
};
|
|
29258
|
+
}
|
|
29259
|
+
const naturalTurnsAfter = new Array(messagesForAging.length).fill(0);
|
|
29260
|
+
let runningTurns = 0;
|
|
29261
|
+
for (let i = messagesForAging.length - 1; i >= 0; i -= 1) {
|
|
29262
|
+
naturalTurnsAfter[i] = runningTurns;
|
|
29263
|
+
if (isNaturalUserMessage(messagesForAging[i])) {
|
|
29264
|
+
runningTurns += 1;
|
|
29265
|
+
}
|
|
29266
|
+
}
|
|
29267
|
+
let agedBlocks = 0;
|
|
29268
|
+
let skippedFailedBlocks = 0;
|
|
29269
|
+
let protectedBlocks = 0;
|
|
29270
|
+
let l1Blocks = 0;
|
|
29271
|
+
let l2Blocks = 0;
|
|
29272
|
+
let l3Blocks = 0;
|
|
29273
|
+
const nextMessages = messagesForAging.map((message, index) => {
|
|
29274
|
+
if (message.type !== "user") return message;
|
|
29275
|
+
const content = message?.message?.content;
|
|
29276
|
+
if (!Array.isArray(content)) return message;
|
|
29277
|
+
let changed = false;
|
|
29278
|
+
const nextContent = content.map((block) => {
|
|
29279
|
+
if (!block || typeof block !== "object" || block.type !== "tool_result") {
|
|
29280
|
+
return block;
|
|
29281
|
+
}
|
|
29282
|
+
const ageTurns = naturalTurnsAfter[index];
|
|
29283
|
+
if (ageTurns <= options.maxAgeTurns) {
|
|
29284
|
+
return block;
|
|
29285
|
+
}
|
|
29286
|
+
const isError = Boolean(block.is_error);
|
|
29287
|
+
if (isError && ageTurns <= options.protectFailedResultTurns) {
|
|
29288
|
+
skippedFailedBlocks += 1;
|
|
29289
|
+
return block;
|
|
29290
|
+
}
|
|
29291
|
+
const rawText = typeof block.content === "string" ? block.content : Array.isArray(block.content) ? block.content.filter(
|
|
29292
|
+
(item) => item && typeof item === "object" && item.type === "text"
|
|
29293
|
+
).map((item) => String(item.text ?? "")).join("\n") : "";
|
|
29294
|
+
const signals = extractLifecycleSignals(rawText);
|
|
29295
|
+
const status = extractStatusSignal(rawText);
|
|
29296
|
+
const normalizedSignals = signals.length > 0 ? signals : ["targets: none", "keyFacts: none", "errors: none"];
|
|
29297
|
+
let lifecycleLevel = "L2";
|
|
29298
|
+
if (ageTurns >= l3AgeTurns && rawText.length >= l3MinChars) {
|
|
29299
|
+
lifecycleLevel = "L3";
|
|
29300
|
+
} else if (rawText.length >= l1MinChars) {
|
|
29301
|
+
lifecycleLevel = "L1";
|
|
29302
|
+
}
|
|
29303
|
+
const placeholder = (lifecycleLevel === "L3" ? [
|
|
29304
|
+
"[Tool output aged]",
|
|
29305
|
+
"lifecycleLevel: L3",
|
|
29306
|
+
`toolUseId: ${String(block.tool_use_id ?? "")}`,
|
|
29307
|
+
`ageTurns: ${ageTurns}`,
|
|
29308
|
+
status,
|
|
29309
|
+
...normalizedSignals,
|
|
29310
|
+
"content: audit-index-only"
|
|
29311
|
+
] : lifecycleLevel === "L1" ? [
|
|
29312
|
+
"[Tool output aged]",
|
|
29313
|
+
"lifecycleLevel: L1",
|
|
29314
|
+
`ageTurns: ${ageTurns}`,
|
|
29315
|
+
status,
|
|
29316
|
+
...normalizedSignals,
|
|
29317
|
+
"content: summarized"
|
|
29318
|
+
] : [
|
|
29319
|
+
"[Tool output aged]",
|
|
29320
|
+
"lifecycleLevel: L2",
|
|
29321
|
+
`ageTurns: ${ageTurns}`,
|
|
29322
|
+
status,
|
|
29323
|
+
...normalizedSignals,
|
|
29324
|
+
"content: placeholder"
|
|
29325
|
+
]).join("\n");
|
|
29326
|
+
changed = true;
|
|
29327
|
+
agedBlocks += 1;
|
|
29328
|
+
protectedBlocks += signals.length;
|
|
29329
|
+
if (lifecycleLevel === "L1") l1Blocks += 1;
|
|
29330
|
+
if (lifecycleLevel === "L2") l2Blocks += 1;
|
|
29331
|
+
if (lifecycleLevel === "L3") l3Blocks += 1;
|
|
29332
|
+
return {
|
|
29333
|
+
...block,
|
|
29334
|
+
content: placeholder,
|
|
29335
|
+
metadata: {
|
|
29336
|
+
...block.metadata && typeof block.metadata === "object" ? block.metadata : {},
|
|
29337
|
+
lifecycleAged: true,
|
|
29338
|
+
ageTurns,
|
|
29339
|
+
lifecycleLevel
|
|
29340
|
+
}
|
|
29341
|
+
};
|
|
29342
|
+
});
|
|
29343
|
+
if (!changed) return message;
|
|
29344
|
+
return {
|
|
29345
|
+
...message,
|
|
29346
|
+
message: {
|
|
29347
|
+
...message.message,
|
|
29348
|
+
content: nextContent
|
|
29349
|
+
}
|
|
29350
|
+
};
|
|
29351
|
+
});
|
|
29352
|
+
return {
|
|
29353
|
+
messages: nextMessages,
|
|
29354
|
+
report: {
|
|
29355
|
+
applied: true,
|
|
29356
|
+
agedBlocks,
|
|
29357
|
+
skippedFailedBlocks,
|
|
29358
|
+
protectedBlocks,
|
|
29359
|
+
totalToolResultBlocksBefore,
|
|
29360
|
+
totalToolResultBlocksAfter: countToolResultBlocks(nextMessages),
|
|
29361
|
+
l1Blocks,
|
|
29362
|
+
l2Blocks,
|
|
29363
|
+
l3Blocks,
|
|
29364
|
+
danglingDetected: closureResult.detected,
|
|
29365
|
+
danglingClosed: closureResult.closed,
|
|
29366
|
+
beforeTokens,
|
|
29367
|
+
afterTokens: estimateMessagesTokens(nextMessages),
|
|
29368
|
+
tokenDelta: Math.max(
|
|
29369
|
+
0,
|
|
29370
|
+
beforeTokens - estimateMessagesTokens(nextMessages)
|
|
29371
|
+
)
|
|
29372
|
+
}
|
|
29373
|
+
};
|
|
29374
|
+
}
|
|
29375
|
+
|
|
29376
|
+
// src/utils/session/threeLayerRollout.ts
|
|
29377
|
+
function parseBooleanFlag4(value) {
|
|
29378
|
+
const raw = String(value ?? "").trim().toLowerCase();
|
|
29379
|
+
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
29380
|
+
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
29381
|
+
return null;
|
|
29382
|
+
}
|
|
29383
|
+
function parsePercent(value) {
|
|
29384
|
+
const parsed = Number(value);
|
|
29385
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
29386
|
+
return Math.min(100, Math.max(0, parsed));
|
|
29387
|
+
}
|
|
29388
|
+
function parsePositiveInteger(value) {
|
|
29389
|
+
const parsed = Number(value);
|
|
29390
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
29391
|
+
return Math.max(1, Math.floor(parsed));
|
|
29392
|
+
}
|
|
29393
|
+
function parseNonNegativeInteger(value) {
|
|
29394
|
+
const parsed = Number(value);
|
|
29395
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
29396
|
+
return Math.max(0, Math.floor(parsed));
|
|
29397
|
+
}
|
|
29398
|
+
function parseRolloutStage(value) {
|
|
29399
|
+
const normalized = String(value ?? "").trim().toLowerCase();
|
|
29400
|
+
if (normalized === "stage_10") return "stage_10";
|
|
29401
|
+
if (normalized === "stage_30") return "stage_30";
|
|
29402
|
+
if (normalized === "stage_100") return "stage_100";
|
|
29403
|
+
return void 0;
|
|
29404
|
+
}
|
|
29405
|
+
function stageToPercent(stage) {
|
|
29406
|
+
if (stage === "stage_10") return 10;
|
|
29407
|
+
if (stage === "stage_30") return 30;
|
|
29408
|
+
return 100;
|
|
29409
|
+
}
|
|
29410
|
+
function promoteStage(stage) {
|
|
29411
|
+
if (stage === "stage_10") return "stage_30";
|
|
29412
|
+
if (stage === "stage_30") return "stage_100";
|
|
29413
|
+
return "stage_100";
|
|
29414
|
+
}
|
|
29415
|
+
function rollbackStage(stage) {
|
|
29416
|
+
if (stage === "stage_100") return "stage_30";
|
|
29417
|
+
if (stage === "stage_30") return "stage_10";
|
|
29418
|
+
return "stage_10";
|
|
29419
|
+
}
|
|
29420
|
+
function evaluateThreeLayerRolloutStageDecision(input) {
|
|
29421
|
+
if (!input.rolloutEnabled) {
|
|
29422
|
+
return {
|
|
29423
|
+
nextStage: input.currentStage,
|
|
29424
|
+
decision: "keep",
|
|
29425
|
+
reason: "rollout_disabled"
|
|
29426
|
+
};
|
|
29427
|
+
}
|
|
29428
|
+
if (!input.autoControllerEnabled) {
|
|
29429
|
+
return {
|
|
29430
|
+
nextStage: input.currentStage,
|
|
29431
|
+
decision: "keep",
|
|
29432
|
+
reason: "threshold_not_met"
|
|
29433
|
+
};
|
|
29434
|
+
}
|
|
29435
|
+
if (input.consecutiveUnhealthyWindows >= input.maxUnhealthyWindowsForRollback && input.currentStage !== "stage_10") {
|
|
29436
|
+
return {
|
|
29437
|
+
nextStage: rollbackStage(input.currentStage),
|
|
29438
|
+
decision: "rollback",
|
|
29439
|
+
reason: "unhealthy_window_rollback"
|
|
29440
|
+
};
|
|
29441
|
+
}
|
|
29442
|
+
if (input.consecutiveHealthyWindows >= input.minHealthyWindowsForPromote && input.currentStage !== "stage_100") {
|
|
29443
|
+
return {
|
|
29444
|
+
nextStage: promoteStage(input.currentStage),
|
|
29445
|
+
decision: "promote",
|
|
29446
|
+
reason: "healthy_window_promote"
|
|
29447
|
+
};
|
|
29448
|
+
}
|
|
29449
|
+
return {
|
|
29450
|
+
nextStage: input.currentStage,
|
|
29451
|
+
decision: "keep",
|
|
29452
|
+
reason: "threshold_not_met"
|
|
29453
|
+
};
|
|
29454
|
+
}
|
|
29455
|
+
function hashToBucket(value) {
|
|
29456
|
+
let hash = 2166136261;
|
|
29457
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
29458
|
+
hash ^= value.charCodeAt(i);
|
|
29459
|
+
hash = Math.imul(hash, 16777619);
|
|
29460
|
+
}
|
|
29461
|
+
return Math.abs(hash >>> 0) % 100;
|
|
29462
|
+
}
|
|
29463
|
+
function resolveThreeLayerRolloutFlags(toolUseContext, options) {
|
|
29464
|
+
const rolloutEnabledEnv = parseBooleanFlag4(
|
|
29465
|
+
process.env.PYB_THREE_LAYER_ROLLOUT_ENABLED
|
|
29466
|
+
);
|
|
29467
|
+
const rolloutEnabledContext = typeof toolUseContext?.threeLayerRolloutEnabled === "boolean" ? toolUseContext.threeLayerRolloutEnabled : void 0;
|
|
29468
|
+
const rolloutEnabled = rolloutEnabledEnv !== null ? rolloutEnabledEnv : rolloutEnabledContext ?? false;
|
|
29469
|
+
const rolloutStageEnv = parseRolloutStage(process.env.PYB_THREE_LAYER_ROLLOUT_STAGE);
|
|
29470
|
+
const rolloutStageContext = parseRolloutStage(toolUseContext?.threeLayerRolloutStage);
|
|
29471
|
+
const rolloutStageInput = rolloutStageEnv ?? rolloutStageContext ?? "stage_100";
|
|
29472
|
+
const autoControllerEnabledEnv = parseBooleanFlag4(
|
|
29473
|
+
process.env.PYB_THREE_LAYER_ROLLOUT_AUTO_CONTROLLER_ENABLED
|
|
29474
|
+
);
|
|
29475
|
+
const autoControllerEnabledContext = typeof toolUseContext?.threeLayerRolloutAutoControllerEnabled === "boolean" ? toolUseContext.threeLayerRolloutAutoControllerEnabled : void 0;
|
|
29476
|
+
const autoControllerEnabled = autoControllerEnabledEnv !== null ? autoControllerEnabledEnv : autoControllerEnabledContext ?? false;
|
|
29477
|
+
const consecutiveHealthyWindows = parseNonNegativeInteger(
|
|
29478
|
+
toolUseContext?.threeLayerRolloutConsecutiveHealthyWindows
|
|
29479
|
+
) ?? 0;
|
|
29480
|
+
const consecutiveUnhealthyWindows = parseNonNegativeInteger(
|
|
29481
|
+
toolUseContext?.threeLayerRolloutConsecutiveUnhealthyWindows
|
|
29482
|
+
) ?? 0;
|
|
29483
|
+
const minHealthyWindowsForPromote = parsePositiveInteger(
|
|
29484
|
+
toolUseContext?.threeLayerRolloutMinHealthyWindowsForPromote ?? process.env.PYB_THREE_LAYER_ROLLOUT_MIN_HEALTHY_WINDOWS
|
|
29485
|
+
) ?? 2;
|
|
29486
|
+
const maxUnhealthyWindowsForRollback = parsePositiveInteger(
|
|
29487
|
+
toolUseContext?.threeLayerRolloutMaxUnhealthyWindowsForRollback ?? process.env.PYB_THREE_LAYER_ROLLOUT_MAX_UNHEALTHY_WINDOWS
|
|
29488
|
+
) ?? 2;
|
|
29489
|
+
const stageDecision = evaluateThreeLayerRolloutStageDecision({
|
|
29490
|
+
rolloutEnabled,
|
|
29491
|
+
currentStage: rolloutStageInput,
|
|
29492
|
+
autoControllerEnabled,
|
|
29493
|
+
consecutiveHealthyWindows,
|
|
29494
|
+
consecutiveUnhealthyWindows,
|
|
29495
|
+
minHealthyWindowsForPromote,
|
|
29496
|
+
maxUnhealthyWindowsForRollback
|
|
29497
|
+
});
|
|
29498
|
+
const rolloutStage = stageDecision.nextStage;
|
|
29499
|
+
const rolloutDecision = stageDecision.decision;
|
|
29500
|
+
const rolloutReason = stageDecision.reason;
|
|
29501
|
+
const rolloutPercent = parsePercent(process.env.PYB_THREE_LAYER_ROLLOUT_PERCENT) ?? parsePercent(toolUseContext?.threeLayerRolloutPercent) ?? stageToPercent(rolloutStage);
|
|
29502
|
+
const rolloutKey = String(
|
|
29503
|
+
options?.requestId || toolUseContext?.options?.messageLogName || toolUseContext?.agentId || "global"
|
|
29504
|
+
);
|
|
29505
|
+
const rolloutBucket = hashToBucket(rolloutKey);
|
|
29506
|
+
const rolloutActive = rolloutEnabled && rolloutBucket < rolloutPercent;
|
|
29507
|
+
const typedWriteExplicitEnv = parseBooleanFlag4(
|
|
29508
|
+
process.env.PYB_TYPED_SESSION_WRITE_ENABLED
|
|
29509
|
+
);
|
|
29510
|
+
const typedWriteExplicitContext = typeof toolUseContext?.typedSessionWriteEnabled === "boolean" ? toolUseContext.typedSessionWriteEnabled : void 0;
|
|
29511
|
+
const boundaryExplicitEnv = parseBooleanFlag4(
|
|
29512
|
+
process.env.PYB_COMPACTION_BOUNDARY_ENABLED
|
|
29513
|
+
);
|
|
29514
|
+
const boundaryExplicitContext = typeof toolUseContext?.compactionBoundaryEnabled === "boolean" ? toolUseContext.compactionBoundaryEnabled : void 0;
|
|
29515
|
+
const lifecycleExplicitEnv = parseBooleanFlag4(
|
|
29516
|
+
process.env.PYB_TOOL_OUTPUT_LIFECYCLE_ENABLED
|
|
29517
|
+
);
|
|
29518
|
+
const lifecycleExplicitContext = typeof toolUseContext?.toolOutputLifecycleEnabled === "boolean" ? toolUseContext.toolOutputLifecycleEnabled : void 0;
|
|
29519
|
+
const typedSessionWriteEnabled = typedWriteExplicitEnv !== null ? typedWriteExplicitEnv : typedWriteExplicitContext ?? (rolloutEnabled ? rolloutActive : true);
|
|
29520
|
+
const compactionBoundaryEnabled = boundaryExplicitEnv !== null ? boundaryExplicitEnv : boundaryExplicitContext ?? (rolloutEnabled ? rolloutActive : false);
|
|
29521
|
+
const toolOutputLifecycleEnabled = lifecycleExplicitEnv !== null ? lifecycleExplicitEnv : lifecycleExplicitContext ?? (rolloutEnabled ? rolloutActive : false);
|
|
29522
|
+
return {
|
|
29523
|
+
typedSessionWriteEnabled,
|
|
29524
|
+
compactionBoundaryEnabled,
|
|
29525
|
+
toolOutputLifecycleEnabled,
|
|
29526
|
+
rolloutEnabled,
|
|
29527
|
+
rolloutPercent,
|
|
29528
|
+
rolloutBucket,
|
|
29529
|
+
rolloutStage,
|
|
29530
|
+
rolloutDecision,
|
|
29531
|
+
rolloutReason
|
|
29532
|
+
};
|
|
29533
|
+
}
|
|
29534
|
+
|
|
29535
|
+
// src/utils/session/toolOutputLifecycleMetricsDraft.ts
|
|
29536
|
+
function safeRate(numerator, denominator) {
|
|
29537
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator) || denominator <= 0) {
|
|
29538
|
+
return 0;
|
|
29539
|
+
}
|
|
29540
|
+
return Math.max(0, Math.min(1, numerator / denominator));
|
|
29541
|
+
}
|
|
29542
|
+
function buildToolOutputLifecyclePreGateMetrics(samples) {
|
|
29543
|
+
const normalized = Array.isArray(samples) ? samples : [];
|
|
29544
|
+
let totalToolResultBlocksBefore = 0;
|
|
29545
|
+
let totalAgedBlocks = 0;
|
|
29546
|
+
let totalPlaceholderBlocks = 0;
|
|
29547
|
+
let totalBeforeTokens = 0;
|
|
29548
|
+
let totalTokenDelta = 0;
|
|
29549
|
+
let totalDanglingDetected = 0;
|
|
29550
|
+
let totalDanglingClosed = 0;
|
|
29551
|
+
let w11Total = 0;
|
|
29552
|
+
let w11Passed = 0;
|
|
29553
|
+
let w14Total = 0;
|
|
29554
|
+
let w14Passed = 0;
|
|
29555
|
+
for (const sample2 of normalized) {
|
|
29556
|
+
const report = sample2?.report ?? {};
|
|
29557
|
+
const toolResultBefore = Number(report.totalToolResultBlocksBefore ?? 0);
|
|
29558
|
+
const aged = Number(report.agedBlocks ?? 0);
|
|
29559
|
+
const l2 = Number(report.l2Blocks ?? 0);
|
|
29560
|
+
const l3 = Number(report.l3Blocks ?? 0);
|
|
29561
|
+
const danglingDetected = Number(report.danglingDetected ?? 0);
|
|
29562
|
+
const danglingClosed = Number(report.danglingClosed ?? 0);
|
|
29563
|
+
const beforeTokens = Number(report.beforeTokens ?? 0);
|
|
29564
|
+
const tokenDelta = Number(report.tokenDelta ?? 0);
|
|
29565
|
+
totalToolResultBlocksBefore += Number.isFinite(toolResultBefore) ? toolResultBefore : 0;
|
|
29566
|
+
totalAgedBlocks += Number.isFinite(aged) ? aged : 0;
|
|
29567
|
+
totalPlaceholderBlocks += Number.isFinite(l2 + l3) ? l2 + l3 : 0;
|
|
29568
|
+
totalBeforeTokens += Number.isFinite(beforeTokens) ? beforeTokens : 0;
|
|
29569
|
+
totalTokenDelta += Number.isFinite(tokenDelta) ? tokenDelta : 0;
|
|
29570
|
+
totalDanglingDetected += Number.isFinite(danglingDetected) ? danglingDetected : 0;
|
|
29571
|
+
totalDanglingClosed += Number.isFinite(danglingClosed) ? danglingClosed : 0;
|
|
29572
|
+
const sampleId = String(sample2?.sampleId ?? "").trim().toUpperCase();
|
|
29573
|
+
if (sampleId === "W11") {
|
|
29574
|
+
w11Total += 1;
|
|
29575
|
+
if (aged > 0 && tokenDelta > 0) {
|
|
29576
|
+
w11Passed += 1;
|
|
29577
|
+
}
|
|
29578
|
+
}
|
|
29579
|
+
if (sampleId === "W14") {
|
|
29580
|
+
w14Total += 1;
|
|
29581
|
+
if (danglingDetected > 0 && danglingClosed >= danglingDetected) {
|
|
29582
|
+
w14Passed += 1;
|
|
29583
|
+
}
|
|
29584
|
+
}
|
|
29585
|
+
}
|
|
29586
|
+
return {
|
|
29587
|
+
samples: normalized.length,
|
|
29588
|
+
tool_output_aging_hit_rate: safeRate(
|
|
29589
|
+
totalAgedBlocks,
|
|
29590
|
+
totalToolResultBlocksBefore
|
|
29591
|
+
),
|
|
29592
|
+
tool_output_placeholder_hit_rate: safeRate(
|
|
29593
|
+
totalPlaceholderBlocks,
|
|
29594
|
+
totalAgedBlocks || 1
|
|
29595
|
+
),
|
|
29596
|
+
tool_output_token_reduction_rate: safeRate(totalTokenDelta, totalBeforeTokens),
|
|
29597
|
+
dangling_tool_closure_rate: safeRate(totalDanglingClosed, totalDanglingDetected || 1),
|
|
29598
|
+
w11_sample_pass_rate: safeRate(w11Passed, w11Total || 1),
|
|
29599
|
+
w14_sample_pass_rate: safeRate(w14Passed, w14Total || 1)
|
|
29600
|
+
};
|
|
29601
|
+
}
|
|
29602
|
+
|
|
28690
29603
|
// src/services/telemetry/autoCompactTelemetryPersistence.ts
|
|
28691
29604
|
import { appendFileSync as appendFileSync2, existsSync as existsSync19, mkdirSync as mkdirSync8 } from "fs";
|
|
28692
29605
|
import { dirname as dirname10 } from "path";
|
|
@@ -28986,18 +29899,75 @@ async function queryWithBinaryFeedback(toolUseContext, getAssistantResponse, get
|
|
|
28986
29899
|
}
|
|
28987
29900
|
async function* query(messages, systemPrompt, context, canUseTool, toolUseContext, getBinaryFeedbackResponse) {
|
|
28988
29901
|
const shouldPersistSession = toolUseContext.options?.persistSession !== false && process.env.NODE_ENV !== "test";
|
|
28989
|
-
|
|
28990
|
-
|
|
28991
|
-
|
|
28992
|
-
|
|
28993
|
-
|
|
28994
|
-
|
|
28995
|
-
|
|
28996
|
-
))
|
|
28997
|
-
|
|
28998
|
-
|
|
29902
|
+
const typedRequestId = (() => {
|
|
29903
|
+
const currentRequestId = getCurrentRequest()?.id;
|
|
29904
|
+
if (currentRequestId) return `query_${currentRequestId}`;
|
|
29905
|
+
const lastUser = [...messages].reverse().find((item) => item?.type === "user" && item?.queryId);
|
|
29906
|
+
const fallbackQueryId = lastUser?.queryId;
|
|
29907
|
+
if (fallbackQueryId) return `query_${fallbackQueryId}`;
|
|
29908
|
+
return `query_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
29909
|
+
})();
|
|
29910
|
+
const modelPointer = toolUseContext.options.model || "main";
|
|
29911
|
+
const modelResolution = getModelManager().resolveModelWithInfo(modelPointer);
|
|
29912
|
+
const typedProvider = modelResolution.success ? String(modelResolution.profile?.provider ?? "").trim().toLowerCase() : "unknown";
|
|
29913
|
+
const typedProjector = createStreamTypedProjector({
|
|
29914
|
+
requestId: typedRequestId,
|
|
29915
|
+
source: "query_main",
|
|
29916
|
+
provider: typedProvider
|
|
29917
|
+
});
|
|
29918
|
+
const rolloutFlags = resolveThreeLayerRolloutFlags(toolUseContext, {
|
|
29919
|
+
requestId: getCurrentRequest()?.id ?? typedRequestId
|
|
29920
|
+
});
|
|
29921
|
+
const shouldPersistTypedSession = shouldPersistSession && rolloutFlags.typedSessionWriteEnabled;
|
|
29922
|
+
logUserFriendly("THREE_LAYER_ROLLOUT_APPLIED", {
|
|
29923
|
+
enabled: rolloutFlags.rolloutEnabled,
|
|
29924
|
+
stage: rolloutFlags.rolloutStage,
|
|
29925
|
+
decision: rolloutFlags.rolloutDecision,
|
|
29926
|
+
reason: rolloutFlags.rolloutReason,
|
|
29927
|
+
percent: rolloutFlags.rolloutPercent,
|
|
29928
|
+
bucket: rolloutFlags.rolloutBucket,
|
|
29929
|
+
typedSessionWriteEnabled: rolloutFlags.typedSessionWriteEnabled,
|
|
29930
|
+
compactionBoundaryEnabled: rolloutFlags.compactionBoundaryEnabled,
|
|
29931
|
+
toolOutputLifecycleEnabled: rolloutFlags.toolOutputLifecycleEnabled
|
|
29932
|
+
});
|
|
29933
|
+
if (typeof toolUseContext.compactionBoundaryEnabled !== "boolean") {
|
|
29934
|
+
toolUseContext.compactionBoundaryEnabled = rolloutFlags.compactionBoundaryEnabled;
|
|
29935
|
+
}
|
|
29936
|
+
if (typeof toolUseContext.toolOutputLifecycleEnabled !== "boolean") {
|
|
29937
|
+
toolUseContext.toolOutputLifecycleEnabled = rolloutFlags.toolOutputLifecycleEnabled;
|
|
29938
|
+
}
|
|
29939
|
+
try {
|
|
29940
|
+
for await (const message of queryCore(
|
|
29941
|
+
messages,
|
|
29942
|
+
systemPrompt,
|
|
29943
|
+
context,
|
|
29944
|
+
canUseTool,
|
|
29945
|
+
toolUseContext,
|
|
29946
|
+
getBinaryFeedbackResponse
|
|
29947
|
+
)) {
|
|
29948
|
+
if (shouldPersistSession) {
|
|
29949
|
+
appendSessionJsonlFromMessage({ message, toolUseContext });
|
|
29950
|
+
}
|
|
29951
|
+
if (shouldPersistTypedSession) {
|
|
29952
|
+
const parts = projectMessageToTypedParts(typedProjector, message);
|
|
29953
|
+
for (const part of parts) {
|
|
29954
|
+
emitTypedPart({ requestId: typedRequestId, part });
|
|
29955
|
+
}
|
|
29956
|
+
}
|
|
29957
|
+
yield message;
|
|
29958
|
+
}
|
|
29959
|
+
} finally {
|
|
29960
|
+
if (shouldPersistTypedSession) {
|
|
29961
|
+
flushTypedPartBuffer({ requestId: typedRequestId });
|
|
29962
|
+
const compatibilityMetrics = consumeProjectorCompatibilityMetrics(typedProjector);
|
|
29963
|
+
logUserFriendly("STREAM_TYPED_PROVIDER_COMPATIBILITY", {
|
|
29964
|
+
requestId: typedRequestId,
|
|
29965
|
+
provider: compatibilityMetrics.provider,
|
|
29966
|
+
supportsRichToolResult: compatibilityMetrics.supportsRichToolResult,
|
|
29967
|
+
richToolResultBlockCount: compatibilityMetrics.richToolResultBlockCount,
|
|
29968
|
+
downgradedToolResultCount: compatibilityMetrics.downgradedToolResultCount
|
|
29969
|
+
});
|
|
28999
29970
|
}
|
|
29000
|
-
yield message;
|
|
29001
29971
|
}
|
|
29002
29972
|
}
|
|
29003
29973
|
async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseContext, getBinaryFeedbackResponse, hookState) {
|
|
@@ -29036,6 +30006,76 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
29036
30006
|
if (wasCompacted) {
|
|
29037
30007
|
messages = processedMessages;
|
|
29038
30008
|
}
|
|
30009
|
+
const boundaryConfig = resolveCompactionBoundaryConfig(toolUseContext);
|
|
30010
|
+
const boundaryResult = filterAfterCompactionBoundary(messages, {
|
|
30011
|
+
enabled: boundaryConfig.enabled
|
|
30012
|
+
});
|
|
30013
|
+
messages = boundaryResult.messages;
|
|
30014
|
+
if (boundaryConfig.enabled) {
|
|
30015
|
+
logUserFriendly("COMPACTION_BOUNDARY_APPLIED", {
|
|
30016
|
+
source: boundaryConfig.source,
|
|
30017
|
+
applied: boundaryResult.applied,
|
|
30018
|
+
droppedMessageCount: boundaryResult.droppedMessageCount,
|
|
30019
|
+
preservedMessageCount: boundaryResult.preservedMessageCount,
|
|
30020
|
+
lastCompactionIndex: boundaryResult.lastCompactionIndex,
|
|
30021
|
+
replayMode: boundaryResult.replayMode
|
|
30022
|
+
});
|
|
30023
|
+
emitAutoCompactTelemetryEvent("COMPACTION_BOUNDARY_APPLIED", {
|
|
30024
|
+
source: boundaryConfig.source,
|
|
30025
|
+
applied: boundaryResult.applied,
|
|
30026
|
+
droppedMessageCount: boundaryResult.droppedMessageCount,
|
|
30027
|
+
preservedMessageCount: boundaryResult.preservedMessageCount,
|
|
30028
|
+
lastCompactionIndex: boundaryResult.lastCompactionIndex,
|
|
30029
|
+
replayMode: boundaryResult.replayMode
|
|
30030
|
+
});
|
|
30031
|
+
}
|
|
30032
|
+
const lifecycleConfig = resolveToolOutputLifecycleConfig(toolUseContext);
|
|
30033
|
+
const lifecycleResult = applyToolOutputLifecycle(messages, {
|
|
30034
|
+
enabled: lifecycleConfig.enabled,
|
|
30035
|
+
maxAgeTurns: lifecycleConfig.maxAgeTurns,
|
|
30036
|
+
protectFailedResultTurns: lifecycleConfig.protectFailedResultTurns,
|
|
30037
|
+
l3AgeTurns: lifecycleConfig.l3AgeTurns,
|
|
30038
|
+
l1MinChars: lifecycleConfig.l1MinChars,
|
|
30039
|
+
l3MinChars: lifecycleConfig.l3MinChars
|
|
30040
|
+
});
|
|
30041
|
+
messages = lifecycleResult.messages;
|
|
30042
|
+
if (lifecycleConfig.enabled) {
|
|
30043
|
+
logUserFriendly("TOOL_OUTPUT_LIFECYCLE_APPLIED", {
|
|
30044
|
+
source: lifecycleConfig.source,
|
|
30045
|
+
applied: lifecycleResult.report.applied,
|
|
30046
|
+
agedBlocks: lifecycleResult.report.agedBlocks,
|
|
30047
|
+
skippedFailedBlocks: lifecycleResult.report.skippedFailedBlocks,
|
|
30048
|
+
protectedBlocks: lifecycleResult.report.protectedBlocks,
|
|
30049
|
+
l1Blocks: lifecycleResult.report.l1Blocks,
|
|
30050
|
+
l2Blocks: lifecycleResult.report.l2Blocks,
|
|
30051
|
+
l3Blocks: lifecycleResult.report.l3Blocks,
|
|
30052
|
+
beforeTokens: lifecycleResult.report.beforeTokens,
|
|
30053
|
+
afterTokens: lifecycleResult.report.afterTokens,
|
|
30054
|
+
tokenDelta: lifecycleResult.report.tokenDelta
|
|
30055
|
+
});
|
|
30056
|
+
if (lifecycleResult.report.agedBlocks > 0) {
|
|
30057
|
+
logUserFriendly("TOOL_OUTPUT_AGED", {
|
|
30058
|
+
agedBlocks: lifecycleResult.report.agedBlocks,
|
|
30059
|
+
l1Blocks: lifecycleResult.report.l1Blocks,
|
|
30060
|
+
l2Blocks: lifecycleResult.report.l2Blocks,
|
|
30061
|
+
l3Blocks: lifecycleResult.report.l3Blocks
|
|
30062
|
+
});
|
|
30063
|
+
}
|
|
30064
|
+
if (lifecycleResult.report.l2Blocks > 0 || lifecycleResult.report.l3Blocks > 0) {
|
|
30065
|
+
logUserFriendly("TOOL_OUTPUT_PLACEHOLDER_APPLIED", {
|
|
30066
|
+
l2Blocks: lifecycleResult.report.l2Blocks,
|
|
30067
|
+
l3Blocks: lifecycleResult.report.l3Blocks
|
|
30068
|
+
});
|
|
30069
|
+
}
|
|
30070
|
+
const preGateMetrics = buildToolOutputLifecyclePreGateMetrics([
|
|
30071
|
+
{ sampleId: "W11", report: lifecycleResult.report },
|
|
30072
|
+
{ sampleId: "W14", report: lifecycleResult.report }
|
|
30073
|
+
]);
|
|
30074
|
+
logUserFriendly("TOOL_OUTPUT_LIFECYCLE_PRE_GATE_METRICS_DRAFT", {
|
|
30075
|
+
...preGateMetrics,
|
|
30076
|
+
source: lifecycleConfig.source
|
|
30077
|
+
});
|
|
30078
|
+
}
|
|
29039
30079
|
const tracker = getConversationTrackerForContext(toolUseContext);
|
|
29040
30080
|
const activeNaturalUserMessage = findNaturalUserMessageForParent(messages);
|
|
29041
30081
|
const activeQueryId = activeNaturalUserMessage?.queryId || activeNaturalUserMessage?.uuid;
|
|
@@ -29350,10 +30390,16 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
29350
30390
|
}
|
|
29351
30391
|
} finally {
|
|
29352
30392
|
const currentRequest = getCurrentRequest();
|
|
29353
|
-
flushAutoCompactTelemetrySnapshot({
|
|
30393
|
+
const telemetryRecord = flushAutoCompactTelemetrySnapshot({
|
|
29354
30394
|
requestId: currentRequest?.id,
|
|
29355
30395
|
agentId: toolUseContext?.agentId
|
|
29356
30396
|
});
|
|
30397
|
+
if (Number.isFinite(Number(telemetryRecord?.metrics?.typed_primary_path_rate))) {
|
|
30398
|
+
logUserFriendly("SESSION_READ_PATH_METRICS", {
|
|
30399
|
+
requestId: currentRequest?.id,
|
|
30400
|
+
typed_primary_path_rate: telemetryRecord?.metrics?.typed_primary_path_rate
|
|
30401
|
+
});
|
|
30402
|
+
}
|
|
29357
30403
|
setRequestStatus({ kind: "idle" });
|
|
29358
30404
|
}
|
|
29359
30405
|
}
|
|
@@ -30882,7 +31928,7 @@ import { homedir as homedir8 } from "os";
|
|
|
30882
31928
|
// src/commands/agents/generation.ts
|
|
30883
31929
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
30884
31930
|
async function generateAgentWithClaude(prompt) {
|
|
30885
|
-
const { queryModel } = await import("./llm-
|
|
31931
|
+
const { queryModel } = await import("./llm-Q23IAP4O.js");
|
|
30886
31932
|
const systemPrompt = `You are an expert at creating AI agent configurations. Based on the user's description, generate a specialized agent configuration.
|
|
30887
31933
|
|
|
30888
31934
|
Return your response as a JSON object with exactly these fields:
|