@zergai/ztc 0.16.0-beta.1 → 0.16.2-dev.202611091056

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 CHANGED
@@ -269,13 +269,15 @@ and publication contract.
269
269
  typing in its main session (its Main pane in `--mux`, or the desktop app),
270
270
  the browser mirror (a colony cell's own included), or a `ztc` you run
271
271
  yourself (`ztc -p` and `ztc --headless` included). That covers the agent's
272
- `ztc_command`, ZTC panes and colony cells, colony's `send_to_worktree` and
273
- the colony dashboard's Send Message (both post to a mirror's `/broadcast`),
274
- bus messages and `write_terminal_pane`: a ZTC that another ZTC runs in one
275
- of its panes reads a terminal the overseer's `write_terminal_pane` types
276
- into too, so it can't tell your typing there from that. A choice you queue
277
- (with Tab, or while an account or model change runs) is refused when it
278
- runs, so type it again. An agent that can run shell commands can still
272
+ `ztc_command`, a `/loop`'s ticks, ZTC panes and colony cells, colony's
273
+ `send_to_worktree` and the colony dashboard's Send Message (both post to a
274
+ mirror's `/broadcast`), bus messages and `write_terminal_pane`: a ZTC that
275
+ another ZTC runs in one of its panes reads a terminal the overseer's
276
+ `write_terminal_pane` types into too, so it can't tell your typing there
277
+ from that. A choice you queue
278
+ yourself (with Tab, or while an account or model change runs) is made when
279
+ it runs, edited in the queue (Option+Up) or not; one queued from any of
280
+ those others is still refused. An agent that can run shell commands can still
279
281
  change your settings files, as it can any file you can edit, so the first
280
282
  recording each session that goes to OpenAI says so in one line. What needs
