@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.
Files changed (171) hide show
  1. package/dist/anthropic-OVRWAZRD.js +1 -0
  2. package/dist/arena/index.js +1 -104
  3. package/dist/arena-64T2EQD4.js +3 -0
  4. package/dist/bwrap-PVZMLHZR.js +2 -0
  5. package/dist/chunk-2EUIMKJA.js +1 -0
  6. package/dist/chunk-2GJ7H5NC.js +641 -0
  7. package/dist/chunk-2OD6VR4N.js +2 -0
  8. package/dist/chunk-3QP5BQ3L.js +1 -0
  9. package/dist/chunk-A4M2Y42L.js +2 -0
  10. package/dist/chunk-DEYFK6FP.js +1 -0
  11. package/dist/chunk-DTPABBSV.js +2 -0
  12. package/dist/chunk-EU3J7TBP.js +1 -0
  13. package/dist/chunk-FU7AHZNN.js +1 -0
  14. package/dist/chunk-L7B2ORID.js +4 -0
  15. package/dist/chunk-M7VU4YVY.js +49 -0
  16. package/dist/chunk-MGP35GKD.js +254 -0
  17. package/dist/chunk-MLCTC53I.js +1 -0
  18. package/dist/chunk-O5HFCH2U.js +1 -0
  19. package/dist/chunk-P6JSTIFM.js +1 -0
  20. package/dist/chunk-Q3RSX66I.js +1 -0
  21. package/dist/chunk-QTWU7UNA.js +5 -0
  22. package/dist/chunk-RERBX75D.js +251 -0
  23. package/dist/chunk-SNFAPSLA.js +1 -0
  24. package/dist/chunk-T222K6IV.js +18 -0
  25. package/dist/chunk-TKJA6W36.js +3 -0
  26. package/dist/chunk-VKKU4LOM.js +3 -0
  27. package/dist/chunk-WI6FSWGU.js +1 -0
  28. package/dist/chunk-XXCZE2U2.js +2 -0
  29. package/dist/chunk-ZSAONDT6.js +2 -0
  30. package/dist/cli/main.js +303 -22060
  31. package/dist/cli/onboarding.d.ts +7 -2
  32. package/dist/client-base-F5FCRSB3.js +1 -0
  33. package/dist/compaction-L3Y6NG4N.js +1 -0
  34. package/dist/context/compaction.d.ts +2 -1
  35. package/dist/data/static-catalogs.d.ts +25 -0
  36. package/dist/devtools-SGDUOOM4.js +1 -0
  37. package/dist/engine/engine.d.ts +24 -0
  38. package/dist/engine/turn-loop.d.ts +20 -0
  39. package/dist/export-md-U72T7NW7.js +22 -0
  40. package/dist/file-history-7FQFEQOL.js +1 -0
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.js +1 -347
  43. package/dist/llm/capabilities/index.d.ts +20 -0
  44. package/dist/llm/capabilities/rules.d.ts +26 -0
  45. package/dist/llm/capabilities/types.d.ts +108 -0
  46. package/dist/llm/model-pool.d.ts +7 -0
  47. package/dist/llm/provider-catalog.d.ts +2 -0
  48. package/dist/llm/provider-kinds.d.ts +1 -1
  49. package/dist/llm/providers/openai.d.ts +22 -0
  50. package/dist/llm/token-counter.d.ts +17 -0
  51. package/dist/llm/types.d.ts +8 -0
  52. package/dist/logging/logger.d.ts +10 -2
  53. package/dist/logging/session-recorder.d.ts +16 -3
  54. package/dist/manager-J6FXEUEK.js +1 -0
  55. package/dist/mcp-manager-27EVBKRT.js +1 -0
  56. package/dist/memory-BNI4WEWL.js +1 -0
  57. package/dist/model-cache-HEDXI7UJ.js +1 -0
  58. package/dist/model-fetcher-X5W5EASG.js +1 -0
  59. package/dist/off-7SDVMMXW.js +1 -0
  60. package/dist/openai-3QEADSYL.js +1 -0
  61. package/dist/openrouter-models-GZVCRWD2.js +1 -0
  62. package/dist/openrouter-sync-WG4AG5NC.js +1 -0
  63. package/dist/product/index.js +1 -21
  64. package/dist/protocol/client.d.ts +1 -1
  65. package/dist/run/index.js +1 -48
  66. package/dist/seatbelt-L54CNI2Y.js +37 -0
  67. package/dist/session/session-manager.d.ts +2 -0
  68. package/dist/session-manager-AGWS5SMJ.js +1 -0
  69. package/dist/settings/schema.d.ts +147 -21
  70. package/dist/tool-summary-V2B3MD5N.js +2 -0
  71. package/dist/tool-system/builtin/bash.d.ts +7 -1
  72. package/dist/tool-system/context.d.ts +7 -0
  73. package/dist/tool-system/executor.d.ts +4 -0
  74. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  75. package/dist/tool-system/sandbox/index.d.ts +78 -0
  76. package/dist/tool-system/sandbox/off.d.ts +2 -0
  77. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  78. package/dist/tool-system/task-guard.d.ts +30 -0
  79. package/dist/types.d.ts +17 -0
  80. package/dist/ui/components/SessionPicker.d.ts +2 -0
  81. package/dist/ui/components/SpinnerWithVerb.d.ts +7 -2
  82. package/dist/ui/components/StatusLine.d.ts +7 -3
  83. package/dist/updater-OCNU2K2Z.js +1 -0
  84. package/package.json +7 -10
  85. package/dist/anthropic-IBTI4WL2.cjs +0 -10
  86. package/dist/anthropic-PRZZKHEZ.js +0 -10
  87. package/dist/arena/index.cjs +0 -104
  88. package/dist/arena-2LTLIXOL.js +0 -261
  89. package/dist/arena-ADB7DRFI.cjs +0 -261
  90. package/dist/chunk-2YW4FPFG.cjs +0 -101
  91. package/dist/chunk-3OA5G4TM.js +0 -47
  92. package/dist/chunk-3QO25N6E.js +0 -4711
  93. package/dist/chunk-3SBSUOWZ.js +0 -447
  94. package/dist/chunk-52LGZKT3.cjs +0 -47
  95. package/dist/chunk-55XGPMAP.cjs +0 -146
  96. package/dist/chunk-6QVAYW7C.cjs +0 -438
  97. package/dist/chunk-6S4BJ65N.js +0 -113
  98. package/dist/chunk-76HYEPDM.js +0 -307
  99. package/dist/chunk-7BI3V74Y.cjs +0 -447
  100. package/dist/chunk-7EG3V4JY.cjs +0 -113
  101. package/dist/chunk-7JVTYEEC.js +0 -340
  102. package/dist/chunk-7QIM3BKD.js +0 -44
  103. package/dist/chunk-7Y6S3OCX.js +0 -438
  104. package/dist/chunk-ABRRONJ7.js +0 -107
  105. package/dist/chunk-BSW22MPA.js +0 -146
  106. package/dist/chunk-BXCY2FSE.js +0 -203
  107. package/dist/chunk-BZ5TNE7L.js +0 -5128
  108. package/dist/chunk-DDB6QOKJ.cjs +0 -1252
  109. package/dist/chunk-HEKQCI7B.cjs +0 -224
  110. package/dist/chunk-IK4EWJBP.cjs +0 -203
  111. package/dist/chunk-ILHE7XLT.cjs +0 -107
  112. package/dist/chunk-JMR33QVF.cjs +0 -169
  113. package/dist/chunk-KAQHULYN.js +0 -54
  114. package/dist/chunk-KE4EQOWA.js +0 -294
  115. package/dist/chunk-KOVYSDHZ.cjs +0 -340
  116. package/dist/chunk-KS3RYAYL.cjs +0 -45
  117. package/dist/chunk-MD32R22I.js +0 -50
  118. package/dist/chunk-MV7YI4WO.cjs +0 -293
  119. package/dist/chunk-MY5XHADU.cjs +0 -216
  120. package/dist/chunk-NUNC3VFB.cjs +0 -307
  121. package/dist/chunk-PKGRTCCY.js +0 -9092
  122. package/dist/chunk-QARL3IDQ.js +0 -1252
  123. package/dist/chunk-S754JHLR.cjs +0 -54
  124. package/dist/chunk-SFXHZSRF.js +0 -101
  125. package/dist/chunk-SIHHIQLO.js +0 -224
  126. package/dist/chunk-T6VYG46N.js +0 -105
  127. package/dist/chunk-TNLGBJYS.cjs +0 -44
  128. package/dist/chunk-TUY2T5KP.cjs +0 -105
  129. package/dist/chunk-UXOCVJJ6.cjs +0 -9092
  130. package/dist/chunk-VIAGTYYW.js +0 -169
  131. package/dist/chunk-WASS5YWB.js +0 -215
  132. package/dist/chunk-WZJV6DJC.cjs +0 -5128
  133. package/dist/chunk-YIQBXAYU.cjs +0 -264
  134. package/dist/chunk-YKIAELDZ.cjs +0 -4711
  135. package/dist/chunk-ZBPSQCPU.js +0 -264
  136. package/dist/cli/main.cjs +0 -22156
  137. package/dist/client-base-HTF236ZD.cjs +0 -9
  138. package/dist/client-base-QKRKCOWB.js +0 -9
  139. package/dist/compaction-6VU2T643.js +0 -33
  140. package/dist/compaction-OKUNTCA7.cjs +0 -33
  141. package/dist/devtools-T2NIZBJK.cjs +0 -6
  142. package/dist/devtools-YXWHOVKR.js +0 -6
  143. package/dist/export-md-RXDW6F5W.cjs +0 -135
  144. package/dist/export-md-XXKZANW5.js +0 -135
  145. package/dist/file-history-KYPE3ECT.cjs +0 -7
  146. package/dist/file-history-LF4F7X26.js +0 -7
  147. package/dist/index.cjs +0 -347
  148. package/dist/manager-D65VFAPX.js +0 -7
  149. package/dist/manager-TTF5VHJC.cjs +0 -7
  150. package/dist/mcp-manager-QMKWPBZ4.js +0 -8
  151. package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
  152. package/dist/memory-5LWZ6FI2.cjs +0 -9
  153. package/dist/memory-VIJLBAMQ.js +0 -9
  154. package/dist/model-cache-5KIYL5SL.js +0 -13
  155. package/dist/model-cache-OED3IM4R.cjs +0 -13
  156. package/dist/model-fetcher-HKGICACL.js +0 -8
  157. package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
  158. package/dist/openai-JR2WEKOF.js +0 -10
  159. package/dist/openai-YBTOET4O.cjs +0 -10
  160. package/dist/openrouter-models-H56GHBHN.js +0 -15
  161. package/dist/openrouter-models-TWUFWZ5T.cjs +0 -15
  162. package/dist/openrouter-sync-5VMGN6C2.cjs +0 -11
  163. package/dist/openrouter-sync-ALEMF5IU.js +0 -11
  164. package/dist/product/index.cjs +0 -21
  165. package/dist/run/index.cjs +0 -48
  166. package/dist/session-manager-Q22BBMD3.js +0 -8
  167. package/dist/session-manager-XODQVL3C.cjs +0 -8
  168. package/dist/tool-summary-63DPIS7G.cjs +0 -31
  169. package/dist/tool-summary-NP5CDBKG.js +0 -31
  170. package/dist/updater-I7QBW4DP.cjs +0 -17
  171. package/dist/updater-NVME5S3Z.js +0 -17
