pybao-cli 1.5.21 → 1.5.23
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-CI5ET6VF.js +50 -0
- package/dist/{acp-VH2FWCMR.js → acp-5G7LPADD.js} +32 -32
- package/dist/{agentsValidate-4E7AHAMS.js → agentsValidate-BIRAVXBL.js} +7 -7
- package/dist/{ask-R3YZ5B44.js → ask-XQZT6WIO.js} +31 -31
- package/dist/{autoUpdater-DCNAXD4F.js → autoUpdater-DDJAJPKA.js} +3 -3
- package/dist/{chunk-GIXE5FJ2.js → chunk-2GHNW642.js} +1 -1
- package/dist/{chunk-NRQHLVJJ.js → chunk-2SVUNNJB.js} +2 -2
- package/dist/{chunk-6UNYL6XK.js → chunk-3CC7QXCN.js} +222 -75
- package/dist/chunk-3CC7QXCN.js.map +7 -0
- package/dist/{chunk-H2ZE5QDY.js → chunk-4ZZYPG6P.js} +4 -4
- package/dist/{chunk-TBEA6BY3.js → chunk-5B7UCAYL.js} +1 -1
- package/dist/{chunk-ZQR3MM2D.js → chunk-652OMXEE.js} +2 -2
- package/dist/{chunk-EP62LHB7.js → chunk-6QGIRDZS.js} +1 -1
- package/dist/{chunk-BED7SG2Q.js → chunk-76BOJQUE.js} +1 -1
- package/dist/{chunk-TXZ5UTGP.js → chunk-7SYDIES4.js} +1 -1
- package/dist/{chunk-TXZ5UTGP.js.map → chunk-7SYDIES4.js.map} +1 -1
- package/dist/{chunk-CSONCQLF.js → chunk-A6QEPK5J.js} +2 -2
- package/dist/{chunk-X5LLT4P2.js → chunk-ABJT5MG2.js} +1 -1
- package/dist/{chunk-56IL2VXC.js → chunk-C2GNLGBM.js} +1 -1
- package/dist/{chunk-2OOER4FR.js → chunk-CNMNKSWQ.js} +3 -3
- package/dist/{chunk-QE7PZPHW.js → chunk-CT7LWVB7.js} +1 -1
- package/dist/{chunk-P5NTGZ5H.js → chunk-CZZKRPE2.js} +1 -1
- package/dist/{chunk-P5NTGZ5H.js.map → chunk-CZZKRPE2.js.map} +1 -1
- package/dist/chunk-G5MP72ZL.js +515 -0
- package/dist/chunk-G5MP72ZL.js.map +7 -0
- package/dist/{chunk-25GZITCX.js → chunk-GU4XA76N.js} +3 -3
- package/dist/chunk-KQZAS4DO.js +582 -0
- package/dist/chunk-KQZAS4DO.js.map +7 -0
- package/dist/{chunk-VP5A6FKG.js → chunk-LBDLSBXN.js} +4 -1
- package/dist/{chunk-SE7UGQCE.js → chunk-M7FEUIHO.js} +2 -2
- package/dist/{chunk-HA7FKBZI.js → chunk-MMW6MLFR.js} +2 -2
- package/dist/{chunk-XRLMQN3Q.js → chunk-MN77HNBB.js} +4 -4
- package/dist/{chunk-VY5KEHU5.js → chunk-N7GEPTZB.js} +3 -3
- package/dist/{chunk-MMMMRMOG.js → chunk-O7LWCCRJ.js} +3 -3
- package/dist/{chunk-5VO2CFAL.js → chunk-PUPDIRI6.js} +2 -2
- package/dist/{chunk-YQ2RQUQF.js → chunk-QCI5HPTA.js} +1 -1
- package/dist/{chunk-KMCUZUZG.js → chunk-QSMZLK7K.js} +3 -3
- package/dist/{chunk-4ZGZTWMR.js → chunk-S65MIABQ.js} +4 -4
- package/dist/{chunk-3UWTN6DM.js → chunk-V22PQM4W.js} +3 -3
- package/dist/{chunk-RQ5X6LFM.js → chunk-VVXC3SNP.js} +4 -4
- package/dist/{chunk-LRL3MYKR.js → chunk-W7VIESST.js} +3 -3
- package/dist/{chunk-CPYDPN2J.js → chunk-XEVB4WON.js} +15 -15
- package/dist/chunk-ZB3ZWD2K.js +96 -0
- package/dist/chunk-ZB3ZWD2K.js.map +7 -0
- package/dist/{cli-RBMZQ5KF.js → cli-YIANCHDD.js} +130 -103
- package/dist/cli-YIANCHDD.js.map +7 -0
- package/dist/commands-4YMZW52K.js +54 -0
- package/dist/{config-7TO5SQU5.js → config-QVH3VNUQ.js} +4 -4
- package/dist/{context-LRA2DKJT.js → context-5VXEWH3G.js} +6 -6
- package/dist/{conversationPersistence-Z4QSI5NB.js → conversationPersistence-INUNJHOV.js} +3 -3
- package/dist/{conversationTracker-B3DMEHMA.js → conversationTracker-H25IOHBE.js} +4 -4
- package/dist/{customCommands-6JZ2VUO2.js → customCommands-7RZHKH2K.js} +4 -4
- package/dist/{env-37ALKFXU.js → env-DPJTGHMP.js} +2 -2
- package/dist/{file-7EOMBX72.js → file-D7W2FBZP.js} +4 -4
- package/dist/index.js +3 -3
- package/dist/{llm-3KQG5NEP.js → llm-TOU5REY5.js} +32 -32
- package/dist/{llmLazy-ENEH3KAB.js → llmLazy-HSKKIGLC.js} +1 -1
- package/dist/{loader-D6V3WFL6.js → loader-YUP6OJTJ.js} +4 -4
- package/dist/{lsp-CTPOMI7O.js → lsp-7QKC4DVK.js} +6 -6
- package/dist/{lspAnchor-PPPTHRQH.js → lspAnchor-LCRZ23GA.js} +6 -6
- package/dist/{mcp-6M34WBA5.js → mcp-KK6BOD6I.js} +7 -7
- package/dist/{mentionProcessor-TS4SITI3.js → mentionProcessor-V6JH6HUD.js} +5 -5
- package/dist/{messages-BINU6SYX.js → messages-7NVTXWIJ.js} +1 -1
- package/dist/{model-6IW224UU.js → model-QSDSUJDB.js} +5 -5
- package/dist/{openai-O6CGVMYK.js → openai-JC3KJN3H.js} +5 -5
- package/dist/{outputStyles-7PPMLSV6.js → outputStyles-TPH3CCB4.js} +4 -4
- package/dist/{pluginRuntime-RU5STQ6F.js → pluginRuntime-7EK4LQDD.js} +6 -6
- package/dist/{pluginValidation-JTJTB3TB.js → pluginValidation-BJWCS55I.js} +6 -6
- package/dist/prompts-KQNPPEOG.js +56 -0
- package/dist/{pybAgentSessionLoad-ZXQAHTQS.js → pybAgentSessionLoad-V3IAJJPS.js} +4 -6
- package/dist/{pybAgentSessionResume-R73KFN3V.js → pybAgentSessionResume-WE7ET356.js} +4 -4
- package/dist/{pybAgentStreamJsonSession-N4SMTC64.js → pybAgentStreamJsonSession-VWDYV4XL.js} +1 -1
- package/dist/{pybHooks-NGJ5OFAI.js → pybHooks-UV7BTIVT.js} +4 -4
- package/dist/query-KAZY5LOW.js +54 -0
- package/dist/{registry-FKY6JQ3L.js → registry-FK6UGJPV.js} +5 -5
- package/dist/{ripgrep-O7MOW25M.js → ripgrep-CXJ4DFPU.js} +3 -3
- package/dist/{skillMarketplace-VK3AYR6Q.js → skillMarketplace-QUJXDKZK.js} +3 -3
- package/dist/{state-T57IG35V.js → state-GC3XELIE.js} +2 -2
- package/dist/{theme-ZEFQIPVH.js → theme-24PLJSPD.js} +5 -5
- package/dist/{toolPermissionSettings-ERNXVP7A.js → toolPermissionSettings-S6NJPBKT.js} +6 -6
- package/dist/tools-NC5R4I6F.js +55 -0
- package/dist/{userInput-JBAUBHGI.js → userInput-4VZSNII7.js} +34 -34
- package/package.json +1 -1
- package/dist/REPL-64WF5V7K.js +0 -50
- package/dist/chunk-6UNYL6XK.js.map +0 -7
- package/dist/chunk-BRSPPFSY.js +0 -196
- package/dist/chunk-BRSPPFSY.js.map +0 -7
- package/dist/chunk-N3T2WAYN.js +0 -138
- package/dist/chunk-N3T2WAYN.js.map +0 -7
- package/dist/chunk-TSAURYF2.js +0 -81
- package/dist/chunk-TSAURYF2.js.map +0 -7
- package/dist/cli-RBMZQ5KF.js.map +0 -7
- package/dist/commands-WPHK776A.js +0 -54
- package/dist/prompts-CAPCICF3.js +0 -56
- package/dist/query-CYTIVMQ6.js +0 -54
- package/dist/tools-2XLLIKZM.js +0 -55
- /package/dist/{REPL-64WF5V7K.js.map → REPL-CI5ET6VF.js.map} +0 -0
- /package/dist/{acp-VH2FWCMR.js.map → acp-5G7LPADD.js.map} +0 -0
- /package/dist/{agentsValidate-4E7AHAMS.js.map → agentsValidate-BIRAVXBL.js.map} +0 -0
- /package/dist/{ask-R3YZ5B44.js.map → ask-XQZT6WIO.js.map} +0 -0
- /package/dist/{autoUpdater-DCNAXD4F.js.map → autoUpdater-DDJAJPKA.js.map} +0 -0
- /package/dist/{chunk-GIXE5FJ2.js.map → chunk-2GHNW642.js.map} +0 -0
- /package/dist/{chunk-NRQHLVJJ.js.map → chunk-2SVUNNJB.js.map} +0 -0
- /package/dist/{chunk-H2ZE5QDY.js.map → chunk-4ZZYPG6P.js.map} +0 -0
- /package/dist/{chunk-TBEA6BY3.js.map → chunk-5B7UCAYL.js.map} +0 -0
- /package/dist/{chunk-ZQR3MM2D.js.map → chunk-652OMXEE.js.map} +0 -0
- /package/dist/{chunk-EP62LHB7.js.map → chunk-6QGIRDZS.js.map} +0 -0
- /package/dist/{chunk-BED7SG2Q.js.map → chunk-76BOJQUE.js.map} +0 -0
- /package/dist/{chunk-CSONCQLF.js.map → chunk-A6QEPK5J.js.map} +0 -0
- /package/dist/{chunk-X5LLT4P2.js.map → chunk-ABJT5MG2.js.map} +0 -0
- /package/dist/{chunk-56IL2VXC.js.map → chunk-C2GNLGBM.js.map} +0 -0
- /package/dist/{chunk-2OOER4FR.js.map → chunk-CNMNKSWQ.js.map} +0 -0
- /package/dist/{chunk-QE7PZPHW.js.map → chunk-CT7LWVB7.js.map} +0 -0
- /package/dist/{chunk-25GZITCX.js.map → chunk-GU4XA76N.js.map} +0 -0
- /package/dist/{chunk-VP5A6FKG.js.map → chunk-LBDLSBXN.js.map} +0 -0
- /package/dist/{chunk-SE7UGQCE.js.map → chunk-M7FEUIHO.js.map} +0 -0
- /package/dist/{chunk-HA7FKBZI.js.map → chunk-MMW6MLFR.js.map} +0 -0
- /package/dist/{chunk-XRLMQN3Q.js.map → chunk-MN77HNBB.js.map} +0 -0
- /package/dist/{chunk-VY5KEHU5.js.map → chunk-N7GEPTZB.js.map} +0 -0
- /package/dist/{chunk-MMMMRMOG.js.map → chunk-O7LWCCRJ.js.map} +0 -0
- /package/dist/{chunk-5VO2CFAL.js.map → chunk-PUPDIRI6.js.map} +0 -0
- /package/dist/{chunk-YQ2RQUQF.js.map → chunk-QCI5HPTA.js.map} +0 -0
- /package/dist/{chunk-KMCUZUZG.js.map → chunk-QSMZLK7K.js.map} +0 -0
- /package/dist/{chunk-4ZGZTWMR.js.map → chunk-S65MIABQ.js.map} +0 -0
- /package/dist/{chunk-3UWTN6DM.js.map → chunk-V22PQM4W.js.map} +0 -0
- /package/dist/{chunk-RQ5X6LFM.js.map → chunk-VVXC3SNP.js.map} +0 -0
- /package/dist/{chunk-LRL3MYKR.js.map → chunk-W7VIESST.js.map} +0 -0
- /package/dist/{chunk-CPYDPN2J.js.map → chunk-XEVB4WON.js.map} +0 -0
- /package/dist/{commands-WPHK776A.js.map → commands-4YMZW52K.js.map} +0 -0
- /package/dist/{config-7TO5SQU5.js.map → config-QVH3VNUQ.js.map} +0 -0
- /package/dist/{context-LRA2DKJT.js.map → context-5VXEWH3G.js.map} +0 -0
- /package/dist/{conversationPersistence-Z4QSI5NB.js.map → conversationPersistence-INUNJHOV.js.map} +0 -0
- /package/dist/{conversationTracker-B3DMEHMA.js.map → conversationTracker-H25IOHBE.js.map} +0 -0
- /package/dist/{customCommands-6JZ2VUO2.js.map → customCommands-7RZHKH2K.js.map} +0 -0
- /package/dist/{env-37ALKFXU.js.map → env-DPJTGHMP.js.map} +0 -0
- /package/dist/{file-7EOMBX72.js.map → file-D7W2FBZP.js.map} +0 -0
- /package/dist/{llm-3KQG5NEP.js.map → llm-TOU5REY5.js.map} +0 -0
- /package/dist/{llmLazy-ENEH3KAB.js.map → llmLazy-HSKKIGLC.js.map} +0 -0
- /package/dist/{loader-D6V3WFL6.js.map → loader-YUP6OJTJ.js.map} +0 -0
- /package/dist/{lsp-CTPOMI7O.js.map → lsp-7QKC4DVK.js.map} +0 -0
- /package/dist/{lspAnchor-PPPTHRQH.js.map → lspAnchor-LCRZ23GA.js.map} +0 -0
- /package/dist/{mcp-6M34WBA5.js.map → mcp-KK6BOD6I.js.map} +0 -0
- /package/dist/{mentionProcessor-TS4SITI3.js.map → mentionProcessor-V6JH6HUD.js.map} +0 -0
- /package/dist/{messages-BINU6SYX.js.map → messages-7NVTXWIJ.js.map} +0 -0
- /package/dist/{model-6IW224UU.js.map → model-QSDSUJDB.js.map} +0 -0
- /package/dist/{openai-O6CGVMYK.js.map → openai-JC3KJN3H.js.map} +0 -0
- /package/dist/{outputStyles-7PPMLSV6.js.map → outputStyles-TPH3CCB4.js.map} +0 -0
- /package/dist/{pluginRuntime-RU5STQ6F.js.map → pluginRuntime-7EK4LQDD.js.map} +0 -0
- /package/dist/{pluginValidation-JTJTB3TB.js.map → pluginValidation-BJWCS55I.js.map} +0 -0
- /package/dist/{prompts-CAPCICF3.js.map → prompts-KQNPPEOG.js.map} +0 -0
- /package/dist/{pybAgentSessionLoad-ZXQAHTQS.js.map → pybAgentSessionLoad-V3IAJJPS.js.map} +0 -0
- /package/dist/{pybAgentSessionResume-R73KFN3V.js.map → pybAgentSessionResume-WE7ET356.js.map} +0 -0
- /package/dist/{pybAgentStreamJsonSession-N4SMTC64.js.map → pybAgentStreamJsonSession-VWDYV4XL.js.map} +0 -0
- /package/dist/{pybHooks-NGJ5OFAI.js.map → pybHooks-UV7BTIVT.js.map} +0 -0
- /package/dist/{query-CYTIVMQ6.js.map → query-KAZY5LOW.js.map} +0 -0
- /package/dist/{registry-FKY6JQ3L.js.map → registry-FK6UGJPV.js.map} +0 -0
- /package/dist/{ripgrep-O7MOW25M.js.map → ripgrep-CXJ4DFPU.js.map} +0 -0
- /package/dist/{skillMarketplace-VK3AYR6Q.js.map → skillMarketplace-QUJXDKZK.js.map} +0 -0
- /package/dist/{state-T57IG35V.js.map → state-GC3XELIE.js.map} +0 -0
- /package/dist/{theme-ZEFQIPVH.js.map → theme-24PLJSPD.js.map} +0 -0
- /package/dist/{toolPermissionSettings-ERNXVP7A.js.map → toolPermissionSettings-S6NJPBKT.js.map} +0 -0
- /package/dist/{tools-2XLLIKZM.js.map → tools-NC5R4I6F.js.map} +0 -0
- /package/dist/{userInput-JBAUBHGI.js.map → userInput-4VZSNII7.js.map} +0 -0
package/dist/chunk-BRSPPFSY.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { createRequire as __pybCreateRequire } from "node:module";
|
|
2
|
-
const require = __pybCreateRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
getSessionProjectDir,
|
|
5
|
-
getSessionProjectsDir
|
|
6
|
-
} from "./chunk-TSAURYF2.js";
|
|
7
|
-
import {
|
|
8
|
-
isUuid
|
|
9
|
-
} from "./chunk-5P7HBXTD.js";
|
|
10
|
-
|
|
11
|
-
// src/utils/protocol/pybAgentSessionResume.ts
|
|
12
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
13
|
-
import { basename, join } from "path";
|
|
14
|
-
function safeParseJson(line) {
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(line);
|
|
17
|
-
} catch {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function safeParseDate(value) {
|
|
22
|
-
if (typeof value !== "string") return null;
|
|
23
|
-
const d = new Date(value);
|
|
24
|
-
if (Number.isNaN(d.getTime())) return null;
|
|
25
|
-
return d;
|
|
26
|
-
}
|
|
27
|
-
function readSessionListItemBestEffort(args) {
|
|
28
|
-
const { filePath, sessionId } = args;
|
|
29
|
-
let slug = null;
|
|
30
|
-
let cwd = null;
|
|
31
|
-
let createdAt = null;
|
|
32
|
-
let modifiedAt = null;
|
|
33
|
-
let customTitle = null;
|
|
34
|
-
let tag = null;
|
|
35
|
-
let lastAssistantUuid = null;
|
|
36
|
-
const summariesByLeaf = /* @__PURE__ */ new Map();
|
|
37
|
-
let lastSummary = null;
|
|
38
|
-
try {
|
|
39
|
-
modifiedAt = new Date(statSync(filePath).mtimeMs);
|
|
40
|
-
} catch {
|
|
41
|
-
modifiedAt = null;
|
|
42
|
-
}
|
|
43
|
-
let content;
|
|
44
|
-
try {
|
|
45
|
-
content = readFileSync(filePath, "utf8");
|
|
46
|
-
} catch {
|
|
47
|
-
return {
|
|
48
|
-
slug,
|
|
49
|
-
customTitle,
|
|
50
|
-
tag,
|
|
51
|
-
summary: null,
|
|
52
|
-
cwd,
|
|
53
|
-
createdAt,
|
|
54
|
-
modifiedAt
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
for (const rawLine of content.split("\n")) {
|
|
58
|
-
const line = rawLine.trim();
|
|
59
|
-
if (!line) continue;
|
|
60
|
-
const parsed = safeParseJson(line);
|
|
61
|
-
if (!parsed || typeof parsed !== "object") continue;
|
|
62
|
-
const entry = parsed;
|
|
63
|
-
if (!slug && typeof entry.slug === "string" && entry.slug.trim()) {
|
|
64
|
-
slug = entry.slug.trim();
|
|
65
|
-
}
|
|
66
|
-
if (!cwd && typeof entry.cwd === "string" && entry.cwd.trim()) {
|
|
67
|
-
cwd = entry.cwd.trim();
|
|
68
|
-
}
|
|
69
|
-
if (!createdAt) {
|
|
70
|
-
const ts = safeParseDate(entry.timestamp);
|
|
71
|
-
if (ts) createdAt = ts;
|
|
72
|
-
}
|
|
73
|
-
if (typeof entry.type !== "string") continue;
|
|
74
|
-
if (entry.type === "assistant") {
|
|
75
|
-
if (typeof entry.uuid === "string" && entry.uuid)
|
|
76
|
-
lastAssistantUuid = entry.uuid;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (entry.type === "summary") {
|
|
80
|
-
const leafUuid = typeof entry.leafUuid === "string" ? entry.leafUuid : "";
|
|
81
|
-
const summary2 = typeof entry.summary === "string" ? entry.summary : "";
|
|
82
|
-
if (leafUuid && summary2) {
|
|
83
|
-
summariesByLeaf.set(leafUuid, summary2);
|
|
84
|
-
lastSummary = summary2;
|
|
85
|
-
}
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (entry.type === "custom-title") {
|
|
89
|
-
const id = typeof entry.sessionId === "string" ? entry.sessionId : "";
|
|
90
|
-
const title = typeof entry.customTitle === "string" ? entry.customTitle : "";
|
|
91
|
-
if (id === sessionId && title) customTitle = title;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (entry.type === "tag") {
|
|
95
|
-
const id = typeof entry.sessionId === "string" ? entry.sessionId : "";
|
|
96
|
-
const t = typeof entry.tag === "string" ? entry.tag : "";
|
|
97
|
-
if (id === sessionId && t) tag = t;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const summary = (lastAssistantUuid ? summariesByLeaf.get(lastAssistantUuid) ?? null : null) ?? lastSummary ?? null;
|
|
102
|
-
return {
|
|
103
|
-
slug,
|
|
104
|
-
customTitle,
|
|
105
|
-
tag,
|
|
106
|
-
summary,
|
|
107
|
-
cwd,
|
|
108
|
-
createdAt,
|
|
109
|
-
modifiedAt
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function listPybAgentSessions(args) {
|
|
113
|
-
const { cwd } = args;
|
|
114
|
-
const projectDir = getSessionProjectDir(cwd);
|
|
115
|
-
if (!existsSync(projectDir)) return [];
|
|
116
|
-
const candidates = readdirSync(projectDir).filter((name) => name.endsWith(".jsonl")).filter((name) => !name.startsWith("agent-")).map((name) => ({
|
|
117
|
-
sessionId: basename(name, ".jsonl"),
|
|
118
|
-
filePath: join(projectDir, name)
|
|
119
|
-
})).filter((c) => isUuid(c.sessionId));
|
|
120
|
-
const items = candidates.map(({ sessionId, filePath }) => ({
|
|
121
|
-
sessionId,
|
|
122
|
-
...readSessionListItemBestEffort({ filePath, sessionId })
|
|
123
|
-
}));
|
|
124
|
-
items.sort((a, b) => {
|
|
125
|
-
const am = a.modifiedAt?.getTime() ?? 0;
|
|
126
|
-
const bm = b.modifiedAt?.getTime() ?? 0;
|
|
127
|
-
return bm - am;
|
|
128
|
-
});
|
|
129
|
-
return items;
|
|
130
|
-
}
|
|
131
|
-
function findSessionFileAcrossProjects(args) {
|
|
132
|
-
const { sessionId } = args;
|
|
133
|
-
const projectsDir = getSessionProjectsDir();
|
|
134
|
-
if (!existsSync(projectsDir)) return null;
|
|
135
|
-
let projectNames;
|
|
136
|
-
try {
|
|
137
|
-
projectNames = readdirSync(projectsDir);
|
|
138
|
-
} catch {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
for (const projectName of projectNames) {
|
|
142
|
-
const candidate = join(projectsDir, projectName, `${sessionId}.jsonl`);
|
|
143
|
-
if (existsSync(candidate)) return { filePath: candidate };
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
function readSessionCwdBestEffort(filePath) {
|
|
148
|
-
try {
|
|
149
|
-
const content = readFileSync(filePath, "utf8");
|
|
150
|
-
for (const rawLine of content.split("\n")) {
|
|
151
|
-
const line = rawLine.trim();
|
|
152
|
-
if (!line) continue;
|
|
153
|
-
const parsed = safeParseJson(line);
|
|
154
|
-
if (!parsed || typeof parsed !== "object") continue;
|
|
155
|
-
const cwd = parsed.cwd;
|
|
156
|
-
if (typeof cwd === "string" && cwd.trim()) return cwd.trim();
|
|
157
|
-
}
|
|
158
|
-
} catch {
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
function sessionExistsInProject(cwd, sessionId) {
|
|
163
|
-
try {
|
|
164
|
-
return existsSync(join(getSessionProjectDir(cwd), `${sessionId}.jsonl`));
|
|
165
|
-
} catch {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function resolvePybResumeSessionIdentifier(args) {
|
|
170
|
-
const { cwd, identifier } = args;
|
|
171
|
-
const id = identifier.trim();
|
|
172
|
-
if (!id) return { kind: "not_found", identifier };
|
|
173
|
-
if (isUuid(id)) {
|
|
174
|
-
if (sessionExistsInProject(cwd, id)) return { kind: "ok", sessionId: id };
|
|
175
|
-
const elsewhere = findSessionFileAcrossProjects({ sessionId: id });
|
|
176
|
-
if (elsewhere) {
|
|
177
|
-
return {
|
|
178
|
-
kind: "different_directory",
|
|
179
|
-
sessionId: id,
|
|
180
|
-
otherCwd: readSessionCwdBestEffort(elsewhere.filePath)
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
return { kind: "not_found", identifier: id };
|
|
184
|
-
}
|
|
185
|
-
const sessions = listPybAgentSessions({ cwd });
|
|
186
|
-
const matches = sessions.filter((s) => s.slug === id || s.customTitle === id).map((s) => s.sessionId);
|
|
187
|
-
if (matches.length === 1) return { kind: "ok", sessionId: matches[0] };
|
|
188
|
-
if (matches.length > 1)
|
|
189
|
-
return { kind: "ambiguous", identifier: id, matchingSessionIds: matches };
|
|
190
|
-
return { kind: "not_found", identifier: id };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export {
|
|
194
|
-
listPybAgentSessions,
|
|
195
|
-
resolvePybResumeSessionIdentifier
|
|
196
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/utils/protocol/pybAgentSessionResume.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync, readdirSync, readFileSync, statSync } from 'fs'\nimport { basename, join } from 'path'\nimport {\n getSessionProjectDir,\n getSessionProjectsDir,\n} from './pybAgentSessionLog'\nimport { isUuid } from '@utils/text/uuid'\n\nexport type PybAgentSessionListItem = {\n sessionId: string\n slug: string | null\n customTitle: string | null\n tag: string | null\n summary: string | null\n cwd: string | null\n createdAt: Date | null\n modifiedAt: Date | null\n}\n\nexport type ResumeResolveResult =\n | { kind: 'ok'; sessionId: string }\n | { kind: 'ambiguous'; identifier: string; matchingSessionIds: string[] }\n | { kind: 'different_directory'; sessionId: string; otherCwd: string | null }\n | { kind: 'not_found'; identifier: string }\n\nfunction safeParseJson(line: string): unknown | null {\n try {\n return JSON.parse(line)\n } catch {\n return null\n }\n}\n\nfunction safeParseDate(value: unknown): Date | null {\n if (typeof value !== 'string') return null\n const d = new Date(value)\n if (Number.isNaN(d.getTime())) return null\n return d\n}\n\nfunction readSessionListItemBestEffort(args: {\n filePath: string\n sessionId: string\n}): Omit<PybAgentSessionListItem, 'sessionId'> {\n const { filePath, sessionId } = args\n\n let slug: string | null = null\n let cwd: string | null = null\n let createdAt: Date | null = null\n let modifiedAt: Date | null = null\n let customTitle: string | null = null\n let tag: string | null = null\n let lastAssistantUuid: string | null = null\n const summariesByLeaf = new Map<string, string>()\n let lastSummary: string | null = null\n\n try {\n modifiedAt = new Date(statSync(filePath).mtimeMs)\n } catch {\n modifiedAt = null\n }\n\n let content: string\n try {\n content = readFileSync(filePath, 'utf8')\n } catch {\n return {\n slug,\n customTitle,\n tag,\n summary: null,\n cwd,\n createdAt,\n modifiedAt,\n }\n }\n\n for (const rawLine of content.split('\\n')) {\n const line = rawLine.trim()\n if (!line) continue\n const parsed = safeParseJson(line)\n if (!parsed || typeof parsed !== 'object') continue\n\n const entry: any = parsed\n\n if (!slug && typeof entry.slug === 'string' && entry.slug.trim()) {\n slug = entry.slug.trim()\n }\n if (!cwd && typeof entry.cwd === 'string' && entry.cwd.trim()) {\n cwd = entry.cwd.trim()\n }\n if (!createdAt) {\n const ts = safeParseDate(entry.timestamp)\n if (ts) createdAt = ts\n }\n\n if (typeof entry.type !== 'string') continue\n\n if (entry.type === 'assistant') {\n if (typeof entry.uuid === 'string' && entry.uuid)\n lastAssistantUuid = entry.uuid\n continue\n }\n\n if (entry.type === 'summary') {\n const leafUuid = typeof entry.leafUuid === 'string' ? entry.leafUuid : ''\n const summary = typeof entry.summary === 'string' ? entry.summary : ''\n if (leafUuid && summary) {\n summariesByLeaf.set(leafUuid, summary)\n lastSummary = summary\n }\n continue\n }\n\n if (entry.type === 'custom-title') {\n const id = typeof entry.sessionId === 'string' ? entry.sessionId : ''\n const title =\n typeof entry.customTitle === 'string' ? entry.customTitle : ''\n if (id === sessionId && title) customTitle = title\n continue\n }\n\n if (entry.type === 'tag') {\n const id = typeof entry.sessionId === 'string' ? entry.sessionId : ''\n const t = typeof entry.tag === 'string' ? entry.tag : ''\n if (id === sessionId && t) tag = t\n continue\n }\n }\n\n const summary =\n (lastAssistantUuid\n ? (summariesByLeaf.get(lastAssistantUuid) ?? null)\n : null) ??\n lastSummary ??\n null\n\n return {\n slug,\n customTitle,\n tag,\n summary,\n cwd,\n createdAt,\n modifiedAt,\n }\n}\n\nexport function listPybAgentSessions(args: {\n cwd: string\n}): PybAgentSessionListItem[] {\n const { cwd } = args\n const projectDir = getSessionProjectDir(cwd)\n if (!existsSync(projectDir)) return []\n\n const candidates = readdirSync(projectDir)\n .filter(name => name.endsWith('.jsonl'))\n .filter(name => !name.startsWith('agent-'))\n .map(name => ({\n sessionId: basename(name, '.jsonl'),\n filePath: join(projectDir, name),\n }))\n .filter(c => isUuid(c.sessionId))\n\n const items = candidates.map(({ sessionId, filePath }) => ({\n sessionId,\n ...readSessionListItemBestEffort({ filePath, sessionId }),\n }))\n\n items.sort((a, b) => {\n const am = a.modifiedAt?.getTime() ?? 0\n const bm = b.modifiedAt?.getTime() ?? 0\n return bm - am\n })\n\n return items\n}\n\nfunction findSessionFileAcrossProjects(args: {\n sessionId: string\n}): { filePath: string } | null {\n const { sessionId } = args\n const projectsDir = getSessionProjectsDir()\n if (!existsSync(projectsDir)) return null\n\n let projectNames: string[]\n try {\n projectNames = readdirSync(projectsDir)\n } catch {\n return null\n }\n\n for (const projectName of projectNames) {\n const candidate = join(projectsDir, projectName, `${sessionId}.jsonl`)\n if (existsSync(candidate)) return { filePath: candidate }\n }\n\n return null\n}\n\nfunction readSessionCwdBestEffort(filePath: string): string | null {\n try {\n const content = readFileSync(filePath, 'utf8')\n for (const rawLine of content.split('\\n')) {\n const line = rawLine.trim()\n if (!line) continue\n const parsed = safeParseJson(line)\n if (!parsed || typeof parsed !== 'object') continue\n const cwd = (parsed as any).cwd\n if (typeof cwd === 'string' && cwd.trim()) return cwd.trim()\n }\n } catch {\n }\n return null\n}\n\nfunction sessionExistsInProject(cwd: string, sessionId: string): boolean {\n try {\n return existsSync(join(getSessionProjectDir(cwd), `${sessionId}.jsonl`))\n } catch {\n return false\n }\n}\n\nexport function resolvePybResumeSessionIdentifier(args: {\n cwd: string\n identifier: string\n}): ResumeResolveResult {\n const { cwd, identifier } = args\n const id = identifier.trim()\n if (!id) return { kind: 'not_found', identifier }\n\n if (isUuid(id)) {\n if (sessionExistsInProject(cwd, id)) return { kind: 'ok', sessionId: id }\n\n const elsewhere = findSessionFileAcrossProjects({ sessionId: id })\n if (elsewhere) {\n return {\n kind: 'different_directory',\n sessionId: id,\n otherCwd: readSessionCwdBestEffort(elsewhere.filePath),\n }\n }\n\n return { kind: 'not_found', identifier: id }\n }\n\n const sessions = listPybAgentSessions({ cwd })\n const matches = sessions\n .filter(s => s.slug === id || s.customTitle === id)\n .map(s => s.sessionId)\n\n if (matches.length === 1) return { kind: 'ok', sessionId: matches[0]! }\n if (matches.length > 1)\n return { kind: 'ambiguous', identifier: id, matchingSessionIds: matches }\n return { kind: 'not_found', identifier: id }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAAA,SAAS,YAAY,aAAa,cAAc,gBAAgB;AAChE,SAAS,UAAU,YAAY;AAwB/B,SAAS,cAAc,MAA8B;AACnD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,cAAc,OAA6B;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,IAAI,IAAI,KAAK,KAAK;AACxB,MAAI,OAAO,MAAM,EAAE,QAAQ,CAAC,EAAG,QAAO;AACtC,SAAO;AACT;AAEA,SAAS,8BAA8B,MAGQ;AAC7C,QAAM,EAAE,UAAU,UAAU,IAAI;AAEhC,MAAI,OAAsB;AAC1B,MAAI,MAAqB;AACzB,MAAI,YAAyB;AAC7B,MAAI,aAA0B;AAC9B,MAAI,cAA6B;AACjC,MAAI,MAAqB;AACzB,MAAI,oBAAmC;AACvC,QAAM,kBAAkB,oBAAI,IAAoB;AAChD,MAAI,cAA6B;AAEjC,MAAI;AACF,iBAAa,IAAI,KAAK,SAAS,QAAQ,EAAE,OAAO;AAAA,EAClD,QAAQ;AACN,iBAAa;AAAA,EACf;AAEA,MAAI;AACJ,MAAI;AACF,cAAU,aAAa,UAAU,MAAM;AAAA,E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;AAAA,IACF;AAEA,WAAO,EAAE,MAAM,aAAa,YAAY,GAAG;AAAA,EAC7C;AAEA,QAAM,WAAW,qBAAqB,EAAE,IAAI,CAAC;AAC7C,QAAM,UAAU,SACb,OAAO,OAAK,EAAE,SAAS,MAAM,EAAE,gBAAgB,EAAE,EACjD,IAAI,OAAK,EAAE,SAAS;AAEvB,MAAI,QAAQ,WAAW,EAAG,QAAO,EAAE,MAAM,MAAM,WAAW,QAAQ,CAAC,EAAG;AACtE,MAAI,QAAQ,SAAS;AACnB,WAAO,EAAE,MAAM,aAAa,YAAY,IAAI,oBAAoB,QAAQ;AAC1E,SAAO,EAAE,MAAM,aAAa,YAAY,GAAG;AAC7C;",
|
|
6
|
-
"names": ["summary"]
|
|
7
|
-
}
|
package/dist/chunk-N3T2WAYN.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { createRequire as __pybCreateRequire } from "node:module";
|
|
2
|
-
const require = __pybCreateRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
getSessionProjectDir
|
|
5
|
-
} from "./chunk-TSAURYF2.js";
|
|
6
|
-
import {
|
|
7
|
-
isUuid
|
|
8
|
-
} from "./chunk-5P7HBXTD.js";
|
|
9
|
-
|
|
10
|
-
// src/utils/protocol/pybAgentSessionLoad.ts
|
|
11
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
12
|
-
import { basename, join } from "path";
|
|
13
|
-
function safeParseJson(line) {
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(line);
|
|
16
|
-
} catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function isUserEntry(entry) {
|
|
21
|
-
return typeof entry?.type === "string" && entry.type === "user";
|
|
22
|
-
}
|
|
23
|
-
function isAssistantEntry(entry) {
|
|
24
|
-
return typeof entry?.type === "string" && entry.type === "assistant";
|
|
25
|
-
}
|
|
26
|
-
function isSummaryEntry(entry) {
|
|
27
|
-
return typeof entry?.type === "string" && entry.type === "summary";
|
|
28
|
-
}
|
|
29
|
-
function isCustomTitleEntry(entry) {
|
|
30
|
-
return typeof entry?.type === "string" && entry.type === "custom-title";
|
|
31
|
-
}
|
|
32
|
-
function isTagEntry(entry) {
|
|
33
|
-
return typeof entry?.type === "string" && entry.type === "tag";
|
|
34
|
-
}
|
|
35
|
-
function isFileHistorySnapshotEntry(entry) {
|
|
36
|
-
return typeof entry?.type === "string" && entry.type === "file-history-snapshot";
|
|
37
|
-
}
|
|
38
|
-
function normalizeLoadedUser(entry) {
|
|
39
|
-
if (!entry.uuid || !entry.message) return null;
|
|
40
|
-
return {
|
|
41
|
-
type: "user",
|
|
42
|
-
uuid: entry.uuid,
|
|
43
|
-
message: entry.message
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function normalizeLoadedAssistant(entry) {
|
|
47
|
-
if (!entry.uuid || !entry.message) return null;
|
|
48
|
-
return {
|
|
49
|
-
type: "assistant",
|
|
50
|
-
uuid: entry.uuid,
|
|
51
|
-
costUSD: 0,
|
|
52
|
-
durationMs: 0,
|
|
53
|
-
message: entry.message,
|
|
54
|
-
...entry.isApiErrorMessage ? { isApiErrorMessage: true } : {},
|
|
55
|
-
...typeof entry.requestId === "string" ? { requestId: entry.requestId } : {}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function loadPybAgentSessionLogData(args) {
|
|
59
|
-
const { cwd, sessionId } = args;
|
|
60
|
-
const projectDir = getSessionProjectDir(cwd);
|
|
61
|
-
const filePath = join(projectDir, `${sessionId}.jsonl`);
|
|
62
|
-
if (!existsSync(filePath)) {
|
|
63
|
-
throw new Error(`No conversation found with session ID: ${sessionId}`);
|
|
64
|
-
}
|
|
65
|
-
const lines = readFileSync(filePath, "utf8").split("\n");
|
|
66
|
-
const messages = [];
|
|
67
|
-
const summaries = /* @__PURE__ */ new Map();
|
|
68
|
-
const customTitles = /* @__PURE__ */ new Map();
|
|
69
|
-
const tags = /* @__PURE__ */ new Map();
|
|
70
|
-
const fileHistorySnapshots = /* @__PURE__ */ new Map();
|
|
71
|
-
for (const line of lines) {
|
|
72
|
-
const raw = safeParseJson(line.trim());
|
|
73
|
-
if (!raw || typeof raw !== "object") continue;
|
|
74
|
-
const entry = raw;
|
|
75
|
-
if (isUserEntry(entry)) {
|
|
76
|
-
if (entry.sessionId && entry.sessionId !== sessionId) continue;
|
|
77
|
-
const msg = normalizeLoadedUser(entry);
|
|
78
|
-
if (msg) messages.push(msg);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if (isAssistantEntry(entry)) {
|
|
82
|
-
if (entry.sessionId && entry.sessionId !== sessionId) continue;
|
|
83
|
-
const msg = normalizeLoadedAssistant(entry);
|
|
84
|
-
if (msg) messages.push(msg);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (isSummaryEntry(entry)) {
|
|
88
|
-
const leafUuid = typeof entry.leafUuid === "string" ? entry.leafUuid : "";
|
|
89
|
-
const summary = typeof entry.summary === "string" ? entry.summary : "";
|
|
90
|
-
if (leafUuid && summary) summaries.set(leafUuid, summary);
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (isCustomTitleEntry(entry)) {
|
|
94
|
-
const id = typeof entry.sessionId === "string" ? entry.sessionId : "";
|
|
95
|
-
const title = typeof entry.customTitle === "string" ? entry.customTitle : "";
|
|
96
|
-
if (id && title) customTitles.set(id, title);
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (isTagEntry(entry)) {
|
|
100
|
-
const id = typeof entry.sessionId === "string" ? entry.sessionId : "";
|
|
101
|
-
const tag = typeof entry.tag === "string" ? entry.tag : "";
|
|
102
|
-
if (id && tag) tags.set(id, tag);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (isFileHistorySnapshotEntry(entry)) {
|
|
106
|
-
const messageId = typeof entry.messageId === "string" ? entry.messageId : "";
|
|
107
|
-
if (messageId) fileHistorySnapshots.set(messageId, entry);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return { messages, summaries, customTitles, tags, fileHistorySnapshots };
|
|
112
|
-
}
|
|
113
|
-
function loadPybAgentSessionMessages(args) {
|
|
114
|
-
return loadPybAgentSessionLogData(args).messages;
|
|
115
|
-
}
|
|
116
|
-
function findMostRecentPybAgentSessionId(cwd) {
|
|
117
|
-
const projectDir = getSessionProjectDir(cwd);
|
|
118
|
-
if (!existsSync(projectDir)) return null;
|
|
119
|
-
const candidates = readdirSync(projectDir).filter((name) => name.endsWith(".jsonl")).filter((name) => !name.startsWith("agent-")).map((name) => ({
|
|
120
|
-
sessionId: basename(name, ".jsonl"),
|
|
121
|
-
path: join(projectDir, name)
|
|
122
|
-
})).filter((c) => isUuid(c.sessionId));
|
|
123
|
-
if (candidates.length === 0) return null;
|
|
124
|
-
candidates.sort((a, b) => {
|
|
125
|
-
try {
|
|
126
|
-
return statSync(b.path).mtimeMs - statSync(a.path).mtimeMs;
|
|
127
|
-
} catch {
|
|
128
|
-
return 0;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
return candidates[0]?.sessionId ?? null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export {
|
|
135
|
-
loadPybAgentSessionLogData,
|
|
136
|
-
loadPybAgentSessionMessages,
|
|
137
|
-
findMostRecentPybAgentSessionId
|
|
138
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/utils/protocol/pybAgentSessionLoad.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync, readdirSync, readFileSync, statSync } from 'fs'\nimport { basename, join } from 'path'\nimport type { Message } from '@query'\nimport type {\n Message as APIMessage,\n MessageParam,\n} from '@anthropic-ai/sdk/resources/index.mjs'\nimport { getSessionProjectDir } from './pybAgentSessionLog'\nimport { isUuid } from '@utils/text/uuid'\n\ntype JsonlUserEntry = {\n type: 'user'\n sessionId?: string\n uuid?: string\n message?: MessageParam\n isApiErrorMessage?: boolean\n toolUseResult?: unknown\n}\n\ntype JsonlAssistantEntry = {\n type: 'assistant'\n sessionId?: string\n uuid?: string\n message?: APIMessage\n isApiErrorMessage?: boolean\n requestId?: string\n}\n\ntype JsonlSummaryEntry = {\n type: 'summary'\n summary?: string\n leafUuid?: string\n}\n\ntype JsonlCustomTitleEntry = {\n type: 'custom-title'\n sessionId?: string\n customTitle?: string\n}\n\ntype JsonlTagEntry = {\n type: 'tag'\n sessionId?: string\n tag?: string\n}\n\ntype JsonlFileHistorySnapshotEntry = {\n type: 'file-history-snapshot'\n messageId?: string\n snapshot?: unknown\n isSnapshotUpdate?: boolean\n}\n\ntype JsonlEntry =\n | JsonlUserEntry\n | JsonlAssistantEntry\n | JsonlSummaryEntry\n | JsonlCustomTitleEntry\n | JsonlTagEntry\n | JsonlFileHistorySnapshotEntry\n | Record<string, unknown>\n\nfunction safeParseJson(line: string): unknown | null {\n try {\n return JSON.parse(line)\n } catch {\n return null\n }\n}\n\nfunction isUserEntry(entry: JsonlEntry): entry is JsonlUserEntry {\n return (\n typeof (entry as any)?.type === 'string' && (entry as any).type === 'user'\n )\n}\n\nfunction isAssistantEntry(entry: JsonlEntry): entry is JsonlAssistantEntry {\n return (\n typeof (entry as any)?.type === 'string' &&\n (entry as any).type === 'assistant'\n )\n}\n\nfunction isSummaryEntry(entry: JsonlEntry): entry is JsonlSummaryEntry {\n return (\n typeof (entry as any)?.type === 'string' &&\n (entry as any).type === 'summary'\n )\n}\n\nfunction isCustomTitleEntry(entry: JsonlEntry): entry is JsonlCustomTitleEntry {\n return (\n typeof (entry as any)?.type === 'string' &&\n (entry as any).type === 'custom-title'\n )\n}\n\nfunction isTagEntry(entry: JsonlEntry): entry is JsonlTagEntry {\n return (\n typeof (entry as any)?.type === 'string' && (entry as any).type === 'tag'\n )\n}\n\nfunction isFileHistorySnapshotEntry(\n entry: JsonlEntry,\n): entry is JsonlFileHistorySnapshotEntry {\n return (\n typeof (entry as any)?.type === 'string' &&\n (entry as any).type === 'file-history-snapshot'\n )\n}\n\nfunction normalizeLoadedUser(entry: JsonlUserEntry): Message | null {\n if (!entry.uuid || !entry.message) return null\n return {\n type: 'user',\n uuid: entry.uuid as any,\n message: entry.message as any,\n }\n}\n\nfunction normalizeLoadedAssistant(entry: JsonlAssistantEntry): Message | null {\n if (!entry.uuid || !entry.message) return null\n return {\n type: 'assistant',\n uuid: entry.uuid as any,\n costUSD: 0,\n durationMs: 0,\n message: entry.message as any,\n ...(entry.isApiErrorMessage ? { isApiErrorMessage: true } : {}),\n ...(typeof entry.requestId === 'string'\n ? { requestId: entry.requestId }\n : {}),\n } as any\n}\n\nexport type PybAgentSessionLogData = {\n messages: Message[]\n summaries: Map<string, string>\n customTitles: Map<string, string>\n tags: Map<string, string>\n fileHistorySnapshots: Map<string, JsonlFileHistorySnapshotEntry>\n}\n\nexport function loadPybAgentSessionLogData(args: {\n cwd: string\n sessionId: string\n}): PybAgentSessionLogData {\n const { cwd, sessionId } = args\n const projectDir = getSessionProjectDir(cwd)\n const filePath = join(projectDir, `${sessionId}.jsonl`)\n if (!existsSync(filePath)) {\n throw new Error(`No conversation found with session ID: ${sessionId}`)\n }\n\n const lines = readFileSync(filePath, 'utf8').split('\\n')\n const messages: Message[] = []\n const summaries = new Map<string, string>()\n const customTitles = new Map<string, string>()\n const tags = new Map<string, string>()\n const fileHistorySnapshots = new Map<string, JsonlFileHistorySnapshotEntry>()\n\n for (const line of lines) {\n const raw = safeParseJson(line.trim())\n if (!raw || typeof raw !== 'object') continue\n const entry = raw as JsonlEntry\n\n if (isUserEntry(entry)) {\n if (entry.sessionId && entry.sessionId !== sessionId) continue\n const msg = normalizeLoadedUser(entry)\n if (msg) messages.push(msg)\n continue\n }\n\n if (isAssistantEntry(entry)) {\n if (entry.sessionId && entry.sessionId !== sessionId) continue\n const msg = normalizeLoadedAssistant(entry)\n if (msg) messages.push(msg)\n continue\n }\n\n if (isSummaryEntry(entry)) {\n const leafUuid = typeof entry.leafUuid === 'string' ? entry.leafUuid : ''\n const summary = typeof entry.summary === 'string' ? entry.summary : ''\n if (leafUuid && summary) summaries.set(leafUuid, summary)\n continue\n }\n\n if (isCustomTitleEntry(entry)) {\n const id = typeof entry.sessionId === 'string' ? entry.sessionId : ''\n const title =\n typeof entry.customTitle === 'string' ? entry.customTitle : ''\n if (id && title) customTitles.set(id, title)\n continue\n }\n\n if (isTagEntry(entry)) {\n const id = typeof entry.sessionId === 'string' ? entry.sessionId : ''\n const tag = typeof entry.tag === 'string' ? entry.tag : ''\n if (id && tag) tags.set(id, tag)\n continue\n }\n\n if (isFileHistorySnapshotEntry(entry)) {\n const messageId =\n typeof entry.messageId === 'string' ? entry.messageId : ''\n if (messageId) fileHistorySnapshots.set(messageId, entry)\n continue\n }\n }\n\n return { messages, summaries, customTitles, tags, fileHistorySnapshots }\n}\n\nexport function loadPybAgentSessionMessages(args: {\n cwd: string\n sessionId: string\n}): Message[] {\n return loadPybAgentSessionLogData(args).messages\n}\n\nexport function findMostRecentPybAgentSessionId(cwd: string): string | null {\n const projectDir = getSessionProjectDir(cwd)\n if (!existsSync(projectDir)) return null\n\n const candidates = readdirSync(projectDir)\n .filter(name => name.endsWith('.jsonl'))\n .filter(name => !name.startsWith('agent-'))\n .map(name => ({\n sessionId: basename(name, '.jsonl'),\n path: join(projectDir, name),\n }))\n .filter(c => isUuid(c.sessionId))\n\n if (candidates.length === 0) return null\n\n candidates.sort((a, b) => {\n try {\n return statSync(b.path).mtimeMs - statSync(a.path).mtimeMs\n } catch {\n return 0\n }\n })\n\n return candidates[0]?.sessionId ?? null\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;AAAA,SAAS,YAAY,aAAa,cAAc,gBAAgB;AAChE,SAAS,UAAU,YAAY;AA6D/B,SAAS,cAAc,MAA8B;AACnD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,Y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AAW,MAAM,MAAM;AACxD,UAAI,MAAM,IAAK,MAAK,IAAI,IAAI,GAAG;AAC/B;AAAA,IACF;AAEA,QAAI,2BAA2B,KAAK,GAAG;AACrC,YAAM,YACJ,OAAO,MAAM,cAAc,WAAW,MAAM,YAAY;AAC1D,UAAI,UAAW,sBAAqB,IAAI,WAAW,KAAK;AACxD;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,WAAW,cAAc,MAAM,qBAAqB;AACzE;AAEO,SAAS,4BAA4B,MAG9B;AACZ,SAAO,2BAA2B,IAAI,EAAE;AAC1C;AAEO,SAAS,gCAAgC,KAA4B;AAC1E,QAAM,aAAa,qBAAqB,GAAG;AAC3C,MAAI,CAAC,WAAW,UAAU,EAAG,QAAO;AAEpC,QAAM,aAAa,YAAY,UAAU,EACtC,OAAO,UAAQ,KAAK,SAAS,QAAQ,CAAC,EACtC,OAAO,UAAQ,CAAC,KAAK,WAAW,QAAQ,CAAC,EACzC,IAAI,WAAS;AAAA,IACZ,WAAW,SAAS,MAAM,QAAQ;AAAA,IAClC,MAAM,KAAK,YAAY,IAAI;AAAA,EAC7B,EAAE,EACD,OAAO,OAAK,OAAO,EAAE,SAAS,CAAC;AAElC,MAAI,WAAW,WAAW,EAAG,QAAO;AAEpC,aAAW,KAAK,CAAC,GAAG,MAAM;AACxB,QAAI;AACF,aAAO,SAAS,EAAE,IAAI,EAAE,UAAU,SAAS,EAAE,IAAI,EAAE;AAAA,IACrD,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AAED,SAAO,WAAW,CAAC,GAAG,aAAa;AACrC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/chunk-TSAURYF2.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { createRequire as __pybCreateRequire } from "node:module";
|
|
2
|
-
const require = __pybCreateRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
getPybAgentSessionId
|
|
5
|
-
} from "./chunk-B6IMQJZM.js";
|
|
6
|
-
import {
|
|
7
|
-
getCwd,
|
|
8
|
-
resolveXdgDataPath
|
|
9
|
-
} from "./chunk-VP5A6FKG.js";
|
|
10
|
-
|
|
11
|
-
// src/utils/protocol/pybAgentSessionLog.ts
|
|
12
|
-
import {
|
|
13
|
-
appendFileSync,
|
|
14
|
-
existsSync,
|
|
15
|
-
mkdirSync,
|
|
16
|
-
readFileSync,
|
|
17
|
-
statSync,
|
|
18
|
-
writeFileSync
|
|
19
|
-
} from "fs";
|
|
20
|
-
import { dirname, join } from "path";
|
|
21
|
-
function getSessionStoreBaseDir() {
|
|
22
|
-
return resolveXdgDataPath("sessions");
|
|
23
|
-
}
|
|
24
|
-
function sanitizeProjectNameForSessionStore(cwd) {
|
|
25
|
-
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
26
|
-
}
|
|
27
|
-
function getSessionProjectsDir() {
|
|
28
|
-
return join(getSessionStoreBaseDir(), "projects");
|
|
29
|
-
}
|
|
30
|
-
function getSessionProjectDir(cwd) {
|
|
31
|
-
return join(getSessionProjectsDir(), sanitizeProjectNameForSessionStore(cwd));
|
|
32
|
-
}
|
|
33
|
-
function getSessionLogFilePath(args) {
|
|
34
|
-
return join(getSessionProjectDir(args.cwd), `${args.sessionId}.jsonl`);
|
|
35
|
-
}
|
|
36
|
-
function safeMkdir(dir) {
|
|
37
|
-
if (existsSync(dir)) return;
|
|
38
|
-
mkdirSync(dir, { recursive: true });
|
|
39
|
-
}
|
|
40
|
-
function safeEnsureFile(path) {
|
|
41
|
-
safeMkdir(dirname(path));
|
|
42
|
-
if (!existsSync(path)) writeFileSync(path, "", "utf8");
|
|
43
|
-
}
|
|
44
|
-
function safeAppendJsonl(path, record) {
|
|
45
|
-
try {
|
|
46
|
-
safeEnsureFile(path);
|
|
47
|
-
appendFileSync(path, JSON.stringify(record) + "\n", "utf8");
|
|
48
|
-
} catch {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
var currentSessionCustomTitle = null;
|
|
52
|
-
var currentSessionTag = null;
|
|
53
|
-
function appendSessionCustomTitleRecord(args) {
|
|
54
|
-
const cwd = getCwd();
|
|
55
|
-
safeAppendJsonl(getSessionLogFilePath({ cwd, sessionId: args.sessionId }), {
|
|
56
|
-
type: "custom-title",
|
|
57
|
-
sessionId: args.sessionId,
|
|
58
|
-
customTitle: args.customTitle
|
|
59
|
-
});
|
|
60
|
-
if (args.sessionId === getPybAgentSessionId()) {
|
|
61
|
-
currentSessionCustomTitle = args.customTitle;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function appendSessionTagRecord(args) {
|
|
65
|
-
const cwd = getCwd();
|
|
66
|
-
safeAppendJsonl(getSessionLogFilePath({ cwd, sessionId: args.sessionId }), {
|
|
67
|
-
type: "tag",
|
|
68
|
-
sessionId: args.sessionId,
|
|
69
|
-
tag: args.tag
|
|
70
|
-
});
|
|
71
|
-
if (args.sessionId === getPybAgentSessionId()) {
|
|
72
|
-
currentSessionTag = args.tag;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export {
|
|
77
|
-
getSessionProjectsDir,
|
|
78
|
-
getSessionProjectDir,
|
|
79
|
-
appendSessionCustomTitleRecord,
|
|
80
|
-
appendSessionTagRecord
|
|
81
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/utils/protocol/pybAgentSessionLog.ts"],
|
|
4
|
-
"sourcesContent": ["import { execFileSync } from 'child_process'\nimport {\n appendFileSync,\n existsSync,\n mkdirSync,\n readFileSync,\n statSync,\n writeFileSync,\n} from 'fs'\nimport { randomBytes } from 'crypto'\nimport { dirname, join } from 'path'\nimport type { Message } from '@query'\nimport { MACRO } from '@constants/macros'\nimport { getCwd } from '@utils/state'\nimport { getPybAgentSessionId } from './pybAgentSessionId'\nimport { resolveXdgDataPath } from '@utils/config/env'\nimport {\n PLAN_SLUG_ADJECTIVES,\n PLAN_SLUG_NOUNS,\n PLAN_SLUG_VERBS,\n} from '@utils/plan/planSlugWords'\n\ntype PersistTarget =\n | { kind: 'session'; sessionId: string }\n | { kind: 'agent'; agentId: string }\n\ntype JsonlEnvelopeBase = {\n cwd: string\n sessionId: string\n version: string\n gitBranch?: string\n userType: string\n isSidechain: boolean\n parentUuid: string | null\n logicalParentUuid?: string\n agentId: string\n slug: string\n uuid: string\n timestamp: string\n}\n\ntype SessionJsonlEntry =\n | (JsonlEnvelopeBase & {\n type: 'user'\n message: any\n toolUseResult?: any\n })\n | (JsonlEnvelopeBase & {\n type: 'assistant'\n message: any\n requestId?: string\n isApiErrorMessage?: boolean\n })\n | { type: 'summary'; summary: string; leafUuid: string }\n | { type: 'custom-title'; sessionId: string; customTitle: string }\n | { type: 'tag'; sessionId: string; tag: string }\n | {\n type: 'file-history-snapshot'\n messageId: string\n snapshot: {\n messageId: string\n trackedFileBackups: Record<string, unknown>\n timestamp: string\n }\n isSnapshotUpdate: boolean\n }\n\nfunction getSessionStoreBaseDir(): string {\n return resolveXdgDataPath('sessions')\n}\n\nexport function sanitizeProjectNameForSessionStore(cwd: string): string {\n return cwd.replace(/[^a-zA-Z0-9]/g, '-')\n}\n\nexport function getSessionProjectsDir(): string {\n return join(getSessionStoreBaseDir(), 'projects')\n}\n\nexport function getSessionProjectDir(cwd: string): string {\n return join(getSessionProjectsDir(), sanitizeProjectNameForSessionStore(cwd))\n}\n\nexport function getSessionLogFilePath(args: {\n cwd: string\n sessionId: string\n}): string {\n return join(getSessionProjectDir(args.cwd), `${args.sessionId}.jsonl`)\n}\n\nexport function getAgentLogFilePath(args: {\n cwd: string\n agentId: string\n}): string {\n return join(getSessionProjectDir(args.cwd), `agent-${args.agentId}.jsonl`)\n}\n\nfunction safeMkdir(dir: string): void {\n if (existsSync(dir)) return\n mkdirSync(dir, { recursive: true })\n}\n\nfunction safeEnsureFile(path: string): void {\n safeMkdir(dirname(path))\n if (!existsSync(path)) writeFileSync(path, '', 'utf8')\n}\n\nfunction safeAppendJsonl(path: string, record: unknown): void {\n try {\n safeEnsureFile(path)\n appendFileSync(path, JSON.stringify(record) + '\\n', 'utf8')\n } catch {\n }\n}\n\nconst lastUuidByFile = new Map<string, string | null>()\nconst snapshotWrittenByFile = new Set<string>()\nconst slugBySessionId = new Map<string, string>()\nlet currentSessionCustomTitle: string | null = null\nlet currentSessionTag: string | null = null\n\ntype LastPersistedInfo = { uuid: string | null; slug: string | null }\n\nfunction safeReadLastPersistedInfo(filePath: string): LastPersistedInfo {\n try {\n if (!existsSync(filePath)) return { uuid: null, slug: null }\n const content = readFileSync(filePath, 'utf8')\n const lines = content.split('\\n')\n\n let lastSlug: string | null = null\n for (let i = lines.length - 1; i >= 0; i--) {\n const line = lines[i]?.trim()\n if (!line) continue\n let parsed: any\n try {\n parsed = JSON.parse(line)\n } catch {\n continue\n }\n if (!parsed || typeof parsed !== 'object') continue\n\n if (!lastSlug && typeof parsed.slug === 'string' && parsed.slug.trim()) {\n lastSlug = parsed.slug.trim()\n }\n\n if (typeof parsed.uuid === 'string' && parsed.uuid) {\n return { uuid: parsed.uuid, slug: lastSlug }\n }\n }\n\n return { uuid: null, slug: lastSlug }\n } catch {\n return { uuid: null, slug: null }\n }\n}\n\nfunction pickIndex(length: number): number {\n return randomBytes(4).readUInt32BE(0) % length\n}\n\nfunction pickWord(words: readonly string[]): string {\n return words[pickIndex(words.length)]!\n}\n\nfunction generateSessionSlug(): string {\n const adjective = pickWord(PLAN_SLUG_ADJECTIVES)\n const verb = pickWord(PLAN_SLUG_VERBS)\n const noun = pickWord(PLAN_SLUG_NOUNS)\n return `${adjective}-${verb}-${noun}`\n}\n\nfunction getOrCreateSessionSlug(sessionId: string): string {\n const existing = slugBySessionId.get(sessionId)\n if (existing) return existing\n const slug = generateSessionSlug()\n slugBySessionId.set(sessionId, slug)\n return slug\n}\n\ntype GitBranchCacheEntry = { cwd: string; value: string | undefined }\nlet gitBranchCache: GitBranchCacheEntry | null = null\n\nfunction getGitBranchBestEffort(cwd: string): string | undefined {\n if (gitBranchCache && gitBranchCache.cwd === cwd) return gitBranchCache.value\n\n let value: string | undefined\n try {\n const stdout = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {\n cwd,\n stdio: ['ignore', 'pipe', 'ignore'],\n timeout: 750,\n })\n const branch = stdout.toString('utf8').trim()\n value = branch || undefined\n } catch {\n value = undefined\n }\n\n gitBranchCache = { cwd, value }\n return value\n}\n\nfunction ensureFileHistorySnapshot(\n filePath: string,\n firstMessageUuid: string,\n): void {\n if (snapshotWrittenByFile.has(filePath)) return\n\n try {\n safeEnsureFile(filePath)\n const size = statSync(filePath).size\n if (size > 0) {\n snapshotWrittenByFile.add(filePath)\n return\n }\n } catch {\n }\n\n const now = new Date().toISOString()\n safeAppendJsonl(filePath, {\n type: 'file-history-snapshot',\n messageId: firstMessageUuid,\n snapshot: {\n messageId: firstMessageUuid,\n trackedFileBackups: {},\n timestamp: now,\n },\n isSnapshotUpdate: false,\n } satisfies SessionJsonlEntry)\n\n snapshotWrittenByFile.add(filePath)\n}\n\nfunction resolvePersistTarget(toolUseContext: {\n agentId?: string\n}): PersistTarget {\n const agentId = toolUseContext.agentId\n if (agentId && agentId !== 'main') return { kind: 'agent', agentId }\n return { kind: 'session', sessionId: getPybAgentSessionId() }\n}\n\nexport function appendSessionJsonlFromMessage(args: {\n message: Message\n toolUseContext: { agentId?: string }\n}): void {\n const { message, toolUseContext } = args\n if (message.type !== 'user' && message.type !== 'assistant') return\n\n const cwd = getCwd()\n const userType = (process.env.USER_TYPE ?? 'external').trim() || 'external'\n const sessionId = getPybAgentSessionId()\n const agentId = (toolUseContext.agentId ?? 'main').trim() || 'main'\n const isSidechain = agentId !== 'main'\n const gitBranch = getGitBranchBestEffort(cwd)\n\n const target = resolvePersistTarget(toolUseContext)\n const filePath =\n target.kind === 'agent'\n ? getAgentLogFilePath({ cwd, agentId: target.agentId })\n : getSessionLogFilePath({ cwd, sessionId: target.sessionId })\n\n if (!lastUuidByFile.has(filePath)) {\n const info = safeReadLastPersistedInfo(filePath)\n lastUuidByFile.set(filePath, info.uuid)\n if (info.slug) slugBySessionId.set(sessionId, info.slug)\n }\n const previousUuid = lastUuidByFile.get(filePath) ?? null\n\n const slug = getOrCreateSessionSlug(sessionId)\n\n if (target.kind === 'session') {\n ensureFileHistorySnapshot(filePath, message.uuid)\n }\n\n const base: JsonlEnvelopeBase = {\n parentUuid: previousUuid,\n logicalParentUuid: undefined,\n isSidechain,\n userType,\n cwd,\n sessionId,\n version: MACRO.VERSION,\n ...(gitBranch ? { gitBranch } : {}),\n agentId,\n slug,\n uuid: message.uuid,\n timestamp: new Date().toISOString(),\n }\n\n const record: SessionJsonlEntry =\n message.type === 'user'\n ? {\n ...base,\n type: 'user',\n message: message.message,\n ...(message.toolUseResult?.data !== undefined\n ? { toolUseResult: message.toolUseResult.data }\n : {}),\n }\n : {\n ...base,\n type: 'assistant',\n message: message.message,\n ...(typeof (message as any).requestId === 'string'\n ? { requestId: String((message as any).requestId) }\n : {}),\n ...(message.isApiErrorMessage ? { isApiErrorMessage: true } : {}),\n }\n\n safeAppendJsonl(filePath, record)\n lastUuidByFile.set(filePath, message.uuid)\n}\n\nexport function appendSessionSummaryRecord(args: {\n summary: string\n leafUuid: string\n sessionId?: string\n}): void {\n const sessionId = args.sessionId ?? getPybAgentSessionId()\n const cwd = getCwd()\n safeAppendJsonl(getSessionLogFilePath({ cwd, sessionId }), {\n type: 'summary',\n summary: args.summary,\n leafUuid: args.leafUuid,\n } satisfies SessionJsonlEntry)\n}\n\nexport function appendSessionCustomTitleRecord(args: {\n sessionId: string\n customTitle: string\n}): void {\n const cwd = getCwd()\n safeAppendJsonl(getSessionLogFilePath({ cwd, sessionId: args.sessionId }), {\n type: 'custom-title',\n sessionId: args.sessionId,\n customTitle: args.customTitle,\n } satisfies SessionJsonlEntry)\n if (args.sessionId === getPybAgentSessionId()) {\n currentSessionCustomTitle = args.customTitle\n }\n}\n\nexport function appendSessionTagRecord(args: {\n sessionId: string\n tag: string\n}): void {\n const cwd = getCwd()\n safeAppendJsonl(getSessionLogFilePath({ cwd, sessionId: args.sessionId }), {\n type: 'tag',\n sessionId: args.sessionId,\n tag: args.tag,\n } satisfies SessionJsonlEntry)\n if (args.sessionId === getPybAgentSessionId()) {\n currentSessionTag = args.tag\n }\n}\n\nexport function getCurrentSessionCustomTitle(): string | null {\n return currentSessionCustomTitle\n}\n\nexport function getCurrentSessionTag(): string | null {\n return currentSessionTag\n}\n\nexport function resetSessionJsonlStateForTests(): void {\n lastUuidByFile.clear()\n snapshotWrittenByFile.clear()\n slugBySessionId.clear()\n gitBranchCache = null\n currentSessionCustomTitle = null\n currentSessionTag = null\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,SAAS,YAAY;AAyD9B,SAAS,yBAAiC;AACxC,SAAO,mBAAmB,UAAU;AACtC;AAEO,SAAS,mCAAmC,KAAqB;AACtE,SAAO,IAAI,QAAQ,iBAAiB,GAAG;AACzC;AAEO,SAAS,wBAAgC;AAC9C,SAAO,KAAK,uBAAuB,GAAG,UAAU;AAClD;AAEO,SAAS,qBAAqB,KAAqB;AACxD,SAAO,KAAK,sBAAsB,GAAG,mCAAmC,GAAG,CAAC;AAC9E;AAEO,SAAS,sBAAsB,MAG3B;AACT,SAAO,KAAK,qBAAqB,KAAK,GAAG,GAAG,GAAG,KAAK,SAAS,QAAQ;AACvE;AASA,SAAS,UAAU,KAAmB;AACpC,MAAI,WAAW,GAAG,EAAG;AACrB,YAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AACpC;AAEA,SAAS,eAAe,MAAoB;AAC1C,YAAU,QAAQ,IAAI,CAAC;AACvB,MAAI,CAAC,WAAW,IAAI,EAAG,eAAc,MAAM,IAAI,MAAM;AACvD;AAEA,SAAS,gBAAgB,MAAc,QAAuB;AAC5D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