@zergai/ztc 0.26.2-dev.202611210149 → 0.26.4-dev.202611231953
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/README.md +590 -28
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/zmux-linux-x64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-tui-linux-x64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/App.js +18 -1
- package/dist/agent/agent.d.ts +25 -1
- package/dist/agent/agent.js +26 -1
- package/dist/agent/attached_images.d.ts +58 -0
- package/dist/agent/attached_images.js +145 -0
- package/dist/agent/backends/anthropic.d.ts +14 -0
- package/dist/agent/backends/anthropic.js +49 -2
- package/dist/agent/backends/codex_app_server.d.ts +3 -1
- package/dist/agent/backends/codex_app_server.js +9 -6
- package/dist/agent/backends/codex_auth.js +3 -0
- package/dist/agent/backends/gemini.js +3 -0
- package/dist/agent/backends/host_effort_policy.js +14 -2
- package/dist/agent/backends/http_error.d.ts +17 -0
- package/dist/agent/backends/http_error.js +50 -1
- package/dist/agent/backends/index.js +2 -1
- package/dist/agent/backends/model_redirect.d.ts +47 -0
- package/dist/agent/backends/model_redirect.js +97 -0
- package/dist/agent/backends/openai_compatible.js +5 -0
- package/dist/agent/backends/openai_responses.d.ts +9 -1
- package/dist/agent/backends/openai_responses.js +21 -12
- package/dist/agent/backends/prompt_cache.d.ts +8 -0
- package/dist/agent/backends/prompt_cache.js +10 -0
- package/dist/agent/backends/provider_ids.d.ts +1 -1
- package/dist/agent/backends/provider_ids.js +1 -1
- package/dist/agent/backends/types.d.ts +8 -0
- package/dist/agent/backends/zerg-api.js +5 -1
- package/dist/agent/backends/zrouter_stream.d.ts +75 -9
- package/dist/agent/backends/zrouter_stream.js +250 -49
- package/dist/agent/commands/config.js +51 -4
- package/dist/agent/commands/connect.js +20 -0
- package/dist/agent/commands/credential_status.js +5 -3
- package/dist/agent/commands/debug.js +3 -0
- package/dist/agent/commands/diff.js +9 -5
- package/dist/agent/commands/emulation.js +7 -1
- package/dist/agent/commands/inbox.js +4 -3
- package/dist/agent/commands/mcp.js +3 -0
- package/dist/agent/commands/models.js +20 -3
- package/dist/agent/commands/permissions.js +16 -2
- package/dist/agent/commands/provider_selection.js +13 -6
- package/dist/agent/commands/settings.js +15 -4
- package/dist/agent/commands/status.js +23 -1
- package/dist/agent/commands/types.d.ts +34 -3
- package/dist/agent/commands/update.d.ts +2 -1
- package/dist/agent/commands/update.js +8 -3
- package/dist/agent/commands/zerg.d.ts +6 -0
- package/dist/agent/commands/zerg.js +152 -28
- package/dist/agent/commands/ztc_pane.js +8 -5
- package/dist/agent/factory.js +22 -4
- package/dist/agent/request_encoder.js +11 -2
- package/dist/agent/runtime/command_jobs.js +16 -1
- package/dist/agent/runtime/command_panes.js +4 -1
- package/dist/agent/runtime/execution_context.d.ts +8 -1
- package/dist/agent/runtime/execution_context.js +8 -2
- package/dist/agent/runtime/policy.d.ts +66 -5
- package/dist/agent/runtime/policy.js +161 -33
- package/dist/agent/runtime/remote_broker_transport.d.ts +7 -0
- package/dist/agent/runtime/remote_broker_transport.js +33 -3
- package/dist/agent/runtime/remote_resource_errors.d.ts +7 -0
- package/dist/agent/runtime/remote_resource_errors.js +10 -0
- package/dist/agent/runtime/remote_resources.d.ts +1 -1
- package/dist/agent/runtime/remote_resources.js +7 -3
- package/dist/agent/runtime/source_verification.js +15 -12
- package/dist/agent/runtime/tool_runtime.js +165 -58
- package/dist/agent/runtime/verifier_capture.d.ts +1 -1
- package/dist/agent/runtime/verifier_capture.js +6 -0
- package/dist/agent/runtime/work_base.js +46 -14
- package/dist/agent/tools/adaptation.js +29 -12
- package/dist/agent/tools/apply_patch.js +62 -5
- package/dist/agent/tools/background.js +2 -0
- package/dist/agent/tools/benchmark_cpu.js +2 -0
- package/dist/agent/tools/bus_message.d.ts +4 -2
- package/dist/agent/tools/bus_message.js +21 -3
- package/dist/agent/tools/delegate.js +2 -0
- package/dist/agent/tools/file.d.ts +12 -1
- package/dist/agent/tools/file.js +92 -11
- package/dist/agent/tools/lsp.d.ts +12 -0
- package/dist/agent/tools/lsp.js +61 -5
- package/dist/agent/tools/pane.js +20 -45
- package/dist/agent/tools/project_context.js +5 -2
- package/dist/agent/tools/routine.js +20 -4
- package/dist/agent/tools/screenshot.d.ts +8 -0
- package/dist/agent/tools/screenshot.js +39 -25
- package/dist/agent/tools/search.js +31 -3
- package/dist/agent/tools/shell.js +7 -1
- package/dist/agent/tools/supervision.js +6 -0
- package/dist/agent/tools/types.d.ts +18 -0
- package/dist/agent/tools/zerg.js +15 -19
- package/dist/agent/tools/ztc_command.d.ts +15 -4
- package/dist/agent/tools/ztc_command.js +48 -34
- package/dist/app/agent_runner.js +8 -6
- package/dist/app/conversation_compaction.d.ts +6 -3
- package/dist/app/conversation_compaction.js +6 -3
- package/dist/app/tool_callbacks.js +1 -0
- package/dist/audio/sfx.js +6 -0
- package/dist/batch/worktree.js +22 -10
- package/dist/board/client.js +2 -1
- package/dist/cli_main.d.ts +1 -0
- package/dist/cli_main.js +141 -45
- package/dist/cli_ratatui.d.ts +49 -4
- package/dist/cli_ratatui.js +355 -79
- package/dist/conductor_branch.js +4 -1
- package/dist/config/host_credentials.d.ts +157 -0
- package/dist/config/host_credentials.js +589 -0
- package/dist/config/model_pin.d.ts +111 -0
- package/dist/config/model_pin.js +182 -0
- package/dist/config/own_state_files.d.ts +35 -0
- package/dist/config/own_state_files.js +161 -0
- package/dist/config/permission_pin.d.ts +148 -0
- package/dist/config/permission_pin.js +203 -0
- package/dist/config/permissions.d.ts +9 -2
- package/dist/config/permissions.js +14 -3
- package/dist/config/platform_login.d.ts +72 -0
- package/dist/config/platform_login.js +111 -0
- package/dist/config/profile_limits.d.ts +34 -0
- package/dist/config/profile_limits.js +66 -0
- package/dist/config/provider_api_key_env.js +3 -2
- package/dist/config/provider_models.d.ts +6 -1
- package/dist/config/provider_models.js +38 -11
- package/dist/config/repo_config.d.ts +22 -0
- package/dist/config/repo_config.js +77 -3
- package/dist/config/router_runtime_grant.d.ts +53 -0
- package/dist/config/router_runtime_grant.js +131 -0
- package/dist/config/settings_merge.d.ts +22 -0
- package/dist/config/settings_merge.js +75 -0
- package/dist/config/types.d.ts +8 -0
- package/dist/config.d.ts +334 -4
- package/dist/config.js +1024 -41
- package/dist/context/project_intelligence.d.ts +11 -2
- package/dist/context/project_intelligence.js +38 -15
- package/dist/desktop/daily/desktop_wiring.js +8 -6
- package/dist/desktop/daily/native_pane_launcher.js +2 -1
- package/dist/desktop/daily/native_tool.d.ts +1 -1
- package/dist/desktop/daily/native_tool.js +4 -3
- package/dist/desktop/daily/process_identity.js +10 -2
- package/dist/desktop/daily/source_baseline.js +4 -3
- package/dist/diagnostics/native_terminal_benchmark.js +3 -2
- package/dist/diagnostics/session_export.js +27 -14
- package/dist/embedded/anempa_runtime.js +3 -3
- package/dist/embedded/gameboy_runtime.js +5 -4
- package/dist/embedded/zergpod_runtime.js +5 -4
- package/dist/emulation/catalog.js +6 -1
- package/dist/emulation/tool_adapters.js +13 -3
- package/dist/environment/store.js +5 -4
- package/dist/extension_discovery.d.ts +12 -2
- package/dist/extension_discovery.js +52 -7
- package/dist/headless.d.ts +8 -0
- package/dist/headless.js +52 -13
- package/dist/headless_cli.js +16 -1
- package/dist/headless_workflow_trigger.js +1 -1
- package/dist/hooks/dispatcher.d.ts +8 -0
- package/dist/hooks/dispatcher.js +22 -2
- package/dist/hooks/lifecycle.d.ts +6 -0
- package/dist/hooks/lifecycle.js +1 -0
- package/dist/hooks/program_files.d.ts +10 -0
- package/dist/hooks/program_files.js +175 -0
- package/dist/hooks/runner.d.ts +11 -1
- package/dist/hooks/runner.js +112 -11
- package/dist/hooks/types.d.ts +2 -0
- package/dist/host_credentials_startup.d.ts +6 -0
- package/dist/host_credentials_startup.js +17 -0
- package/dist/instance_registry.d.ts +6 -2
- package/dist/instance_registry.js +9 -15
- package/dist/intake/format.d.ts +6 -0
- package/dist/intake/format.js +9 -0
- package/dist/intake/notifications.js +2 -1
- package/dist/lsp/manager.d.ts +1 -1
- package/dist/lsp/manager.js +4 -5
- package/dist/mcp/client.d.ts +2 -0
- package/dist/mcp/client.js +116 -18
- package/dist/mcp/registry.d.ts +12 -0
- package/dist/mcp/registry.js +15 -1
- package/dist/modes/handlers.js +14 -5
- package/dist/panes/agent_cli.d.ts +23 -1
- package/dist/panes/agent_cli.js +96 -1
- package/dist/panes/agent_panes.d.ts +27 -4
- package/dist/panes/agent_panes.js +73 -11
- package/dist/panes/editor_program.d.ts +8 -0
- package/dist/panes/editor_program.js +25 -0
- package/dist/panes/motsi.d.ts +11 -1
- package/dist/panes/motsi.js +14 -1
- package/dist/panes/pane_registry.d.ts +28 -1
- package/dist/panes/pane_registry.js +25 -0
- package/dist/panes/worker_route.js +5 -3
- package/dist/panes/ztc_launch.d.ts +8 -0
- package/dist/panes/ztc_launch.js +26 -1
- package/dist/profile_baseline.js +2 -0
- package/dist/router_auth.d.ts +8 -3
- package/dist/router_auth.js +34 -2
- package/dist/runtime_info.js +56 -38
- package/dist/session.js +12 -2
- package/dist/shannon/runtime.js +13 -1
- package/dist/simulation/domains/loader.d.ts +2 -1
- package/dist/simulation/domains/loader.js +19 -2
- package/dist/simulation/living/context.d.ts +8 -8
- package/dist/simulation/living/types.d.ts +2 -2
- package/dist/simulation/memory/embedding.d.ts +2 -1
- package/dist/simulation/memory/embedding.js +25 -6
- package/dist/terminal_attach.js +2 -1
- package/dist/types.d.ts +21 -0
- package/dist/ui/ratatui/headless_pane_manager.d.ts +12 -6
- package/dist/ui/ratatui/headless_pane_manager.js +65 -21
- package/dist/ui/ratatui/ipc_path.d.ts +41 -2
- package/dist/ui/ratatui/ipc_path.js +164 -5
- package/dist/ui/ratatui/pane_credential_broker.d.ts +17 -4
- package/dist/ui/ratatui/pane_credential_broker.js +23 -5
- package/dist/ui/ratatui/pane_relay.d.ts +74 -0
- package/dist/ui/ratatui/pane_relay.js +188 -13
- package/dist/ui/ratatui/process.d.ts +15 -1
- package/dist/ui/ratatui/process.js +129 -163
- package/dist/ui/ratatui/protocol.d.ts +11 -1
- package/dist/ui/ratatui/protocol.js +6 -0
- package/dist/ui/ratatui/ztc_launch_trust.d.ts +87 -0
- package/dist/ui/ratatui/ztc_launch_trust.js +249 -0
- package/dist/utils/admitted_open.d.ts +40 -0
- package/dist/utils/admitted_open.js +111 -0
- package/dist/utils/clipboard.js +2 -1
- package/dist/utils/computer_native.js +12 -56
- package/dist/utils/dictation.js +15 -12
- package/dist/utils/dictation_native.js +17 -60
- package/dist/utils/git_probe_options.d.ts +28 -0
- package/dist/utils/git_probe_options.js +30 -0
- package/dist/utils/git_program_files.d.ts +145 -0
- package/dist/utils/git_program_files.js +1282 -0
- package/dist/utils/git_repository_programs.d.ts +13 -0
- package/dist/utils/git_repository_programs.js +38 -0
- package/dist/utils/host_shell.js +2 -1
- package/dist/utils/idle_compaction.js +8 -1
- package/dist/utils/image_fit.d.ts +4 -1
- package/dist/utils/image_fit.js +6 -2
- package/dist/utils/image_preview.js +3 -2
- package/dist/utils/mirror_media.d.ts +22 -4
- package/dist/utils/mirror_media.js +87 -86
- package/dist/utils/ml_native.js +11 -56
- package/dist/utils/native_install.d.ts +55 -0
- package/dist/utils/native_install.js +107 -0
- package/dist/utils/open_url.js +2 -0
- package/dist/utils/process_end.d.ts +16 -0
- package/dist/utils/process_end.js +73 -0
- package/dist/utils/router_catalog.js +9 -2
- package/dist/utils/sandbox.d.ts +64 -1
- package/dist/utils/sandbox.js +397 -89
- package/dist/utils/shell.js +31 -12
- package/dist/utils/subprocess_env.d.ts +218 -2
- package/dist/utils/subprocess_env.js +429 -11
- package/dist/utils/system_ps.d.ts +5 -0
- package/dist/utils/system_ps.js +30 -0
- package/dist/utils/tts.js +5 -0
- package/dist/utils/tts_native.js +13 -60
- package/dist/utils/zlicky_overlay.js +17 -50
- package/dist/utils/ztc_own_state.d.ts +58 -0
- package/dist/utils/ztc_own_state.js +236 -0
- package/dist/web/mirror_authenticator.d.ts +67 -6
- package/dist/web/mirror_authenticator.js +131 -22
- package/dist/web/mirror_stream.d.ts +54 -10
- package/dist/web/mirror_stream.js +379 -92
- package/dist/web/observer_query_redaction.js +53 -13
- package/dist/web/observer_secret_redaction.d.ts +59 -0
- package/dist/web/observer_secret_redaction.js +714 -0
- package/dist/web/pane_credentials.d.ts +20 -2
- package/dist/web/pane_credentials.js +58 -5
- package/dist/worker/executor.js +3 -1
- package/dist/workspace_collision.js +19 -15
- package/dist/zerg/local_zerg_launches.d.ts +27 -0
- package/dist/zerg/local_zerg_launches.js +198 -0
- package/dist/zlm-embed.mjs +6257 -2791
- package/npm-shrinkwrap.json +1 -1
- package/package.json +42 -15
package/dist/utils/tts_native.js
CHANGED
|
@@ -6,70 +6,18 @@
|
|
|
6
6
|
* - Metal GPU acceleration on macOS
|
|
7
7
|
*/
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
|
-
import {
|
|
9
|
+
import { appendFileSync } from 'fs';
|
|
10
10
|
import { createInterface } from 'readline';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { fileURLToPath } from 'url';
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = dirname(__filename);
|
|
11
|
+
import { findNativeProgram, nativeProgramBuildCommand } from './native_install.js';
|
|
12
|
+
import { buildNativeHelperEnv } from './subprocess_env.js';
|
|
16
13
|
let activeProcess = null;
|
|
17
14
|
let eventHandlers = [];
|
|
18
15
|
/**
|
|
19
|
-
* Get the
|
|
20
|
-
|
|
21
|
-
function getBinaryName() {
|
|
22
|
-
const p = platform();
|
|
23
|
-
const a = arch();
|
|
24
|
-
let os;
|
|
25
|
-
switch (p) {
|
|
26
|
-
case 'darwin':
|
|
27
|
-
os = 'darwin';
|
|
28
|
-
break;
|
|
29
|
-
case 'linux':
|
|
30
|
-
os = 'linux';
|
|
31
|
-
break;
|
|
32
|
-
case 'win32':
|
|
33
|
-
os = 'win';
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
os = p;
|
|
37
|
-
}
|
|
38
|
-
let cpu;
|
|
39
|
-
switch (a) {
|
|
40
|
-
case 'x64':
|
|
41
|
-
cpu = 'x64';
|
|
42
|
-
break;
|
|
43
|
-
case 'arm64':
|
|
44
|
-
cpu = 'arm64';
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
cpu = a;
|
|
48
|
-
}
|
|
49
|
-
const ext = p === 'win32' ? '.exe' : '';
|
|
50
|
-
return `ztc-tts-${os}-${cpu}${ext}`;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get the path to the ztc-tts binary
|
|
16
|
+
* Get the path to the ztc-tts binary, from ZTC's own install only (native_install.ts findNativeProgram): the package's
|
|
17
|
+
* bin/, then a source checkout's cargo build under the package. Never the working directory or ~/.ztc/bin.
|
|
54
18
|
*/
|
|
55
19
|
function getBinaryPath() {
|
|
56
|
-
|
|
57
|
-
const possiblePaths = [
|
|
58
|
-
// Installed via npm (relative to this file in dist/utils/)
|
|
59
|
-
join(__dirname, '..', '..', 'bin', binaryName),
|
|
60
|
-
// Development: Rust build output
|
|
61
|
-
join(process.cwd(), 'packages', 'ztc-tts', 'target', 'release', 'ztc-tts'),
|
|
62
|
-
// Development: bin directory (for local testing)
|
|
63
|
-
join(process.cwd(), 'bin', binaryName),
|
|
64
|
-
// Global install location
|
|
65
|
-
join(homedir(), '.ztc', 'bin', binaryName),
|
|
66
|
-
];
|
|
67
|
-
for (const p of possiblePaths) {
|
|
68
|
-
if (existsSync(p)) {
|
|
69
|
-
return p;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
20
|
+
return findNativeProgram('ztc-tts');
|
|
73
21
|
}
|
|
74
22
|
/**
|
|
75
23
|
* Check if native TTS is available
|
|
@@ -113,6 +61,7 @@ export async function checkModelStatus(model = 'mini') {
|
|
|
113
61
|
return new Promise((resolve, reject) => {
|
|
114
62
|
const proc = spawn(binaryPath, ['--check-model', '--model', model], {
|
|
115
63
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
64
|
+
env: buildNativeHelperEnv(),
|
|
116
65
|
});
|
|
117
66
|
const rl = createInterface({
|
|
118
67
|
input: proc.stdout,
|
|
@@ -153,6 +102,7 @@ export async function downloadModel(model = 'mini', onProgress) {
|
|
|
153
102
|
return new Promise((resolve, reject) => {
|
|
154
103
|
const proc = spawn(binaryPath, ['--download-model', '--model', model], {
|
|
155
104
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
105
|
+
env: buildNativeHelperEnv(),
|
|
156
106
|
});
|
|
157
107
|
const rl = createInterface({
|
|
158
108
|
input: proc.stdout,
|
|
@@ -217,6 +167,7 @@ export async function speakText(text, options = {}) {
|
|
|
217
167
|
const proc = spawn(binaryPath, args, {
|
|
218
168
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
219
169
|
detached: false,
|
|
170
|
+
env: buildNativeHelperEnv(),
|
|
220
171
|
});
|
|
221
172
|
const rl = createInterface({
|
|
222
173
|
input: proc.stdout,
|
|
@@ -272,7 +223,7 @@ export function startTTSServer(options = {}) {
|
|
|
272
223
|
if (!binaryPath) {
|
|
273
224
|
emit({
|
|
274
225
|
type: 'error',
|
|
275
|
-
message:
|
|
226
|
+
message: `ztc-tts binary not found. Build with: ${nativeProgramBuildCommand('ztc-tts')}`
|
|
276
227
|
});
|
|
277
228
|
return false;
|
|
278
229
|
}
|
|
@@ -286,6 +237,8 @@ export function startTTSServer(options = {}) {
|
|
|
286
237
|
try {
|
|
287
238
|
activeProcess = spawn(binaryPath, args, {
|
|
288
239
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
240
|
+
// The person's environment, none of ZTC's or its route's credentials: the player it starts gets the same.
|
|
241
|
+
env: buildNativeHelperEnv(),
|
|
289
242
|
});
|
|
290
243
|
const rl = createInterface({
|
|
291
244
|
input: activeProcess.stdout,
|
|
@@ -385,7 +338,7 @@ export function getTTSStatus() {
|
|
|
385
338
|
}
|
|
386
339
|
else {
|
|
387
340
|
parts.push('TTS: not available');
|
|
388
|
-
parts.push(
|
|
341
|
+
parts.push(`Build with: ${nativeProgramBuildCommand('ztc-tts')}`);
|
|
389
342
|
}
|
|
390
343
|
if (isTTSActive()) {
|
|
391
344
|
parts.push('\nTTS server is running');
|
|
@@ -7,39 +7,9 @@
|
|
|
7
7
|
import { spawn } from 'child_process';
|
|
8
8
|
import { existsSync } from 'fs';
|
|
9
9
|
import { createInterface } from 'readline';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
-
const __dirname = dirname(__filename);
|
|
15
|
-
function normalizedPlatform() {
|
|
16
|
-
switch (platform()) {
|
|
17
|
-
case 'darwin':
|
|
18
|
-
return 'darwin';
|
|
19
|
-
case 'linux':
|
|
20
|
-
return 'linux';
|
|
21
|
-
case 'win32':
|
|
22
|
-
return 'win';
|
|
23
|
-
default:
|
|
24
|
-
return platform();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function normalizedArch() {
|
|
28
|
-
switch (arch()) {
|
|
29
|
-
case 'x64':
|
|
30
|
-
return 'x64';
|
|
31
|
-
case 'arm64':
|
|
32
|
-
return 'arm64';
|
|
33
|
-
default:
|
|
34
|
-
return arch();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function overlayBinaryName() {
|
|
38
|
-
return `ztc-zlicky-overlay-${normalizedPlatform()}-${normalizedArch()}`;
|
|
39
|
-
}
|
|
40
|
-
function overlaySourcePath() {
|
|
41
|
-
return join(__dirname, '..', '..', 'native', 'zlicky-overlay', 'main.swift');
|
|
42
|
-
}
|
|
10
|
+
import { platform } from 'os';
|
|
11
|
+
import { findNativeProgram, zlickyOverlaySource } from './native_install.js';
|
|
12
|
+
import { buildNativeHelperEnv } from './subprocess_env.js';
|
|
43
13
|
function findOverlayLaunch() {
|
|
44
14
|
if (process.env.ZTC_ZLICKY_DISABLE_NATIVE_OVERLAY === '1') {
|
|
45
15
|
return null;
|
|
@@ -47,24 +17,19 @@ function findOverlayLaunch() {
|
|
|
47
17
|
if (platform() !== 'darwin') {
|
|
48
18
|
return null;
|
|
49
19
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
command: binaryPath,
|
|
61
|
-
args: [],
|
|
62
|
-
description: binaryPath,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
20
|
+
// From ZTC's own install only (native_install.ts findNativeProgram): the package's bin/, then a source checkout's build
|
|
21
|
+
// of the overlay. Never the working directory or ~/.ztc/bin.
|
|
22
|
+
const binaryPath = findNativeProgram('ztc-zlicky-overlay');
|
|
23
|
+
if (binaryPath) {
|
|
24
|
+
return {
|
|
25
|
+
command: binaryPath,
|
|
26
|
+
args: [],
|
|
27
|
+
description: binaryPath,
|
|
28
|
+
};
|
|
65
29
|
}
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
// A source checkout's main.swift where it has no build; a packed install ships none (native_install.ts).
|
|
31
|
+
const sourcePath = zlickyOverlaySource();
|
|
32
|
+
if (sourcePath && existsSync('/usr/bin/swift')) {
|
|
68
33
|
return {
|
|
69
34
|
command: '/usr/bin/swift',
|
|
70
35
|
args: [sourcePath],
|
|
@@ -124,6 +89,8 @@ export class ZlickyOverlayNative {
|
|
|
124
89
|
try {
|
|
125
90
|
this.process = spawn(launch.command, launch.args, {
|
|
126
91
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
92
|
+
// The person's environment, none of ZTC's or its route's credentials.
|
|
93
|
+
env: buildNativeHelperEnv(),
|
|
127
94
|
});
|
|
128
95
|
this.launchDescription = launch.description;
|
|
129
96
|
this.readline = createInterface({
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ZTCPermissionProfile, ZTCSandboxSettings } from '../config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The folders that hold ZTC's own state, absolute, each as named and as it really is: ~/.ztc, the active profile's
|
|
4
|
+
* config folder, and ZTC_CONFIG_DIR, ZTC_SESSIONS_DIR and ZTC_WORKSPACE_LAYOUT_DIR where they are set.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ztcOwnStateRoots(): string[];
|
|
7
|
+
/** The temp folders ZTC's runtime keeps its entries in: this process's, and /tmp, each as named and as it really is. */
|
|
8
|
+
export declare function ztcRuntimeTempFolders(): string[];
|
|
9
|
+
/** The entries of ZTC's runtime in those temp folders now, absolute: what a sandbox that binds paths hides one by one. */
|
|
10
|
+
export declare function ztcRuntimeEntries(): string[];
|
|
11
|
+
/** Regular expressions, as Seatbelt reads them, for every entry of ZTC's runtime in those temp folders, now or later. */
|
|
12
|
+
export declare function ztcRuntimeSeatbeltPatterns(): string[];
|
|
13
|
+
/**
|
|
14
|
+
* The part of ZTC's own state that holds PATH (absolute), as named or as it really is: one of ztcOwnStateRoots, or an
|
|
15
|
+
* entry of ZTC's runtime in a temp folder; null when it is in none. Every spelling that can name the same file counts
|
|
16
|
+
* (sameFileKey), as a denial does.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ztcOwnStateHolding(path: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* The folders of ZTC's own state that ZTC reads the person's skills from (skills/loader.ts defaultMarkdownRoots: the
|
|
21
|
+
* user skills folder ~/.ztc/skills, where discovery is not explicit), each as named and as it really is. A skill's SKILL.md
|
|
22
|
+
* tells the agent to read the files beside it, which are the person's instructions and scripts, so under a profile that
|
|
23
|
+
* limits the agent they stay readable (ztcOwnStateHoldingForRead, and the OS sandbox's reads), and, as the rest of
|
|
24
|
+
* ZTC's own state, never writable: no agent plants a skill. A discovery setting that can't be read names none.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ztcOwnSkillRoots(): string[];
|
|
27
|
+
/**
|
|
28
|
+
* ztcOwnStateHolding for a call that only reads PATH: null too where each spelling of PATH that lies in ZTC's own state
|
|
29
|
+
* is inside a skills folder of ZTC's own (ztcOwnSkillRoots). A skill linked there from a folder of the person's reads
|
|
30
|
+
* through its name, as its target does; a link there that leads into the rest of ZTC's own state is still refused.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ztcOwnStateHoldingForRead(path: string): string | null;
|
|
33
|
+
/** Which file a path or descriptor is, as stat and fstat say, and how many names it has. */
|
|
34
|
+
export interface FileIdentity {
|
|
35
|
+
dev: number;
|
|
36
|
+
ino: number;
|
|
37
|
+
nlink: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A check, for one call of a tool, of whether a file is one of ZTC's own under another name: a hard link gives a file
|
|
41
|
+
* of ZTC's own state (its config, hook approvals, a session, a hand-off) a name in the workspace, which no check of a
|
|
42
|
+
* path sees. It gives the part of ZTC's own state that holds FILE (its identity, from the descriptor a tool opened),
|
|
43
|
+
* or null. A file with one name cannot be one and costs nothing; for the first file with more, ZTC's own folders and
|
|
44
|
+
* its runtime's entries are walked, once, for their files of the same device and inode.
|
|
45
|
+
*/
|
|
46
|
+
export declare function ztcOwnStateLinkCheck(): (file: FileIdentity) => Promise<string | null>;
|
|
47
|
+
/**
|
|
48
|
+
* ztcOwnStateLinkCheck for a reader of files the agent names outside the file tools, which reads them in ZTC's own
|
|
49
|
+
* process: the project-context index (index_project_context, query_project_context) and the host verifiers' inputs
|
|
50
|
+
* (verify_artifact, benchmark_cpu). Under POLICY, the agent's command policy, where its profile limits the agent;
|
|
51
|
+
* undefined elsewhere, where they read as before (as the file tools' openAdmission).
|
|
52
|
+
*/
|
|
53
|
+
export declare function ownStateLinkGuard(policy: {
|
|
54
|
+
profile?: ZTCPermissionProfile;
|
|
55
|
+
sandbox?: ZTCSandboxSettings;
|
|
56
|
+
} | undefined): ((file: FileIdentity) => Promise<string | null>) | undefined;
|
|
57
|
+
/** What a reader that found a file to be one of ZTC's own under another name (ownStateLinkGuard) says, refusing it. */
|
|
58
|
+
export declare function ownStateLinkRefusal(path: string, holding: string): string;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZTC's own state, which no agent under a profile that limits it (config/profile_limits.ts) reaches, whatever its
|
|
3
|
+
* allowedPaths say: ZTC's config folder (the active profile's, and the ZTC_CONFIG_DIR root), ~/.ztc (sessions, hook
|
|
4
|
+
* approvals, caches, tool responses), a sessions or layouts folder the environment moves elsewhere, and the entries of
|
|
5
|
+
* ZTC's runtime in a temp folder: the pane relay's endpoint and the pane-credential, host-credential and pane-input
|
|
6
|
+
* hand-offs. A hosted resident runs every process as root, so the path policy (agent/runtime/policy.ts) and the OS
|
|
7
|
+
* sandbox (utils/sandbox.ts) are what keep an agent from writing a hook and its approval, an MCP server or a looser
|
|
8
|
+
* profile there, or from reading a credential ZTC handed over. The file tools refuse these paths by name, and a file
|
|
9
|
+
* that is one of ZTC's under another name (a hard link, which no check of a path sees) by identity:
|
|
10
|
+
* ztcOwnStateLinkCheck. An OS-sandboxed command does not see them and cannot link them anywhere. Both sandboxes deny
|
|
11
|
+
* by path, so a command would still read through a link made outside the sandbox; where HOME and ZTC_CONFIG_DIR are on
|
|
12
|
+
* another filesystem than the workspace, none can exist. ZTC's own reads and writes go around both, unchanged.
|
|
13
|
+
*/
|
|
14
|
+
import { readdirSync, realpathSync } from 'node:fs';
|
|
15
|
+
import { lstat, readdir, stat } from 'node:fs/promises';
|
|
16
|
+
import { homedir, tmpdir } from 'node:os';
|
|
17
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
18
|
+
import { profileLimitsAgent } from '../config/profile_limits.js';
|
|
19
|
+
import { profileConfigDir } from '../config/profiles.js';
|
|
20
|
+
import { defaultMarkdownRoots } from '../skills/loader.js';
|
|
21
|
+
import { canonicalPath, sameFileKey } from './canonical_path.js';
|
|
22
|
+
/**
|
|
23
|
+
* The names ZTC gives its runtime's entries in a temp folder: a hand-off folder mkdtemp named (web/pane_credentials.ts,
|
|
24
|
+
* config/host_credentials.ts, panes/initial_input.ts), and a relay or renderer endpoint, a socket in a private temp
|
|
25
|
+
* folder or a folder of its own in /tmp (ui/ratatui/ipc_path.ts).
|
|
26
|
+
*/
|
|
27
|
+
const RUNTIME_ENTRY = /^ztc-(?:(?:pane-credential|host-credential|pane-input)-[a-z0-9]{6}|(?:relay|tui)-(?:[a-z0-9]{6}|\d+-\d+\.sock))$/i;
|
|
28
|
+
/** The same names as a Seatbelt regular expression, after a temp folder: it has no counted repetition, so any suffix. */
|
|
29
|
+
const RUNTIME_ENTRY_SEATBELT = 'ztc-(pane-credential|host-credential|pane-input|relay|tui)-[^/]+';
|
|
30
|
+
/** PATH as named and, where it exists, as it really is. */
|
|
31
|
+
function spellings(path) {
|
|
32
|
+
const absolute = resolve(path);
|
|
33
|
+
try {
|
|
34
|
+
const real = canonicalPath(absolute);
|
|
35
|
+
return real === absolute ? [absolute] : [absolute, real];
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return [absolute];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The folders that hold ZTC's own state, absolute, each as named and as it really is: ~/.ztc, the active profile's
|
|
43
|
+
* config folder, and ZTC_CONFIG_DIR, ZTC_SESSIONS_DIR and ZTC_WORKSPACE_LAYOUT_DIR where they are set.
|
|
44
|
+
*/
|
|
45
|
+
export function ztcOwnStateRoots() {
|
|
46
|
+
const named = [join(homedir(), '.ztc')];
|
|
47
|
+
try {
|
|
48
|
+
named.push(profileConfigDir());
|
|
49
|
+
}
|
|
50
|
+
catch { /* an invalid ZTC_PROFILE names no folder; the root below still counts */ }
|
|
51
|
+
for (const variable of ['ZTC_CONFIG_DIR', 'ZTC_SESSIONS_DIR', 'ZTC_WORKSPACE_LAYOUT_DIR']) {
|
|
52
|
+
const value = process.env[variable]?.trim();
|
|
53
|
+
if (value)
|
|
54
|
+
named.push(value);
|
|
55
|
+
}
|
|
56
|
+
return [...new Set(named.flatMap(spellings))];
|
|
57
|
+
}
|
|
58
|
+
/** The temp folders ZTC's runtime keeps its entries in: this process's, and /tmp, each as named and as it really is. */
|
|
59
|
+
export function ztcRuntimeTempFolders() {
|
|
60
|
+
const folders = [tmpdir(), ...(process.platform === 'win32' ? [] : ['/tmp'])];
|
|
61
|
+
return [...new Set(folders.flatMap(folder => {
|
|
62
|
+
const absolute = resolve(folder);
|
|
63
|
+
try {
|
|
64
|
+
return [absolute, realpathSync.native(absolute)];
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return [absolute];
|
|
68
|
+
}
|
|
69
|
+
}))];
|
|
70
|
+
}
|
|
71
|
+
/** The entries of ZTC's runtime in those temp folders now, absolute: what a sandbox that binds paths hides one by one. */
|
|
72
|
+
export function ztcRuntimeEntries() {
|
|
73
|
+
const entries = new Set();
|
|
74
|
+
for (const folder of ztcRuntimeTempFolders()) {
|
|
75
|
+
let names;
|
|
76
|
+
try {
|
|
77
|
+
names = readdirSync(folder);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
for (const name of names)
|
|
83
|
+
if (RUNTIME_ENTRY.test(name))
|
|
84
|
+
entries.add(join(folder, name));
|
|
85
|
+
}
|
|
86
|
+
return [...entries];
|
|
87
|
+
}
|
|
88
|
+
/** Regular expressions, as Seatbelt reads them, for every entry of ZTC's runtime in those temp folders, now or later. */
|
|
89
|
+
export function ztcRuntimeSeatbeltPatterns() {
|
|
90
|
+
const patterns = [];
|
|
91
|
+
for (const folder of ztcRuntimeTempFolders()) {
|
|
92
|
+
// A folder Seatbelt's raw string cannot hold is never one ZTC's own temp folder is in practice; it gets no pattern.
|
|
93
|
+
if (folder.includes('"'))
|
|
94
|
+
continue;
|
|
95
|
+
const prefix = folder.replace(/[.*+?^$()[\]{}|\\]/g, '\\$&').replace(/\/$/, '');
|
|
96
|
+
patterns.push(`^${prefix}/${RUNTIME_ENTRY_SEATBELT}(/|$)`);
|
|
97
|
+
}
|
|
98
|
+
return patterns;
|
|
99
|
+
}
|
|
100
|
+
function within(path, root) {
|
|
101
|
+
const rel = relative(root, path);
|
|
102
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The part of ZTC's own state that holds PATH (absolute), as named or as it really is: one of ztcOwnStateRoots, or an
|
|
106
|
+
* entry of ZTC's runtime in a temp folder; null when it is in none. Every spelling that can name the same file counts
|
|
107
|
+
* (sameFileKey), as a denial does.
|
|
108
|
+
*/
|
|
109
|
+
export function ztcOwnStateHolding(path) {
|
|
110
|
+
const forms = spellings(path).map(sameFileKey);
|
|
111
|
+
for (const root of ztcOwnStateRoots()) {
|
|
112
|
+
const key = sameFileKey(root);
|
|
113
|
+
if (forms.some(form => within(form, key)))
|
|
114
|
+
return root;
|
|
115
|
+
}
|
|
116
|
+
for (const folder of ztcRuntimeTempFolders()) {
|
|
117
|
+
const key = sameFileKey(folder);
|
|
118
|
+
for (const form of forms) {
|
|
119
|
+
if (!within(form, key))
|
|
120
|
+
continue;
|
|
121
|
+
const first = relative(key, form).split(sep)[0];
|
|
122
|
+
if (first && RUNTIME_ENTRY.test(first))
|
|
123
|
+
return join(folder, first);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The folders of ZTC's own state that ZTC reads the person's skills from (skills/loader.ts defaultMarkdownRoots: the
|
|
130
|
+
* user skills folder ~/.ztc/skills, where discovery is not explicit), each as named and as it really is. A skill's SKILL.md
|
|
131
|
+
* tells the agent to read the files beside it, which are the person's instructions and scripts, so under a profile that
|
|
132
|
+
* limits the agent they stay readable (ztcOwnStateHoldingForRead, and the OS sandbox's reads), and, as the rest of
|
|
133
|
+
* ZTC's own state, never writable: no agent plants a skill. A discovery setting that can't be read names none.
|
|
134
|
+
*/
|
|
135
|
+
export function ztcOwnSkillRoots() {
|
|
136
|
+
let roots;
|
|
137
|
+
try {
|
|
138
|
+
roots = defaultMarkdownRoots();
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
return [...new Set(roots.filter(root => ztcOwnStateHolding(root) !== null).flatMap(spellings))];
|
|
144
|
+
}
|
|
145
|
+
/** Whether KEY (sameFileKey of one absolute spelling, not resolved further) lies in ZTC's own state. */
|
|
146
|
+
function holdsSpelling(key) {
|
|
147
|
+
if (ztcOwnStateRoots().some(root => within(key, sameFileKey(root))))
|
|
148
|
+
return true;
|
|
149
|
+
return ztcRuntimeTempFolders().some(folder => {
|
|
150
|
+
const folderKey = sameFileKey(folder);
|
|
151
|
+
if (!within(key, folderKey))
|
|
152
|
+
return false;
|
|
153
|
+
const first = relative(folderKey, key).split(sep)[0];
|
|
154
|
+
return Boolean(first && RUNTIME_ENTRY.test(first));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* ztcOwnStateHolding for a call that only reads PATH: null too where each spelling of PATH that lies in ZTC's own state
|
|
159
|
+
* is inside a skills folder of ZTC's own (ztcOwnSkillRoots). A skill linked there from a folder of the person's reads
|
|
160
|
+
* through its name, as its target does; a link there that leads into the rest of ZTC's own state is still refused.
|
|
161
|
+
*/
|
|
162
|
+
export function ztcOwnStateHoldingForRead(path) {
|
|
163
|
+
const holding = ztcOwnStateHolding(path);
|
|
164
|
+
if (holding === null)
|
|
165
|
+
return null;
|
|
166
|
+
const skills = ztcOwnSkillRoots().map(sameFileKey);
|
|
167
|
+
if (skills.length === 0)
|
|
168
|
+
return holding;
|
|
169
|
+
const outsideSkills = spellings(path).map(sameFileKey)
|
|
170
|
+
.some(form => holdsSpelling(form) && !skills.some(root => within(form, root)));
|
|
171
|
+
return outsideSkills ? holding : null;
|
|
172
|
+
}
|
|
173
|
+
const identityKey = (file) => `${file.dev}:${file.ino}`;
|
|
174
|
+
/**
|
|
175
|
+
* ZTC's own regular files that have more than one name, by identity, each with the part of ZTC's own state that holds
|
|
176
|
+
* it: the files in ztcOwnStateRoots and in the entries of its runtime, walked without following a link in them, each
|
|
177
|
+
* folder once.
|
|
178
|
+
*/
|
|
179
|
+
async function ownFilesWithOtherNames() {
|
|
180
|
+
const linked = new Map();
|
|
181
|
+
const walked = new Set();
|
|
182
|
+
const visit = async (path, holding, info) => {
|
|
183
|
+
if (info.isFile()) {
|
|
184
|
+
if (info.nlink > 1)
|
|
185
|
+
linked.set(identityKey(info), holding);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (!info.isDirectory() || walked.has(identityKey(info)))
|
|
189
|
+
return;
|
|
190
|
+
walked.add(identityKey(info));
|
|
191
|
+
const entries = await readdir(path, { withFileTypes: true }).catch(() => []);
|
|
192
|
+
await Promise.all(entries.filter(entry => entry.isFile() || entry.isDirectory()).map(async (entry) => {
|
|
193
|
+
const child = join(path, entry.name);
|
|
194
|
+
const childInfo = await lstat(child).catch(() => null);
|
|
195
|
+
if (childInfo)
|
|
196
|
+
await visit(child, holding, childInfo);
|
|
197
|
+
}));
|
|
198
|
+
};
|
|
199
|
+
// A root is followed where it is itself a link: as named and as it really is, it is one folder, walked once.
|
|
200
|
+
for (const root of [...ztcOwnStateRoots(), ...ztcRuntimeEntries()]) {
|
|
201
|
+
const info = await stat(root).catch(() => null);
|
|
202
|
+
if (info)
|
|
203
|
+
await visit(root, root, info);
|
|
204
|
+
}
|
|
205
|
+
return linked;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A check, for one call of a tool, of whether a file is one of ZTC's own under another name: a hard link gives a file
|
|
209
|
+
* of ZTC's own state (its config, hook approvals, a session, a hand-off) a name in the workspace, which no check of a
|
|
210
|
+
* path sees. It gives the part of ZTC's own state that holds FILE (its identity, from the descriptor a tool opened),
|
|
211
|
+
* or null. A file with one name cannot be one and costs nothing; for the first file with more, ZTC's own folders and
|
|
212
|
+
* its runtime's entries are walked, once, for their files of the same device and inode.
|
|
213
|
+
*/
|
|
214
|
+
export function ztcOwnStateLinkCheck() {
|
|
215
|
+
let linked;
|
|
216
|
+
return async (file) => {
|
|
217
|
+
if (file.nlink <= 1)
|
|
218
|
+
return null;
|
|
219
|
+
linked ??= ownFilesWithOtherNames();
|
|
220
|
+
return (await linked).get(identityKey(file)) ?? null;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* ztcOwnStateLinkCheck for a reader of files the agent names outside the file tools, which reads them in ZTC's own
|
|
225
|
+
* process: the project-context index (index_project_context, query_project_context) and the host verifiers' inputs
|
|
226
|
+
* (verify_artifact, benchmark_cpu). Under POLICY, the agent's command policy, where its profile limits the agent;
|
|
227
|
+
* undefined elsewhere, where they read as before (as the file tools' openAdmission).
|
|
228
|
+
*/
|
|
229
|
+
export function ownStateLinkGuard(policy) {
|
|
230
|
+
return profileLimitsAgent(policy?.profile, policy?.sandbox) ? ztcOwnStateLinkCheck() : undefined;
|
|
231
|
+
}
|
|
232
|
+
/** What a reader that found a file to be one of ZTC's own under another name (ownStateLinkGuard) says, refusing it. */
|
|
233
|
+
export function ownStateLinkRefusal(path, holding) {
|
|
234
|
+
return `Permission denied: ${path} is a hard link to a file in ZTC's own state (${holding}), which no profile that `
|
|
235
|
+
+ 'limits the agent reaches';
|
|
236
|
+
}
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* OpenMirrorAuthenticator (dev/local — softens the final deny to allow, while the
|
|
16
16
|
* token path still issues a scoped session so a dev superuser keeps prompt access).
|
|
17
17
|
*
|
|
18
|
-
* Self-contained: depends only on node crypto, the URL/header shapes
|
|
19
|
-
* self-contained pane credential store
|
|
20
|
-
* dependency stays one-way (mirror_stream -> here).
|
|
18
|
+
* Self-contained: depends only on node crypto, the URL/header shapes, the
|
|
19
|
+
* self-contained pane credential store and the host-credential store. No imports
|
|
20
|
+
* from the transport, so the dependency stays one-way (mirror_stream -> here).
|
|
21
21
|
*/
|
|
22
22
|
import { PaneCredentialStore, type PanePrincipal } from './pane_credentials.js';
|
|
23
23
|
export interface MirrorSession {
|
|
@@ -73,6 +73,16 @@ export interface MirrorAuthenticatorConfig {
|
|
|
73
73
|
internalToken: string;
|
|
74
74
|
cookieName?: string;
|
|
75
75
|
queryTokenName?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The most sessions the store keeps, whatever tokens started them: a backstop past what tokens keep in use, past
|
|
78
|
+
* which the one used longest ago goes. DEFAULT_MAX_SESSIONS when unset.
|
|
79
|
+
*/
|
|
80
|
+
maxSessions?: number;
|
|
81
|
+
/**
|
|
82
|
+
* The most sessions one token keeps; past it that token's own session used longest ago goes, so no token can push
|
|
83
|
+
* out another's. DEFAULT_MAX_SESSIONS_PER_TOKEN when unset.
|
|
84
|
+
*/
|
|
85
|
+
maxSessionsPerToken?: number;
|
|
76
86
|
}
|
|
77
87
|
export interface MirrorAuthenticator {
|
|
78
88
|
readonly enabled: boolean;
|
|
@@ -93,9 +103,34 @@ export interface MirrorAuthenticator {
|
|
|
93
103
|
authenticate(ctx: MirrorAuthContext): MirrorAuthDecision;
|
|
94
104
|
authenticateUpgrade(ctx: MirrorAuthContext): boolean;
|
|
95
105
|
persistSession(session: MirrorSession): string;
|
|
106
|
+
/**
|
|
107
|
+
* A new session for TOKEN, as signing in with it starts one (POST /debug/signin-token), for the transport to persist:
|
|
108
|
+
* it counts against TOKEN's own sessions, as one a request presenting TOKEN starts does. Null when TOKEN is not valid.
|
|
109
|
+
*/
|
|
110
|
+
startSession(token: string): MirrorSession | null;
|
|
96
111
|
getSession(sessionId: string): MirrorSession | null;
|
|
97
112
|
clearSession(sessionId: string): void;
|
|
113
|
+
/**
|
|
114
|
+
* Run CALLBACK with each session the store drops, as it keeps it: signed out, pushed out by a cap, or found no
|
|
115
|
+
* longer valid. Returns what stops it.
|
|
116
|
+
*/
|
|
117
|
+
onSessionDropped(callback: (session: MirrorSession) => void): () => void;
|
|
118
|
+
/**
|
|
119
|
+
* A name for the token SESSION came from: the same for every session that token starts, and one no caller can
|
|
120
|
+
* change by asking again, so a limit can key on it. Null for a session no token of this authenticator started.
|
|
121
|
+
*/
|
|
122
|
+
credentialKeyOf(session: MirrorSession | null): string | null;
|
|
98
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Sessions one token keeps at most: its requests keep one as a header and one in its link, and each sign-in with it
|
|
126
|
+
* starts another, as a browser that signs in with the token from Settings does.
|
|
127
|
+
*/
|
|
128
|
+
export declare const DEFAULT_MAX_SESSIONS_PER_TOKEN = 16;
|
|
129
|
+
/**
|
|
130
|
+
* Sessions the store keeps at most, whatever tokens started them: a backstop that binds only when thousands of tokens
|
|
131
|
+
* hold sessions at once, which only the owner's own minting (or someone holding the mirror's secret) can bring about.
|
|
132
|
+
*/
|
|
133
|
+
export declare const DEFAULT_MAX_SESSIONS = 4096;
|
|
99
134
|
/** Production HMAC + session authenticator. Denies requests without valid credentials. */
|
|
100
135
|
export declare class HmacMirrorAuthenticator implements MirrorAuthenticator {
|
|
101
136
|
protected requiresCredentials: boolean;
|
|
@@ -106,9 +141,20 @@ export declare class HmacMirrorAuthenticator implements MirrorAuthenticator {
|
|
|
106
141
|
protected readonly sharedSecret: string;
|
|
107
142
|
protected readonly internalToken: string;
|
|
108
143
|
paneCredentials: PaneCredentialStore;
|
|
144
|
+
/** The sessions, the one used longest ago first (getSession moves a session to the end). */
|
|
109
145
|
protected readonly sessions: Map<string, MirrorSession>;
|
|
146
|
+
private readonly sessionIds;
|
|
147
|
+
private readonly origins;
|
|
148
|
+
/**
|
|
149
|
+
* The session each token's requests started last, as a header and in its link (keyed `<how>:<token key>`): a later
|
|
150
|
+
* request presenting the token the same way, a poller's or a browser's with no cookie of it yet, keeps that one.
|
|
151
|
+
*/
|
|
152
|
+
private readonly requestSessions;
|
|
153
|
+
private readonly maxSessions;
|
|
154
|
+
private readonly maxSessionsPerToken;
|
|
110
155
|
private readonly shares;
|
|
111
156
|
private readonly revocationListeners;
|
|
157
|
+
private readonly dropListeners;
|
|
112
158
|
constructor(config: MirrorAuthenticatorConfig);
|
|
113
159
|
issueToken(opts?: MirrorTokenOptions): string;
|
|
114
160
|
isValidToken(token: string): MirrorTokenValidationResult;
|
|
@@ -117,9 +163,23 @@ export declare class HmacMirrorAuthenticator implements MirrorAuthenticator {
|
|
|
117
163
|
onShareRevoked(callback: (id: string) => void): () => void;
|
|
118
164
|
authenticate(ctx: MirrorAuthContext): MirrorAuthDecision;
|
|
119
165
|
authenticateUpgrade(ctx: MirrorAuthContext): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Keep SESSION and return the id its cookie carries: a session the store already keeps (one authenticate() handed
|
|
168
|
+
* back) keeps its id. Each insert first drops every session that is no longer valid; then, while the token SESSION
|
|
169
|
+
* came from keeps more than its cap, that token's own session used longest ago, so no token pushes out another's;
|
|
170
|
+
* then, while the store holds more than its cap, the one used longest ago.
|
|
171
|
+
*/
|
|
120
172
|
persistSession(session: MirrorSession): string;
|
|
173
|
+
startSession(token: string): MirrorSession | null;
|
|
121
174
|
getSession(sessionId: string): MirrorSession | null;
|
|
122
175
|
clearSession(sessionId: string): void;
|
|
176
|
+
onSessionDropped(callback: (session: MirrorSession) => void): () => void;
|
|
177
|
+
credentialKeyOf(session: MirrorSession | null): string | null;
|
|
178
|
+
/** A session for the token RESULT validated, which goes by TOKEN_KEY, started as STARTED says. */
|
|
179
|
+
private newSession;
|
|
180
|
+
/** Whether SESSION is still valid: not expired, and its share, if it has one, neither revoked nor expired. */
|
|
181
|
+
private isLive;
|
|
182
|
+
private dropSession;
|
|
123
183
|
protected matchesInternalToken(headers: NodeJS.Dict<string | string[]>): boolean;
|
|
124
184
|
protected paneTokenOf(headers: NodeJS.Dict<string | string[]>): string;
|
|
125
185
|
protected extractBearerToken(headers: NodeJS.Dict<string | string[]>): string;
|
|
@@ -144,9 +204,10 @@ export declare function mirrorSignInRequired(env?: NodeJS.ProcessEnv): boolean;
|
|
|
144
204
|
/**
|
|
145
205
|
* Build the authenticator from environment policy, mirroring the legacy
|
|
146
206
|
* MirrorStreamServer constructor: derive the enabled flag and self-mint the shared
|
|
147
|
-
* secret and the internal token
|
|
148
|
-
*
|
|
149
|
-
*
|
|
207
|
+
* secret and the internal token when the host gave none, keeping them in the
|
|
208
|
+
* host-credential store (config/host_credentials.ts), never in process.env, so the
|
|
209
|
+
* rest of this process (another mirror it runs, its own relaunch) shares them and no
|
|
210
|
+
* program it starts inherits them. No pane or renderer is given either: every pane
|
|
150
211
|
* transport clears them, and each pane gets a credential of its own instead (see
|
|
151
212
|
* pane_credentials.ts).
|
|
152
213
|
*/
|