@rallycry/conveyor-agent 11.1.2 → 11.1.3

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.
@@ -1515,6 +1515,16 @@ function parseEnvelope(line) {
1515
1515
  request: { id: record.id, tool_name: record.tool_name, tool_input: toolInput }
1516
1516
  };
1517
1517
  }
1518
+ if (record.kind === "notification") {
1519
+ if (typeof record.notification_type !== "string") return null;
1520
+ return {
1521
+ kind: "notification",
1522
+ notification: {
1523
+ notification_type: record.notification_type,
1524
+ message: typeof record.message === "string" ? record.message : ""
1525
+ }
1526
+ };
1527
+ }
1518
1528
  const result = {};
1519
1529
  if (typeof record.tool_name === "string") result.tool_name = record.tool_name;
1520
1530
  if (typeof record.elapsed_time_seconds === "number") {
@@ -1523,14 +1533,16 @@ function parseEnvelope(line) {
1523
1533
  return { kind: "progress", progress: result };
1524
1534
  }
1525
1535
  var HookSocketServer = class {
1526
- constructor(socketPath, onProgress, onPreToolUse) {
1536
+ constructor(socketPath, onProgress, onPreToolUse, onNotification) {
1527
1537
  this.socketPath = socketPath;
1528
1538
  this.onProgress = onProgress;
1529
1539
  this.onPreToolUse = onPreToolUse;
1540
+ this.onNotification = onNotification;
1530
1541
  }
1531
1542
  socketPath;
1532
1543
  onProgress;
1533
1544
  onPreToolUse;
1545
+ onNotification;
1534
1546
  server = null;
1535
1547
  _closed = false;
1536
1548
  async listen() {
@@ -1582,6 +1594,10 @@ var HookSocketServer = class {
1582
1594
  this.onProgress(envelope.progress);
1583
1595
  return;
1584
1596
  }
1597
+ if (envelope.kind === "notification") {
1598
+ this.onNotification?.(envelope.notification);
1599
+ return;
1600
+ }
1585
1601
  void this.respondToPreToolUse(envelope.request, socket);
1586
1602
  }
1587
1603
  async respondToPreToolUse(request, socket) {
@@ -1664,6 +1680,10 @@ process.stdin.on("end", () => {
1664
1680
  }
1665
1681
  if (payload.hook_event_name === "PreToolUse") {
1666
1682
  preToolUse(payload);
1683
+ } else if (payload.hook_event_name === "PermissionRequest") {
1684
+ permissionRequest(payload);
1685
+ } else if (payload.hook_event_name === "Notification") {
1686
+ relayNotification(payload);
1667
1687
  } else {
1668
1688
  relayProgress(typeof payload.tool_name === "string" ? payload.tool_name : "");
1669
1689
  }
@@ -1702,6 +1722,66 @@ function relayProgress(toolName) {
1702
1722
  });
1703
1723
  }
1704
1724
 
1725
+ // Tools whose dialog IS the product: the discovery plan review and the
1726
+ // questionnaire. The CLI ignores a hook allow for them anyway (they require
1727
+ // user interaction); abstaining keeps their existing dialog flows unchanged.
1728
+ const DIALOG_TOOLS = ["ExitPlanMode", "AskUserQuestion"];
1729
+
1730
+ // Answering allow here is safe because a dialog can only open AFTER Conveyor's
1731
+ // PreToolUse verdict was allow \u2014 a PreToolUse deny ends the call first. Plan
1732
+ // spawns route every tool through PreToolUse; build spawns allow everything
1733
+ // but destructive Bash, which their Bash PreToolUse hook denies. So any dialog
1734
+ // left is the CLI's own plan-mode floor or safety check, not a Conveyor
1735
+ // decision, and there is nobody at the terminal to answer it.
1736
+ function permissionRequest(payload) {
1737
+ if (DIALOG_TOOLS.includes(payload.tool_name)) {
1738
+ process.exit(0);
1739
+ return;
1740
+ }
1741
+ process.stdout.write(
1742
+ JSON.stringify({
1743
+ hookSpecificOutput: { hookEventName: "PermissionRequest", decision: { behavior: "allow" } },
1744
+ }),
1745
+ );
1746
+ process.exit(0);
1747
+ }
1748
+
1749
+ function relayNotification(payload) {
1750
+ const socketPath = process.env.CONVEYOR_HOOK_SOCKET;
1751
+ let done = false;
1752
+ const finish = () => {
1753
+ if (done) return;
1754
+ done = true;
1755
+ process.exit(0);
1756
+ };
1757
+ const fallback = setTimeout(finish, 500);
1758
+ if (!socketPath) {
1759
+ clearTimeout(fallback);
1760
+ finish();
1761
+ return;
1762
+ }
1763
+ const client = net.connect(socketPath, () => {
1764
+ const line =
1765
+ JSON.stringify({
1766
+ kind: "notification",
1767
+ notification_type:
1768
+ typeof payload.notification_type === "string" ? payload.notification_type : "",
1769
+ message: typeof payload.message === "string" ? payload.message : "",
1770
+ }) + "\\n";
1771
+ client.write(line, () => {
1772
+ client.end();
1773
+ });
1774
+ });
1775
+ client.on("close", () => {
1776
+ clearTimeout(fallback);
1777
+ finish();
1778
+ });
1779
+ client.on("error", () => {
1780
+ clearTimeout(fallback);
1781
+ finish();
1782
+ });
1783
+ }
1784
+
1705
1785
  function preToolUse(payload) {
1706
1786
  const socketPath = process.env.CONVEYOR_HOOK_SOCKET;
1707
1787
  let done = false;
@@ -1811,14 +1891,24 @@ function buildPreToolUseHooks(helperPath, gateAllTools) {
1811
1891
  hooks: [{ type: "command", command, timeout: 120 }]
1812
1892
  },
1813
1893
  {
1814
- // A hook allow bypasses the permission engine in every mode. Loose by
1815
- // design: the pod is the sandbox, and agents must call update_task etc.
1816
- // The helper answers locally (no socket).
1894
+ // Loose by design: the pod is the sandbox, and agents must call
1895
+ // update_task etc. The helper answers locally (no socket). This allow is
1896
+ // a verdict only — a dialog the CLI still opens is answered by the
1897
+ // PermissionRequest hook.
1817
1898
  matcher: "mcp__.*",
1818
1899
  hooks: [{ type: "command", command, timeout: 30 }]
1819
1900
  }
1820
1901
  ];
1821
1902
  }
1903
+ function buildDialogHooks(helperPath) {
1904
+ const command = `node ${JSON.stringify(helperPath)}`;
1905
+ return {
1906
+ PermissionRequest: [{ matcher: "*", hooks: [{ type: "command", command, timeout: 30 }] }],
1907
+ Notification: [
1908
+ { matcher: "permission_prompt", hooks: [{ type: "command", command, timeout: 10 }] }
1909
+ ]
1910
+ };
1911
+ }
1822
1912
  async function writeHookSettings(dir, opts = {}) {
1823
1913
  const helperPath = join3(dir, "hook-helper.cjs");
1824
1914
  const settingsPath = join3(dir, "settings.json");
@@ -1842,8 +1932,8 @@ async function writeHookSettings(dir, opts = {}) {
1842
1932
  // does NOT relax the planning gate: in discovery/plan mode the spawn passes
1843
1933
  // `--permission-mode plan`, which keeps file edits blocked until the agent
1844
1934
  // exits plan mode regardless of this allow-list. Plan mode still prompts
1845
- // for anything it cannot classify as read-only; the PreToolUse hooks below
1846
- // answer those. In build mode the spawn already bypasses prompts via
1935
+ // for anything it cannot classify as read-only; the PermissionRequest hook
1936
+ // below answers those. In build mode the spawn already bypasses prompts via
1847
1937
  // `--dangerously-skip-permissions`.
1848
1938
  // NOTE: a bare "*" rule is INVALID (the CLI rejects it and parks the TUI on
1849
1939
  // a Settings Warning dialog at boot) — hence the explicit ALLOW_RULES list.
@@ -1862,7 +1952,8 @@ async function writeHookSettings(dir, opts = {}) {
1862
1952
  matcher: "*",
1863
1953
  hooks: [{ type: "command", command: `node ${JSON.stringify(helperPath)}` }]
1864
1954
  }
1865
- ]
1955
+ ],
1956
+ ...buildDialogHooks(helperPath)
1866
1957
  }
1867
1958
  };
