feat/computer: add direct AutoHotkey execution and screenshots #12

Merged
BlackHatMagic merged 3 commits from feat/ahk into master 2026-11-04 00:40:21 +00:00

Summary

  • Add an opt-in Windows-only ahk tool that executes AutoHotkey v2 code directly, like bash, with stdout/error capture, cancellation, process-tree termination, and timeouts.
  • Keep persistent scripts on the normal write/edit + bash workflow; no special writer or approval dialog.
  • Add computer_screenshot for primary-monitor/full-desktop PNG capture with native coordinate metadata.
  • Render tool-result images during execution and after session reload; add Windows settings and documentation.
  • Preserve the current master Exa discovery/fallback fix.

Requested directly by the repository owner; no separate issue.

Design / security

Computer tools are disabled by default and only load on native Windows. AHK executes with full user permissions, without extra approval, as requested. Captures are sent to the selected model provider and retained in session history. Temporary scripts/captures are cleaned up. Detached apps and existing side effects are not undone by Stop.

Testing evidence

  • bun run check: typecheck + 54 tests pass.
  • bun run build: production build passes.
  • git diff --check: passes.
  • Covers inline execution without UI, output/errors, cleanup, timeouts, abort/shutdown, coordinate metadata, production extension serialization, image rendering/history, and Exa lifecycle regression.

Known validation limit

This workspace runs Linux. Native Windows AutoHotkey and real screen capture still need a Windows smoke test; process behavior is covered by deterministic helper mocks.

Checklist

  • README updated
  • Tests added and passing
  • Production build passes
  • No debug artifacts or credentials committed
## Summary - Add an opt-in Windows-only `ahk` tool that executes AutoHotkey v2 code directly, like bash, with stdout/error capture, cancellation, process-tree termination, and timeouts. - Keep persistent scripts on the normal write/edit + bash workflow; no special writer or approval dialog. - Add `computer_screenshot` for primary-monitor/full-desktop PNG capture with native coordinate metadata. - Render tool-result images during execution and after session reload; add Windows settings and documentation. - Preserve the current master Exa discovery/fallback fix. ## Related issues Requested directly by the repository owner; no separate issue. ## Design / security Computer tools are disabled by default and only load on native Windows. AHK executes with full user permissions, without extra approval, as requested. Captures are sent to the selected model provider and retained in session history. Temporary scripts/captures are cleaned up. Detached apps and existing side effects are not undone by Stop. ## Testing evidence - `bun run check`: typecheck + 54 tests pass. - `bun run build`: production build passes. - `git diff --check`: passes. - Covers inline execution without UI, output/errors, cleanup, timeouts, abort/shutdown, coordinate metadata, production extension serialization, image rendering/history, and Exa lifecycle regression. ## Known validation limit This workspace runs Linux. Native Windows AutoHotkey and real screen capture still need a Windows smoke test; process behavior is covered by deterministic helper mocks. ## Checklist - [x] README updated - [x] Tests added and passing - [x] Production build passes - [x] No debug artifacts or credentials committed
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] UTF-8 output can be corrupted across pipe chunks — src/computer-extension.ts:80

Reviewed the supplied changes against the pinned base, focusing on Windows tool execution, screenshot handling, session integration, and image rendering. No checks were run, and native Windows behavior could not be exercised.

Change walkthrough
Area Files Changes
Documentation (1) README.md Documents Windows computer-use setup, tool behavior, and security implications.
Other code (8) src/computer-extension.ts, src/session.ts, src/settings-data.ts, src/settings.ts (+4 more) Adds opt-in AutoHotkey execution and screenshot capture tools. Generates and loads the computer extension when enabled on Windows. Adds computer-use and interpreter-path settings. Exposes Windows computer-use settings.
Tests (5) tests/computer-extension.test.ts, tests/chat-state.test.ts, tests/chat-view.test.ts, tests/fixtures/chat-view.ts (+1 more) Adds mocked coverage for computer-tool execution, cleanup, cancellation, capture, and serialization. Covers screenshot preservation through execution and history loading. Covers tool-image rendering and replacement. Adds a screenshot update hook to the view test harness.

