@songsid/agend 2.3.2-beta.10 → 2.3.2-beta.11

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.
Files changed (128) hide show
  1. package/dist/agent-cli.js +48 -0
  2. package/dist/agent-cli.js.map +1 -1
  3. package/dist/agent-endpoint.js +6 -0
  4. package/dist/agent-endpoint.js.map +1 -1
  5. package/dist/agent-whats-new.js +3 -0
  6. package/dist/agent-whats-new.js.map +1 -1
  7. package/dist/backend/kiro-classic-archive.d.ts +52 -0
  8. package/dist/backend/kiro-classic-archive.js +444 -0
  9. package/dist/backend/kiro-classic-archive.js.map +1 -0
  10. package/dist/backend/kiro-identity.d.ts +19 -0
  11. package/dist/backend/kiro-identity.js +43 -0
  12. package/dist/backend/kiro-identity.js.map +1 -1
  13. package/dist/backend/kiro-migration-verify.d.ts +10 -0
  14. package/dist/backend/kiro-migration-verify.js +52 -0
  15. package/dist/backend/kiro-migration-verify.js.map +1 -0
  16. package/dist/backend/kiro-v2-store-worker.js +21 -1
  17. package/dist/backend/kiro-v2-store-worker.js.map +1 -1
  18. package/dist/backend/kiro-v2-store.d.ts +8 -0
  19. package/dist/backend/kiro-v2-store.js.map +1 -1
  20. package/dist/backend/kiro.d.ts +99 -1
  21. package/dist/backend/kiro.js +352 -18
  22. package/dist/backend/kiro.js.map +1 -1
  23. package/dist/backend/types.d.ts +49 -0
  24. package/dist/backend/types.js +9 -0
  25. package/dist/backend/types.js.map +1 -1
  26. package/dist/channel/ipc-timeouts.js +3 -0
  27. package/dist/channel/ipc-timeouts.js.map +1 -1
  28. package/dist/channel/mcp-tools.js +12 -0
  29. package/dist/channel/mcp-tools.js.map +1 -1
  30. package/dist/cli.js +33 -0
  31. package/dist/cli.js.map +1 -1
  32. package/dist/config-validator.js +2 -0
  33. package/dist/config-validator.js.map +1 -1
  34. package/dist/config.js +2 -0
  35. package/dist/config.js.map +1 -1
  36. package/dist/daemon.d.ts +45 -0
  37. package/dist/daemon.js +342 -19
  38. package/dist/daemon.js.map +1 -1
  39. package/dist/dashboard-permissions.d.ts +15 -4
  40. package/dist/dashboard-permissions.js +49 -23
  41. package/dist/dashboard-permissions.js.map +1 -1
  42. package/dist/fleet-control-audit.d.ts +1 -1
  43. package/dist/fleet-control-audit.js +3 -0
  44. package/dist/fleet-control-audit.js.map +1 -1
  45. package/dist/fleet-manager.d.ts +61 -2
  46. package/dist/fleet-manager.js +421 -28
  47. package/dist/fleet-manager.js.map +1 -1
  48. package/dist/general-knowledge/skills/kiro-engine-migration/SKILL.md +10 -0
  49. package/dist/general-knowledge/skills/web-appearance/SKILL.canvas-worker-off.md +25 -0
  50. package/dist/general-knowledge/skills/web-appearance/SKILL.md +25 -0
  51. package/dist/general-knowledge/skills/web-dashboard/SKILL.canvas-worker-off.md +12 -2
  52. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +12 -2
  53. package/dist/instance-config-impact.js +2 -2
  54. package/dist/instance-config-impact.js.map +1 -1
  55. package/dist/instance-lifecycle.d.ts +4 -0
  56. package/dist/instance-lifecycle.js +7 -0
  57. package/dist/instance-lifecycle.js.map +1 -1
  58. package/dist/kiro-migrate.d.ts +11 -0
  59. package/dist/kiro-migrate.js +86 -31
  60. package/dist/kiro-migrate.js.map +1 -1
  61. package/dist/kiro-session-proof.d.ts +41 -0
  62. package/dist/kiro-session-proof.js +89 -0
  63. package/dist/kiro-session-proof.js.map +1 -0
  64. package/dist/kiro-tui-forensic.d.ts +5 -0
  65. package/dist/kiro-tui-forensic.js +3 -3
  66. package/dist/kiro-tui-forensic.js.map +1 -1
  67. package/dist/locale.js +142 -0
  68. package/dist/locale.js.map +1 -1
  69. package/dist/log-service.js +1 -1
  70. package/dist/log-service.js.map +1 -1
  71. package/dist/needs-you.d.ts +3 -1
  72. package/dist/needs-you.js +4 -2
  73. package/dist/needs-you.js.map +1 -1
  74. package/dist/office-share.d.ts +12 -2
  75. package/dist/office-share.js +27 -2
  76. package/dist/office-share.js.map +1 -1
  77. package/dist/outbound-schemas.d.ts +39 -0
  78. package/dist/outbound-schemas.js +29 -0
  79. package/dist/outbound-schemas.js.map +1 -1
  80. package/dist/remote-card-prompt.d.ts +38 -0
  81. package/dist/remote-card-prompt.js +86 -0
  82. package/dist/remote-card-prompt.js.map +1 -0
  83. package/dist/settings-change.js +8 -5
  84. package/dist/settings-change.js.map +1 -1
  85. package/dist/settings-instance-patch.js +1 -1
  86. package/dist/settings-instance-patch.js.map +1 -1
  87. package/dist/tool-permissions.js +17 -0
  88. package/dist/tool-permissions.js.map +1 -1
  89. package/dist/transcript-sources.d.ts +1 -0
  90. package/dist/transcript-sources.js +2 -1
  91. package/dist/transcript-sources.js.map +1 -1
  92. package/dist/types.d.ts +5 -0
  93. package/dist/ui/chat-store.js +3 -2
  94. package/dist/ui/chat-strings.js +2 -2
  95. package/dist/ui/fleet-office-editor.js +54 -2
  96. package/dist/ui/fleet-office-layout.js +44 -7
  97. package/dist/ui/fleet-office-pack.d.ts +6 -1
  98. package/dist/ui/fleet-office-pack.js +101 -15
  99. package/dist/ui/fleet-office-store.js +43 -0
  100. package/dist/ui/fleet-office-zones.js +64 -13
  101. package/dist/ui/fleet-office.js +5 -3
  102. package/dist/ui/panel-chat.js +14 -2
  103. package/dist/ui/panel-log.js +2 -2
  104. package/dist/ui/panel-needs.js +1 -1
  105. package/dist/ui/panel-settings.js +5 -5
  106. package/dist/ui/settings-model.js +17 -9
  107. package/dist/ui/settings-strings.js +2 -0
  108. package/dist/ui/shared/app-i18n.js +2 -2
  109. package/dist/ui/shared/app-stream.js +1 -1
  110. package/dist/ui/shared/app.css +18 -2
  111. package/dist/web-api.d.ts +5 -1
  112. package/dist/web-api.js +91 -3
  113. package/dist/web-api.js.map +1 -1
  114. package/dist/web-office-acts.js +2 -2
  115. package/dist/web-office-acts.js.map +1 -1
  116. package/dist/web-office-pack-read.d.ts +35 -0
  117. package/dist/web-office-pack-read.js +252 -0
  118. package/dist/web-office-pack-read.js.map +1 -0
  119. package/dist/web-office-pack-tools.d.ts +232 -0
  120. package/dist/web-office-pack-tools.js +754 -0
  121. package/dist/web-office-pack-tools.js.map +1 -0
  122. package/dist/web-office-skins.d.ts +68 -4
  123. package/dist/web-office-skins.js +318 -33
  124. package/dist/web-office-skins.js.map +1 -1
  125. package/dist/web-office-store.d.ts +5 -2
  126. package/dist/web-office-store.js +41 -15
  127. package/dist/web-office-store.js.map +1 -1
  128. package/package.json +1 -1
