@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
|
@@ -15,15 +15,30 @@
|
|
|
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
|
-
import { createHmac, randomUUID, timingSafeEqual } from 'crypto';
|
|
22
|
+
import { createHash, createHmac, randomUUID, timingSafeEqual } from 'crypto';
|
|
23
|
+
import { hostCredential, holdMintedCredential } from '../config/host_credentials.js';
|
|
23
24
|
import { PANE_CREDENTIAL_HEADER, PaneCredentialStore } from './pane_credentials.js';
|
|
24
25
|
const DEFAULT_COOKIE_NAME = 'ztc_mirror_session';
|
|
25
26
|
const DEFAULT_QUERY_TOKEN_NAME = 'ztc_mirror_token';
|
|
26
27
|
const DEFAULT_TTL_MS = 12 * 60 * 60 * 1000;
|
|
28
|
+
/**
|
|
29
|
+
* Sessions one token keeps at most: its requests keep one as a header and one in its link, and each sign-in with it
|
|
30
|
+
* starts another, as a browser that signs in with the token from Settings does.
|
|
31
|
+
*/
|
|
32
|
+
export const DEFAULT_MAX_SESSIONS_PER_TOKEN = 16;
|
|
33
|
+
/**
|
|
34
|
+
* Sessions the store keeps at most, whatever tokens started them: a backstop that binds only when thousands of tokens
|
|
35
|
+
* hold sessions at once, which only the owner's own minting (or someone holding the mirror's secret) can bring about.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_MAX_SESSIONS = 4096;
|
|
38
|
+
/** The name a token goes by in the store: its digest, the same for every session it starts. */
|
|
39
|
+
function tokenKeyOf(token) {
|
|
40
|
+
return createHash('sha256').update(token).digest('hex');
|
|
41
|
+
}
|
|
27
42
|
/** Production HMAC + session authenticator. Denies requests without valid credentials. */
|
|
28
43
|
export class HmacMirrorAuthenticator {
|
|
29
44
|
requiresCredentials = true;
|
|
@@ -34,15 +49,28 @@ export class HmacMirrorAuthenticator {
|
|
|
34
49
|
sharedSecret;
|
|
35
50
|
internalToken;
|
|
36
51
|
paneCredentials = new PaneCredentialStore();
|
|
52
|
+
/** The sessions, the one used longest ago first (getSession moves a session to the end). */
|
|
37
53
|
sessions = new Map();
|
|
54
|
+
sessionIds = new WeakMap();
|
|
55
|
+
origins = new WeakMap();
|
|
56
|
+
/**
|
|
57
|
+
* The session each token's requests started last, as a header and in its link (keyed `<how>:<token key>`): a later
|
|
58
|
+
* request presenting the token the same way, a poller's or a browser's with no cookie of it yet, keeps that one.
|
|
59
|
+
*/
|
|
60
|
+
requestSessions = new Map();
|
|
61
|
+
maxSessions;
|
|
62
|
+
maxSessionsPerToken;
|
|
38
63
|
shares = new Map();
|
|
39
64
|
revocationListeners = new Set();
|
|
65
|
+
dropListeners = new Set();
|
|
40
66
|
constructor(config) {
|
|
41
67
|
this.sharedSecret = config.sharedSecret;
|
|
42
68
|
this.zergId = config.zergId;
|
|
43
69
|
this.internalToken = config.internalToken;
|
|
44
70
|
this.cookieName = config.cookieName ?? DEFAULT_COOKIE_NAME;
|
|
45
71
|
this.queryTokenName = config.queryTokenName ?? DEFAULT_QUERY_TOKEN_NAME;
|
|
72
|
+
this.maxSessions = Math.max(1, Math.floor(config.maxSessions ?? DEFAULT_MAX_SESSIONS));
|
|
73
|
+
this.maxSessionsPerToken = Math.max(1, Math.floor(config.maxSessionsPerToken ?? DEFAULT_MAX_SESSIONS_PER_TOKEN));
|
|
46
74
|
}
|
|
47
75
|
issueToken(opts = {}) {
|
|
48
76
|
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
|
|
@@ -149,19 +177,29 @@ export class HmacMirrorAuthenticator {
|
|
|
149
177
|
return { ok: false, session: null, issueCookie: null, source: null };
|
|
150
178
|
}
|
|
151
179
|
// 2. Bearer (Authorization header) or query token. A valid one mints a scoped
|
|
152
|
-
// session the transport should persist as a cookie
|
|
180
|
+
// session the transport should persist as a cookie, unless this token already
|
|
181
|
+
// started the session the request can keep.
|
|
153
182
|
const bearer = this.extractBearerToken(ctx.headers);
|
|
154
183
|
const queryToken = ctx.url.searchParams.get(this.queryTokenName) || '';
|
|
155
184
|
const tokenCandidate = bearer || queryToken;
|
|
156
185
|
if (tokenCandidate) {
|
|
157
186
|
const result = this.isValidToken(tokenCandidate);
|
|
158
187
|
if (result.ok) {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
188
|
+
const tokenKey = tokenKeyOf(tokenCandidate);
|
|
189
|
+
// A browser this token signed in sends its link's token with the cookie it was given: it keeps that session.
|
|
190
|
+
const presented = this.sessionFromCookies(ctx.cookies);
|
|
191
|
+
if (presented && this.origins.get(presented)?.tokenKey === tokenKey) {
|
|
192
|
+
return { ok: true, session: presented, issueCookie: null, source: 'browser' };
|
|
193
|
+
}
|
|
194
|
+
// Any other request presenting the token keeps the session the token's requests presenting it the same way
|
|
195
|
+
// started last: a poller's, as a header on each request, or a browser's, in its link with no cookie of it.
|
|
196
|
+
// A browser signing out of its session so leaves a poller's alone.
|
|
197
|
+
const how = bearer ? 'header' : 'link';
|
|
198
|
+
const started = this.requestSessions.get(`${how}:${tokenKey}`);
|
|
199
|
+
const kept = started ? this.getSession(started) : null;
|
|
200
|
+
if (kept)
|
|
201
|
+
return { ok: true, session: kept, issueCookie: kept, source: 'browser' };
|
|
202
|
+
const session = this.newSession(result, tokenKey, how);
|
|
165
203
|
return { ok: true, session, issueCookie: session, source: 'browser' };
|
|
166
204
|
}
|
|
167
205
|
if (tokenCandidate.split('.')[1] === 'observe')
|
|
@@ -180,25 +218,95 @@ export class HmacMirrorAuthenticator {
|
|
|
180
218
|
// A pane credential is for a pane's own bus and publications, never the voice stream.
|
|
181
219
|
return decision.ok && decision.source !== 'pane' && decision.session?.canControl !== false;
|
|
182
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Keep SESSION and return the id its cookie carries: a session the store already keeps (one authenticate() handed
|
|
223
|
+
* back) keeps its id. Each insert first drops every session that is no longer valid; then, while the token SESSION
|
|
224
|
+
* came from keeps more than its cap, that token's own session used longest ago, so no token pushes out another's;
|
|
225
|
+
* then, while the store holds more than its cap, the one used longest ago.
|
|
226
|
+
*/
|
|
183
227
|
persistSession(session) {
|
|
228
|
+
const known = this.sessionIds.get(session);
|
|
229
|
+
if (known !== undefined && this.sessions.get(known) === session && this.getSession(known))
|
|
230
|
+
return known;
|
|
231
|
+
for (const [id, kept] of this.sessions)
|
|
232
|
+
if (!this.isLive(kept))
|
|
233
|
+
this.dropSession(id);
|
|
184
234
|
const sessionId = randomUUID();
|
|
185
235
|
const observer = session.canControl === false || session.shareId !== undefined;
|
|
186
|
-
|
|
236
|
+
const stored = { ...session, canControl: !observer, canInspectPrompts: observer ? false : session.canInspectPrompts };
|
|
237
|
+
this.sessions.set(sessionId, stored);
|
|
238
|
+
this.sessionIds.set(stored, sessionId);
|
|
239
|
+
const origin = this.origins.get(session);
|
|
240
|
+
if (origin) {
|
|
241
|
+
this.origins.set(stored, origin);
|
|
242
|
+
if (origin.started !== 'sign-in')
|
|
243
|
+
this.requestSessions.set(`${origin.started}:${origin.tokenKey}`, sessionId);
|
|
244
|
+
const own = [...this.sessions].filter(([, kept]) => this.origins.get(kept)?.tokenKey === origin.tokenKey);
|
|
245
|
+
for (const [id] of own.slice(0, Math.max(0, own.length - this.maxSessionsPerToken)))
|
|
246
|
+
this.dropSession(id);
|
|
247
|
+
}
|
|
248
|
+
for (const [id] of this.sessions) {
|
|
249
|
+
if (this.sessions.size <= this.maxSessions)
|
|
250
|
+
break;
|
|
251
|
+
this.dropSession(id);
|
|
252
|
+
}
|
|
187
253
|
return sessionId;
|
|
188
254
|
}
|
|
255
|
+
startSession(token) {
|
|
256
|
+
const result = this.isValidToken(token);
|
|
257
|
+
return result.ok ? this.newSession(result, tokenKeyOf(token), 'sign-in') : null;
|
|
258
|
+
}
|
|
189
259
|
getSession(sessionId) {
|
|
190
260
|
const session = this.sessions.get(sessionId);
|
|
191
261
|
if (!session)
|
|
192
262
|
return null;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.sessions.delete(sessionId);
|
|
263
|
+
if (!this.isLive(session)) {
|
|
264
|
+
this.dropSession(sessionId);
|
|
196
265
|
return null;
|
|
197
266
|
}
|
|
267
|
+
// Used now: the last the store would drop.
|
|
268
|
+
this.sessions.delete(sessionId);
|
|
269
|
+
this.sessions.set(sessionId, session);
|
|
198
270
|
return session;
|
|
199
271
|
}
|
|
200
272
|
clearSession(sessionId) {
|
|
273
|
+
this.dropSession(sessionId);
|
|
274
|
+
}
|
|
275
|
+
onSessionDropped(callback) {
|
|
276
|
+
this.dropListeners.add(callback);
|
|
277
|
+
return () => { this.dropListeners.delete(callback); };
|
|
278
|
+
}
|
|
279
|
+
credentialKeyOf(session) {
|
|
280
|
+
return (session && this.origins.get(session)?.tokenKey) ?? null;
|
|
281
|
+
}
|
|
282
|
+
/** A session for the token RESULT validated, which goes by TOKEN_KEY, started as STARTED says. */
|
|
283
|
+
newSession(result, tokenKey, started) {
|
|
284
|
+
const session = {
|
|
285
|
+
expiresAtMs: result.expiresAtMs,
|
|
286
|
+
canInspectPrompts: result.canInspectPrompts,
|
|
287
|
+
canControl: result.canControl !== false,
|
|
288
|
+
...(result.shareId ? { shareId: result.shareId } : {}),
|
|
289
|
+
};
|
|
290
|
+
this.origins.set(session, { tokenKey, started });
|
|
291
|
+
return session;
|
|
292
|
+
}
|
|
293
|
+
/** Whether SESSION is still valid: not expired, and its share, if it has one, neither revoked nor expired. */
|
|
294
|
+
isLive(session) {
|
|
295
|
+
const share = session.shareId ? this.shares.get(session.shareId) : undefined;
|
|
296
|
+
return Date.now() < session.expiresAtMs
|
|
297
|
+
&& !(session.shareId && (!share || share.revoked || Date.now() >= share.expiresAtMs));
|
|
298
|
+
}
|
|
299
|
+
dropSession(sessionId) {
|
|
300
|
+
const session = this.sessions.get(sessionId);
|
|
301
|
+
if (!session)
|
|
302
|
+
return;
|
|
201
303
|
this.sessions.delete(sessionId);
|
|
304
|
+
const origin = this.origins.get(session);
|
|
305
|
+
const key = origin ? `${origin.started}:${origin.tokenKey}` : '';
|
|
306
|
+
if (origin && this.requestSessions.get(key) === sessionId)
|
|
307
|
+
this.requestSessions.delete(key);
|
|
308
|
+
for (const listener of this.dropListeners)
|
|
309
|
+
listener(session);
|
|
202
310
|
}
|
|
203
311
|
matchesInternalToken(headers) {
|
|
204
312
|
if (!this.internalToken)
|
|
@@ -265,26 +373,27 @@ export function mirrorSignInRequired(env = process.env) {
|
|
|
265
373
|
/**
|
|
266
374
|
* Build the authenticator from environment policy, mirroring the legacy
|
|
267
375
|
* MirrorStreamServer constructor: derive the enabled flag and self-mint the shared
|
|
268
|
-
* secret and the internal token
|
|
269
|
-
*
|
|
270
|
-
*
|
|
376
|
+
* secret and the internal token when the host gave none, keeping them in the
|
|
377
|
+
* host-credential store (config/host_credentials.ts), never in process.env, so the
|
|
378
|
+
* rest of this process (another mirror it runs, its own relaunch) shares them and no
|
|
379
|
+
* program it starts inherits them. No pane or renderer is given either: every pane
|
|
271
380
|
* transport clears them, and each pane gets a credential of its own instead (see
|
|
272
381
|
* pane_credentials.ts).
|
|
273
382
|
*/
|
|
274
383
|
export function createMirrorAuthenticatorFromEnv() {
|
|
275
384
|
const zergId = (process.env.ZERG_ID || '').trim();
|
|
276
385
|
const enabled = mirrorSignInRequired(process.env);
|
|
277
|
-
let sharedSecret = (
|
|
386
|
+
let sharedSecret = (hostCredential('ZTC_MIRROR_SHARED_SECRET') || '').trim();
|
|
278
387
|
if (!sharedSecret) {
|
|
279
388
|
sharedSecret = randomUUID();
|
|
280
|
-
|
|
389
|
+
holdMintedCredential('ZTC_MIRROR_SHARED_SECRET', sharedSecret);
|
|
281
390
|
}
|
|
282
391
|
// Always mint an internal token (even in dev/open mode): it is ZTC's own credential
|
|
283
392
|
// for the internal-only endpoints, kept in this process. Panes use their own.
|
|
284
|
-
let internalToken = (
|
|
393
|
+
let internalToken = (hostCredential('ZTC_MIRROR_INTERNAL_TOKEN') || '').trim();
|
|
285
394
|
if (!internalToken) {
|
|
286
395
|
internalToken = randomUUID();
|
|
287
|
-
|
|
396
|
+
holdMintedCredential('ZTC_MIRROR_INTERNAL_TOKEN', internalToken);
|
|
288
397
|
}
|
|
289
398
|
const config = { sharedSecret, zergId, internalToken };
|
|
290
399
|
return enabled ? new HmacMirrorAuthenticator(config) : new OpenMirrorAuthenticator(config);
|
|
@@ -2,6 +2,7 @@ import type { DailyDesktopSnapshot } from '../desktop/daily/desktop_wiring.js';
|
|
|
2
2
|
import { type GoalView } from '../goal_contract.js';
|
|
3
3
|
import { type EvidenceSnapshot } from '../agent/runtime/evidence.js';
|
|
4
4
|
import type { TaskHandoffProjection } from '../session_handoff_contract.js';
|
|
5
|
+
import type { NativeNonAgentPane } from '../panes/pane_registry.js';
|
|
5
6
|
import type { PaneRunStatus } from '../panes/types.js';
|
|
6
7
|
import { type AttentionSnapshot } from '../attention/queue.js';
|
|
7
8
|
import type { ViewPlugin } from './view_plugin.js';
|
|
@@ -116,6 +117,15 @@ export type BusSendResult = {
|
|
|
116
117
|
code?: string;
|
|
117
118
|
error: string;
|
|
118
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* The refusal of a message for pane TO, which runs no agent (a shell, a command, another program), or, when MISSING, is
|
|
122
|
+
* no pane at all (not_an_agent): the mirror's answer, and ZTC's own when it runs no mirror (typeOverseerMessage). Said
|
|
123
|
+
* to an agent, workspace-mcp's in a Claude Code or Codex pane or a ZTC's own: each types into such a pane with its tool.
|
|
124
|
+
* When the pane is one of the desktop app's NATIVE panes that takes no agent's message (nativeNonAgentPane), the refusal
|
|
125
|
+
* says what the pane is and what works instead (nativePaneRefusal): a native Claude Code or Codex pane is no pane a
|
|
126
|
+
* message reaches, though Claude Code and Codex panes are.
|
|
127
|
+
*/
|
|
128
|
+
export declare function notAnAgentResult(to: number | 'all', missing: boolean, native?: NativeNonAgentPane): BusSendResult;
|
|
119
129
|
export type MirrorMuxCommand = {
|
|
120
130
|
type: 'focus_pane';
|
|
121
131
|
pane_id: number;
|
|
@@ -514,6 +524,7 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
514
524
|
private paneInputCallback;
|
|
515
525
|
private paneControlCallback;
|
|
516
526
|
private agentPaneMessageCallback;
|
|
527
|
+
private nativeNonAgentPaneLookup;
|
|
517
528
|
private busMessageCheck;
|
|
518
529
|
private muxCommandCallback;
|
|
519
530
|
private supervisionCommandCallback;
|
|
@@ -781,6 +792,12 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
781
792
|
* it into the pane with its sender); false leaves the usual fallbacks.
|
|
782
793
|
*/
|
|
783
794
|
onAgentPaneMessage(cb: (paneId: number, msg: BusMessage) => boolean): void;
|
|
795
|
+
/**
|
|
796
|
+
* Name the desktop app's native panes that take no agent's message (nativeNonAgentPane), from the owner's record of
|
|
797
|
+
* each, so the refusal of a message for one (not_an_agent), Main's or a pane's own, says what the pane is and what
|
|
798
|
+
* works instead (notAnAgentResult). Nothing is delivered either way.
|
|
799
|
+
*/
|
|
800
|
+
onNativeNonAgentPane(cb: (paneId: number) => NativeNonAgentPane | undefined): void;
|
|
784
801
|
/**
|
|
785
802
|
* What Main says of a message a pane posts to /bus/send before it is delivered (BusMessageCheck): it refuses a reply
|
|
786
803
|
* mode that names an arbitrator the person didn't set up, and tells the sender what became of its mode.
|
|
@@ -792,7 +809,16 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
792
809
|
onAllEvents(callback: (event: MirrorEvent) => void): () => void;
|
|
793
810
|
getAttentionSnapshot(limit?: number, offset?: number): AttentionSnapshot;
|
|
794
811
|
private resolveAttention;
|
|
795
|
-
|
|
812
|
+
/**
|
|
813
|
+
* Answer attention item ID with ANSWER: a question's text, an approval's decision and reason, a prompt widget's fields.
|
|
814
|
+
* FROM is who sent it: the browser mirror ('mirror': this server's routes, and a command the browser sent or that is
|
|
815
|
+
* relayed here), or the person at this ZTC's own terminal ('terminal': the /attention command they type). Every string
|
|
816
|
+
* the mirror sends is mirror text (stripForeignMediaTokensIn), wherever it goes next: a question's answer becomes the
|
|
817
|
+
* agent's next message, a plan's feedback becomes one, and a ZTC pane that is relayed an answer runs it as its prompt,
|
|
818
|
+
* so a forged `[image PATH]` in it would read PATH. What the person types at the terminal keeps their own paths, as
|
|
819
|
+
* their messages do.
|
|
820
|
+
*/
|
|
821
|
+
respondAttention(id: string, answer: unknown, from?: 'mirror' | 'terminal'): void;
|
|
796
822
|
dismissAttention(id: string): void;
|
|
797
823
|
/**
|
|
798
824
|
* Register an in-process bus member (parent ZTC). No HTTP round-trip needed.
|
|
@@ -807,14 +833,16 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
807
833
|
*/
|
|
808
834
|
onAllBusMessages(callback: (msg: BusMessage) => void): () => void;
|
|
809
835
|
/**
|
|
810
|
-
* Deliver a bus message to the appropriate target(s). With `agentsOnly` (what a pane's own credential sends
|
|
811
|
-
* goes only to an agent: Main, every bus member ('all'), a pane on the bus
|
|
812
|
-
* pane, which the owner types it into with its sender. For any other pane (a
|
|
813
|
-
* queued or typed, and the answer is 'not_an_agent'. Whoever sends it, an
|
|
814
|
-
* hasn't joined the bus is held until it joins, never typed into the pane,
|
|
815
|
-
* once the renderer has reported that pane's program exited, nothing is held
|
|
816
|
-
* (forExitedZtc), until a ZTC that joins stands for the pane again. What a
|
|
817
|
-
* first (dropUnjoinable), so no message for it goes ahead of one that
|
|
836
|
+
* Deliver a bus message to the appropriate target(s). With `agentsOnly` (what a pane's own credential sends, and what
|
|
837
|
+
* Main sends: overseerBusTransport), a message goes only to an agent: Main, every bus member ('all'), a pane on the bus
|
|
838
|
+
* or running ZTC, or a Claude Code or Codex pane, which the owner types it into with its sender. For any other pane (a
|
|
839
|
+
* shell, a command) nothing is delivered, queued or typed, and the answer is 'not_an_agent'. Whoever sends it, an
|
|
840
|
+
* agent's message for a ZTC agent's pane that hasn't joined the bus is held until it joins, never typed into the pane,
|
|
841
|
+
* and the answer is 'held' (waitsForJoin); once the renderer has reported that pane's program exited, nothing is held
|
|
842
|
+
* or typed and the answer is 'pane_exited' (forExitedZtc), until a ZTC that joins stands for the pane again. What a
|
|
843
|
+
* pane that can no longer join held is dropped first (dropUnjoinable), so no message for it goes ahead of one that
|
|
844
|
+
* waits. With `agentsOnly`, a message for a ZTC pane that reads stdin and joins no bus is typed in as one line that
|
|
845
|
+
* says who sent it, never on the pane's control channel and never as its raw text.
|
|
818
846
|
*/
|
|
819
847
|
deliverBusMessage(msg: BusMessage, options?: {
|
|
820
848
|
agentsOnly?: boolean;
|
|
@@ -930,7 +958,17 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
930
958
|
private observerProjections;
|
|
931
959
|
private observerQueryRedaction;
|
|
932
960
|
private observerTextRedaction;
|
|
961
|
+
/** Each live stream's credential context, keyed as observerQueryRedaction is (see observer_secret_redaction.ts). */
|
|
962
|
+
private observerSecretRedaction;
|
|
963
|
+
/**
|
|
964
|
+
* EVENT as a read-only observer gets it, or null for a type it never gets. Every string it carries has the URL
|
|
965
|
+
* tokens and the credentials an observer is never shown withheld; streamed text keeps each stream's context, so a
|
|
966
|
+
* credential split across its pieces is withheld too. A STANDALONE event is a connect snapshot of a stream's
|
|
967
|
+
* retained text, which neither reads nor moves its live stream's context.
|
|
968
|
+
*/
|
|
933
969
|
private observerEvent;
|
|
970
|
+
/** A copy of VALUE with each string in it as an observer reads it: no /job environment options, URL tokens or SECRETS. */
|
|
971
|
+
private observerStrings;
|
|
934
972
|
private observerConnectionData;
|
|
935
973
|
/**
|
|
936
974
|
* The /debug/config payload. The web client fetches this right after
|
|
@@ -1065,6 +1103,10 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
1065
1103
|
height: number;
|
|
1066
1104
|
byte_length: number;
|
|
1067
1105
|
}>;
|
|
1106
|
+
/**
|
|
1107
|
+
* The bucket a capture POST counts against: the token that sent it (one name for every session it starts), the pane
|
|
1108
|
+
* or ZTC process, else the socket's address. Never a header the client writes, such as X-Forwarded-For.
|
|
1109
|
+
*/
|
|
1068
1110
|
private rateLimitKey;
|
|
1069
1111
|
private isLocalRequest;
|
|
1070
1112
|
private allowZlickyCapture;
|
|
@@ -1118,7 +1160,7 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
1118
1160
|
private isWavBuffer;
|
|
1119
1161
|
private transcribeVoiceWav;
|
|
1120
1162
|
private parseCookies;
|
|
1121
|
-
/** Persist the authenticator-minted session and write the Set-Cookie header. */
|
|
1163
|
+
/** Persist the authenticator-minted session and write the Set-Cookie header. Returns the session as the store keeps it. */
|
|
1122
1164
|
private issueMirrorSession;
|
|
1123
1165
|
private persistLayoutToDisk;
|
|
1124
1166
|
private clearMirrorSession;
|
|
@@ -1203,6 +1245,8 @@ export declare class MirrorStreamServer implements MirrorPublisher {
|
|
|
1203
1245
|
private parseWebSocketFrames;
|
|
1204
1246
|
private handleUpgrade;
|
|
1205
1247
|
private handleVoiceStreamSocket;
|
|
1248
|
+
/** Refuse with 403, and say so, an event a pane's own credential may not publish (paneEventRefusal). */
|
|
1249
|
+
private refusePaneEvent;
|
|
1206
1250
|
private admitChildPublication;
|
|
1207
1251
|
private handleRequest;
|
|
1208
1252
|
}
|