Review effort: 4/5.

Static observations (not validation results)
Observation Detail
Diff size 14 files, +585/-7.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed d710873af42deca5b726ab1cd91c18fc453da807 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:03b60f2e1a6cfde29b62a72c75a5ed2ad426528b2e1d74695db0c555ab66795e --> ## Pi code review **1 new actionable finding** - **[P2] UTF-8 output can be corrupted across pipe chunks** — `src/computer-extension.ts:80` Reviewed the supplied changes against the pinned base, focusing on Windows tool execution, screenshot handling, session integration, and image rendering. No checks were run, and native Windows behavior could not be exercised. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Documentation (1) | `README.md` | Documents Windows computer-use setup, tool behavior, and security implications. | | Other code (8) | `src/computer-extension.ts`, `src/session.ts`, `src/settings-data.ts`, `src/settings.ts` (+4 more) | Adds opt-in AutoHotkey execution and screenshot capture tools. Generates and loads the computer extension when enabled on Windows. Adds computer-use and interpreter-path settings. Exposes Windows computer-use settings. | | Tests (5) | `tests/computer-extension.test.ts`, `tests/chat-state.test.ts`, `tests/chat-view.test.ts`, `tests/fixtures/chat-view.ts` (+1 more) | Adds mocked coverage for computer-tool execution, cleanup, cancellation, capture, and serialization. Covers screenshot preservation through execution and history loading. Covers tool-image rendering and replacement. Adds a screenshot update hook to the view test harness. | Review effort: **4/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 14 files, +585/-7. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `d710873af42deca5b726ab1cd91c18fc453da807` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra`. Automated advisory review; no project commands or tests were executed.
@ -0,0 +77,4 @@
let output = "";
let failure: Error | undefined;
let killer: ReturnType<typeof spawn> | undefined;
const append = (chunk: Buffer): void => { output = (output + chunk.toString("utf8")).slice(-32_768); };
Collaborator

[P2] UTF-8 output can be corrupted across pipe chunks

The runner decodes each stdout and stderr chunk independently. If a multibyte UTF-8 character is split across chunks, its bytes are replaced with replacement characters rather than reconstructed.

Trigger: An AutoHotkey script writes UTF-8 output containing a multibyte character whose bytes arrive in separate pipe chunks.

Impact: The agent and user can receive corrupted window titles, file paths, or other script results, potentially preventing the agent from correctly using those results in subsequent automation.

Evidence: In src/computer-extension.ts, the shared data handler calls chunk.toString("utf8") separately for each chunk before appending it to the output. Neither stream retains an incomplete character between data events; the mocked execution tests write output in a single chunk.

**[P2] UTF-8 output can be corrupted across pipe chunks** The runner decodes each stdout and stderr chunk independently. If a multibyte UTF-8 character is split across chunks, its bytes are replaced with replacement characters rather than reconstructed. **Trigger:** An AutoHotkey script writes UTF-8 output containing a multibyte character whose bytes arrive in separate pipe chunks. **Impact:** The agent and user can receive corrupted window titles, file paths, or other script results, potentially preventing the agent from correctly using those results in subsequent automation. **Evidence:** In src/computer-extension.ts, the shared data handler calls chunk.toString("utf8") separately for each chunk before appending it to the output. Neither stream retains an incomplete character between data events; the mocked execution tests write output in a single chunk.
Author
Owner

Confirmed review finding 2320 and fixed in 4ace741. Both pipes now use setEncoding("utf8"), giving stdout and stderr independent streaming decoder state. Added a regression test with interleaved incomplete UTF-8 characters across both pipes. Typecheck, all 55 tests, production build, and diff checks pass.

Confirmed review finding 2320 and fixed in 4ace741. Both pipes now use setEncoding("utf8"), giving stdout and stderr independent streaming decoder state. Added a regression test with interleaved incomplete UTF-8 characters across both pipes. Typecheck, all 55 tests, production build, and diff checks pass.
Code-Reviewer left a comment

