Commit Graph

232 Commits

Author SHA1 Message Date
can1357 e8090bb48a feat: introduced binary file detection to prevent encoding corruption
- Introduced `isProbablyBinary` utility to sniff file headers for NUL bytes or invalid UTF-8 sequences.
- Updated `ReadTool` to use the binary sniffer, preventing mojibake corruption in output when reading non-text files.
- Refined `file-mentions` auto-reads to skip binary files and mark them as `binary` in the message transcript.
- Added comprehensive unit tests for binary detection logic, covering NUL bytes, truncated multibyte characters, and path-based file sniffing.
2026-06-30 02:59:41 +02:00
roboomp 777b609e63 fix(cli): preserved windows extension paths
Rejoined split Windows extension module paths before launch parsing finishes and stripped extended-length Win32 prefixes before Bun import and worker spawn APIs see them.

Fixes #3804
2026-06-29 11:50:36 +00:00
can1357 45918a9ccf Merge remote-tracking branch 'origin/farm/afffb7cd/fix-ptree-bytes-arraybuffer-normalize' 2026-06-28 16:08:37 +02:00
can1357 fbad280b57 feat: implemented multi-advisor concurrent runtime with tui management
- Introduced comprehensive support for multiple concurrent, independently-configured advisors via `WATCHDOG.yml` files.
- Implemented a full-screen TUI overlay for managing advisor rosters, models, tools, and instructions.
- Added session-wide advisor initialization, telemetry aggregation, and named transcript isolation.
- Enhanced advisor security and observability with secret redaction in tool results and secure XML attribute encoding.
2026-06-28 12:55:09 +02:00
roboomp 7d6a5c6de0 fix(utils): normalized ptree.bytes() return type to Uint8Array
Bun's `Response(stream).bytes()` returns the raw `ArrayBuffer` once the
body arrives in more than one chunk, which happens for subprocess stdout
past ~128 KB. The public contract of `ptree.ChildProcess.bytes()` is
`Promise<Uint8Array>`, and callers — most visibly the `ssh://` read
path's `decodeUtf8Text` — rely on `Uint8Array` methods such as `.indexOf`
and `.subarray`. On larger remote text files this surfaced as:

  TypeError: bytes.indexOf is not a function

Normalize the result at the boundary: when `Response.bytes()` hands back
an `ArrayBuffer`, wrap it in a zero-copy `Uint8Array` view before
returning. Adds a regression test that drives a 256 KB stdout payload
through `ptree.spawn(...).bytes()` and asserts the contract.

Fixes #3712
2026-06-28 10:04:53 +00:00
can1357 b5da1099af fix(pr-3347): address integration review notes 2026-06-27 02:04:51 +02:00
can1357 82b63976d8 Merge PR #3347: fix(utils): export removeWithRetries + migrate ai test files (@oldschoola) 2026-06-27 02:04:50 +02:00
can1357 a241cb0999 test: restore directory profile state after cache tests 2026-06-27 01:39:34 +02:00
can1357 9dea09e238 Merge PR #3264: feat(coding-agent): cache successful document conversions (@wolfiesch) 2026-06-27 01:39:33 +02:00
can1357 ae1650d689 refactor: renamed search and find tools to grep and glob
- Renamed the `find` and `search` tools to `glob` and `grep` respectively across the codebase to improve command clarity.
- Implemented full-stack support for the renamed tools, including CLI arguments, system prompts, SDK exports, and tool registration.
- Added automated migration logic in `settings` to transform legacy `find` and `search` configuration keys to their new equivalents.
- Updated the `collab-web` renderer registry to ensure backwards compatibility with legacy tool outputs.
2026-06-27 00:57:55 +02:00
can1357 97845b3d69 feat(coding-agent): added configurable worktree base directory
- Added a `worktree.base` setting to allow users to specify a custom directory for agent-managed git worktrees.
- Updated the `worktree` command to ensure settings are initialized before operations to respect the configured base path.
- Enhanced directory resolution logic to support `~` expansion and enforce absolute paths for worktree environments.
2026-06-27 00:30:47 +02:00
can1357 eb4a02433c refactor: consolidated json parsing and stream utilities
- Centralized JSON parsing and stream processing logic by moving utilities from `packages/ai` to the shared `@oh-my-pi/pi-utils` package.
- Standardized import paths for JSON parsing and streaming across the agent, ai, and coding-agent packages.
- Refactored SSE stream handling to use consolidated `parseStreamingJson` logic and introduced robust error recovery for malformed container-shaped tail events.
- Cleaned up legacy bundled registry references and updated related module exports and tests to reflect the new utility structure.
2026-06-27 00:11:42 +02:00
oldschoola d87c3e9ed8 fix(utils): increase EBUSY retry delay from 25ms to 50ms
The retry-on-EBUSY logic in removeSyncWithRetries/removeWithRetries
used 40 retries × 25ms = 1 second total. Windows can hold file locks
on SQLite databases for up to ~1.5s after close(), so tests that
already used removeSyncWithRetries (e.g. settings-manager.test.ts,
sdk-credential-disabled-bridge.test.ts) still failed with EBUSY.

