stitchkit-tui 0.1.1
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/LICENSE +21 -0
- package/README.md +85 -0
- package/dist/App.d.ts +19 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/builtins.d.ts +3 -0
- package/dist/builtins.d.ts.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2257 -0
- package/dist/commands.d.ts +44 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/composer.d.ts +16 -0
- package/dist/composer.d.ts.map +1 -0
- package/dist/config.d.ts +49 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/controller.d.ts +37 -0
- package/dist/controller.d.ts.map +1 -0
- package/dist/core/collection.d.ts +32 -0
- package/dist/core/collection.d.ts.map +1 -0
- package/dist/core/command-palette.d.ts +23 -0
- package/dist/core/command-palette.d.ts.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +361 -0
- package/dist/core/operation.d.ts +33 -0
- package/dist/core/operation.d.ts.map +1 -0
- package/dist/core/panes.d.ts +51 -0
- package/dist/core/panes.d.ts.map +1 -0
- package/dist/core/viewport.d.ts +36 -0
- package/dist/core/viewport.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +72 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2219 -0
- package/dist/keyboard.d.ts +7 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/model-picker.d.ts +40 -0
- package/dist/model-picker.d.ts.map +1 -0
- package/dist/run.d.ts +11 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/session.d.ts +64 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/status-line.d.ts +20 -0
- package/dist/status-line.d.ts.map +1 -0
- package/dist/transcript.d.ts +9 -0
- package/dist/transcript.d.ts.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const AgentTuiCommandOutcomeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"submit">;
|
|
4
|
+
text: z.ZodString;
|
|
5
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
6
|
+
type: z.ZodLiteral<"dialog">;
|
|
7
|
+
dialog: z.ZodString;
|
|
8
|
+
query: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"notice">;
|
|
11
|
+
message: z.ZodString;
|
|
12
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"action">;
|
|
14
|
+
action: z.ZodString;
|
|
15
|
+
}, z.core.$strict>], "type">;
|
|
16
|
+
export type AgentTuiCommandOutcome = z.infer<typeof AgentTuiCommandOutcomeSchema>;
|
|
17
|
+
export interface AgentTuiCommandContext {
|
|
18
|
+
conversationId: string;
|
|
19
|
+
activeRunId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentTuiCommand {
|
|
22
|
+
name: string;
|
|
23
|
+
aliases?: readonly string[];
|
|
24
|
+
description: string;
|
|
25
|
+
available?(context: AgentTuiCommandContext): boolean;
|
|
26
|
+
complete?(query: string): readonly string[];
|
|
27
|
+
execute(argumentsText: string, context: AgentTuiCommandContext): AgentTuiCommandOutcome | Promise<AgentTuiCommandOutcome>;
|
|
28
|
+
}
|
|
29
|
+
export declare function defineTuiCommand(command: AgentTuiCommand): AgentTuiCommand;
|
|
30
|
+
export declare function composeTuiCommands(...groups: readonly (readonly AgentTuiCommand[])[]): readonly AgentTuiCommand[];
|
|
31
|
+
export type AgentTuiCommandResolution = {
|
|
32
|
+
type: 'prompt';
|
|
33
|
+
text: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'command';
|
|
36
|
+
command: AgentTuiCommand;
|
|
37
|
+
argumentsText: string;
|
|
38
|
+
};
|
|
39
|
+
export declare function resolveTuiCommand(text: string, commands: readonly AgentTuiCommand[]): AgentTuiCommandResolution;
|
|
40
|
+
export declare function commandCompletions(text: string, commands: readonly AgentTuiCommand[]): readonly AgentTuiCommand[];
|
|
41
|
+
export declare function selectedCommandCompletion(text: string, commands: readonly AgentTuiCommand[], selectedIndex: number): AgentTuiCommand | undefined;
|
|
42
|
+
export declare function moveCommandCompletionSelection(selectedIndex: number, direction: 'previous' | 'next', completionCount: number): number;
|
|
43
|
+
export declare function resolveTuiCommandSubmission(text: string, commands: readonly AgentTuiCommand[], selectedIndex: number, paletteDismissed?: boolean): AgentTuiCommandResolution;
|
|
44
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;4BAWvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACrD,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAC5C,OAAO,CACL,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,sBAAsB,GAC9B,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAC7D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,CAU1E;AAED,wBAAgB,kBAAkB,CAChC,GAAG,MAAM,EAAE,SAAS,CAAC,SAAS,eAAe,EAAE,CAAC,EAAE,GACjD,SAAS,eAAe,EAAE,CAW5B;AAED,MAAM,MAAM,yBAAyB,GACjC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,eAAe,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,eAAe,EAAE,GACnC,yBAAyB,CAW3B;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,eAAe,EAAE,GACnC,SAAS,eAAe,EAAE,CAgB5B;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,eAAe,EAAE,EACpC,aAAa,EAAE,MAAM,GACpB,eAAe,GAAG,SAAS,CAG7B;AAED,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,UAAU,GAAG,MAAM,EAC9B,eAAe,EAAE,MAAM,GACtB,MAAM,CAOR;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,eAAe,EAAE,EACpC,aAAa,EAAE,MAAM,EACrB,gBAAgB,UAAQ,GACvB,yBAAyB,CAK3B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const AgentTuiComposerSchema: z.ZodObject<{
|
|
3
|
+
draft: z.ZodString;
|
|
4
|
+
history: z.ZodArray<z.ZodString>;
|
|
5
|
+
historyIndex: z.ZodOptional<z.ZodInt>;
|
|
6
|
+
preservedDraft: z.ZodString;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export type AgentTuiComposer = z.infer<typeof AgentTuiComposerSchema>;
|
|
9
|
+
export declare function createAgentTuiComposer(): AgentTuiComposer;
|
|
10
|
+
export declare function setAgentTuiDraft(state: AgentTuiComposer, draft: string): AgentTuiComposer;
|
|
11
|
+
export declare function submitAgentTuiComposer(state: AgentTuiComposer): {
|
|
12
|
+
state: AgentTuiComposer;
|
|
13
|
+
text?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function navigateAgentTuiHistory(state: AgentTuiComposer, direction: 'older' | 'newer'): AgentTuiComposer;
|
|
16
|
+
//# sourceMappingURL=composer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composer.d.ts","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,sBAAsB;;;;;kBAOxB,CAAC;AAEZ,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,wBAAgB,sBAAsB,IAAI,gBAAgB,CAEzD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAGzF;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,GAAG;IAC/D,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAKA;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EACvB,SAAS,EAAE,OAAO,GAAG,OAAO,GAC3B,gBAAgB,CAgBlB"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AgentConversationReader, AgentModelCatalog, AgentModelCatalogProvider, AgentModelSelectionStore, AgentRuntimeRecoverOptions } from 'stitchkit/agent-runtime';
|
|
2
|
+
import type { HeadlessAgentHarness } from 'stitchkit/agent-runtime/harness';
|
|
3
|
+
import type { AgentTuiCommand } from './commands';
|
|
4
|
+
import type { AgentTuiStatusLineFormatter } from './status-line';
|
|
5
|
+
export interface AgentTuiRuntimeBundle<CONTEXT> {
|
|
6
|
+
harness: HeadlessAgentHarness<CONTEXT>;
|
|
7
|
+
conversations?: AgentConversationReader;
|
|
8
|
+
}
|
|
9
|
+
export interface AgentTuiDiagnostics {
|
|
10
|
+
write(value: unknown): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentTuiConfig<CONTEXT> {
|
|
13
|
+
title?: string;
|
|
14
|
+
workspace?: string;
|
|
15
|
+
/** Explicit durable conversation to open. Omit to start a fresh conversation. */
|
|
16
|
+
initialConversationId?: string;
|
|
17
|
+
preferredModelId?: string;
|
|
18
|
+
context(): CONTEXT | Promise<CONTEXT>;
|
|
19
|
+
modelCatalog: AgentModelCatalogProvider;
|
|
20
|
+
createRuntime(input: {
|
|
21
|
+
catalog: AgentModelCatalog;
|
|
22
|
+
selections: AgentModelSelectionStore;
|
|
23
|
+
diagnostics: AgentTuiDiagnostics;
|
|
24
|
+
}): AgentTuiRuntimeBundle<CONTEXT> | Promise<AgentTuiRuntimeBundle<CONTEXT>>;
|
|
25
|
+
/** Host evidence for acquired runs. The safe default skips anything not still queued. */
|
|
26
|
+
recover?: AgentRuntimeRecoverOptions<CONTEXT>['decide'];
|
|
27
|
+
commands?: readonly AgentTuiCommand[];
|
|
28
|
+
theme?: Partial<AgentTuiTheme>;
|
|
29
|
+
/** Replace the default durable status rows, or set false to hide them. */
|
|
30
|
+
statusLine?: AgentTuiStatusLineFormatter | false;
|
|
31
|
+
}
|
|
32
|
+
export interface AgentTuiTheme {
|
|
33
|
+
canvas: string;
|
|
34
|
+
panel: string;
|
|
35
|
+
panelRaised: string;
|
|
36
|
+
border: string;
|
|
37
|
+
borderActive: string;
|
|
38
|
+
primary: string;
|
|
39
|
+
muted: string;
|
|
40
|
+
accent: string;
|
|
41
|
+
success: string;
|
|
42
|
+
danger: string;
|
|
43
|
+
warning: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const defaultAgentTuiTheme: AgentTuiTheme;
|
|
46
|
+
export declare function defineAgentTui<CONTEXT>(config: AgentTuiConfig<CONTEXT>): AgentTuiConfig<CONTEXT>;
|
|
47
|
+
export declare function resolveAgentTuiTheme(theme?: Partial<AgentTuiTheme>): AgentTuiTheme;
|
|
48
|
+
export declare function createFileAgentModelSelectionStore(workspace: string): AgentModelSelectionStore;
|
|
49
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,EAEzB,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AASjE,MAAM,WAAW,qBAAqB,CAAC,OAAO;IAC5C,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACvC,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,cAAc,CAAC,OAAO;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,YAAY,EAAE,yBAAyB,CAAC;IACxC,aAAa,CAAC,KAAK,EAAE;QACnB,OAAO,EAAE,iBAAiB,CAAC;QAC3B,UAAU,EAAE,wBAAwB,CAAC;QACrC,WAAW,EAAE,mBAAmB,CAAC;KAClC,GAAG,qBAAqB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,yFAAyF;IACzF,OAAO,CAAC,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,2BAA2B,GAAG,KAAK,CAAC;CAClD;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,oBAAoB,EAAE,aAYlC,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EACpC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,GAC9B,cAAc,CAAC,OAAO,CAAC,CAEzB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAElF;AAED,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,MAAM,GAChB,wBAAwB,CAuC1B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AgentModelCatalog, AgentModelSelectionStore, AgentRuntimeEvent, AgentSnapshot } from 'stitchkit/agent-runtime';
|
|
2
|
+
import type { AgentHarnessPendingApproval, HeadlessAgentHarness } from 'stitchkit/agent-runtime/harness';
|
|
3
|
+
export interface AgentTuiControllerState {
|
|
4
|
+
conversationId: string;
|
|
5
|
+
snapshot: AgentSnapshot;
|
|
6
|
+
selectedModelId?: string;
|
|
7
|
+
pendingApproval?: AgentHarnessPendingApproval;
|
|
8
|
+
streaming: Readonly<Record<string, string>>;
|
|
9
|
+
notice?: {
|
|
10
|
+
tone: 'info' | 'error';
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface AgentTuiController<_CONTEXT> {
|
|
15
|
+
state(): AgentTuiControllerState;
|
|
16
|
+
subscribe(listener: (state: AgentTuiControllerState) => void): () => void;
|
|
17
|
+
submit(text: string, idempotencyKey?: string): Promise<string>;
|
|
18
|
+
selectModel(modelId: string): Promise<void>;
|
|
19
|
+
switchConversation(conversationId: string): Promise<void>;
|
|
20
|
+
respondToApproval(approved: boolean, reason?: string): Promise<string>;
|
|
21
|
+
interrupt(runId?: string): Promise<void>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createAgentTuiController<CONTEXT>(input: {
|
|
25
|
+
harness: HeadlessAgentHarness<CONTEXT>;
|
|
26
|
+
catalog: AgentModelCatalog;
|
|
27
|
+
selections: AgentModelSelectionStore;
|
|
28
|
+
conversationId: string;
|
|
29
|
+
context(): CONTEXT | Promise<CONTEXT>;
|
|
30
|
+
preferredModelId?: string;
|
|
31
|
+
onDiagnostic?(input: {
|
|
32
|
+
conversationId: string;
|
|
33
|
+
runId?: string;
|
|
34
|
+
event: AgentRuntimeEvent;
|
|
35
|
+
}): void | Promise<void>;
|
|
36
|
+
}): Promise<AgentTuiController<CONTEXT>>;
|
|
37
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../src/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,aAAa,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,2BAA2B,CAAC;IAC9C,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACtD;AAED,MAAM,WAAW,kBAAkB,CAAC,QAAQ;IAC1C,KAAK,IAAI,uBAAuB,CAAC;IACjC,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC1E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAiBD,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,KAAK,EAAE;IAC7D,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,UAAU,EAAE,wBAAwB,CAAC;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,CAAC,KAAK,EAAE;QACnB,cAAc,EAAE,MAAM,CAAC;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,iBAAiB,CAAC;KAC1B,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B,GAAG,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAoLvC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TerminalCollectionStateSchema: z.ZodObject<{
|
|
3
|
+
keys: z.ZodArray<z.ZodString>;
|
|
4
|
+
selectedKey: z.ZodNullable<z.ZodString>;
|
|
5
|
+
start: z.ZodInt;
|
|
6
|
+
capacity: z.ZodInt;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export type TerminalCollectionState = z.infer<typeof TerminalCollectionStateSchema>;
|
|
9
|
+
export type TerminalCollectionAction = {
|
|
10
|
+
type: 'reconcile';
|
|
11
|
+
keys: readonly string[];
|
|
12
|
+
} | {
|
|
13
|
+
type: 'select';
|
|
14
|
+
key: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'move';
|
|
17
|
+
delta: number;
|
|
18
|
+
wrap?: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'scroll';
|
|
21
|
+
lines: number;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'resize';
|
|
24
|
+
capacity: number;
|
|
25
|
+
};
|
|
26
|
+
export declare function createTerminalCollection(keys: readonly string[], capacity: number, selectedKey?: string): TerminalCollectionState;
|
|
27
|
+
export declare function reduceTerminalCollection(state: TerminalCollectionState, action: TerminalCollectionAction): TerminalCollectionState;
|
|
28
|
+
export declare function visibleTerminalCollectionRange(state: TerminalCollectionState): {
|
|
29
|
+
start: number;
|
|
30
|
+
end: number;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/core/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,6BAA6B;;;;;kBAO/B,CAAC;AAEZ,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEpF,MAAM,MAAM,wBAAwB,GAChC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAqBzC,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,uBAAuB,CAczB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,uBAAuB,EAC9B,MAAM,EAAE,wBAAwB,GAC/B,uBAAuB,CAkEzB;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,uBAAuB,GAAG;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAMA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TerminalCommandDescriptorSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
aliases: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
5
|
+
label: z.ZodString;
|
|
6
|
+
description: z.ZodDefault<z.ZodString>;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export declare const TerminalCommandPaletteStateSchema: z.ZodObject<{
|
|
9
|
+
query: z.ZodString;
|
|
10
|
+
selectedIndex: z.ZodInt;
|
|
11
|
+
dismissed: z.ZodBoolean;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export type TerminalCommandDescriptor = z.infer<typeof TerminalCommandDescriptorSchema>;
|
|
14
|
+
export type TerminalCommandPaletteState = z.infer<typeof TerminalCommandPaletteStateSchema>;
|
|
15
|
+
export declare function validateTerminalCommands(commands: readonly TerminalCommandDescriptor[]): readonly TerminalCommandDescriptor[];
|
|
16
|
+
export declare function createTerminalCommandPalette(): TerminalCommandPaletteState;
|
|
17
|
+
export declare function setTerminalCommandQuery(state: TerminalCommandPaletteState, query: string): TerminalCommandPaletteState;
|
|
18
|
+
export declare function dismissTerminalCommandPalette(state: TerminalCommandPaletteState): TerminalCommandPaletteState;
|
|
19
|
+
export declare function terminalCommandMatches(state: TerminalCommandPaletteState, commands: readonly TerminalCommandDescriptor[], limit?: number): readonly TerminalCommandDescriptor[];
|
|
20
|
+
export declare function moveTerminalCommandSelection(state: TerminalCommandPaletteState, delta: number, matchCount: number): TerminalCommandPaletteState;
|
|
21
|
+
export declare function selectedTerminalCommand(state: TerminalCommandPaletteState, commands: readonly TerminalCommandDescriptor[], limit?: number): TerminalCommandDescriptor | undefined;
|
|
22
|
+
export declare function resolveExactTerminalCommand(name: string, commands: readonly TerminalCommandDescriptor[]): TerminalCommandDescriptor | undefined;
|
|
23
|
+
//# sourceMappingURL=command-palette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-palette.d.ts","sourceRoot":"","sources":["../../src/core/command-palette.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,+BAA+B;;;;;kBAOjC,CAAC;AAEZ,eAAO,MAAM,iCAAiC;;;;kBAMnC,CAAC;AAEZ,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AACxF,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAC;AAE5F,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,yBAAyB,EAAE,GAC7C,SAAS,yBAAyB,EAAE,CAWtC;AACD,wBAAgB,4BAA4B,IAAI,2BAA2B,CAE1E;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,2BAA2B,EAClC,KAAK,EAAE,MAAM,GACZ,2BAA2B,CAG7B;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,2BAA2B,GACjC,2BAA2B,CAE7B;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,2BAA2B,EAClC,QAAQ,EAAE,SAAS,yBAAyB,EAAE,EAC9C,KAAK,SAAK,GACT,SAAS,yBAAyB,EAAE,CAatC;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,2BAA2B,EAClC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,2BAA2B,CAO7B;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,2BAA2B,EAClC,QAAQ,EAAE,SAAS,yBAAyB,EAAE,EAC9C,KAAK,SAAK,GACT,yBAAyB,GAAG,SAAS,CAGvC;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,yBAAyB,EAAE,GAC7C,yBAAyB,GAAG,SAAS,CAIvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/core/collection.ts
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var TerminalCollectionStateSchema = z.object({
|
|
5
|
+
keys: z.array(z.string().min(1)),
|
|
6
|
+
selectedKey: z.string().min(1).nullable(),
|
|
7
|
+
start: z.int().nonnegative(),
|
|
8
|
+
capacity: z.int().positive()
|
|
9
|
+
}).strict();
|
|
10
|
+
function maximumStart(total, capacity) {
|
|
11
|
+
return Math.max(0, total - capacity);
|
|
12
|
+
}
|
|
13
|
+
function reveal(start, capacity, index, total) {
|
|
14
|
+
const bounded = Math.min(Math.max(0, start), maximumStart(total, capacity));
|
|
15
|
+
if (index < bounded)
|
|
16
|
+
return index;
|
|
17
|
+
if (index >= bounded + capacity)
|
|
18
|
+
return index - capacity + 1;
|
|
19
|
+
return bounded;
|
|
20
|
+
}
|
|
21
|
+
function uniqueKeys(keys) {
|
|
22
|
+
const result = z.array(z.string().min(1)).parse(keys);
|
|
23
|
+
if (new Set(result).size !== result.length) {
|
|
24
|
+
throw new Error("Terminal collection keys must be unique");
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
function createTerminalCollection(keys, capacity, selectedKey) {
|
|
29
|
+
const parsedKeys = uniqueKeys(keys);
|
|
30
|
+
const parsedCapacity = z.int().positive().parse(capacity);
|
|
31
|
+
const selected = selectedKey !== undefined && parsedKeys.includes(selectedKey) ? selectedKey : parsedKeys[0] ?? null;
|
|
32
|
+
const index = selected === null ? -1 : parsedKeys.indexOf(selected);
|
|
33
|
+
return TerminalCollectionStateSchema.parse({
|
|
34
|
+
keys: parsedKeys,
|
|
35
|
+
selectedKey: selected,
|
|
36
|
+
start: index < 0 ? 0 : reveal(0, parsedCapacity, index, parsedKeys.length),
|
|
37
|
+
capacity: parsedCapacity
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function reduceTerminalCollection(state, action) {
|
|
41
|
+
const current = TerminalCollectionStateSchema.parse(state);
|
|
42
|
+
if (action.type === "reconcile") {
|
|
43
|
+
const keys = uniqueKeys(action.keys);
|
|
44
|
+
if (keys.length === 0)
|
|
45
|
+
return { keys, selectedKey: null, start: 0, capacity: current.capacity };
|
|
46
|
+
const previousIndex = current.selectedKey === null ? 0 : Math.max(0, current.keys.indexOf(current.selectedKey));
|
|
47
|
+
const selectedKey2 = current.selectedKey !== null && keys.includes(current.selectedKey) ? current.selectedKey : keys[Math.min(previousIndex, keys.length - 1)];
|
|
48
|
+
if (!selectedKey2)
|
|
49
|
+
throw new Error("Terminal collection survivor is unavailable");
|
|
50
|
+
const index = keys.indexOf(selectedKey2);
|
|
51
|
+
return TerminalCollectionStateSchema.parse({
|
|
52
|
+
...current,
|
|
53
|
+
keys,
|
|
54
|
+
selectedKey: selectedKey2,
|
|
55
|
+
start: reveal(current.start, current.capacity, index, keys.length)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (action.type === "resize") {
|
|
59
|
+
const capacity = z.int().positive().parse(action.capacity);
|
|
60
|
+
const index = current.selectedKey === null ? -1 : current.keys.indexOf(current.selectedKey);
|
|
61
|
+
return TerminalCollectionStateSchema.parse({
|
|
62
|
+
...current,
|
|
63
|
+
capacity,
|
|
64
|
+
start: index < 0 ? 0 : reveal(current.start, capacity, index, current.keys.length)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (action.type === "scroll") {
|
|
68
|
+
return TerminalCollectionStateSchema.parse({
|
|
69
|
+
...current,
|
|
70
|
+
start: Math.min(Math.max(0, current.start + action.lines), maximumStart(current.keys.length, current.capacity))
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (current.keys.length === 0)
|
|
74
|
+
return current;
|
|
75
|
+
const currentIndex = current.selectedKey === null ? 0 : Math.max(0, current.keys.indexOf(current.selectedKey));
|
|
76
|
+
const nextIndex = action.type === "select" ? current.keys.indexOf(action.key) : action.wrap ? ((currentIndex + action.delta) % current.keys.length + current.keys.length) % current.keys.length : Math.min(Math.max(0, currentIndex + action.delta), current.keys.length - 1);
|
|
77
|
+
if (nextIndex < 0) {
|
|
78
|
+
throw new Error(action.type === "select" ? `Unknown terminal collection key: ${action.key}` : "Terminal collection movement could not resolve a selection");
|
|
79
|
+
}
|
|
80
|
+
const selectedKey = current.keys[nextIndex];
|
|
81
|
+
if (!selectedKey)
|
|
82
|
+
throw new Error("Terminal collection selection is unavailable");
|
|
83
|
+
return TerminalCollectionStateSchema.parse({
|
|
84
|
+
...current,
|
|
85
|
+
selectedKey,
|
|
86
|
+
start: reveal(current.start, current.capacity, nextIndex, current.keys.length)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function visibleTerminalCollectionRange(state) {
|
|
90
|
+
const parsed = TerminalCollectionStateSchema.parse(state);
|
|
91
|
+
return {
|
|
92
|
+
start: parsed.start,
|
|
93
|
+
end: Math.min(parsed.keys.length, parsed.start + parsed.capacity)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// src/core/command-palette.ts
|
|
97
|
+
import { z as z2 } from "zod";
|
|
98
|
+
var TerminalCommandDescriptorSchema = z2.object({
|
|
99
|
+
id: z2.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
100
|
+
aliases: z2.array(z2.string().min(1)).default([]),
|
|
101
|
+
label: z2.string().min(1),
|
|
102
|
+
description: z2.string().default("")
|
|
103
|
+
}).strict();
|
|
104
|
+
var TerminalCommandPaletteStateSchema = z2.object({
|
|
105
|
+
query: z2.string(),
|
|
106
|
+
selectedIndex: z2.int().nonnegative(),
|
|
107
|
+
dismissed: z2.boolean()
|
|
108
|
+
}).strict();
|
|
109
|
+
function validateTerminalCommands(commands) {
|
|
110
|
+
const parsed = commands.map((command) => TerminalCommandDescriptorSchema.parse(command));
|
|
111
|
+
const owners = new Map;
|
|
112
|
+
for (const command of parsed) {
|
|
113
|
+
for (const name of [command.id, ...command.aliases]) {
|
|
114
|
+
const owner = owners.get(name);
|
|
115
|
+
if (owner)
|
|
116
|
+
throw new Error(`Terminal command ${name} collides with ${owner}`);
|
|
117
|
+
owners.set(name, command.id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return parsed;
|
|
121
|
+
}
|
|
122
|
+
function createTerminalCommandPalette() {
|
|
123
|
+
return { query: "", selectedIndex: 0, dismissed: false };
|
|
124
|
+
}
|
|
125
|
+
function setTerminalCommandQuery(state, query) {
|
|
126
|
+
TerminalCommandPaletteStateSchema.parse(state);
|
|
127
|
+
return { query, selectedIndex: 0, dismissed: false };
|
|
128
|
+
}
|
|
129
|
+
function dismissTerminalCommandPalette(state) {
|
|
130
|
+
return { ...TerminalCommandPaletteStateSchema.parse(state), dismissed: true };
|
|
131
|
+
}
|
|
132
|
+
function terminalCommandMatches(state, commands, limit = 20) {
|
|
133
|
+
const current = TerminalCommandPaletteStateSchema.parse(state);
|
|
134
|
+
if (current.dismissed)
|
|
135
|
+
return [];
|
|
136
|
+
const parsed = validateTerminalCommands(commands);
|
|
137
|
+
const query = current.query.toLowerCase();
|
|
138
|
+
return parsed.filter((command) => command.id.includes(query) || command.label.toLowerCase().includes(query) || command.aliases.some((alias) => alias.includes(query))).slice(0, z2.int().positive().parse(limit));
|
|
139
|
+
}
|
|
140
|
+
function moveTerminalCommandSelection(state, delta, matchCount) {
|
|
141
|
+
const current = TerminalCommandPaletteStateSchema.parse(state);
|
|
142
|
+
if (matchCount <= 0)
|
|
143
|
+
return { ...current, selectedIndex: 0 };
|
|
144
|
+
return {
|
|
145
|
+
...current,
|
|
146
|
+
selectedIndex: ((current.selectedIndex + delta) % matchCount + matchCount) % matchCount
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function selectedTerminalCommand(state, commands, limit = 20) {
|
|
150
|
+
const matches = terminalCommandMatches(state, commands, limit);
|
|
151
|
+
return matches[state.selectedIndex] ?? matches[0];
|
|
152
|
+
}
|
|
153
|
+
function resolveExactTerminalCommand(name, commands) {
|
|
154
|
+
return validateTerminalCommands(commands).find((command) => command.id === name || command.aliases.includes(name));
|
|
155
|
+
}
|
|
156
|
+
// src/core/operation.ts
|
|
157
|
+
import { z as z3 } from "zod";
|
|
158
|
+
var TerminalOperationStateSchema = z3.object({
|
|
159
|
+
status: z3.enum(["idle", "confirming", "pending", "succeeded", "failed"]),
|
|
160
|
+
operationId: z3.string().min(1).nullable(),
|
|
161
|
+
message: z3.string().optional()
|
|
162
|
+
}).strict();
|
|
163
|
+
function createTerminalOperationState() {
|
|
164
|
+
return { status: "idle", operationId: null };
|
|
165
|
+
}
|
|
166
|
+
function reduceTerminalOperationState(state, action) {
|
|
167
|
+
const current = TerminalOperationStateSchema.parse(state);
|
|
168
|
+
if (action.type === "request") {
|
|
169
|
+
if (current.status === "pending")
|
|
170
|
+
throw new Error("A terminal operation is already pending");
|
|
171
|
+
return TerminalOperationStateSchema.parse({
|
|
172
|
+
status: "confirming",
|
|
173
|
+
operationId: action.operationId,
|
|
174
|
+
...action.message !== undefined && { message: action.message }
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (action.type === "reset" || action.type === "cancel") {
|
|
178
|
+
if (action.type === "cancel" && current.status !== "confirming") {
|
|
179
|
+
throw new Error("Only a confirming terminal operation can be cancelled");
|
|
180
|
+
}
|
|
181
|
+
return createTerminalOperationState();
|
|
182
|
+
}
|
|
183
|
+
if (action.type === "confirm") {
|
|
184
|
+
if (current.status !== "confirming") {
|
|
185
|
+
throw new Error("Only a confirming terminal operation can become pending");
|
|
186
|
+
}
|
|
187
|
+
return { ...current, status: "pending" };
|
|
188
|
+
}
|
|
189
|
+
if (current.status !== "pending") {
|
|
190
|
+
throw new Error("Only a pending terminal operation can settle");
|
|
191
|
+
}
|
|
192
|
+
return TerminalOperationStateSchema.parse({
|
|
193
|
+
status: action.type === "succeed" ? "succeeded" : "failed",
|
|
194
|
+
operationId: current.operationId,
|
|
195
|
+
...action.message !== undefined && { message: action.message }
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// src/core/panes.ts
|
|
199
|
+
import { z as z4 } from "zod";
|
|
200
|
+
var TerminalPaneIdSchema = z4.enum(["primary", "secondary"]);
|
|
201
|
+
var TerminalPaneModeSchema = z4.enum(["split", "single"]);
|
|
202
|
+
var TerminalPaneStateSchema = z4.object({
|
|
203
|
+
mode: TerminalPaneModeSchema,
|
|
204
|
+
focus: TerminalPaneIdSchema,
|
|
205
|
+
primarySize: z4.int().positive(),
|
|
206
|
+
totalSize: z4.int().positive(),
|
|
207
|
+
minPrimary: z4.int().positive(),
|
|
208
|
+
minSecondary: z4.int().positive()
|
|
209
|
+
}).strict();
|
|
210
|
+
function clampPrimary(input) {
|
|
211
|
+
const maximum = Math.max(input.minPrimary, input.totalSize - input.minSecondary);
|
|
212
|
+
return Math.min(Math.max(input.minPrimary, input.primarySize), maximum);
|
|
213
|
+
}
|
|
214
|
+
function createTerminalPaneState(input) {
|
|
215
|
+
const values = z4.object({
|
|
216
|
+
totalSize: z4.int().positive(),
|
|
217
|
+
primarySize: z4.int().positive(),
|
|
218
|
+
minPrimary: z4.int().positive(),
|
|
219
|
+
minSecondary: z4.int().positive(),
|
|
220
|
+
mode: TerminalPaneModeSchema.default("split"),
|
|
221
|
+
focus: TerminalPaneIdSchema.default("primary")
|
|
222
|
+
}).strict().parse(input);
|
|
223
|
+
if (values.mode === "split" && values.totalSize < values.minPrimary + values.minSecondary) {
|
|
224
|
+
throw new Error("Split terminal panes do not fit within the total size");
|
|
225
|
+
}
|
|
226
|
+
return TerminalPaneStateSchema.parse({
|
|
227
|
+
...values,
|
|
228
|
+
primarySize: clampPrimary(values)
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function reduceTerminalPaneState(state, action) {
|
|
232
|
+
const current = TerminalPaneStateSchema.parse(state);
|
|
233
|
+
if (action.type === "focus")
|
|
234
|
+
return { ...current, focus: action.pane };
|
|
235
|
+
if (action.type === "toggle-focus") {
|
|
236
|
+
return { ...current, focus: current.focus === "primary" ? "secondary" : "primary" };
|
|
237
|
+
}
|
|
238
|
+
if (action.type === "mode") {
|
|
239
|
+
if (action.mode === "split" && current.totalSize < current.minPrimary + current.minSecondary) {
|
|
240
|
+
throw new Error("Split terminal panes do not fit within the total size");
|
|
241
|
+
}
|
|
242
|
+
return { ...current, mode: action.mode };
|
|
243
|
+
}
|
|
244
|
+
const totalSize = action.type === "terminal-resize" ? action.totalSize : current.totalSize;
|
|
245
|
+
const mode = current.mode === "split" && totalSize < current.minPrimary + current.minSecondary ? "single" : current.mode;
|
|
246
|
+
const primarySize = action.type === "resize" ? action.primarySize : current.primarySize;
|
|
247
|
+
return TerminalPaneStateSchema.parse({
|
|
248
|
+
...current,
|
|
249
|
+
totalSize,
|
|
250
|
+
mode,
|
|
251
|
+
primarySize: clampPrimary({
|
|
252
|
+
primarySize,
|
|
253
|
+
totalSize,
|
|
254
|
+
minPrimary: current.minPrimary,
|
|
255
|
+
minSecondary: current.minSecondary
|
|
256
|
+
})
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function visibleTerminalPanes(state) {
|
|
260
|
+
const parsed = TerminalPaneStateSchema.parse(state);
|
|
261
|
+
return parsed.mode === "split" ? ["primary", "secondary"] : [parsed.focus];
|
|
262
|
+
}
|
|
263
|
+
// src/core/viewport.ts
|
|
264
|
+
import { z as z5 } from "zod";
|
|
265
|
+
var TerminalFeedViewportSchema = z5.object({
|
|
266
|
+
total: z5.int().nonnegative(),
|
|
267
|
+
capacity: z5.int().positive(),
|
|
268
|
+
start: z5.int().nonnegative(),
|
|
269
|
+
followTail: z5.boolean(),
|
|
270
|
+
unseen: z5.int().nonnegative()
|
|
271
|
+
}).strict();
|
|
272
|
+
function maximumStart2(total, capacity) {
|
|
273
|
+
return Math.max(0, total - capacity);
|
|
274
|
+
}
|
|
275
|
+
function createTerminalFeedViewport(total, capacity) {
|
|
276
|
+
const parsedTotal = z5.int().nonnegative().parse(total);
|
|
277
|
+
const parsedCapacity = z5.int().positive().parse(capacity);
|
|
278
|
+
return TerminalFeedViewportSchema.parse({
|
|
279
|
+
total: parsedTotal,
|
|
280
|
+
capacity: parsedCapacity,
|
|
281
|
+
start: maximumStart2(parsedTotal, parsedCapacity),
|
|
282
|
+
followTail: true,
|
|
283
|
+
unseen: 0
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function reduceTerminalFeedViewport(state, action) {
|
|
287
|
+
const current = TerminalFeedViewportSchema.parse(state);
|
|
288
|
+
if (action.type === "append") {
|
|
289
|
+
const count = Math.max(0, action.count);
|
|
290
|
+
const total = current.total + count;
|
|
291
|
+
return TerminalFeedViewportSchema.parse({
|
|
292
|
+
...current,
|
|
293
|
+
total,
|
|
294
|
+
start: current.followTail ? maximumStart2(total, current.capacity) : current.start,
|
|
295
|
+
unseen: current.followTail ? 0 : current.unseen + count
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (action.type === "prepend") {
|
|
299
|
+
const count = Math.max(0, action.count);
|
|
300
|
+
return TerminalFeedViewportSchema.parse({
|
|
301
|
+
...current,
|
|
302
|
+
total: current.total + count,
|
|
303
|
+
start: current.start + count
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (action.type === "resize") {
|
|
307
|
+
const capacity = z5.int().positive().parse(action.capacity);
|
|
308
|
+
return TerminalFeedViewportSchema.parse({
|
|
309
|
+
...current,
|
|
310
|
+
capacity,
|
|
311
|
+
start: current.followTail ? maximumStart2(current.total, capacity) : Math.min(current.start, maximumStart2(current.total, capacity))
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (action.type === "home")
|
|
315
|
+
return { ...current, start: 0, followTail: false };
|
|
316
|
+
if (action.type === "end") {
|
|
317
|
+
return {
|
|
318
|
+
...current,
|
|
319
|
+
start: maximumStart2(current.total, current.capacity),
|
|
320
|
+
followTail: true,
|
|
321
|
+
unseen: 0
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const delta = action.type === "page" ? action.pages * current.capacity : action.lines;
|
|
325
|
+
const start = Math.max(0, Math.min(maximumStart2(current.total, current.capacity), current.start + delta));
|
|
326
|
+
const atTail = start === maximumStart2(current.total, current.capacity) && delta > 0;
|
|
327
|
+
return { ...current, start, followTail: atTail, unseen: atTail ? 0 : current.unseen };
|
|
328
|
+
}
|
|
329
|
+
function visibleTerminalFeedRange(state) {
|
|
330
|
+
const parsed = TerminalFeedViewportSchema.parse(state);
|
|
331
|
+
return { start: parsed.start, end: Math.min(parsed.total, parsed.start + parsed.capacity) };
|
|
332
|
+
}
|
|
333
|
+
export {
|
|
334
|
+
TerminalCollectionStateSchema,
|
|
335
|
+
TerminalCommandDescriptorSchema,
|
|
336
|
+
TerminalCommandPaletteStateSchema,
|
|
337
|
+
TerminalFeedViewportSchema,
|
|
338
|
+
TerminalOperationStateSchema,
|
|
339
|
+
TerminalPaneIdSchema,
|
|
340
|
+
TerminalPaneModeSchema,
|
|
341
|
+
TerminalPaneStateSchema,
|
|
342
|
+
createTerminalCollection,
|
|
343
|
+
createTerminalCommandPalette,
|
|
344
|
+
createTerminalFeedViewport,
|
|
345
|
+
createTerminalOperationState,
|
|
346
|
+
createTerminalPaneState,
|
|
347
|
+
dismissTerminalCommandPalette,
|
|
348
|
+
moveTerminalCommandSelection,
|
|
349
|
+
reduceTerminalCollection,
|
|
350
|
+
reduceTerminalFeedViewport,
|
|
351
|
+
reduceTerminalOperationState,
|
|
352
|
+
reduceTerminalPaneState,
|
|
353
|
+
resolveExactTerminalCommand,
|
|
354
|
+
selectedTerminalCommand,
|
|
355
|
+
setTerminalCommandQuery,
|
|
356
|
+
terminalCommandMatches,
|
|
357
|
+
validateTerminalCommands,
|
|
358
|
+
visibleTerminalCollectionRange,
|
|
359
|
+
visibleTerminalFeedRange,
|
|
360
|
+
visibleTerminalPanes
|
|
361
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TerminalOperationStateSchema: z.ZodObject<{
|
|
3
|
+
status: z.ZodEnum<{
|
|
4
|
+
confirming: "confirming";
|
|
5
|
+
failed: "failed";
|
|
6
|
+
idle: "idle";
|
|
7
|
+
pending: "pending";
|
|
8
|
+
succeeded: "succeeded";
|
|
9
|
+
}>;
|
|
10
|
+
operationId: z.ZodNullable<z.ZodString>;
|
|
11
|
+
message: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export type TerminalOperationState = z.infer<typeof TerminalOperationStateSchema>;
|
|
14
|
+
export type TerminalOperationAction = {
|
|
15
|
+
type: 'request';
|
|
16
|
+
operationId: string;
|
|
17
|
+
message?: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'confirm';
|
|
20
|
+
} | {
|
|
21
|
+
type: 'cancel';
|
|
22
|
+
} | {
|
|
23
|
+
type: 'succeed';
|
|
24
|
+
message?: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'fail';
|
|
27
|
+
message: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'reset';
|
|
30
|
+
};
|
|
31
|
+
export declare function createTerminalOperationState(): TerminalOperationState;
|
|
32
|
+
export declare function reduceTerminalOperationState(state: TerminalOperationState, action: TerminalOperationAction): TerminalOperationState;
|
|
33
|
+
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/core/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,4BAA4B;;;;;;;;;;kBAM9B,CAAC;AAEZ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF,MAAM,MAAM,uBAAuB,GAC/B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtB,wBAAgB,4BAA4B,IAAI,sBAAsB,CAErE;AACD,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,sBAAsB,EAC7B,MAAM,EAAE,uBAAuB,GAC9B,sBAAsB,CA+BxB"}
|