@saturn-universe/cli 0.0.0-stage → 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 +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
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ModelPricing, SessionUsageResult } from '@saturn-universe/protocol';
|
|
2
|
+
type UsageBucketView = SessionUsageResult['total'];
|
|
3
|
+
export type SessionUsageView = Omit<SessionUsageResult, 'sessionId' | 'model'>;
|
|
4
|
+
export declare function resolveModelPricing(modelId?: string, explicit?: ModelPricing, source?: 'config' | 'builtin'): {
|
|
5
|
+
readonly pricing: ModelPricing;
|
|
6
|
+
readonly source: 'config' | 'builtin';
|
|
7
|
+
} | undefined;
|
|
8
|
+
export declare function estimateUsageCostUsd(bucket: UsageBucketView, pricing: ModelPricing): number;
|
|
9
|
+
export declare function formatTokenCompact(tokens: number): string;
|
|
10
|
+
export declare function formatTokenExact(tokens: number): string;
|
|
11
|
+
export declare function formatCacheRate(inputTokens: number, cachedInputTokens: number): string;
|
|
12
|
+
export declare function formatUsd(usd: number): string;
|
|
13
|
+
export {};
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { lookupModelMetadata } from '@saturn-universe/protocol';
|
|
2
|
+
export function resolveModelPricing(modelId, explicit, source = 'config') {
|
|
3
|
+
if (explicit)
|
|
4
|
+
return { pricing: explicit, source };
|
|
5
|
+
if (!modelId)
|
|
6
|
+
return undefined;
|
|
7
|
+
const pricing = lookupModelMetadata(modelId)?.pricing;
|
|
8
|
+
return pricing ? { pricing, source: 'builtin' } : undefined;
|
|
9
|
+
}
|
|
10
|
+
export function estimateUsageCostUsd(bucket, pricing) {
|
|
11
|
+
const cached = Math.min(bucket.inputTokens, Math.max(0, bucket.cachedInputTokens));
|
|
12
|
+
const uncached = Math.max(0, bucket.inputTokens - cached);
|
|
13
|
+
const cachedRate = pricing.cachedInputPerMillion ?? pricing.inputPerMillion;
|
|
14
|
+
return ((uncached * pricing.inputPerMillion +
|
|
15
|
+
cached * cachedRate +
|
|
16
|
+
bucket.outputTokens * pricing.outputPerMillion) /
|
|
17
|
+
1_000_000);
|
|
18
|
+
}
|
|
19
|
+
export function formatTokenCompact(tokens) {
|
|
20
|
+
if (tokens >= 1_000_000) {
|
|
21
|
+
const val = tokens / 1_000_000;
|
|
22
|
+
return `${val >= 10 ? Math.round(val) : Number(val.toFixed(1))}M`;
|
|
23
|
+
}
|
|
24
|
+
if (tokens >= 1_000) {
|
|
25
|
+
const val = tokens / 1_000;
|
|
26
|
+
return `${val >= 100 ? Math.round(val) : Number(val.toFixed(1))}k`;
|
|
27
|
+
}
|
|
28
|
+
return String(tokens);
|
|
29
|
+
}
|
|
30
|
+
const exactTokenFormat = new Intl.NumberFormat('en-US');
|
|
31
|
+
export function formatTokenExact(tokens) {
|
|
32
|
+
return exactTokenFormat.format(tokens);
|
|
33
|
+
}
|
|
34
|
+
export function formatCacheRate(inputTokens, cachedInputTokens) {
|
|
35
|
+
if (inputTokens <= 0)
|
|
36
|
+
return '—';
|
|
37
|
+
const pct = (Math.min(inputTokens, Math.max(0, cachedInputTokens)) / inputTokens) * 100;
|
|
38
|
+
return `${pct >= 10 ? pct.toFixed(1) : pct.toFixed(1)}%`;
|
|
39
|
+
}
|
|
40
|
+
export function formatUsd(usd) {
|
|
41
|
+
if (usd === 0)
|
|
42
|
+
return '$0.0000';
|
|
43
|
+
if (usd < 0.01)
|
|
44
|
+
return `$${usd.toFixed(4)}`;
|
|
45
|
+
return `$${usd.toFixed(3)}`;
|
|
46
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type TomlTable } from 'smol-toml';
|
|
2
|
+
import type { PermissionMode } from '@saturn-universe/protocol';
|
|
3
|
+
export interface ConfigFileStatus {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly exists: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface UserConfigInspection {
|
|
8
|
+
readonly saturnHome: string;
|
|
9
|
+
readonly workdir: string;
|
|
10
|
+
readonly files: {
|
|
11
|
+
readonly workspaceConfig: ConfigFileStatus;
|
|
12
|
+
readonly userConfig: ConfigFileStatus;
|
|
13
|
+
readonly userCredentials: ConfigFileStatus;
|
|
14
|
+
readonly userEnv: ConfigFileStatus;
|
|
15
|
+
readonly authCredentials: ConfigFileStatus;
|
|
16
|
+
readonly workspaceEnv: ConfigFileStatus;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface InitUserConfigResult {
|
|
20
|
+
readonly saturnHome: string;
|
|
21
|
+
readonly configPath: string;
|
|
22
|
+
readonly credentialsPath: string;
|
|
23
|
+
readonly configCreated: boolean;
|
|
24
|
+
readonly credentialsCreated: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface UserConfigDefaultsPatch {
|
|
27
|
+
readonly defaultProfile?: string | null;
|
|
28
|
+
readonly permissionMode?: PermissionMode | null;
|
|
29
|
+
readonly reasoningEffort?: string | null;
|
|
30
|
+
readonly workerReasoningEffort?: string | null;
|
|
31
|
+
readonly modeRef?: string | null;
|
|
32
|
+
}
|
|
33
|
+
export interface SaveUserConfigResult {
|
|
34
|
+
readonly configPath: string;
|
|
35
|
+
readonly created: boolean;
|
|
36
|
+
readonly workspaceConfigOverrides: boolean;
|
|
37
|
+
readonly workspaceConfigPath?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function inspectUserConfig(workdir: string, env?: NodeJS.ProcessEnv): Promise<UserConfigInspection>;
|
|
40
|
+
export declare function initUserConfig(force?: boolean, env?: NodeJS.ProcessEnv): Promise<InitUserConfigResult>;
|
|
41
|
+
export declare function updateUserConfigToml(mutate: (config: TomlTable) => void, options?: {
|
|
42
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
43
|
+
readonly workdir?: string;
|
|
44
|
+
}): Promise<SaveUserConfigResult>;
|
|
45
|
+
export declare function syncUserConfigDefaults(patch: UserConfigDefaultsPatch, options?: {
|
|
46
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
47
|
+
readonly workdir?: string;
|
|
48
|
+
}): Promise<SaveUserConfigResult>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { access, chmod, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { parse, stringify } from 'smol-toml';
|
|
3
|
+
import { saturnHomeDir, userAuthCredentialsPath, userConfigPath, userCredentialsPath, userEnvPath, workspaceConfigPath, workspaceEnvPath, } from '@saturn-universe/protocol';
|
|
4
|
+
import { atomicWriteText } from './config-file.js';
|
|
5
|
+
import { withUserConfigLock } from './config-lock.js';
|
|
6
|
+
const STARTER_CONFIG_TOML = `version = 1
|
|
7
|
+
default_profile = "openai/gpt-4.1"
|
|
8
|
+
workspace_tools = true
|
|
9
|
+
|
|
10
|
+
[run_defaults]
|
|
11
|
+
permission_mode = "default"
|
|
12
|
+
# mode_ref = "default@1"
|
|
13
|
+
# max_total_tokens = 0 # Default 0 means no hard total-token cap; set a positive integer to enforce a Run token budget
|
|
14
|
+
model_timeout_ms = 120000
|
|
15
|
+
# subagent_wall_time_ms = 900000 # Subagents/workers are time-limited; main agent has no wall-clock limit by default
|
|
16
|
+
# reasoning_effort = "high" # Applied automatically when the selected profile enables reasoningModel = true
|
|
17
|
+
# worker_reasoning_effort = "medium"
|
|
18
|
+
|
|
19
|
+
# Run \`saturn provider add\` to discover models and save credentials.
|
|
20
|
+
[providers.openai]
|
|
21
|
+
base_url = "https://api.openai.com/v1"
|
|
22
|
+
protocol = "openai-responses"
|
|
23
|
+
credential_ref = "env:SATURN_PROVIDER_OPENAI_API_KEY"
|
|
24
|
+
models = ["gpt-4.1"]
|
|
25
|
+
|
|
26
|
+
# Example team preset (use with \`/team --preset review <task>\` or \`--team-preset review\`):
|
|
27
|
+
# [team_presets.review]
|
|
28
|
+
# concurrency = 2
|
|
29
|
+
#
|
|
30
|
+
# [[team_presets.review.members]]
|
|
31
|
+
# id = "reviewer"
|
|
32
|
+
# parent = "main"
|
|
33
|
+
# task = "Review the workspace for: {{prompt}}"
|
|
34
|
+
`;
|
|
35
|
+
const STARTER_CREDENTIALS_TOML = `version = 1
|
|
36
|
+
|
|
37
|
+
[credentials]
|
|
38
|
+
SATURN_PROVIDER_OPENAI_API_KEY = ""
|
|
39
|
+
# SATURN_CUSTOM_API_KEY = ""
|
|
40
|
+
`;
|
|
41
|
+
async function fileExists(target) {
|
|
42
|
+
try {
|
|
43
|
+
await access(target);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function inspectUserConfig(workdir, env = process.env) {
|
|
51
|
+
const saturnHome = saturnHomeDir(env);
|
|
52
|
+
const paths = {
|
|
53
|
+
workspaceConfig: workspaceConfigPath(workdir),
|
|
54
|
+
userConfig: userConfigPath(env),
|
|
55
|
+
userCredentials: userCredentialsPath(env),
|
|
56
|
+
authCredentials: userAuthCredentialsPath(env),
|
|
57
|
+
userEnv: userEnvPath(env),
|
|
58
|
+
workspaceEnv: workspaceEnvPath(workdir),
|
|
59
|
+
};
|
|
60
|
+
const [workspaceConfig, userConfig, userCredentials, userEnv, workspaceEnv, authCredentials] = await Promise.all([
|
|
61
|
+
fileExists(paths.workspaceConfig),
|
|
62
|
+
fileExists(paths.userConfig),
|
|
63
|
+
fileExists(paths.userCredentials),
|
|
64
|
+
fileExists(paths.userEnv),
|
|
65
|
+
fileExists(paths.workspaceEnv),
|
|
66
|
+
fileExists(paths.authCredentials),
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
saturnHome,
|
|
70
|
+
workdir,
|
|
71
|
+
files: {
|
|
72
|
+
workspaceConfig: { path: paths.workspaceConfig, exists: workspaceConfig },
|
|
73
|
+
userConfig: { path: paths.userConfig, exists: userConfig },
|
|
74
|
+
userCredentials: { path: paths.userCredentials, exists: userCredentials },
|
|
75
|
+
userEnv: { path: paths.userEnv, exists: userEnv },
|
|
76
|
+
workspaceEnv: { path: paths.workspaceEnv, exists: workspaceEnv },
|
|
77
|
+
authCredentials: { path: paths.authCredentials, exists: authCredentials },
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async function writeStarterFile(target, content, force, mode) {
|
|
82
|
+
try {
|
|
83
|
+
await writeFile(target, content, { encoding: 'utf8', flag: force ? 'w' : 'wx' });
|
|
84
|
+
if (process.platform !== 'win32' && mode !== undefined)
|
|
85
|
+
await chmod(target, mode);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (!force && error.code === 'EEXIST')
|
|
90
|
+
return false;
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export async function initUserConfig(force = false, env = process.env) {
|
|
95
|
+
return withUserConfigLock({ env }, async () => {
|
|
96
|
+
const saturnHome = saturnHomeDir(env);
|
|
97
|
+
if (process.platform !== 'win32')
|
|
98
|
+
await chmod(saturnHome, 0o700);
|
|
99
|
+
const configPath = userConfigPath(env);
|
|
100
|
+
const credentialsPath = userCredentialsPath(env);
|
|
101
|
+
const configCreated = await writeStarterFile(configPath, STARTER_CONFIG_TOML, force);
|
|
102
|
+
const credentialsCreated = await writeStarterFile(credentialsPath, STARTER_CREDENTIALS_TOML, force, 0o600);
|
|
103
|
+
return {
|
|
104
|
+
saturnHome,
|
|
105
|
+
configPath,
|
|
106
|
+
credentialsPath,
|
|
107
|
+
configCreated,
|
|
108
|
+
credentialsCreated,
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function asTomlTable(value, label) {
|
|
113
|
+
if (value === undefined)
|
|
114
|
+
return {};
|
|
115
|
+
if (value &&
|
|
116
|
+
typeof value === 'object' &&
|
|
117
|
+
!Array.isArray(value) &&
|
|
118
|
+
[null, Object.prototype].includes(Object.getPrototypeOf(value))) {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`Invalid TOML table for ${label}`);
|
|
122
|
+
}
|
|
123
|
+
export async function updateUserConfigToml(mutate, options = {}) {
|
|
124
|
+
const env = options.env ?? process.env;
|
|
125
|
+
const configPath = userConfigPath(env);
|
|
126
|
+
const workspacePath = options.workdir ? workspaceConfigPath(options.workdir) : undefined;
|
|
127
|
+
const workspaceConfigOverrides = workspacePath ? await fileExists(workspacePath) : false;
|
|
128
|
+
return withUserConfigLock({ env }, async () => {
|
|
129
|
+
let created = false;
|
|
130
|
+
let existingText;
|
|
131
|
+
try {
|
|
132
|
+
existingText = await readFile(configPath, 'utf8');
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code !== 'ENOENT')
|
|
136
|
+
throw error;
|
|
137
|
+
created = true;
|
|
138
|
+
}
|
|
139
|
+
const parsed = parse(existingText ?? STARTER_CONFIG_TOML);
|
|
140
|
+
if (parsed.version !== undefined && parsed.version !== 1) {
|
|
141
|
+
throw new Error('Unsupported config.toml version');
|
|
142
|
+
}
|
|
143
|
+
const config = { version: 1, ...parsed };
|
|
144
|
+
mutate(config);
|
|
145
|
+
const nextToml = stringify(config);
|
|
146
|
+
parse(nextToml);
|
|
147
|
+
await atomicWriteText(configPath, nextToml, 0o600);
|
|
148
|
+
return {
|
|
149
|
+
configPath,
|
|
150
|
+
created,
|
|
151
|
+
workspaceConfigOverrides,
|
|
152
|
+
...(workspaceConfigOverrides && workspacePath ? { workspaceConfigPath: workspacePath } : {}),
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function patchOptionalString(target, key, value) {
|
|
157
|
+
if (value === undefined)
|
|
158
|
+
return;
|
|
159
|
+
if (value === null) {
|
|
160
|
+
delete target[key];
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
target[key] = value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export async function syncUserConfigDefaults(patch, options = {}) {
|
|
167
|
+
return updateUserConfigToml((config) => {
|
|
168
|
+
patchOptionalString(config, 'default_profile', patch.defaultProfile);
|
|
169
|
+
const hasRunDefaultPatch = patch.permissionMode !== undefined ||
|
|
170
|
+
patch.reasoningEffort !== undefined ||
|
|
171
|
+
patch.workerReasoningEffort !== undefined ||
|
|
172
|
+
patch.modeRef !== undefined;
|
|
173
|
+
if (!hasRunDefaultPatch)
|
|
174
|
+
return;
|
|
175
|
+
const hadRunDefaults = Object.hasOwn(config, 'run_defaults') && config.run_defaults !== undefined;
|
|
176
|
+
const runDefaults = { ...asTomlTable(config.run_defaults, 'run_defaults') };
|
|
177
|
+
patchOptionalString(runDefaults, 'permission_mode', patch.permissionMode);
|
|
178
|
+
patchOptionalString(runDefaults, 'reasoning_effort', patch.reasoningEffort);
|
|
179
|
+
patchOptionalString(runDefaults, 'worker_reasoning_effort', patch.workerReasoningEffort);
|
|
180
|
+
patchOptionalString(runDefaults, 'mode_ref', patch.modeRef);
|
|
181
|
+
if (Object.keys(runDefaults).length > 0 || hadRunDefaults) {
|
|
182
|
+
config.run_defaults = runDefaults;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
delete config.run_defaults;
|
|
186
|
+
}
|
|
187
|
+
}, options);
|
|
188
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saturn-universe/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Saturn local multi-agent runtime CLI",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@saturn-universe/protocol": "0.1.1",
|
|
12
|
+
"@saturn-universe/runtime-host": "0.1.1",
|
|
13
|
+
"mdast-util-from-markdown": "^2.1.0",
|
|
14
|
+
"mdast-util-gfm": "^3.1.0",
|
|
15
|
+
"micromark-extension-gfm": "^3.0.0",
|
|
16
|
+
"smol-toml": "1.9.1"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"saturn": "./dist/index.js"
|
|
20
|
+
}
|
|
6
21
|
}
|
package/README.md
DELETED