Fix: increase the delay to 50ms (40 × 50ms = 2s total window). This
only affects Windows — the retry logic only runs on win32. Linux CI
is unaffected.

(cherry picked from commit ac67e96f1285ce0d80b2022c40c383b7ca262354)
2026-06-26 23:43:03 +02:00
can1357 9cd9349d05 Merge PR #3362: fix(utils): handle trailing-truncated JSON in readSseJson (@usr-bin-roygbiv) 2026-06-26 23:27:38 +02:00
can1357 a13c8d2698 fix(utils): prevented winston warnings when transports are disabled
- Set logger to silent mode when no transports are active to avoid "no transports" errors during log emission.
- Added a regression test to verify that disabling all transports suppresses warnings and that log output resumes after re-enabling transports.
2026-06-25 12:46:49 +02:00
can1357 2c80863e55 fix(utils): silenced logger when no transports are configured
- Added a check for empty transport arrays during logger initialization.
- Set the logger to silent mode if no transports exist to prevent unnecessary warning messages on every log emit.
2026-06-25 12:45:02 +02:00
usr_bin_roygbiv 5f22e58a61 fix(utils): require string closed in hasValidPredecessorForComma 2026-06-23 23:53:04 -05:00
usr_bin_roygbiv 2a31d063b2 fix(utils): handle string escapes and partial unicode escapes at EOF in getClosingSuffix 2026-06-23 23:43:46 -05:00
usr_bin_roygbiv 4528f5414a fix(utils): gate literal completion to non-inString state in getClosingSuffix 2026-06-23 23:39:56 -05:00
usr_bin_roygbiv 3a91053566 fix(utils): transition arrays back to expect_value on comma in scanJsonState 2026-06-23 23:36:28 -05:00
usr_bin_roygbiv a971f1aa9b fix(utils): validate comma predecessor using parser state instead of character rules 2026-06-23 23:32:42 -05:00
usr_bin_roygbiv fde4a33a59 fix(utils): handle invalid comma predecessors in isJsonTruncated 2026-06-23 23:29:36 -05:00
usr_bin_roygbiv 5032116702 fix(utils): handle truncated JSON gracefully in readSseJson 2026-06-23 23:23:55 -05:00
usr_bin_roygbiv 4d8a85e028 fix(utils): handle truncated JSON gracefully in readSseJson 2026-06-23 23:20:17 -05:00
oldschoola 63e075f75d fix(utils): export removeWithRetries for async test cleanup on Windows
The async removeWithRetries function in packages/utils/src/temp.ts was
used internally by TempDir.remove() but not exported, while the sync
variant (removeSyncWithRetries) was exported. This inconsistency forced
tests with async cleanup hooks (afterEach(async () => ...)) to use
fs.rm directly, which fails with EBUSY on Windows when SQLite database
files are still locked by the process.

Fix: export removeWithRetries so async tests can import it from
@oh-my-pi/pi-utils and use retry-enabled cleanup. Migrated
auth-storage-api-key-login.test.ts as a demonstration — 5 EBUSY
failures now pass consistently on Windows.
2026-06-23 12:36:42 -07:00
Wolfgang Schoenberger 2cb892ef1f feat(coding-agent): cache successful document conversions
Repeated reads of unchanged PDFs, Office documents, and EPUBs re-ran the
full markit conversion every time. Add a transparent, content-addressed
cache for successful conversions keyed by SHA-256(content) + normalized
extension, so repeat reads reuse converted markdown instead of
reconverting.

- packages/utils: XDG-aware getDocumentConversionCacheDir() helper
- coding-agent: markit-cache module (bounded 256 MiB, oldest-first prune,
  best-effort writes that never fail conversion) layered over the central
  convertFileWithMarkit/convertBufferWithMarkit wrappers
- imageDir conversions stay uncached (cache:"skipped") to preserve PDF
  image extraction side effects; failed/empty/aborted conversions are
  never cached
- abort-safe: file byte reads run under untilAborted; cache I/O rechecks
  the signal
2026-06-22 16:54:13 -07:00
can1357 f29822bb4d fix(utils): forwarded timeout option to fetch calls
- Included the timeout option in the initialization object when prepareInit is absent.
- Ensured that custom timeout settings are preserved for long-running streams instead of being silently dropped.