@@ -1,54 +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 _chunkYKIAELDZcjs = require('./chunk-YKIAELDZ.cjs');
4
-
5
-
6
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
7
-
8
- // src/data/openrouter-sync.ts
9
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
10
- var ENDPOINT = "https://openrouter.ai/api/v1/models";
11
- function priceToPerMillion(raw) {
12
- if (!raw) return 0;
13
- const n = Number(raw);
14
- return Number.isFinite(n) ? n * 1e6 : 0;
15
- }
16
- function slim(m) {
17
- return {
18
- id: m.id,
19
- name: _nullishCoalesce(m.name, () => ( m.id)),
20
- created: _nullishCoalesce(m.created, () => ( 0)),
21
- contextLength: _nullishCoalesce(_nullishCoalesce(_optionalChain([m, 'access', _ => _.top_provider, 'optionalAccess', _2 => _2.context_length]), () => ( m.context_length)), () => ( 0)),
22
- maxOutputTokens: _nullishCoalesce(_optionalChain([m, 'access', _3 => _3.top_provider, 'optionalAccess', _4 => _4.max_completion_tokens]), () => ( 0)),
23
- inputPricePerMillion: priceToPerMillion(_optionalChain([m, 'access', _5 => _5.pricing, 'optionalAccess', _6 => _6.prompt])),
24
- outputPricePerMillion: priceToPerMillion(_optionalChain([m, 'access', _7 => _7.pricing, 'optionalAccess', _8 => _8.completion])),
25
- modalities: _nullishCoalesce(_optionalChain([m, 'access', _9 => _9.architecture, 'optionalAccess', _10 => _10.input_modalities]), () => ( []))
26
- };
27
- }
28
- async function syncOpenRouterCatalog(timeoutMs = 15e3) {
29
- try {
30
- const res = await fetch(ENDPOINT, {
31
- headers: { Accept: "application/json" },
32
- signal: AbortSignal.timeout(timeoutMs)
33
- });
34
- if (!res.ok) {
35
- return { ok: false, count: 0, error: `HTTP ${res.status} ${res.statusText}` };
36
- }
37
- const payload = await res.json();
38
- const raw = _nullishCoalesce(payload.data, () => ( []));
39
- const models = raw.map(slim).sort((a, b) => b.created - a.created);
40
- _chunkYKIAELDZcjs.setOpenRouterSnapshot.call(void 0, {
41
- fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
42
- source: ENDPOINT,
43
- count: models.length,
44
- models
45
- });
46
- return { ok: true, count: models.length };
47
- } catch (err) {
48
- return { ok: false, count: 0, error: err.message };
49
- }
50
- }
51
-
52
-
53
-
54
- exports.syncOpenRouterCatalog = syncOpenRouterCatalog;
@@ -1,101 +0,0 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-MD32R22I.js";
4
-
5
- // src/exceptions.ts
6
- init_esm_shims();
7
- var FrameworkError = class extends Error {
8
- constructor(message, details) {
9
- super(message);
10
- this.details = details;
11
- this.name = "FrameworkError";
12
- }
13
- };
14
- var LLMError = class extends FrameworkError {
15
- constructor(message, provider, details) {
16
- super(message, details);
17
- this.provider = provider;
18
- this.name = "LLMError";
19
- }
20
- };
21
- var LLMRateLimitError = class extends LLMError {
22
- constructor(provider, retryAfter) {
23
- super(`Rate limit exceeded for ${provider}`, provider, { retryAfter });
24
- this.retryAfter = retryAfter;
25
- this.name = "LLMRateLimitError";
26
- }
27
- };
28
- var ContextLimitError = class extends LLMError {
29
- constructor(provider) {
30
- super("Context limit exceeded", provider);
31
- this.name = "ContextLimitError";
32
- }
33
- };
34
- var ToolError = class extends FrameworkError {
35
- constructor(message, toolName, details) {
36
- super(message, details);
37
- this.toolName = toolName;
38
- this.name = "ToolError";
39
- }
40
- };
41
- var ToolNotFoundError = class extends ToolError {
42
- constructor(toolName) {
43
- super(`Tool not found: ${toolName}`, toolName);
44
- this.name = "ToolNotFoundError";
45
- }
46
- };
47
- var ToolExecutionError = class extends ToolError {
48
- constructor(toolName, cause) {
49
- super(`Tool execution failed: ${toolName} - ${cause}`, toolName, { cause });
50
- this.name = "ToolExecutionError";
51
- }
52
- };
53
- var ToolTimeoutError = class extends ToolError {
54
- constructor(toolName, timeoutMs) {
55
- super(`Tool timed out after ${timeoutMs}ms: ${toolName}`, toolName, { timeoutMs });
56
- this.timeoutMs = timeoutMs;
57
- this.name = "ToolTimeoutError";
58
- }
59
- };
60
- var PermissionDeniedError = class extends FrameworkError {
61
- constructor(toolName, reason) {
62
- super(`Permission denied for tool: ${toolName}${reason ? ` - ${reason}` : ""}`, {
63
- toolName,
64
- reason
65
- });
66
- this.name = "PermissionDeniedError";
67
- }
68
- };
69
- var SessionError = class extends FrameworkError {
70
- constructor(message, details) {
71
- super(message, details);
72
- this.name = "SessionError";
73
- }
74
- };
75
- var TranscriptError = class extends FrameworkError {
76
- constructor(message, details) {
77
- super(message, details);
78
- this.name = "TranscriptError";
79
- }
80
- };
81
- var ConfigError = class extends FrameworkError {
82
- constructor(message, details) {
83
- super(message, details);
84
- this.name = "ConfigError";
85
- }
86
- };
87
-
88
- export {
89
- FrameworkError,
90
- LLMError,
91
- LLMRateLimitError,
92
- ContextLimitError,
93
- ToolError,
94
- ToolNotFoundError,
95
- ToolExecutionError,
96
- ToolTimeoutError,
97
- PermissionDeniedError,
98
- SessionError,
99
- TranscriptError,
100
- ConfigError
101
- };
@@ -1,224 +0,0 @@
1
- import {
2
- logger
3
- } from "./chunk-BXCY2FSE.js";
4
- import {
5
- init_esm_shims
6
- } from "./chunk-MD32R22I.js";
7
-
8
- // src/tool-system/mcp-manager.ts
9
- init_esm_shims();
10
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
11
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
12
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
13
- var MCPManager = class _MCPManager {
14
- constructor(toolRegistry) {
15
- this.toolRegistry = toolRegistry;
16
- _MCPManager.instance = this;
17
- }
18
- static instance = null;
19
- connections = /* @__PURE__ */ new Map();
20
- static getInstance() {
21
- if (!_MCPManager.instance) {
22
- throw new Error("MCPManager not initialized. Connect to servers first.");
23
- }
24
- return _MCPManager.instance;
25
- }
26
- /**
27
- * Connect to all configured MCP servers and register their tools.
28
- */
29
- async connectAll(servers) {
30
- const entries = Object.entries(servers);
31
- if (entries.length === 0) return;
32
- const results = await Promise.allSettled(
33
- entries.map(([name, config]) => this.connect(name, config))
34
- );
35
- for (let i = 0; i < results.length; i++) {
36
- const result = results[i];
37
- if (result.status === "rejected") {
38
- logger.warn("mcp.connect_failed", {
39
- server: entries[i][0],
40
- error: result.reason.message
41
- });
42
- }
43
- }
44
- }
45
- /**
46
- * Connect to a single MCP server.
47
- */
48
- async connect(name, config) {
49
- if (this.connections.has(name)) {
50
- logger.info("mcp.already_connected", { server: name });
51
- return;
52
- }
53
- logger.info("mcp.connecting", { server: name, transport: config.transport ?? "stdio" });
54
- const client = new Client(
55
- { name: "code-shell", version: "0.1.0" },
56
- { capabilities: {} }
57
- );
58
- let transport;
59
- const transportType = config.transport ?? "stdio";
60
- if (transportType === "stdio") {
61
- if (!config.command) {
62
- throw new Error(`MCP server "${name}": command is required for stdio transport`);
63
- }
64
- transport = new StdioClientTransport({
65
- command: config.command,
66
- args: config.args,
67
- env: config.env ? { ...process.env, ...config.env } : void 0
68
- });
69
- } else if (transportType === "streamable-http" || transportType === "sse") {
70
- if (!config.url) {
71
- throw new Error(`MCP server "${name}": url is required for ${transportType} transport`);
72
- }
73
- transport = new StreamableHTTPClientTransport(new URL(config.url), {
74
- requestInit: config.headers ? { headers: config.headers } : void 0
75
- });
76
- } else {
77
- throw new Error(`MCP server "${name}": unsupported transport "${transportType}"`);
78
- }
79
- const CONNECT_TIMEOUT_MS = 15e3;
80
- let timeoutHandle;
81
- try {
82
- await new Promise((resolve, reject) => {
83
- timeoutHandle = setTimeout(() => {
84
- reject(new Error(`MCP server "${name}" connect timed out after ${CONNECT_TIMEOUT_MS}ms`));
85
- }, CONNECT_TIMEOUT_MS);
86
- client.connect(transport).then(
87
- () => resolve(),
88
- (err) => reject(err)
89
- );
90
- });
91
- } catch (err) {
92
- try {
93
- await transport.close?.();
94
- } catch {
95
- }
96
- throw err;
97
- } finally {
98
- if (timeoutHandle) clearTimeout(timeoutHandle);
99
- }
100
- this.connections.set(name, { client, serverName: name, transport });
101
- await this.discoverTools(name, client);
102
- logger.info("mcp.connected", { server: name });
103
- }
104
- /**
105
- * Discover tools from an MCP server and register them.
106
- */
107
- async discoverTools(serverName, client) {
108
- const result = await client.listTools();
109
- for (const tool of result.tools) {
110
- const registered = {
111
- name: `mcp_${serverName}_${tool.name}`,
112
- description: `[${serverName}] ${tool.description ?? tool.name}`,
113
- inputSchema: tool.inputSchema ?? { type: "object", properties: {} },
114
- source: "mcp",
115
- serverName,
116
- permissionDefault: "ask",
117
- isConcurrencySafe: true,
118
- isReadOnly: false
119
- };
120
- this.toolRegistry.registerTool(registered, async (args) => {
121
- const callResult = await client.callTool({ name: tool.name, arguments: args });
122
- const parts = [];
123
- if (Array.isArray(callResult.content)) {
124
- for (const item of callResult.content) {
125
- if (typeof item === "object" && item !== null && "text" in item) {
126
- parts.push(String(item.text));
127
- } else if (typeof item === "string") {
128
- parts.push(item);
129
- }
130
- }
131
- }
132
- return parts.join("\n") || "(no output)";
133
- });
134
- logger.info("mcp.tool_registered", { server: serverName, tool: registered.name });
135
- }
136
- }
137
- /**
138
- * Disconnect all MCP servers.
139
- */
140
- async disconnectAll() {
141
- for (const [name, conn] of this.connections) {
142
- try {
143
- await conn.client.close();
144
- logger.info("mcp.disconnected", { server: name });
145
- } catch (err) {
146
- logger.warn("mcp.disconnect_error", { server: name, error: err.message });
147
- }
148
- }
149
- this.connections.clear();
150
- }
151
- /**
152
- * List connected servers.
153
- */
154
- listServers() {
155
- return [...this.connections.keys()];
156
- }
157
- /**
158
- * Call a tool on a specific MCP server.
159
- */
160
- async callTool(serverName, toolName, args) {
161
- const conn = this.connections.get(serverName);
162
- if (!conn) {
163
- throw new Error(`MCP server "${serverName}" is not connected.`);
164
- }
165
- const result = await conn.client.callTool({ name: toolName, arguments: args });
166
- const parts = [];
167
- if (Array.isArray(result.content)) {
168
- for (const item of result.content) {
169
- if (typeof item === "object" && item !== null && "text" in item) {
170
- parts.push(String(item.text));
171
- } else if (typeof item === "string") {
172
- parts.push(item);
173
- }
174
- }
175
- }
176
- return parts.join("\n") || "(no output)";
177
- }
178
- /**
179
- * List resources from MCP servers.
180
- */
181
- async listResources(serverName) {
182
- const results = [];
183
- const servers = serverName ? [serverName] : [...this.connections.keys()];
184
- for (const name of servers) {
185
- const conn = this.connections.get(name);
186
- if (!conn) continue;
187
- try {
188
- const res = await conn.client.listResources();
189
- for (const r of res.resources) {
190
- results.push({
191
- uri: r.uri,
192
- name: r.name ?? r.uri,
193
- description: r.description
194
- });
195
- }
196
- } catch {
197
- }
198
- }
199
- return results;
200
- }
201
- /**
202
- * Read a resource from an MCP server.
203
- */
204
- async readResource(serverName, uri) {
205
- const conn = this.connections.get(serverName);
206
- if (!conn) {
207
- throw new Error(`MCP server "${serverName}" is not connected.`);
208
- }
209
- const result = await conn.client.readResource({ uri });
210
- const parts = [];
211
- if (Array.isArray(result.contents)) {
212
- for (const item of result.contents) {
213
- if (typeof item === "object" && item !== null && "text" in item) {
214
- parts.push(String(item.text));
215
- }
216
- }
217
- }
218
- return parts.join("\n") || "(no content)";
219
- }
220
- };
221
-
222
- export {
223
- MCPManager
224
- };
@@ -1,105 +0,0 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-MD32R22I.js";
4
-
5
- // src/session/file-history.ts
6
- init_esm_shims();
7
- import { mkdirSync, existsSync, readFileSync, writeFileSync, copyFileSync } from "fs";
8
- import { join, resolve } from "path";
9
- import { createHash } from "crypto";
10
- var FileHistory = class _FileHistory {
11
- historyDir;
12
- snapshots = [];
13
- constructor(sessionDir) {
14
- this.historyDir = join(sessionDir, "file-history");
15
- mkdirSync(this.historyDir, { recursive: true });
16
- }
17
- /**
18
- * Save a snapshot of a file before it is modified.
19
- * Returns the snapshot record, or null if the file doesn't exist.
20
- */
21
- saveSnapshot(filePath) {
22
- const absPath = resolve(filePath);
23
- if (!existsSync(absPath)) return null;
24
- try {
25
- const content = readFileSync(absPath);
26
- const hash = createHash("md5").update(content).digest("hex");
27
- const existing = this.snapshots.find(
28
- (s) => s.filePath === absPath && s.hash === hash
29
- );
30
- if (existing) return existing;
31
- const timestamp = Date.now();
32
- const safeName = absPath.replace(/[/\\:]/g, "_").slice(-100);
33
- const backupPath = join(this.historyDir, `${timestamp}_${safeName}`);
34
- copyFileSync(absPath, backupPath);
35
- const snapshot = {
36
- filePath: absPath,
37
- timestamp,
38
- backupPath,
39
- hash,
40
- size: content.length
41
- };
42
- this.snapshots.push(snapshot);
43
- this.saveIndex();
44
- return snapshot;
45
- } catch {
46
- return null;
47
- }
48
- }
49
- /**
50
- * Get all snapshots for a specific file.
51
- */
52
- getSnapshots(filePath) {
53
- const absPath = resolve(filePath);
54
- return this.snapshots.filter((s) => s.filePath === absPath).sort((a, b) => b.timestamp - a.timestamp);
55
- }
56
- /**
57
- * Restore a file to a specific snapshot.
58
- */
59
- restore(snapshot) {
60
- try {
61
- if (!existsSync(snapshot.backupPath)) return false;
62
- this.saveSnapshot(snapshot.filePath);
63
- copyFileSync(snapshot.backupPath, snapshot.filePath);
64
- return true;
65
- } catch {
66
- return false;
67
- }
68
- }
69
- /**
70
- * Restore a file to its most recent snapshot.
71
- */
72
- restoreLatest(filePath) {
73
- const snapshots = this.getSnapshots(filePath);
74
- if (snapshots.length === 0) return false;
75
- return this.restore(snapshots[0]);
76
- }
77
- /**
78
- * Get all tracked files.
79
- */
80
- getTrackedFiles() {
81
- return [...new Set(this.snapshots.map((s) => s.filePath))];
82
- }
83
- saveIndex() {
84
- try {
85
- const indexPath = join(this.historyDir, "index.json");
86
- writeFileSync(indexPath, JSON.stringify(this.snapshots, null, 2), "utf-8");
87
- } catch {
88
- }
89
- }
90
- static loadFromDir(sessionDir) {
91
- const history = new _FileHistory(sessionDir);
92
- const indexPath = join(history.historyDir, "index.json");
93
- if (existsSync(indexPath)) {
94
- try {
95
- history.snapshots = JSON.parse(readFileSync(indexPath, "utf-8"));
96
- } catch {
97
- }
98
- }
99
- return history;
100
- }
101
- };
102
-
103
- export {
104
- FileHistory
105
- };
@@ -1,44 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
-
3
-
4
- var _chunkUXOCVJJ6cjs = require('./chunk-UXOCVJJ6.cjs');
5
-
6
-
7
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
8
-
9
- // src/run/index.ts
10
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
11
-
12
- // src/run/factory.ts
13
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
14
- var _path = require('path');
15
- var _os = require('os');
16
- function createRunManager(options) {
17
- const runsDir = _nullishCoalesce(options.runsDir, () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
18
- const store = new (0, _chunkUXOCVJJ6cjs.FileRunStore)(runsDir);
19
- return new (0, _chunkUXOCVJJ6cjs.RunManager)({
20
- store,
21
- executor: {
22
- llm: options.llm,
23
- maxTurns: _nullishCoalesce(options.maxTurns, () => ( 30)),
24
- maxContextTokens: _nullishCoalesce(options.maxContextTokens, () => ( 2e5)),
25
- permissionMode: _nullishCoalesce(options.permissionMode, () => ( "acceptEdits")),
26
- sessionStorageDir: options.sessionStorageDir,
27
- mcpServers: options.mcpServers,
28
- enabledBuiltinTools: options.enabledBuiltinTools,
29
- disabledBuiltinTools: options.disabledBuiltinTools,
30
- customSystemPrompt: options.customSystemPrompt,
31
- appendSystemPrompt: options.appendSystemPrompt,
32
- hooks: options.hooks
33
- },
34
- concurrency: _nullishCoalesce(options.concurrency, () => ( 1)),
35
- runsDir,
36
- evaluator: options.evaluator,
37
- defaultTags: options.defaultTags,
38
- defaultMetadata: options.defaultMetadata
39
- });
40
- }
41
-
42
-
43
-
44
- exports.createRunManager = createRunManager;
@@ -1,105 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
-
3
- var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
4
-
5
- // src/session/file-history.ts
6
- _chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
7
- var _fs = require('fs');
8
- var _path = require('path');
9
- var _crypto = require('crypto');
10
- var FileHistory = (_class = class _FileHistory {
11
-
12
- __init() {this.snapshots = []}
13
- constructor(sessionDir) {;_class.prototype.__init.call(this);
14
- this.historyDir = _path.join.call(void 0, sessionDir, "file-history");
15
- _fs.mkdirSync.call(void 0, this.historyDir, { recursive: true });
16
- }
17
- /**
18
- * Save a snapshot of a file before it is modified.
19
- * Returns the snapshot record, or null if the file doesn't exist.
20
- */
21
- saveSnapshot(filePath) {
22
- const absPath = _path.resolve.call(void 0, filePath);
23
- if (!_fs.existsSync.call(void 0, absPath)) return null;
24
- try {
25
- const content = _fs.readFileSync.call(void 0, absPath);
26
- const hash = _crypto.createHash.call(void 0, "md5").update(content).digest("hex");
27
- const existing = this.snapshots.find(
28
- (s) => s.filePath === absPath && s.hash === hash
29
- );
30
- if (existing) return existing;
31
- const timestamp = Date.now();
32
- const safeName = absPath.replace(/[/\\:]/g, "_").slice(-100);
33
- const backupPath = _path.join.call(void 0, this.historyDir, `${timestamp}_${safeName}`);
34
- _fs.copyFileSync.call(void 0, absPath, backupPath);
35
- const snapshot = {
36
- filePath: absPath,
37
- timestamp,
38
- backupPath,
39
- hash,
40
- size: content.length
41
- };
42
- this.snapshots.push(snapshot);
43
- this.saveIndex();
44
- return snapshot;
45
- } catch (e) {
46
- return null;
47
- }
48
- }
49
- /**
50
- * Get all snapshots for a specific file.
51
- */
52
- getSnapshots(filePath) {
53
- const absPath = _path.resolve.call(void 0, filePath);
54
- return this.snapshots.filter((s) => s.filePath === absPath).sort((a, b) => b.timestamp - a.timestamp);
55
- }
56
- /**
57
- * Restore a file to a specific snapshot.
58
- */
59
- restore(snapshot) {
60
- try {
61
- if (!_fs.existsSync.call(void 0, snapshot.backupPath)) return false;
62
- this.saveSnapshot(snapshot.filePath);
63
- _fs.copyFileSync.call(void 0, snapshot.backupPath, snapshot.filePath);
64
- return true;
65
- } catch (e2) {
66
- return false;
67
- }
68
- }
69
- /**
70
- * Restore a file to its most recent snapshot.
71
- */
72
- restoreLatest(filePath) {
73
- const snapshots = this.getSnapshots(filePath);
74
- if (snapshots.length === 0) return false;
75
- return this.restore(snapshots[0]);
76
- }
77
- /**
78
- * Get all tracked files.
79
- */
80
- getTrackedFiles() {
81
- return [...new Set(this.snapshots.map((s) => s.filePath))];
82
- }
83
- saveIndex() {
84
- try {
85
- const indexPath = _path.join.call(void 0, this.historyDir, "index.json");
86
- _fs.writeFileSync.call(void 0, indexPath, JSON.stringify(this.snapshots, null, 2), "utf-8");
87
- } catch (e3) {
88
- }
89
- }
90
- static loadFromDir(sessionDir) {
91
- const history = new _FileHistory(sessionDir);
92
- const indexPath = _path.join.call(void 0, history.historyDir, "index.json");
93
- if (_fs.existsSync.call(void 0, indexPath)) {
94
- try {
95
- history.snapshots = JSON.parse(_fs.readFileSync.call(void 0, indexPath, "utf-8"));
96
- } catch (e4) {
97
- }
98
- }
99
- return history;
100
- }
101
- }, _class);
102
-
103
-
104
-
105
- exports.FileHistory = FileHistory;