package/dist/daemon.js CHANGED
@@ -1,10 +1,13 @@
1
+ import { readActiveKiroModel } from "./backend/kiro.js";
1
2
  import { dashboardAccessOf } from "./dashboard-permissions.js";
3
+ import { sendPackSources } from "./web-office-pack-read.js";
2
4
  import { agentWhatsNew, agendVersion, planWhatsNew, readWhatsNewRecord, recordWhatsNew, whatsNewNotice } from "./agent-whats-new.js";
3
5
  import { join, dirname, resolve } from "node:path";
4
6
  import { checkoutTarget, readCheckouts, releaseCandidate, reposRoot, verifyWorktree, writeCheckouts } from "./repo-worktree-guard.js";
5
7
  import { mkdirSync, writeFileSync, readFileSync, readdirSync, existsSync, unlinkSync, rmSync, appendFileSync, statSync, renameSync } from "node:fs";
6
8
  import { COMPACT_WATCH_TIMEOUT_MS, launchIdentity } from "./compact-watch.js";
7
9
  import { KIRO_COMPACT_PANE_LINES, KiroCompactPaneFollower } from "./kiro-compact-pane.js";
10
+ import { clearKiroSessionProof, proveKiroSessionId, recordKiroSessionProof } from "./kiro-session-proof.js";
8
11
  import { fileURLToPath } from "node:url";
9
12
  import { ensureInstanceDir } from "./private-dir.js";
10
13
  import { createHash, randomBytes, randomUUID } from "node:crypto";
@@ -36,7 +39,7 @@ import { ContextGuardian } from "./context-guardian.js";
36
39
  import { IpcServer } from "./channel/ipc-bridge.js";
37
40
  import { daemonBudgetMs } from "./channel/ipc-timeouts.js";
38
41
  import { MessageBus } from "./channel/message-bus.js";
39
- import { shellQuote, UnsupportedCliError } from "./backend/types.js";
42
+ import { shellQuote, UnsupportedCliError, ResumeBlockedError } from "./backend/types.js";
40
43
  import { getTmuxSession } from "./config.js";
41
44
  import { routeToolCall } from "./channel/tool-router.js";
42
45
  import { parseReplyButtons, replyButtonsFallbackText } from "./reply-buttons.js";
@@ -90,6 +93,10 @@ const WEB_THEME_IPC = Object.freeze({
90
93
  delete_web_effect: "fleet_delete_web_effect",
91
94
  // #2578: its own character in the Office view — the args as they are (the fleet checks them).
92
95
  office_view: "fleet_office_view", office_set: "fleet_office_set",
96
+ // #2692: the skin packs — check and upload read the pack here (web-office-pack-read.ts) and send its bytes in parts.
97
+ office_pack_check: "fleet_office_pack_check", office_pack_upload: "fleet_office_pack_upload",
98
+ office_pack_delete: "fleet_office_pack_delete", office_pack_restore: "fleet_office_pack_restore",
99
+ office_pack_list: "fleet_office_pack_list", office_set_style: "fleet_office_set_style",
93
100
  });
94
101
  /** The largest picture any slot may take (a card slot's ceiling; the fleet checks the limit in force): read no more. */
95
102
  const WEB_THEME_ASSET_MAX_BYTES = ASSET_UPLOAD_MAX_BYTES;
