@nghyane/arcane 0.1.29 → 0.1.30
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/package.json +4 -4
- package/src/cli/config-cli.ts +1 -1
- package/src/config/settings-schema.ts +19 -27
- package/src/config/settings.ts +3 -4
- package/src/extensibility/custom-tools/types.ts +0 -12
- package/src/extensibility/extensions/index.ts +0 -5
- package/src/extensibility/extensions/runner.ts +6 -26
- package/src/extensibility/extensions/types.ts +1 -77
- package/src/extensibility/hooks/runner.ts +5 -24
- package/src/extensibility/hooks/types.ts +1 -77
- package/src/index.ts +2 -13
- package/src/modes/components/footer.ts +4 -11
- package/src/modes/components/index.ts +0 -1
- package/src/modes/components/status-line/segments.ts +1 -2
- package/src/modes/components/status-line/types.ts +0 -1
- package/src/modes/components/status-line.ts +0 -6
- package/src/modes/components/tree-selector.ts +0 -8
- package/src/modes/controllers/command-controller.ts +2 -98
- package/src/modes/controllers/event-controller.ts +46 -52
- package/src/modes/controllers/extension-ui-controller.ts +0 -42
- package/src/modes/controllers/input-controller.ts +0 -23
- package/src/modes/controllers/selector-controller.ts +0 -5
- package/src/modes/interactive-mode.ts +3 -24
- package/src/modes/print-mode.ts +0 -16
- package/src/modes/rpc/rpc-client.ts +0 -16
- package/src/modes/rpc/rpc-mode.ts +0 -32
- package/src/modes/rpc/rpc-types.ts +0 -9
- package/src/modes/types.ts +1 -13
- package/src/modes/utils/ui-helpers.ts +2 -118
- package/src/sdk.ts +0 -15
- package/src/session/agent-session.ts +89 -650
- package/src/session/compaction/branch-summarization.ts +5 -13
- package/src/session/compaction/index.ts +0 -1
- package/src/session/compaction/utils.ts +94 -2
- package/src/session/messages.ts +0 -37
- package/src/session/retry-utils.ts +1 -1
- package/src/session/session-manager.ts +8 -108
- package/src/session/session-types.ts +4 -25
- package/src/session/stats.ts +2 -39
- package/src/slash-commands/builtin-registry.ts +0 -11
- package/src/task/executor.ts +0 -8
- package/examples/hooks/custom-compaction.ts +0 -116
- package/src/modes/components/compaction-summary-message.ts +0 -59
- package/src/prompts/compaction/compaction-short-summary.md +0 -9
- package/src/prompts/compaction/compaction-summary-context.md +0 -5
- package/src/prompts/compaction/compaction-summary.md +0 -41
- package/src/prompts/compaction/compaction-turn-prefix.md +0 -17
- package/src/prompts/compaction/compaction-update-summary.md +0 -45
- package/src/session/compaction/compaction.ts +0 -864
- package/src/session/compaction/pruning.ts +0 -91
|
@@ -21,7 +21,6 @@ import chalk from "chalk";
|
|
|
21
21
|
import { KeybindingsManager } from "../config/keybindings";
|
|
22
22
|
import { type Settings, settings } from "../config/settings";
|
|
23
23
|
import type { ExtensionUIContext, ExtensionUIDialogOptions } from "../extensibility/extensions";
|
|
24
|
-
import type { CompactOptions } from "../extensibility/extensions/types";
|
|
25
24
|
import { BUILTIN_SLASH_COMMANDS, loadSlashCommands } from "../extensibility/slash-commands";
|
|
26
25
|
import type { AgentSession, AgentSessionEvent } from "../session/agent-session";
|
|
27
26
|
import { HistoryStorage } from "../session/history-storage";
|
|
@@ -50,7 +49,7 @@ import { InputController } from "./controllers/input-controller";
|
|
|
50
49
|
import { MCPCommandController } from "./controllers/mcp-command-controller";
|
|
51
50
|
import { SelectorController } from "./controllers/selector-controller";
|
|
52
51
|
import { SSHCommandController } from "./controllers/ssh-command-controller";
|
|
53
|
-
import type {
|
|
52
|
+
import type { InteractiveModeContext, TodoItem } from "./types";
|
|
54
53
|
import { UiHelpers } from "./utils/ui-helpers";
|
|
55
54
|
|
|
56
55
|
const TODO_FILE_NAME = "todos.json";
|
|
@@ -98,7 +97,6 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
98
97
|
todoItems: TodoItem[] = [];
|
|
99
98
|
hideThinkingBlock = false;
|
|
100
99
|
pendingImages: ImageContent[] = [];
|
|
101
|
-
compactionQueuedMessages: CompactionQueuedMessage[] = [];
|
|
102
100
|
pendingTools = new Map<string, ToolExecutionHandle>();
|
|
103
101
|
pendingBashComponents: BashExecutionComponent[] = [];
|
|
104
102
|
bashComponent: BashExecutionComponent | undefined = undefined;
|
|
@@ -108,11 +106,7 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
108
106
|
streamingComponent: AssistantMessageComponent | undefined = undefined;
|
|
109
107
|
streamingMessage: AssistantMessage | undefined = undefined;
|
|
110
108
|
loadingAnimation: Loader | undefined = undefined;
|
|
111
|
-
autoCompactionLoader: Loader | undefined = undefined;
|
|
112
109
|
retryLoader: Loader | undefined = undefined;
|
|
113
|
-
#pendingWorkingMessage: string | undefined;
|
|
114
|
-
readonly #defaultWorkingMessage = `Working… (esc to interrupt)`;
|
|
115
|
-
autoCompactionEscapeHandler?: () => void;
|
|
116
110
|
retryEscapeHandler?: () => void;
|
|
117
111
|
unsubscribe?: () => void;
|
|
118
112
|
onInputCallback?: (input: { text: string; images?: ImageContent[] }) => void;
|
|
@@ -130,6 +124,8 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
130
124
|
|
|
131
125
|
#pendingSlashCommands: SlashCommand[] = [];
|
|
132
126
|
#cleanupUnsubscribe?: () => void;
|
|
127
|
+
#pendingWorkingMessage: string | undefined = undefined;
|
|
128
|
+
#defaultWorkingMessage = "Working…";
|
|
133
129
|
readonly #version: string;
|
|
134
130
|
readonly #changelogMarkdown: string | undefined;
|
|
135
131
|
readonly lspServers:
|
|
@@ -198,7 +194,6 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
198
194
|
this.editorContainer = new Container();
|
|
199
195
|
this.editorContainer.addChild(this.editor);
|
|
200
196
|
this.statusLine = new StatusLineComponent(session);
|
|
201
|
-
this.statusLine.setAutoCompactEnabled(session.autoCompactionEnabled);
|
|
202
197
|
|
|
203
198
|
this.hideThinkingBlock = settings.get("hideThinkingBlock");
|
|
204
199
|
|
|
@@ -622,14 +617,6 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
622
617
|
this.#uiHelpers.updatePendingMessagesDisplay();
|
|
623
618
|
}
|
|
624
619
|
|
|
625
|
-
queueCompactionMessage(text: string, mode: "steer" | "followUp"): void {
|
|
626
|
-
this.#uiHelpers.queueCompactionMessage(text, mode);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
flushCompactionQueue(options?: { willRetry?: boolean }): Promise<void> {
|
|
630
|
-
return this.#uiHelpers.flushCompactionQueue(options);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
620
|
flushPendingBashComponents(): void {
|
|
634
621
|
this.#uiHelpers.flushPendingBashComponents();
|
|
635
622
|
}
|
|
@@ -737,18 +724,10 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
737
724
|
await controller.handle(text);
|
|
738
725
|
}
|
|
739
726
|
|
|
740
|
-
handleCompactCommand(customInstructions?: string): Promise<void> {
|
|
741
|
-
return this.#commandController.handleCompactCommand(customInstructions);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
727
|
handleHandoffCommand(customInstructions?: string): Promise<void> {
|
|
745
728
|
return this.#commandController.handleHandoffCommand(customInstructions);
|
|
746
729
|
}
|
|
747
730
|
|
|
748
|
-
executeCompaction(customInstructionsOrOptions?: string | CompactOptions, isAuto?: boolean): Promise<void> {
|
|
749
|
-
return this.#commandController.executeCompaction(customInstructionsOrOptions, isAuto);
|
|
750
|
-
}
|
|
751
|
-
|
|
752
731
|
openInBrowser(urlOrPath: string): void {
|
|
753
732
|
this.#commandController.openInBrowser(urlOrPath);
|
|
754
733
|
}
|
package/src/modes/print-mode.ts
CHANGED
|
@@ -82,14 +82,6 @@ export async function runPrintMode(session: AgentSession, options: PrintModeOpti
|
|
|
82
82
|
shutdown: () => {},
|
|
83
83
|
getContextUsage: () => session.getContextUsage(),
|
|
84
84
|
getSystemPrompt: () => session.systemPrompt,
|
|
85
|
-
compact: async instructionsOrOptions => {
|
|
86
|
-
const instructions = typeof instructionsOrOptions === "string" ? instructionsOrOptions : undefined;
|
|
87
|
-
const options =
|
|
88
|
-
instructionsOrOptions && typeof instructionsOrOptions === "object"
|
|
89
|
-
? instructionsOrOptions
|
|
90
|
-
: undefined;
|
|
91
|
-
await session.compact(instructions, options);
|
|
92
|
-
},
|
|
93
85
|
},
|
|
94
86
|
// ExtensionCommandContextActions - commands invokable via prompt("/command")
|
|
95
87
|
{
|
|
@@ -117,14 +109,6 @@ export async function runPrintMode(session: AgentSession, options: PrintModeOpti
|
|
|
117
109
|
reload: async () => {
|
|
118
110
|
await session.reload();
|
|
119
111
|
},
|
|
120
|
-
compact: async instructionsOrOptions => {
|
|
121
|
-
const instructions = typeof instructionsOrOptions === "string" ? instructionsOrOptions : undefined;
|
|
122
|
-
const options =
|
|
123
|
-
instructionsOrOptions && typeof instructionsOrOptions === "object"
|
|
124
|
-
? instructionsOrOptions
|
|
125
|
-
: undefined;
|
|
126
|
-
await session.compact(instructions, options);
|
|
127
|
-
},
|
|
128
112
|
},
|
|
129
113
|
// No UI context
|
|
130
114
|
);
|
|
@@ -8,7 +8,6 @@ import type { ImageContent } from "@nghyane/arcane-ai";
|
|
|
8
8
|
import { ptree, readJsonl } from "@nghyane/arcane-utils";
|
|
9
9
|
import type { BashResult } from "../../exec/bash-executor";
|
|
10
10
|
import type { SessionStats } from "../../session/agent-session";
|
|
11
|
-
import type { CompactionResult } from "../../session/compaction";
|
|
12
11
|
import type { RpcCommand, RpcResponse, RpcSessionState } from "./rpc-types";
|
|
13
12
|
|
|
14
13
|
/** Distributive Omit that works with union types */
|
|
@@ -332,21 +331,6 @@ export class RpcClient {
|
|
|
332
331
|
await this.#send({ type: "set_follow_up_mode", mode });
|
|
333
332
|
}
|
|
334
333
|
|
|
335
|
-
/**
|
|
336
|
-
* Compact session context.
|
|
337
|
-
*/
|
|
338
|
-
async compact(customInstructions?: string): Promise<CompactionResult> {
|
|
339
|
-
const response = await this.#send({ type: "compact", customInstructions });
|
|
340
|
-
return this.#getData(response);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Set auto-compaction enabled/disabled.
|
|
345
|
-
*/
|
|
346
|
-
async setAutoCompaction(enabled: boolean): Promise<void> {
|
|
347
|
-
await this.#send({ type: "set_auto_compaction", enabled });
|
|
348
|
-
}
|
|
349
|
-
|
|
350
334
|
/**
|
|
351
335
|
* Set auto-retry enabled/disabled.
|
|
352
336
|
*/
|
|
@@ -358,14 +358,6 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|
|
358
358
|
},
|
|
359
359
|
getContextUsage: () => session.getContextUsage(),
|
|
360
360
|
getSystemPrompt: () => session.systemPrompt,
|
|
361
|
-
compact: async instructionsOrOptions => {
|
|
362
|
-
const instructions = typeof instructionsOrOptions === "string" ? instructionsOrOptions : undefined;
|
|
363
|
-
const options =
|
|
364
|
-
instructionsOrOptions && typeof instructionsOrOptions === "object"
|
|
365
|
-
? instructionsOrOptions
|
|
366
|
-
: undefined;
|
|
367
|
-
await session.compact(instructions, options);
|
|
368
|
-
},
|
|
369
361
|
},
|
|
370
362
|
// ExtensionCommandContextActions - commands invokable via prompt("/command")
|
|
371
363
|
{
|
|
@@ -394,14 +386,6 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|
|
394
386
|
reload: async () => {
|
|
395
387
|
await session.reload();
|
|
396
388
|
},
|
|
397
|
-
compact: async instructionsOrOptions => {
|
|
398
|
-
const instructions = typeof instructionsOrOptions === "string" ? instructionsOrOptions : undefined;
|
|
399
|
-
const options =
|
|
400
|
-
instructionsOrOptions && typeof instructionsOrOptions === "object"
|
|
401
|
-
? instructionsOrOptions
|
|
402
|
-
: undefined;
|
|
403
|
-
await session.compact(instructions, options);
|
|
404
|
-
},
|
|
405
389
|
},
|
|
406
390
|
new RpcExtensionUIContext(pendingExtensionRequests, output),
|
|
407
391
|
);
|
|
@@ -479,14 +463,12 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|
|
479
463
|
model: session.model,
|
|
480
464
|
thinkingLevel: session.thinkingLevel,
|
|
481
465
|
isStreaming: session.isStreaming,
|
|
482
|
-
isCompacting: session.isCompacting,
|
|
483
466
|
steeringMode: session.steeringMode,
|
|
484
467
|
followUpMode: session.followUpMode,
|
|
485
468
|
interruptMode: session.interruptMode,
|
|
486
469
|
sessionFile: session.sessionFile,
|
|
487
470
|
sessionId: session.sessionId,
|
|
488
471
|
sessionName: session.sessionName,
|
|
489
|
-
autoCompactionEnabled: session.autoCompactionEnabled,
|
|
490
472
|
messageCount: session.messages.length,
|
|
491
473
|
queuedMessageCount: session.queuedMessageCount,
|
|
492
474
|
};
|
|
@@ -556,20 +538,6 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|
|
556
538
|
return success(id, "set_interrupt_mode");
|
|
557
539
|
}
|
|
558
540
|
|
|
559
|
-
// =================================================================
|
|
560
|
-
// Compaction
|
|
561
|
-
// =================================================================
|
|
562
|
-
|
|
563
|
-
case "compact": {
|
|
564
|
-
const result = await session.compact(command.customInstructions);
|
|
565
|
-
return success(id, "compact", result);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
case "set_auto_compaction": {
|
|
569
|
-
session.setAutoCompactionEnabled(command.enabled);
|
|
570
|
-
return success(id, "set_auto_compaction");
|
|
571
|
-
}
|
|
572
|
-
|
|
573
541
|
// =================================================================
|
|
574
542
|
// Retry
|
|
575
543
|
// =================================================================
|
|
@@ -8,7 +8,6 @@ import type { AgentMessage, ThinkingLevel } from "@nghyane/arcane-agent";
|
|
|
8
8
|
import type { ImageContent, Model } from "@nghyane/arcane-ai";
|
|
9
9
|
import type { BashResult } from "../../exec/bash-executor";
|
|
10
10
|
import type { SessionStats } from "../../session/agent-session";
|
|
11
|
-
import type { CompactionResult } from "../../session/compaction";
|
|
12
11
|
|
|
13
12
|
// ============================================================================
|
|
14
13
|
// RPC Commands (stdin)
|
|
@@ -40,10 +39,6 @@ export type RpcCommand =
|
|
|
40
39
|
| { id?: string; type: "set_follow_up_mode"; mode: "all" | "one-at-a-time" }
|
|
41
40
|
| { id?: string; type: "set_interrupt_mode"; mode: "immediate" | "wait" }
|
|
42
41
|
|
|
43
|
-
// Compaction
|
|
44
|
-
| { id?: string; type: "compact"; customInstructions?: string }
|
|
45
|
-
| { id?: string; type: "set_auto_compaction"; enabled: boolean }
|
|
46
|
-
|
|
47
42
|
// Retry
|
|
48
43
|
| { id?: string; type: "set_auto_retry"; enabled: boolean }
|
|
49
44
|
| { id?: string; type: "abort_retry" }
|
|
@@ -72,14 +67,12 @@ export interface RpcSessionState {
|
|
|
72
67
|
model?: Model;
|
|
73
68
|
thinkingLevel: ThinkingLevel;
|
|
74
69
|
isStreaming: boolean;
|
|
75
|
-
isCompacting: boolean;
|
|
76
70
|
steeringMode: "all" | "one-at-a-time";
|
|
77
71
|
followUpMode: "all" | "one-at-a-time";
|
|
78
72
|
interruptMode: "immediate" | "wait";
|
|
79
73
|
sessionFile?: string;
|
|
80
74
|
sessionId: string;
|
|
81
75
|
sessionName?: string;
|
|
82
|
-
autoCompactionEnabled: boolean;
|
|
83
76
|
messageCount: number;
|
|
84
77
|
queuedMessageCount: number;
|
|
85
78
|
}
|
|
@@ -140,8 +133,6 @@ export type RpcResponse =
|
|
|
140
133
|
| { id?: string; type: "response"; command: "set_interrupt_mode"; success: true }
|
|
141
134
|
|
|
142
135
|
// Compaction
|
|
143
|
-
| { id?: string; type: "response"; command: "compact"; success: true; data: CompactionResult }
|
|
144
|
-
| { id?: string; type: "response"; command: "set_auto_compaction"; success: true }
|
|
145
136
|
|
|
146
137
|
// Retry
|
|
147
138
|
| { id?: string; type: "response"; command: "set_auto_retry"; success: true }
|
package/src/modes/types.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Component, Container, Loader, Spacer, Text, TUI } from "@nghyane/a
|
|
|
4
4
|
import type { KeybindingsManager } from "../config/keybindings";
|
|
5
5
|
import type { Settings } from "../config/settings";
|
|
6
6
|
import type { ExtensionUIContext, ExtensionUIDialogOptions } from "../extensibility/extensions";
|
|
7
|
-
import type { CompactOptions } from "../extensibility/extensions/types";
|
|
8
7
|
import type { MCPManager } from "../mcp";
|
|
9
8
|
import type { AgentSession, AgentSessionEvent } from "../session/agent-session";
|
|
10
9
|
import type { HistoryStorage } from "../session/history-storage";
|
|
@@ -20,11 +19,6 @@ import type { PythonExecutionComponent } from "./components/python-execution";
|
|
|
20
19
|
import type { StatusLineComponent } from "./components/status-line";
|
|
21
20
|
import type { ToolExecutionHandle } from "./components/tool-execution";
|
|
22
21
|
|
|
23
|
-
export type CompactionQueuedMessage = {
|
|
24
|
-
text: string;
|
|
25
|
-
mode: "steer" | "followUp";
|
|
26
|
-
};
|
|
27
|
-
|
|
28
22
|
export type TodoItem = {
|
|
29
23
|
id: string;
|
|
30
24
|
content: string;
|
|
@@ -60,7 +54,6 @@ export interface InteractiveModeContext {
|
|
|
60
54
|
todoExpanded: boolean;
|
|
61
55
|
hideThinkingBlock: boolean;
|
|
62
56
|
pendingImages: ImageContent[];
|
|
63
|
-
compactionQueuedMessages: CompactionQueuedMessage[];
|
|
64
57
|
pendingTools: Map<string, ToolExecutionHandle>;
|
|
65
58
|
pendingBashComponents: BashExecutionComponent[];
|
|
66
59
|
bashComponent: BashExecutionComponent | undefined;
|
|
@@ -70,9 +63,8 @@ export interface InteractiveModeContext {
|
|
|
70
63
|
streamingComponent: AssistantMessageComponent | undefined;
|
|
71
64
|
streamingMessage: AssistantMessage | undefined;
|
|
72
65
|
loadingAnimation: Loader | undefined;
|
|
73
|
-
autoCompactionLoader: Loader | undefined;
|
|
74
66
|
retryLoader: Loader | undefined;
|
|
75
|
-
|
|
67
|
+
handoffLoader?: Loader;
|
|
76
68
|
retryEscapeHandler?: () => void;
|
|
77
69
|
unsubscribe?: () => void;
|
|
78
70
|
onInputCallback?: (input: { text: string; images?: ImageContent[] }) => void;
|
|
@@ -108,8 +100,6 @@ export interface InteractiveModeContext {
|
|
|
108
100
|
showNewVersionNotification(newVersion: string): void;
|
|
109
101
|
clearEditor(): void;
|
|
110
102
|
updatePendingMessagesDisplay(): void;
|
|
111
|
-
queueCompactionMessage(text: string, mode: "steer" | "followUp"): void;
|
|
112
|
-
flushCompactionQueue(options?: { willRetry?: boolean }): Promise<void>;
|
|
113
103
|
flushPendingBashComponents(): void;
|
|
114
104
|
setWorkingMessage(message?: string): void;
|
|
115
105
|
applyPendingWorkingMessage(): void;
|
|
@@ -145,11 +135,9 @@ export interface InteractiveModeContext {
|
|
|
145
135
|
handlePythonCommand(code: string, excludeFromContext?: boolean): Promise<void>;
|
|
146
136
|
handleMCPCommand(text: string): Promise<void>;
|
|
147
137
|
handleSSHCommand(text: string): Promise<void>;
|
|
148
|
-
handleCompactCommand(customInstructions?: string): Promise<void>;
|
|
149
138
|
handleHandoffCommand(customInstructions?: string): Promise<void>;
|
|
150
139
|
handleMoveCommand(targetPath: string): Promise<void>;
|
|
151
140
|
handleMemoryCommand(text: string): Promise<void>;
|
|
152
|
-
executeCompaction(customInstructionsOrOptions?: string | CompactOptions, isAuto?: boolean): Promise<void>;
|
|
153
141
|
openInBrowser(urlOrPath: string): void;
|
|
154
142
|
refreshSlashCommandState(cwd?: string): Promise<void>;
|
|
155
143
|
|
|
@@ -6,7 +6,6 @@ import { settings } from "../../config/settings";
|
|
|
6
6
|
import { AssistantMessageComponent } from "../../modes/components/assistant-message";
|
|
7
7
|
import { BashExecutionComponent } from "../../modes/components/bash-execution";
|
|
8
8
|
import { BranchSummaryMessageComponent } from "../../modes/components/branch-summary-message";
|
|
9
|
-
import { CompactionSummaryMessageComponent } from "../../modes/components/compaction-summary-message";
|
|
10
9
|
import { ContextGroupComponent } from "../../modes/components/context-group";
|
|
11
10
|
import { CustomMessageComponent } from "../../modes/components/custom-message";
|
|
12
11
|
import { DynamicBorder } from "../../modes/components/dynamic-border";
|
|
@@ -14,7 +13,7 @@ import { PythonExecutionComponent } from "../../modes/components/python-executio
|
|
|
14
13
|
import { SkillMessageComponent } from "../../modes/components/skill-message";
|
|
15
14
|
import { ToolExecutionComponent } from "../../modes/components/tool-execution";
|
|
16
15
|
import { UserMessageComponent } from "../../modes/components/user-message";
|
|
17
|
-
import type {
|
|
16
|
+
import type { InteractiveModeContext } from "../../modes/types";
|
|
18
17
|
import { type CustomMessage, SKILL_PROMPT_MESSAGE_TYPE, type SkillPromptDetails } from "../../session/messages";
|
|
19
18
|
import type { SessionContext } from "../../session/session-manager";
|
|
20
19
|
import { formatBytes } from "../../session/streaming-output";
|
|
@@ -113,13 +112,6 @@ export class UiHelpers {
|
|
|
113
112
|
}
|
|
114
113
|
break;
|
|
115
114
|
}
|
|
116
|
-
case "compactionSummary": {
|
|
117
|
-
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
118
|
-
const component = new CompactionSummaryMessageComponent(message);
|
|
119
|
-
component.setExpanded(this.ctx.toolOutputExpanded);
|
|
120
|
-
this.ctx.chatContainer.addChild(component);
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
115
|
case "branchSummary": {
|
|
124
116
|
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
125
117
|
const component = new BranchSummaryMessageComponent(message);
|
|
@@ -176,7 +168,7 @@ export class UiHelpers {
|
|
|
176
168
|
}
|
|
177
169
|
|
|
178
170
|
/**
|
|
179
|
-
* Render session context to chat. Used for initial load and rebuild after
|
|
171
|
+
* Render session context to chat. Used for initial load and rebuild after handoff.
|
|
180
172
|
* @param sessionContext Session context to render
|
|
181
173
|
* @param options.updateFooter Update footer state
|
|
182
174
|
* @param options.populateHistory Add user messages to editor history
|
|
@@ -294,19 +286,6 @@ export class UiHelpers {
|
|
|
294
286
|
updateFooter: true,
|
|
295
287
|
populateHistory: true,
|
|
296
288
|
});
|
|
297
|
-
|
|
298
|
-
// Show compaction info if session was compacted
|
|
299
|
-
const allEntries = this.ctx.sessionManager.getEntries();
|
|
300
|
-
let compactionCount = 0;
|
|
301
|
-
for (const entry of allEntries) {
|
|
302
|
-
if (entry.type === "compaction") {
|
|
303
|
-
compactionCount++;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (compactionCount > 0) {
|
|
307
|
-
const times = compactionCount === 1 ? "1 time" : `${compactionCount} times`;
|
|
308
|
-
this.ctx.showStatus(`Session compacted ${times}`);
|
|
309
|
-
}
|
|
310
289
|
}
|
|
311
290
|
|
|
312
291
|
clearEditor(): void {
|
|
@@ -363,21 +342,11 @@ export class UiHelpers {
|
|
|
363
342
|
for (const message of queuedMessages.steering) {
|
|
364
343
|
steeringMessages.push({ message, label: "Steer" });
|
|
365
344
|
}
|
|
366
|
-
for (const entry of this.ctx.compactionQueuedMessages as CompactionQueuedMessage[]) {
|
|
367
|
-
if (entry.mode === "steer") {
|
|
368
|
-
steeringMessages.push({ message: entry.text, label: "Steer" });
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
345
|
|
|
372
346
|
const followUpMessages: Array<{ message: string; label: string }> = [];
|
|
373
347
|
for (const message of queuedMessages.followUp) {
|
|
374
348
|
followUpMessages.push({ message, label: "Follow-up" });
|
|
375
349
|
}
|
|
376
|
-
for (const entry of this.ctx.compactionQueuedMessages as CompactionQueuedMessage[]) {
|
|
377
|
-
if (entry.mode === "followUp") {
|
|
378
|
-
followUpMessages.push({ message: entry.text, label: "Follow-up" });
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
350
|
|
|
382
351
|
const allMessages = [...steeringMessages, ...followUpMessages];
|
|
383
352
|
if (allMessages.length > 0) {
|
|
@@ -392,14 +361,6 @@ export class UiHelpers {
|
|
|
392
361
|
}
|
|
393
362
|
}
|
|
394
363
|
|
|
395
|
-
queueCompactionMessage(text: string, mode: "steer" | "followUp"): void {
|
|
396
|
-
this.ctx.compactionQueuedMessages.push({ text, mode } as CompactionQueuedMessage);
|
|
397
|
-
this.ctx.editor.addToHistory(text);
|
|
398
|
-
this.ctx.editor.setText("");
|
|
399
|
-
this.ctx.updatePendingMessagesDisplay();
|
|
400
|
-
this.ctx.showStatus("Queued message for after compaction");
|
|
401
|
-
}
|
|
402
|
-
|
|
403
364
|
isKnownSlashCommand(text: string): boolean {
|
|
404
365
|
if (!text.startsWith("/")) return false;
|
|
405
366
|
const spaceIndex = text.indexOf(" ");
|
|
@@ -419,83 +380,6 @@ export class UiHelpers {
|
|
|
419
380
|
return this.ctx.fileSlashCommands.has(commandName);
|
|
420
381
|
}
|
|
421
382
|
|
|
422
|
-
async flushCompactionQueue(options?: { willRetry?: boolean }): Promise<void> {
|
|
423
|
-
if (this.ctx.compactionQueuedMessages.length === 0) {
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const queuedMessages = [...(this.ctx.compactionQueuedMessages as CompactionQueuedMessage[])];
|
|
428
|
-
this.ctx.compactionQueuedMessages = [] as CompactionQueuedMessage[];
|
|
429
|
-
this.ctx.updatePendingMessagesDisplay();
|
|
430
|
-
|
|
431
|
-
const restoreQueue = (error: unknown) => {
|
|
432
|
-
this.ctx.session.clearQueue();
|
|
433
|
-
this.ctx.compactionQueuedMessages = queuedMessages;
|
|
434
|
-
this.ctx.updatePendingMessagesDisplay();
|
|
435
|
-
this.ctx.showError(
|
|
436
|
-
`Failed to send queued message${queuedMessages.length > 1 ? "s" : ""}: ${
|
|
437
|
-
error instanceof Error ? error.message : String(error)
|
|
438
|
-
}`,
|
|
439
|
-
);
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
try {
|
|
443
|
-
if (options?.willRetry) {
|
|
444
|
-
for (const message of queuedMessages) {
|
|
445
|
-
if (this.ctx.isKnownSlashCommand(message.text)) {
|
|
446
|
-
await this.ctx.session.prompt(message.text);
|
|
447
|
-
} else if (message.mode === "followUp") {
|
|
448
|
-
await this.ctx.session.followUp(message.text);
|
|
449
|
-
} else {
|
|
450
|
-
await this.ctx.session.steer(message.text);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
this.ctx.updatePendingMessagesDisplay();
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
let firstPromptIndex = -1;
|
|
458
|
-
for (let i = 0; i < queuedMessages.length; i++) {
|
|
459
|
-
if (!this.ctx.isKnownSlashCommand(queuedMessages[i].text)) {
|
|
460
|
-
firstPromptIndex = i;
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if (firstPromptIndex === -1) {
|
|
465
|
-
for (const message of queuedMessages) {
|
|
466
|
-
await this.ctx.session.prompt(message.text);
|
|
467
|
-
}
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
const preCommands = queuedMessages.slice(0, firstPromptIndex);
|
|
472
|
-
const firstPrompt = queuedMessages[firstPromptIndex];
|
|
473
|
-
const rest = queuedMessages.slice(firstPromptIndex + 1);
|
|
474
|
-
|
|
475
|
-
for (const message of preCommands) {
|
|
476
|
-
await this.ctx.session.prompt(message.text);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
const promptPromise = this.ctx.session.prompt(firstPrompt.text).catch((error: unknown) => {
|
|
480
|
-
restoreQueue(error);
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
for (const message of rest) {
|
|
484
|
-
if (this.ctx.isKnownSlashCommand(message.text)) {
|
|
485
|
-
await this.ctx.session.prompt(message.text);
|
|
486
|
-
} else if (message.mode === "followUp") {
|
|
487
|
-
await this.ctx.session.followUp(message.text);
|
|
488
|
-
} else {
|
|
489
|
-
await this.ctx.session.steer(message.text);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
this.ctx.updatePendingMessagesDisplay();
|
|
493
|
-
void promptPromise;
|
|
494
|
-
} catch (error) {
|
|
495
|
-
restoreQueue(error);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
383
|
/** Move pending bash components from pending area to chat */
|
|
500
384
|
flushPendingBashComponents(): void {
|
|
501
385
|
for (const component of this.ctx.pendingBashComponents) {
|
package/src/sdk.ts
CHANGED
|
@@ -442,21 +442,6 @@ function createCustomToolsExtension(tools: CustomTool[]): ExtensionFactory {
|
|
|
442
442
|
api.on("session_shutdown", async (_event, ctx) =>
|
|
443
443
|
runOnSession({ reason: "shutdown", previousSessionFile: undefined }, ctx),
|
|
444
444
|
);
|
|
445
|
-
api.on("auto_compaction_start", async (event, ctx) =>
|
|
446
|
-
runOnSession({ reason: "auto_compaction_start", trigger: event.reason }, ctx),
|
|
447
|
-
);
|
|
448
|
-
api.on("auto_compaction_end", async (event, ctx) =>
|
|
449
|
-
runOnSession(
|
|
450
|
-
{
|
|
451
|
-
reason: "auto_compaction_end",
|
|
452
|
-
result: event.result,
|
|
453
|
-
aborted: event.aborted,
|
|
454
|
-
willRetry: event.willRetry,
|
|
455
|
-
errorMessage: event.errorMessage,
|
|
456
|
-
},
|
|
457
|
-
ctx,
|
|
458
|
-
),
|
|
459
|
-
);
|
|
460
445
|
api.on("auto_retry_start", async (event, ctx) =>
|
|
461
446
|
runOnSession(
|
|
462
447
|
{
|