281
283
  code running on this machine (a process writing to a socket, an agent's
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/dist/App.js CHANGED
@@ -239,6 +239,8 @@ export const App = () => {
239
239
  const runCounterRef = useRef(0);
240
240
  const abortControllerRef = useRef(null);
241
241
  const runtimeMutationRef = useRef(false);
242
+ // Counts finished account changes, so the flush-on-idle effect looks at the queue again once one ends.
243
+ const [runtimeMutationsEnded, setRuntimeMutationsEnded] = useState(0);
242
244
  const accountReloadPendingRef = useRef(false);
243
245
  const [escapeStopArm, setEscapeStopArm] = useState(null);
244
246
  const escapeStopArmRef = useRef(null);
@@ -687,8 +689,12 @@ export const App = () => {
687
689
  renderScopeWidget(version => version + 1);
688
690
  }, [resetEscapeStop, scopeWidget]);
689
691
  React.useEffect(() => () => { retireRouting(false); }, [retireRouting]);
690
- /** Returns the post-enqueue size, or null if the queue was full. */
691
- const enqueueMessage = useCallback((text, delivery = 'end-of-turn', submitted) => {
692
+ /**
693
+ * Returns the post-enqueue size, or null if the queue was full. `person`: the person typed it, so it runs as theirs
694
+ * when it is sent (QueueEntry.person); every line Ink takes is typed on its terminal, so only a queued entry
695
+ * passed back here can say otherwise.
696
+ */
697
+ const enqueueMessage = useCallback((text, delivery = 'end-of-turn', submitted, person = false) => {
692
698
  const current = queueRef.current;
693
699
  const reserved = routingDraftsRef.current.size
694
700
  - (submitted && routingDraftsRef.current.has(submitted.id) ? 1 : 0);
@@ -701,6 +707,7 @@ export const App = () => {
701
707
  text,
702
708
  queuedAt: new Date(),
703
709
  delivery,
710
+ ...(person ? { person: true } : {}),
704
711
  };
705
712
  const nextSize = current.length + 1;
706
713
  queueRef.current = [...current, entry];
@@ -971,6 +978,8 @@ export const App = () => {
971
978
  finally {
972
979
  operationOpen = false;
973
980
  runtimeMutationRef.current = false;
981
+ // What the change held in the queue is sent now, by the flush-on-idle effect.
982
+ setRuntimeMutationsEnded(ended => ended + 1);
974
983
  }
975
984
  }, [reloadAgent, addMessage]);
976
985
  React.useEffect(() => { setAgent(createBoundAgent()); }, [createBoundAgent]);
@@ -1651,7 +1660,8 @@ export const App = () => {
1651
1660
  queueMicrotask(() => draft?.restore());
1652
1661
  return Promise.resolve();
1653
1662
  }
1654
- const submitted = { id: generateId(), text, queuedAt: new Date(), delivery: 'subturn' };
1663
+ // Typed by the person while a turn runs: the request that carries it is theirs.
1664
+ const submitted = { id: generateId(), text, queuedAt: new Date(), delivery: 'subturn', person: true };
1655
1665
  const epoch = routingEpochRef.current;
1656
1666
  const controller = new AbortController();
1657
1667
  const config = structuredClone(configStore.get());
@@ -1724,8 +1734,10 @@ export const App = () => {
1724
1734
  // blank input, so bypass this check when one is pending.
1725
1735
  if (!pendingPromptRef.current && !isMeaningfulUserInput(text))
1726
1736
  return;
1737
+ // What the person typed is theirs, and a queued entry is whoever queued it (QueueEntry.person).
1738
+ const person = queuedEntry ? queuedEntry.person === true : true;
1727
1739
  if (runtimeMutationRef.current && !pendingPromptRef.current) {
1728
- const position = enqueueMessage(text, 'end-of-turn');
1740
+ const position = enqueueMessage(text, 'end-of-turn', undefined, person);
1729
1741
  addMessage({ role: 'system', content: position === null ? 'Account change in progress; the queue is full. Retry when it finishes.'
1730
1742
  : 'Account change in progress; input retained in the queue.' });
1731
1743
  return;
@@ -1797,7 +1809,7 @@ export const App = () => {
1797
1809
  }
1798
1810
  if (busy) {
1799
1811
  if (inputMode === 'steer') {
1800
- const nextSize = enqueueMessage(text, 'subturn');
1812
+ const nextSize = enqueueMessage(text, 'subturn', undefined, person);
1801
1813
  if (nextSize !== null) {
1802
1814
  showToastRef.current?.('Steering current task · Sending after the current tool finishes');
1803
1815
  }
@@ -2024,9 +2036,9 @@ export const App = () => {
2024
2036
  break;
2025
2037
  }
2026
2038
  });
2027
- // A message the person just typed gets one real attempt even while Zerg Router's refusal holds the route; a
2028
- // queued entry never does.
2029
- if (!queuedEntry)
2039
+ // A message the person typed gets one real attempt even while Zerg Router's refusal holds the route, sent at once
2040
+ // or from the queue.
2041
+ if (person)
2030
2042
  currentAgent.admitPersonRequest();
2031
2043
  try {
2032
2044
  await runWithRetry(requestMessages, currentAgent, false, isActive, controller.signal, () => {
@@ -2035,6 +2047,9 @@ export const App = () => {
2035
2047
  const pending = queueRef.current.filter(entry => entry.delivery === 'subturn');
2036
2048
  queueRef.current = queueRef.current.filter(entry => entry.delivery !== 'subturn');
2037
2049
  setQueue(queueRef.current);
2050
+ // The person's steering makes the request that carries it theirs, as their own message would.
2051
+ if (pending.some(entry => entry.person === true))
2052
+ currentAgent.admitPersonRequest();
2038
2053
  // These messages become visible through the real history checkpoint
2039
2054
  // when the Agent admits them after the completed tool result.
2040
2055
  return pending.map(entry => ({ id: entry.id, role: 'user', content: entry.text,
@@ -2113,6 +2128,10 @@ export const App = () => {
2113
2128
  return;
2114
2129
  if (abortControllerRef.current !== null)
2115
2130
  return;
2131
+ // An account change holds the queue until it ends, and its end runs this effect again. Sent meanwhile, the head
2132
+ // went into the change, which held it again as a new entry with another notice, and again, until the change ended.
2133
+ if (runtimeMutationRef.current)
2134
+ return;
2116
2135
  if (queuePausedRef.current || workspacePausedRef.current || agentQuestionRef.current || pendingPromptRef.current || formCallbacksRef.current.size > 0 || questionnaireWidget.isActive() || scopeWidget.isActive() || workspaceWidget.isActive())
2117
2136
  return;
2118
2137
  if (prevStatus === 'idle' && queue.length === 0)
@@ -2133,7 +2152,7 @@ export const App = () => {
2133
2152
  flushingRef.current = false;
2134
2153
  setFlushing(false);
2135
2154
  });
2136
- }, [agentState.status, queue.length, flushing, dequeueMessage, handleSubmit, scopeWidget, workspaceWidget, questionnaireWidget, questionnaireVersion, workspaceResumeVersion]);
2155
+ }, [agentState.status, queue.length, flushing, dequeueMessage, handleSubmit, scopeWidget, workspaceWidget, questionnaireWidget, questionnaireVersion, workspaceResumeVersion, runtimeMutationsEnded]);
2137
2156
  const showToast = useCallback((message, durationMs = DEFAULT_TOAST_MS) => {
2138
2157
  setToast(message);
2139
2158
  if (toastTimerRef.current) {
@@ -2292,7 +2311,8 @@ export const App = () => {
2292
2311
  retireRouting();
2293
2312
  return cancelGeneration() || routing;
2294
2313
  }, isRunning: agentState.status !== 'idle' && agentState.status !== 'error', mode: agentMode, onSubmit: handleSubmit, onQueue: (text) => {
2295
- const size = enqueueMessage(text, 'end-of-turn');
2314
+ // Tab queues what the person typed, which runs as theirs when the turn ends.
2315
+ const size = enqueueMessage(text, 'end-of-turn', undefined, true);
2296
2316
  if (size === null)
2297
2317
  return false;
2298
2318
  showToast(`Queued (${size})`);
@@ -488,6 +488,9 @@ export const accountsCommand = {
488
488
  name: 'accounts',
489
489
  description: 'Manage switchable Codex and Kimi Code accounts (Claude Code profiles: /subs)',
490
490
  usage: '[add|use|login|remove] …',
491
+ // Each of these is an account operation, which the renderer refuses while a turn runs (applyAccountOperation).
492
+ waitsForTurnEnd: ([sub, ...rest]) => rest.length > 0
493
+ && ['add', 'use', 'switch', 'login', 'remove', 'rm'].includes(sub ?? ''),
491
494
  handler: async (args, ctx) => {
492
495
  const [sub, ...rest] = args;
493
496
  switch (sub) {
@@ -45,9 +45,9 @@ export const dictationStatusCommand = {
45
45
  if (subcommand === 'local' || subcommand === 'macos' || subcommand === 'openai') {
46
46
  // The person's choice of where a recording is transcribed, saved, and said as they make it: OpenAI's Whisper
47
47
  // API would get their audio on their key. Only the person makes it, in ZTC's main session, the browser mirror
48
- // or a ztc they run themselves; never the agent, nor input relayed to this ZTC (what a ZTC pane or a colony cell
49
- // reads from its terminal, what a mirror's /broadcast gets, a bus message, a /loop or the queue), which is told
50
- // where to make it.
48
+ // or a ztc they run themselves, at once or from the queue; never the agent, nor input relayed to this ZTC (what a
49
+ // ZTC pane or a colony cell reads from its terminal, what a mirror's /broadcast gets, a bus message, a /loop),
50
+ // queued or not, which is told where to make it.
51
51
  if (ctx.commandOrigin === 'agent') {
52
52
  ctx.addMessage({ role: 'system', content: `Only you can choose where dictation transcribes: type /dictation ${subcommand} yourself.` });
53
53
  return;
@@ -5,6 +5,8 @@ const activeOperations = new Set();
5
5
  export function environmentOperationInProgress(sessionId) { return activeOperations.has(sessionId); }
6
6
  export const environmentCommand = {
7
7
  name: 'environment', description: 'Manage durable local workspaces, checkpoints and services', usage, category: 'core',
8
+ // Every change refuses while a turn runs (below); list and status only read.
9
+ waitsForTurnEnd: args => !['list', 'status'].includes(args[0] ?? 'status'),
8
10
  handler: async (args, ctx) => {
9
11
  const say = (content) => ctx.addMessage({ role: 'system', content });
10
12
  const action = args[0] ?? 'status';
@@ -13,6 +13,9 @@ export const profileCommand = {
13
13
  name: 'profile',
14
14
  description: 'List, switch, create, and duplicate configuration profiles',
15
15
  usage: '[list|<name>|use <name>|create <name>|duplicate [name]]',
16
+ // Switching (duplicate switches to the copy) waits for an idle session in the renderer (switchConfigProfile).
17
+ waitsForTurnEnd: ([action]) => action !== undefined && !['list', 'configs', 'help'].includes(action)
18
+ && !OLD_BENCHMARK_COMMANDS.has(action),
16
19
  handler: async (args, ctx) => {
17
20
  const [action, ...rest] = args;
18
21
  if (!action || action === 'list' || action === 'configs' || action === 'help') {
@@ -3,6 +3,8 @@ export const rewindCommand = {
3
3
  name: 'rewind',
4
4
  description: 'Choose an earlier prompt to restore and remove its following context',
5
5
  usage: '/rewind',
6
+ // The picker opens only between turns (the renderer's rewindPanel).
7
+ waitsForTurnEnd: () => true,
6
8
  handler: (_, ctx) => {
7
9
  if (!ctx.rewindPanel) {
8
10
  ctx.addMessage({
@@ -367,15 +367,17 @@ export interface CommandContext {
367
367
  * `ztc_command` tool, or input relayed into this session (`relayed`): a
368
368
  * message from another pane, the coordinator or another ZTC on the bus, a
369
369
  * prompt on a pane's stdin (what a parent pane or the overseer's
370
- * write_terminal_pane sends), a /loop tick, a goal continuation, a queued
371
- * entry, and what a ZTC that another ZTC launched into one of its panes (a
372
- * ZTC pane, a colony cell: ZTC_PARENT_PID or ZTC_COLONY_CHILD) reads from
373
- * its terminal, since the overseer's write_terminal_pane types into the same
374
- * PTY as the person; and what a mirror's /broadcast delivers, which only
375
- * colony's AgentBridge posts (send_to_worktree, the colony dashboard). That
376
- * is input the TUI's handleSubmit and the headless runner do not mark as the
377
- * person's own: only the person typing in ZTC's main session, a ztc they
378
- * run, or the browser mirror is.
370
+ * write_terminal_pane sends), a /loop tick, a goal continuation, any of
371
+ * these queued (a queued entry keeps who entered it, so what the person
372
+ * queued is still theirs), and what a ZTC that another ZTC launched into one
373
+ * of its panes (a ZTC pane, a colony cell: ZTC_PARENT_PID or
374
+ * ZTC_COLONY_CHILD) reads from its terminal, since the overseer's
375
+ * write_terminal_pane types into the same PTY as the person; and what a
376
+ * mirror's /broadcast delivers, which only colony's AgentBridge posts
377
+ * (send_to_worktree, the colony dashboard). That is input the TUI's
378
+ * handleSubmit and the headless runner do not mark as the person's own: only
379
+ * the person typing in ZTC's main session, a ztc they run, or the browser
380
+ * mirror is.
379
381
  * Absent means user — every renderer therefore keeps the user's full
380
382
  * authority with no change, and only the agent-facing dispatch path and the
381
383
  * relaying paths have to opt in. Commands that can clear their own safety
@@ -712,4 +714,11 @@ export interface Command {
712
714
  agentRunnable?: boolean;
713
715
  /** Grouping label for the agent-facing description (e.g. "zerg", "manifest", "config"). */
714
716
  category?: string;
717
+ /**
718
+ * True when this command, given these arguments, can't run while an agent turn is running: its handler, or the change
719
+ * it asks the renderer for (an account, a config profile, the rewind picker), refuses until the turn ends. The desktop
720
+ * app's Send now during a run then leaves the queued command in the queue, to run when the turn ends, instead of
721
+ * running it into that refusal. Absent: the command runs during a turn.
722
+ */
723
+ waitsForTurnEnd?: (args: string[]) => boolean;
715
724
  }
@@ -7,7 +7,7 @@
7
7
  * The state is a single immutable object that gets updated via dispatch().
8
8
  * Subscribers are notified whenever the state changes.
9
9
  */
10
- import { type Message, type AgentState, type InputMode, type CanonicalInputMode, type MessageInput, type QueueEntry, type DeliveryIntent, type TodoStatus } from '../types.js';
10
+ import { type Message, type AgentState, type InputMode, type CanonicalInputMode, type MessageInput, type QueueEntry, type QueueEntryOrigin, type DeliveryIntent, type TodoStatus } from '../types.js';
11
11
  import type { InputState } from '../ui/core/input_state.js';
12
12
  import type { ContextStatus } from '../utils/context.js';
13
13
  import type { Skill } from '../skills/types.js';
@@ -275,8 +275,10 @@ export declare class AppController {
275
275
  * `delivery` records when the message should reach the model. It defaults to
276
276
  * `end-of-turn`, the conservative choice: an entry whose intent was never
277
277
  * stated must wait for the whole turn rather than slip into the middle of one.
278
+ * `origin` says who entered it; without `person`, the entry runs as relayed
279
+ * input (see QueueEntry.person).
278
280
  */
279
- enqueueMessage(input: string | MessageInput, delivery?: DeliveryIntent): boolean;
281
+ enqueueMessage(input: string | MessageInput, delivery?: DeliveryIntent, origin?: QueueEntryOrigin): boolean;
280
282
  /**
281
283
  * Remove the head of the queue and return it.
282
284
  * Called by the flush-on-idle path.
@@ -437,8 +437,10 @@ export class AppController {
437
437
  * `delivery` records when the message should reach the model. It defaults to
438
438
  * `end-of-turn`, the conservative choice: an entry whose intent was never
439
439
  * stated must wait for the whole turn rather than slip into the middle of one.
440
+ * `origin` says who entered it; without `person`, the entry runs as relayed
441
+ * input (see QueueEntry.person).
440
442
  */
441
- enqueueMessage(input, delivery = 'end-of-turn') {
443
+ enqueueMessage(input, delivery = 'end-of-turn', origin = {}) {
442
444
  if (this.state.queue.length >= MAX_QUEUE)
443
445
  return false;
444
446
  const text = typeof input === 'string' ? input : input.text;
@@ -448,6 +450,7 @@ export class AppController {
448
450
  attachments: typeof input === 'string' ? [] : input.attachments,
449
451
  queuedAt: new Date(),
450
452
  delivery,
453
+ ...(origin.person === true ? { person: true, ...(origin.via ? { via: origin.via } : {}) } : {}),
451
454
  };
452
455
  this.dispatch({ type: 'ENQUEUE_MESSAGE', entry });
453
456
  return true;
@@ -564,6 +564,14 @@ export declare class RatatuiApp {
564
564
  /** This projection describes live accepted queue sources; checkpoints do not grant dispatch ownership. */
565
565
  private syncOwnPaneTaskControls;
566
566
  private handleDesktopTaskAction;
567
+ /** The queue's entry ids with ID first and the rest in their order: where Send now puts the entry it sends or keeps. */
568
+ private queueIdsWithFirst;
569
+ /**
570
+ * What a command Send now ran says, for the desktop app: the last system line it added to the transcript, a refusal
571
+ * included, in at most the 1 KiB of whole characters the app shows, or that it ran when it said nothing. BEFORE: the
572
+ * transcript's message ids before it ran.
573
+ */
574
+ private queuedCommandOutcome;
567
575
  /**
568
576
  * Recreate the live agent in place (new backend resolved from current config)
569
577
  * and re-arm the hook watcher. Shared by /accounts use — both the CLI command
@@ -949,10 +957,17 @@ export declare class RatatuiApp {
949
957
  * /broadcast (see handleSubmit's `via`).
950
958
  */
951
959
  private submitPersonInput;
960
+ /**
961
+ * Who entered input the queue holds for later, kept with its entry: handleSubmit's `person` and `via`. Each place
962
+ * that sends a queued entry passes them back (`entry.person === true`, `entry.via ?? 'terminal'`), so the person's
963
+ * line runs as theirs and relayed input stays relayed.
964
+ */
965
+ private queueOrigin;
952
966
  /**
953
967
  * `person`: the person entered this input themselves (see submitPersonInput). A /loop tick, a goal continuation,
954
- * another pane's or the coordinator's message, a pane's initial task and a queued entry never are, so none of them
955
- * passes a Zerg Router refusal the process holds. `via`: where the person entered it, this ZTC's terminal or the
968
+ * another pane's or the coordinator's message and a pane's initial task never are, so none of them passes a Zerg
969
+ * Router refusal the process holds; a queued entry is whoever queued it (QueueEntry.person and QueueEntry.via, which
970
+ * the queue passes back here). `via`: where the person entered it, this ZTC's terminal or the
956
971
  * browser mirror, or else the mirror's /broadcast, which only colony's AgentBridge posts to (the overseer's
957
972
  * send_to_worktree tool and the colony dashboard's send). In a ZTC another ZTC launched into one of its panes, what
958
973
  * the terminal gives it isn't only the person's, and what /broadcast gives any ZTC never is (see the origin below).