@cjhyy/code-shell-core 0.6.0-rc.7 → 0.6.0-rc.8
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/engine/engine.d.ts +2 -2
- package/dist/engine/engine.js +20 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/protocol/server.js +31 -7
- package/package.json +1 -1
package/dist/engine/engine.d.ts
CHANGED
|
@@ -452,10 +452,10 @@ export declare class Engine {
|
|
|
452
452
|
clearGoal(sessionId: string): boolean;
|
|
453
453
|
injectContext(sessionId: string, content: string): void;
|
|
454
454
|
/**
|
|
455
|
-
* Force context compaction on
|
|
455
|
+
* Force context compaction on a session.
|
|
456
456
|
* Returns token stats before/after.
|
|
457
457
|
*/
|
|
458
|
-
forceCompact(): {
|
|
458
|
+
forceCompact(sessionId?: string): {
|
|
459
459
|
before: number;
|
|
460
460
|
after: number;
|
|
461
461
|
strategy: string;
|
package/dist/engine/engine.js
CHANGED
|
@@ -2351,20 +2351,32 @@ export class Engine {
|
|
|
2351
2351
|
}
|
|
2352
2352
|
}
|
|
2353
2353
|
/**
|
|
2354
|
-
* Force context compaction on
|
|
2354
|
+
* Force context compaction on a session.
|
|
2355
2355
|
* Returns token stats before/after.
|
|
2356
2356
|
*/
|
|
2357
|
-
forceCompact() {
|
|
2358
|
-
const
|
|
2359
|
-
if (!
|
|
2357
|
+
forceCompact(sessionId) {
|
|
2358
|
+
const effectiveSessionId = sessionId ?? this.lastSessionId;
|
|
2359
|
+
if (!effectiveSessionId) {
|
|
2360
2360
|
return { before: 0, after: 0, strategy: "none (no active session)" };
|
|
2361
2361
|
}
|
|
2362
|
-
const
|
|
2363
|
-
|
|
2362
|
+
const session = this.sessionManager.resume(effectiveSessionId);
|
|
2363
|
+
const sourceMessages = this.compactedMessagesBySession.get(effectiveSessionId) ??
|
|
2364
|
+
session.transcript.toMessages();
|
|
2364
2365
|
const before = estimateTokens(sourceMessages);
|
|
2365
|
-
|
|
2366
|
+
let contextManager = this.lastContextManager;
|
|
2367
|
+
if (!contextManager || this.lastSessionId !== effectiveSessionId) {
|
|
2368
|
+
contextManager = new ContextManager({
|
|
2369
|
+
maxTokens: this.resolveMaxContextTokens(),
|
|
2370
|
+
...Object.fromEntries(Object.entries(this.resolveContextRatios()).filter(([, v]) => v !== undefined)),
|
|
2371
|
+
});
|
|
2372
|
+
contextManager.setTranscriptPath(session.transcript.getFilePath());
|
|
2373
|
+
contextManager.initReplacementStateFromMessages(sourceMessages);
|
|
2374
|
+
this.lastContextManager = contextManager;
|
|
2375
|
+
}
|
|
2376
|
+
const compacted = contextManager.manage(sourceMessages);
|
|
2366
2377
|
const after = estimateTokens(compacted);
|
|
2367
|
-
this.compactedMessagesBySession.set(
|
|
2378
|
+
this.compactedMessagesBySession.set(effectiveSessionId, compacted);
|
|
2379
|
+
this.lastSessionId = effectiveSessionId;
|
|
2368
2380
|
this.lastMessages = compacted;
|
|
2369
2381
|
return {
|
|
2370
2382
|
before,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Public API exports.
|
|
5
5
|
*/
|
|
6
|
-
export declare const VERSION = "0.6.0-rc.
|
|
6
|
+
export declare const VERSION = "0.6.0-rc.8";
|
|
7
7
|
export type { Message, ContentBlock, ToolDefinition, ToolCall, ToolResult, RegisteredTool, TranscriptEvent, TranscriptEventType, SessionState, SessionStatus, TokenUsage, CompiledInput, PermissionDecision, PermissionMode, PermissionRule, TurnPhase, TurnResult, TerminalReason, StreamEvent, StreamCallback, LLMConfig, ClientDefaults, LLMResponse, Settings, MCPServerConfig, } from "./types.js";
|
|
8
8
|
export { FrameworkError, LLMError, LLMRateLimitError, ContextLimitError, ToolError, ToolNotFoundError, ToolExecutionError, ToolTimeoutError, PermissionDeniedError, SessionError, TranscriptError, ConfigError, SandboxUnavailableError, } from "./exceptions.js";
|
|
9
9
|
export { Engine, loadAgentDefinitionsForCwd } from "./engine/engine.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Public API exports.
|
|
5
5
|
*/
|
|
6
|
-
export const VERSION = "0.6.0-rc.
|
|
6
|
+
export const VERSION = "0.6.0-rc.8";
|
|
7
7
|
// ─── Exceptions ──────────────────────────────────────────────────
|
|
8
8
|
export { FrameworkError, LLMError, LLMRateLimitError, ContextLimitError, ToolError, ToolNotFoundError, ToolExecutionError, ToolTimeoutError, PermissionDeniedError, SessionError, TranscriptError, ConfigError, SandboxUnavailableError, } from "./exceptions.js";
|
|
9
9
|
// ─── Engine (primary API) ────────────────────────────────────────
|
package/dist/protocol/server.js
CHANGED
|
@@ -997,17 +997,41 @@ export class AgentServer {
|
|
|
997
997
|
break;
|
|
998
998
|
}
|
|
999
999
|
case "compact": {
|
|
1000
|
-
const
|
|
1001
|
-
?
|
|
1002
|
-
:
|
|
1000
|
+
const compactSessionId = typeof params.sessionId === "string" && params.sessionId.length > 0
|
|
1001
|
+
? params.sessionId
|
|
1002
|
+
: undefined;
|
|
1003
|
+
let compactEngine = engine;
|
|
1004
|
+
if (this.chatManager) {
|
|
1005
|
+
if (compactSessionId) {
|
|
1006
|
+
let session = this.chatManager.get(compactSessionId);
|
|
1007
|
+
if (!session) {
|
|
1008
|
+
const probeEngine = this.anyEngine();
|
|
1009
|
+
if (!probeEngine?.sessionExistsOnDisk(compactSessionId)) {
|
|
1010
|
+
this.transport.send(createErrorResponse(req.id, ErrorCodes.SessionNotFound, `Session not found: ${compactSessionId}`));
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
try {
|
|
1014
|
+
session = this.chatManager.getOrCreate(compactSessionId, {
|
|
1015
|
+
cwd: probeEngine.getSessionManager().readCwd(compactSessionId),
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
catch (err) {
|
|
1019
|
+
this.transport.send(createErrorResponse(req.id, err.code ?? ErrorCodes.InternalError, err.message));
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
compactEngine = session.engine;
|
|
1024
|
+
}
|
|
1025
|
+
else {
|
|
1026
|
+
compactEngine = this.anyEngine();
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1003
1029
|
if (!compactEngine) {
|
|
1004
|
-
this.transport.send(createErrorResponse(req.id,
|
|
1005
|
-
? `No such live session: ${params.sessionId}`
|
|
1006
|
-
: "No engine available for compact query"));
|
|
1030
|
+
this.transport.send(createErrorResponse(req.id, ErrorCodes.InternalError, "No engine available for compact query"));
|
|
1007
1031
|
return;
|
|
1008
1032
|
}
|
|
1009
1033
|
try {
|
|
1010
|
-
const result = compactEngine.forceCompact();
|
|
1034
|
+
const result = compactEngine.forceCompact(compactSessionId);
|
|
1011
1035
|
this.transport.send(createResponse(req.id, {
|
|
1012
1036
|
type: "compact",
|
|
1013
1037
|
data: result,
|
package/package.json
CHANGED