@saturn-universe/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/dist/attach.d.ts +9 -0
- package/dist/attach.js +80 -0
- package/dist/auth-config.d.ts +31 -0
- package/dist/auth-config.js +285 -0
- package/dist/choice-menu.d.ts +13 -0
- package/dist/choice-menu.js +238 -0
- package/dist/cli-diagnostics.d.ts +23 -0
- package/dist/cli-diagnostics.js +42 -0
- package/dist/cli-help.d.ts +6 -0
- package/dist/cli-help.js +163 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +90 -0
- package/dist/commands.d.ts +64 -0
- package/dist/commands.js +299 -0
- package/dist/compaction-command.d.ts +16 -0
- package/dist/compaction-command.js +16 -0
- package/dist/composer.d.ts +88 -0
- package/dist/composer.js +124 -0
- package/dist/config-cli.d.ts +1 -0
- package/dist/config-cli.js +47 -0
- package/dist/config-file.d.ts +1 -0
- package/dist/config-file.js +43 -0
- package/dist/config-lock.d.ts +5 -0
- package/dist/config-lock.js +45 -0
- package/dist/duration.d.ts +2 -0
- package/dist/duration.js +11 -0
- package/dist/export.d.ts +19 -0
- package/dist/export.js +66 -0
- package/dist/host-command.d.ts +40 -0
- package/dist/host-command.js +48 -0
- package/dist/host-launcher.d.ts +22 -0
- package/dist/host-launcher.js +300 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +400 -0
- package/dist/markdown.d.ts +1 -0
- package/dist/markdown.js +118 -0
- package/dist/mcp-cli.d.ts +44 -0
- package/dist/mcp-cli.js +647 -0
- package/dist/menu.d.ts +7 -0
- package/dist/menu.js +91 -0
- package/dist/project-mcp-config.d.ts +9 -0
- package/dist/project-mcp-config.js +98 -0
- package/dist/provider-discovery.d.ts +26 -0
- package/dist/provider-discovery.js +138 -0
- package/dist/provider-pricing.d.ts +3 -0
- package/dist/provider-pricing.js +130 -0
- package/dist/provider.d.ts +16 -0
- package/dist/provider.js +370 -0
- package/dist/reconcile-command.d.ts +36 -0
- package/dist/reconcile-command.js +64 -0
- package/dist/renderer.d.ts +204 -0
- package/dist/renderer.js +1134 -0
- package/dist/repl-host.d.ts +22 -0
- package/dist/repl-host.js +51 -0
- package/dist/repl-run-observer.d.ts +27 -0
- package/dist/repl-run-observer.js +86 -0
- package/dist/repl.d.ts +12 -0
- package/dist/repl.js +1834 -0
- package/dist/results.d.ts +23 -0
- package/dist/results.js +1 -0
- package/dist/sandbox-cli.d.ts +39 -0
- package/dist/sandbox-cli.js +324 -0
- package/dist/session-history.d.ts +17 -0
- package/dist/session-history.js +76 -0
- package/dist/settings-menu.d.ts +2 -0
- package/dist/settings-menu.js +111 -0
- package/dist/skill-cli.d.ts +25 -0
- package/dist/skill-cli.js +355 -0
- package/dist/slash-commands.d.ts +66 -0
- package/dist/slash-commands.js +1449 -0
- package/dist/terminal-input.d.ts +24 -0
- package/dist/terminal-input.js +111 -0
- package/dist/terminal-selection.d.ts +21 -0
- package/dist/terminal-selection.js +72 -0
- package/dist/terminal-text.d.ts +38 -0
- package/dist/terminal-text.js +238 -0
- package/dist/tui.d.ts +170 -0
- package/dist/tui.js +2559 -0
- package/dist/usage.d.ts +13 -0
- package/dist/usage.js +46 -0
- package/dist/user-config.d.ts +48 -0
- package/dist/user-config.js +188 -0
- package/package.json +18 -3
- package/README.md +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HostStatusSnapshot, ModeSummary } from '@saturn-universe/protocol';
|
|
2
|
+
import type { HostLaunchOptions, ManagedHost } from './host-launcher.js';
|
|
3
|
+
export interface ReplHostState {
|
|
4
|
+
workdir: string;
|
|
5
|
+
host?: ManagedHost | undefined;
|
|
6
|
+
activeMode?: ModeSummary | undefined;
|
|
7
|
+
modeRef?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function applyReplMode(state: ReplHostState, activeMode: ModeSummary | undefined, modeRef?: string): void;
|
|
10
|
+
export declare function createReplHostConnection(state: ReplHostState, initialOptions: HostLaunchOptions): {
|
|
11
|
+
launch: () => Promise<ManagedHost>;
|
|
12
|
+
accept: (host: ManagedHost) => ManagedHost;
|
|
13
|
+
refreshStatus: ({ signal, merge }?: {
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
merge?: boolean;
|
|
16
|
+
}) => Promise<{
|
|
17
|
+
previous: ManagedHost;
|
|
18
|
+
current: ManagedHost;
|
|
19
|
+
} | undefined>;
|
|
20
|
+
refreshSnapshot(): Promise<HostStatusSnapshot | undefined>;
|
|
21
|
+
restart(targetMode?: string): Promise<ManagedHost>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { sendHostCommand } from './host-command.js';
|
|
2
|
+
import { ensureHost, restartHost } from './host-launcher.js';
|
|
3
|
+
export function applyReplMode(state, activeMode, modeRef) {
|
|
4
|
+
state.activeMode = activeMode;
|
|
5
|
+
state.modeRef = activeMode?.ref ?? modeRef;
|
|
6
|
+
}
|
|
7
|
+
export function createReplHostConnection(state, initialOptions) {
|
|
8
|
+
let launchOptions = { ...initialOptions };
|
|
9
|
+
let latestStatusRequest = 0;
|
|
10
|
+
function accept(host) {
|
|
11
|
+
state.host = host;
|
|
12
|
+
applyReplMode(state, host.status.activeMode);
|
|
13
|
+
return host;
|
|
14
|
+
}
|
|
15
|
+
async function refreshStatus({ signal, merge = false } = {}) {
|
|
16
|
+
const previous = state.host;
|
|
17
|
+
if (!previous || signal?.aborted)
|
|
18
|
+
return undefined;
|
|
19
|
+
const request = ++latestStatusRequest;
|
|
20
|
+
const isCurrent = () => state.host === previous && request === latestStatusRequest && !signal?.aborted;
|
|
21
|
+
let status;
|
|
22
|
+
try {
|
|
23
|
+
status = await sendHostCommand(state.workdir, { type: 'host.status' }, signal ? { signal } : undefined);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!isCurrent())
|
|
27
|
+
return undefined;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
if (!isCurrent() || !status)
|
|
31
|
+
return undefined;
|
|
32
|
+
const current = accept({ ...previous, status: merge ? { ...previous.status, ...status } : status });
|
|
33
|
+
return { previous, current };
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
launch: () => ensureHost(state.workdir, launchOptions),
|
|
37
|
+
accept,
|
|
38
|
+
refreshStatus,
|
|
39
|
+
async refreshSnapshot() {
|
|
40
|
+
await refreshStatus({ merge: true });
|
|
41
|
+
return state.host?.status;
|
|
42
|
+
},
|
|
43
|
+
async restart(targetMode) {
|
|
44
|
+
const nextOptions = targetMode === undefined ? launchOptions : { ...launchOptions, mode: targetMode };
|
|
45
|
+
latestStatusRequest++;
|
|
46
|
+
const host = await restartHost(state.workdir, state.host, nextOptions);
|
|
47
|
+
launchOptions = nextOptions;
|
|
48
|
+
return accept(host);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RenderProgressEvent } from './renderer.js';
|
|
2
|
+
import type { CliResult } from './results.js';
|
|
3
|
+
interface FollowOptions {
|
|
4
|
+
readonly runId: string;
|
|
5
|
+
readonly after: string;
|
|
6
|
+
readonly interactiveProgress?: true;
|
|
7
|
+
readonly approvals: {
|
|
8
|
+
readonly resolved: number;
|
|
9
|
+
observe(snapshot: CliResult['pendingApprovals']): void;
|
|
10
|
+
finishPause(runId: string, reason: string | undefined, signal: AbortSignal): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
onReconnect(message: string): void;
|
|
13
|
+
onPage(page: CliResult, events: readonly RenderProgressEvent[]): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function createReplRunObserver(workdir: string, runCursors: Map<string, string>): {
|
|
16
|
+
readonly active: boolean;
|
|
17
|
+
detach: () => boolean;
|
|
18
|
+
close(): void;
|
|
19
|
+
follow({ runId, after, interactiveProgress, approvals, onReconnect, onPage }: FollowOptions): Promise<{
|
|
20
|
+
reportedError: boolean;
|
|
21
|
+
cursor: string;
|
|
22
|
+
status?: import("@saturn-universe/core").TerminalRunStatus | "paused";
|
|
23
|
+
pauseReason?: string;
|
|
24
|
+
detached?: boolean;
|
|
25
|
+
} | undefined>;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import { attach } from './attach.js';
|
|
4
|
+
import { safeCode } from './cli-diagnostics.js';
|
|
5
|
+
export function createReplRunObserver(workdir, runCursors) {
|
|
6
|
+
const lifetime = new AbortController();
|
|
7
|
+
const { signal } = lifetime;
|
|
8
|
+
let activeAttempt;
|
|
9
|
+
function detach() {
|
|
10
|
+
if (!activeAttempt || activeAttempt.signal.aborted)
|
|
11
|
+
return false;
|
|
12
|
+
activeAttempt.abort();
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
get active() {
|
|
17
|
+
return activeAttempt !== undefined;
|
|
18
|
+
},
|
|
19
|
+
detach,
|
|
20
|
+
close() {
|
|
21
|
+
lifetime.abort();
|
|
22
|
+
detach();
|
|
23
|
+
},
|
|
24
|
+
async follow({ runId, after, interactiveProgress, approvals, onReconnect, onPage }) {
|
|
25
|
+
let cursor = after;
|
|
26
|
+
let lastPosition = -1n;
|
|
27
|
+
while (!signal.aborted) {
|
|
28
|
+
const resolvedBeforeAttach = approvals.resolved;
|
|
29
|
+
const attempt = new AbortController();
|
|
30
|
+
activeAttempt = attempt;
|
|
31
|
+
let reportedError = false;
|
|
32
|
+
let result;
|
|
33
|
+
try {
|
|
34
|
+
result = await attach(workdir, {
|
|
35
|
+
runId,
|
|
36
|
+
...(interactiveProgress ? { interactiveProgress } : {}),
|
|
37
|
+
values: { after: cursor, 'poll-ms': '100', 'timeout-ms': '0', reconnect: true },
|
|
38
|
+
commandId: randomUUID(),
|
|
39
|
+
}, (frame) => {
|
|
40
|
+
if (signal.aborted)
|
|
41
|
+
return;
|
|
42
|
+
if (!frame.ok) {
|
|
43
|
+
onReconnect(`[Reconnecting] ${safeCode(frame.error.code)} (cursor=${frame.cursor ?? cursor})`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const page = frame.result;
|
|
47
|
+
const events = (page.events ?? []).filter((event) => {
|
|
48
|
+
const position = BigInt(event.position);
|
|
49
|
+
if (position <= lastPosition)
|
|
50
|
+
return false;
|
|
51
|
+
lastPosition = position;
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
if (onPage(page, events))
|
|
55
|
+
reportedError = true;
|
|
56
|
+
if (page.cursor !== undefined)
|
|
57
|
+
runCursors.set(runId, page.cursor);
|
|
58
|
+
approvals.observe(page.pendingApprovals);
|
|
59
|
+
}, attempt.signal);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
activeAttempt = undefined;
|
|
63
|
+
}
|
|
64
|
+
cursor = result.cursor;
|
|
65
|
+
runCursors.set(runId, cursor);
|
|
66
|
+
const outcome = { ...result, reportedError };
|
|
67
|
+
if (result.detached || result.status !== 'paused')
|
|
68
|
+
return outcome;
|
|
69
|
+
if (signal.aborted)
|
|
70
|
+
return;
|
|
71
|
+
try {
|
|
72
|
+
await approvals.finishPause(runId, result.pauseReason, signal);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (!signal.aborted)
|
|
76
|
+
throw error;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (approvals.resolved <= resolvedBeforeAttach)
|
|
80
|
+
return outcome;
|
|
81
|
+
if (!signal.aborted)
|
|
82
|
+
await delay(20);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
package/dist/repl.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HostLaunchOptions } from './host-launcher.js';
|
|
2
|
+
import type { RenderProgressEvent } from './renderer.js';
|
|
3
|
+
import type { ReplState } from './slash-commands.js';
|
|
4
|
+
export interface ReplOptions extends HostLaunchOptions {
|
|
5
|
+
readonly workdir: string;
|
|
6
|
+
readonly modeRef?: string | undefined;
|
|
7
|
+
readonly skillRefs?: readonly string[] | undefined;
|
|
8
|
+
readonly sessionId?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function formatResumeCommand(workdir: string, sessionId: string, cwd?: string): string;
|
|
11
|
+
export declare function showTeamEvent(event: RenderProgressEvent, member: ReplState['member']): boolean;
|
|
12
|
+
export declare function startRepl(options: ReplOptions): Promise<void>;
|