@zergai/ztc 0.23.1-dev.202611152321 → 0.24.0-beta.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/README.md +299 -13
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/agent/agent.js +57 -14
- package/dist/agent/backends/http_error.d.ts +2 -0
- package/dist/agent/backends/http_error.js +2 -0
- package/dist/agent/backends/router_gate.d.ts +3 -2
- package/dist/agent/backends/router_gate.js +5 -4
- package/dist/agent/backends/router_keys.d.ts +14 -0
- package/dist/agent/backends/router_keys.js +19 -0
- package/dist/agent/backends/router_refusal.d.ts +5 -3
- package/dist/agent/backends/router_refusal.js +28 -6
- package/dist/agent/backends/types.d.ts +1 -1
- package/dist/agent/backends/zrouter_stream.js +10 -6
- package/dist/agent/commands/agent_cli.d.ts +11 -1
- package/dist/agent/commands/agent_cli.js +295 -38
- package/dist/agent/commands/diff.js +4 -1
- package/dist/agent/commands/help.js +4 -1
- package/dist/agent/commands/plan.js +3 -1
- package/dist/agent/commands/session_redaction.d.ts +16 -0
- package/dist/agent/commands/session_redaction.js +77 -0
- package/dist/agent/commands/settings.js +144 -0
- package/dist/agent/commands/types.d.ts +5 -0
- package/dist/agent/commands/usage_spec.d.ts +4 -0
- package/dist/agent/commands/usage_spec.js +10 -4
- package/dist/agent/runtime/policy.d.ts +25 -0
- package/dist/agent/runtime/policy.js +154 -26
- package/dist/agent/runtime/source_verification.js +6 -2
- package/dist/agent/runtime/tool_runtime.js +81 -3
- package/dist/agent/tools/apply_patch.js +678 -131
- package/dist/agent/tools/bus_message.d.ts +26 -1
- package/dist/agent/tools/bus_message.js +126 -10
- package/dist/agent/tools/file.d.ts +16 -1
- package/dist/agent/tools/file.js +43 -5
- package/dist/agent/tools/index.d.ts +1 -1
- package/dist/agent/tools/index.js +1 -1
- package/dist/agent/tools/pane.js +5 -0
- package/dist/agent/tools/search.js +5 -1
- package/dist/agent/tools/supervision.js +16 -2
- package/dist/agent/tools/types.d.ts +22 -0
- package/dist/app/mirror_startup.d.ts +7 -5
- package/dist/app/mirror_startup.js +7 -5
- package/dist/app/navigator_mirrors.d.ts +20 -0
- package/dist/app/navigator_mirrors.js +36 -0
- package/dist/app/workspace_layout_controller.d.ts +11 -2
- package/dist/app/workspace_layout_controller.js +13 -2
- package/dist/batch/worktree.js +9 -1
- package/dist/cli_ratatui.d.ts +264 -12
- package/dist/cli_ratatui.js +1198 -103
- package/dist/config/types.d.ts +29 -0
- package/dist/desktop/daily/source_baseline.js +3 -1
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +229 -26
- package/dist/emulation/tool_adapters.js +42 -5
- package/dist/headless.js +24 -5
- package/dist/instance_registry.d.ts +7 -0
- package/dist/mcp/workspace_server.d.ts +12 -1
- package/dist/mcp/workspace_server.js +75 -8
- package/dist/panes/agent_cli.d.ts +60 -3
- package/dist/panes/agent_cli.js +169 -16
- package/dist/panes/agent_pane_sessions.d.ts +22 -0
- package/dist/panes/agent_pane_sessions.js +111 -0
- package/dist/panes/agent_panes.d.ts +77 -3
- package/dist/panes/agent_panes.js +199 -10
- package/dist/panes/agent_profiles.d.ts +5 -0
- package/dist/panes/agent_profiles.js +7 -0
- package/dist/panes/agent_resume.d.ts +134 -0
- package/dist/panes/agent_resume.js +155 -0
- package/dist/panes/agent_sessions/claude_head.d.ts +32 -0
- package/dist/panes/agent_sessions/claude_head.js +122 -0
- package/dist/panes/agent_sessions/claude_store.d.ts +59 -0
- package/dist/panes/agent_sessions/claude_store.js +223 -0
- package/dist/panes/agent_sessions/codex_head.d.ts +55 -0
- package/dist/panes/agent_sessions/codex_head.js +161 -0
- package/dist/panes/agent_sessions/codex_store.d.ts +43 -0
- package/dist/panes/agent_sessions/codex_store.js +187 -0
- package/dist/panes/agent_sessions/controller.d.ts +74 -0
- package/dist/panes/agent_sessions/controller.js +110 -0
- package/dist/panes/agent_sessions/cut_json.d.ts +14 -0
- package/dist/panes/agent_sessions/cut_json.js +109 -0
- package/dist/panes/agent_sessions/limits.d.ts +48 -0
- package/dist/panes/agent_sessions/limits.js +48 -0
- package/dist/panes/agent_sessions/scan.d.ts +49 -0
- package/dist/panes/agent_sessions/scan.js +86 -0
- package/dist/panes/agent_sessions/store_fs.d.ts +51 -0
- package/dist/panes/agent_sessions/store_fs.js +128 -0
- package/dist/panes/agent_sessions/stores.d.ts +36 -0
- package/dist/panes/agent_sessions/stores.js +89 -0
- package/dist/panes/agent_sessions/title.d.ts +9 -0
- package/dist/panes/agent_sessions/title.js +51 -0
- package/dist/panes/agent_sessions/types.d.ts +48 -0
- package/dist/panes/agent_sessions/types.js +2 -0
- package/dist/panes/reply_arbitrator.d.ts +39 -0
- package/dist/panes/reply_arbitrator.js +185 -0
- package/dist/panes/reply_modes.d.ts +291 -0
- package/dist/panes/reply_modes.js +598 -0
- package/dist/runtime_info.js +11 -2
- package/dist/session.js +4 -2
- package/dist/simulation/living/context.d.ts +8 -8
- package/dist/simulation/living/types.d.ts +5 -5
- package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
- package/dist/ui/ratatui/ipc_path.d.ts +5 -0
- package/dist/ui/ratatui/ipc_path.js +23 -3
- package/dist/ui/ratatui/pane_credential_broker.d.ts +23 -8
- package/dist/ui/ratatui/pane_credential_broker.js +49 -14
- package/dist/ui/ratatui/pane_relay.d.ts +5 -2
- package/dist/ui/ratatui/pane_relay.js +86 -19
- package/dist/ui/ratatui/process.js +3 -0
- package/dist/ui/ratatui/protocol.d.ts +50 -1
- package/dist/ui/ratatui/protocol.js +56 -0
- package/dist/ui/ratatui/relay_policy.d.ts +39 -0
- package/dist/ui/ratatui/relay_policy.js +94 -0
- package/dist/ui/ratatui/screen_privacy.d.ts +15 -0
- package/dist/ui/ratatui/screen_privacy.js +24 -0
- package/dist/ui/scrollback.js +8 -0
- package/dist/ui/widgets/agent_sessions_panel.d.ts +139 -0
- package/dist/ui/widgets/agent_sessions_panel.js +542 -0
- package/dist/ui/widgets/log_view.d.ts +5 -1
- package/dist/ui/widgets/log_view.js +40 -4
- package/dist/utils/atomic_write.js +9 -11
- package/dist/utils/canonical_path.d.ts +19 -0
- package/dist/utils/canonical_path.js +44 -0
- package/dist/utils/compaction.d.ts +2 -1
- package/dist/utils/compaction.js +3 -1
- package/dist/utils/git_directory_names.d.ts +51 -0
- package/dist/utils/git_directory_names.js +429 -0
- package/dist/utils/temporary_write_root.d.ts +6 -1
- package/dist/utils/temporary_write_root.js +32 -2
- package/dist/utils/tool_result_message.d.ts +4 -1
- package/dist/utils/tool_result_message.js +6 -2
- package/dist/web/bus_hold.d.ts +70 -0
- package/dist/web/bus_hold.js +118 -0
- package/dist/web/mirror_client.d.ts +7 -3
- package/dist/web/mirror_client.js +61 -23
- package/dist/web/mirror_route_gate.d.ts +40 -0
- package/dist/web/mirror_route_gate.js +71 -0
- package/dist/web/mirror_stream.d.ts +147 -22
- package/dist/web/mirror_stream.js +350 -83
- package/dist/web/pane_credentials.d.ts +32 -1
- package/dist/web/pane_credentials.js +62 -2
- package/dist/workspace_collision.js +11 -2
- package/dist/zlm-embed.mjs +940 -273
- package/package.json +39 -7
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A session's title as the picker shows it: one clean line, at most TITLE_CODE_POINTS code points and "…".
|
|
3
|
+
*
|
|
4
|
+
* A title comes from a file someone else's program wrote, so nothing in it may act on the terminal: controls (C0, C1,
|
|
5
|
+
* DEL) and the bidirectional controls that reorder the text after them are dropped, lone surrogates too, and every run
|
|
6
|
+
* of whitespace, line breaks included, becomes one space.
|
|
7
|
+
*/
|
|
8
|
+
import { TITLE_CODE_POINTS } from './limits.js';
|
|
9
|
+
/** C0 and C1 controls, DEL, and the bidi controls: ALM, LRM, RLM, LRE to RLO, LRI to PDI. */
|
|
10
|
+
function isControl(code) {
|
|
11
|
+
return code <= 0x1f || (code >= 0x7f && code <= 0x9f) || code === 0x61c || code === 0x200e || code === 0x200f
|
|
12
|
+
|| (code >= 0x202a && code <= 0x202e) || (code >= 0x2066 && code <= 0x2069);
|
|
13
|
+
}
|
|
14
|
+
/** Whitespace, line and paragraph separators among it: tab to carriage return, space, NEL, and Unicode's spaces. */
|
|
15
|
+
function isSpace(code) {
|
|
16
|
+
return (code >= 0x09 && code <= 0x0d) || code === 0x20 || code === 0x85 || code === 0xa0 || code === 0x1680
|
|
17
|
+
|| (code >= 0x2000 && code <= 0x200a) || code === 0x2028 || code === 0x2029 || code === 0x202f || code === 0x205f
|
|
18
|
+
|| code === 0x3000 || code === 0xfeff;
|
|
19
|
+
}
|
|
20
|
+
function isSurrogate(code) {
|
|
21
|
+
return code >= 0xd800 && code <= 0xdfff;
|
|
22
|
+
}
|
|
23
|
+
/** One line of a session's name, title or prompt, or null when nothing printable is left. */
|
|
24
|
+
export function sessionTitle(text) {
|
|
25
|
+
if (typeof text !== 'string')
|
|
26
|
+
return null;
|
|
27
|
+
const points = [];
|
|
28
|
+
let space = false;
|
|
29
|
+
for (const char of text) {
|
|
30
|
+
const code = char.codePointAt(0);
|
|
31
|
+
if (isSpace(code)) {
|
|
32
|
+
space = points.length > 0;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// A lone surrogate iterates as one code unit; a pair is one code point above 0xffff.
|
|
36
|
+
if (isControl(code) || isSurrogate(code))
|
|
37
|
+
continue;
|
|
38
|
+
if (space) {
|
|
39
|
+
points.push(' ');
|
|
40
|
+
space = false;
|
|
41
|
+
}
|
|
42
|
+
points.push(char);
|
|
43
|
+
if (points.length > TITLE_CODE_POINTS)
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (points.length === 0)
|
|
47
|
+
return null;
|
|
48
|
+
if (points.length <= TITLE_CODE_POINTS)
|
|
49
|
+
return points.join('');
|
|
50
|
+
return `${points.slice(0, TITLE_CODE_POINTS).join('').trimEnd()}…`;
|
|
51
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** What the sessions list holds about one Claude Code or Codex session: its metadata, never its content. */
|
|
2
|
+
import type { AgentCliId } from '../agent_cli.js';
|
|
3
|
+
export interface AgentSessionRow {
|
|
4
|
+
cli: AgentCliId;
|
|
5
|
+
/** The session id, lowercase, as the CLI resumes it. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The folder the session works in, as its file says; null when its head names none. */
|
|
8
|
+
cwd: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Whether that folder is known to be the session's: Claude Code keeps a session under a project folder named after
|
|
11
|
+
* its folder, and a session moved with /cd, or whose head names no folder, can't be placed by its head alone.
|
|
12
|
+
*/
|
|
13
|
+
folderVerified: boolean;
|
|
14
|
+
/** When the session was last active: its file's modification time. */
|
|
15
|
+
mtimeMs: number;
|
|
16
|
+
/** One line: the session's name, its CLI's title for it or its opening prompt (title.ts), or null. */
|
|
17
|
+
title: string | null;
|
|
18
|
+
/** The ZTC sign-in profile whose store holds it; null for this computer's own sign-in. */
|
|
19
|
+
profile: string | null;
|
|
20
|
+
/** The session file. Used to read its head again on resume; never shown. */
|
|
21
|
+
path: string;
|
|
22
|
+
}
|
|
23
|
+
/** A session file found by its name, before its head is read. */
|
|
24
|
+
export interface SessionCandidate {
|
|
25
|
+
cli: AgentCliId;
|
|
26
|
+
id: string;
|
|
27
|
+
path: string;
|
|
28
|
+
profile: string | null;
|
|
29
|
+
mtimeMs: number;
|
|
30
|
+
/** Claude Code: the project folder's name the file is in. Codex: empty. */
|
|
31
|
+
group: string;
|
|
32
|
+
}
|
|
33
|
+
/** What one listing found. */
|
|
34
|
+
export interface SessionListing {
|
|
35
|
+
rows: AgentSessionRow[];
|
|
36
|
+
/** Files whose heads couldn't be read. */
|
|
37
|
+
unreadable: number;
|
|
38
|
+
/** True when the scan stopped at its deadline with files left unread. */
|
|
39
|
+
partial: boolean;
|
|
40
|
+
/** Files whose heads were read, listed or not. */
|
|
41
|
+
read: number;
|
|
42
|
+
/** Files read and left out, as the CLI's own picker leaves them out: the Agent SDK's, codex exec's, a subagent's… */
|
|
43
|
+
skipped: number;
|
|
44
|
+
/** Session files not read: older than the newest the scan reads. */
|
|
45
|
+
older: number;
|
|
46
|
+
/** Session folders not followed, because they are symbolic links. */
|
|
47
|
+
links: number;
|
|
48
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asking an arbitrator whether Main's exchange with an agent pane goes on (panes/reply_modes.ts): an HTTP(S) endpoint
|
|
3
|
+
* the person set up, POSTed the exchange's summary, or a model on Main's own route, asked a fixed prompt with the
|
|
4
|
+
* summary as data. Either answers {continue, reason}. A timeout, an error, or an answer that isn't such a decision comes
|
|
5
|
+
* back as no decision, with why, and the exchange stops.
|
|
6
|
+
*
|
|
7
|
+
* The arbitrator reads the summary and nothing else: no request it gets carries a credential of ZTC's, and the summary
|
|
8
|
+
* has none (arbitrationSummary takes them out). A model arbitrator is reached as Main reaches its own model, on its own
|
|
9
|
+
* route, but never on a subscription login (subscriptionRefusal).
|
|
10
|
+
*/
|
|
11
|
+
import type { ZTCConfig } from '../config/types.js';
|
|
12
|
+
import { type ArbitrationSummary, type ArbitratorOutcome } from './reply_modes.js';
|
|
13
|
+
/**
|
|
14
|
+
* Ask the HTTP(S) arbitrator at URL: a POST of SUMMARY as JSON, with no credential of any kind and no redirect
|
|
15
|
+
* followed, which must answer 2xx with {continue, reason} within TIMEOUT_MS.
|
|
16
|
+
*/
|
|
17
|
+
export declare function askHttpArbitrator(url: string, summary: ArbitrationSummary, timeoutMs: number): Promise<ArbitratorOutcome>;
|
|
18
|
+
/** Where a model arbitrator runs: Main's settings and working directory, and the provider and model it names, if any. */
|
|
19
|
+
export interface ModelArbitratorRoute {
|
|
20
|
+
config: ZTCConfig;
|
|
21
|
+
cwd: string;
|
|
22
|
+
provider?: string;
|
|
23
|
+
model?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Ask a model on Main's own route (ROUTE: its provider and model, or the ones ROUTE names) whether the exchange goes on:
|
|
27
|
+
* the fixed prompt ARBITRATOR_SYSTEM_PROMPT, SUMMARY as the user message's JSON, no tools, within TIMEOUT_MS. A route on
|
|
28
|
+
* a subscription login gives no decision (subscriptionRefusal).
|
|
29
|
+
*/
|
|
30
|
+
export declare function askModelArbitrator(route: ModelArbitratorRoute, summary: ArbitrationSummary, timeoutMs: number): Promise<ArbitratorOutcome>;
|
|
31
|
+
/**
|
|
32
|
+
* Ask the arbitrator NAME whether the exchange SUMMARY stands for goes on: "model", a model on Main's own route, or one
|
|
33
|
+
* the person set up in CONFIG (panes.replyArbitrators), with its own time to decide. A name no longer set up gives no
|
|
34
|
+
* decision.
|
|
35
|
+
*/
|
|
36
|
+
export declare function askArbitrator(name: string, summary: ArbitrationSummary, where: {
|
|
37
|
+
config: ZTCConfig;
|
|
38
|
+
cwd: string;
|
|
39
|
+
}): Promise<ArbitratorOutcome>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asking an arbitrator whether Main's exchange with an agent pane goes on (panes/reply_modes.ts): an HTTP(S) endpoint
|
|
3
|
+
* the person set up, POSTed the exchange's summary, or a model on Main's own route, asked a fixed prompt with the
|
|
4
|
+
* summary as data. Either answers {continue, reason}. A timeout, an error, or an answer that isn't such a decision comes
|
|
5
|
+
* back as no decision, with why, and the exchange stops.
|
|
6
|
+
*
|
|
7
|
+
* The arbitrator reads the summary and nothing else: no request it gets carries a credential of ZTC's, and the summary
|
|
8
|
+
* has none (arbitrationSummary takes them out). A model arbitrator is reached as Main reaches its own model, on its own
|
|
9
|
+
* route, but never on a subscription login (subscriptionRefusal).
|
|
10
|
+
*/
|
|
11
|
+
import { randomUUID } from 'node:crypto';
|
|
12
|
+
import { resolveAgentBackendFromConfig } from '../agent/factory.js';
|
|
13
|
+
import { isLocalSubscriptionProvider, normalizeProviderId } from '../agent/backends/provider_ids.js';
|
|
14
|
+
import { resolveCodexEffort } from '../config/defaults.js';
|
|
15
|
+
import { ARBITRATOR_SYSTEM_PROMPT, DEFAULT_ARBITRATOR_TIMEOUT_SECONDS, MAIN_MODEL_ARBITRATOR, answerPreview, arbitratorLabel, parseArbitratorAnswer, redactForArbitrator, replyModeSettings, } from './reply_modes.js';
|
|
16
|
+
/** The most an arbitrator's answer may hold, in bytes; a longer one is no decision. */
|
|
17
|
+
const ANSWER_MAX_BYTES = 16 * 1024;
|
|
18
|
+
/** The most a model arbitrator may write, in tokens. */
|
|
19
|
+
const MODEL_ANSWER_MAX_TOKENS = 300;
|
|
20
|
+
function seconds(ms) {
|
|
21
|
+
return `${Math.round(ms / 1000)} s`;
|
|
22
|
+
}
|
|
23
|
+
/** The body of RESPONSE as text, up to ANSWER_MAX_BYTES; null past it. */
|
|
24
|
+
async function boundedText(response) {
|
|
25
|
+
if (!response.body)
|
|
26
|
+
return '';
|
|
27
|
+
const reader = response.body.getReader();
|
|
28
|
+
const chunks = [];
|
|
29
|
+
let size = 0;
|
|
30
|
+
for (;;) {
|
|
31
|
+
const { done, value } = await reader.read();
|
|
32
|
+
if (done)
|
|
33
|
+
break;
|
|
34
|
+
size += value.byteLength;
|
|
35
|
+
if (size > ANSWER_MAX_BYTES) {
|
|
36
|
+
await reader.cancel().catch(() => { });
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
chunks.push(value);
|
|
40
|
+
}
|
|
41
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Ask the HTTP(S) arbitrator at URL: a POST of SUMMARY as JSON, with no credential of any kind and no redirect
|
|
45
|
+
* followed, which must answer 2xx with {continue, reason} within TIMEOUT_MS.
|
|
46
|
+
*/
|
|
47
|
+
export async function askHttpArbitrator(url, summary, timeoutMs) {
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
54
|
+
body: JSON.stringify(summary),
|
|
55
|
+
// A redirect could take the summary somewhere the person didn't choose.
|
|
56
|
+
redirect: 'manual',
|
|
57
|
+
signal: controller.signal,
|
|
58
|
+
});
|
|
59
|
+
if (response.status < 200 || response.status > 299) {
|
|
60
|
+
await response.body?.cancel().catch(() => { });
|
|
61
|
+
return { ok: false, why: `it answered HTTP ${response.status}` };
|
|
62
|
+
}
|
|
63
|
+
const text = await boundedText(response);
|
|
64
|
+
if (text === null)
|
|
65
|
+
return { ok: false, why: `its answer was longer than ${ANSWER_MAX_BYTES} bytes` };
|
|
66
|
+
const decision = parseArbitratorAnswer(text);
|
|
67
|
+
return decision ? { ok: true, decision }
|
|
68
|
+
: { ok: false, why: `its answer wasn't {"continue": true or false, "reason": "…"}: ${answerPreview(text)}` };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (controller.signal.aborted)
|
|
72
|
+
return { ok: false, why: `it didn't answer within ${seconds(timeoutMs)}` };
|
|
73
|
+
const message = error instanceof Error ? (error.cause instanceof Error ? error.cause.message : error.message) : String(error);
|
|
74
|
+
return { ok: false, why: `it couldn't be reached (${redactForArbitrator(message)})` };
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** The subscription logins, by the names /provider gives them. */
|
|
81
|
+
const SUBSCRIPTION_LABELS = {
|
|
82
|
+
codex_app_server: 'Codex CLI', codex_legacy: 'Codex Legacy', kimi_code: 'Kimi Code', 'kimi-code': 'Kimi Code',
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Why a model arbitrator on PROVIDER gives no decision, or null. A model arbitrator is a model asked a fixed prompt with
|
|
86
|
+
* no tools, which a subscription login (Codex CLI, Codex Legacy, Kimi Code) doesn't hold it to: Codex CLI's App Server
|
|
87
|
+
* runs a whole Codex agent, its native shell and patch tools included, in Main's sandbox with no approvals, and what it
|
|
88
|
+
* runs never reaches ZTC as a tool call. So ZTC builds nothing on one for an arbitrator, and asks it nothing.
|
|
89
|
+
*/
|
|
90
|
+
function subscriptionRefusal(provider) {
|
|
91
|
+
if (!provider || !isLocalSubscriptionProvider(provider))
|
|
92
|
+
return null;
|
|
93
|
+
const label = SUBSCRIPTION_LABELS[normalizeProviderId(provider)] ?? provider;
|
|
94
|
+
return `it runs on ${label}, and ZTC asks no subscription login to decide, since Codex CLI's agent runs tools of its own with no `
|
|
95
|
+
+ 'one to approve them; an arbitrator on another provider, set up in /settings → Panes, can';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Ask a model on Main's own route (ROUTE: its provider and model, or the ones ROUTE names) whether the exchange goes on:
|
|
99
|
+
* the fixed prompt ARBITRATOR_SYSTEM_PROMPT, SUMMARY as the user message's JSON, no tools, within TIMEOUT_MS. A route on
|
|
100
|
+
* a subscription login gives no decision (subscriptionRefusal).
|
|
101
|
+
*/
|
|
102
|
+
export async function askModelArbitrator(route, summary, timeoutMs) {
|
|
103
|
+
// The provider the arbitrator names, else Main's: a subscription login gets no backend built at all.
|
|
104
|
+
const named = subscriptionRefusal(route.provider ?? route.config.provider);
|
|
105
|
+
if (named)
|
|
106
|
+
return { ok: false, why: named };
|
|
107
|
+
const controller = new AbortController();
|
|
108
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
109
|
+
let backend;
|
|
110
|
+
const id = randomUUID();
|
|
111
|
+
try {
|
|
112
|
+
const resolved = resolveAgentBackendFromConfig({
|
|
113
|
+
config: route.config, cwd: route.cwd, sessionId: `reply-arbitrator-${id}`,
|
|
114
|
+
...(route.provider ? { provider: route.provider } : {}), ...(route.model ? { model: route.model } : {}),
|
|
115
|
+
});
|
|
116
|
+
if (!resolved)
|
|
117
|
+
return { ok: false, why: 'Main\'s route reaches no model to ask' };
|
|
118
|
+
backend = resolved.backend;
|
|
119
|
+
if (resolved.hostRuntime)
|
|
120
|
+
return { ok: false, why: 'Main runs on a host runtime, which ZTC can\'t ask anything of its own' };
|
|
121
|
+
// One the repository's own settings chose, or ZTC's default: built, never asked.
|
|
122
|
+
const resolvedRefusal = subscriptionRefusal(resolved.provider);
|
|
123
|
+
if (resolvedRefusal)
|
|
124
|
+
return { ok: false, why: resolvedRefusal };
|
|
125
|
+
let text = '';
|
|
126
|
+
for await (const event of backend.generateStream({
|
|
127
|
+
model: resolved.model,
|
|
128
|
+
system: ARBITRATOR_SYSTEM_PROMPT,
|
|
129
|
+
messages: [{ role: 'user', content: JSON.stringify(summary) }],
|
|
130
|
+
tools: [],
|
|
131
|
+
maxTokens: MODEL_ANSWER_MAX_TOKENS,
|
|
132
|
+
signal: controller.signal,
|
|
133
|
+
timeoutMs,
|
|
134
|
+
// One attempt: a transport retry would outlast the time the arbitrator has.
|
|
135
|
+
onTransportRetry: () => controller.abort(),
|
|
136
|
+
agentRunId: id,
|
|
137
|
+
routePlan: route.config.zrouterRoutePlan,
|
|
138
|
+
codexEffort: resolveCodexEffort(route.config, resolved.provider, resolved.model),
|
|
139
|
+
codexFastMode: route.config.codexFastMode,
|
|
140
|
+
})) {
|
|
141
|
+
if (controller.signal.aborted)
|
|
142
|
+
break;
|
|
143
|
+
if (event.type === 'tool_use_start')
|
|
144
|
+
return { ok: false, why: 'it called a tool instead of answering' };
|
|
145
|
+
if (event.type === 'text_delta') {
|
|
146
|
+
text += event.text;
|
|
147
|
+
if (Buffer.byteLength(text) > ANSWER_MAX_BYTES)
|
|
148
|
+
return { ok: false, why: `its answer was longer than ${ANSWER_MAX_BYTES} bytes` };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (controller.signal.aborted)
|
|
152
|
+
return { ok: false, why: `it didn't answer within ${seconds(timeoutMs)}` };
|
|
153
|
+
const decision = parseArbitratorAnswer(text);
|
|
154
|
+
return decision ? { ok: true, decision }
|
|
155
|
+
: { ok: false, why: `its answer wasn't {"continue": true or false, "reason": "…"}: ${answerPreview(text)}` };
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (controller.signal.aborted)
|
|
159
|
+
return { ok: false, why: `it didn't answer within ${seconds(timeoutMs)}` };
|
|
160
|
+
return { ok: false, why: `asking it failed (${redactForArbitrator(error instanceof Error ? error.message : String(error))})` };
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
clearTimeout(timer);
|
|
164
|
+
controller.abort();
|
|
165
|
+
backend?.close?.();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Ask the arbitrator NAME whether the exchange SUMMARY stands for goes on: "model", a model on Main's own route, or one
|
|
170
|
+
* the person set up in CONFIG (panes.replyArbitrators), with its own time to decide. A name no longer set up gives no
|
|
171
|
+
* decision.
|
|
172
|
+
*/
|
|
173
|
+
export async function askArbitrator(name, summary, where) {
|
|
174
|
+
const defaultMs = DEFAULT_ARBITRATOR_TIMEOUT_SECONDS * 1000;
|
|
175
|
+
if (name === MAIN_MODEL_ARBITRATOR)
|
|
176
|
+
return askModelArbitrator(where, summary, defaultMs);
|
|
177
|
+
const arbitrator = replyModeSettings(where.config.panes).arbitrators
|
|
178
|
+
.find(candidate => candidate.name === name);
|
|
179
|
+
if (!arbitrator)
|
|
180
|
+
return { ok: false, why: `no arbitrator named ${arbitratorLabel(name)} is set up any more` };
|
|
181
|
+
const timeoutMs = (arbitrator.timeoutSeconds ?? DEFAULT_ARBITRATOR_TIMEOUT_SECONDS) * 1000;
|
|
182
|
+
if (arbitrator.kind === 'http')
|
|
183
|
+
return askHttpArbitrator(arbitrator.url, summary, timeoutMs);
|
|
184
|
+
return askModelArbitrator({ ...where, ...(arbitrator.provider ? { provider: arbitrator.provider } : {}), model: arbitrator.model }, summary, timeoutMs);
|
|
185
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reply modes: how Main, the ZTC that runs a workspace, answers a Claude Code or Codex pane by itself.
|
|
3
|
+
*
|
|
4
|
+
* Main answers such a pane's message once the work on it ends ("[Answer from Main (pane 0)] …"), and the agent in the
|
|
5
|
+
* pane may answer that, so two agents could go on answering each other with nobody watching. An exchange is that run of
|
|
6
|
+
* messages back and forth between Main and one pane. The pane that starts it, an agent pane with workspace-mcp's
|
|
7
|
+
* send_message or Main with its model's send_message or ask_ztc_pane, chooses with that message how Main answers in it:
|
|
8
|
+
* 'uncapped': every message;
|
|
9
|
+
* { capped: N }: N automatic answers with no message from the person in Main, the last saying so, then none until
|
|
10
|
+
* the person's next message in Main or a different mode from the pane that started it;
|
|
11
|
+
* { arbitrator: NAME }: before each automatic answer after the first, an arbitrator the person set up in /settings
|
|
12
|
+
* (or "model", a model on Main's own route) decides whether the exchange goes on; a timeout, an error or an answer
|
|
13
|
+
* that isn't such a decision stops it.
|
|
14
|
+
* A message that names no mode takes the person's default (/settings → Panes → Agent reply mode, capped at 5 until they
|
|
15
|
+
* change it). A mode from the pane that didn't start the exchange is not applied, and its sender is told so. Only an
|
|
16
|
+
* arbitrator the person set up can be named, so an agent can't send the conversation to a URL of its own.
|
|
17
|
+
*/
|
|
18
|
+
import type { AgentReplyMode, PanesSettings, ReplyArbitratorSetting, ZTCConfig } from '../config/types.js';
|
|
19
|
+
/** How Main answers the other pane in an exchange by itself; see the module comment. */
|
|
20
|
+
export type ReplyMode = AgentReplyMode;
|
|
21
|
+
/**
|
|
22
|
+
* The person's default until they choose one: capped at 5. Five automatic answers carry a request, a follow-up and its
|
|
23
|
+
* answer, and a check or two, so ordinary orchestration finishes without the person; a pair of agents stuck answering
|
|
24
|
+
* each other costs at most five turns of each before it stops and says so, where uncapped would run until someone
|
|
25
|
+
* noticed; and an arbitrator needs one set up, and costs a decision before every answer after the first.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_REPLY_MODE: ReplyMode;
|
|
28
|
+
/** The largest cap a capped mode takes; "uncapped" is the mode for more. */
|
|
29
|
+
export declare const MAX_REPLY_CAP = 100;
|
|
30
|
+
/** The arbitrator every agent may name: a model on Main's own route, its provider and its model, asked a fixed prompt. */
|
|
31
|
+
export declare const MAIN_MODEL_ARBITRATOR = "model";
|
|
32
|
+
/** How long an arbitrator has to decide, unless the person set another time for it. */
|
|
33
|
+
export declare const DEFAULT_ARBITRATOR_TIMEOUT_SECONDS = 20;
|
|
34
|
+
/** The longest time the person can give an arbitrator to decide. */
|
|
35
|
+
export declare const MAX_ARBITRATOR_TIMEOUT_SECONDS = 120;
|
|
36
|
+
/**
|
|
37
|
+
* An arbitrator the person set up in /settings, by the name an agent's reply mode names it by: a model on Main's own
|
|
38
|
+
* route (its provider, Main's unless given, and model), or an HTTP(S) endpoint that answers a POST of the exchange's
|
|
39
|
+
* summary with {continue, reason}. TIMEOUT_SECONDS: how long it has to decide (default 20).
|
|
40
|
+
*/
|
|
41
|
+
export type ReplyArbitratorConfig = ReplyArbitratorSetting;
|
|
42
|
+
/** A reply mode, or an arbitrator, that can't be used, in words its sender can act on. */
|
|
43
|
+
export declare class ReplyModeError extends Error {
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* VALUE as a reply mode: "uncapped", {capped: N} or {arbitrator: NAME}, or the same written as text ("capped 5",
|
|
47
|
+
* "capped:5", "arbitrator judge", or the JSON). Anything else throws a ReplyModeError that says what a mode is.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseReplyMode(value: unknown): ReplyMode;
|
|
50
|
+
/** Whether A and B are the same mode. */
|
|
51
|
+
export declare function sameReplyMode(a: ReplyMode, b: ReplyMode): boolean;
|
|
52
|
+
/** MODE in words: "uncapped", "capped at 5", or "arbitrated by "judge"". */
|
|
53
|
+
export declare function describeReplyMode(mode: ReplyMode): string;
|
|
54
|
+
/** MODE as /settings shows and takes it: "uncapped", "capped 5" or "arbitrator judge". */
|
|
55
|
+
export declare function formatReplyModeSetting(mode: ReplyMode): string;
|
|
56
|
+
/**
|
|
57
|
+
* URL as an HTTP arbitrator's endpoint: https, or http to this computer only (localhost, 127.0.0.1, ::1), so the
|
|
58
|
+
* exchange's summary never crosses a network in the clear; and no user name or password in it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseArbitratorUrl(value: unknown): string;
|
|
61
|
+
/**
|
|
62
|
+
* ENTRY as an arbitrator the person set up: a name (not "model", which is Main's own model's) and either a model
|
|
63
|
+
* (with an optional provider) or an HTTP(S) URL, and an optional timeout. Throws a ReplyModeError that says what is
|
|
64
|
+
* wrong.
|
|
65
|
+
*/
|
|
66
|
+
export declare function parseReplyArbitrator(entry: unknown): ReplyArbitratorConfig;
|
|
67
|
+
/** The person's reply-mode settings: the default mode and the arbitrators they set up, as saved (unreadable ones left out). */
|
|
68
|
+
export interface ReplyModeSettings {
|
|
69
|
+
mode: ReplyMode;
|
|
70
|
+
arbitrators: ReplyArbitratorConfig[];
|
|
71
|
+
}
|
|
72
|
+
/** The reply-mode settings PANES saves: panes.agentReplyMode (DEFAULT_REPLY_MODE when unset) and panes.replyArbitrators. */
|
|
73
|
+
export declare function replyModeSettings(panes: PanesSettings | undefined): ReplyModeSettings;
|
|
74
|
+
/**
|
|
75
|
+
* Why MODE can't be used, or null: an arbitrator it names must be "model" or one of ARBITRATORS, the ones the person set
|
|
76
|
+
* up, so no agent can have the conversation sent anywhere the person didn't choose.
|
|
77
|
+
*/
|
|
78
|
+
export declare function replyModeRefusal(mode: ReplyMode, arbitrators: readonly ReplyArbitratorConfig[]): string | null;
|
|
79
|
+
/** Which side of an exchange a message comes from: Main, or the agent pane it answers. */
|
|
80
|
+
export type ExchangeSide = 'main' | 'pane';
|
|
81
|
+
/**
|
|
82
|
+
* Why an exchange stopped: its cap (ANSWERS: the automatic answers it had when a cap lowered below them stopped it), an
|
|
83
|
+
* arbitrator's decision, or an arbitrator that gave none.
|
|
84
|
+
*/
|
|
85
|
+
export type ExchangeStop = {
|
|
86
|
+
why: 'cap';
|
|
87
|
+
cap: number;
|
|
88
|
+
answers?: number;
|
|
89
|
+
} | {
|
|
90
|
+
why: 'arbitrator';
|
|
91
|
+
arbitrator: string;
|
|
92
|
+
reason: string;
|
|
93
|
+
} | {
|
|
94
|
+
why: 'arbitrator_failed';
|
|
95
|
+
arbitrator: string;
|
|
96
|
+
error: string;
|
|
97
|
+
};
|
|
98
|
+
/** A message of an exchange, as an arbitrator reads it. */
|
|
99
|
+
export interface ExchangeMessage {
|
|
100
|
+
from: ExchangeSide;
|
|
101
|
+
text: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* An exchange as it stands: the side that started it, its mode (the one that side set, or the person's default, read
|
|
105
|
+
* as it is now: EXPLICIT says which), the automatic answers Main has sent in it since the person's last message in Main
|
|
106
|
+
* or the last change of mode, and why it stopped, if it has.
|
|
107
|
+
*/
|
|
108
|
+
export interface ExchangeView {
|
|
109
|
+
originator: ExchangeSide;
|
|
110
|
+
mode: ReplyMode;
|
|
111
|
+
explicit: boolean;
|
|
112
|
+
answers: number;
|
|
113
|
+
stopped: ExchangeStop | null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* What a message did to its exchange: STARTED it; RESET it (a different mode from the side that started it, which
|
|
117
|
+
* starts the count again and ends a stop); carried a mode that was not applied (IGNORED, from the side that didn't start
|
|
118
|
+
* it); and, for the pane's message, whether Main HOLDS it for the person, its exchange having stopped.
|
|
119
|
+
*/
|
|
120
|
+
export interface ExchangeArrival {
|
|
121
|
+
started: boolean;
|
|
122
|
+
reset: boolean;
|
|
123
|
+
ignored: ReplyMode | null;
|
|
124
|
+
held: boolean;
|
|
125
|
+
view: ExchangeView;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* What Main may do with its next automatic answer to a pane: SEND it, the NUMBER-th of the exchange (LAST: its cap's,
|
|
129
|
+
* which says so); ask the arbitrator its mode names first (ARBITRATE: about the exchange's count EPOCH, which
|
|
130
|
+
* ReplyExchanges.isCurrent says still stands, or not once the count starts again); or WITHHOLD it, the exchange having
|
|
131
|
+
* stopped (LOWERED: just now, at a cap the person's default was lowered to, below the answers it had had).
|
|
132
|
+
*/
|
|
133
|
+
export type AnswerGate = {
|
|
134
|
+
kind: 'send';
|
|
135
|
+
number: number;
|
|
136
|
+
last: boolean;
|
|
137
|
+
view: ExchangeView;
|
|
138
|
+
} | {
|
|
139
|
+
kind: 'arbitrate';
|
|
140
|
+
number: number;
|
|
141
|
+
arbitrator: string;
|
|
142
|
+
view: ExchangeView;
|
|
143
|
+
epoch: number;
|
|
144
|
+
} | {
|
|
145
|
+
kind: 'withhold';
|
|
146
|
+
view: ExchangeView;
|
|
147
|
+
lowered?: true;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Main's exchanges with the agent panes it answers by itself, by pane. DEFAULT_MODE reads the person's default as it is
|
|
151
|
+
* at the moment, so an exchange started without a mode follows a change of it.
|
|
152
|
+
*/
|
|
153
|
+
export declare class ReplyExchanges {
|
|
154
|
+
private readonly defaultMode;
|
|
155
|
+
private readonly exchanges;
|
|
156
|
+
/** The last count any exchange started (ExchangeState.epoch), so no two counts are told apart by chance. */
|
|
157
|
+
private epochs;
|
|
158
|
+
constructor(defaultMode: () => ReplyMode);
|
|
159
|
+
private viewOf;
|
|
160
|
+
/** The exchange with pane PANE_ID, if there is one. */
|
|
161
|
+
view(paneId: number): ExchangeView | null;
|
|
162
|
+
/** The messages of the exchange with pane PANE_ID kept for an arbitrator, oldest first. */
|
|
163
|
+
recent(paneId: number): readonly ExchangeMessage[];
|
|
164
|
+
/** What a message from SIDE in the exchange with pane PANE_ID, with MODE or none, would do; nothing changes. */
|
|
165
|
+
preview(side: ExchangeSide, paneId: number, mode?: ReplyMode): ExchangeArrival;
|
|
166
|
+
/** A message from SIDE (TEXT, with MODE or none) in the exchange with pane PANE_ID: what it did to the exchange. */
|
|
167
|
+
arrive(side: ExchangeSide, paneId: number, text: string, mode?: ReplyMode): ExchangeArrival;
|
|
168
|
+
private arrival;
|
|
169
|
+
private remember;
|
|
170
|
+
/** What Main may do with its next automatic answer to pane PANE_ID (an exchange it hasn't one with starts as the pane's). */
|
|
171
|
+
gate(paneId: number): AnswerGate;
|
|
172
|
+
/**
|
|
173
|
+
* Whether the exchange with pane PANE_ID is still on the count EPOCH (a gate's): not once its count has started again,
|
|
174
|
+
* by the person's message or a reset, nor once the pane closed, so a decision about that count no longer applies.
|
|
175
|
+
*/
|
|
176
|
+
isCurrent(paneId: number, epoch: number): boolean;
|
|
177
|
+
/** Main sent pane PANE_ID an automatic answer (TEXT). */
|
|
178
|
+
answered(paneId: number, text: string): void;
|
|
179
|
+
/** The exchange with pane PANE_ID stopped (WHY): Main sends it no more automatic answers until it is reset. */
|
|
180
|
+
stop(paneId: number, why: ExchangeStop): void;
|
|
181
|
+
/**
|
|
182
|
+
* The person sent Main a message of their own: every exchange starts its count again and goes on, keeping its mode.
|
|
183
|
+
* Returns the panes whose exchange had stopped.
|
|
184
|
+
*/
|
|
185
|
+
person(): number[];
|
|
186
|
+
/** Pane PANE_ID closed: its exchange ends, and a pane that takes its number starts a new one. */
|
|
187
|
+
closed(paneId: number): void;
|
|
188
|
+
}
|
|
189
|
+
/** How many of an exchange's messages an arbitrator reads, the latest. */
|
|
190
|
+
export declare const ARBITRATION_MESSAGES = 6;
|
|
191
|
+
/** The most characters of each message an arbitrator reads. */
|
|
192
|
+
export declare const ARBITRATION_MESSAGE_CHARS = 600;
|
|
193
|
+
/**
|
|
194
|
+
* What an arbitrator reads of an exchange, and nothing else: the two panes' names (the one that answers by itself
|
|
195
|
+
* first), how many automatic answers Main has sent in it so far, and its last ARBITRATION_MESSAGES messages, each cut
|
|
196
|
+
* to ARBITRATION_MESSAGE_CHARS characters, credentials taken out; the last is the answer Main is about to send.
|
|
197
|
+
*/
|
|
198
|
+
export interface ArbitrationSummary {
|
|
199
|
+
panes: [string, string];
|
|
200
|
+
automaticAnswers: number;
|
|
201
|
+
messages: Array<{
|
|
202
|
+
from: string;
|
|
203
|
+
text: string;
|
|
204
|
+
}>;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The credentials an arbitrator must never read, as CONFIG and ENV hold them: saved API keys and tokens, the Anthropic
|
|
208
|
+
* key the move off the retired routes kept, the hosted native Router's token, every value of an MCP server's environment
|
|
209
|
+
* and headers (which a server is given only for itself, its tokens among them), and the values of environment variables
|
|
210
|
+
* named like a key, token, secret or password; and HELD, those ZTC keeps outside its settings (its Zerg Router
|
|
211
|
+
* sign-in). Short values are left out (they would match ordinary words).
|
|
212
|
+
*/
|
|
213
|
+
export declare function knownSecrets(config: ZTCConfig, env?: NodeJS.ProcessEnv, held?: readonly (string | undefined)[]): string[];
|
|
214
|
+
/**
|
|
215
|
+
* TEXT with the credentials in it taken out: each of SECRETS where it appears, bearer tokens, `key: value` credential
|
|
216
|
+
* pairs, and words with a known API key prefix.
|
|
217
|
+
*/
|
|
218
|
+
export declare function redactForArbitrator(text: string, secrets?: readonly string[]): string;
|
|
219
|
+
/** The summary an arbitrator reads of an exchange (ArbitrationSummary) between MAIN and PANE, by their names. */
|
|
220
|
+
export declare function arbitrationSummary(names: {
|
|
221
|
+
main: string;
|
|
222
|
+
pane: string;
|
|
223
|
+
}, automaticAnswers: number, messages: readonly ExchangeMessage[], secrets?: readonly string[]): ArbitrationSummary;
|
|
224
|
+
/** An arbitrator's decision: whether the exchange goes on, and why, in a line. */
|
|
225
|
+
export interface ArbitratorDecision {
|
|
226
|
+
continue: boolean;
|
|
227
|
+
reason: string;
|
|
228
|
+
}
|
|
229
|
+
/** What asking an arbitrator came to: its decision, or why it gave none (it timed out, failed, or answered something else). */
|
|
230
|
+
export type ArbitratorOutcome = {
|
|
231
|
+
ok: true;
|
|
232
|
+
decision: ArbitratorDecision;
|
|
233
|
+
} | {
|
|
234
|
+
ok: false;
|
|
235
|
+
why: string;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* TEXT as an arbitrator's decision: a JSON object with a boolean "continue" and a string "reason" (a code fence around
|
|
239
|
+
* it is allowed); null for anything else.
|
|
240
|
+
*/
|
|
241
|
+
export declare function parseArbitratorAnswer(text: string): ArbitratorDecision | null;
|
|
242
|
+
/** A short, one-line spelling of an answer that wasn't a decision, for the reason the exchange stopped. */
|
|
243
|
+
export declare function answerPreview(text: string): string;
|
|
244
|
+
/**
|
|
245
|
+
* The fixed prompt a model arbitrator is asked with. The summary comes as the user message, as JSON: data to judge,
|
|
246
|
+
* never instructions.
|
|
247
|
+
*/
|
|
248
|
+
export declare const ARBITRATOR_SYSTEM_PROMPT: string;
|
|
249
|
+
/** The arbitrator NAME as Main's words name it. */
|
|
250
|
+
export declare function arbitratorLabel(name: string): string;
|
|
251
|
+
/** The note that ends the answer that is an exchange's last under its cap, in the agent pane. */
|
|
252
|
+
export declare function capNoteForPane(view: ExchangeView, main: string, number: number): string;
|
|
253
|
+
/** What pane 0 says when an exchange reaches its cap. */
|
|
254
|
+
export declare function capStopNotice(view: ExchangeView, main: string, pane: string, paneId: number, cap: number): string;
|
|
255
|
+
/** What pane 0 says when a cap the person lowered below an exchange's answers stops it, at Main's answer NUMBER. */
|
|
256
|
+
export declare function capLoweredNotice(view: ExchangeView, main: string, pane: string, paneId: number, number: number): string;
|
|
257
|
+
/** The line an agent pane hears instead of Main's answer NUMBER when a cap lowered below the exchange's answers stopped it. */
|
|
258
|
+
export declare function capLoweredStopForPane(view: ExchangeView, main: string, number: number): string;
|
|
259
|
+
/** What pane 0 says of an arbitrator's decision, or of its giving none (OUTCOME), before answer NUMBER. */
|
|
260
|
+
export declare function arbitrationNotice(view: ExchangeView, arbitrator: string, outcome: ArbitratorOutcome, main: string, pane: string, paneId: number, number: number): string;
|
|
261
|
+
/**
|
|
262
|
+
* What pane 0 says of an arbitrator's decision (OUTCOME) about answer NUMBER that came once the exchange's count had
|
|
263
|
+
* started again (the person's message, or a new mode from the side that started it): it doesn't apply.
|
|
264
|
+
*/
|
|
265
|
+
export declare function staleArbitrationNotice(arbitrator: string, outcome: ArbitratorOutcome, main: string, pane: string, paneId: number, number: number): string;
|
|
266
|
+
/** The line an agent pane hears instead of answer NUMBER when an arbitrator stopped the exchange, or gave no decision. */
|
|
267
|
+
export declare function arbitrationStopForPane(view: ExchangeView, arbitrator: string, outcome: ArbitratorOutcome, main: string, number: number): string;
|
|
268
|
+
/** What pane 0 says of a message from an agent pane that came after its exchange stopped: Main holds it for the person. */
|
|
269
|
+
export declare function heldNotice(main: string, pane: string, paneId: number, text: string): string;
|
|
270
|
+
/** What an agent pane's send_message says of a message Main holds for the person (heldNotice). */
|
|
271
|
+
export declare function heldNoticeForPane(view: ExchangeView, main: string): string;
|
|
272
|
+
/** What pane 0 says of an answer Main didn't send since the exchange had stopped. */
|
|
273
|
+
export declare function withheldNotice(view: ExchangeView, main: string, pane: string, paneId: number): string;
|
|
274
|
+
/** What pane 0 says when the person's message resumes Main's answers to PANE, with a message it held (HELD) or none. */
|
|
275
|
+
export declare function resumedNotice(main: string, pane: string, paneId: number, held: boolean): string;
|
|
276
|
+
/**
|
|
277
|
+
* What a sender's tool says of the mode its message carried, as ARRIVAL has it: the exchange it started or is in, and
|
|
278
|
+
* its mode, or why the mode it gave wasn't applied. OTHER names the other side of the exchange; MAIN names Main.
|
|
279
|
+
*/
|
|
280
|
+
export declare function arrivalNote(arrival: ExchangeArrival, other: string, main: string): string;
|
|
281
|
+
/**
|
|
282
|
+
* What a message Main's model sends a Claude Code or Codex pane does to their exchange, for the ZTC that answers it:
|
|
283
|
+
* REFUSAL says why MODE can't be used (an arbitrator the person didn't set up), ANSWERS whether pane TO is one Main
|
|
284
|
+
* answers by itself, and SENT records the message (TEXT, with MODE or none) and says what it did to the exchange.
|
|
285
|
+
* Main's bus transport carries it (BusTransport.replyModes); a ZTC that answers no pane has none.
|
|
286
|
+
*/
|
|
287
|
+
export interface ReplyModeHost {
|
|
288
|
+
refusal(mode: ReplyMode): string | null;
|
|
289
|
+
answers(to: number): boolean;
|
|
290
|
+
sent(to: number, text: string, mode: ReplyMode | undefined): string;
|
|
291
|
+
}
|