@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
|
@@ -1,73 +1,330 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/claude` and `/codex` — open the user's own Claude Code or Codex in a new
|
|
3
|
-
* pane, in this pane's directory.
|
|
3
|
+
* pane, in this pane's directory, or resume one of their own sessions.
|
|
4
4
|
*
|
|
5
5
|
* The CLI signs in with the user's own account through its own flow; ZTC only
|
|
6
6
|
* runs it, unmodified, and attaches its workspace MCP server so the agent can
|
|
7
7
|
* open, read, type into and message other panes. Plain text after the command
|
|
8
8
|
* is the opening prompt; text starting with a flag is the CLI's arguments.
|
|
9
|
+
*
|
|
10
|
+
* `resume`, `continue`, `fork`, `sessions` and `show-resumable` resume the
|
|
11
|
+
* person's sessions (panes/agent_cli.ts's parseAgentCommand): one by id opens
|
|
12
|
+
* in its own folder, on the sign-in whose store holds it (panes/agent_resume.ts).
|
|
13
|
+
* They are the person's alone: an agent's or relayed input's are refused before
|
|
14
|
+
* anything is read, and only Main, which has the sessions controller, reads the
|
|
15
|
+
* stores. What is said about a session is shown in this terminal only
|
|
16
|
+
* (localOnly) and never saved (ephemeral); with panes, which may read Main's
|
|
17
|
+
* screen, it names no session, folder or prompt (openedSessionLine), and only
|
|
18
|
+
* the command printed to run elsewhere, where there are none, names them.
|
|
9
19
|
*/
|
|
10
20
|
import { getMuxTransport } from '../tools/pane.js';
|
|
11
21
|
import { ToolCapability } from '../runtime/capabilities.js';
|
|
12
|
-
import { AGENT_CLIS,
|
|
22
|
+
import { AGENT_CLIS, claudeResumeFlagId, findAgentCli, parseAgentCommand, workspaceMcpProgram, } from '../../panes/agent_cli.js';
|
|
13
23
|
import { openAgentPane } from '../../panes/agent_panes.js';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
import { openAgentSessionPanes } from '../../panes/agent_pane_sessions.js';
|
|
25
|
+
import { continueLaunchPlan, elsewhereCommandLine, homeRelative, nameLaunchPlan, openResumedAgentPane, openedSessionLine, resumeLaunchPlan, shownAgentCommand as shownCommand, } from '../../panes/agent_resume.js';
|
|
26
|
+
/** An id's first characters, as the picker's footer shows them: eight hex digits, and more of the id if typed. */
|
|
27
|
+
const ID_START = /^[0-9a-f]{8}[0-9a-f-]*$/i;
|
|
28
|
+
/** A line about the person's sessions: shown in this terminal only and never saved with the session. */
|
|
29
|
+
const LOCAL_LINE = { ephemeral: true, localOnly: true };
|
|
30
|
+
/** What each CLI's own words are where ZTC points the person to them. */
|
|
31
|
+
function ownResume(id) {
|
|
32
|
+
return id === 'claude' ? `/claude --resume <id> opens Claude Code's own resume in this folder.` : `Codex's own /resume, in a /codex pane, lists them.`;
|
|
18
33
|
}
|
|
19
34
|
export function createAgentCliCommand(id, deps = {}) {
|
|
20
35
|
const spec = AGENT_CLIS[id];
|
|
21
36
|
const account = id === 'claude' ? 'Claude' : 'ChatGPT';
|
|
37
|
+
const say = (ctx, content, local = false) => {
|
|
38
|
+
ctx.addMessage({ role: 'system', content, ...(local ? { metadata: { ...LOCAL_LINE } } : {}) });
|
|
39
|
+
};
|
|
40
|
+
const env = () => (deps.env ?? (() => process.env))();
|
|
41
|
+
const findBinary = deps.findBinary ?? findAgentCli;
|
|
42
|
+
const paneDeps = () => ({
|
|
43
|
+
findBinary,
|
|
44
|
+
server: (deps.server ?? workspaceMcpProgram)(),
|
|
45
|
+
env: env(),
|
|
46
|
+
...(deps.motsi ? { motsi: deps.motsi() } : {}),
|
|
47
|
+
});
|
|
48
|
+
const noPanes = (command) => `/${id} opens ${spec.label} in a pane, which needs ZTC's panes: start ZTC with zmux (plain \`ztc\`) or use `
|
|
49
|
+
+ `the desktop app. You can also run \`${command}\` in another terminal.`;
|
|
50
|
+
/** Where ZTC looked for a session, for the message that it isn't there. */
|
|
51
|
+
const searched = (sessions) => {
|
|
52
|
+
const { ownDir, profiles } = sessions.describeStores(id);
|
|
53
|
+
const own = homeRelative(id === 'claude' ? ownDir : `${ownDir}/sessions`, sessions.home);
|
|
54
|
+
return profiles.length > 0 ? `${own} or your ZTC profiles (${profiles.join(', ')})` : own;
|
|
55
|
+
};
|
|
56
|
+
/** That an id is in none of the stores ZTC reads, and the session folders it didn't follow because they are links. */
|
|
57
|
+
const unknownSession = async (sessions) => {
|
|
58
|
+
const links = (await sessions.linkedFolders(id)).map(path => homeRelative(path, sessions.home));
|
|
59
|
+
const linked = links.length === 0 ? ''
|
|
60
|
+
: ` ZTC doesn't follow symbolic links in session stores, and ${links.join(', ')} ${links.length === 1 ? 'is one' : 'are'}.`;
|
|
61
|
+
return `ZTC found no ${spec.label} session with that id in ${searched(sessions)}.${linked}${id === 'claude'
|
|
62
|
+
? ' Claude Code deletes sessions after 30 days unless cleanupPeriodDays says otherwise. To have Claude Code look from this folder: /claude --resume <id>.'
|
|
63
|
+
: ' To have Codex look itself, open /codex and use its own /resume.'}`;
|
|
64
|
+
};
|
|
65
|
+
const whose = (profile) => (profile === null ? `this computer's own ${spec.label} sign-in` : `@${profile}'s store`);
|
|
66
|
+
/** The command line that runs the plan's CLI elsewhere, on the plan's sign-in, as its pane would sign in. */
|
|
67
|
+
const elsewhere = (plan, sessions) => {
|
|
68
|
+
const signIn = sessions.signInFor(id, plan.profile ?? null);
|
|
69
|
+
return elsewhereCommandLine(plan, signIn.dir, { profile: signIn.profile });
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Open a plan's pane as the person's, and say so in this terminal. With panes, other panes and their agents may read
|
|
73
|
+
* Main's screen, so the line names the pane and nothing of the session, its folder or its prompt; with none, nothing
|
|
74
|
+
* else can read it, and the command to run elsewhere is printed whole.
|
|
75
|
+
*/
|
|
76
|
+
const openPlan = async (ctx, plan, how, sessions) => {
|
|
77
|
+
const transport = (deps.transport ?? getMuxTransport)();
|
|
78
|
+
if (!transport) {
|
|
79
|
+
// A plan whose sign-in is known prints it; continue and a name without @profile start on the one new panes do.
|
|
80
|
+
say(ctx, sessions && plan.profile !== undefined ? elsewhere(plan, sessions) : noPanes(shownCommand(spec.binary, plan.request)), true);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const opened = await openResumedAgentPane(transport, plan, { ...paneDeps(), ...(sessions ? { profilesHome: sessions.home } : {}) });
|
|
84
|
+
if (opened.error) {
|
|
85
|
+
say(ctx, opened.error, true);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
say(ctx, openedSessionLine(opened, how), true);
|
|
89
|
+
if (opened.notice)
|
|
90
|
+
say(ctx, opened.notice, true);
|
|
91
|
+
};
|
|
92
|
+
/** One session by id: looked up in the person's stores, then opened in its folder on its store's sign-in. */
|
|
93
|
+
const resumeById = async (ctx, sessions, parsed) => {
|
|
94
|
+
const matches = await sessions.find(id, parsed.id, { cwd: ctx.shell.getCwd() });
|
|
95
|
+
let target;
|
|
96
|
+
if (parsed.profile !== undefined) {
|
|
97
|
+
const mine = matches.find(match => match.profile === parsed.profile);
|
|
98
|
+
if (!mine) {
|
|
99
|
+
say(ctx, matches.length > 0
|
|
100
|
+
? `That session isn't one of @${parsed.profile}'s: it's in ${whose(matches[0].profile)}. Without @${parsed.profile}, the same command opens it there.`
|
|
101
|
+
: await unknownSession(sessions), true);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
target = mine;
|
|
105
|
+
}
|
|
106
|
+
else if (matches.length === 0) {
|
|
107
|
+
say(ctx, await unknownSession(sessions), true);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
else if (matches.length > 1) {
|
|
111
|
+
const named = matches.map(match => (match.profile === null ? "this computer's own" : `@${match.profile}`));
|
|
112
|
+
const example = matches.find(match => match.profile !== null).profile;
|
|
113
|
+
say(ctx, `That ${spec.label} session is in ${matches.length === 2 ? 'two' : matches.length} sign-ins' stores: `
|
|
114
|
+
+ `${named.slice(0, -1).join(', ')} and ${named.at(-1)}. Put @${example} before ${parsed.mode} to open @${example}'s; `
|
|
115
|
+
+ `/${id} resume lists ${matches.length === 2 ? 'both' : 'them all'}.`, true);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
target = matches[0];
|
|
120
|
+
}
|
|
121
|
+
await resumeTarget(ctx, sessions, target, parsed);
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* A session found in the person's stores, opened in its folder on its store's sign-in, or gone to where it is already
|
|
125
|
+
* open in a pane: two CLIs writing one session would interleave it. A fork makes a new one.
|
|
126
|
+
*/
|
|
127
|
+
const resumeTarget = async (ctx, sessions, target, parsed) => {
|
|
128
|
+
const transport = (deps.transport ?? getMuxTransport)();
|
|
129
|
+
if (parsed.mode === 'resume' && transport) {
|
|
130
|
+
const pane = (await openAgentSessionPanes(transport)).get(`${id}:${target.id}`);
|
|
131
|
+
if (pane !== undefined) {
|
|
132
|
+
transport.send({ type: 'focus_pane', pane_id: pane });
|
|
133
|
+
say(ctx, `That ${spec.label} session is already open in pane ${pane}.`, true);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Asked off the event loop, with a deadline: a folder that doesn't answer counts as gone.
|
|
138
|
+
const exists = !parsed.here && target.cwd !== null && target.folderVerified ? await sessions.folderExists(target.cwd) : false;
|
|
139
|
+
const planned = resumeLaunchPlan(target, {
|
|
140
|
+
mode: parsed.mode,
|
|
141
|
+
here: parsed.here,
|
|
142
|
+
cwdNow: ctx.shell.getCwd(),
|
|
143
|
+
...(parsed.prompt ? { prompt: parsed.prompt } : {}),
|
|
144
|
+
folderExists: () => exists,
|
|
145
|
+
});
|
|
146
|
+
if ('error' in planned) {
|
|
147
|
+
say(ctx, planned.error === 'folder-gone'
|
|
148
|
+
? `That ${spec.label} session's folder no longer exists. To ${parsed.mode} it in this folder instead, add --here to the command.`
|
|
149
|
+
: `ZTC can't tell which folder that ${spec.label} session works in. To ${parsed.mode} it in this folder, add --here to the command.`, true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
await openPlan(ctx, planned.plan, parsed.mode, sessions);
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* A launch as before. The person's own Claude Code `--resume <id>` is looked up first, when Main can: found in one
|
|
156
|
+
* store, the pane opens in the session's folder on that store's sign-in (an explicit @profile wins); otherwise the
|
|
157
|
+
* words are used as typed, in this folder, and a notice says why.
|
|
158
|
+
*/
|
|
159
|
+
const launch = async (ctx, request) => {
|
|
160
|
+
const transport = (deps.transport ?? getMuxTransport)();
|
|
161
|
+
if (!transport) {
|
|
162
|
+
say(ctx, noPanes(spec.binary));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const byPerson = ctx.commandOrigin !== 'agent' && ctx.commandOrigin !== 'relayed';
|
|
166
|
+
const sessions = ctx.agentSessions;
|
|
167
|
+
const flagged = id === 'claude' && byPerson && sessions && !env().MOTSI_TERMINAL_ID ? claudeResumeFlagId(request.words) : null;
|
|
168
|
+
// Already open in a pane: gone to, as /claude resume <id> goes, unless the words fork it into a new session.
|
|
169
|
+
if (flagged && !request.words.includes('--fork-session')) {
|
|
170
|
+
const pane = (await openAgentSessionPanes(transport)).get(`${id}:${flagged}`);
|
|
171
|
+
if (pane !== undefined) {
|
|
172
|
+
transport.send({ type: 'focus_pane', pane_id: pane });
|
|
173
|
+
say(ctx, `That ${spec.label} session is already open in pane ${pane}.`, true);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
let cwd = ctx.shell.getCwd();
|
|
178
|
+
let profile;
|
|
179
|
+
const notices = [];
|
|
180
|
+
if (flagged && sessions) {
|
|
181
|
+
const matches = (await sessions.find(id, flagged, { cwd })).filter(match => request.profile === undefined || match.profile === request.profile);
|
|
182
|
+
if (matches.length === 1) {
|
|
183
|
+
const match = matches[0];
|
|
184
|
+
profile = request.profile ?? match.profile;
|
|
185
|
+
if (match.cwd !== null && match.folderVerified && await sessions.folderExists(match.cwd))
|
|
186
|
+
cwd = match.cwd;
|
|
187
|
+
else
|
|
188
|
+
notices.push(`ZTC can't find that ${spec.label} session's folder, so it resumes in this one.`);
|
|
189
|
+
}
|
|
190
|
+
else if (matches.length === 0) {
|
|
191
|
+
notices.push(`ZTC found no ${spec.label} session with that id in ${searched(sessions)}, so Claude Code looks for it itself, from this folder.`);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
notices.push(`That ${spec.label} session is in ${matches.length} sign-ins' stores, so it opens as typed, in this folder; put @<profile> first to choose one.`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const result = await openAgentPane(transport, {
|
|
198
|
+
cli: id,
|
|
199
|
+
request,
|
|
200
|
+
cwd,
|
|
201
|
+
...paneDeps(),
|
|
202
|
+
...(profile !== undefined ? { profile, ...(sessions ? { profilesHome: sessions.home } : {}) } : {}),
|
|
203
|
+
// The ztc_command tool runs commands as the agent ('agent'). What the person types in a ZTC pane reaches it as
|
|
204
|
+
// relayed input, so relayed is theirs here: what else types there (write_terminal_pane, a pane's message) is
|
|
205
|
+
// an agent already allowed to run commands, or a pane that can open a shell of its own.
|
|
206
|
+
openedBy: ctx.commandOrigin === 'agent' ? 'agent' : 'person',
|
|
207
|
+
});
|
|
208
|
+
const local = flagged !== null;
|
|
209
|
+
if (result.error) {
|
|
210
|
+
say(ctx, result.error, local);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// The person's own --resume <id>, looked up: as for any resumed session, the line names nothing of it.
|
|
214
|
+
say(ctx, local ? openedSessionLine(result, 'resume')
|
|
215
|
+
: `Opened ${result.title} in pane ${result.paneId} (${cwd}): ${shownCommand(spec.binary, request, result.permissionArgs)}`, local);
|
|
216
|
+
for (const notice of notices)
|
|
217
|
+
say(ctx, notice, local);
|
|
218
|
+
if (result.notice)
|
|
219
|
+
say(ctx, result.notice, local);
|
|
220
|
+
};
|
|
22
221
|
return {
|
|
23
222
|
name: id,
|
|
24
|
-
description: `Open ${spec.label} in a new pane, signed in with your own ${account} account`,
|
|
25
|
-
usage:
|
|
223
|
+
description: `Open ${spec.label} in a new pane, signed in with your own ${account} account, or resume one of your own sessions in its folder (yours only)`,
|
|
224
|
+
usage: {
|
|
225
|
+
default: '[@profile] [prompt | flags | resume [<id>] | continue | fork [<id>] | sessions]',
|
|
226
|
+
variants: [
|
|
227
|
+
{ when: { 0: ['resume'] }, usage: 'resume [<id> | --all | --last] [--here] [-- <prompt>]' },
|
|
228
|
+
{ when: { 0: ['fork'] }, usage: 'fork [<id> | --all] [--here] [-- <prompt>]' },
|
|
229
|
+
{ when: { 0: ['continue'] }, usage: 'continue [-- <prompt>]' },
|
|
230
|
+
{ when: { 0: ['sessions'] }, usage: 'sessions [--all]' },
|
|
231
|
+
{ when: { 0: ['show-resumable'] }, usage: 'show-resumable [--all]' },
|
|
232
|
+
],
|
|
233
|
+
// As parseAgentCommand reads them: in lowercase only, after a leading @profile.
|
|
234
|
+
caseSensitive: true,
|
|
235
|
+
skipLeading: '@',
|
|
236
|
+
},
|
|
26
237
|
agentRunnable: true,
|
|
27
238
|
// The CLI runs commands, so an agent's permission profile governs opening it as it governs a shell.
|
|
28
239
|
agentCapabilities: [ToolCapability.SHELL_EXEC],
|
|
29
240
|
category: 'panes',
|
|
30
241
|
handler: async (args, ctx) => {
|
|
31
|
-
let
|
|
242
|
+
let parsed;
|
|
32
243
|
try {
|
|
33
|
-
|
|
244
|
+
parsed = parseAgentCommand(id, args.join(' '));
|
|
34
245
|
}
|
|
35
246
|
catch (error) {
|
|
36
|
-
ctx
|
|
247
|
+
say(ctx, `/${id}: ${error.message}`);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (parsed.kind === 'error') {
|
|
251
|
+
say(ctx, parsed.message);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (parsed.kind === 'launch') {
|
|
255
|
+
await launch(ctx, parsed.request);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
// The resume words are the person's: refused for an agent and for relayed input before anything is read.
|
|
259
|
+
if (ctx.commandOrigin === 'agent' || ctx.commandOrigin === 'relayed') {
|
|
260
|
+
// What the person types in a ZTC pane arrives as relayed input too, so this says where, not who.
|
|
261
|
+
say(ctx, `Your ${spec.label} sessions are listed and resumed only in Main (pane 0), not in a ZTC pane or from an agent. `
|
|
262
|
+
+ (id === 'claude'
|
|
263
|
+
? `Agents and other panes can still pass Claude Code's own --resume <id> or --continue, which open in this folder.`
|
|
264
|
+
: `Agents and other panes can still start Codex with its own flags, which open in this folder.`));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const cwdNow = ctx.shell.getCwd();
|
|
268
|
+
const options = { cwdNow, ...(parsed.prompt ? { prompt: parsed.prompt } : {}), ...(parsed.profile ? { profile: parsed.profile } : {}) };
|
|
269
|
+
const readable = ctx.agentSessions && !env().MOTSI_TERMINAL_ID ? ctx.agentSessions : null;
|
|
270
|
+
// continue is this folder's latest session, looked up across the stores where Main can read them, so it opens on the
|
|
271
|
+
// sign-in that holds it rather than the profile new panes start on; with none, the CLI finds its own.
|
|
272
|
+
if (parsed.kind === 'continue' && readable && findBinary(id)) {
|
|
273
|
+
const latest = await readable.latestHere(id, cwdNow, parsed.profile);
|
|
274
|
+
if (latest) {
|
|
275
|
+
await resumeTarget(ctx, readable, { ...latest, cwd: cwdNow, folderVerified: true }, { mode: 'resume', here: false, ...(parsed.prompt ? { prompt: parsed.prompt } : {}) });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// A name that is an id's start (as the picker's footer shows ids) is looked up, where Main can read the stores.
|
|
280
|
+
const idStart = parsed.kind === 'name' && ID_START.test(parsed.name) && readable ? parsed.name.toLowerCase() : null;
|
|
281
|
+
if (parsed.kind === 'continue' || (parsed.kind === 'name' && idStart === null)) {
|
|
282
|
+
// Each CLI finds its most recent session, or a name, itself, on the profiles' home Main uses.
|
|
283
|
+
await openPlan(ctx, parsed.kind === 'continue' ? continueLaunchPlan(id, options) : nameLaunchPlan(id, parsed.name, options), parsed.kind === 'continue' ? 'continue' : 'resume', readable ?? undefined);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const sessions = ctx.agentSessions;
|
|
287
|
+
if (!sessions) {
|
|
288
|
+
say(ctx, `/${id} resume lists and opens your ${spec.label} sessions in Main, ZTC's own pane in a terminal or the desktop app; this ZTC `
|
|
289
|
+
+ `(a headless run, the classic renderer or another pane) has none. ${ownResume(id)}`);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (env().MOTSI_TERMINAL_ID) {
|
|
293
|
+
say(ctx, `This ZTC runs inside motsi run, which streams its terminal to Zerg Router's Command Central, so it doesn't read or list your `
|
|
294
|
+
+ `sessions here. ${ownResume(id)}`);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (!findBinary(id)) {
|
|
298
|
+
say(ctx, `${spec.label} is not installed. Install it from ${spec.setupUrl}, for example with \`${spec.install}\`, then try again.`);
|
|
37
299
|
return;
|
|
38
300
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
301
|
+
if (parsed.kind === 'picker') {
|
|
302
|
+
if (!sessions.openPicker) {
|
|
303
|
+
say(ctx, `/${id} resume lists your sessions in Main's picker, which this ZTC can't draw. ${ownResume(id)}`);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
sessions.openPicker(id, {
|
|
307
|
+
mode: parsed.mode, all: parsed.all, here: parsed.here,
|
|
308
|
+
...(parsed.prompt ? { prompt: parsed.prompt } : {}), ...(parsed.profile ? { profile: parsed.profile } : {}),
|
|
44
309
|
});
|
|
45
310
|
return;
|
|
46
311
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
if (result.error) {
|
|
62
|
-
ctx.addMessage({ role: 'system', content: result.error });
|
|
312
|
+
if (parsed.kind === 'name') {
|
|
313
|
+
const ids = await sessions.matchIds(id, idStart ?? parsed.name);
|
|
314
|
+
if (ids.length === 1) {
|
|
315
|
+
await resumeById(ctx, sessions, { kind: 'session', mode: 'resume', id: ids[0], here: false,
|
|
316
|
+
...(parsed.prompt ? { prompt: parsed.prompt } : {}), ...(parsed.profile ? { profile: parsed.profile } : {}) });
|
|
317
|
+
}
|
|
318
|
+
else if (ids.length > 1) {
|
|
319
|
+
say(ctx, `${ids.length} ${spec.label} sessions' ids start with that. Type more of the id, or pick one in /${id} resume.`, true);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
// No session's id starts so: a name, which the CLI looks for itself.
|
|
323
|
+
await openPlan(ctx, nameLaunchPlan(id, parsed.name, options), 'resume', sessions);
|
|
324
|
+
}
|
|
63
325
|
return;
|
|
64
326
|
}
|
|
65
|
-
ctx
|
|
66
|
-
role: 'system',
|
|
67
|
-
content: `Opened ${result.title} in pane ${result.paneId} (${cwd}): ${shownCommand(spec.binary, request, result.permissionArgs)}`,
|
|
68
|
-
});
|
|
69
|
-
if (result.notice)
|
|
70
|
-
ctx.addMessage({ role: 'system', content: result.notice });
|
|
327
|
+
await resumeById(ctx, sessions, parsed);
|
|
71
328
|
},
|
|
72
329
|
};
|
|
73
330
|
}
|
|
@@ -4,7 +4,10 @@ export const diffCommand = {
|
|
|
4
4
|
description: 'Show git status and diff for the current working directory',
|
|
5
5
|
usage: '',
|
|
6
6
|
handler: async (_args, ctx) => {
|
|
7
|
-
|
|
7
|
+
// The agent writes this work tree: git runs no core.fsmonitor command from its config, and
|
|
8
|
+
// safe.bareRepository=explicit stops it reading a planted implicit bare repository's config.
|
|
9
|
+
const git = 'git -c core.fsmonitor=false -c safe.bareRepository=explicit';
|
|
10
|
+
const result = await ctx.shell.run(`${git} status --short && printf "\\n--- diff --stat ---\\n" && ${git} diff --stat && printf "\\n--- diff ---\\n" && ${git} diff -- .`);
|
|
8
11
|
const output = [result.stdout, result.stderr].filter(Boolean).join('\n');
|
|
9
12
|
const content = output.length > MAX_DIFF_CHARS
|
|
10
13
|
? `${output.slice(0, MAX_DIFF_CHARS)}\n\n[diff truncated at ${MAX_DIFF_CHARS} chars]`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveSlashUsage } from './usage_spec.js';
|
|
1
2
|
import { buildHelpIntroduction } from '../../onboarding/first_run.js';
|
|
2
3
|
import { STATUS_LINE_ITEMS, STATUS_LINE_ITEM_LABELS, STATUS_LINE_ITEM_DESCRIPTIONS } from '../../ui/status_line_config.js';
|
|
3
4
|
export function makeHelpCommand(getCommands) {
|
|
@@ -10,7 +11,9 @@ export function makeHelpCommand(getCommands) {
|
|
|
10
11
|
const statusHelp = STATUS_LINE_ITEMS.map(item => ` ${STATUS_LINE_ITEM_LABELS[item]}: ${STATUS_LINE_ITEM_DESCRIPTIONS[item]}`).join('\n');
|
|
11
12
|
const helpText = getCommands()
|
|
12
13
|
.map(c => {
|
|
13
|
-
|
|
14
|
+
// As the command is typed: its usage (a spec's default), `/name` first when the usage doesn't name it.
|
|
15
|
+
const usage = resolveSlashUsage(c.usage, [])?.trim();
|
|
16
|
+
const cmdLine = !usage ? ` /${c.name}` : usage.startsWith(`/${c.name}`) ? ` ${usage}` : ` /${c.name} ${usage}`;
|
|
14
17
|
return `${cmdLine}\n ${c.description}`;
|
|
15
18
|
})
|
|
16
19
|
.join('\n\n');
|
|
@@ -447,10 +447,12 @@ Tasks extracted: ${tasks.length}
|
|
|
447
447
|
|
|
448
448
|
${tasks.length > 0 ? 'Implementation steps are included in the plan below.' : 'No tasks found in Implementation Steps section.'}`,
|
|
449
449
|
});
|
|
450
|
-
// Add plan as context for the agent with explicit implementation instructions
|
|
450
|
+
// Add plan as context for the agent with explicit implementation instructions. It is the plan's approval, not a
|
|
451
|
+
// prompt of the person's own (planDecision).
|
|
451
452
|
if (tasks.length > 0) {
|
|
452
453
|
ctx.addMessage({
|
|
453
454
|
role: 'user',
|
|
455
|
+
metadata: { planDecision: true },
|
|
454
456
|
content: `Implement the following plan.
|
|
455
457
|
|
|
456
458
|
IMPORTANT - after ALL implementation steps are done you MUST do these two things:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the web mirror records of a /claude or /codex command that names one of the person's sessions: the mirror's
|
|
3
|
+
* viewers, and the history it keeps on disk, see the command without the session's id or name and without the prompt
|
|
4
|
+
* it passes, as they see /config key without the key. The command itself runs as typed. Workspace spec §14: no mirror
|
|
5
|
+
* observer sees the person's sessions or their prompts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The command as the mirror records it. A resume form, or one ZTC refuses, keeps its words and options and hides any
|
|
9
|
+
* session and the prompt after `--`; a launch with Claude Code's own --resume, -r, --resume= or --session-id hides
|
|
10
|
+
* their values and the prompt after `--`. A command ZTC can't read (words that don't split, an @profile that is no
|
|
11
|
+
* profile's name) never runs, but may still name a session: its words are read as typed, by the same rules. Anything
|
|
12
|
+
* else, a prompt included, is returned as typed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function redactResumeCommand(text: string): string;
|
|
15
|
+
/** A submitted command line as the mirror records it: without a key (credential_redaction.ts) or a session. */
|
|
16
|
+
export declare function redactMirroredCommand(text: string): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the web mirror records of a /claude or /codex command that names one of the person's sessions: the mirror's
|
|
3
|
+
* viewers, and the history it keeps on disk, see the command without the session's id or name and without the prompt
|
|
4
|
+
* it passes, as they see /config key without the key. The command itself runs as typed. Workspace spec §14: no mirror
|
|
5
|
+
* observer sees the person's sessions or their prompts.
|
|
6
|
+
*/
|
|
7
|
+
import { parseAgentCommand } from '../../panes/agent_cli.js';
|
|
8
|
+
import { REDACTED_SECRET, redactCredentialCommand } from './credential_redaction.js';
|
|
9
|
+
/** The words that resume the person's sessions (panes/agent_cli.ts's parseAgentCommand). */
|
|
10
|
+
const RESUME_WORDS = new Set(['resume', 'continue', 'fork', 'sessions', 'show-resumable']);
|
|
11
|
+
/** Claude Code's own flags whose value is a session id. */
|
|
12
|
+
const SESSION_FLAGS = new Set(['--resume', '-r', '--session-id']);
|
|
13
|
+
const SESSION_FLAG_JOINED = /^(--resume|--session-id)=/;
|
|
14
|
+
/**
|
|
15
|
+
* The command as the mirror records it. A resume form, or one ZTC refuses, keeps its words and options and hides any
|
|
16
|
+
* session and the prompt after `--`; a launch with Claude Code's own --resume, -r, --resume= or --session-id hides
|
|
17
|
+
* their values and the prompt after `--`. A command ZTC can't read (words that don't split, an @profile that is no
|
|
18
|
+
* profile's name) never runs, but may still name a session: its words are read as typed, by the same rules. Anything
|
|
19
|
+
* else, a prompt included, is returned as typed.
|
|
20
|
+
*/
|
|
21
|
+
export function redactResumeCommand(text) {
|
|
22
|
+
const head = /^\s*\/(claude|codex)(?=\s|$)/i.exec(text);
|
|
23
|
+
if (!head)
|
|
24
|
+
return text;
|
|
25
|
+
const body = text.slice(head[0].length);
|
|
26
|
+
let parsed = null;
|
|
27
|
+
try {
|
|
28
|
+
parsed = parseAgentCommand(head[1].toLowerCase(), body);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Read as typed, below.
|
|
32
|
+
}
|
|
33
|
+
const tokens = body.trim().split(/\s+/).filter(Boolean);
|
|
34
|
+
const kept = [`/${head[1]}`];
|
|
35
|
+
let at = 0;
|
|
36
|
+
if (tokens[0]?.startsWith('@'))
|
|
37
|
+
kept.push(tokens[at++]);
|
|
38
|
+
if (RESUME_WORDS.has(tokens[at] ?? '') && parsed?.kind !== 'launch') {
|
|
39
|
+
kept.push(tokens[at++]);
|
|
40
|
+
for (; at < tokens.length; at++) {
|
|
41
|
+
const token = tokens[at];
|
|
42
|
+
if (token === '--') {
|
|
43
|
+
kept.push('--', REDACTED_SECRET);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
kept.push(token.startsWith('-') ? token : REDACTED_SECRET);
|
|
47
|
+
}
|
|
48
|
+
return kept.join(' ');
|
|
49
|
+
}
|
|
50
|
+
// A launch's own words, whose prompt after -- is the person's to show; those of a command that can't be read.
|
|
51
|
+
const words = parsed?.kind === 'launch' ? parsed.request.words : tokens;
|
|
52
|
+
if (!words.some(word => SESSION_FLAGS.has(word) || SESSION_FLAG_JOINED.test(word)))
|
|
53
|
+
return text;
|
|
54
|
+
for (; at < tokens.length; at++) {
|
|
55
|
+
const token = tokens[at];
|
|
56
|
+
if (token === '--') {
|
|
57
|
+
kept.push('--', REDACTED_SECRET);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const joined = SESSION_FLAG_JOINED.exec(token);
|
|
61
|
+
if (joined) {
|
|
62
|
+
kept.push(`${joined[1]}=${REDACTED_SECRET}`);
|
|
63
|
+
}
|
|
64
|
+
else if (SESSION_FLAGS.has(token) && at + 1 < tokens.length && tokens[at + 1] !== '--') {
|
|
65
|
+
kept.push(token, REDACTED_SECRET);
|
|
66
|
+
at += 1;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
kept.push(token);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return kept.join(' ');
|
|
73
|
+
}
|
|
74
|
+
/** A submitted command line as the mirror records it: without a key (credential_redaction.ts) or a session. */
|
|
75
|
+
export function redactMirroredCommand(text) {
|
|
76
|
+
return redactResumeCommand(redactCredentialCommand(text));
|
|
77
|
+
}
|