Fixes #2422
2026-06-21 17:57:26 +02:00
oldschoola fa903b2b2c fix(test): migrate fs.rmSync to removeSyncWithRetries for EBUSY-safe cleanup
Export removeSyncWithRetries from @oh-my-pi/pi-utils as a standalone
function, then migrate the highest-impact fs.rmSync call sites:

- test/helpers/temp-home-cleanup.ts: 2 fs.rmSync → removeSyncWithRetries
  (affects all tests using the cleanupTempHome helper)
- test/core/apply-patch-regression.test.ts: 16 fs.rmSync → removeSyncWithRetries
  (the most fs.rmSync calls of any test file)

removeSyncWithRetries retries on EBUSY/EPERM/ENOTEMPTY (40x25ms on
Windows), matching TempDir.removeSync's retry logic. On Linux/macOS
(CI) the retries are a no-op — fs.rmSync succeeds immediately.
2026-06-19 17:27:54 -07:00
can1357 2de02f2119 Merge PR #3019: fix: Windows test failures — path handling, EBUSY, SQLite handle leaks (@oldschoola) 2026-06-19 17:17:04 +02:00
can1357 6486e2a14a Merge PR #3021: fix(ipc): harden worker IPC send against async EPIPE rejections (@oldschoola) 2026-06-19 17:16:37 +02:00
can1357 80a0a1b8a8 feat(utils): replaced createAbortableStream with abortableSource
- Introduced `abortableSource` as a lighter, direct-reader async generator.
- Removed the `createAbortableStream` public API to eliminate unnecessary stream wrapper layers.
- Updated internal stream processing to use `abortableSource` for improved memory and performance.
2026-06-19 16:06:18 +02:00
can1357 6d7dab0c68 fix(coding-agent): prevented crash when resuming session in deleted directory
- Export `directoryExists` in `utils` to safely validate working directories before traversal.
- Update `SessionManager` and startup logic to fallback to the launch directory if a session's recorded working directory no longer exists.
- Add regression tests to ensure sessions now correctly adopt the launch directory instead of crashing on missing paths.
2026-06-19 16:06:01 +02:00
oldschoola 23565e3e58 fix(ipc): hardened worker IPC send against async EPIPE rejections
- Added `safeSend` helper wrapping `Subprocess.send()` so sync throws and async EPIPE rejections cannot escape.
- Replaced inline try/catch send wrappers in STT, TTS, and tiny-title clients with shared `safeSend`.
- Added `isIpcSendEpipe` predicate and made matching rejections non-fatal in the `unhandledRejection` handler.
- Added contract tests for `safeSend` and `isIpcSendEpipe` covering sync throws, async rejections, and edge cases.
2026-06-18 21:42:02 -07:00
oldschoola 14252e71cb fix: Windows test failures — path handling, EBUSY, SQLite handle leaks
Fix all Windows-specific test failures caused by path handling problems
and EBUSY errors from unclosed SQLite database handles.

Root causes fixed:
1. POSIX path assumptions: replaced hard-coded file:///tmp, /repo, etc.
   with pathToFileURL/path.resolve/path.join computed expectations
2. shortenPath() now normalizes backslashes to forward slashes after ~
   and respects home directory boundaries
3. HistoryStorage.resetInstance() leaked its Database — added #close()
   that finalizes all prepared statements and closes the DB
4. AgentStorage gained the same resetInstance()/#close() pattern
5. SqliteAuthCredentialStore.close() leaked one-off prepared statements
   from inline this.#db.prepare() calls — wrapped each in try/finally
6. model-cache.ts used a process-global DB even for custom dbPath —
   now opens/closes per-call via withModelCacheDb
7. createAgentSession leaked AuthStorage on construction failure —
   added ownsAuthStorage cleanup in catch block
8. MnemopiBackend.removeDbFiles() now truly best-effort (catches errors)
9. TempDir retry window expanded from 4x10ms to 40x25ms
10. TempDir prefix convention: non-@ prefixes created dirs relative to
    cwd instead of os.tmpdir() — all test temp dirs now use @ prefix
11. Shell-escaped interpolated paths in bash tool tests
12. git core.autocrlf false in autoresearch test repo init