1868
1959
  await writeFile3(settingsPath, JSON.stringify(settings, null, 2), "utf8");
@@ -3258,6 +3349,14 @@ var PtySession = class {
3258
3349
  // type chat text into the questionnaire. Fail-safe — a stale flag only
3259
3350
  // costs a teardown + respawn (`--resume` recovers the conversation).
3260
3351
  questionnairePending = false;
3352
+ // Parked-permission-dialog backstop (see handleHookNotification). The last
3353
+ // tool the PreToolUse hook saw over the socket, cleared once that tool runs:
3354
+ // a parked ExitPlanMode/AskUserQuestion dialog is an expected wait, not an
3355
+ // alert. MCP tools are answered without the socket and never set it.
3356
+ lastPreToolUseTool = null;
3357
+ // One alert per parked dialog: set when the backstop fires, cleared when
3358
+ // any tool runs (the dialog was answered) or a new turn starts.
3359
+ permissionAlertArmed = false;
3261
3360
  // Per-turn state: the prompt to feed and the per-turn options subset. Both
3262
3361
  // start from the constructor args (turn 1) and are replaced by beginTurn.
3263
3362
  turnPrompt;
@@ -3447,6 +3546,8 @@ var PtySession = class {
3447
3546
  this.disarmSubmitNudge();
3448
3547
  this.disarmPlanDialogAutoAccept();
3449
3548
  this.questionnairePending = false;
3549
+ this.permissionAlertArmed = false;
3550
+ this.lastPreToolUseTool = null;
3450
3551
  this.closeSyntheticQuestionCards();
3451
3552
  }
3452
3553
  /**
@@ -3703,7 +3804,8 @@ var PtySession = class {
3703
3804
  this.socket = new HookSocketServer(
3704
3805
  socketPath,
3705
3806
  (progress) => this.handleProgress(progress),
3706
- (request) => this.handlePreToolUse(request)
3807
+ (request) => this.handlePreToolUse(request),
3808
+ (notification) => this.handleHookNotification(notification)
3707
3809
  );
3708
3810
  await this.socket.listen();
3709
3811
  const { settingsPath } = await writeHookSettings(this.tempDir, {
@@ -4167,6 +4269,10 @@ var PtySession = class {
4167
4269
  this.disarmPlanDialogAutoAccept();
4168
4270
  }
4169
4271
  if (progress.tool_name === "AskUserQuestion") this.questionnairePending = false;
4272
+ this.permissionAlertArmed = false;
4273
+ if (progress.tool_name !== void 0 && progress.tool_name === this.lastPreToolUseTool) {
4274
+ this.lastPreToolUseTool = null;
4275
+ }
4170
4276
  if (this.pendingSubmitNudge) this.disarmSubmitNudge();
4171
4277
  this.pushEvent({
4172
4278
  type: "tool_progress",
@@ -4184,6 +4290,7 @@ var PtySession = class {
4184
4290
  */
4185
4291
  async handlePreToolUse(request) {
4186
4292
  if (this.pendingSubmitNudge) this.disarmSubmitNudge();
4293
+ this.lastPreToolUseTool = request.tool_name;
4187
4294
  if (request.tool_name === "AskUserQuestion") {
4188
4295
  this.disarmSubmitNudge();
4189
4296
  this.disarmPlanDialogAutoAccept();
@@ -4206,6 +4313,39 @@ var PtySession = class {
4206
4313
  }
4207
4314
  return verdict;
4208
4315
  }
4316
+ /**
4317
+ * The CLI's `permission_prompt` notification: a permission dialog has been
4318
+ * open ~6s with nobody answering it. The PermissionRequest hook answers
4319
+ * every dialog Conveyor can answer, so one still parked means the CLI found
4320
+ * a new way to ask. Raise the existing needs-input alert (a `user_question`
4321
+ * event → `waiting_for_input`/`user_question`) rather than sending a blind
4322
+ * keypress, which could approve or cancel the wrong thing.
4323
+ *
4324
+ * Ignored for the expected parked states — an open questionnaire, the plan
4325
+ * dialog auto-accept loop, a discovery plan review — and while an alert for
4326
+ * the same dialog is already up.
4327
+ */
4328
+ handleHookNotification(notification) {
4329
+ if (notification.notification_type !== "permission_prompt") return;
4330
+ if (this.questionnairePending || this.pendingPlanApproval || this.permissionAlertArmed) return;
4331
+ if (this.lastPreToolUseTool === "ExitPlanMode" || this.lastPreToolUseTool === "AskUserQuestion") {
4332
+ return;
4333
+ }
4334
+ this.permissionAlertArmed = true;
4335
+ const message = notification.message.trim() || "Claude needs your permission";
4336
+ process.stderr.write(`[PtySession] permission dialog parked: ${message}
4337
+ `);
4338
+ this.pushEvent({
4339
+ type: "user_question",
4340
+ questions: [
4341
+ {
4342
+ question: `Claude Code is waiting on a permission dialog (${message}). Answer it in the Claude tab.`,
4343
+ header: "Permission",
4344
+ options: []
4345
+ }
4346
+ ]
4347
+ });
4348
+ }
4209
4349
  /**
4210
4350
  * A hook "allow" does not bypass the CLI's plan-approval dialog — it renders
4211
4351
  * right after the verdict and parks the turn until answered. Press Enter
package/dist/cli.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  resolveTuiKindFromEnv,
26
26
  sampleKeyUsage,
27
27
  usesNativeUsageReporting
28
- } from "./chunk-U3X4LTN4.js";
28
+ } from "./chunk-VXGZSCRL.js";
29
29
  import "./chunk-V5WR2F2P.js";
30
30
  import {
31
31
  inheritedEnv,
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SessionRunner,
3
3
  unshallowRepo
4
- } from "./chunk-U3X4LTN4.js";
4
+ } from "./chunk-VXGZSCRL.js";
5
5
  import "./chunk-V5WR2F2P.js";
6
6
  import "./chunk-76JCOHPE.js";
7
7
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rallycry/conveyor-agent",
3
- "version": "11.1.2",
3
+ "version": "11.1.3",
4
4
  "description": "Conveyor Agent Runner v10 - PTY harness for the task chat (SDK harness for audit/project-chat). Agent-as-User architecture with BaseService patterns. Works locally too.",
5
5
  "keywords": [
6
6
  "agent",