@@ -704,6 +711,18 @@ const FIRST_DELIVERY_WINDOW_MS = 5_000;
704
711
  const NATIVE_QUEUE_PASTE_VERIFY_MS = 2_000;
705
712
  /** #1405: how long a steer's paste gets to show in a mode-switched composer before its one Enter (captures included). */
706
713
  const STEER_PASTE_VISIBLE_MS = 2_000;
714
+ /**
715
+ * #2676: the longest one-line paste kiro's TUI composer still shows as typed text; longer, it collapses to a
716
+ * `N chars ▸` chip (2.34.0 tui.js: more than 10 lines or 500 characters collapse).
717
+ */
718
+ const KIRO_COLLAPSE_CHARS = 500;
719
+ /**
720
+ * #1405/#2676: whether a mode-switched composer in `mode` may take a busy hand-off: a steer only on "steer", an ordinary
721
+ * message on "steer" or "queue" (kiro takes either into its tray), and "idle" — the turn over — only where `allowIdle`.
722
+ */
723
+ function composerModeAdmits(mode, allowIdle, steerOnly) {
724
+ return mode === "steer" || (!steerOnly && mode === "queue") || (allowIdle && mode === "idle");
725
+ }
707
726
  /** `promise`'s value if it settles within `ms`, else undefined — the late answer is dropped, never awaited (#1405). */