All 522 previously-failing Windows tests now pass.
2026-06-18 21:32:38 -07:00
can1357 3998d95088 feat: standardized tab expansion to fixed width
- Removed configurable tab width support and the `display.tabWidth` setting across all packages.
- Deleted obsolete utility functions `getIndentation`, `getIndentationNoescape`, and `setDefaultTabWidth`.
- Standardized tab expansion logic to use a fixed `DEFAULT_TAB_WIDTH` globally.
- Cleaned up related configuration schemas, test suites, and internal API signatures to remove path-dependency.
2026-06-19 04:48:41 +02:00
can1357 f5ebab2b83 feat(utils): vendor mermaid rendering 2026-06-18 18:52:38 +02:00
can1357 0386d44fec refactor(ai): replaced abort signal timeouts with clearable fetch timers
- Prevents absolute `AbortSignal.timeout` from cutting off active stream bodies by introducing a clearable pre-response timer.
- Clears the watchdog timer for Bedrock, Gemini, Ollama, and Codex providers once headers are received.
- Restores regular caller abort signaling capability on the combined fetch stream.
- Adds comprehensive fake-timer tests to cover the timeout arming and clearing lifecycle.
2026-06-18 01:57:23 +02:00
can1357 dcd1836d51 feat(utils): added isTerminalHeadless/setTerminalHeadless terminal-suppression flag
- Added `isTerminalHeadless()` / `setTerminalHeadless()` to `env`, a process-wide switch that suppresses real-terminal side effects (stdout escape/frame writes, stdin raw mode, CSI/OSC probes, SIGWINCH, window-title changes, emergency restore).
- Defaulted the flag to `isBunTestRuntime()` so it engages when `bun test` sets `NODE_ENV=test`, and made `setTerminalHeadless` return the previous value so callers can restore exact prior state.
2026-06-17 01:20:37 +02:00
can1357 5bce7ed6df feat: added advisory transcript formatting and one-shot benchmark metrics
- Introduced advisory note output as `<advisory>` tags with optional severity and guidance.
- Updated session transcript formatting to `### Session update` and inline watched role labels.
- Added shared `escapeXmlText` utility and escaped XML-sensitive text in advisor outputs.
- Added one-shot success run token metrics and one-shot statistics reporting.
2026-06-16 18:34:50 +02:00
Can Bölük fb157f4abc Merge pull request #2637 from Parsifa1/fix/xdg-fix
fix: align tool cache paths with XDG dirs
2026-06-15 13:43:32 +02:00
Parsifa1 ed5855807f fix: align tool cache paths with XDG dirs 2026-06-15 11:28:36 +00:00
can1357 3ab675a83b fix: added buffered worker inboxing and standardized worker selectors
- Added `WorkerInbox` and `installWorkerInbox(port)` to queue worker messages before bind.
- Added `consumeWorkerInbox()` to replay buffered messages and clear one active inbox.
- Added buffered inbox consumption in JS and tab worker transports before direct message handlers.
- Normalized worker selector arguments to the `__omp_worker_*` naming across workers and tests.
2026-06-15 11:59:44 +02:00
can1357 3f82589ec1 fix: fixed OAuth and profile-boundary regressions across CLI and env handling
- Fixed OAuth credentials to keep unknown fields in schema while preserving existing shape checks.
- Fixed MCP OAuth IDs to be profile-scoped and avoid deleting credentials from non-active profiles.
- Fixed string-flag parsing so PROFILE_BOOTSTRAP_BOUNDARY tokens are not consumed as values.
- Fixed active-profile directory resolution to refresh after env updates so profile .env overrides apply.
2026-06-15 03:20:45 +02:00
Ogrodev 932ebe9a48 Merge remote-tracking branch 'upstream/main' into feat/profiles-and-alias
# Conflicts:
#	.github/actions/build-native/action.yml
#	.github/workflows/ci.yml
2026-06-14 21:26:03 -03:00
Ogrodev f9bc96e96c fix(coding-agent): harden profile auth shipping gaps 2026-06-14 20:30:50 -03:00
Ogrodev 0123a46f83 Merge remote-tracking branch 'upstream/main' into feat/profiles-and-alias
# Conflicts:
#	packages/coding-agent/src/cli/args.ts
2026-06-14 19:10:31 -03:00
roboomp d7d94949fa fix(tts): isolated kokoro onnxruntime loading
Loaded Kokoro's side-installed transformers runtime by absolute path before requiring kokoro-js, avoiding host/workspace onnxruntime libraries in the worker process.

Kept runtime-cache bare module requests inside the registered runtime cache when the parent module is already inside that cache, and covered the resolver boundary with a regression test.

Fixes #2591
2026-06-14 21:56:50 +00:00
can1357 e69fa5efd2 style(utils): sort temp.ts imports to satisfy biome
The added node:fs/promises import preceded node:fs, which biome's
organizeImports rejects and fails CI lint. Reorder to unblock merge.

Addresses review feedback on #2382.
2026-06-14 17:27:15 +02:00
oldschoola 0d83a0fabc fix(utils): drop sleepSync type assertion; add EBUSY retry tests 2026-06-14 17:23:06 +02:00
oldschoola e19516aa91 fix(utils): retry TempDir removal on Windows EBUSY 2026-06-14 17:23:06 +02:00