pybao-cli 1.5.4 → 1.5.6
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-S2UEVXWF.js +49 -0
- package/dist/{acp-IRGLAUUJ.js → acp-3KRM4YMC.js} +30 -30
- package/dist/{agentsValidate-JBJJ2EH7.js → agentsValidate-T6E3S4SD.js} +7 -7
- package/dist/{ask-WKLLFN55.js → ask-OT3N6WUV.js} +29 -29
- package/dist/{autoUpdater-UAC34Y6K.js → autoUpdater-MBTYMKZZ.js} +3 -3
- package/dist/{chunk-ATT3HCME.js → chunk-2DY7NKZY.js} +3 -3
- package/dist/{chunk-GL5OH6V4.js → chunk-33HCNVDW.js} +2 -2
- package/dist/{chunk-TBZGYEDP.js → chunk-5TPUQEB7.js} +3 -3
- package/dist/{chunk-M73XAOTH.js → chunk-63RVOHFS.js} +1 -1
- package/dist/{chunk-M73XAOTH.js.map → chunk-63RVOHFS.js.map} +1 -1
- package/dist/{chunk-KG3TWGBU.js → chunk-6MZDAIOV.js} +2 -2
- package/dist/{chunk-G3SWBGWN.js → chunk-AKLGEOKM.js} +172 -72
- package/dist/chunk-AKLGEOKM.js.map +7 -0
- package/dist/{chunk-IQV3HS22.js → chunk-BKG4N5U7.js} +1 -1
- package/dist/{chunk-MBM5WCIY.js → chunk-BRDQQ6DH.js} +2 -2
- package/dist/{chunk-XXDO6DFB.js → chunk-CXLPIXKP.js} +2 -2
- package/dist/{chunk-MWSQEKK6.js → chunk-DM2LV6T7.js} +4 -4
- package/dist/{chunk-A3NFY5TV.js → chunk-DTWSIMGF.js} +2 -2
- package/dist/{chunk-U5AY65EA.js → chunk-FZEVFEDH.js} +1 -1
- package/dist/{chunk-RHLNLOZP.js → chunk-GKFPN3PD.js} +1 -1
- package/dist/{chunk-2HK2IYZU.js → chunk-GPSHYLDR.js} +1 -1
- package/dist/{chunk-U76IVQIF.js → chunk-HV4AL2VG.js} +1 -1
- package/dist/{chunk-HLFRL66T.js → chunk-KO6ENKTQ.js} +3 -3
- package/dist/{chunk-6KR5MXW4.js → chunk-L3QFTUHN.js} +3 -3
- package/dist/{chunk-BJHBQUXH.js → chunk-LMTF4FXH.js} +2 -2
- package/dist/{chunk-PUBU44C2.js → chunk-MLZYATJX.js} +1 -1
- package/dist/{chunk-TI57KY6H.js → chunk-NM5GLMVH.js} +1 -1
- package/dist/{chunk-LKJJGCDP.js → chunk-PCSIH35L.js} +1 -1
- package/dist/{chunk-BVJZ6435.js → chunk-QD4OU22C.js} +3 -3
- package/dist/{chunk-RYALTDJI.js → chunk-RPIILAZ5.js} +4 -4
- package/dist/{chunk-A3WIVAEQ.js → chunk-SIE7VHSI.js} +1458 -301
- package/dist/chunk-SIE7VHSI.js.map +7 -0
- package/dist/{chunk-QJFAJORX.js → chunk-TN4TZY7G.js} +2 -2
- package/dist/{chunk-H744C3MH.js → chunk-VDIUCVWJ.js} +3 -3
- package/dist/{chunk-HCGBT46A.js → chunk-WTF7JOIQ.js} +4 -4
- package/dist/{chunk-Q64XH2HD.js → chunk-X7PDG4FB.js} +1 -1
- package/dist/{chunk-GUBKR5CU.js → chunk-YSZEGC2L.js} +3 -3
- package/dist/{chunk-QMQYRYOJ.js → chunk-ZUWPUBWZ.js} +1 -1
- package/dist/{chunk-SNLXXBXP.js → chunk-ZXUQALBB.js} +4 -4
- package/dist/{cli-UUU72LBP.js → cli-F65QNC6S.js} +89 -89
- package/dist/commands-A6WCP2T2.js +53 -0
- package/dist/{config-SKKYAIQT.js → config-TEBSBFSO.js} +4 -4
- package/dist/{context-VC4F6CQH.js → context-T5NFLTK4.js} +6 -6
- package/dist/{conversationTracker-2PRBUDU7.js → conversationTracker-ZUJHBMDH.js} +3 -3
- package/dist/{customCommands-KFSKRLOR.js → customCommands-TBZ5RMJ5.js} +4 -4
- package/dist/{env-UXRNUTRY.js → env-3LH2POC2.js} +2 -2
- package/dist/{file-YOLDPGAZ.js → file-O7PWWVFS.js} +4 -4
- package/dist/index.js +3 -3
- package/dist/{llm-NNPSCVNC.js → llm-OW7QDXPZ.js} +30 -30
- package/dist/{llmLazy-VFQBE4VQ.js → llmLazy-CCD2PHFB.js} +1 -1
- package/dist/{loader-JLKU56P4.js → loader-RBCHNZJW.js} +4 -4
- package/dist/{lsp-ODCSAM2C.js → lsp-WAD7S2GA.js} +6 -6
- package/dist/{lspAnchor-DRPDOTNI.js → lspAnchor-B5AR4FPG.js} +6 -6
- package/dist/{mcp-YNM5F6DI.js → mcp-5H5KKR2C.js} +7 -7
- package/dist/{mentionProcessor-XE5YX3QF.js → mentionProcessor-NK7NPMF2.js} +5 -5
- package/dist/{messages-S6CUVFAR.js → messages-DHHFMED7.js} +1 -1
- package/dist/{model-XRNLQZ4O.js → model-XWJ23WCS.js} +5 -5
- package/dist/{openai-JAWY3TYO.js → openai-WAGWEANY.js} +5 -5
- package/dist/{outputStyles-C2BALUUY.js → outputStyles-F6PPD3VU.js} +4 -4
- package/dist/{pluginRuntime-S7J5ODQU.js → pluginRuntime-BFIRISID.js} +6 -6
- package/dist/{pluginValidation-QTKM6IXY.js → pluginValidation-FDI5C7J7.js} +6 -6
- package/dist/prompts-XIY3JRPC.js +55 -0
- package/dist/{pybAgentSessionLoad-QONCGHTI.js → pybAgentSessionLoad-Z57EVSBX.js} +4 -4
- package/dist/{pybAgentSessionResume-2MIW4X3R.js → pybAgentSessionResume-74AWGCWV.js} +4 -4
- package/dist/{pybAgentStreamJsonSession-7IBCTJCI.js → pybAgentStreamJsonSession-HVWGJB4Q.js} +1 -1
- package/dist/{pybHooks-2FKUCMJD.js → pybHooks-FZYE52XG.js} +4 -4
- package/dist/query-JWT6DB4G.js +57 -0
- package/dist/{registry-OVP3MKFX.js → registry-FCKOLGU5.js} +5 -5
- package/dist/{ripgrep-KOL5M55E.js → ripgrep-MYG754KL.js} +3 -3
- package/dist/{skillMarketplace-XXVBYC57.js → skillMarketplace-B5UZC4ES.js} +3 -3
- package/dist/{state-CVENJNIV.js → state-SP4W7M4L.js} +2 -2
- package/dist/{theme-CV36XY2J.js → theme-OZAWAG6W.js} +5 -5
- package/dist/{toolPermissionSettings-MBBYIXDA.js → toolPermissionSettings-S2WBKN66.js} +6 -6
- package/dist/tools-UE2MORVX.js +54 -0
- package/dist/{userInput-JZQSTMJF.js → userInput-YJPISBP7.js} +31 -31
- package/package.json +1 -1
- package/dist/REPL-MBDNDVDD.js +0 -49
- package/dist/chunk-A3WIVAEQ.js.map +0 -7
- package/dist/chunk-G3SWBGWN.js.map +0 -7
- package/dist/commands-HN4V6NUM.js +0 -53
- package/dist/prompts-QVC7LLMH.js +0 -55
- package/dist/query-HUTD7BSB.js +0 -57
- package/dist/tools-2UQZG6N5.js +0 -54
- /package/dist/{REPL-MBDNDVDD.js.map → REPL-S2UEVXWF.js.map} +0 -0
- /package/dist/{acp-IRGLAUUJ.js.map → acp-3KRM4YMC.js.map} +0 -0
- /package/dist/{agentsValidate-JBJJ2EH7.js.map → agentsValidate-T6E3S4SD.js.map} +0 -0
- /package/dist/{ask-WKLLFN55.js.map → ask-OT3N6WUV.js.map} +0 -0
- /package/dist/{autoUpdater-UAC34Y6K.js.map → autoUpdater-MBTYMKZZ.js.map} +0 -0
- /package/dist/{chunk-ATT3HCME.js.map → chunk-2DY7NKZY.js.map} +0 -0
- /package/dist/{chunk-GL5OH6V4.js.map → chunk-33HCNVDW.js.map} +0 -0
- /package/dist/{chunk-TBZGYEDP.js.map → chunk-5TPUQEB7.js.map} +0 -0
- /package/dist/{chunk-KG3TWGBU.js.map → chunk-6MZDAIOV.js.map} +0 -0
- /package/dist/{chunk-IQV3HS22.js.map → chunk-BKG4N5U7.js.map} +0 -0
- /package/dist/{chunk-MBM5WCIY.js.map → chunk-BRDQQ6DH.js.map} +0 -0
- /package/dist/{chunk-XXDO6DFB.js.map → chunk-CXLPIXKP.js.map} +0 -0
- /package/dist/{chunk-MWSQEKK6.js.map → chunk-DM2LV6T7.js.map} +0 -0
- /package/dist/{chunk-A3NFY5TV.js.map → chunk-DTWSIMGF.js.map} +0 -0
- /package/dist/{chunk-U5AY65EA.js.map → chunk-FZEVFEDH.js.map} +0 -0
- /package/dist/{chunk-RHLNLOZP.js.map → chunk-GKFPN3PD.js.map} +0 -0
- /package/dist/{chunk-2HK2IYZU.js.map → chunk-GPSHYLDR.js.map} +0 -0
- /package/dist/{chunk-U76IVQIF.js.map → chunk-HV4AL2VG.js.map} +0 -0
- /package/dist/{chunk-HLFRL66T.js.map → chunk-KO6ENKTQ.js.map} +0 -0
- /package/dist/{chunk-6KR5MXW4.js.map → chunk-L3QFTUHN.js.map} +0 -0
- /package/dist/{chunk-BJHBQUXH.js.map → chunk-LMTF4FXH.js.map} +0 -0
- /package/dist/{chunk-PUBU44C2.js.map → chunk-MLZYATJX.js.map} +0 -0
- /package/dist/{chunk-TI57KY6H.js.map → chunk-NM5GLMVH.js.map} +0 -0
- /package/dist/{chunk-LKJJGCDP.js.map → chunk-PCSIH35L.js.map} +0 -0
- /package/dist/{chunk-BVJZ6435.js.map → chunk-QD4OU22C.js.map} +0 -0
- /package/dist/{chunk-RYALTDJI.js.map → chunk-RPIILAZ5.js.map} +0 -0
- /package/dist/{chunk-QJFAJORX.js.map → chunk-TN4TZY7G.js.map} +0 -0
- /package/dist/{chunk-H744C3MH.js.map → chunk-VDIUCVWJ.js.map} +0 -0
- /package/dist/{chunk-HCGBT46A.js.map → chunk-WTF7JOIQ.js.map} +0 -0
- /package/dist/{chunk-Q64XH2HD.js.map → chunk-X7PDG4FB.js.map} +0 -0
- /package/dist/{chunk-GUBKR5CU.js.map → chunk-YSZEGC2L.js.map} +0 -0
- /package/dist/{chunk-QMQYRYOJ.js.map → chunk-ZUWPUBWZ.js.map} +0 -0
- /package/dist/{chunk-SNLXXBXP.js.map → chunk-ZXUQALBB.js.map} +0 -0
- /package/dist/{cli-UUU72LBP.js.map → cli-F65QNC6S.js.map} +0 -0
- /package/dist/{commands-HN4V6NUM.js.map → commands-A6WCP2T2.js.map} +0 -0
- /package/dist/{config-SKKYAIQT.js.map → config-TEBSBFSO.js.map} +0 -0
- /package/dist/{context-VC4F6CQH.js.map → context-T5NFLTK4.js.map} +0 -0
- /package/dist/{conversationTracker-2PRBUDU7.js.map → conversationTracker-ZUJHBMDH.js.map} +0 -0
- /package/dist/{customCommands-KFSKRLOR.js.map → customCommands-TBZ5RMJ5.js.map} +0 -0
- /package/dist/{env-UXRNUTRY.js.map → env-3LH2POC2.js.map} +0 -0
- /package/dist/{file-YOLDPGAZ.js.map → file-O7PWWVFS.js.map} +0 -0
- /package/dist/{llm-NNPSCVNC.js.map → llm-OW7QDXPZ.js.map} +0 -0
- /package/dist/{llmLazy-VFQBE4VQ.js.map → llmLazy-CCD2PHFB.js.map} +0 -0
- /package/dist/{loader-JLKU56P4.js.map → loader-RBCHNZJW.js.map} +0 -0
- /package/dist/{lsp-ODCSAM2C.js.map → lsp-WAD7S2GA.js.map} +0 -0
- /package/dist/{lspAnchor-DRPDOTNI.js.map → lspAnchor-B5AR4FPG.js.map} +0 -0
- /package/dist/{mcp-YNM5F6DI.js.map → mcp-5H5KKR2C.js.map} +0 -0
- /package/dist/{mentionProcessor-XE5YX3QF.js.map → mentionProcessor-NK7NPMF2.js.map} +0 -0
- /package/dist/{messages-S6CUVFAR.js.map → messages-DHHFMED7.js.map} +0 -0
- /package/dist/{model-XRNLQZ4O.js.map → model-XWJ23WCS.js.map} +0 -0
- /package/dist/{openai-JAWY3TYO.js.map → openai-WAGWEANY.js.map} +0 -0
- /package/dist/{outputStyles-C2BALUUY.js.map → outputStyles-F6PPD3VU.js.map} +0 -0
- /package/dist/{pluginRuntime-S7J5ODQU.js.map → pluginRuntime-BFIRISID.js.map} +0 -0
- /package/dist/{pluginValidation-QTKM6IXY.js.map → pluginValidation-FDI5C7J7.js.map} +0 -0
- /package/dist/{prompts-QVC7LLMH.js.map → prompts-XIY3JRPC.js.map} +0 -0
- /package/dist/{pybAgentSessionLoad-QONCGHTI.js.map → pybAgentSessionLoad-Z57EVSBX.js.map} +0 -0
- /package/dist/{pybAgentSessionResume-2MIW4X3R.js.map → pybAgentSessionResume-74AWGCWV.js.map} +0 -0
- /package/dist/{pybAgentStreamJsonSession-7IBCTJCI.js.map → pybAgentStreamJsonSession-HVWGJB4Q.js.map} +0 -0
- /package/dist/{pybHooks-2FKUCMJD.js.map → pybHooks-FZYE52XG.js.map} +0 -0
- /package/dist/{query-HUTD7BSB.js.map → query-JWT6DB4G.js.map} +0 -0
- /package/dist/{registry-OVP3MKFX.js.map → registry-FCKOLGU5.js.map} +0 -0
- /package/dist/{ripgrep-KOL5M55E.js.map → ripgrep-MYG754KL.js.map} +0 -0
- /package/dist/{skillMarketplace-XXVBYC57.js.map → skillMarketplace-B5UZC4ES.js.map} +0 -0
- /package/dist/{state-CVENJNIV.js.map → state-SP4W7M4L.js.map} +0 -0
- /package/dist/{theme-CV36XY2J.js.map → theme-OZAWAG6W.js.map} +0 -0
- /package/dist/{toolPermissionSettings-MBBYIXDA.js.map → toolPermissionSettings-S2WBKN66.js.map} +0 -0
- /package/dist/{tools-2UQZG6N5.js.map → tools-UE2MORVX.js.map} +0 -0
- /package/dist/{userInput-JZQSTMJF.js.map → userInput-YJPISBP7.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-MLZYATJX.js";
|
|
6
6
|
import {
|
|
7
7
|
formatValidationResult,
|
|
8
8
|
validatePluginOrMarketplacePath
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-KO6ENKTQ.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-HV4AL2VG.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-FZEVFEDH.js";
|
|
24
24
|
import {
|
|
25
25
|
appendSessionCustomTitleRecord,
|
|
26
26
|
appendSessionJsonlFromMessage,
|
|
27
27
|
appendSessionTagRecord
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-DTWSIMGF.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-VDIUCVWJ.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-TN4TZY7G.js";
|
|
50
50
|
import {
|
|
51
51
|
fetchCustomModels,
|
|
52
52
|
getModelFeatures
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-CXLPIXKP.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-RPIILAZ5.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-ZXUQALBB.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-GPSHYLDR.js";
|
|
89
89
|
import {
|
|
90
90
|
loadToolPermissionContextFromDisk,
|
|
91
91
|
persistToolPermissionUpdateToDisk
|
|
92
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-L3QFTUHN.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-LMTF4FXH.js";
|
|
104
104
|
import {
|
|
105
105
|
clearAgentCache,
|
|
106
106
|
getActiveAgents,
|
|
107
107
|
getAgentByType,
|
|
108
108
|
getAllAgents
|
|
109
|
-
} from "./chunk-
|
|
109
|
+
} from "./chunk-6MZDAIOV.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-BKG4N5U7.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-BRDQQ6DH.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-WTF7JOIQ.js";
|
|
181
181
|
import {
|
|
182
182
|
getSettingsFileCandidates,
|
|
183
183
|
loadSettingsWithLegacyFallback,
|
|
184
184
|
readSettingsFile
|
|
185
|
-
} from "./chunk-
|
|
185
|
+
} from "./chunk-PCSIH35L.js";
|
|
186
186
|
import {
|
|
187
187
|
getCustomCommandDirectories,
|
|
188
188
|
hasCustomCommands,
|
|
189
189
|
loadCustomCommands,
|
|
190
190
|
reloadCustomCommands
|
|
191
|
-
} from "./chunk-
|
|
191
|
+
} from "./chunk-33HCNVDW.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-QD4OU22C.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-DM2LV6T7.js";
|
|
209
209
|
import {
|
|
210
210
|
getRipgrepPath,
|
|
211
211
|
getRipgrepPolicyMode,
|
|
212
212
|
resolveRipgrepPolicy,
|
|
213
213
|
ripGrep
|
|
214
|
-
} from "./chunk-
|
|
214
|
+
} from "./chunk-ZUWPUBWZ.js";
|
|
215
215
|
import {
|
|
216
216
|
getTheme
|
|
217
|
-
} from "./chunk-
|
|
217
|
+
} from "./chunk-NM5GLMVH.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-YSZEGC2L.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-X7PDG4FB.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-GKFPN3PD.js";
|
|
281
281
|
import {
|
|
282
282
|
MACRO
|
|
283
|
-
} from "./chunk-
|
|
283
|
+
} from "./chunk-63RVOHFS.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-OW7QDXPZ.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-OW7QDXPZ.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-B5AR4FPG.js");
|
|
6628
6628
|
for (const op of editOperations) {
|
|
6629
6629
|
const normalizedSearch = normalizeLineEndings(op.search);
|
|
6630
6630
|
const normalizedReplace = normalizeLineEndings(op.replace);
|
|
@@ -8107,7 +8107,7 @@ import { z as z6 } from "zod";
|
|
|
8107
8107
|
|
|
8108
8108
|
// src/tools/filesystem/GlobTool/prompt.ts
|
|
8109
8109
|
var TOOL_NAME_FOR_PROMPT2 = "Glob";
|
|
8110
|
-
var DESCRIPTION4 =
|
|
8110
|
+
var DESCRIPTION4 = `Fast file pattern matching tool that works with any codebase size
|
|
8111
8111
|
|
|
8112
8112
|
## WhenToUse & Best Practice
|
|
8113
8113
|
- If you have keywords or fuzzy paths, use Glob first to narrow candidates.
|
|
@@ -8134,11 +8134,70 @@ var DESCRIPTION4 = `- Fast file pattern matching tool that works with any codeba
|
|
|
8134
8134
|
|
|
8135
8135
|
## Usage Details
|
|
8136
8136
|
- Supports glob patterns like "**/*.js" or "src/**/*.ts"
|
|
8137
|
-
- Returns
|
|
8137
|
+
- Returns absolute file paths sorted by modification time (most recent first)
|
|
8138
8138
|
- Use this tool when you need to find files by name patterns
|
|
8139
|
-
-
|
|
8140
|
-
-
|
|
8141
|
-
-
|
|
8139
|
+
- Powered by ripgrep with \`--files\` mode for fast pattern matching
|
|
8140
|
+
- \`path\` parameter: Specify the directory to search in. If omitted, uses the current working directory. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Supports both relative and absolute paths.
|
|
8141
|
+
- Results are limited to 100 files by default. If truncated, use a more specific path or pattern to narrow results.
|
|
8142
|
+
- Search ignores .gitignore rules and includes hidden files by default.
|
|
8143
|
+
- **Semantic Search**: Set \`semantic: true\` to enable LSP workspace symbol search as fallback.
|
|
8144
|
+
- Trigger condition: Semantic search only activates when normal glob returns zero results.
|
|
8145
|
+
- In semantic mode, the \`pattern\` parameter is interpreted as a symbol name (e.g., class name, function name) for LSP workspace symbol lookup.
|
|
8146
|
+
- Returns file paths where the symbol is defined, helping locate source files by symbol name rather than filename pattern.
|
|
8147
|
+
- On success: returns notice "Semantic search: added X results. Next: use LspTool for details."
|
|
8148
|
+
- If LSP is unavailable, returns empty results with notice "Semantic search: LSP unavailable."
|
|
8149
|
+
- **Empty Results**: When no files are found, use LS to confirm directory structure, then try broader patterns (e.g., src/**/*) or enable semantic search.
|
|
8150
|
+
- **Error Handling**: Returns error if \`path\` does not exist or is not a valid directory.
|
|
8151
|
+
|
|
8152
|
+
## Typical Usage Examples
|
|
8153
|
+
|
|
8154
|
+
### Example 1: Project Structure Discovery (Unknown Codebase)
|
|
8155
|
+
<example>
|
|
8156
|
+
user: I'm new to this project, what's the structure?
|
|
8157
|
+
assistant: [uses Glob tool with pattern="**/package.json" to find project roots]
|
|
8158
|
+
[uses Glob tool with pattern="src/**/*.{ts,tsx}" to understand source layout]
|
|
8159
|
+
[uses LS tool on key directories to see detailed structure]
|
|
8160
|
+
</example>
|
|
8161
|
+
|
|
8162
|
+
### Example 2: Find Files by Type in Specific Area
|
|
8163
|
+
<example>
|
|
8164
|
+
user: Find all test files in the auth module
|
|
8165
|
+
assistant: [uses Glob tool with pattern="src/auth/**/*.test.ts"]
|
|
8166
|
+
[uses Read tool to examine specific test files]
|
|
8167
|
+
</example>
|
|
8168
|
+
|
|
8169
|
+
### Example 3: Config File Location (Deterministic)
|
|
8170
|
+
<example>
|
|
8171
|
+
user: Where is the webpack configuration?
|
|
8172
|
+
assistant: [uses Glob tool with pattern="**/webpack*.{js,ts,json}"]
|
|
8173
|
+
[uses Read tool on the matched config file]
|
|
8174
|
+
</example>
|
|
8175
|
+
|
|
8176
|
+
### Example 4: Semantic Fallback for Symbol-Based File Lookup
|
|
8177
|
+
<example>
|
|
8178
|
+
user: Find the file that defines \`UserRepository\`
|
|
8179
|
+
assistant: [uses Glob tool with pattern="*UserRepository*" - no results]
|
|
8180
|
+
[uses Glob tool with pattern="UserRepository" semantic:true]
|
|
8181
|
+
[uses LSP goToDefinition to confirm the symbol location]
|
|
8182
|
+
</example>
|
|
8183
|
+
|
|
8184
|
+
### Example 5: Parallel Discovery for Entry Points
|
|
8185
|
+
<example>
|
|
8186
|
+
user: What are the main entry points of this application?
|
|
8187
|
+
assistant: [uses Glob tool with pattern="**/index.{ts,js}"]
|
|
8188
|
+
[uses Glob tool with pattern="**/main.{ts,js}"]
|
|
8189
|
+
[uses Glob tool with pattern="**/app.{ts,js}"]
|
|
8190
|
+
[uses Read tool to examine the entry point files]
|
|
8191
|
+
</example>
|
|
8192
|
+
|
|
8193
|
+
### Example 6: Narrow Down After Broad Results
|
|
8194
|
+
<example>
|
|
8195
|
+
user: Find all TypeScript files in the project
|
|
8196
|
+
assistant: [uses Glob tool with pattern="**/*.ts" - returns 500+ files, truncated]
|
|
8197
|
+
[uses Glob tool with pattern="src/**/*.ts" to focus on source code]
|
|
8198
|
+
[uses Glob tool with pattern="src/core/**/*.ts" to narrow further if needed]
|
|
8199
|
+
</example>
|
|
8200
|
+
`;
|
|
8142
8201
|
|
|
8143
8202
|
// src/tools/filesystem/GlobTool/GlobTool.tsx
|
|
8144
8203
|
import { existsSync as existsSync6, statSync as statSync9 } from "fs";
|
|
@@ -8298,7 +8357,7 @@ import { z as z7 } from "zod";
|
|
|
8298
8357
|
|
|
8299
8358
|
// src/tools/search/GrepTool/prompt.ts
|
|
8300
8359
|
var TOOL_NAME_FOR_PROMPT3 = "Grep";
|
|
8301
|
-
var DESCRIPTION5 = `A powerful search tool
|
|
8360
|
+
var DESCRIPTION5 = `A powerful fast content search tool that works with any codebase size
|
|
8302
8361
|
|
|
8303
8362
|
## Best Practice
|
|
8304
8363
|
- Use Grep as a "Scout" to *find* entry points based on text patterns.
|
|
@@ -8329,17 +8388,90 @@ var DESCRIPTION5 = `A powerful search tool built on ripgrep
|
|
|
8329
8388
|
|
|
8330
8389
|
## Usage Details
|
|
8331
8390
|
- ALWAYS use Grep for search tasks. NEVER invoke \`grep\` or \`rg\` as a Bash command. The Grep tool has been optimized for correct permissions and access.
|
|
8332
|
-
-
|
|
8333
|
-
-
|
|
8334
|
-
-
|
|
8335
|
-
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
-
|
|
8339
|
-
-
|
|
8391
|
+
- Powered by ripgrep for fast text search with full regex support (e.g., "log.*Error", "function\\s+\\w+")
|
|
8392
|
+
- Pattern syntax: Uses ripgrep - literal braces need escaping (use \`interface\\{\\}\` to find \`interface{}\` in Go code)
|
|
8393
|
+
- Excludes version control directories (.git, .svn, .hg, .bzr) automatically
|
|
8394
|
+
- Includes hidden files by default
|
|
8395
|
+
|
|
8396
|
+
**Path & Scope**:
|
|
8397
|
+
- \`path\` parameter: File or directory to search in. Defaults to current working directory.
|
|
8398
|
+
- \`glob\` parameter: Filter files by glob pattern (e.g., "*.js", "*.{ts,tsx}") - maps to rg --glob
|
|
8399
|
+
- \`type\` parameter: Filter by file type (e.g., "js", "py", "rust", "go", "java") - more efficient than glob for standard types
|
|
8400
|
+
- Path guidance: If user provides a path, use it directly. If uncertain, confirm with LS/Glob first.
|
|
8401
|
+
|
|
8402
|
+
**Output Modes**:
|
|
8403
|
+
- \`files_with_matches\` (default): Returns file paths sorted by modification time
|
|
8404
|
+
- \`content\`: Shows matching lines with line numbers (supports -A/-B/-C context)
|
|
8405
|
+
- \`count\`: Shows match counts per file
|
|
8406
|
+
|
|
8407
|
+
**Context & Pagination**:
|
|
8408
|
+
- \`-B\`, \`-A\`, \`-C\`: Context lines before/after/around matches (requires output_mode: "content")
|
|
8409
|
+
- \`-n\`: Show line numbers (default: true, requires output_mode: "content")
|
|
8410
|
+
- \`head_limit\`: Limit output to first N entries (works across all modes)
|
|
8411
|
+
- \`offset\`: Skip first N entries before applying head_limit
|
|
8412
|
+
- \`multiline\`: Enable multiline mode where . matches newlines (default: false)
|
|
8413
|
+
|
|
8414
|
+
**Case Sensitivity**:
|
|
8415
|
+
- \`-i\`: Enable case-insensitive search
|
|
8416
|
+
|
|
8417
|
+
**Semantic Search**:
|
|
8418
|
+
- \`semantic: true\`: Enable LSP workspace symbol search as fallback when text search yields no results.
|
|
8419
|
+
- \`symbol_type\`: Filter semantic search by symbol type (e.g., "class", "function", "variable"). Requires semantic: true.
|
|
8420
|
+
- When \`symbol_type\` is specified, LSP search replaces (not augments) text search results.
|
|
8421
|
+
- Supported types: file, module, namespace, package, class, method, property, field, constructor, enum, interface, function, variable, constant, struct, event, operator, typeparameter
|
|
8340
8422
|
- Semantic output format: \`file:line: name (Kind)\` for quick follow-up reads
|
|
8341
|
-
-
|
|
8342
|
-
-
|
|
8423
|
+
- On success: returns notice "Semantic search: added X results. Next: use LspTool for details."
|
|
8424
|
+
- If LSP is unavailable: returns "Semantic search: LSP unavailable."
|
|
8425
|
+
|
|
8426
|
+
**Result Handling**:
|
|
8427
|
+
- Results are truncated at 20,000 characters if too large
|
|
8428
|
+
- Use Task tool for open-ended searches requiring multiple rounds
|
|
8429
|
+
|
|
8430
|
+
**Typical Usage Examples**:
|
|
8431
|
+
|
|
8432
|
+
Example 1: Exact Error Message Tracing (Deterministic)
|
|
8433
|
+
<example>
|
|
8434
|
+
user: Where does the error "Connection timeout after 30s" come from?
|
|
8435
|
+
assistant: [uses Grep tool with pattern="Connection timeout after 30s"output_mode="content"]
|
|
8436
|
+
[uses Read tool to examine the error source and surrounding context]
|
|
8437
|
+
</example>
|
|
8438
|
+
|
|
8439
|
+
Example 2: Precise Function Definition Lookup (Deterministic)
|
|
8440
|
+
<example>
|
|
8441
|
+
user: Find the implementation of \`calculateCompoundInterest\` function
|
|
8442
|
+
assistant: [uses Grep tool with pattern="calculateCompoundInterest" type="ts"output_mode="content"]
|
|
8443
|
+
[uses Read tool on the matched file to read the full implementation]
|
|
8444
|
+
</example>
|
|
8445
|
+
|
|
8446
|
+
Example 3: Concept Search with Semantic Fallback
|
|
8447
|
+
<example>
|
|
8448
|
+
user: Where is authentication logic implemented?
|
|
8449
|
+
assistant: [uses Grep tool with pattern="auth" type="ts" semantic: true]
|
|
8450
|
+
[uses Read tool to examine the most relevant matches]
|
|
8451
|
+
[uses LSP goToDefinition to trace the core auth flow]
|
|
8452
|
+
</example>
|
|
8453
|
+
|
|
8454
|
+
Example 4: Iterative Narrowing for Broad Patterns
|
|
8455
|
+
<example>
|
|
8456
|
+
user: Find all API route definitions
|
|
8457
|
+
assistant: [uses Grep tool with pattern="router\\.(get|post|put|delete)" type="ts"]
|
|
8458
|
+
[if too many results: adds path="src/routes" to narrow scope]
|
|
8459
|
+
[uses Read tool to inspect specific route handlers]
|
|
8460
|
+
</example>
|
|
8461
|
+
|
|
8462
|
+
Example 5: Handoff to LSP After Entry Point Found
|
|
8463
|
+
<example>
|
|
8464
|
+
user: Find all usages of the \`PaymentService\` class
|
|
8465
|
+
assistant: [uses Grep tool with pattern="class PaymentService" type="ts"output_mode="content"]
|
|
8466
|
+
[uses LSP findReferences at the class definition location to get all references]
|
|
8467
|
+
</example>
|
|
8468
|
+
|
|
8469
|
+
Example 6: Case-Insensitive Search for Config Values
|
|
8470
|
+
<example>
|
|
8471
|
+
user: Where is the database host configured?
|
|
8472
|
+
assistant: [uses Grep tool with pattern="database.*host|db_host|DB_HOST" -i: true]
|
|
8473
|
+
[uses Read tool to examine configuration files]
|
|
8474
|
+
</example>`;
|
|
8343
8475
|
|
|
8344
8476
|
// src/tools/search/GrepTool/GrepTool.tsx
|
|
8345
8477
|
import { isAbsolute as isAbsolute7, relative as relative9, resolve as resolve7 } from "path";
|
|
@@ -11926,7 +12058,7 @@ async function createAndStoreApiKey(accessToken) {
|
|
|
11926
12058
|
}
|
|
11927
12059
|
saveGlobalConfig(config2);
|
|
11928
12060
|
try {
|
|
11929
|
-
const { resetAnthropicClient } = await import("./llm-
|
|
12061
|
+
const { resetAnthropicClient } = await import("./llm-OW7QDXPZ.js");
|
|
11930
12062
|
resetAnthropicClient();
|
|
11931
12063
|
} catch {
|
|
11932
12064
|
}
|
|
@@ -16350,7 +16482,7 @@ async function refreshPluginRuntimeFromInstalls() {
|
|
|
16350
16482
|
const existingRoots = getSessionPlugins().map((p) => p.rootDir);
|
|
16351
16483
|
const dirs = Array.from(/* @__PURE__ */ new Set([...existingRoots, ...installedRoots]));
|
|
16352
16484
|
if (dirs.length === 0) return [];
|
|
16353
|
-
const { configureSessionPlugins } = await import("./pluginRuntime-
|
|
16485
|
+
const { configureSessionPlugins } = await import("./pluginRuntime-BFIRISID.js");
|
|
16354
16486
|
const { errors } = await configureSessionPlugins({ pluginDirs: dirs });
|
|
16355
16487
|
return errors;
|
|
16356
16488
|
}
|
|
@@ -17025,7 +17157,7 @@ async function call(onDone, context) {
|
|
|
17025
17157
|
ModelConfig,
|
|
17026
17158
|
{
|
|
17027
17159
|
onClose: () => {
|
|
17028
|
-
import("./model-
|
|
17160
|
+
import("./model-XWJ23WCS.js").then(({ reloadModelManager: reloadModelManager2 }) => {
|
|
17029
17161
|
reloadModelManager2();
|
|
17030
17162
|
triggerModelConfigChange();
|
|
17031
17163
|
onDone();
|
|
@@ -25229,7 +25361,7 @@ function useStatusLine() {
|
|
|
25229
25361
|
// src/ui/components/PromptInput.tsx
|
|
25230
25362
|
async function interpretHashCommand(input) {
|
|
25231
25363
|
try {
|
|
25232
|
-
const { queryQuick: queryQuick2 } = await import("./llm-
|
|
25364
|
+
const { queryQuick: queryQuick2 } = await import("./llm-OW7QDXPZ.js");
|
|
25233
25365
|
const systemPrompt = [
|
|
25234
25366
|
"You're helping the user structure notes that will be added to their PYB.md file.",
|
|
25235
25367
|
"Format the user's input into a well-structured note that will be useful for later reference.",
|
|
@@ -25542,7 +25674,7 @@ function PromptInput({
|
|
|
25542
25674
|
if (messages2.length) {
|
|
25543
25675
|
if (mode === "bash") {
|
|
25544
25676
|
onQuery(messages2, newAbortController).then(async () => {
|
|
25545
|
-
const { getCwd: getCwd2 } = await import("./state-
|
|
25677
|
+
const { getCwd: getCwd2 } = await import("./state-SP4W7M4L.js");
|
|
25546
25678
|
setCurrentPwd(getCwd2());
|
|
25547
25679
|
});
|
|
25548
25680
|
} else {
|
|
@@ -26801,6 +26933,344 @@ function startWatchingTaskList(listId) {
|
|
|
26801
26933
|
startFallbackWatcher(entry);
|
|
26802
26934
|
}
|
|
26803
26935
|
|
|
26936
|
+
// src/services/ai/streamTyped/partStore.ts
|
|
26937
|
+
import { appendFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, readFileSync as readFileSync13 } from "fs";
|
|
26938
|
+
import { dirname as dirname9 } from "path";
|
|
26939
|
+
|
|
26940
|
+
// src/services/ai/streamTyped/partTypes.ts
|
|
26941
|
+
import { z as z11 } from "zod";
|
|
26942
|
+
var SOURCE_VALUES = ["auto_compact", "query_main"];
|
|
26943
|
+
var TOOL_STATUS_VALUES = ["pending", "running", "completed", "failed", "interrupted"];
|
|
26944
|
+
var textPayloadSchema = z11.object({
|
|
26945
|
+
text: z11.string().min(1)
|
|
26946
|
+
});
|
|
26947
|
+
var reasoningPayloadSchema = z11.object({
|
|
26948
|
+
text: z11.string().min(1)
|
|
26949
|
+
});
|
|
26950
|
+
var toolPayloadSchema = z11.object({
|
|
26951
|
+
toolName: z11.string().min(1),
|
|
26952
|
+
toolCallId: z11.string().min(1),
|
|
26953
|
+
status: z11.enum(TOOL_STATUS_VALUES),
|
|
26954
|
+
outputText: z11.string().optional()
|
|
26955
|
+
});
|
|
26956
|
+
var streamTypedPartBaseSchema = z11.object({
|
|
26957
|
+
id: z11.string().min(1),
|
|
26958
|
+
requestId: z11.string().min(1),
|
|
26959
|
+
source: z11.enum(SOURCE_VALUES),
|
|
26960
|
+
timestamp: z11.number().int().positive()
|
|
26961
|
+
});
|
|
26962
|
+
var streamTypedPartSchema = z11.discriminatedUnion("partType", [
|
|
26963
|
+
streamTypedPartBaseSchema.extend({
|
|
26964
|
+
partType: z11.literal("text"),
|
|
26965
|
+
payload: textPayloadSchema
|
|
26966
|
+
}),
|
|
26967
|
+
streamTypedPartBaseSchema.extend({
|
|
26968
|
+
partType: z11.literal("reasoning"),
|
|
26969
|
+
payload: reasoningPayloadSchema
|
|
26970
|
+
}),
|
|
26971
|
+
streamTypedPartBaseSchema.extend({
|
|
26972
|
+
partType: z11.literal("tool"),
|
|
26973
|
+
payload: toolPayloadSchema
|
|
26974
|
+
})
|
|
26975
|
+
]);
|
|
26976
|
+
function createId() {
|
|
26977
|
+
return `stp_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
26978
|
+
}
|
|
26979
|
+
function createBase(input) {
|
|
26980
|
+
return {
|
|
26981
|
+
id: createId(),
|
|
26982
|
+
requestId: input.requestId,
|
|
26983
|
+
source: input.source ?? "auto_compact",
|
|
26984
|
+
timestamp: Date.now()
|
|
26985
|
+
};
|
|
26986
|
+
}
|
|
26987
|
+
function createTextPart(input) {
|
|
26988
|
+
return streamTypedPartSchema.parse({
|
|
26989
|
+
...createBase(input),
|
|
26990
|
+
partType: "text",
|
|
26991
|
+
payload: {
|
|
26992
|
+
text: input.text.trim()
|
|
26993
|
+
}
|
|
26994
|
+
});
|
|
26995
|
+
}
|
|
26996
|
+
function createReasoningPart(input) {
|
|
26997
|
+
return streamTypedPartSchema.parse({
|
|
26998
|
+
...createBase(input),
|
|
26999
|
+
partType: "reasoning",
|
|
27000
|
+
payload: {
|
|
27001
|
+
text: input.text.trim()
|
|
27002
|
+
}
|
|
27003
|
+
});
|
|
27004
|
+
}
|
|
27005
|
+
function createToolPart(input) {
|
|
27006
|
+
return streamTypedPartSchema.parse({
|
|
27007
|
+
...createBase(input),
|
|
27008
|
+
partType: "tool",
|
|
27009
|
+
payload: {
|
|
27010
|
+
toolName: input.toolName,
|
|
27011
|
+
toolCallId: input.toolCallId,
|
|
27012
|
+
status: input.status,
|
|
27013
|
+
...input.outputText ? { outputText: input.outputText } : {}
|
|
27014
|
+
}
|
|
27015
|
+
});
|
|
27016
|
+
}
|
|
27017
|
+
|
|
27018
|
+
// src/services/ai/streamTyped/partStore.ts
|
|
27019
|
+
function getStreamTypedOutputFilePath() {
|
|
27020
|
+
return resolveXdgCachePath("telemetry/stream-typed-parts.jsonl");
|
|
27021
|
+
}
|
|
27022
|
+
function validateTypedPartRecord(record) {
|
|
27023
|
+
return streamTypedPartSchema.safeParse(record).success;
|
|
27024
|
+
}
|
|
27025
|
+
function readAllValidParts(outputFilePath) {
|
|
27026
|
+
if (!existsSync17(outputFilePath)) return [];
|
|
27027
|
+
const raw = readFileSync13(outputFilePath, "utf8");
|
|
27028
|
+
const lines = raw.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
27029
|
+
const parts = [];
|
|
27030
|
+
for (const line of lines) {
|
|
27031
|
+
try {
|
|
27032
|
+
const parsed = JSON.parse(line);
|
|
27033
|
+
if (!validateTypedPartRecord(parsed)) continue;
|
|
27034
|
+
parts.push(parsed);
|
|
27035
|
+
} catch {
|
|
27036
|
+
continue;
|
|
27037
|
+
}
|
|
27038
|
+
}
|
|
27039
|
+
return parts;
|
|
27040
|
+
}
|
|
27041
|
+
function appendTypedParts(options) {
|
|
27042
|
+
if (!Array.isArray(options.parts) || options.parts.length === 0) {
|
|
27043
|
+
return { appended: 0 };
|
|
27044
|
+
}
|
|
27045
|
+
const outputFilePath = options.outputFilePath ?? getStreamTypedOutputFilePath();
|
|
27046
|
+
if (!existsSync17(dirname9(outputFilePath))) {
|
|
27047
|
+
mkdirSync7(dirname9(outputFilePath), { recursive: true });
|
|
27048
|
+
}
|
|
27049
|
+
const existingIds = new Set(readAllValidParts(outputFilePath).map((item) => item.id));
|
|
27050
|
+
const toAppend = options.parts.filter(
|
|
27051
|
+
(item) => validateTypedPartRecord(item) && !existingIds.has(item.id)
|
|
27052
|
+
);
|
|
27053
|
+
if (toAppend.length === 0) return { appended: 0 };
|
|
27054
|
+
appendFileSync(
|
|
27055
|
+
outputFilePath,
|
|
27056
|
+
`${toAppend.map((item) => JSON.stringify(item)).join("\n")}
|
|
27057
|
+
`
|
|
27058
|
+
);
|
|
27059
|
+
return { appended: toAppend.length };
|
|
27060
|
+
}
|
|
27061
|
+
|
|
27062
|
+
// src/services/ai/streamTyped/index.ts
|
|
27063
|
+
var streamTypedBuffer = /* @__PURE__ */ new Map();
|
|
27064
|
+
function emitTypedPart(event) {
|
|
27065
|
+
const requestId = String(event.requestId || "").trim();
|
|
27066
|
+
if (!requestId) return;
|
|
27067
|
+
const current = streamTypedBuffer.get(requestId) ?? [];
|
|
27068
|
+
current.push(event.part);
|
|
27069
|
+
streamTypedBuffer.set(requestId, current);
|
|
27070
|
+
}
|
|
27071
|
+
function flushTypedPartBuffer(options) {
|
|
27072
|
+
const requestId = String(options.requestId || "").trim();
|
|
27073
|
+
if (!requestId) return { appended: 0 };
|
|
27074
|
+
const parts = streamTypedBuffer.get(requestId) ?? [];
|
|
27075
|
+
streamTypedBuffer.delete(requestId);
|
|
27076
|
+
return appendTypedParts({
|
|
27077
|
+
outputFilePath: options.outputFilePath,
|
|
27078
|
+
parts
|
|
27079
|
+
});
|
|
27080
|
+
}
|
|
27081
|
+
|
|
27082
|
+
// src/services/ai/streamTyped/eventAssembler.ts
|
|
27083
|
+
function createAssemblerState(requestId, source = "auto_compact") {
|
|
27084
|
+
return {
|
|
27085
|
+
requestId,
|
|
27086
|
+
parts: [],
|
|
27087
|
+
textBuffer: {},
|
|
27088
|
+
reasoningBuffer: {},
|
|
27089
|
+
toolMap: {},
|
|
27090
|
+
source
|
|
27091
|
+
};
|
|
27092
|
+
}
|
|
27093
|
+
function onTextStart(event, state) {
|
|
27094
|
+
state.textBuffer[event.textId] = "";
|
|
27095
|
+
}
|
|
27096
|
+
function onTextDelta(event, state) {
|
|
27097
|
+
const current = state.textBuffer[event.textId] ?? "";
|
|
27098
|
+
state.textBuffer[event.textId] = `${current}${event.text}`;
|
|
27099
|
+
}
|
|
27100
|
+
function onTextEnd(event, state) {
|
|
27101
|
+
const text = String(state.textBuffer[event.textId] ?? "").trim();
|
|
27102
|
+
delete state.textBuffer[event.textId];
|
|
27103
|
+
if (!text) return;
|
|
27104
|
+
state.parts.push(
|
|
27105
|
+
createTextPart({
|
|
27106
|
+
requestId: state.requestId,
|
|
27107
|
+
text,
|
|
27108
|
+
source: state.source
|
|
27109
|
+
})
|
|
27110
|
+
);
|
|
27111
|
+
}
|
|
27112
|
+
function onReasoningStart(event, state) {
|
|
27113
|
+
state.reasoningBuffer[event.reasoningId] = "";
|
|
27114
|
+
}
|
|
27115
|
+
function onReasoningDelta(event, state) {
|
|
27116
|
+
const current = state.reasoningBuffer[event.reasoningId] ?? "";
|
|
27117
|
+
state.reasoningBuffer[event.reasoningId] = `${current}${event.text}`;
|
|
27118
|
+
}
|
|
27119
|
+
function onReasoningEnd(event, state) {
|
|
27120
|
+
const text = String(state.reasoningBuffer[event.reasoningId] ?? "").trim();
|
|
27121
|
+
delete state.reasoningBuffer[event.reasoningId];
|
|
27122
|
+
if (!text) return;
|
|
27123
|
+
state.parts.push(
|
|
27124
|
+
createReasoningPart({
|
|
27125
|
+
requestId: state.requestId,
|
|
27126
|
+
text,
|
|
27127
|
+
source: state.source
|
|
27128
|
+
})
|
|
27129
|
+
);
|
|
27130
|
+
}
|
|
27131
|
+
function onToolCall(event, state) {
|
|
27132
|
+
state.toolMap[event.toolCallId] = { toolName: event.toolName };
|
|
27133
|
+
}
|
|
27134
|
+
function onToolResult(event, state) {
|
|
27135
|
+
const toolName = state.toolMap[event.toolCallId]?.toolName ?? "unknown";
|
|
27136
|
+
state.parts.push(
|
|
27137
|
+
createToolPart({
|
|
27138
|
+
requestId: state.requestId,
|
|
27139
|
+
toolName,
|
|
27140
|
+
toolCallId: event.toolCallId,
|
|
27141
|
+
status: event.status,
|
|
27142
|
+
outputText: event.outputText,
|
|
27143
|
+
source: state.source
|
|
27144
|
+
})
|
|
27145
|
+
);
|
|
27146
|
+
if (event.status === "completed" || event.status === "failed" || event.status === "interrupted") {
|
|
27147
|
+
delete state.toolMap[event.toolCallId];
|
|
27148
|
+
}
|
|
27149
|
+
}
|
|
27150
|
+
function flushTypedParts(state) {
|
|
27151
|
+
const parts = state.parts.slice();
|
|
27152
|
+
state.parts.length = 0;
|
|
27153
|
+
return parts;
|
|
27154
|
+
}
|
|
27155
|
+
|
|
27156
|
+
// src/services/ai/streamTyped/projector.ts
|
|
27157
|
+
function supportsRichToolResultByProvider(provider) {
|
|
27158
|
+
return String(provider ?? "").trim().toLowerCase() === "anthropic";
|
|
27159
|
+
}
|
|
27160
|
+
function extractToolResultText(content) {
|
|
27161
|
+
if (typeof content === "string") return { text: content, hasNonTextBlock: false };
|
|
27162
|
+
if (!Array.isArray(content)) return { text: "", hasNonTextBlock: false };
|
|
27163
|
+
let hasNonTextBlock = false;
|
|
27164
|
+
const text = content.filter((block) => {
|
|
27165
|
+
if (!block || typeof block !== "object") return false;
|
|
27166
|
+
if (block.type === "text") return true;
|
|
27167
|
+
hasNonTextBlock = true;
|
|
27168
|
+
return false;
|
|
27169
|
+
}).map((block) => String(block.text ?? "")).join("\n");
|
|
27170
|
+
return { text, hasNonTextBlock };
|
|
27171
|
+
}
|
|
27172
|
+
function projectAssistantMessage(state, message) {
|
|
27173
|
+
const content = message?.message?.content;
|
|
27174
|
+
if (!Array.isArray(content)) return;
|
|
27175
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
27176
|
+
const block = content[i];
|
|
27177
|
+
if (!block || typeof block !== "object") continue;
|
|
27178
|
+
const type3 = String(block.type ?? "");
|
|
27179
|
+
if (type3 === "text") {
|
|
27180
|
+
const text = String(block.text ?? "");
|
|
27181
|
+
onTextStart({ textId: `text-${i}` }, state);
|
|
27182
|
+
onTextDelta({ textId: `text-${i}`, text }, state);
|
|
27183
|
+
onTextEnd({ textId: `text-${i}` }, state);
|
|
27184
|
+
continue;
|
|
27185
|
+
}
|
|
27186
|
+
if (type3 === "thinking" || type3 === "reasoning") {
|
|
27187
|
+
const text = String(block.thinking ?? block.reasoning ?? "");
|
|
27188
|
+
onReasoningStart({ reasoningId: `reasoning-${i}` }, state);
|
|
27189
|
+
onReasoningDelta({ reasoningId: `reasoning-${i}`, text }, state);
|
|
27190
|
+
onReasoningEnd({ reasoningId: `reasoning-${i}` }, state);
|
|
27191
|
+
continue;
|
|
27192
|
+
}
|
|
27193
|
+
if (type3 === "tool_use" || type3 === "server_tool_use" || type3 === "mcp_tool_use") {
|
|
27194
|
+
const toolCallId = String(block.id ?? `tool-${i}`);
|
|
27195
|
+
const toolName = String(block.name ?? "unknown");
|
|
27196
|
+
onToolCall({ toolCallId, toolName }, state);
|
|
27197
|
+
}
|
|
27198
|
+
}
|
|
27199
|
+
}
|
|
27200
|
+
function projectUserToolResult(projector, message) {
|
|
27201
|
+
const state = projector.state;
|
|
27202
|
+
const content = message?.message?.content;
|
|
27203
|
+
if (!Array.isArray(content)) return;
|
|
27204
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
27205
|
+
const block = content[i];
|
|
27206
|
+
if (!block || typeof block !== "object") continue;
|
|
27207
|
+
if (block.type !== "tool_result") continue;
|
|
27208
|
+
const toolCallId = String(block.tool_use_id ?? `tool-${i}`);
|
|
27209
|
+
const extracted = extractToolResultText(block.content);
|
|
27210
|
+
if (extracted.hasNonTextBlock) {
|
|
27211
|
+
projector.richToolResultBlockCount += 1;
|
|
27212
|
+
if (!projector.supportsRichToolResult) {
|
|
27213
|
+
projector.downgradedToolResultCount += 1;
|
|
27214
|
+
}
|
|
27215
|
+
}
|
|
27216
|
+
onToolResult(
|
|
27217
|
+
{
|
|
27218
|
+
toolCallId,
|
|
27219
|
+
status: block.is_error ? "failed" : "completed",
|
|
27220
|
+
outputText: extracted.text
|
|
27221
|
+
},
|
|
27222
|
+
state
|
|
27223
|
+
);
|
|
27224
|
+
}
|
|
27225
|
+
}
|
|
27226
|
+
function projectProgressMessage(state, message) {
|
|
27227
|
+
const toolCallId = String(message?.toolUseID ?? "").trim();
|
|
27228
|
+
if (!toolCallId) return;
|
|
27229
|
+
const content = String(
|
|
27230
|
+
message?.content?.message?.content?.find?.((block) => block?.type === "text")?.text ?? ""
|
|
27231
|
+
);
|
|
27232
|
+
onToolResult(
|
|
27233
|
+
{
|
|
27234
|
+
toolCallId,
|
|
27235
|
+
status: "running",
|
|
27236
|
+
outputText: content || void 0
|
|
27237
|
+
},
|
|
27238
|
+
state
|
|
27239
|
+
);
|
|
27240
|
+
}
|
|
27241
|
+
function createStreamTypedProjector(options) {
|
|
27242
|
+
const provider = String(options.provider ?? "").trim().toLowerCase();
|
|
27243
|
+
return {
|
|
27244
|
+
state: createAssemblerState(options.requestId, options.source ?? "query_main"),
|
|
27245
|
+
provider,
|
|
27246
|
+
supportsRichToolResult: typeof options.supportsRichToolResult === "boolean" ? options.supportsRichToolResult : supportsRichToolResultByProvider(provider),
|
|
27247
|
+
richToolResultBlockCount: 0,
|
|
27248
|
+
downgradedToolResultCount: 0
|
|
27249
|
+
};
|
|
27250
|
+
}
|
|
27251
|
+
function consumeProjectorCompatibilityMetrics(projector) {
|
|
27252
|
+
const snapshot = {
|
|
27253
|
+
provider: projector.provider || "unknown",
|
|
27254
|
+
supportsRichToolResult: projector.supportsRichToolResult,
|
|
27255
|
+
richToolResultBlockCount: projector.richToolResultBlockCount,
|
|
27256
|
+
downgradedToolResultCount: projector.downgradedToolResultCount
|
|
27257
|
+
};
|
|
27258
|
+
projector.richToolResultBlockCount = 0;
|
|
27259
|
+
projector.downgradedToolResultCount = 0;
|
|
27260
|
+
return snapshot;
|
|
27261
|
+
}
|
|
27262
|
+
function projectMessageToTypedParts(projector, message) {
|
|
27263
|
+
if (!message || typeof message !== "object") return [];
|
|
27264
|
+
if (message.type === "assistant") {
|
|
27265
|
+
projectAssistantMessage(projector.state, message);
|
|
27266
|
+
} else if (message.type === "user") {
|
|
27267
|
+
projectUserToolResult(projector, message);
|
|
27268
|
+
} else if (message.type === "progress") {
|
|
27269
|
+
projectProgressMessage(projector.state, message);
|
|
27270
|
+
}
|
|
27271
|
+
return flushTypedParts(projector.state);
|
|
27272
|
+
}
|
|
27273
|
+
|
|
26804
27274
|
// src/utils/session/fileRecoveryCore.ts
|
|
26805
27275
|
var MAX_FILES_TO_RECOVER = 5;
|
|
26806
27276
|
var MAX_TOKENS_PER_FILE = 1e4;
|
|
@@ -26889,6 +27359,34 @@ function computeAutoCompactMetrics(events) {
|
|
|
26889
27359
|
crossReplayErrors,
|
|
26890
27360
|
crossReplayTotal
|
|
26891
27361
|
);
|
|
27362
|
+
const sessionTypedPathEvents = events.filter(
|
|
27363
|
+
(event) => event.phase === "SESSION_TYPED_PATH_APPLIED"
|
|
27364
|
+
);
|
|
27365
|
+
const sessionFallbackEvents = events.filter(
|
|
27366
|
+
(event) => event.phase === "SESSION_CANONICAL_FALLBACK_APPLIED"
|
|
27367
|
+
);
|
|
27368
|
+
const typed_primary_path_rate = sessionTypedPathEvents.length + sessionFallbackEvents.length > 0 ? safeDivide(
|
|
27369
|
+
sessionTypedPathEvents.length,
|
|
27370
|
+
sessionTypedPathEvents.length + sessionFallbackEvents.length
|
|
27371
|
+
) : void 0;
|
|
27372
|
+
const boundaryEvents = events.filter(
|
|
27373
|
+
(event) => event.phase === "COMPACTION_BOUNDARY_APPLIED"
|
|
27374
|
+
);
|
|
27375
|
+
const compaction_boundary_hit_rate = boundaryEvents.length > 0 ? safeDivide(
|
|
27376
|
+
boundaryEvents.filter((event) => event.data?.applied === true).length,
|
|
27377
|
+
boundaryEvents.length
|
|
27378
|
+
) : void 0;
|
|
27379
|
+
const replayOutcomeEvents = boundaryEvents.filter(
|
|
27380
|
+
(event) => ["replayed_latest_user_task", "synthetic_continue_prompt"].includes(
|
|
27381
|
+
String(event.data?.replayMode ?? "")
|
|
27382
|
+
)
|
|
27383
|
+
);
|
|
27384
|
+
const overflow_replay_success_rate = replayOutcomeEvents.length > 0 ? safeDivide(
|
|
27385
|
+
replayOutcomeEvents.filter(
|
|
27386
|
+
(event) => event.data?.replayMode === "replayed_latest_user_task"
|
|
27387
|
+
).length,
|
|
27388
|
+
replayOutcomeEvents.length
|
|
27389
|
+
) : void 0;
|
|
26892
27390
|
const sanitizerEvents = events.filter(
|
|
26893
27391
|
(event) => event.phase === "AUTO_COMPACT_SANITIZER_APPLIED"
|
|
26894
27392
|
);
|
|
@@ -26940,6 +27438,9 @@ function computeAutoCompactMetrics(events) {
|
|
|
26940
27438
|
compact_retry_success_rate,
|
|
26941
27439
|
thinking_first_ratio,
|
|
26942
27440
|
cross_model_replay_error_rate,
|
|
27441
|
+
typed_primary_path_rate,
|
|
27442
|
+
compaction_boundary_hit_rate,
|
|
27443
|
+
overflow_replay_success_rate,
|
|
26943
27444
|
noise_ratio_after_compaction,
|
|
26944
27445
|
task_goal_retention_rate,
|
|
26945
27446
|
result_fidelity_rate,
|
|
@@ -26975,7 +27476,13 @@ var AUTO_COMPACT_TELEMETRY_PHASES = /* @__PURE__ */ new Set([
|
|
|
26975
27476
|
"MESSAGE_TRANSFORM_APPLIED",
|
|
26976
27477
|
"AUTO_COMPACT_SANITIZER_APPLIED",
|
|
26977
27478
|
"AUTO_COMPACT_SUMMARY_QUALITY",
|
|
26978
|
-
"AUTO_COMPACT_BUDGET_APPLIED"
|
|
27479
|
+
"AUTO_COMPACT_BUDGET_APPLIED",
|
|
27480
|
+
"COMPACTION_BOUNDARY_APPLIED",
|
|
27481
|
+
"SESSION_TYPED_PATH_APPLIED",
|
|
27482
|
+
"SESSION_CANONICAL_FALLBACK_APPLIED",
|
|
27483
|
+
"SESSION_TYPED_PATH_CONSISTENCY_FAILED",
|
|
27484
|
+
"SESSION_TYPED_PATH_POLICY_APPLIED",
|
|
27485
|
+
"SESSION_TYPED_PATH_AUTO_DEGRADED"
|
|
26979
27486
|
]);
|
|
26980
27487
|
var AUTO_COMPACT_SINK_LISTENER_ID = "auto-compact-metrics-sink";
|
|
26981
27488
|
var autoCompactSink = createAutoCompactMetricsSink();
|
|
@@ -27226,35 +27733,35 @@ function getModelCapabilities(modelName) {
|
|
|
27226
27733
|
}
|
|
27227
27734
|
|
|
27228
27735
|
// src/services/ai/policyDispatch/policyConfigLoader.ts
|
|
27229
|
-
import { existsSync as
|
|
27736
|
+
import { existsSync as existsSync18, readFileSync as readFileSync14 } from "fs";
|
|
27230
27737
|
import { join as join14, resolve as resolve11 } from "path";
|
|
27231
27738
|
|
|
27232
27739
|
// src/services/ai/policyDispatch/policyConfigSchema.ts
|
|
27233
|
-
import { z as
|
|
27234
|
-
var policyConfigSchema =
|
|
27235
|
-
version:
|
|
27236
|
-
defaults:
|
|
27237
|
-
reasoningPolicy:
|
|
27740
|
+
import { z as z12 } from "zod";
|
|
27741
|
+
var policyConfigSchema = z12.object({
|
|
27742
|
+
version: z12.string().min(1),
|
|
27743
|
+
defaults: z12.object({
|
|
27744
|
+
reasoningPolicy: z12.enum([
|
|
27238
27745
|
"preserve_reasoning_blocks",
|
|
27239
27746
|
"map_to_provider_options",
|
|
27240
27747
|
"flatten_to_text_fallback"
|
|
27241
27748
|
]).optional(),
|
|
27242
|
-
normalizeProviderContent:
|
|
27243
|
-
trimCrossModelMetadata:
|
|
27749
|
+
normalizeProviderContent: z12.boolean().optional(),
|
|
27750
|
+
trimCrossModelMetadata: z12.boolean().optional()
|
|
27244
27751
|
}).optional(),
|
|
27245
|
-
overrides:
|
|
27246
|
-
|
|
27247
|
-
model:
|
|
27248
|
-
modelFamily:
|
|
27249
|
-
provider:
|
|
27250
|
-
scenario:
|
|
27251
|
-
reasoningPolicy:
|
|
27752
|
+
overrides: z12.array(
|
|
27753
|
+
z12.object({
|
|
27754
|
+
model: z12.string().min(1).optional(),
|
|
27755
|
+
modelFamily: z12.string().min(1).optional(),
|
|
27756
|
+
provider: z12.string().min(1).optional(),
|
|
27757
|
+
scenario: z12.enum(["query", "auto_compact", "other"]).optional(),
|
|
27758
|
+
reasoningPolicy: z12.enum([
|
|
27252
27759
|
"preserve_reasoning_blocks",
|
|
27253
27760
|
"map_to_provider_options",
|
|
27254
27761
|
"flatten_to_text_fallback"
|
|
27255
27762
|
]).optional(),
|
|
27256
|
-
normalizeProviderContent:
|
|
27257
|
-
trimCrossModelMetadata:
|
|
27763
|
+
normalizeProviderContent: z12.boolean().optional(),
|
|
27764
|
+
trimCrossModelMetadata: z12.boolean().optional()
|
|
27258
27765
|
})
|
|
27259
27766
|
).optional().default([])
|
|
27260
27767
|
});
|
|
@@ -27273,9 +27780,9 @@ function getDefaultPolicyConfigPath() {
|
|
|
27273
27780
|
}
|
|
27274
27781
|
function loadAutoCompactPolicyConfig(options) {
|
|
27275
27782
|
const filePath = resolve11(options?.filePath ?? getDefaultPolicyConfigPath());
|
|
27276
|
-
if (!
|
|
27783
|
+
if (!existsSync18(filePath)) return null;
|
|
27277
27784
|
try {
|
|
27278
|
-
const raw =
|
|
27785
|
+
const raw = readFileSync14(filePath, "utf8");
|
|
27279
27786
|
const parsed = JSON.parse(raw);
|
|
27280
27787
|
return policyConfigSchema.parse(parsed);
|
|
27281
27788
|
} catch {
|
|
@@ -27361,218 +27868,6 @@ function resolveModelResponsePolicy(input) {
|
|
|
27361
27868
|
};
|
|
27362
27869
|
}
|
|
27363
27870
|
|
|
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
27871
|
// src/services/ai/streamTyped/replay.ts
|
|
27577
27872
|
function toNonEmptyText(value) {
|
|
27578
27873
|
const text = String(value ?? "").trim();
|
|
@@ -28278,7 +28573,7 @@ function getSummaryContentDiagnostics(content) {
|
|
|
28278
28573
|
value: content
|
|
28279
28574
|
};
|
|
28280
28575
|
}
|
|
28281
|
-
function
|
|
28576
|
+
function extractToolResultText2(content) {
|
|
28282
28577
|
if (typeof content === "string") return content;
|
|
28283
28578
|
if (!Array.isArray(content)) return "";
|
|
28284
28579
|
return content.filter((block) => block && typeof block === "object" && block.type === "text").map((block) => String(block.text ?? "")).join("\n");
|
|
@@ -28289,6 +28584,11 @@ function parseBooleanFlag(value) {
|
|
|
28289
28584
|
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
28290
28585
|
return null;
|
|
28291
28586
|
}
|
|
28587
|
+
function parseNumberFlag(value) {
|
|
28588
|
+
const parsed = Number(value);
|
|
28589
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
28590
|
+
return parsed;
|
|
28591
|
+
}
|
|
28292
28592
|
function resolveTypedReadPathConfig(toolUseContext) {
|
|
28293
28593
|
const envValue = parseBooleanFlag(
|
|
28294
28594
|
process.env.PYB_AUTO_COMPACT_TYPED_READ_PATH_ENABLED
|
|
@@ -28310,6 +28610,49 @@ function resolveTypedReadPathConfig(toolUseContext) {
|
|
|
28310
28610
|
source: "default"
|
|
28311
28611
|
};
|
|
28312
28612
|
}
|
|
28613
|
+
function resolveTypedPathPolicyConfig(toolUseContext) {
|
|
28614
|
+
const policy = toolUseContext?.typedPathPolicy ?? {};
|
|
28615
|
+
const envMinPrimaryPathRate = parseNumberFlag(
|
|
28616
|
+
process.env.PYB_AUTO_COMPACT_TYPED_PATH_MIN_PRIMARY_RATE
|
|
28617
|
+
);
|
|
28618
|
+
const envMaxFallbackAnomalyStreak = parseNumberFlag(
|
|
28619
|
+
process.env.PYB_AUTO_COMPACT_TYPED_PATH_MAX_FALLBACK_STREAK
|
|
28620
|
+
);
|
|
28621
|
+
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;
|
|
28622
|
+
const observedPrimaryPathRate = Number.isFinite(policy?.observedPrimaryPathRate) ? Math.min(1, Math.max(0, Number(policy.observedPrimaryPathRate))) : void 0;
|
|
28623
|
+
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;
|
|
28624
|
+
const currentFallbackAnomalyStreak = Number.isFinite(
|
|
28625
|
+
policy?.currentFallbackAnomalyStreak
|
|
28626
|
+
) ? Math.max(0, Math.floor(Number(policy.currentFallbackAnomalyStreak))) : 0;
|
|
28627
|
+
return {
|
|
28628
|
+
minPrimaryPathRate,
|
|
28629
|
+
observedPrimaryPathRate,
|
|
28630
|
+
maxFallbackAnomalyStreak,
|
|
28631
|
+
currentFallbackAnomalyStreak
|
|
28632
|
+
};
|
|
28633
|
+
}
|
|
28634
|
+
function evaluateTypedPathPolicyDecision(config2) {
|
|
28635
|
+
if (Number.isFinite(config2.minPrimaryPathRate) && Number.isFinite(config2.observedPrimaryPathRate) && Number(config2.observedPrimaryPathRate) < Number(config2.minPrimaryPathRate)) {
|
|
28636
|
+
return {
|
|
28637
|
+
forceFallback: true,
|
|
28638
|
+
reason: "promotion_threshold_not_met"
|
|
28639
|
+
};
|
|
28640
|
+
}
|
|
28641
|
+
if (Number.isFinite(config2.maxFallbackAnomalyStreak) && config2.currentFallbackAnomalyStreak >= Number(config2.maxFallbackAnomalyStreak)) {
|
|
28642
|
+
return {
|
|
28643
|
+
forceFallback: true,
|
|
28644
|
+
reason: "fallback_anomaly_streak"
|
|
28645
|
+
};
|
|
28646
|
+
}
|
|
28647
|
+
return {
|
|
28648
|
+
forceFallback: false,
|
|
28649
|
+
reason: "policy_not_triggered"
|
|
28650
|
+
};
|
|
28651
|
+
}
|
|
28652
|
+
function emitSessionReadPathEvent(phase, payload) {
|
|
28653
|
+
debug.warn(phase, payload);
|
|
28654
|
+
emitAutoCompactTelemetryEvent(phase, payload);
|
|
28655
|
+
}
|
|
28313
28656
|
function emitStreamTypedPartsFromContent(content, requestId) {
|
|
28314
28657
|
const state = createAssemblerState(requestId);
|
|
28315
28658
|
if (typeof content === "string") {
|
|
@@ -28345,7 +28688,7 @@ function emitStreamTypedPartsFromContent(content, requestId) {
|
|
|
28345
28688
|
}
|
|
28346
28689
|
if (type3 === "tool_result") {
|
|
28347
28690
|
const toolCallId = String(block.tool_use_id ?? `tool-${i}`);
|
|
28348
|
-
const outputText =
|
|
28691
|
+
const outputText = extractToolResultText2(block.content);
|
|
28349
28692
|
onToolResult(
|
|
28350
28693
|
{
|
|
28351
28694
|
toolCallId,
|
|
@@ -28490,9 +28833,24 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28490
28833
|
enabled: typedPath.enabled,
|
|
28491
28834
|
parts: emittedTypedParts
|
|
28492
28835
|
});
|
|
28836
|
+
const typedPathPolicyConfig = resolveTypedPathPolicyConfig(toolUseContext);
|
|
28837
|
+
const typedPathPolicyDecision = evaluateTypedPathPolicyDecision(
|
|
28838
|
+
typedPathPolicyConfig
|
|
28839
|
+
);
|
|
28840
|
+
const hasTypedPolicy = Number.isFinite(typedPathPolicyConfig.minPrimaryPathRate) || Number.isFinite(typedPathPolicyConfig.maxFallbackAnomalyStreak);
|
|
28841
|
+
if (typedPath.enabled && hasTypedPolicy) {
|
|
28842
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_POLICY_APPLIED", {
|
|
28843
|
+
forceFallback: typedPathPolicyDecision.forceFallback,
|
|
28844
|
+
reason: typedPathPolicyDecision.reason,
|
|
28845
|
+
minPrimaryPathRate: typedPathPolicyConfig.minPrimaryPathRate,
|
|
28846
|
+
observedPrimaryPathRate: typedPathPolicyConfig.observedPrimaryPathRate,
|
|
28847
|
+
maxFallbackAnomalyStreak: typedPathPolicyConfig.maxFallbackAnomalyStreak,
|
|
28848
|
+
currentFallbackAnomalyStreak: typedPathPolicyConfig.currentFallbackAnomalyStreak
|
|
28849
|
+
});
|
|
28850
|
+
}
|
|
28493
28851
|
let canonicalResult = null;
|
|
28494
28852
|
let summary = null;
|
|
28495
|
-
if (typedPath.enabled && typedReplay.isComplete && typedReplay.summaryText) {
|
|
28853
|
+
if (typedPath.enabled && typedReplay.isComplete && typedReplay.summaryText && !typedPathPolicyDecision.forceFallback) {
|
|
28496
28854
|
summary = typedReplay.summaryText;
|
|
28497
28855
|
const typedAppliedPayload = {
|
|
28498
28856
|
mode: "typed",
|
|
@@ -28506,7 +28864,30 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28506
28864
|
"AUTO_COMPACT_TYPED_PATH_APPLIED",
|
|
28507
28865
|
typedAppliedPayload
|
|
28508
28866
|
);
|
|
28867
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_APPLIED", typedAppliedPayload);
|
|
28868
|
+
if (toolUseContext) {
|
|
28869
|
+
toolUseContext.typedPathPolicy = {
|
|
28870
|
+
...toolUseContext.typedPathPolicy ?? {},
|
|
28871
|
+
currentFallbackAnomalyStreak: 0
|
|
28872
|
+
};
|
|
28873
|
+
}
|
|
28509
28874
|
} else {
|
|
28875
|
+
if (typedPath.enabled && typedPathPolicyDecision.forceFallback && typedPathPolicyDecision.reason === "fallback_anomaly_streak") {
|
|
28876
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_AUTO_DEGRADED", {
|
|
28877
|
+
reason: typedPathPolicyDecision.reason,
|
|
28878
|
+
currentFallbackAnomalyStreak: typedPathPolicyConfig.currentFallbackAnomalyStreak,
|
|
28879
|
+
maxFallbackAnomalyStreak: typedPathPolicyConfig.maxFallbackAnomalyStreak
|
|
28880
|
+
});
|
|
28881
|
+
}
|
|
28882
|
+
if (typedPath.enabled && typedReplay.isComplete && !typedReplay.summaryText) {
|
|
28883
|
+
emitSessionReadPathEvent("SESSION_TYPED_PATH_CONSISTENCY_FAILED", {
|
|
28884
|
+
mode: "typed_incomplete_payload",
|
|
28885
|
+
pathSource: typedPath.source,
|
|
28886
|
+
reason: typedReplay.reason,
|
|
28887
|
+
textPartCount: typedReplay.textPartCount,
|
|
28888
|
+
reasoningPartCount: typedReplay.reasoningPartCount
|
|
28889
|
+
});
|
|
28890
|
+
}
|
|
28510
28891
|
canonicalResult = normalizeModelResponseContent(content, {
|
|
28511
28892
|
source: "auto_compact",
|
|
28512
28893
|
model: activeModelName,
|
|
@@ -28519,7 +28900,7 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28519
28900
|
mode: typedPath.enabled ? "canonical_fallback" : "canonical_disabled",
|
|
28520
28901
|
pathSource: typedPath.source,
|
|
28521
28902
|
...typedPath.enabled ? {
|
|
28522
|
-
reason: typedReplay.reason,
|
|
28903
|
+
reason: typedPathPolicyDecision.forceFallback ? typedPathPolicyDecision.reason : typedReplay.reason,
|
|
28523
28904
|
textPartCount: typedReplay.textPartCount,
|
|
28524
28905
|
reasoningPartCount: typedReplay.reasoningPartCount
|
|
28525
28906
|
} : {}
|
|
@@ -28529,6 +28910,18 @@ ${COMPRESSION_PROMPT2}` : COMPRESSION_PROMPT2;
|
|
|
28529
28910
|
"AUTO_COMPACT_TYPED_PATH_APPLIED",
|
|
28530
28911
|
typedAppliedPayload
|
|
28531
28912
|
);
|
|
28913
|
+
if (typedPath.enabled) {
|
|
28914
|
+
emitSessionReadPathEvent(
|
|
28915
|
+
"SESSION_CANONICAL_FALLBACK_APPLIED",
|
|
28916
|
+
typedAppliedPayload
|
|
28917
|
+
);
|
|
28918
|
+
if (toolUseContext) {
|
|
28919
|
+
toolUseContext.typedPathPolicy = {
|
|
28920
|
+
...toolUseContext.typedPathPolicy ?? {},
|
|
28921
|
+
currentFallbackAnomalyStreak: typedPathPolicyConfig.currentFallbackAnomalyStreak + 1
|
|
28922
|
+
};
|
|
28923
|
+
}
|
|
28924
|
+
}
|
|
28532
28925
|
}
|
|
28533
28926
|
if (!summary) {
|
|
28534
28927
|
debug.warn("AUTO_COMPACT_SUMMARY_CONTENT_INVALID", {
|
|
@@ -28708,6 +29101,637 @@ ${contentWithLines}
|
|
|
28708
29101
|
return budgetApplied.messages;
|
|
28709
29102
|
}
|
|
28710
29103
|
|
|
29104
|
+
// src/utils/session/compactionBoundary.ts
|
|
29105
|
+
function parseBooleanFlag2(value) {
|
|
29106
|
+
const raw = String(value ?? "").trim().toLowerCase();
|
|
29107
|
+
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
29108
|
+
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
29109
|
+
return null;
|
|
29110
|
+
}
|
|
29111
|
+
function resolveCompactionBoundaryConfig(toolUseContext) {
|
|
29112
|
+
const envValue = parseBooleanFlag2(process.env.PYB_COMPACTION_BOUNDARY_ENABLED);
|
|
29113
|
+
if (envValue !== null) {
|
|
29114
|
+
return {
|
|
29115
|
+
enabled: envValue,
|
|
29116
|
+
source: "env"
|
|
29117
|
+
};
|
|
29118
|
+
}
|
|
29119
|
+
if (typeof toolUseContext?.compactionBoundaryEnabled === "boolean") {
|
|
29120
|
+
return {
|
|
29121
|
+
enabled: toolUseContext.compactionBoundaryEnabled,
|
|
29122
|
+
source: "context"
|
|
29123
|
+
};
|
|
29124
|
+
}
|
|
29125
|
+
return {
|
|
29126
|
+
enabled: false,
|
|
29127
|
+
source: "default"
|
|
29128
|
+
};
|
|
29129
|
+
}
|
|
29130
|
+
function findLastCompactionBoundaryIndex(messages) {
|
|
29131
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
29132
|
+
const message = messages[i];
|
|
29133
|
+
if (message?.type === "assistant" && message?.compaction?.type === "compaction") {
|
|
29134
|
+
return i;
|
|
29135
|
+
}
|
|
29136
|
+
}
|
|
29137
|
+
return -1;
|
|
29138
|
+
}
|
|
29139
|
+
function filterAfterCompactionBoundary(messages, options) {
|
|
29140
|
+
const getMessageText4 = (message) => {
|
|
29141
|
+
if (message.type !== "user") return "";
|
|
29142
|
+
const content = message?.message?.content;
|
|
29143
|
+
if (typeof content === "string") return content.trim();
|
|
29144
|
+
if (!Array.isArray(content)) return "";
|
|
29145
|
+
return content.filter(
|
|
29146
|
+
(block) => block && typeof block === "object" && block.type === "text"
|
|
29147
|
+
).map((block) => String(block.text ?? "")).join("\n").trim();
|
|
29148
|
+
};
|
|
29149
|
+
const isAutoCompactNotice2 = (message) => getMessageText4(message).includes("Context automatically compressed due to token limit.");
|
|
29150
|
+
const isRecoveredFileMessage2 = (message) => getMessageText4(message).includes("**Recovered File:");
|
|
29151
|
+
const isReplayableUserTask = (message) => {
|
|
29152
|
+
const text = getMessageText4(message);
|
|
29153
|
+
if (!text) return false;
|
|
29154
|
+
if (isAutoCompactNotice2(message)) return false;
|
|
29155
|
+
if (isRecoveredFileMessage2(message)) return false;
|
|
29156
|
+
return true;
|
|
29157
|
+
};
|
|
29158
|
+
if (!options.enabled) {
|
|
29159
|
+
return {
|
|
29160
|
+
messages,
|
|
29161
|
+
applied: false,
|
|
29162
|
+
droppedMessageCount: 0,
|
|
29163
|
+
preservedMessageCount: messages.length,
|
|
29164
|
+
lastCompactionIndex: -1,
|
|
29165
|
+
replayMode: "not_applied"
|
|
29166
|
+
};
|
|
29167
|
+
}
|
|
29168
|
+
const lastCompactionIndex = findLastCompactionBoundaryIndex(messages);
|
|
29169
|
+
if (lastCompactionIndex < 0) {
|
|
29170
|
+
return {
|
|
29171
|
+
messages,
|
|
29172
|
+
applied: false,
|
|
29173
|
+
droppedMessageCount: 0,
|
|
29174
|
+
preservedMessageCount: messages.length,
|
|
29175
|
+
lastCompactionIndex: -1,
|
|
29176
|
+
replayMode: "not_applied"
|
|
29177
|
+
};
|
|
29178
|
+
}
|
|
29179
|
+
const filtered = messages.slice(lastCompactionIndex);
|
|
29180
|
+
const hasUserTask = filtered.some((item) => isReplayableUserTask(item));
|
|
29181
|
+
if (hasUserTask) {
|
|
29182
|
+
return {
|
|
29183
|
+
messages: filtered,
|
|
29184
|
+
applied: true,
|
|
29185
|
+
droppedMessageCount: Math.max(0, messages.length - filtered.length),
|
|
29186
|
+
preservedMessageCount: filtered.length,
|
|
29187
|
+
lastCompactionIndex,
|
|
29188
|
+
replayMode: "already_has_user_task"
|
|
29189
|
+
};
|
|
29190
|
+
}
|
|
29191
|
+
let replayText = "";
|
|
29192
|
+
for (let i = lastCompactionIndex - 1; i >= 0; i -= 1) {
|
|
29193
|
+
const message = messages[i];
|
|
29194
|
+
if (!isReplayableUserTask(message)) continue;
|
|
29195
|
+
replayText = getMessageText4(message);
|
|
29196
|
+
break;
|
|
29197
|
+
}
|
|
29198
|
+
const replayMessage = replayText ? createUserMessage(replayText) : createUserMessage(
|
|
29199
|
+
"Continue from compressed context and ask a brief clarifying question if the task objective is missing."
|
|
29200
|
+
);
|
|
29201
|
+
const withReplay = [...filtered, replayMessage];
|
|
29202
|
+
return {
|
|
29203
|
+
messages: withReplay,
|
|
29204
|
+
applied: true,
|
|
29205
|
+
droppedMessageCount: Math.max(0, messages.length - withReplay.length),
|
|
29206
|
+
preservedMessageCount: withReplay.length,
|
|
29207
|
+
lastCompactionIndex,
|
|
29208
|
+
replayMode: replayText ? "replayed_latest_user_task" : "synthetic_continue_prompt"
|
|
29209
|
+
};
|
|
29210
|
+
}
|
|
29211
|
+
|
|
29212
|
+
// src/utils/session/toolOutputLifecycle.ts
|
|
29213
|
+
function parseBooleanFlag3(value) {
|
|
29214
|
+
const raw = String(value ?? "").trim().toLowerCase();
|
|
29215
|
+
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
29216
|
+
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
29217
|
+
return null;
|
|
29218
|
+
}
|
|
29219
|
+
function resolveToolOutputLifecycleConfig(toolUseContext) {
|
|
29220
|
+
const envValue = parseBooleanFlag3(process.env.PYB_TOOL_OUTPUT_LIFECYCLE_ENABLED);
|
|
29221
|
+
const enabled = envValue !== null ? envValue : typeof toolUseContext?.toolOutputLifecycleEnabled === "boolean" ? toolUseContext.toolOutputLifecycleEnabled : false;
|
|
29222
|
+
const source = envValue !== null ? "env" : typeof toolUseContext?.toolOutputLifecycleEnabled === "boolean" ? "context" : "default";
|
|
29223
|
+
const maxAgeTurnsRaw = toolUseContext?.toolOutputLifecycleConfig?.maxAgeTurns ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_MAX_AGE_TURNS;
|
|
29224
|
+
const protectFailedRaw = toolUseContext?.toolOutputLifecycleConfig?.protectFailedResultTurns ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_PROTECT_FAILED_TURNS;
|
|
29225
|
+
const maxAgeTurns = Number.isFinite(Number(maxAgeTurnsRaw)) ? Math.max(1, Number(maxAgeTurnsRaw)) : 3;
|
|
29226
|
+
const protectFailedResultTurns = Number.isFinite(Number(protectFailedRaw)) ? Math.max(1, Number(protectFailedRaw)) : 6;
|
|
29227
|
+
const l3AgeTurnsRaw = toolUseContext?.toolOutputLifecycleConfig?.l3AgeTurns ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_L3_AGE_TURNS;
|
|
29228
|
+
const l1MinCharsRaw = toolUseContext?.toolOutputLifecycleConfig?.l1MinChars ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_L1_MIN_CHARS;
|
|
29229
|
+
const l3MinCharsRaw = toolUseContext?.toolOutputLifecycleConfig?.l3MinChars ?? process.env.PYB_TOOL_OUTPUT_LIFECYCLE_L3_MIN_CHARS;
|
|
29230
|
+
const l3AgeTurns = Number.isFinite(Number(l3AgeTurnsRaw)) ? Math.max(maxAgeTurns + 1, Number(l3AgeTurnsRaw)) : Math.max(maxAgeTurns + 2, 6);
|
|
29231
|
+
const l1MinChars = Number.isFinite(Number(l1MinCharsRaw)) ? Math.max(120, Number(l1MinCharsRaw)) : 500;
|
|
29232
|
+
const l3MinChars = Number.isFinite(Number(l3MinCharsRaw)) ? Math.max(l1MinChars, Number(l3MinCharsRaw)) : 1800;
|
|
29233
|
+
return {
|
|
29234
|
+
enabled,
|
|
29235
|
+
source,
|
|
29236
|
+
maxAgeTurns,
|
|
29237
|
+
protectFailedResultTurns,
|
|
29238
|
+
l3AgeTurns,
|
|
29239
|
+
l1MinChars,
|
|
29240
|
+
l3MinChars
|
|
29241
|
+
};
|
|
29242
|
+
}
|
|
29243
|
+
function getMessageText3(message) {
|
|
29244
|
+
const content = message?.message?.content;
|
|
29245
|
+
if (typeof content === "string") return content.trim();
|
|
29246
|
+
if (!Array.isArray(content)) return "";
|
|
29247
|
+
return content.filter((block) => block && typeof block === "object" && block.type === "text").map((block) => String(block.text ?? "")).join("\n").trim();
|
|
29248
|
+
}
|
|
29249
|
+
function isNaturalUserMessage(message) {
|
|
29250
|
+
if (message.type !== "user") return false;
|
|
29251
|
+
const content = message?.message?.content;
|
|
29252
|
+
if (typeof content === "string") return content.trim().length > 0;
|
|
29253
|
+
if (!Array.isArray(content)) return false;
|
|
29254
|
+
const hasToolResultOnly = content.every(
|
|
29255
|
+
(block) => block && typeof block === "object" && block.type === "tool_result"
|
|
29256
|
+
);
|
|
29257
|
+
if (hasToolResultOnly) return false;
|
|
29258
|
+
const text = getMessageText3(message);
|
|
29259
|
+
return text.length > 0;
|
|
29260
|
+
}
|
|
29261
|
+
function extractLifecycleSignals(text) {
|
|
29262
|
+
const lines = text.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
29263
|
+
const fields = ["targets:", "keyfacts:", "errors:"];
|
|
29264
|
+
return lines.filter(
|
|
29265
|
+
(line) => fields.some((field) => line.toLowerCase().startsWith(field))
|
|
29266
|
+
);
|
|
29267
|
+
}
|
|
29268
|
+
function extractStatusSignal(text) {
|
|
29269
|
+
const line = text.split("\n").map((item) => item.trim()).find((item) => item.toLowerCase().startsWith("status:"));
|
|
29270
|
+
return line || "status: unknown";
|
|
29271
|
+
}
|
|
29272
|
+
function estimateTokens2(text) {
|
|
29273
|
+
return Math.max(1, Math.ceil(String(text ?? "").length * 0.25));
|
|
29274
|
+
}
|
|
29275
|
+
function estimateMessageTokens(message) {
|
|
29276
|
+
const content = message?.message?.content;
|
|
29277
|
+
if (typeof content === "string") {
|
|
29278
|
+
return estimateTokens2(content);
|
|
29279
|
+
}
|
|
29280
|
+
if (Array.isArray(content)) {
|
|
29281
|
+
const text = content.map((block) => {
|
|
29282
|
+
if (!block || typeof block !== "object") return "";
|
|
29283
|
+
if (typeof block.text === "string") return block.text;
|
|
29284
|
+
if (typeof block.content === "string") return block.content;
|
|
29285
|
+
return "";
|
|
29286
|
+
}).filter(Boolean).join("\n");
|
|
29287
|
+
return estimateTokens2(text);
|
|
29288
|
+
}
|
|
29289
|
+
return 1;
|
|
29290
|
+
}
|
|
29291
|
+
function estimateMessagesTokens(messages) {
|
|
29292
|
+
return messages.reduce((sum, message) => sum + estimateMessageTokens(message), 0);
|
|
29293
|
+
}
|
|
29294
|
+
function countToolResultBlocks(messages) {
|
|
29295
|
+
return messages.reduce((sum, message) => {
|
|
29296
|
+
if (message.type !== "user") return sum;
|
|
29297
|
+
const content = message?.message?.content;
|
|
29298
|
+
if (!Array.isArray(content)) return sum;
|
|
29299
|
+
return sum + content.filter(
|
|
29300
|
+
(block) => block && typeof block === "object" && block.type === "tool_result"
|
|
29301
|
+
).length;
|
|
29302
|
+
}, 0);
|
|
29303
|
+
}
|
|
29304
|
+
function buildDanglingClosureMessage(toolUseId) {
|
|
29305
|
+
return {
|
|
29306
|
+
type: "user",
|
|
29307
|
+
uuid: `dangling_${toolUseId}_${Date.now()}`,
|
|
29308
|
+
message: {
|
|
29309
|
+
role: "user",
|
|
29310
|
+
content: [
|
|
29311
|
+
{
|
|
29312
|
+
type: "tool_result",
|
|
29313
|
+
tool_use_id: toolUseId,
|
|
29314
|
+
is_error: true,
|
|
29315
|
+
error_class: "fatal",
|
|
29316
|
+
content: "status: interrupted\nerrors: dangling tool_use closed before replay\nkeyFacts: replay-safe closure applied\ntargets: none"
|
|
29317
|
+
}
|
|
29318
|
+
]
|
|
29319
|
+
}
|
|
29320
|
+
};
|
|
29321
|
+
}
|
|
29322
|
+
function closeDanglingToolUseBeforeReplay(messages) {
|
|
29323
|
+
const used = /* @__PURE__ */ new Set();
|
|
29324
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
29325
|
+
for (const message of messages) {
|
|
29326
|
+
if (message.type === "assistant") {
|
|
29327
|
+
const content = message?.message?.content;
|
|
29328
|
+
if (Array.isArray(content)) {
|
|
29329
|
+
for (const block of content) {
|
|
29330
|
+
if (!block || typeof block !== "object") continue;
|
|
29331
|
+
if (block.type === "tool_use" || block.type === "server_tool_use" || block.type === "mcp_tool_use") {
|
|
29332
|
+
const id = String(block.id ?? "").trim();
|
|
29333
|
+
if (id) used.add(id);
|
|
29334
|
+
}
|
|
29335
|
+
}
|
|
29336
|
+
}
|
|
29337
|
+
} else if (message.type === "user") {
|
|
29338
|
+
const content = message?.message?.content;
|
|
29339
|
+
if (!Array.isArray(content)) continue;
|
|
29340
|
+
for (const block of content) {
|
|
29341
|
+
if (!block || typeof block !== "object" || block.type !== "tool_result") continue;
|
|
29342
|
+
const id = String(block.tool_use_id ?? "").trim();
|
|
29343
|
+
if (id) resolved.add(id);
|
|
29344
|
+
}
|
|
29345
|
+
}
|
|
29346
|
+
}
|
|
29347
|
+
const dangling = Array.from(used).filter((id) => !resolved.has(id));
|
|
29348
|
+
if (dangling.length === 0) {
|
|
29349
|
+
return { messages, detected: 0, closed: 0 };
|
|
29350
|
+
}
|
|
29351
|
+
const closures = dangling.map((id) => buildDanglingClosureMessage(id));
|
|
29352
|
+
return {
|
|
29353
|
+
messages: [...messages, ...closures],
|
|
29354
|
+
detected: dangling.length,
|
|
29355
|
+
closed: closures.length
|
|
29356
|
+
};
|
|
29357
|
+
}
|
|
29358
|
+
function applyToolOutputLifecycle(messages, options) {
|
|
29359
|
+
const l3AgeTurns = Math.max(
|
|
29360
|
+
options.maxAgeTurns + 1,
|
|
29361
|
+
options.l3AgeTurns ?? Math.max(options.maxAgeTurns + 2, 6)
|
|
29362
|
+
);
|
|
29363
|
+
const l1MinChars = Math.max(120, options.l1MinChars ?? 500);
|
|
29364
|
+
const l3MinChars = Math.max(l1MinChars, options.l3MinChars ?? 1800);
|
|
29365
|
+
const shouldCloseDangling = options.closeDanglingToolUseBeforeReplay ?? true;
|
|
29366
|
+
const closureResult = shouldCloseDangling ? closeDanglingToolUseBeforeReplay(messages) : { messages, detected: 0, closed: 0 };
|
|
29367
|
+
const messagesForAging = closureResult.messages;
|
|
29368
|
+
const beforeTokens = estimateMessagesTokens(messagesForAging);
|
|
29369
|
+
const totalToolResultBlocksBefore = countToolResultBlocks(messagesForAging);
|
|
29370
|
+
if (!options.enabled) {
|
|
29371
|
+
return {
|
|
29372
|
+
messages: messagesForAging,
|
|
29373
|
+
report: {
|
|
29374
|
+
applied: false,
|
|
29375
|
+
agedBlocks: 0,
|
|
29376
|
+
skippedFailedBlocks: 0,
|
|
29377
|
+
protectedBlocks: 0,
|
|
29378
|
+
totalToolResultBlocksBefore,
|
|
29379
|
+
totalToolResultBlocksAfter: totalToolResultBlocksBefore,
|
|
29380
|
+
l1Blocks: 0,
|
|
29381
|
+
l2Blocks: 0,
|
|
29382
|
+
l3Blocks: 0,
|
|
29383
|
+
danglingDetected: closureResult.detected,
|
|
29384
|
+
danglingClosed: closureResult.closed,
|
|
29385
|
+
beforeTokens,
|
|
29386
|
+
afterTokens: beforeTokens,
|
|
29387
|
+
tokenDelta: 0
|
|
29388
|
+
}
|
|
29389
|
+
};
|
|
29390
|
+
}
|
|
29391
|
+
const naturalTurnsAfter = new Array(messagesForAging.length).fill(0);
|
|
29392
|
+
let runningTurns = 0;
|
|
29393
|
+
for (let i = messagesForAging.length - 1; i >= 0; i -= 1) {
|
|
29394
|
+
naturalTurnsAfter[i] = runningTurns;
|
|
29395
|
+
if (isNaturalUserMessage(messagesForAging[i])) {
|
|
29396
|
+
runningTurns += 1;
|
|
29397
|
+
}
|
|
29398
|
+
}
|
|
29399
|
+
let agedBlocks = 0;
|
|
29400
|
+
let skippedFailedBlocks = 0;
|
|
29401
|
+
let protectedBlocks = 0;
|
|
29402
|
+
let l1Blocks = 0;
|
|
29403
|
+
let l2Blocks = 0;
|
|
29404
|
+
let l3Blocks = 0;
|
|
29405
|
+
const nextMessages = messagesForAging.map((message, index) => {
|
|
29406
|
+
if (message.type !== "user") return message;
|
|
29407
|
+
const content = message?.message?.content;
|
|
29408
|
+
if (!Array.isArray(content)) return message;
|
|
29409
|
+
let changed = false;
|
|
29410
|
+
const nextContent = content.map((block) => {
|
|
29411
|
+
if (!block || typeof block !== "object" || block.type !== "tool_result") {
|
|
29412
|
+
return block;
|
|
29413
|
+
}
|
|
29414
|
+
const ageTurns = naturalTurnsAfter[index];
|
|
29415
|
+
if (ageTurns <= options.maxAgeTurns) {
|
|
29416
|
+
return block;
|
|
29417
|
+
}
|
|
29418
|
+
const isError = Boolean(block.is_error);
|
|
29419
|
+
if (isError && ageTurns <= options.protectFailedResultTurns) {
|
|
29420
|
+
skippedFailedBlocks += 1;
|
|
29421
|
+
return block;
|
|
29422
|
+
}
|
|
29423
|
+
const rawText = typeof block.content === "string" ? block.content : Array.isArray(block.content) ? block.content.filter(
|
|
29424
|
+
(item) => item && typeof item === "object" && item.type === "text"
|
|
29425
|
+
).map((item) => String(item.text ?? "")).join("\n") : "";
|
|
29426
|
+
const signals = extractLifecycleSignals(rawText);
|
|
29427
|
+
const status = extractStatusSignal(rawText);
|
|
29428
|
+
const normalizedSignals = signals.length > 0 ? signals : ["targets: none", "keyFacts: none", "errors: none"];
|
|
29429
|
+
let lifecycleLevel = "L2";
|
|
29430
|
+
if (ageTurns >= l3AgeTurns && rawText.length >= l3MinChars) {
|
|
29431
|
+
lifecycleLevel = "L3";
|
|
29432
|
+
} else if (rawText.length >= l1MinChars) {
|
|
29433
|
+
lifecycleLevel = "L1";
|
|
29434
|
+
}
|
|
29435
|
+
const placeholder = (lifecycleLevel === "L3" ? [
|
|
29436
|
+
"[Tool output aged]",
|
|
29437
|
+
"lifecycleLevel: L3",
|
|
29438
|
+
`toolUseId: ${String(block.tool_use_id ?? "")}`,
|
|
29439
|
+
`ageTurns: ${ageTurns}`,
|
|
29440
|
+
status,
|
|
29441
|
+
...normalizedSignals,
|
|
29442
|
+
"content: audit-index-only"
|
|
29443
|
+
] : lifecycleLevel === "L1" ? [
|
|
29444
|
+
"[Tool output aged]",
|
|
29445
|
+
"lifecycleLevel: L1",
|
|
29446
|
+
`ageTurns: ${ageTurns}`,
|
|
29447
|
+
status,
|
|
29448
|
+
...normalizedSignals,
|
|
29449
|
+
"content: summarized"
|
|
29450
|
+
] : [
|
|
29451
|
+
"[Tool output aged]",
|
|
29452
|
+
"lifecycleLevel: L2",
|
|
29453
|
+
`ageTurns: ${ageTurns}`,
|
|
29454
|
+
status,
|
|
29455
|
+
...normalizedSignals,
|
|
29456
|
+
"content: placeholder"
|
|
29457
|
+
]).join("\n");
|
|
29458
|
+
changed = true;
|
|
29459
|
+
agedBlocks += 1;
|
|
29460
|
+
protectedBlocks += signals.length;
|
|
29461
|
+
if (lifecycleLevel === "L1") l1Blocks += 1;
|
|
29462
|
+
if (lifecycleLevel === "L2") l2Blocks += 1;
|
|
29463
|
+
if (lifecycleLevel === "L3") l3Blocks += 1;
|
|
29464
|
+
return {
|
|
29465
|
+
...block,
|
|
29466
|
+
content: placeholder,
|
|
29467
|
+
metadata: {
|
|
29468
|
+
...block.metadata && typeof block.metadata === "object" ? block.metadata : {},
|
|
29469
|
+
lifecycleAged: true,
|
|
29470
|
+
ageTurns,
|
|
29471
|
+
lifecycleLevel
|
|
29472
|
+
}
|
|
29473
|
+
};
|
|
29474
|
+
});
|
|
29475
|
+
if (!changed) return message;
|
|
29476
|
+
return {
|
|
29477
|
+
...message,
|
|
29478
|
+
message: {
|
|
29479
|
+
...message.message,
|
|
29480
|
+
content: nextContent
|
|
29481
|
+
}
|
|
29482
|
+
};
|
|
29483
|
+
});
|
|
29484
|
+
return {
|
|
29485
|
+
messages: nextMessages,
|
|
29486
|
+
report: {
|
|
29487
|
+
applied: true,
|
|
29488
|
+
agedBlocks,
|
|
29489
|
+
skippedFailedBlocks,
|
|
29490
|
+
protectedBlocks,
|
|
29491
|
+
totalToolResultBlocksBefore,
|
|
29492
|
+
totalToolResultBlocksAfter: countToolResultBlocks(nextMessages),
|
|
29493
|
+
l1Blocks,
|
|
29494
|
+
l2Blocks,
|
|
29495
|
+
l3Blocks,
|
|
29496
|
+
danglingDetected: closureResult.detected,
|
|
29497
|
+
danglingClosed: closureResult.closed,
|
|
29498
|
+
beforeTokens,
|
|
29499
|
+
afterTokens: estimateMessagesTokens(nextMessages),
|
|
29500
|
+
tokenDelta: Math.max(
|
|
29501
|
+
0,
|
|
29502
|
+
beforeTokens - estimateMessagesTokens(nextMessages)
|
|
29503
|
+
)
|
|
29504
|
+
}
|
|
29505
|
+
};
|
|
29506
|
+
}
|
|
29507
|
+
|
|
29508
|
+
// src/utils/session/threeLayerRollout.ts
|
|
29509
|
+
function parseBooleanFlag4(value) {
|
|
29510
|
+
const raw = String(value ?? "").trim().toLowerCase();
|
|
29511
|
+
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
29512
|
+
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
29513
|
+
return null;
|
|
29514
|
+
}
|
|
29515
|
+
function parsePercent(value) {
|
|
29516
|
+
const parsed = Number(value);
|
|
29517
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
29518
|
+
return Math.min(100, Math.max(0, parsed));
|
|
29519
|
+
}
|
|
29520
|
+
function parsePositiveInteger(value) {
|
|
29521
|
+
const parsed = Number(value);
|
|
29522
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
29523
|
+
return Math.max(1, Math.floor(parsed));
|
|
29524
|
+
}
|
|
29525
|
+
function parseNonNegativeInteger(value) {
|
|
29526
|
+
const parsed = Number(value);
|
|
29527
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
29528
|
+
return Math.max(0, Math.floor(parsed));
|
|
29529
|
+
}
|
|
29530
|
+
function parseRolloutStage(value) {
|
|
29531
|
+
const normalized = String(value ?? "").trim().toLowerCase();
|
|
29532
|
+
if (normalized === "stage_10") return "stage_10";
|
|
29533
|
+
if (normalized === "stage_30") return "stage_30";
|
|
29534
|
+
if (normalized === "stage_100") return "stage_100";
|
|
29535
|
+
return void 0;
|
|
29536
|
+
}
|
|
29537
|
+
function stageToPercent(stage) {
|
|
29538
|
+
if (stage === "stage_10") return 10;
|
|
29539
|
+
if (stage === "stage_30") return 30;
|
|
29540
|
+
return 100;
|
|
29541
|
+
}
|
|
29542
|
+
function promoteStage(stage) {
|
|
29543
|
+
if (stage === "stage_10") return "stage_30";
|
|
29544
|
+
if (stage === "stage_30") return "stage_100";
|
|
29545
|
+
return "stage_100";
|
|
29546
|
+
}
|
|
29547
|
+
function rollbackStage(stage) {
|
|
29548
|
+
if (stage === "stage_100") return "stage_30";
|
|
29549
|
+
if (stage === "stage_30") return "stage_10";
|
|
29550
|
+
return "stage_10";
|
|
29551
|
+
}
|
|
29552
|
+
function evaluateThreeLayerRolloutStageDecision(input) {
|
|
29553
|
+
if (!input.rolloutEnabled) {
|
|
29554
|
+
return {
|
|
29555
|
+
nextStage: input.currentStage,
|
|
29556
|
+
decision: "keep",
|
|
29557
|
+
reason: "rollout_disabled"
|
|
29558
|
+
};
|
|
29559
|
+
}
|
|
29560
|
+
if (!input.autoControllerEnabled) {
|
|
29561
|
+
return {
|
|
29562
|
+
nextStage: input.currentStage,
|
|
29563
|
+
decision: "keep",
|
|
29564
|
+
reason: "threshold_not_met"
|
|
29565
|
+
};
|
|
29566
|
+
}
|
|
29567
|
+
if (input.consecutiveUnhealthyWindows >= input.maxUnhealthyWindowsForRollback && input.currentStage !== "stage_10") {
|
|
29568
|
+
return {
|
|
29569
|
+
nextStage: rollbackStage(input.currentStage),
|
|
29570
|
+
decision: "rollback",
|
|
29571
|
+
reason: "unhealthy_window_rollback"
|
|
29572
|
+
};
|
|
29573
|
+
}
|
|
29574
|
+
if (input.consecutiveHealthyWindows >= input.minHealthyWindowsForPromote && input.currentStage !== "stage_100") {
|
|
29575
|
+
return {
|
|
29576
|
+
nextStage: promoteStage(input.currentStage),
|
|
29577
|
+
decision: "promote",
|
|
29578
|
+
reason: "healthy_window_promote"
|
|
29579
|
+
};
|
|
29580
|
+
}
|
|
29581
|
+
return {
|
|
29582
|
+
nextStage: input.currentStage,
|
|
29583
|
+
decision: "keep",
|
|
29584
|
+
reason: "threshold_not_met"
|
|
29585
|
+
};
|
|
29586
|
+
}
|
|
29587
|
+
function hashToBucket(value) {
|
|
29588
|
+
let hash = 2166136261;
|
|
29589
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
29590
|
+
hash ^= value.charCodeAt(i);
|
|
29591
|
+
hash = Math.imul(hash, 16777619);
|
|
29592
|
+
}
|
|
29593
|
+
return Math.abs(hash >>> 0) % 100;
|
|
29594
|
+
}
|
|
29595
|
+
function resolveThreeLayerRolloutFlags(toolUseContext, options) {
|
|
29596
|
+
const rolloutEnabledEnv = parseBooleanFlag4(
|
|
29597
|
+
process.env.PYB_THREE_LAYER_ROLLOUT_ENABLED
|
|
29598
|
+
);
|
|
29599
|
+
const rolloutEnabledContext = typeof toolUseContext?.threeLayerRolloutEnabled === "boolean" ? toolUseContext.threeLayerRolloutEnabled : void 0;
|
|
29600
|
+
const rolloutEnabled = rolloutEnabledEnv !== null ? rolloutEnabledEnv : rolloutEnabledContext ?? false;
|
|
29601
|
+
const rolloutStageEnv = parseRolloutStage(process.env.PYB_THREE_LAYER_ROLLOUT_STAGE);
|
|
29602
|
+
const rolloutStageContext = parseRolloutStage(toolUseContext?.threeLayerRolloutStage);
|
|
29603
|
+
const rolloutStageInput = rolloutStageEnv ?? rolloutStageContext ?? "stage_100";
|
|
29604
|
+
const autoControllerEnabledEnv = parseBooleanFlag4(
|
|
29605
|
+
process.env.PYB_THREE_LAYER_ROLLOUT_AUTO_CONTROLLER_ENABLED
|
|
29606
|
+
);
|
|
29607
|
+
const autoControllerEnabledContext = typeof toolUseContext?.threeLayerRolloutAutoControllerEnabled === "boolean" ? toolUseContext.threeLayerRolloutAutoControllerEnabled : void 0;
|
|
29608
|
+
const autoControllerEnabled = autoControllerEnabledEnv !== null ? autoControllerEnabledEnv : autoControllerEnabledContext ?? false;
|
|
29609
|
+
const consecutiveHealthyWindows = parseNonNegativeInteger(
|
|
29610
|
+
toolUseContext?.threeLayerRolloutConsecutiveHealthyWindows
|
|
29611
|
+
) ?? 0;
|
|
29612
|
+
const consecutiveUnhealthyWindows = parseNonNegativeInteger(
|
|
29613
|
+
toolUseContext?.threeLayerRolloutConsecutiveUnhealthyWindows
|
|
29614
|
+
) ?? 0;
|
|
29615
|
+
const minHealthyWindowsForPromote = parsePositiveInteger(
|
|
29616
|
+
toolUseContext?.threeLayerRolloutMinHealthyWindowsForPromote ?? process.env.PYB_THREE_LAYER_ROLLOUT_MIN_HEALTHY_WINDOWS
|
|
29617
|
+
) ?? 2;
|
|
29618
|
+
const maxUnhealthyWindowsForRollback = parsePositiveInteger(
|
|
29619
|
+
toolUseContext?.threeLayerRolloutMaxUnhealthyWindowsForRollback ?? process.env.PYB_THREE_LAYER_ROLLOUT_MAX_UNHEALTHY_WINDOWS
|
|
29620
|
+
) ?? 2;
|
|
29621
|
+
const stageDecision = evaluateThreeLayerRolloutStageDecision({
|
|
29622
|
+
rolloutEnabled,
|
|
29623
|
+
currentStage: rolloutStageInput,
|
|
29624
|
+
autoControllerEnabled,
|
|
29625
|
+
consecutiveHealthyWindows,
|
|
29626
|
+
consecutiveUnhealthyWindows,
|
|
29627
|
+
minHealthyWindowsForPromote,
|
|
29628
|
+
maxUnhealthyWindowsForRollback
|
|
29629
|
+
});
|
|
29630
|
+
const rolloutStage = stageDecision.nextStage;
|
|
29631
|
+
const rolloutDecision = stageDecision.decision;
|
|
29632
|
+
const rolloutReason = stageDecision.reason;
|
|
29633
|
+
const rolloutPercent = parsePercent(process.env.PYB_THREE_LAYER_ROLLOUT_PERCENT) ?? parsePercent(toolUseContext?.threeLayerRolloutPercent) ?? stageToPercent(rolloutStage);
|
|
29634
|
+
const rolloutKey = String(
|
|
29635
|
+
options?.requestId || toolUseContext?.options?.messageLogName || toolUseContext?.agentId || "global"
|
|
29636
|
+
);
|
|
29637
|
+
const rolloutBucket = hashToBucket(rolloutKey);
|
|
29638
|
+
const rolloutActive = rolloutEnabled && rolloutBucket < rolloutPercent;
|
|
29639
|
+
const typedWriteExplicitEnv = parseBooleanFlag4(
|
|
29640
|
+
process.env.PYB_TYPED_SESSION_WRITE_ENABLED
|
|
29641
|
+
);
|
|
29642
|
+
const typedWriteExplicitContext = typeof toolUseContext?.typedSessionWriteEnabled === "boolean" ? toolUseContext.typedSessionWriteEnabled : void 0;
|
|
29643
|
+
const boundaryExplicitEnv = parseBooleanFlag4(
|
|
29644
|
+
process.env.PYB_COMPACTION_BOUNDARY_ENABLED
|
|
29645
|
+
);
|
|
29646
|
+
const boundaryExplicitContext = typeof toolUseContext?.compactionBoundaryEnabled === "boolean" ? toolUseContext.compactionBoundaryEnabled : void 0;
|
|
29647
|
+
const lifecycleExplicitEnv = parseBooleanFlag4(
|
|
29648
|
+
process.env.PYB_TOOL_OUTPUT_LIFECYCLE_ENABLED
|
|
29649
|
+
);
|
|
29650
|
+
const lifecycleExplicitContext = typeof toolUseContext?.toolOutputLifecycleEnabled === "boolean" ? toolUseContext.toolOutputLifecycleEnabled : void 0;
|
|
29651
|
+
const typedSessionWriteEnabled = typedWriteExplicitEnv !== null ? typedWriteExplicitEnv : typedWriteExplicitContext ?? (rolloutEnabled ? rolloutActive : true);
|
|
29652
|
+
const compactionBoundaryEnabled = boundaryExplicitEnv !== null ? boundaryExplicitEnv : boundaryExplicitContext ?? (rolloutEnabled ? rolloutActive : false);
|
|
29653
|
+
const toolOutputLifecycleEnabled = lifecycleExplicitEnv !== null ? lifecycleExplicitEnv : lifecycleExplicitContext ?? (rolloutEnabled ? rolloutActive : false);
|
|
29654
|
+
return {
|
|
29655
|
+
typedSessionWriteEnabled,
|
|
29656
|
+
compactionBoundaryEnabled,
|
|
29657
|
+
toolOutputLifecycleEnabled,
|
|
29658
|
+
rolloutEnabled,
|
|
29659
|
+
rolloutPercent,
|
|
29660
|
+
rolloutBucket,
|
|
29661
|
+
rolloutStage,
|
|
29662
|
+
rolloutDecision,
|
|
29663
|
+
rolloutReason
|
|
29664
|
+
};
|
|
29665
|
+
}
|
|
29666
|
+
|
|
29667
|
+
// src/utils/session/toolOutputLifecycleMetricsDraft.ts
|
|
29668
|
+
function safeRate(numerator, denominator) {
|
|
29669
|
+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator) || denominator <= 0) {
|
|
29670
|
+
return 0;
|
|
29671
|
+
}
|
|
29672
|
+
return Math.max(0, Math.min(1, numerator / denominator));
|
|
29673
|
+
}
|
|
29674
|
+
function buildToolOutputLifecyclePreGateMetrics(samples) {
|
|
29675
|
+
const normalized = Array.isArray(samples) ? samples : [];
|
|
29676
|
+
let totalToolResultBlocksBefore = 0;
|
|
29677
|
+
let totalAgedBlocks = 0;
|
|
29678
|
+
let totalPlaceholderBlocks = 0;
|
|
29679
|
+
let totalBeforeTokens = 0;
|
|
29680
|
+
let totalTokenDelta = 0;
|
|
29681
|
+
let totalDanglingDetected = 0;
|
|
29682
|
+
let totalDanglingClosed = 0;
|
|
29683
|
+
let w11Total = 0;
|
|
29684
|
+
let w11Passed = 0;
|
|
29685
|
+
let w14Total = 0;
|
|
29686
|
+
let w14Passed = 0;
|
|
29687
|
+
for (const sample2 of normalized) {
|
|
29688
|
+
const report = sample2?.report ?? {};
|
|
29689
|
+
const toolResultBefore = Number(report.totalToolResultBlocksBefore ?? 0);
|
|
29690
|
+
const aged = Number(report.agedBlocks ?? 0);
|
|
29691
|
+
const l2 = Number(report.l2Blocks ?? 0);
|
|
29692
|
+
const l3 = Number(report.l3Blocks ?? 0);
|
|
29693
|
+
const danglingDetected = Number(report.danglingDetected ?? 0);
|
|
29694
|
+
const danglingClosed = Number(report.danglingClosed ?? 0);
|
|
29695
|
+
const beforeTokens = Number(report.beforeTokens ?? 0);
|
|
29696
|
+
const tokenDelta = Number(report.tokenDelta ?? 0);
|
|
29697
|
+
totalToolResultBlocksBefore += Number.isFinite(toolResultBefore) ? toolResultBefore : 0;
|
|
29698
|
+
totalAgedBlocks += Number.isFinite(aged) ? aged : 0;
|
|
29699
|
+
totalPlaceholderBlocks += Number.isFinite(l2 + l3) ? l2 + l3 : 0;
|
|
29700
|
+
totalBeforeTokens += Number.isFinite(beforeTokens) ? beforeTokens : 0;
|
|
29701
|
+
totalTokenDelta += Number.isFinite(tokenDelta) ? tokenDelta : 0;
|
|
29702
|
+
totalDanglingDetected += Number.isFinite(danglingDetected) ? danglingDetected : 0;
|
|
29703
|
+
totalDanglingClosed += Number.isFinite(danglingClosed) ? danglingClosed : 0;
|
|
29704
|
+
const sampleId = String(sample2?.sampleId ?? "").trim().toUpperCase();
|
|
29705
|
+
if (sampleId === "W11") {
|
|
29706
|
+
w11Total += 1;
|
|
29707
|
+
if (aged > 0 && tokenDelta > 0) {
|
|
29708
|
+
w11Passed += 1;
|
|
29709
|
+
}
|
|
29710
|
+
}
|
|
29711
|
+
if (sampleId === "W14") {
|
|
29712
|
+
w14Total += 1;
|
|
29713
|
+
if (danglingDetected > 0 && danglingClosed >= danglingDetected) {
|
|
29714
|
+
w14Passed += 1;
|
|
29715
|
+
}
|
|
29716
|
+
}
|
|
29717
|
+
}
|
|
29718
|
+
return {
|
|
29719
|
+
samples: normalized.length,
|
|
29720
|
+
tool_output_aging_hit_rate: safeRate(
|
|
29721
|
+
totalAgedBlocks,
|
|
29722
|
+
totalToolResultBlocksBefore
|
|
29723
|
+
),
|
|
29724
|
+
tool_output_placeholder_hit_rate: safeRate(
|
|
29725
|
+
totalPlaceholderBlocks,
|
|
29726
|
+
totalAgedBlocks || 1
|
|
29727
|
+
),
|
|
29728
|
+
tool_output_token_reduction_rate: safeRate(totalTokenDelta, totalBeforeTokens),
|
|
29729
|
+
dangling_tool_closure_rate: safeRate(totalDanglingClosed, totalDanglingDetected || 1),
|
|
29730
|
+
w11_sample_pass_rate: safeRate(w11Passed, w11Total || 1),
|
|
29731
|
+
w14_sample_pass_rate: safeRate(w14Passed, w14Total || 1)
|
|
29732
|
+
};
|
|
29733
|
+
}
|
|
29734
|
+
|
|
28711
29735
|
// src/services/telemetry/autoCompactTelemetryPersistence.ts
|
|
28712
29736
|
import { appendFileSync as appendFileSync2, existsSync as existsSync19, mkdirSync as mkdirSync8 } from "fs";
|
|
28713
29737
|
import { dirname as dirname10 } from "path";
|
|
@@ -29007,18 +30031,75 @@ async function queryWithBinaryFeedback(toolUseContext, getAssistantResponse, get
|
|
|
29007
30031
|
}
|
|
29008
30032
|
async function* query(messages, systemPrompt, context, canUseTool, toolUseContext, getBinaryFeedbackResponse) {
|
|
29009
30033
|
const shouldPersistSession = toolUseContext.options?.persistSession !== false && process.env.NODE_ENV !== "test";
|
|
29010
|
-
|
|
29011
|
-
|
|
29012
|
-
|
|
29013
|
-
|
|
29014
|
-
|
|
29015
|
-
|
|
29016
|
-
|
|
29017
|
-
))
|
|
29018
|
-
|
|
29019
|
-
|
|
30034
|
+
const typedRequestId = (() => {
|
|
30035
|
+
const currentRequestId = getCurrentRequest()?.id;
|
|
30036
|
+
if (currentRequestId) return `query_${currentRequestId}`;
|
|
30037
|
+
const lastUser = [...messages].reverse().find((item) => item?.type === "user" && item?.queryId);
|
|
30038
|
+
const fallbackQueryId = lastUser?.queryId;
|
|
30039
|
+
if (fallbackQueryId) return `query_${fallbackQueryId}`;
|
|
30040
|
+
return `query_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
30041
|
+
})();
|
|
30042
|
+
const modelPointer = toolUseContext.options.model || "main";
|
|
30043
|
+
const modelResolution = getModelManager().resolveModelWithInfo(modelPointer);
|
|
30044
|
+
const typedProvider = modelResolution.success ? String(modelResolution.profile?.provider ?? "").trim().toLowerCase() : "unknown";
|
|
30045
|
+
const typedProjector = createStreamTypedProjector({
|
|
30046
|
+
requestId: typedRequestId,
|
|
30047
|
+
source: "query_main",
|
|
30048
|
+
provider: typedProvider
|
|
30049
|
+
});
|
|
30050
|
+
const rolloutFlags = resolveThreeLayerRolloutFlags(toolUseContext, {
|
|
30051
|
+
requestId: getCurrentRequest()?.id ?? typedRequestId
|
|
30052
|
+
});
|
|
30053
|
+
const shouldPersistTypedSession = shouldPersistSession && rolloutFlags.typedSessionWriteEnabled;
|
|
30054
|
+
logUserFriendly("THREE_LAYER_ROLLOUT_APPLIED", {
|
|
30055
|
+
enabled: rolloutFlags.rolloutEnabled,
|
|
30056
|
+
stage: rolloutFlags.rolloutStage,
|
|
30057
|
+
decision: rolloutFlags.rolloutDecision,
|
|
30058
|
+
reason: rolloutFlags.rolloutReason,
|
|
30059
|
+
percent: rolloutFlags.rolloutPercent,
|
|
30060
|
+
bucket: rolloutFlags.rolloutBucket,
|
|
30061
|
+
typedSessionWriteEnabled: rolloutFlags.typedSessionWriteEnabled,
|
|
30062
|
+
compactionBoundaryEnabled: rolloutFlags.compactionBoundaryEnabled,
|
|
30063
|
+
toolOutputLifecycleEnabled: rolloutFlags.toolOutputLifecycleEnabled
|
|
30064
|
+
});
|
|
30065
|
+
if (typeof toolUseContext.compactionBoundaryEnabled !== "boolean") {
|
|
30066
|
+
toolUseContext.compactionBoundaryEnabled = rolloutFlags.compactionBoundaryEnabled;
|
|
30067
|
+
}
|
|
30068
|
+
if (typeof toolUseContext.toolOutputLifecycleEnabled !== "boolean") {
|
|
30069
|
+
toolUseContext.toolOutputLifecycleEnabled = rolloutFlags.toolOutputLifecycleEnabled;
|
|
30070
|
+
}
|
|
30071
|
+
try {
|
|
30072
|
+
for await (const message of queryCore(
|
|
30073
|
+
messages,
|
|
30074
|
+
systemPrompt,
|
|
30075
|
+
context,
|
|
30076
|
+
canUseTool,
|
|
30077
|
+
toolUseContext,
|
|
30078
|
+
getBinaryFeedbackResponse
|
|
30079
|
+
)) {
|
|
30080
|
+
if (shouldPersistSession) {
|
|
30081
|
+
appendSessionJsonlFromMessage({ message, toolUseContext });
|
|
30082
|
+
}
|
|
30083
|
+
if (shouldPersistTypedSession) {
|
|
30084
|
+
const parts = projectMessageToTypedParts(typedProjector, message);
|
|
30085
|
+
for (const part of parts) {
|
|
30086
|
+
emitTypedPart({ requestId: typedRequestId, part });
|
|
30087
|
+
}
|
|
30088
|
+
}
|
|
30089
|
+
yield message;
|
|
30090
|
+
}
|
|
30091
|
+
} finally {
|
|
30092
|
+
if (shouldPersistTypedSession) {
|
|
30093
|
+
flushTypedPartBuffer({ requestId: typedRequestId });
|
|
30094
|
+
const compatibilityMetrics = consumeProjectorCompatibilityMetrics(typedProjector);
|
|
30095
|
+
logUserFriendly("STREAM_TYPED_PROVIDER_COMPATIBILITY", {
|
|
30096
|
+
requestId: typedRequestId,
|
|
30097
|
+
provider: compatibilityMetrics.provider,
|
|
30098
|
+
supportsRichToolResult: compatibilityMetrics.supportsRichToolResult,
|
|
30099
|
+
richToolResultBlockCount: compatibilityMetrics.richToolResultBlockCount,
|
|
30100
|
+
downgradedToolResultCount: compatibilityMetrics.downgradedToolResultCount
|
|
30101
|
+
});
|
|
29020
30102
|
}
|
|
29021
|
-
yield message;
|
|
29022
30103
|
}
|
|
29023
30104
|
}
|
|
29024
30105
|
async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseContext, getBinaryFeedbackResponse, hookState) {
|
|
@@ -29057,6 +30138,76 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
29057
30138
|
if (wasCompacted) {
|
|
29058
30139
|
messages = processedMessages;
|
|
29059
30140
|
}
|
|
30141
|
+
const boundaryConfig = resolveCompactionBoundaryConfig(toolUseContext);
|
|
30142
|
+
const boundaryResult = filterAfterCompactionBoundary(messages, {
|
|
30143
|
+
enabled: boundaryConfig.enabled
|
|
30144
|
+
});
|
|
30145
|
+
messages = boundaryResult.messages;
|
|
30146
|
+
if (boundaryConfig.enabled) {
|
|
30147
|
+
logUserFriendly("COMPACTION_BOUNDARY_APPLIED", {
|
|
30148
|
+
source: boundaryConfig.source,
|
|
30149
|
+
applied: boundaryResult.applied,
|
|
30150
|
+
droppedMessageCount: boundaryResult.droppedMessageCount,
|
|
30151
|
+
preservedMessageCount: boundaryResult.preservedMessageCount,
|
|
30152
|
+
lastCompactionIndex: boundaryResult.lastCompactionIndex,
|
|
30153
|
+
replayMode: boundaryResult.replayMode
|
|
30154
|
+
});
|
|
30155
|
+
emitAutoCompactTelemetryEvent("COMPACTION_BOUNDARY_APPLIED", {
|
|
30156
|
+
source: boundaryConfig.source,
|
|
30157
|
+
applied: boundaryResult.applied,
|
|
30158
|
+
droppedMessageCount: boundaryResult.droppedMessageCount,
|
|
30159
|
+
preservedMessageCount: boundaryResult.preservedMessageCount,
|
|
30160
|
+
lastCompactionIndex: boundaryResult.lastCompactionIndex,
|
|
30161
|
+
replayMode: boundaryResult.replayMode
|
|
30162
|
+
});
|
|
30163
|
+
}
|
|
30164
|
+
const lifecycleConfig = resolveToolOutputLifecycleConfig(toolUseContext);
|
|
30165
|
+
const lifecycleResult = applyToolOutputLifecycle(messages, {
|
|
30166
|
+
enabled: lifecycleConfig.enabled,
|
|
30167
|
+
maxAgeTurns: lifecycleConfig.maxAgeTurns,
|
|
30168
|
+
protectFailedResultTurns: lifecycleConfig.protectFailedResultTurns,
|
|
30169
|
+
l3AgeTurns: lifecycleConfig.l3AgeTurns,
|
|
30170
|
+
l1MinChars: lifecycleConfig.l1MinChars,
|
|
30171
|
+
l3MinChars: lifecycleConfig.l3MinChars
|
|
30172
|
+
});
|
|
30173
|
+
messages = lifecycleResult.messages;
|
|
30174
|
+
if (lifecycleConfig.enabled) {
|
|
30175
|
+
logUserFriendly("TOOL_OUTPUT_LIFECYCLE_APPLIED", {
|
|
30176
|
+
source: lifecycleConfig.source,
|
|
30177
|
+
applied: lifecycleResult.report.applied,
|
|
30178
|
+
agedBlocks: lifecycleResult.report.agedBlocks,
|
|
30179
|
+
skippedFailedBlocks: lifecycleResult.report.skippedFailedBlocks,
|
|
30180
|
+
protectedBlocks: lifecycleResult.report.protectedBlocks,
|
|
30181
|
+
l1Blocks: lifecycleResult.report.l1Blocks,
|
|
30182
|
+
l2Blocks: lifecycleResult.report.l2Blocks,
|
|
30183
|
+
l3Blocks: lifecycleResult.report.l3Blocks,
|
|
30184
|
+
beforeTokens: lifecycleResult.report.beforeTokens,
|
|
30185
|
+
afterTokens: lifecycleResult.report.afterTokens,
|
|
30186
|
+
tokenDelta: lifecycleResult.report.tokenDelta
|
|
30187
|
+
});
|
|
30188
|
+
if (lifecycleResult.report.agedBlocks > 0) {
|
|
30189
|
+
logUserFriendly("TOOL_OUTPUT_AGED", {
|
|
30190
|
+
agedBlocks: lifecycleResult.report.agedBlocks,
|
|
30191
|
+
l1Blocks: lifecycleResult.report.l1Blocks,
|
|
30192
|
+
l2Blocks: lifecycleResult.report.l2Blocks,
|
|
30193
|
+
l3Blocks: lifecycleResult.report.l3Blocks
|
|
30194
|
+
});
|
|
30195
|
+
}
|
|
30196
|
+
if (lifecycleResult.report.l2Blocks > 0 || lifecycleResult.report.l3Blocks > 0) {
|
|
30197
|
+
logUserFriendly("TOOL_OUTPUT_PLACEHOLDER_APPLIED", {
|
|
30198
|
+
l2Blocks: lifecycleResult.report.l2Blocks,
|
|
30199
|
+
l3Blocks: lifecycleResult.report.l3Blocks
|
|
30200
|
+
});
|
|
30201
|
+
}
|
|
30202
|
+
const preGateMetrics = buildToolOutputLifecyclePreGateMetrics([
|
|
30203
|
+
{ sampleId: "W11", report: lifecycleResult.report },
|
|
30204
|
+
{ sampleId: "W14", report: lifecycleResult.report }
|
|
30205
|
+
]);
|
|
30206
|
+
logUserFriendly("TOOL_OUTPUT_LIFECYCLE_PRE_GATE_METRICS_DRAFT", {
|
|
30207
|
+
...preGateMetrics,
|
|
30208
|
+
source: lifecycleConfig.source
|
|
30209
|
+
});
|
|
30210
|
+
}
|
|
29060
30211
|
const tracker = getConversationTrackerForContext(toolUseContext);
|
|
29061
30212
|
const activeNaturalUserMessage = findNaturalUserMessageForParent(messages);
|
|
29062
30213
|
const activeQueryId = activeNaturalUserMessage?.queryId || activeNaturalUserMessage?.uuid;
|
|
@@ -29371,10 +30522,16 @@ async function* queryCore(messages, systemPrompt, context, canUseTool, toolUseCo
|
|
|
29371
30522
|
}
|
|
29372
30523
|
} finally {
|
|
29373
30524
|
const currentRequest = getCurrentRequest();
|
|
29374
|
-
flushAutoCompactTelemetrySnapshot({
|
|
30525
|
+
const telemetryRecord = flushAutoCompactTelemetrySnapshot({
|
|
29375
30526
|
requestId: currentRequest?.id,
|
|
29376
30527
|
agentId: toolUseContext?.agentId
|
|
29377
30528
|
});
|
|
30529
|
+
if (Number.isFinite(Number(telemetryRecord?.metrics?.typed_primary_path_rate))) {
|
|
30530
|
+
logUserFriendly("SESSION_READ_PATH_METRICS", {
|
|
30531
|
+
requestId: currentRequest?.id,
|
|
30532
|
+
typed_primary_path_rate: telemetryRecord?.metrics?.typed_primary_path_rate
|
|
30533
|
+
});
|
|
30534
|
+
}
|
|
29378
30535
|
setRequestStatus({ kind: "idle" });
|
|
29379
30536
|
}
|
|
29380
30537
|
}
|
|
@@ -30903,7 +32060,7 @@ import { homedir as homedir8 } from "os";
|
|
|
30903
32060
|
// src/commands/agents/generation.ts
|
|
30904
32061
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
30905
32062
|
async function generateAgentWithClaude(prompt) {
|
|
30906
|
-
const { queryModel } = await import("./llm-
|
|
32063
|
+
const { queryModel } = await import("./llm-OW7QDXPZ.js");
|
|
30907
32064
|
const systemPrompt = `You are an expert at creating AI agent configurations. Based on the user's description, generate a specialized agent configuration.
|
|
30908
32065
|
|
|
30909
32066
|
Return your response as a JSON object with exactly these fields:
|
|
@@ -34556,7 +35713,7 @@ user: locate where auth token refresh is implemented in a large repo
|
|
|
34556
35713
|
assistant: [uses the LS tool to scan top-level structure]
|
|
34557
35714
|
[uses the Glob tool to find candidate auth-related files]
|
|
34558
35715
|
[uses the Grep tool to search for token refresh patterns]
|
|
34559
|
-
[uses the Read tool to inspect the most likely file]
|
|
35716
|
+
[uses the Read tool to inspect the most likely file]
|
|
34560
35717
|
</example>
|
|
34561
35718
|
|
|
34562
35719
|
<example>
|