708
727
  async function withinMs(promise, ms) {
709
728
  if (ms <= 0) {
@@ -1141,6 +1160,29 @@ export class Daemon extends EventEmitter {
1141
1160
  logTranscriptPath() { return this.transcriptMonitor?.currentPath() ?? null; }
1142
1161
  /** #1218 (kiro): the launch this daemon's backend last built, for the Log's reason only (kiro-log-gate.ts). */
1143
1162
  logLaunch() { return this.backend?.logLaunch?.() ?? null; }
1163
+ async kiroMigrationIdle() {
1164
+ const tmux = this.tmux, owner = this.interactionOwner();
1165
+ if (!tmux || this.spawning || this.runtimeMonitorsFrozen || this.processStatus !== "running")
1166
+ return false;
1167
+ const pane = await tmux.capturePane(2000).catch(() => null);
1168
+ return pane !== null && tmux === this.tmux && sameInteractionOwner(owner, this.interactionOwner())
1169
+ && this.processStatus === "running" && !this.spawning && !this.runtimeMonitorsFrozen && this.paneAuthoritativelyIdle(pane);
1170
+ }
1171
+ /** One read-only migration observation. Never types into a pane or selects a picker. */
1172
+ async kiroMigrationObservation() {
1173
+ const tmux = this.tmux, owner = this.interactionOwner(), backend = this.backend;
1174
+ if (!tmux || backend?.binaryName !== "kiro-cli" || this.processStatus !== "running" || this.spawning || this.runtimeMonitorsFrozen)
1175
+ return null;
1176
+ const pane = await tmux.capturePane(2000).catch(() => null);
1177
+ if (pane === null || tmux !== this.tmux || !sameInteractionOwner(owner, this.interactionOwner())
1178
+ || this.processStatus !== "running" || this.spawning || this.runtimeMonitorsFrozen || !this.paneAuthoritativelyIdle(pane)
1179
+ || backend.readSteerComposer?.(pane) !== "idle")
1180
+ return null;
1181
+ const launch = backend.transcriptLaunch?.(), path = this.logTranscriptPath();
1182
+ // Agent switching is separately disabled for saved-agent resumes; it is not an observation API.
1183
+ const model = readActiveKiroModel(pane);
1184
+ return launch?.engine === "v2" && launch.sessionId && model && path ? { sessionId: launch.sessionId, model, transcript: path } : null;
1185
+ }
1144
1186
  guardian = null;
1145
1187
  adapter = null;
1146
1188
  pendingIpcRequests = new Map();
@@ -2035,6 +2077,11 @@ export class Daemon extends EventEmitter {
2035
2077
  this.finishDurableDelivery(delivery, "delivered", `steer-accepted; composer emptied (${verdict.proof.slice("steer-composer-".length)})`, verdict);
2036
2078
  return;
2037
2079
  }
2080
+ // #2676: an ordinary message typed into that busy composer, proven the same way: taken into the CLI's tray.
2081
+ if (verdict.proof?.startsWith("handoff-composer-")) {
2082
+ this.finishDurableDelivery(delivery, "delivered", `composer-handoff-accepted; composer emptied (${verdict.proof.slice("handoff-composer-".length)})`, verdict);
2083
+ return;
2084
+ }
2038
2085
  // A backend whose input row cannot be read: all that vouched for this delivery is that the pane printed something
2039
2086
  // after Enter, which a redraw that wiped the paste satisfies too (#758). Its transcript can say more.
2040
2087
  if (verdict.proof === "output-edge") {
@@ -3441,6 +3488,11 @@ export class Daemon extends EventEmitter {
3441
3488
  if (!(err instanceof UnsupportedCliError))
3442
3489
  return false;
3443
3490
  this.healthCheckPaused = true;
3491
+ if (err instanceof ResumeBlockedError) {
3492
+ this.logger.error({ reason: err.message }, "Not respawning: retained session needs store repair");
3493
+ this.emitSupervisionEnded(err.message, err.remedy, undefined, "resume_blocked");
3494
+ return true;
3495
+ }
3444
3496
  this.logger.error({ reason: err.message }, "Not respawning: the installed CLI cannot run this instance as configured");
3445
3497
  this.emitSupervisionEnded(err.message, "Install a CLI version that supports this instance's configuration, then start it again.", undefined, "cli_unsupported");
3446
3498
  return true;
@@ -6749,6 +6801,10 @@ export class Daemon extends EventEmitter {
6749
6801
  this.config.office_access = update.office_access;
6750
6802
  else if (update.office_access === null)
6751
6803
  delete this.config.office_access;
6804
+ if (typeof update.office_pack_access === "boolean")
6805
+ this.config.office_pack_access = update.office_pack_access;
6806
+ else if (update.office_pack_access === null)
6807
+ delete this.config.office_pack_access;
6752
6808
  if (update.dashboard && typeof update.dashboard === "object" && !dashboardAccessProblem(update.dashboard))
6753
6809
  this.config.dashboard = update.dashboard;
6754
6810
  else if (update.dashboard === null)
@@ -7356,6 +7412,7 @@ export class Daemon extends EventEmitter {
7356
7412
  return false;
7357
7413
  let windowId = this.getWindowId();
7358
7414
  const supportsQueuedInput = this.backend?.supportsQueuedInput?.() === true;
7415
+ const composerQueue = !opts?.steer && this.composerTakesBusyInput() && this.composerCanShowPaste(formatted);
7359
7416
  let handingOffToNativeQueue = false;
7360
7417
  // If the CLI is busy, either hand the complete submission to its native input
7361
7418
  // queue or wait for idle. Native queue support is an explicit backend capability:
@@ -7372,11 +7429,13 @@ export class Daemon extends EventEmitter {
7372
7429
  // press Enter at once. A dialog painted a moment ago is still "busy" to
7373
7430
  // the silence gate, so the probe is mandatory here; "dialog"/"unknown"
7374
7431
  // fall through to the wait.
7375
- const canHandOff = (supportsQueuedInput || opts?.steer)
7432
+ // #2676: an ordinary message goes into a mode-switched composer (kiro TUI) mid-turn too, on a launch whose busy
7433
+ // composer AgEnD drives, by the steer path's own gates and proof — when its box can show it is this paste.
7434
+ const canHandOff = (supportsQueuedInput || opts?.steer || composerQueue)
7376
7435
  && readiness === "busy"
7377
7436
  && (await this.probeBlockingDialog()).state === "clear"
7378
7437
  && await this.hasPositiveDeliveryInput(true)
7379
- && (!opts?.steer || (this.launchTakesSteer() && await this.steerComposerAdmits(false)));
7438
+ && ((!opts?.steer && !composerQueue) || (this.launchTakesSteer() && await this.steerComposerAdmits(false, opts?.steer === true)));
7380
7439
  if (canHandOff) {
7381
7440
  // Native queue (codex), or an explicit /steer: hand the complete
7382
7441
  // paste+Enter transaction to the busy CLI now. For steer this is the
@@ -7384,7 +7443,9 @@ export class Daemon extends EventEmitter {
7384
7443
  // visibility check + idle-gated fallback catch TUIs that swallow
7385
7444
  // busy input (see steerMessage).
7386
7445
  handingOffToNativeQueue = true;
7387
- this.logger.debug(opts?.steer ? "CLI busy — steering into the running turn" : "CLI busy — handing message to backend-native input queue");
7446
+ this.logger.debug(opts?.steer ? "CLI busy — steering into the running turn"
7447
+ : composerQueue ? "CLI busy — typing message into the busy composer"
7448
+ : "CLI busy — handing message to backend-native input queue");
7388
7449
  }
7389
7450
  else {
7390
7451
  this.logger.debug("CLI busy — queuing message until idle");
@@ -7478,9 +7539,9 @@ export class Daemon extends EventEmitter {
7478
7539
  // #1405: a launch that no longer takes a steer is not the one the gate saw — redo from the top (bounded), where
7479
7540
  // the gate sends it down the idle path. The composer can also have changed mode since (the user's Ctrl+S), or
7480
7541
  // the turn ended.
7481
- if (handingOffToNativeQueue && opts?.steer && !this.launchTakesSteer())
7542
+ if (handingOffToNativeQueue && (opts?.steer || composerQueue) && !this.launchTakesSteer())
7482
7543
  return "spawn-started";
7483
- if (handingOffToNativeQueue && opts?.steer && !(await this.steerComposerAdmits(true)))
7544
+ if (handingOffToNativeQueue && (opts?.steer || composerQueue) && !(await this.steerComposerAdmits(true, opts?.steer === true)))
7484
7545
  return "dialog";
7485
7546
  // #829: a CLI that restores a cancelled prompt into its input box would
7486
7547
  // have this message pasted onto it and both submitted as one. Clear it
@@ -8254,6 +8315,10 @@ export class Daemon extends EventEmitter {
8254
8315
  this.logger.info({ kind: card.kind }, "A card a person can answer from the chat is on screen — posting it");
8255
8316
  this.emit("remote_card", { name: this.name, card });
8256
8317
  }
8318
+ /** #2675: the card's post was used up without answering it (refused, stopped part-way): post it again once it holds still. */
8319
+ repostRemoteCard() {
8320
+ this.remoteCardShown = null;
8321
+ }
8257
8322
  /**
8258
8323
  * #2675: answer the card on screen from the chat, as the person chose: only while it is the card they saw
8259
8324
  * (`identity`), on a verified cursor, under the pane write lock (remote-card-answer.ts). Never logs the answer.
@@ -8393,21 +8458,48 @@ export class Daemon extends EventEmitter {
8393
8458
  * while a fresh capture reads its composer as "steer" — or "idle" once the turn has ended (`allowIdle`, the pre-write
8394
8459
  * re-check). "queue" (the user's choice), text in the box, or a screen it cannot read: not now — the caller waits for
8395
8460
  * the idle prompt as for any message. AgEnD never switches the mode. Backends without the reader are not asked.
8461
+ * #2676: an ordinary message (`steerOnly` false) goes in on "queue" too — kiro takes it into the same tray either way,
8462
+ * held for the turn's end instead of steered into it.
8396
8463
  */
8397
- async steerComposerAdmits(allowIdle) {
8464
+ async steerComposerAdmits(allowIdle, steerOnly = true) {
8398
8465
  const read = this.backend?.readSteerComposer;
8399
8466
  if (!read)
8400
8467
  return true;
8401
8468
  if (!this.tmux)
8402
8469
  return false;
8403
- let mode;
8470
+ let pane;
8404
8471
  try {
8405
- mode = read.call(this.backend, await this.tmux.capturePane());
8472
+ pane = await this.tmux.capturePane();
8406
8473
  }
8407
8474
  catch {
8408
8475
  return false;
8409
8476
  }
8410
- return mode === "steer" || (allowIdle && mode === "idle");
8477
+ return composerModeAdmits(read.call(this.backend, pane), allowIdle, steerOnly) && this.busyInputReachesTurn(pane);
8478
+ }
8479
+ /** #2682: a busy composer's typed input reaches the CLI's own turn (busyTurnTakesInput); an idle box, or no reader: yes. */
8480
+ busyInputReachesTurn(pane) {
8481
+ const mode = this.backend?.readSteerComposer?.(pane);
8482
+ if (mode !== "steer" && mode !== "queue")
8483
+ return true;
8484
+ return this.backend?.busyTurnTakesInput?.(pane) !== false;
8485
+ }
8486
+ /**
8487
+ * #2676: whether an ordinary message may be typed into this CLI's busy composer — a mode-switched one (kiro TUI) on a
8488
+ * launch whose busy composer AgEnD drives (the same evidence as a steer: KIRO_STEER_VERIFIED). The legacy UI, an
8489
+ * unlisted version and every backend without the reader answer false; claude and codex hand off by
8490
+ * supportsQueuedInput instead.
8491
+ */
8492
+ composerTakesBusyInput() {
8493
+ return !!this.backend?.readSteerComposer && this.backend.supportsSteer?.() === true;
8494
+ }
8495
+ /**
8496
+ * #2676: whether the box can show this payload as this delivery's paste before the Enter (steerPasteIsOurs): its
8497
+ * first line, or a collapsed paste's line count. A one-line payload kiro would collapse (over 500 characters) shows only
8498
+ * a character count, which kiro's own normalisation (tabs widened) makes no proof: it waits for the idle prompt.
8499
+ * kiro measures after widening each tab to its 2-column stop, so a tab is counted as 2 here (at most what it becomes).
8500
+ */
8501
+ composerCanShowPaste(formatted) {
8502
+ return /[\r\n]/.test(formatted) || formatted.replace(/\t/g, " ").length <= KIRO_COLLAPSE_CHARS;
8411
8503
  }
8412
8504
  /**
8413
8505
  * #1405: one look at a mode-switched composer for a steer's own proof: on the tmux of this write, inside `deadline`
@@ -8441,10 +8533,18 @@ export class Daemon extends EventEmitter {
8441
8533
  if (first === "")
8442
8534
  return false;
8443
8535
  const row = norm(shown);
8536
+ // #2676: a long paste is collapsed to a chip naming its line count (kiro TUI: more than 10 lines or 500 characters);
8537
+ // it is this paste when that count is exactly this payload's as kiro counts it. tmux pastes every LF as CR (no -r),
8538
+ // so a CRLF arrives as CR CR, and kiro turns each CR into a line break: every CR and every LF is one.
8539
+ const collapsed = this.backend?.readSteerComposerPasteLines?.(shown);
8540
+ if (collapsed != null)
8541
+ return collapsed > 1 && collapsed === formatted.split(/\r|\n/).length;
8444
8542
  // The marker line holds nothing but the marker: the row is exactly it.
8445
8543
  if (/^\[agend-(?:delivery|human)-id:[^\]\s]+\]$/.test(first))
8446
8544
  return row === first;
8447
- return row === first || row.startsWith(`${first} `);
8545
+ // #2676: a first line wider than the box is word-wrapped onto indented rows (live, 2.34.0): the row is its start, cut
8546
+ // at a word boundary.
8547
+ return row === first || row.startsWith(`${first} `) || first.startsWith(`${row} `);
8448
8548
  }
8449
8549
  /**
8450
8550
  * Codex can paint a prompt before the TTY enters raw mode. Both are required.
@@ -8591,6 +8691,18 @@ export class Daemon extends EventEmitter {
8591
8691
  if (this.needsStartupInputProof()) {
8592
8692
  return await this.hasPositiveDeliveryInput() ? "ready" : "transient";
8593
8693
  }
8694
+ // #2682: a backend that can read its own idle input box (kiro's TUI) must show it before an idle paste. Anything
8695
+ // else — another program owning the pane, a frame it cannot read, a capture that fails — is not one to type into.
8696
+ if (this.backend?.idleComposerReady && this.tmux) {
8697
+ try {
8698
+ if (!this.backend.idleComposerReady(await this.tmux.capturePane()))
8699
+ return "busy";
8700
+ }
8701
+ catch (err) {
8702
+ this.logger.debug({ err }, "capture-pane failed during the composer check — treating the pane as not ready");
8703
+ return "busy";
8704
+ }
8705
+ }
8594
8706
  if (this.backend?.dropsEnterWhileBusy?.() !== true)
8595
8707
  return "ready";
8596
8708
  const prompt = this.backend.getBottomReadyPattern?.();
@@ -9234,15 +9346,16 @@ export class Daemon extends EventEmitter {
9234
9346
  }
9235
9347
  // #1405: on that same last capture a mode-switched composer (kiro TUI) must still read "steer" — or "idle", the
9236
9348
  // turn over. "queue", text in the box or an unreadable row: not written; handled as the unread box above.
9237
- if (handingOffToNativeQueue && steer && this.backend?.readSteerComposer
9238
- && pasteBaseline?.steerComposer !== "steer" && pasteBaseline?.steerComposer !== "idle") {
9349
+ // #2676: an ordinary message typed into it (every other hand-off there) may also find "queue".
9350
+ if (handingOffToNativeQueue && this.backend?.readSteerComposer
9351
+ && (!composerModeAdmits(pasteBaseline?.steerComposer ?? null, true, steer) || pasteBaseline?.busyInputReachesTurn === false)) {
9239
9352
  if (!verdict.durableBeginCommitted)
9240
9353
  return "handoff-box-unread";
9241
- return this.failDelivery(verdict, status, "paste", "steer-composer-not-steering");
9354
+ return this.failDelivery(verdict, status, "paste", steer ? "steer-composer-not-steering" : "composer-not-empty");
9242
9355
  }
9243
9356
  // …and the launch must still take a steer (see launchTakesSteer). Not written: before the durable begin the row
9244
- // is retried, as a steer the gate will then send down the idle path.
9245
- if (handingOffToNativeQueue && steer && !this.launchTakesSteer()) {
9357
+ // is retried, as a steer the gate will then send down the idle path (#2676: so is a message typed into the box).
9358
+ if (handingOffToNativeQueue && (steer || this.backend?.readSteerComposer) && !this.launchTakesSteer()) {
9246
9359
  verdict.fenced = !verdict.durableBeginCommitted;
9247
9360
  return false;
9248
9361
  }
@@ -9372,7 +9485,8 @@ export class Daemon extends EventEmitter {
9372
9485
  // #1405: a steer into a mode-switched composer (kiro TUI) is proven by the box alone — before the Enter it must
9373
9486
  // positively hold typed text, and after it be the empty placeholder again. The empty placeholder here means the
9374
9487
  // paste never reached the box; an unreadable box (a failed or late capture, a dialog) proves nothing: no Enter.
9375
- const steerComposerProof = handingOffToNativeQueue && steer && !!this.backend?.readSteerComposer && tmuxAtWrite !== null;
9488
+ // #2676: an ordinary message typed into the busy box is proven the same way.
9489
+ const steerComposerProof = handingOffToNativeQueue && !!this.backend?.readSteerComposer && tmuxAtWrite !== null;
9376
9490
  let humanComposerOwned = false;
9377
9491
  let steerEnterDeadline = Infinity;
9378
9492
  if (steerComposerProof) {
@@ -9473,8 +9587,8 @@ export class Daemon extends EventEmitter {
9473
9587
  if (humanComposerOwned)
9474
9588
  signature.humanPositive?.(after === "steer" ? "composer-empty-steer"
9475
9589
  : after === "queue" ? "composer-empty-queue" : "composer-empty-idle");
9476
- verdict.phase = "steer-accepted";
9477
- verdict.proof = `steer-composer-${after}`;
9590
+ verdict.phase = steer ? "steer-accepted" : "composer-accepted";
9591
+ verdict.proof = `${steer ? "steer" : "handoff"}-composer-${after}`;
9478
9592
  if (status)
9479
9593
  this.emit("message_confirmed", status); // ✅ taken from the box
9480
9594
  return true;
@@ -10165,6 +10279,7 @@ export class Daemon extends EventEmitter {
10165
10279
  collapsedPastes: input?.collapsedPastes ?? 0,
10166
10280
  inputReadable: input != null,
10167
10281
  steerComposer: this.backend?.readSteerComposer?.(pane) ?? null,
10282
+ busyInputReachesTurn: this.busyInputReachesTurn(pane),
10168
10283
  };
10169
10284
  }
10170
10285
  /**
@@ -10660,6 +10775,12 @@ export class Daemon extends EventEmitter {
10660
10775
  reply(failed ? null : answer, failed);
10661
10776
  return;
10662
10777
  }
10778
+ if (tool === "office_pack_check" || tool === "office_pack_upload") {
10779
+ // #2692: the folder (or the manifest's files) is read here, on the agent's side; the fleet gets bytes in parts.
10780
+ const answer = await sendPackSources(args, { workspace: this.config.working_directory, configuredWorkspace: this.config.working_directory, stateDir: getAgendHome(), instance: this.name }, async (payload) => { const r = await ask(payload); return r.error ? { error: "fleet", message: r.error } : (r.result && typeof r.result === "object" ? r.result : {}); });
10781
+ reply(answer, undefined);
10782
+ return;
10783
+ }
10663
10784
  if (tool === "upload_web_effect") {
10664
10785
  const owner = { fence: this.launchFenceEpoch, spawn: this.spawnGeneration, boot: this.bootId, ipc: this.ipcServer };
10665
10786
  const current = () => !!owner.ipc && owner.ipc === this.ipcServer && owner.fence === this.launchFenceEpoch && owner.spawn === this.spawnGeneration && owner.boot === this.bootId && !this.deliveryWritesStopping && !this.startupAborted;
@@ -11430,6 +11551,23 @@ export class Daemon extends EventEmitter {
11430
11551
  paneText = await this.tmux?.capturePaneWithHistory(50);
11431
11552
  }
11432
11553
  catch { /* pane may be gone */ }
11554
+ if (paneText && this.backend.resumeBlockedPattern?.().test(paneText)) {
11555
+ // #2598: a duplicate id proves the conversation exists. The generic retry escape hatch must not
11556
+ // abandon that pin or turn a store-selection error into a fresh conversation, even after many retries.
11557
+ await this.killProcessTree("SIGTERM", "spawn: retained session is blocked");
11558
+ this.startupAdmission?.();
11559
+ await this.tmux.killWindow();
11560
+ this.startupAdmission?.();
11561
+ throw new ResumeBlockedError(t("inst.kiro_resume_ambiguous"), t("inst.kiro_resume_ambiguous_remedy"));
11562
+ }
11563
+ const retained = this.backend.retainedResumeBlock?.();
11564
+ if (retained) {
11565
+ await this.killProcessTree("SIGTERM", "spawn: carried session must be preserved");
11566
+ this.startupAdmission?.();
11567
+ await this.tmux.killWindow();
11568
+ this.startupAdmission?.();
11569
+ throw new ResumeBlockedError(retained.reason, retained.remedy);
11570
+ }
11433
11571
  const proven = this.paneSaysNoConversation(paneText);
11434
11572
  if (!proven) {
11435
11573
  const failures = this.bumpUnprovenResumeFailures();
@@ -11622,6 +11760,188 @@ export class Daemon extends EventEmitter {
11622
11760
  this.logger.warn({ err }, "The agent switch after resume failed — the shared entries stay; the next launch tries again");
11623
11761
  }
11624
11762
  }
11763
+ /**
11764
+ * M-2025: after a tui/V3 launch is ready, type `/session-id` and `/title` once
11765
+ * each, under the pane-write lock, with the same fences as {@link ensureBackendAgent}.
11766
+ * Does not touch the delivery epoch. A mismatch with the #2617 pin is surfaced;
11767
+ * the pin is never replaced by a file-store guess. Legacy backends return null
11768
+ * from sessionProof().
11769
+ *
11770
+ * #2683: these are AgEnD's own housekeeping, so unlike a delivery (which may join
11771
+ * a person's draft) each one goes only into a composer the final capture shows
11772
+ * positively EMPTY; Enter only once a capture shows exactly the command in the box;
11773
+ * and it counts as run only once the box is empty again — a command left in the
11774
+ * box stops here (it is taken back when the box shows exactly it), and nothing
11775
+ * else is typed after it. The id is taken only from kiro's `/session-id` alert
11776
+ * (readSessionIdAlert) on a capture after the command ran, and never when that
11777
+ * alert was already on the final capture before it was typed: an announcement
11778
+ * that was there before is not an answer to this request.
11779
+ */
11780
+ async ensureKiroSessionProof() {
11781
+ let proof = null;
11782
+ try {
11783
+ proof = this.backend?.sessionProof?.() ?? null;
11784
+ }
11785
+ catch {
11786
+ proof = null;
11787
+ }
11788
+ const tmux = this.tmux;
11789
+ if (!proof || !tmux || !this.backend)
11790
+ return;
11791
+ const windowId = tmux.getWindowId();
11792
+ const spawn = this.spawnGeneration, fence = this.launchFenceEpoch, phase = this.pauseWakeState;
11793
+ const fenced = () => !this.startupAborted && !this.deliveryWritesStopping && !this.fatalStartupBlocked
11794
+ && (phase === "active" || phase === "waking") && this.pauseWakeState === phase
11795
+ && spawn === this.spawnGeneration && fence === this.launchFenceEpoch && this.tmux === tmux;
11796
+ const deadline = performance.now() + Daemon.AGENT_SWITCH_BUDGET_MS;
11797
+ const live = () => { this.startupAdmission?.(); return fenced() && performance.now() < deadline; };
11798
+ if (!live())
11799
+ return;
11800
+ // A proof belongs to the launch that read it: an earlier launch's never stands for this one.
11801
+ try {
11802
+ clearKiroSessionProof(this.instanceDir);
11803
+ }
11804
+ catch { /* recorded again below only on a fresh match */ }
11805
+ const TIMEOUT = Symbol("deadline");
11806
+ const within = (work) => {
11807
+ const left = deadline - performance.now();
11808
+ if (left <= 0) {
11809
+ work.catch(() => { });
11810
+ return Promise.resolve(TIMEOUT);
11811
+ }
11812
+ let timer;
11813
+ return Promise.race([work, new Promise(r => { timer = setTimeout(() => r(TIMEOUT), left); })])
11814
+ .finally(() => clearTimeout(timer));
11815
+ };
11816
+ const capture = async () => {
11817
+ const pane = await within(tmux.capturePane().catch(() => null));
11818
+ return pane === TIMEOUT ? null : pane;
11819
+ };
11820
+ const pause = (ms) => within(new Promise(r => setTimeout(r, ms)));
11821
+ const op = Daemon.AGENT_SWITCH_TMUX_OP_MS;
11822
+ const box = async () => {
11823
+ const pane = await capture();
11824
+ return pane === null ? null : proof.readComposer(pane);
11825
+ };
11826
+ /**
11827
+ * Our command, and only it, is in the box: take it back — also past the deadline, on its own bounded capture.
11828
+ * Anything else there is left as it is.
11829
+ */
11830
+ const takeBack = async (command) => {
11831
+ let timer;
11832
+ const pane = await Promise.race([tmux.capturePane().catch(() => null), new Promise(r => { timer = setTimeout(() => r(null), op); })])
11833
+ .finally(() => clearTimeout(timer));
11834
+ if (pane !== null && fenced() && proof.readComposer(pane) === command)
11835
+ await tmux.deleteBackward(command.length, op);
11836
+ };
11837
+ /**
11838
+ * "ran": typed, Enter, and the box is empty again; `after` then read the pane with the capture from before the
11839
+ * paste, still under the lock. "stuck": typed but not run — nothing more may be typed. null: nothing typed.
11840
+ */
11841
+ const typeOnce = async (command, after) => {
11842
+ const wrote = await within(this.paneWriteLock.run(async () => {
11843
+ if (!live())
11844
+ return null;
11845
+ const readiness = await within(this.paneReadinessForDelivery(windowId));
11846
+ if (readiness !== "ready" || !live())
11847
+ return null;
11848
+ const before = await capture();
11849
+ if (before === null || !live())
11850
+ return null;
11851
+ if (this.inputTransientInPane(before) || !this.paneAuthoritativelyIdle(before))
11852
+ return null;
11853
+ if (proof.readComposer(before) !== "")
11854
+ return null; // a draft, or a box that cannot be read
11855
+ if (deadline - performance.now() < Daemon.AGENT_SWITCH_WRITE_RESERVE_MS)
11856
+ return null;
11857
+ if (!await tmux.pasteBuffer(command, { guard: live, timeoutMs: op }))
11858
+ return "stuck";
11859
+ let shown = null;
11860
+ for (let i = 0; i < 4 && live() && shown !== command; i++) {
11861
+ await pause(i === 0 ? Daemon.AGENT_SWITCH_PASTE_SETTLE_MS : Daemon.AGENT_SWITCH_POLL_MS);
11862
+ shown = await box();
11863
+ }
11864
+ if (shown !== command || !live()) {
11865
+ await takeBack(command);
11866
+ return "stuck";
11867
+ }
11868
+ if (!await tmux.sendSpecialKey("Enter", op)) {
11869
+ await takeBack(command);
11870
+ return "stuck";
11871
+ }
11872
+ let left = command;
11873
+ for (let i = 0; i < 6 && left !== ""; i++) {
11874
+ await pause(Daemon.AGENT_SWITCH_POLL_MS);
11875
+ if (!fenced())
11876
+ return "stuck";
11877
+ left = await box();
11878
+ }
11879
+ if (left !== "") {
11880
+ await takeBack(command);
11881
+ return "stuck";
11882
+ }
11883
+ return { ran: true, value: await after(before) };
11884
+ }));
11885
+ return wrote === TIMEOUT ? "stuck" : wrote;
11886
+ };
11887
+ try {
11888
+ const sid = await typeOnce(proof.sessionIdCommand, async (before) => {
11889
+ if (proof.readSessionIdAlert(before) !== null)
11890
+ return null; // already there: ours cannot be told apart
11891
+ for (let i = 0; i < 6 && live(); i++) {
11892
+ const pane = await capture();
11893
+ if (pane === null)
11894
+ break;
11895
+ const id = proof.readSessionIdAlert(pane);
11896
+ if (id !== null)
11897
+ return id;
11898
+ await pause(Daemon.AGENT_SWITCH_POLL_MS);
11899
+ }
11900
+ return null;
11901
+ });
11902
+ if (!live())
11903
+ return;
11904
+ if (sid === "stuck") {
11905
+ this.logger.warn("kiro /session-id did not run from an empty composer; /title is not typed after it");
11906
+ return;
11907
+ }
11908
+ // Unread/mismatch are about kiro's answer after we ran /session-id.
11909
+ // A composer that never read empty is not unread — we never asked.
11910
+ if (sid) {
11911
+ const verdict = proveKiroSessionId(proof.pinned, sid.value);
11912
+ if (verdict.kind === "mismatch") {
11913
+ const message = t("kiro.session_id_mismatch", verdict.pinned, verdict.observed);
11914
+ this.logger.warn({ pinned: verdict.pinned, observed: verdict.observed }, "kiro /session-id does not match the pinned conversation");
11915
+ this.emit("backend_launch_warning", { name: this.name, message });
11916
+ }
11917
+ else if (verdict.kind === "unread") {
11918
+ const message = t("kiro.session_id_unread");
11919
+ this.logger.warn("kiro /session-id did not answer on the pane; not guessing from files");
11920
+ this.emit("backend_launch_warning", { name: this.name, message });
11921
+ }
11922
+ else if (verdict.kind === "match" || verdict.kind === "fresh") {
11923
+ this.logger.info({ id: verdict.id, kind: verdict.kind }, "kiro /session-id on the pane");
11924
+ try {
11925
+ recordKiroSessionProof(this.instanceDir, { sessionId: verdict.id, kind: verdict.kind });
11926
+ }
11927
+ catch (err) {
11928
+ this.logger.warn({ err, id: verdict.id }, "kiro /session-id was proven on the pane but could not be recorded");
11929
+ }
11930
+ }
11931
+ }
11932
+ if (!live() || !proof.titleCommand)
11933
+ return;
11934
+ const titled = await typeOnce(proof.titleCommand, async () => true);
11935
+ if (titled && titled !== "stuck")
11936
+ this.logger.info({ title: proof.titleCommand }, "kiro /title sent for this instance");
11937
+ else if (titled === "stuck")
11938
+ this.logger.warn({ title: proof.titleCommand }, "kiro /title did not run from an empty composer");
11939
+ }
11940
+ catch (err) {
11941
+ this.startupAdmission?.();
11942
+ this.logger.warn({ err }, "kiro /session-id or /title after launch failed — the pin was not guessed from files");
11943
+ }
11944
+ }
11625
11945
  /**
11626
11946
  * Startup budget for this launch: the backend's override (resume-aware), never
11627
11947
  * below a user-configured startup_timeout_ms; undefined = trySpawn's default.
@@ -11784,6 +12104,9 @@ export class Daemon extends EventEmitter {
11784
12104
  if (ready)
11785
12105
  await this.ensureBackendAgent();
11786
12106
  this.startupAdmission?.();
12107
+ if (ready)
12108
+ await this.ensureKiroSessionProof();
12109
+ this.startupAdmission?.();
11787
12110
  return ready;
11788
12111
  }
11789
12112
  /**