@cjhyy/code-shell 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anthropic-OVRWAZRD.js +1 -0
- package/dist/arena/index.js +1 -104
- package/dist/arena-64T2EQD4.js +3 -0
- package/dist/bwrap-PVZMLHZR.js +2 -0
- package/dist/chunk-2EUIMKJA.js +1 -0
- package/dist/chunk-2GJ7H5NC.js +641 -0
- package/dist/chunk-2OD6VR4N.js +2 -0
- package/dist/chunk-3QP5BQ3L.js +1 -0
- package/dist/chunk-A4M2Y42L.js +2 -0
- package/dist/chunk-DEYFK6FP.js +1 -0
- package/dist/chunk-DTPABBSV.js +2 -0
- package/dist/chunk-EU3J7TBP.js +1 -0
- package/dist/chunk-FU7AHZNN.js +1 -0
- package/dist/chunk-L7B2ORID.js +4 -0
- package/dist/chunk-M7VU4YVY.js +49 -0
- package/dist/chunk-MGP35GKD.js +254 -0
- package/dist/chunk-MLCTC53I.js +1 -0
- package/dist/chunk-O5HFCH2U.js +1 -0
- package/dist/chunk-P6JSTIFM.js +1 -0
- package/dist/chunk-Q3RSX66I.js +1 -0
- package/dist/chunk-QTWU7UNA.js +5 -0
- package/dist/chunk-RERBX75D.js +251 -0
- package/dist/chunk-SNFAPSLA.js +1 -0
- package/dist/chunk-T222K6IV.js +18 -0
- package/dist/chunk-TKJA6W36.js +3 -0
- package/dist/chunk-VKKU4LOM.js +3 -0
- package/dist/chunk-WI6FSWGU.js +1 -0
- package/dist/chunk-XXCZE2U2.js +2 -0
- package/dist/chunk-ZSAONDT6.js +2 -0
- package/dist/cli/main.js +303 -22060
- package/dist/cli/onboarding.d.ts +7 -2
- package/dist/client-base-F5FCRSB3.js +1 -0
- package/dist/compaction-L3Y6NG4N.js +1 -0
- package/dist/context/compaction.d.ts +2 -1
- package/dist/data/static-catalogs.d.ts +25 -0
- package/dist/devtools-SGDUOOM4.js +1 -0
- package/dist/engine/engine.d.ts +24 -0
- package/dist/engine/turn-loop.d.ts +20 -0
- package/dist/export-md-U72T7NW7.js +22 -0
- package/dist/file-history-7FQFEQOL.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -347
- package/dist/llm/capabilities/index.d.ts +20 -0
- package/dist/llm/capabilities/rules.d.ts +26 -0
- package/dist/llm/capabilities/types.d.ts +108 -0
- package/dist/llm/model-pool.d.ts +7 -0
- package/dist/llm/provider-catalog.d.ts +2 -0
- package/dist/llm/provider-kinds.d.ts +1 -1
- package/dist/llm/providers/openai.d.ts +22 -0
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/llm/types.d.ts +8 -0
- package/dist/logging/logger.d.ts +10 -2
- package/dist/logging/session-recorder.d.ts +16 -3
- package/dist/manager-J6FXEUEK.js +1 -0
- package/dist/mcp-manager-27EVBKRT.js +1 -0
- package/dist/memory-BNI4WEWL.js +1 -0
- package/dist/model-cache-HEDXI7UJ.js +1 -0
- package/dist/model-fetcher-X5W5EASG.js +1 -0
- package/dist/off-7SDVMMXW.js +1 -0
- package/dist/openai-3QEADSYL.js +1 -0
- package/dist/openrouter-models-GZVCRWD2.js +1 -0
- package/dist/openrouter-sync-WG4AG5NC.js +1 -0
- package/dist/product/index.js +1 -21
- package/dist/protocol/client.d.ts +1 -1
- package/dist/run/index.js +1 -48
- package/dist/seatbelt-L54CNI2Y.js +37 -0
- package/dist/session/session-manager.d.ts +2 -0
- package/dist/session-manager-AGWS5SMJ.js +1 -0
- package/dist/settings/schema.d.ts +147 -21
- package/dist/tool-summary-V2B3MD5N.js +2 -0
- package/dist/tool-system/builtin/bash.d.ts +7 -1
- package/dist/tool-system/context.d.ts +7 -0
- package/dist/tool-system/executor.d.ts +4 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/index.d.ts +78 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/tool-system/task-guard.d.ts +30 -0
- package/dist/types.d.ts +17 -0
- package/dist/ui/components/SessionPicker.d.ts +2 -0
- package/dist/ui/components/SpinnerWithVerb.d.ts +7 -2
- package/dist/ui/components/StatusLine.d.ts +7 -3
- package/dist/updater-OCNU2K2Z.js +1 -0
- package/package.json +7 -10
- package/dist/anthropic-IBTI4WL2.cjs +0 -10
- package/dist/anthropic-PRZZKHEZ.js +0 -10
- package/dist/arena/index.cjs +0 -104
- package/dist/arena-2LTLIXOL.js +0 -261
- package/dist/arena-ADB7DRFI.cjs +0 -261
- package/dist/chunk-2YW4FPFG.cjs +0 -101
- package/dist/chunk-3OA5G4TM.js +0 -47
- package/dist/chunk-3QO25N6E.js +0 -4711
- package/dist/chunk-3SBSUOWZ.js +0 -447
- package/dist/chunk-52LGZKT3.cjs +0 -47
- package/dist/chunk-55XGPMAP.cjs +0 -146
- package/dist/chunk-6QVAYW7C.cjs +0 -438
- package/dist/chunk-6S4BJ65N.js +0 -113
- package/dist/chunk-76HYEPDM.js +0 -307
- package/dist/chunk-7BI3V74Y.cjs +0 -447
- package/dist/chunk-7EG3V4JY.cjs +0 -113
- package/dist/chunk-7JVTYEEC.js +0 -340
- package/dist/chunk-7QIM3BKD.js +0 -44
- package/dist/chunk-7Y6S3OCX.js +0 -438
- package/dist/chunk-ABRRONJ7.js +0 -107
- package/dist/chunk-BSW22MPA.js +0 -146
- package/dist/chunk-BXCY2FSE.js +0 -203
- package/dist/chunk-BZ5TNE7L.js +0 -5128
- package/dist/chunk-DDB6QOKJ.cjs +0 -1252
- package/dist/chunk-HEKQCI7B.cjs +0 -224
- package/dist/chunk-IK4EWJBP.cjs +0 -203
- package/dist/chunk-ILHE7XLT.cjs +0 -107
- package/dist/chunk-JMR33QVF.cjs +0 -169
- package/dist/chunk-KAQHULYN.js +0 -54
- package/dist/chunk-KE4EQOWA.js +0 -294
- package/dist/chunk-KOVYSDHZ.cjs +0 -340
- package/dist/chunk-KS3RYAYL.cjs +0 -45
- package/dist/chunk-MD32R22I.js +0 -50
- package/dist/chunk-MV7YI4WO.cjs +0 -293
- package/dist/chunk-MY5XHADU.cjs +0 -216
- package/dist/chunk-NUNC3VFB.cjs +0 -307
- package/dist/chunk-PKGRTCCY.js +0 -9092
- package/dist/chunk-QARL3IDQ.js +0 -1252
- package/dist/chunk-S754JHLR.cjs +0 -54
- package/dist/chunk-SFXHZSRF.js +0 -101
- package/dist/chunk-SIHHIQLO.js +0 -224
- package/dist/chunk-T6VYG46N.js +0 -105
- package/dist/chunk-TNLGBJYS.cjs +0 -44
- package/dist/chunk-TUY2T5KP.cjs +0 -105
- package/dist/chunk-UXOCVJJ6.cjs +0 -9092
- package/dist/chunk-VIAGTYYW.js +0 -169
- package/dist/chunk-WASS5YWB.js +0 -215
- package/dist/chunk-WZJV6DJC.cjs +0 -5128
- package/dist/chunk-YIQBXAYU.cjs +0 -264
- package/dist/chunk-YKIAELDZ.cjs +0 -4711
- package/dist/chunk-ZBPSQCPU.js +0 -264
- package/dist/cli/main.cjs +0 -22156
- package/dist/client-base-HTF236ZD.cjs +0 -9
- package/dist/client-base-QKRKCOWB.js +0 -9
- package/dist/compaction-6VU2T643.js +0 -33
- package/dist/compaction-OKUNTCA7.cjs +0 -33
- package/dist/devtools-T2NIZBJK.cjs +0 -6
- package/dist/devtools-YXWHOVKR.js +0 -6
- package/dist/export-md-RXDW6F5W.cjs +0 -135
- package/dist/export-md-XXKZANW5.js +0 -135
- package/dist/file-history-KYPE3ECT.cjs +0 -7
- package/dist/file-history-LF4F7X26.js +0 -7
- package/dist/index.cjs +0 -347
- package/dist/manager-D65VFAPX.js +0 -7
- package/dist/manager-TTF5VHJC.cjs +0 -7
- package/dist/mcp-manager-QMKWPBZ4.js +0 -8
- package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
- package/dist/memory-5LWZ6FI2.cjs +0 -9
- package/dist/memory-VIJLBAMQ.js +0 -9
- package/dist/model-cache-5KIYL5SL.js +0 -13
- package/dist/model-cache-OED3IM4R.cjs +0 -13
- package/dist/model-fetcher-HKGICACL.js +0 -8
- package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
- package/dist/openai-JR2WEKOF.js +0 -10
- package/dist/openai-YBTOET4O.cjs +0 -10
- package/dist/openrouter-models-H56GHBHN.js +0 -15
- package/dist/openrouter-models-TWUFWZ5T.cjs +0 -15
- package/dist/openrouter-sync-5VMGN6C2.cjs +0 -11
- package/dist/openrouter-sync-ALEMF5IU.js +0 -11
- package/dist/product/index.cjs +0 -21
- package/dist/run/index.cjs +0 -48
- package/dist/session-manager-Q22BBMD3.js +0 -8
- package/dist/session-manager-XODQVL3C.cjs +0 -8
- package/dist/tool-summary-63DPIS7G.cjs +0 -31
- package/dist/tool-summary-NP5CDBKG.js +0 -31
- package/dist/updater-I7QBW4DP.cjs +0 -17
- package/dist/updater-NVME5S3Z.js +0 -17
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunk7EG3V4JYcjs = require('./chunk-7EG3V4JY.cjs');
|
|
4
|
-
require('./chunk-2YW4FPFG.cjs');
|
|
5
|
-
require('./chunk-IK4EWJBP.cjs');
|
|
6
|
-
require('./chunk-KS3RYAYL.cjs');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.LLMClientBase = _chunk7EG3V4JYcjs.LLMClientBase;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
COMPACTABLE_TOOL_NAMES,
|
|
3
|
-
adjustIndexToPreserveAPIInvariants,
|
|
4
|
-
applySummaryCompaction,
|
|
5
|
-
applyToolResultBudget,
|
|
6
|
-
buildSummarizationPrompt,
|
|
7
|
-
dropOldestRounds,
|
|
8
|
-
estimateTokens,
|
|
9
|
-
extractReferencedFilePaths,
|
|
10
|
-
groupMessagesByApiRound,
|
|
11
|
-
init_compaction,
|
|
12
|
-
microcompact,
|
|
13
|
-
snipCompact,
|
|
14
|
-
truncateToolResult,
|
|
15
|
-
windowCompact
|
|
16
|
-
} from "./chunk-7Y6S3OCX.js";
|
|
17
|
-
import "./chunk-MD32R22I.js";
|
|
18
|
-
init_compaction();
|
|
19
|
-
export {
|
|
20
|
-
COMPACTABLE_TOOL_NAMES,
|
|
21
|
-
adjustIndexToPreserveAPIInvariants,
|
|
22
|
-
applySummaryCompaction,
|
|
23
|
-
applyToolResultBudget,
|
|
24
|
-
buildSummarizationPrompt,
|
|
25
|
-
dropOldestRounds,
|
|
26
|
-
estimateTokens,
|
|
27
|
-
extractReferencedFilePaths,
|
|
28
|
-
groupMessagesByApiRound,
|
|
29
|
-
microcompact,
|
|
30
|
-
snipCompact,
|
|
31
|
-
truncateToolResult,
|
|
32
|
-
windowCompact
|
|
33
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _chunk6QVAYW7Ccjs = require('./chunk-6QVAYW7C.cjs');
|
|
17
|
-
require('./chunk-KS3RYAYL.cjs');
|
|
18
|
-
_chunk6QVAYW7Ccjs.init_compaction.call(void 0, );
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
exports.COMPACTABLE_TOOL_NAMES = _chunk6QVAYW7Ccjs.COMPACTABLE_TOOL_NAMES; exports.adjustIndexToPreserveAPIInvariants = _chunk6QVAYW7Ccjs.adjustIndexToPreserveAPIInvariants; exports.applySummaryCompaction = _chunk6QVAYW7Ccjs.applySummaryCompaction; exports.applyToolResultBudget = _chunk6QVAYW7Ccjs.applyToolResultBudget; exports.buildSummarizationPrompt = _chunk6QVAYW7Ccjs.buildSummarizationPrompt; exports.dropOldestRounds = _chunk6QVAYW7Ccjs.dropOldestRounds; exports.estimateTokens = _chunk6QVAYW7Ccjs.estimateTokens; exports.extractReferencedFilePaths = _chunk6QVAYW7Ccjs.extractReferencedFilePaths; exports.groupMessagesByApiRound = _chunk6QVAYW7Ccjs.groupMessagesByApiRound; exports.microcompact = _chunk6QVAYW7Ccjs.microcompact; exports.snipCompact = _chunk6QVAYW7Ccjs.snipCompact; exports.truncateToolResult = _chunk6QVAYW7Ccjs.truncateToolResult; exports.windowCompact = _chunk6QVAYW7Ccjs.windowCompact;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
4
|
-
|
|
5
|
-
// src/cli/commands/builtin/export-md.ts
|
|
6
|
-
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
7
|
-
var _path = require('path');
|
|
8
|
-
var INLINE_RESULT_LIMIT = 2e3;
|
|
9
|
-
var INLINE_ARG_LIMIT = 800;
|
|
10
|
-
var SAFE_SID_RE = /^[A-Za-z0-9_-]+$/;
|
|
11
|
-
function renderSessionMarkdown(sessionId, events, cwd) {
|
|
12
|
-
if (!SAFE_SID_RE.test(sessionId)) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`renderSessionMarkdown: invalid sessionId ${JSON.stringify(sessionId)} \u2014 expected [A-Za-z0-9_-]+`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
const lines = [];
|
|
18
|
-
const sidecars = [];
|
|
19
|
-
const sidecarDir = `session-${sessionId}-attachments`;
|
|
20
|
-
lines.push(`# Session ${sessionId}`);
|
|
21
|
-
lines.push("");
|
|
22
|
-
let turnNumber = 0;
|
|
23
|
-
for (const evRaw of events) {
|
|
24
|
-
const ev = evRaw;
|
|
25
|
-
if (ev.type !== "message") continue;
|
|
26
|
-
turnNumber += 1;
|
|
27
|
-
const role = _nullishCoalesce(_optionalChain([ev, 'access', _ => _.data, 'optionalAccess', _2 => _2.role]), () => ( "unknown"));
|
|
28
|
-
const content = _optionalChain([ev, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.content]);
|
|
29
|
-
lines.push(`## turn ${turnNumber} \xB7 ${role}`);
|
|
30
|
-
lines.push("");
|
|
31
|
-
if (typeof content === "string") {
|
|
32
|
-
lines.push(content);
|
|
33
|
-
lines.push("");
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (!Array.isArray(content)) {
|
|
37
|
-
lines.push("```json");
|
|
38
|
-
lines.push(JSON.stringify(content, null, 2));
|
|
39
|
-
lines.push("```");
|
|
40
|
-
lines.push("");
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
let itemIdx = 0;
|
|
44
|
-
for (const itemRaw of content) {
|
|
45
|
-
itemIdx += 1;
|
|
46
|
-
const block = renderBlock(itemRaw, {
|
|
47
|
-
turnNumber,
|
|
48
|
-
itemIdx,
|
|
49
|
-
sidecarDir,
|
|
50
|
-
cwd,
|
|
51
|
-
sidecars
|
|
52
|
-
});
|
|
53
|
-
if (block) {
|
|
54
|
-
lines.push(block);
|
|
55
|
-
lines.push("");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return { md: lines.join("\n"), sidecars };
|
|
60
|
-
}
|
|
61
|
-
function renderBlock(item, rctx) {
|
|
62
|
-
const t = item.type;
|
|
63
|
-
if (t === "reasoning") {
|
|
64
|
-
const txt = _nullishCoalesce(item.reasoningContent, () => ( ""));
|
|
65
|
-
return collapsible("reasoning", txt);
|
|
66
|
-
}
|
|
67
|
-
if (t === "text") {
|
|
68
|
-
return _nullishCoalesce(item.text, () => ( ""));
|
|
69
|
-
}
|
|
70
|
-
if (t === "tool_use") {
|
|
71
|
-
const name = _nullishCoalesce(item.name, () => ( "?"));
|
|
72
|
-
const argsJson = _nullishCoalesce(JSON.stringify(_nullishCoalesce(item.input, () => ( {})), null, 2), () => ( "{}"));
|
|
73
|
-
const head = `**\u{1F6E0} tool_use** \xB7 \`${name}\``;
|
|
74
|
-
if (argsJson.length <= INLINE_ARG_LIMIT) {
|
|
75
|
-
return `${head}
|
|
76
|
-
|
|
77
|
-
\`\`\`json
|
|
78
|
-
${argsJson}
|
|
79
|
-
\`\`\``;
|
|
80
|
-
}
|
|
81
|
-
return collapsible(`${name} args (${argsJson.length} bytes)`, argsJson, "json");
|
|
82
|
-
}
|
|
83
|
-
if (t === "tool_result") {
|
|
84
|
-
const toolUseId = _nullishCoalesce(_nullishCoalesce(item.tool_use_id, () => ( item.id)), () => ( "?"));
|
|
85
|
-
const raw = stringifyResult(item.content);
|
|
86
|
-
if (raw.length <= INLINE_RESULT_LIMIT) {
|
|
87
|
-
return `**\u25C0 tool_result** \xB7 ${toolUseId}
|
|
88
|
-
|
|
89
|
-
\`\`\`
|
|
90
|
-
${raw}
|
|
91
|
-
\`\`\``;
|
|
92
|
-
}
|
|
93
|
-
const sidecarName = `t${rctx.turnNumber}-i${rctx.itemIdx}-${toolUseId.slice(0, 12)}.txt`;
|
|
94
|
-
const sidecarPath = _path.join.call(void 0, rctx.cwd, rctx.sidecarDir, sidecarName);
|
|
95
|
-
rctx.sidecars.push({ path: sidecarPath, content: raw });
|
|
96
|
-
const preview = raw.slice(0, INLINE_RESULT_LIMIT);
|
|
97
|
-
const rel = _path.join.call(void 0, rctx.sidecarDir, _path.basename.call(void 0, sidecarPath));
|
|
98
|
-
return `**\u25C0 tool_result** \xB7 ${toolUseId} \xB7 ${raw.length.toLocaleString()} bytes \xB7 [full \u2192 ${rel}](./${rel})
|
|
99
|
-
|
|
100
|
-
\`\`\`
|
|
101
|
-
${preview}
|
|
102
|
-
\u2026(truncated, see sidecar)
|
|
103
|
-
\`\`\``;
|
|
104
|
-
}
|
|
105
|
-
return "```json\n" + JSON.stringify(item, null, 2) + "\n```";
|
|
106
|
-
}
|
|
107
|
-
function collapsible(summary, body, lang = "") {
|
|
108
|
-
const fence = lang ? "```" + lang : "```";
|
|
109
|
-
return `<details><summary>${summary}</summary>
|
|
110
|
-
|
|
111
|
-
${fence}
|
|
112
|
-
${body}
|
|
113
|
-
\`\`\`
|
|
114
|
-
|
|
115
|
-
</details>`;
|
|
116
|
-
}
|
|
117
|
-
function stringifyResult(c) {
|
|
118
|
-
if (c === null || c === void 0) return "";
|
|
119
|
-
if (typeof c === "string") return c;
|
|
120
|
-
if (Array.isArray(c)) {
|
|
121
|
-
const parts = [];
|
|
122
|
-
for (const part of c) {
|
|
123
|
-
if (part && typeof part === "object" && "text" in part && typeof part.text === "string") {
|
|
124
|
-
parts.push(part.text);
|
|
125
|
-
} else {
|
|
126
|
-
parts.push(JSON.stringify(part));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return parts.join("\n");
|
|
130
|
-
}
|
|
131
|
-
return JSON.stringify(c, null, 2);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
exports.renderSessionMarkdown = renderSessionMarkdown;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_esm_shims
|
|
3
|
-
} from "./chunk-MD32R22I.js";
|
|
4
|
-
|
|
5
|
-
// src/cli/commands/builtin/export-md.ts
|
|
6
|
-
init_esm_shims();
|
|
7
|
-
import { join, basename } from "path";
|
|
8
|
-
var INLINE_RESULT_LIMIT = 2e3;
|
|
9
|
-
var INLINE_ARG_LIMIT = 800;
|
|
10
|
-
var SAFE_SID_RE = /^[A-Za-z0-9_-]+$/;
|
|
11
|
-
function renderSessionMarkdown(sessionId, events, cwd) {
|
|
12
|
-
if (!SAFE_SID_RE.test(sessionId)) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`renderSessionMarkdown: invalid sessionId ${JSON.stringify(sessionId)} \u2014 expected [A-Za-z0-9_-]+`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
const lines = [];
|
|
18
|
-
const sidecars = [];
|
|
19
|
-
const sidecarDir = `session-${sessionId}-attachments`;
|
|
20
|
-
lines.push(`# Session ${sessionId}`);
|
|
21
|
-
lines.push("");
|
|
22
|
-
let turnNumber = 0;
|
|
23
|
-
for (const evRaw of events) {
|
|
24
|
-
const ev = evRaw;
|
|
25
|
-
if (ev.type !== "message") continue;
|
|
26
|
-
turnNumber += 1;
|
|
27
|
-
const role = ev.data?.role ?? "unknown";
|
|
28
|
-
const content = ev.data?.content;
|
|
29
|
-
lines.push(`## turn ${turnNumber} \xB7 ${role}`);
|
|
30
|
-
lines.push("");
|
|
31
|
-
if (typeof content === "string") {
|
|
32
|
-
lines.push(content);
|
|
33
|
-
lines.push("");
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (!Array.isArray(content)) {
|
|
37
|
-
lines.push("```json");
|
|
38
|
-
lines.push(JSON.stringify(content, null, 2));
|
|
39
|
-
lines.push("```");
|
|
40
|
-
lines.push("");
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
let itemIdx = 0;
|
|
44
|
-
for (const itemRaw of content) {
|
|
45
|
-
itemIdx += 1;
|
|
46
|
-
const block = renderBlock(itemRaw, {
|
|
47
|
-
turnNumber,
|
|
48
|
-
itemIdx,
|
|
49
|
-
sidecarDir,
|
|
50
|
-
cwd,
|
|
51
|
-
sidecars
|
|
52
|
-
});
|
|
53
|
-
if (block) {
|
|
54
|
-
lines.push(block);
|
|
55
|
-
lines.push("");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return { md: lines.join("\n"), sidecars };
|
|
60
|
-
}
|
|
61
|
-
function renderBlock(item, rctx) {
|
|
62
|
-
const t = item.type;
|
|
63
|
-
if (t === "reasoning") {
|
|
64
|
-
const txt = item.reasoningContent ?? "";
|
|
65
|
-
return collapsible("reasoning", txt);
|
|
66
|
-
}
|
|
67
|
-
if (t === "text") {
|
|
68
|
-
return item.text ?? "";
|
|
69
|
-
}
|
|
70
|
-
if (t === "tool_use") {
|
|
71
|
-
const name = item.name ?? "?";
|
|
72
|
-
const argsJson = JSON.stringify(item.input ?? {}, null, 2) ?? "{}";
|
|
73
|
-
const head = `**\u{1F6E0} tool_use** \xB7 \`${name}\``;
|
|
74
|
-
if (argsJson.length <= INLINE_ARG_LIMIT) {
|
|
75
|
-
return `${head}
|
|
76
|
-
|
|
77
|
-
\`\`\`json
|
|
78
|
-
${argsJson}
|
|
79
|
-
\`\`\``;
|
|
80
|
-
}
|
|
81
|
-
return collapsible(`${name} args (${argsJson.length} bytes)`, argsJson, "json");
|
|
82
|
-
}
|
|
83
|
-
if (t === "tool_result") {
|
|
84
|
-
const toolUseId = item.tool_use_id ?? item.id ?? "?";
|
|
85
|
-
const raw = stringifyResult(item.content);
|
|
86
|
-
if (raw.length <= INLINE_RESULT_LIMIT) {
|
|
87
|
-
return `**\u25C0 tool_result** \xB7 ${toolUseId}
|
|
88
|
-
|
|
89
|
-
\`\`\`
|
|
90
|
-
${raw}
|
|
91
|
-
\`\`\``;
|
|
92
|
-
}
|
|
93
|
-
const sidecarName = `t${rctx.turnNumber}-i${rctx.itemIdx}-${toolUseId.slice(0, 12)}.txt`;
|
|
94
|
-
const sidecarPath = join(rctx.cwd, rctx.sidecarDir, sidecarName);
|
|
95
|
-
rctx.sidecars.push({ path: sidecarPath, content: raw });
|
|
96
|
-
const preview = raw.slice(0, INLINE_RESULT_LIMIT);
|
|
97
|
-
const rel = join(rctx.sidecarDir, basename(sidecarPath));
|
|
98
|
-
return `**\u25C0 tool_result** \xB7 ${toolUseId} \xB7 ${raw.length.toLocaleString()} bytes \xB7 [full \u2192 ${rel}](./${rel})
|
|
99
|
-
|
|
100
|
-
\`\`\`
|
|
101
|
-
${preview}
|
|
102
|
-
\u2026(truncated, see sidecar)
|
|
103
|
-
\`\`\``;
|
|
104
|
-
}
|
|
105
|
-
return "```json\n" + JSON.stringify(item, null, 2) + "\n```";
|
|
106
|
-
}
|
|
107
|
-
function collapsible(summary, body, lang = "") {
|
|
108
|
-
const fence = lang ? "```" + lang : "```";
|
|
109
|
-
return `<details><summary>${summary}</summary>
|
|
110
|
-
|
|
111
|
-
${fence}
|
|
112
|
-
${body}
|
|
113
|
-
\`\`\`
|
|
114
|
-
|
|
115
|
-
</details>`;
|
|
116
|
-
}
|
|
117
|
-
function stringifyResult(c) {
|
|
118
|
-
if (c === null || c === void 0) return "";
|
|
119
|
-
if (typeof c === "string") return c;
|
|
120
|
-
if (Array.isArray(c)) {
|
|
121
|
-
const parts = [];
|
|
122
|
-
for (const part of c) {
|
|
123
|
-
if (part && typeof part === "object" && "text" in part && typeof part.text === "string") {
|
|
124
|
-
parts.push(part.text);
|
|
125
|
-
} else {
|
|
126
|
-
parts.push(JSON.stringify(part));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return parts.join("\n");
|
|
130
|
-
}
|
|
131
|
-
return JSON.stringify(c, null, 2);
|
|
132
|
-
}
|
|
133
|
-
export {
|
|
134
|
-
renderSessionMarkdown
|
|
135
|
-
};
|