Pi code review

0 new actionable findings

No new actionable findings. Previously reported issues, if any, are tracked below.

Earlier findings: 1 rechecked
  • Resolved: UTF-8 output can be corrupted across pipe chunks (src/computer-extension.ts:80, first reported in review #453) — src/computer-extension.ts now calls setEncoding("utf8") independently on stdout and stderr before attaching their data handlers, preserving decoder state across chunks for each stream. tests/computer-extension.test.ts adds interleaved split-byte coverage; the test was inspected but not run.

Reviewed the pinned head against the supplied base across the Windows computer tools, session integration, image rendering, settings, documentation, and tests. This was a read-only static review; checks were not run, and native Windows behavior remains unverified.

Change walkthrough
Area Files Changes
Other code (8) src/computer-extension.ts, src/session.ts, src/chat-state.ts, src/chat-view.ts (+4 more) Add opt-in Windows AutoHotkey execution and screenshot tools with serialization, cancellation, timeouts, and temporary-file cleanup. Generate and load the computer extension when enabled on Windows and pass its settings to Pi. Preserve tool-result images during execution, completion, and history reconstruction. Render and update inline images within tool results.
Documentation (1) README.md Document Windows setup, tool behavior, permissions, screenshot retention, and cancellation limitations.
Tests (5) tests/computer-extension.test.ts, tests/chat-state.test.ts, tests/chat-view.test.ts, tests/fixtures/chat-view.ts (+1 more) Add mocked execution, output decoding, cancellation, cleanup, screenshot metadata, and generated-extension coverage. Cover tool images across streaming, completion, and session reload. Cover screenshot rendering and image updates without duplication. Extend the browser harness with tool-result screenshots.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 14 files, +606/-7.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 4ace7412710bd5c8556d67dab838f7e2e25fc006 with proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:39444e7b6df14a50c3ae8a5c83a2f34bf859684fe1a939e7d016443d05e97155 --> ## Pi code review **0 new actionable findings** No new actionable findings. Previously reported issues, if any, are tracked below. <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** UTF-8 output can be corrupted across pipe chunks (`src/computer-extension.ts:80`, first reported in review #453) — src/computer-extension.ts now calls setEncoding("utf8") independently on stdout and stderr before attaching their data handlers, preserving decoder state across chunks for each stream. tests/computer-extension.test.ts adds interleaved split-byte coverage; the test was inspected but not run. </details> Reviewed the pinned head against the supplied base across the Windows computer tools, session integration, image rendering, settings, documentation, and tests. This was a read-only static review; checks were not run, and native Windows behavior remains unverified. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (8) | `src/computer-extension.ts`, `src/session.ts`, `src/chat-state.ts`, `src/chat-view.ts` (+4 more) | Add opt-in Windows AutoHotkey execution and screenshot tools with serialization, cancellation, timeouts, and temporary-file cleanup. Generate and load the computer extension when enabled on Windows and pass its settings to Pi. Preserve tool-result images during execution, completion, and history reconstruction. Render and update inline images within tool results. | | Documentation (1) | `README.md` | Document Windows setup, tool behavior, permissions, screenshot retention, and cancellation limitations. | | Tests (5) | `tests/computer-extension.test.ts`, `tests/chat-state.test.ts`, `tests/chat-view.test.ts`, `tests/fixtures/chat-view.ts` (+1 more) | Add mocked execution, output decoding, cancellation, cleanup, screenshot metadata, and generated-extension coverage. Cover tool images across streaming, completion, and session reload. Cover screenshot rendering and image updates without duplication. Extend the browser harness with tool-result screenshots. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 14 files, +606/-7. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `4ace7412710bd5c8556d67dab838f7e2e25fc006` with `proxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra`. Automated advisory review; no project commands or tests were executed.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackHatMagic/Pi-Obsidian!12
No description provided.