@code-yeongyu/senpi 2026.9.19-2 → 2026.9.20
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/CHANGELOG.md +53 -0
- package/dist/bundle/chunks/{app-server-command-QBJ4GPN7.js → app-server-command-B35FQUTE.js} +1 -1
- package/dist/bundle/chunks/{bun-extension-importer-JQZRPNJH.js → bun-extension-importer-HHH4TV4B.js} +3 -3
- package/dist/bundle/chunks/{chunk-YRN3PCTM.js → chunk-DQZB4GVV.js} +4 -4
- package/dist/bundle/chunks/{chunk-EHSDTQ6I.js → chunk-E5R67F7G.js} +37 -37
- package/dist/bundle/chunks/{chunk-5E5TLB76.js → chunk-TWGC3TBR.js} +2 -2
- package/dist/bundle/chunks/{chunk-RLRLQRI2.js → chunk-V2ZB62DG.js} +1 -1
- package/dist/bundle/chunks/{chunk-3FRTRCR6.js → chunk-YXQG2SUX.js} +2 -2
- package/dist/bundle/chunks/{chunk-PLZK7ABD.js → chunk-Z4LHCTJ6.js} +1 -1
- package/dist/bundle/chunks/{chunk-3Q4WGKFA.js → chunk-ZMFHNH6U.js} +1 -1
- package/dist/bundle/chunks/{cli-main-MLJ2H637.js → cli-main-USVT7JMN.js} +1 -1
- package/dist/bundle/chunks/{interactive-host-runtime-AITXUDCT.js → interactive-host-runtime-ELBAZ4LN.js} +1 -1
- package/dist/bundle/chunks/{interactive-mode-7C75IXNF.js → interactive-mode-R6225BKI.js} +1 -1
- package/dist/bundle/chunks/{list-tips-KTDNGQUK.js → list-tips-Z7T2ACVU.js} +1 -1
- package/dist/bundle/chunks/{multi-session-host-2YCJKQOL.js → multi-session-host-QNEBJW2P.js} +3 -3
- package/dist/bundle/chunks/{package-manager-cli-4ANSELYT.js → package-manager-cli-4MVJ3JSE.js} +1 -1
- package/dist/bundle/chunks/{rpc-mode-OPFQIWFP.js → rpc-mode-CXVDRIBU.js} +1 -1
- package/dist/bundle/chunks/{session-picker-DXCITGLS.js → session-picker-6N666KQZ.js} +1 -1
- package/dist/bundle/chunks/session-worker.js +66 -66
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +14 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +45 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +233 -11
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/extension.js +16 -5
- package/dist/core/extensions/builtin/ask-user/extension.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/format.d.ts +5 -0
- package/dist/core/extensions/builtin/ask-user/format.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/format.js +4 -0
- package/dist/core/extensions/builtin/ask-user/format.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/notify.d.ts +2 -0
- package/dist/core/extensions/builtin/ask-user/notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/notify.js +2 -0
- package/dist/core/extensions/builtin/ask-user/notify.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/registry.d.ts +15 -2
- package/dist/core/extensions/builtin/ask-user/registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/registry.js +13 -0
- package/dist/core/extensions/builtin/ask-user/registry.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/render.d.ts +6 -0
- package/dist/core/extensions/builtin/ask-user/render.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/render.js +9 -0
- package/dist/core/extensions/builtin/ask-user/render.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/resume.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/resume.js +59 -24
- package/dist/core/extensions/builtin/ask-user/resume.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/tool.d.ts +1 -1
- package/dist/core/extensions/builtin/ask-user/tool.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/tool.js +98 -17
- package/dist/core/extensions/builtin/ask-user/tool.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/model-usability-budget.d.ts +18 -0
- package/dist/core/extensions/builtin/compaction/model-usability-budget.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/model-usability-budget.js +16 -8
- package/dist/core/extensions/builtin/compaction/model-usability-budget.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/switch-admission.d.ts +23 -0
- package/dist/core/extensions/builtin/compaction/switch-admission.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/switch-admission.js +19 -0
- package/dist/core/extensions/builtin/compaction/switch-admission.js.map +1 -0
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +10 -0
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/bun-extension-commonjs.d.ts +1 -1
- package/dist/core/extensions/bun-extension-commonjs.d.ts.map +1 -1
- package/dist/core/extensions/bun-extension-commonjs.js +3 -3
- package/dist/core/extensions/bun-extension-commonjs.js.map +1 -1
- package/dist/core/extensions/bun-extension-importer.d.ts.map +1 -1
- package/dist/core/extensions/bun-extension-importer.js +4 -1
- package/dist/core/extensions/bun-extension-importer.js.map +1 -1
- package/dist/core/extensions/bun-extension-registry.d.ts.map +1 -1
- package/dist/core/extensions/bun-extension-registry.js +5 -9
- package/dist/core/extensions/bun-extension-registry.js.map +1 -1
- package/dist/core/resolved-paths-memo.d.ts +31 -0
- package/dist/core/resolved-paths-memo.d.ts.map +1 -0
- package/dist/core/resolved-paths-memo.js +57 -0
- package/dist/core/resolved-paths-memo.js.map +1 -0
- package/dist/core/resource-loader.d.ts +4 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +25 -12
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/retry-fallback/settings.d.ts +10 -2
- package/dist/core/retry-fallback/settings.d.ts.map +1 -1
- package/dist/core/retry-fallback/settings.js +28 -6
- package/dist/core/retry-fallback/settings.js.map +1 -1
- package/dist/core/skill-discovery.d.ts.map +1 -1
- package/dist/core/skill-discovery.js +11 -1
- package/dist/core/skill-discovery.js.map +1 -1
- package/dist/main.d.ts +10 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +19 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/ask-user-answer-chip.d.ts +2 -5
- package/dist/modes/interactive/components/ask-user-answer-chip.d.ts.map +1 -1
- package/dist/modes/interactive/components/ask-user-answer-chip.js +1 -4
- package/dist/modes/interactive/components/ask-user-answer-chip.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +8 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/assistant-render-descriptors.d.ts +1 -0
- package/dist/modes/interactive/components/assistant-render-descriptors.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-render-descriptors.js +4 -0
- package/dist/modes/interactive/components/assistant-render-descriptors.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +3 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +15 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +81 -6
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/provider-error-presentation.d.ts +18 -0
- package/dist/modes/interactive/provider-error-presentation.d.ts.map +1 -0
- package/dist/modes/interactive/provider-error-presentation.js +100 -0
- package/dist/modes/interactive/provider-error-presentation.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +18 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +14 -0
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +9 -1
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +21 -0
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js +9 -2
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/dist/modes/rpc/session-worker-requests.d.ts +10 -1
- package/dist/modes/rpc/session-worker-requests.d.ts.map +1 -1
- package/dist/modes/rpc/session-worker-requests.js +8 -2
- package/dist/modes/rpc/session-worker-requests.js.map +1 -1
- package/dist/modes/rpc/session-worker-requests.test.d.ts +2 -0
- package/dist/modes/rpc/session-worker-requests.test.d.ts.map +1 -0
- package/dist/modes/rpc/session-worker-requests.test.js +44 -0
- package/dist/modes/rpc/session-worker-requests.test.js.map +1 -0
- package/docs/rpc.md +7 -0
- package/docs/settings.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +12 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.js +26 -3
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +13 -6
- package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +11 -3
- package/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +15 -2
- package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js +45 -2
- package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,59 @@
|
|
|
12
12
|
|
|
13
13
|
### Removed
|
|
14
14
|
|
|
15
|
+
## [2026.9.20] - 2026-09-20
|
|
16
|
+
|
|
17
|
+
### Breaking Changes
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Fable 5 ships with a fallback chain again. A refusal or a rate limit on `claude-fable-5-1` or `claude-fable-5` used to end the turn with an error unless you had written `retry.fallbackChains` yourself. The session now steps down to Opus 5, then Opus 4.8, then Opus 4.6, each at max thinking, and it never leaves the Anthropic family: the default removed on 2026-09-05 led with Kimi K3 rungs, so a Claude session changed vendor mid-turn. Your own configuration still wins. A chain under the same key replaces the shipped one, an empty array turns it off, and `retry.modelFallback: false` disables fallback entirely. ([#1860](https://github.com/code-yeongyu/senpi/issues/1860))
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- Typing works again after answering an ask-user question with the mouse. Clicking the option rows and the Submit line left keyboard focus on the clickable wrapper around them, which has no key handler, so the composer stayed empty while output, tools and the rest of the session carried on as usual. Focus now resolves to a component that can receive keys, and a focus change made by a click handler is no longer overwritten afterwards. ([#1882](https://github.com/code-yeongyu/senpi/issues/1882))
|
|
28
|
+
|
|
29
|
+
- An automatic fallback no longer gives up on a model just because the conversation is currently too long for it. The chain reduces the conversation first, without asking any provider, and then hands the turn to that model. A conversation with no earlier turn to drop still fails the rung, and nothing is reduced when auto-compaction is off ([#1873](https://github.com/code-yeongyu/senpi/issues/1873)).
|
|
30
|
+
|
|
31
|
+
- Picking a model that cannot hold the conversation yet no longer throws the choice away. The switch is held, your next message compacts the conversation first - summarized by the model that can still read all of it, sized for the window it is moving into - and the new model takes over from there. Ctrl+P now only passes over a model that could never serve the session, instead of skipping anything that does not fit right now. Nothing is written down while a switch is held, so a session that ends before the next message is still on the model it was using ([#1873](https://github.com/code-yeongyu/senpi/issues/1873)).
|
|
32
|
+
|
|
33
|
+
- Switching models no longer fails because of headroom the switch does not need. Admission used to charge the speculation lead - the margin the background compactor works inside - against a transcript that had not been admitted yet, so a model the session would have fit onto was refused with a token shortfall smaller than the lead itself. A live switch is now admitted on whether the next request fits, which is the same reasoning already applied to resume. Starting a session on a model still charges the lead, because at that point the margin describes the model itself ([#1873](https://github.com/code-yeongyu/senpi/issues/1873)).
|
|
34
|
+
|
|
35
|
+
- Provider network failures now update one retry status instead of filling the transcript with repeated error payloads. Recovery clears the status, cancellation no longer reports a failed retry, and exhausted retries leave one notice with a next step. Partial answers and stored error details remain available, including when reopening a session. ([#1874](https://github.com/code-yeongyu/senpi/issues/1874))
|
|
36
|
+
|
|
37
|
+
- The startup timing table no longer files the help-flags cache write under the stdin read. `PI_TIMING=1` reported that work in a row named `readPipedStdin`, which returns immediately on a terminal; the write is now its own row. Timings only, no behavior change.
|
|
38
|
+
|
|
39
|
+
- Sending `.` to continue now resumes a blocked goal. Previously, the conversation continued but the goal stayed blocked until you ran `/goal resume`. ([#1871](https://github.com/code-yeongyu/senpi/issues/1871))
|
|
40
|
+
|
|
41
|
+
- An extension's `import value from "./data.json" with { type: "file" }` returns the file path again. The loader rewrites a static import of a CommonJS-shaped file so that Node's export interop keeps working, and that rewrite rebuilt the statement without the attributes that followed the specifier, so a .json, .toml or .txt asset came back parsed or as text instead of as a path. The attributes now travel with the rewritten import. ([#1864](https://github.com/code-yeongyu/senpi/issues/1864))
|
|
42
|
+
|
|
43
|
+
- `senpi` starts about five seconds faster. The command was still booting the unbundled module graph while `pi`, the other name the same package installs, had already moved onto the pre-linked bundle shipped for exactly this reason. Measured on a real TUI launch, with ready meaning the editor accepts a keystroke: 6.3 s to 1.2 s, and the work done before `main()` runs drops from 5.3 s to 0.3 s. `--version` and `--help` produce the same bytes on both Node and Bun. ([#1868](https://github.com/code-yeongyu/senpi/issues/1868))
|
|
44
|
+
|
|
45
|
+
- Building the package no longer prints two esbuild warnings. esbuild reads an `import()` only when its attributes are spelled out in the source, and the extension loader forwards whatever attributes an extension passed, so every build reported that call as unrecognized and the noise sat where a real warning would show up. The loader now builds its import function while it runs, which keeps the bundler out of it; extension imports and their attributes behave as before. ([#1862](https://github.com/code-yeongyu/senpi/issues/1862))
|
|
46
|
+
|
|
47
|
+
- Fixed Ctrl+V silently inserting nothing in the published bundle under Bun. The bundle now resolves the installed native clipboard helper instead of treating the package name as a file path. ([#1848](https://github.com/code-yeongyu/senpi/issues/1848), [#1849](https://github.com/code-yeongyu/senpi/pull/1849) by [@Daiwenxi798673133](https://github.com/Daiwenxi798673133))
|
|
48
|
+
|
|
49
|
+
- Pending questions survive a reload without resetting their answer deadline or sending a duplicate answer. ([#1857](https://github.com/code-yeongyu/senpi/issues/1857))
|
|
50
|
+
- If a question cannot be restored after reload, the user sees a notice and the model receives its outcome once. ([#1857](https://github.com/code-yeongyu/senpi/issues/1857))
|
|
51
|
+
- Unanswered async questions can be recovered after restart; settled questions are not asked again. ([#1857](https://github.com/code-yeongyu/senpi/issues/1857))
|
|
52
|
+
- Question cards retain their renderer while extensions reload. ([#1857](https://github.com/code-yeongyu/senpi/issues/1857))
|
|
53
|
+
|
|
54
|
+
- Skills that ship inside the packaged binary load again. Reading only a skill's frontmatter needs a file descriptor, and the filesystem the binary keeps its own files in hands out none, so those skills were dropped on every start and reported as a `Skill conflicts` warning instead - image generation's skill being the one users saw. A skill the binary can read is now read whole when a descriptor is refused. ([#1852](https://github.com/code-yeongyu/senpi/issues/1852))
|
|
55
|
+
|
|
56
|
+
- Reopening a session file no longer splits it in two. A session started without a file path created one but never claimed it, so opening that same file afterwards started a second session on top of the first and both wrote to it. The file is now claimed as soon as the session has one, and opening it again joins the session that already has it.
|
|
57
|
+
|
|
58
|
+
- The shared host opens sessions faster still. Every session it opened was rediscovering the same installed packages; the host now resolves them once and reuses the answer until its settings change. Measured on the daemon over its socket: eight sessions opened at once finish about 30% sooner than the previous release, and a single open about 25% sooner. ([#1844](https://github.com/code-yeongyu/senpi/issues/1844))
|
|
59
|
+
|
|
60
|
+
- The shared host opens a session faster. Every session it opened was building its own copy of the same model catalog; the host now builds one and hands it to each session, and each session refreshes only the providers it added. Measured on the daemon over its socket: a single open is about 40% faster, and eight opened at once finish about 15% sooner. ([#1844](https://github.com/code-yeongyu/senpi/issues/1844))
|
|
61
|
+
|
|
62
|
+
- An open that waits behind other opens now says so. The shared host starts sessions one at a time, so several starting at once queue up — and when one waited past its deadline, the only message was a bare timeout with nothing after it. The host now tells each caller its place in the queue as soon as the request is accepted, so a slow start can be told apart from a broken one. ([#1844](https://github.com/code-yeongyu/senpi/issues/1844))
|
|
63
|
+
|
|
64
|
+
- Opening a session on a busy machine no longer fails instantly. The open deadline was fixed once when the request queue was built, so anything opened later inherited what was left of it — and after 30 seconds the next open was given a zero-length timer that expired immediately. Each open is now given its own deadline, measured from when it is sent. ([#1719](https://github.com/code-yeongyu/senpi/issues/1719))
|
|
65
|
+
|
|
66
|
+
### Removed
|
|
67
|
+
|
|
15
68
|
## [2026.9.19-2] - 2026-09-19
|
|
16
69
|
|
|
17
70
|
### Breaking Changes
|
package/dist/bundle/chunks/{app-server-command-QBJ4GPN7.js → app-server-command-B35FQUTE.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } }
|
|
2
|
-
import{import_websocket_server,wrapper_default}from"./chunk-2DQQ4XNS.js";import{AuthStorage,DefaultResourceLoader,GOAL_STORE_CHANGED_EVENT,ModelRegistry,clearGoal,createAgentSession,createGoal,createPendingQuestion,defaultModelPerProvider,formatProviderNativeBody,formatProviderNativeSummary,getMcpService,goalStoreRef,loadMcpConfig,loadSkills,readGoal,resolveAuthMode,updateGoal}from"./chunk-
|
|
2
|
+
import{import_websocket_server,wrapper_default}from"./chunk-2DQQ4XNS.js";import{AuthStorage,DefaultResourceLoader,GOAL_STORE_CHANGED_EVENT,ModelRegistry,clearGoal,createAgentSession,createGoal,createPendingQuestion,defaultModelPerProvider,formatProviderNativeBody,formatProviderNativeSummary,getMcpService,goalStoreRef,loadMcpConfig,loadSkills,readGoal,resolveAuthMode,updateGoal}from"./chunk-E5R67F7G.js";import{require_ignore}from"./chunk-YXQG2SUX.js";import"./chunk-EONVPHVX.js";import"./chunk-ZMFHNH6U.js";import{SessionManager,loadEntriesFromFile}from"./chunk-W4SRGDQ4.js";import"./chunk-GFUZPFHN.js";import{getCredentialAccounts,getModels,getProviders,getSupportedThinkingLevels,pinCredentialAccount,removeCredentialAccount,subscribeProviderAccountEvents}from"./chunk-TWGC3TBR.js";import{getAvailableThemesWithPaths,getThemeByName,takeOverStdout,theme,waitForRawStdoutBackpressure,writeRawStdout}from"./chunk-V2ZB62DG.js";import{x}from"./chunk-DQZB4GVV.js";import{SettingsManager}from"./chunk-Z4LHCTJ6.js";import"./chunk-QOBJEPJZ.js";import"./chunk-BMX2U22F.js";import"./chunk-IUZUN32Z.js";import{acquireOwnershipSafeLock}from"./chunk-P7PWCGLJ.js";import"./chunk-U6Z6OBX4.js";import{parseDaemonPidFile,processMatchesPidFile,readProcessStartTime,stopValidatedPid,waitForGone,waitForStartTime}from"./chunk-LF3XTYYF.js";import{attachJsonlLineReader}from"./chunk-HSH674C6.js";import"./chunk-BQVRDBW6.js";import"./chunk-H4QOEVS5.js";import"./chunk-HB35RBP4.js";import"./chunk-XK24AFYU.js";import"./chunk-MUC3MZTV.js";import"./chunk-2H3Y7EYQ.js";import"./chunk-FDLVINNY.js";import"./chunk-56TWFZ2C.js";import"./chunk-34GCWLNV.js";import"./chunk-7X72IACK.js";import"./chunk-3XHLKHSK.js";import"./chunk-X4Q5YSTE.js";import"./chunk-WVGCQOLJ.js";import"./chunk-IXAUDPOK.js";import"./chunk-EAMTSSEH.js";import"./chunk-RFB5CBW7.js";import"./chunk-OYXTZDVT.js";import"./chunk-V55B77HQ.js";import"./chunk-FC7R7NOV.js";import"./chunk-PRC5XIIH.js";import"./chunk-I3F6VZZF.js";import"./chunk-BPX6QWPD.js";import"./chunk-WDTJ6JKE.js";import"./chunk-DMI55M2N.js";import"./chunk-BQVVQ2LQ.js";import"./chunk-TVOODZJH.js";import"./chunk-I7YUNMWH.js";import"./chunk-2SOVDETB.js";import"./chunk-U7RQY7MH.js";import"./chunk-UAYBYTFN.js";import"./chunk-QPIXPR6I.js";import"./chunk-HGAX6JZ7.js";import"./chunk-26UBFF6N.js";import"./chunk-3P23SBT3.js";import{APP_NAME,CONFIG_DIR_NAME,ENV_SESSION_DIR,VERSION,getAgentDir,getSessionsDir,resolvePath}from"./chunk-H5RK2RYZ.js";import"./chunk-TDTKQR7C.js";import{__toESM}from"./chunk-VR4X5O2Z.js";import{isIP}from"node:net";var APP_SERVER_LISTEN_USAGE="Invalid --listen value. Use stdio://, unix://, unix:///abs/path, or ws://IP:PORT.";function formatAppServerUsage(){let listenForms="stdio://|unix://|unix:///abs/path|ws://IP:PORT";return[`Usage: ${APP_NAME} app-server [--listen <${listenForms}>] [--ws-auth <token-file|off>] [--json-logs]`,` ${APP_NAME} app-server daemon <start|stop|status|restart> [--listen <${listenForms}>]`].join(`
|
|
3
3
|
`)}function parseListen(value){if(value==="stdio://")return{kind:"stdio",url:"stdio://"};if(value==="unix://")return{kind:"unix",url:"unix://"};if(value.startsWith("unix:///")){let path=value.slice(7);return path.startsWith("/")?{kind:"unix",url:value,path}:void 0}if(!value.startsWith("ws://"))return;let parsed;try{parsed=new URL(value)}catch(error){if(error instanceof TypeError)return;throw error}let port=Number(parsed.port);if(!(parsed.protocol!=="ws:"||parsed.username!==""||parsed.password!==""||parsed.pathname!=="/"||parsed.search!==""||parsed.hash!==""||parsed.port===""||!Number.isInteger(port)||port<1||port>65535||isIP(parsed.hostname)===0))return{kind:"ws",url:value,host:parsed.hostname,port}}function parseDaemonVerb(value){switch(value){case"start":case"stop":case"status":case"restart":return value;default:return}}function parseWsAuth(value){return value==="off"?{kind:"off"}:{kind:"token-file",path:value}}function parseServerArgs(args){let listen3={kind:"stdio",url:"stdio://"},wsAuth,jsonLogs=!1;for(let index=0;index<args.length;index++){let arg=args[index];if(arg==="--listen"){let value=args[index+1];if(value===void 0)return{kind:"usage-error",message:APP_SERVER_LISTEN_USAGE};let parsed=parseListen(value);if(parsed===void 0)return{kind:"usage-error",message:APP_SERVER_LISTEN_USAGE};listen3=parsed,index++;continue}if(arg==="--ws-auth"){let value=args[index+1];if(value===void 0)return{kind:"usage-error",message:"--ws-auth requires <token-file|off>."};wsAuth=parseWsAuth(value),index++;continue}if(arg==="--json-logs"){jsonLogs=!0;continue}return{kind:"usage-error",message:`Unexpected app-server argument: ${arg}`}}return{kind:"server",listen:listen3,wsAuth,jsonLogs}}function parseDaemonArgs(args){let verb=parseDaemonVerb(args[0]);if(verb===void 0)return{kind:"usage-error",message:"Usage: app-server daemon <start|stop|status|restart>."};let listen3={kind:"ws",url:"ws://127.0.0.1:18800",host:"127.0.0.1",port:18800};for(let index=1;index<args.length;index++){let arg=args[index];if(arg==="--listen"){let value=args[index+1];if(value===void 0)return{kind:"usage-error",message:APP_SERVER_LISTEN_USAGE};let parsed=parseListen(value);if(parsed===void 0)return{kind:"usage-error",message:APP_SERVER_LISTEN_USAGE};listen3=parsed,index++;continue}return{kind:"usage-error",message:`Unexpected app-server daemon argument: ${arg}`}}return{kind:"daemon",verb,listen:listen3}}function parseAppServerCliArgs(args){return args[0]==="daemon"?parseDaemonArgs(args.slice(1)):parseServerArgs(args)}var RpcHandlerError=class extends Error{constructor(error){super(error.message),this.name="RpcHandlerError",this.rpcError=error}};function invalidRequestError(){return{code:-32600,message:"Invalid request"}}function methodNotFoundError(method){return{code:-32601,message:`Method not found: ${method}`}}function invalidParamsError(){return{code:-32602,message:"Invalid params"}}function internalError(message="Internal error"){return{code:-32603,message}}function notInitializedError(){return{code:-32600,message:"Not initialized"}}function alreadyInitializedError(){return{code:-32600,message:"Already initialized"}}function experimentalCapabilityError(method){return{code:-32600,message:`${method} requires experimentalApi capability`}}function registerExtensionRequestMethod(registry,getThread){registry.register("extension_request",{scope:"thread",handler:async({request})=>{let params=request.params;if(typeof params!="object"||params===null||Array.isArray(params))throw new RpcHandlerError({code:-32602,message:"Invalid params"});let threadId=Reflect.get(params,"threadId"),name=Reflect.get(params,"name");if(typeof threadId!="string"||threadId.length===0||typeof name!="string"||name.length===0)throw new RpcHandlerError({code:-32602,message:"Invalid params"});try{return await getThread(threadId).extensionRunner.requestRpc(name,Reflect.get(params,"data"))}catch(error){throw new RpcHandlerError(internalError(error instanceof Error?error.message:String(error)))}}})}function createRegistry(){return new InMemoryMethodRegistry}var InMemoryMethodRegistry=class{constructor(){this.methods=new Map}register(method,registration){this.methods.set(method,registration)}async dispatch(connection,request){if(!connection.initialized){let registration2=this.methods.get(request.method);if(request.method!=="initialize"||registration2?.requiresInit!==!1)return{id:request.id,error:notInitializedError()}}if(connection.initialized&&request.method==="initialize")return{id:request.id,error:alreadyInitializedError()};let registration=this.methods.get(request.method);if(!registration)return{id:request.id,error:methodNotFoundError(request.method)};if(registration.experimental===!0&&connection.capabilities?.experimentalApi!==!0)return{id:request.id,error:experimentalCapabilityError(request.method)};try{let result=await registration.handler({connection,request});return{id:request.id,result}}catch(error){return error instanceof RpcHandlerError?{id:request.id,error:error.rpcError}:{id:request.id,error:internalError(error instanceof Error?error.message:String(error))}}}};function registerFuzzyFileSearchMethods(registry,service){registry.register("fuzzyFileSearch",{scope:"global",handler:({request})=>service.search(parseOneShotParams(request.params))}),registry.register("fuzzyFileSearch/sessionStart",{experimental:!0,scope:"global",handler:({request})=>service.startSession(parseSessionStartParams(request.params))}),registry.register("fuzzyFileSearch/sessionUpdate",{experimental:!0,scope:"global",handler:({request})=>service.updateSession(parseSessionUpdateParams(request.params))}),registry.register("fuzzyFileSearch/sessionStop",{experimental:!0,scope:"global",handler:({request})=>service.stopSession(parseSessionStopParams(request.params))})}function parseOneShotParams(value){let params=objectParams(value,"fuzzyFileSearch");return{query:requiredString(params.query,"fuzzyFileSearch query"),roots:requiredStringArray(params.roots,"fuzzyFileSearch roots"),cancellationToken:optionalString(params.cancellationToken,"fuzzyFileSearch cancellationToken")}}function parseSessionStartParams(value){let params=objectParams(value,"fuzzyFileSearch/sessionStart");return{sessionId:requiredString(params.sessionId,"fuzzyFileSearch/sessionStart sessionId"),roots:requiredStringArray(params.roots,"fuzzyFileSearch/sessionStart roots")}}function parseSessionUpdateParams(value){let params=objectParams(value,"fuzzyFileSearch/sessionUpdate");return{sessionId:requiredString(params.sessionId,"fuzzyFileSearch/sessionUpdate sessionId"),query:requiredString(params.query,"fuzzyFileSearch/sessionUpdate query")}}function parseSessionStopParams(value){let params=objectParams(value,"fuzzyFileSearch/sessionStop");return{sessionId:requiredString(params.sessionId,"fuzzyFileSearch/sessionStop sessionId")}}function objectParams(value,method){if(!isRecord(value))throw invalidRequest(`${method} params must be an object`);return value}function requiredString(value,field){if(typeof value!="string")throw invalidRequest(`${field} must be a string`);return value}function requiredStringArray(value,field){if(!Array.isArray(value)||value.some(entry=>typeof entry!="string"))throw invalidRequest(`${field} must be an array of strings`);return value}function optionalString(value,field){if(value==null)return null;if(typeof value!="string")throw invalidRequest(`${field} must be a string or null`);return value}function invalidRequest(message){return new RpcHandlerError({code:-32600,message})}function isRecord(value){return typeof value=="object"&&value!==null&&!Array.isArray(value)}import{lstat,readdir}from"node:fs/promises";import{basename,join as join2,relative as relative2,resolve,sep as sep2}from"node:path";var import_ignore=__toESM(require_ignore(),1);import{readFile}from"node:fs/promises";import{join,relative,sep}from"node:path";async function addGitignoreScope(matchers,directory){let gitignore=await readableText(join(directory,".gitignore"));return gitignore===void 0?matchers:[...matchers,{directory,matcher:(0,import_ignore.default)().add(gitignore)}]}function isIgnored(matchers,path,isDirectory){let ignored=!1;for(let scope of matchers){let relativePath=relative(scope.directory,path).split(sep).join("/"),result=scope.matcher.test(isDirectory?`${relativePath}/`:relativePath);result.ignored&&(ignored=!0),result.unignored&&(ignored=!1)}return ignored}async function readableText(path){try{return await readFile(path,"utf8")}catch(error){if(error instanceof Error)return;throw error}}var FUZZY_SEARCH_MAX_DEPTH=12,FUZZY_SEARCH_MAX_VISITED_ENTRIES=5e4,FUZZY_SEARCH_RESULT_LIMIT=50,FILENAME_MATCH_BONUS=1e6,CHARACTER_MATCH_SCORE=10,CONTIGUOUS_MATCH_BONUS=20,BOUNDARY_MATCH_BONUS=5,CANCELLATION_YIELD_INTERVAL=256;async function collectFuzzyFileEntries(roots,options={}){let entries=[],state={visitedEntries:0,stopped:!1},maxDepth=options.maxDepth??FUZZY_SEARCH_MAX_DEPTH,maxVisitedEntries=options.maxVisitedEntries??FUZZY_SEARCH_MAX_VISITED_ENTRIES;for(let root of roots){if(options.signal?.aborted||state.stopped)break;let absoluteRoot=resolve(root),rootStat=await readableStat(absoluteRoot);!rootStat?.isDirectory()||rootStat.isSymbolicLink()||await walkDirectory({wireRoot:root,absoluteRoot,absoluteDirectory:absoluteRoot,depth:0,matchers:[],entries,state,signal:options.signal,maxDepth,maxVisitedEntries})}return entries}function rankFuzzyFileEntries(query,entries){if(query.length===0)return[];let results=[];for(let entry of entries){let filenameMatch=scoreSubsequence(entry.fileName,query),pathMatch=filenameMatch??scoreSubsequence(entry.path,query);if(!pathMatch)continue;let filenameOffset=Array.from(entry.path).length-Array.from(entry.fileName).length,indices=filenameMatch?filenameMatch.indices.map(index=>index+filenameOffset):pathMatch.indices;results.push({root:entry.root,path:entry.path,match_type:entry.matchType,file_name:entry.fileName,score:pathMatch.score+(filenameMatch?FILENAME_MATCH_BONUS:0),indices})}return results.sort(compareResults),results.slice(0,FUZZY_SEARCH_RESULT_LIMIT)}async function walkDirectory(input){let matchers=await addGitignoreScope(input.matchers,input.absoluteDirectory),directoryEntries=await readableDirectory(input.absoluteDirectory);directoryEntries.sort((left,right)=>compareText(left.name,right.name));for(let directoryEntry of directoryEntries){if(input.signal?.aborted||input.state.stopped)return;if(input.state.visitedEntries>=input.maxVisitedEntries){input.state.stopped=!0;return}if(input.state.visitedEntries+=1,directoryEntry.name===".git"||directoryEntry.name==="node_modules"||directoryEntry.isSymbolicLink())continue;let isDirectory=directoryEntry.isDirectory();if(!isDirectory&&!directoryEntry.isFile())continue;let absolutePath=join2(input.absoluteDirectory,directoryEntry.name),relativePath=toPosixPath(relative2(input.absoluteRoot,absolutePath));if(isIgnored(matchers,absolutePath,isDirectory))continue;input.entries.push({root:input.wireRoot,path:relativePath,matchType:isDirectory?"directory":"file",fileName:basename(relativePath)});let entryDepth=input.depth+1;isDirectory&&entryDepth<input.maxDepth&&await walkDirectory({...input,absoluteDirectory:absolutePath,depth:entryDepth,matchers}),input.state.visitedEntries%CANCELLATION_YIELD_INTERVAL===0&&await yieldToEventLoop()}}function scoreSubsequence(candidate,query){let normalizedCandidate=normalizeText(candidate),normalizedQuery=query.toLowerCase(),contiguousStart=normalizedCandidate.value.indexOf(normalizedQuery),normalizedIndices=[];if(contiguousStart>=0){let cursor=contiguousStart;for(let character of normalizedQuery)normalizedIndices.push(cursor),cursor+=character.length}else{let cursor=0;for(let character of normalizedQuery){let matchIndex=normalizedCandidate.value.indexOf(character,cursor);if(matchIndex<0)return;normalizedIndices.push(matchIndex),cursor=matchIndex+character.length}}let indices=[];for(let normalizedIndex of normalizedIndices){let sourceIndex=normalizedCandidate.sourceIndices[normalizedIndex];if(sourceIndex===void 0)return;indices.at(-1)!==sourceIndex&&indices.push(sourceIndex)}let candidateCharacters=Array.from(candidate),score=indices.length*CHARACTER_MATCH_SCORE;for(let index=0;index<indices.length;index++){let current=indices[index];if(current===void 0)continue;let previous=indices[index-1];previous!==void 0&¤t===previous+1&&(score+=CONTIGUOUS_MATCH_BONUS),(current===0||isBoundary(candidateCharacters[current-1]))&&(score+=BOUNDARY_MATCH_BONUS)}return{score,indices}}function normalizeText(value){let sourceIndices=[];for(let[sourceIndex,character]of Array.from(value).entries())for(let index=0;index<character.toLowerCase().length;index++)sourceIndices.push(sourceIndex);return{value:value.toLowerCase(),sourceIndices}}function compareResults(left,right){return left.score!==right.score?right.score-left.score:compareText(left.path,right.path)}function compareText(left,right){return left<right?-1:left>right?1:0}function isBoundary(character){return character==="/"||character==="-"||character==="_"||character==="."||character===" "}async function readableDirectory(path){try{return await readdir(path,{withFileTypes:!0})}catch(error){if(error instanceof Error)return[];throw error}}async function readableStat(path){try{return await lstat(path)}catch(error){if(error instanceof Error)return;throw error}}function toPosixPath(path){return path.split(sep2).join("/")}function yieldToEventLoop(){return new Promise(resolve4=>setImmediate(resolve4))}var FuzzyFileSearchService=class{constructor(options){this.activeSearches=new Set,this.pendingSearches=new Map,this.sessions=new Map,this.disposed=!1,this.broadcast=options.broadcast,this.collectEntries=options.collectEntries??((roots,signal)=>collectFuzzyFileEntries(roots,{signal})),this.rankEntries=options.rankEntries??rankFuzzyFileEntries}async search(params){if(this.disposed)return{files:[]};let controller=new AbortController;this.activeSearches.add(controller);let token=params.cancellationToken;token!==null&&(this.pendingSearches.get(token)?.abort(),this.pendingSearches.set(token,controller));try{if(params.query.length===0)return{files:[]};let entries=await this.collectEntries(params.roots,controller.signal);return controller.signal.aborted||this.disposed?{files:[]}:{files:this.rankEntries(params.query,entries)}}finally{this.activeSearches.delete(controller),token!==null&&this.pendingSearches.get(token)===controller&&this.pendingSearches.delete(token)}}startSession(params){if(params.sessionId.length===0)throw invalidRequest2("sessionId must not be empty");this.cancelSession(params.sessionId);let session={id:params.sessionId,roots:params.roots,controller:new AbortController,query:"",version:0,entries:void 0,active:!this.disposed,completedVersion:void 0};return this.sessions.set(session.id,session),this.runTraversal(session),{}}updateSession(params){let session=this.sessions.get(params.sessionId);if(!session?.active)throw invalidRequest2(`fuzzy file search session not found: ${params.sessionId}`);return session.query=params.query,session.version+=1,session.entries!==void 0&&this.emitVersion(session,session.version),{}}stopSession(params){return this.cancelSession(params.sessionId),{}}dispose(){if(!this.disposed){this.disposed=!0;for(let controller of this.activeSearches)controller.abort();this.activeSearches.clear(),this.pendingSearches.clear();for(let session of this.sessions.values())this.deactivate(session);this.sessions.clear()}}async runTraversal(session){let entries;try{entries=await this.collectEntries(session.roots,session.controller.signal)}catch(error){if(!(error instanceof Error))throw error;entries=[]}if(this.isLive(session))for(session.entries=entries;this.isLive(session);){let version=session.version;if(await this.emitVersion(session,version))break}}async emitVersion(session,version){if(await Promise.resolve(),!this.isLive(session)||session.version!==version||session.entries===void 0)return!1;if(session.completedVersion===version)return!0;let query=session.query,files=query.length===0?[]:this.rankEntries(query,session.entries);return!this.isLive(session)||session.version!==version||(this.broadcast({method:"fuzzyFileSearch/sessionUpdated",params:{sessionId:session.id,query,files}}),!this.isLive(session)||session.version!==version)?!1:(session.completedVersion=version,this.broadcast({method:"fuzzyFileSearch/sessionCompleted",params:{sessionId:session.id}}),!0)}cancelSession(sessionId){let session=this.sessions.get(sessionId);session&&(this.deactivate(session),this.sessions.get(sessionId)===session&&this.sessions.delete(sessionId))}deactivate(session){session.active=!1,session.controller.abort()}isLive(session){return!this.disposed&&session.active&&this.sessions.get(session.id)===session}};function invalidRequest2(message){return new RpcHandlerError({code:-32600,message})}var APPROVAL_DECISIONS=["accept","acceptForSession","decline","cancel"],PERMISSION_OPTIONS=["Allow once","Allow always","Deny","Deny with feedback"],CANCEL_REASON="approval request was cancelled because the turn ended",NO_SUBSCRIBER_REASON="no client connected to approve";var ApprovalBridge=class{constructor(sendToThreadSubscribers){this.nextServerRequestId=0,this.pending=new Map,this.sessionAllows=new Set,this.sendToThreadSubscribers=sendToThreadSubscribers}get pendingCount(){return this.pending.size}requestApproval(threadId,kind,payload){let allowKey=createAllowKey(threadId,kind,payload);if(allowKey&&this.sessionAllows.has(allowKey))return Promise.resolve({allow:!0,decision:"acceptForSession"});let requestId=this.nextServerRequestId;this.nextServerRequestId+=1;let request=buildApprovalRequest(threadId,requestId,kind,payload);return new Promise(resolve4=>{this.pending.set(requestId,{threadId,request,allowKey,resolve:resolve4}),!(this.sendToThreadSubscribers(threadId,request)>0)&&(this.pending.delete(requestId),resolve4({allow:!1,decision:"decline",reason:NO_SUBSCRIBER_REASON}))})}resolveResponse(response){let pending=this.pending.get(response.id);if(!pending)return!1;let decision=readDecision(response);return this.pending.delete(response.id),decision==="acceptForSession"&&pending.allowKey&&this.sessionAllows.add(pending.allowKey),this.emitResolved(pending.threadId,response.id),pending.resolve(decisionToOutcome(decision,readReason(response))),!0}replayPendingForThread(threadId){let replayed=0;for(let pending of this.pending.values())pending.threadId===threadId&&(this.sendToThreadSubscribers(threadId,pending.request),replayed+=1);return replayed}cancelPendingForThread(threadId){let cancelled=0;for(let[requestId,pending]of Array.from(this.pending.entries()))pending.threadId===threadId&&(this.pending.delete(requestId),this.emitResolved(threadId,requestId),pending.resolve({allow:!1,decision:"cancel",reason:CANCEL_REASON}),cancelled+=1);return cancelled}emitResolved(threadId,requestId){this.sendToThreadSubscribers(threadId,{method:"serverRequest/resolved",params:{threadId,requestId}})}};function buildApprovalRequest(threadId,requestId,kind,payload){let base={threadId,turnId:payload.turnId??"turn-approval",itemId:payload.itemId??(kind==="commandExecution"?"approval-command":"approval-file-change"),startedAtMs:Date.now()};return kind==="fileChange"?{id:requestId,method:"item/fileChange/requestApproval",params:{...base,reason:payload.reason??null,grantRoot:payload.grantRoot??null}}:{id:requestId,method:"item/commandExecution/requestApproval",params:{...base,approvalId:payload.approvalId??null,environmentId:payload.environmentId??null,reason:payload.reason??null,command:payload.command??null,cwd:payload.cwd??null,availableDecisions:[...APPROVAL_DECISIONS]}}}function decisionToOutcome(decision,reason){return decision==="accept"||decision==="acceptForSession"?{allow:!0,decision}:reason?{allow:!1,decision,reason}:{allow:!1,decision}}function readDecision(response){let decision=isRecord2(response.result)?response.result.decision:void 0;return isApprovalDecision(decision)?decision:"cancel"}function readReason(response){let resultReason=isRecord2(response.result)?response.result.reason??response.result.message:void 0,errorReason=isRecord2(response.error)?response.error.message:void 0,reason=typeof resultReason=="string"?resultReason:errorReason;return typeof reason=="string"&&reason.length>0?reason:void 0}function createAllowKey(threadId,kind,payload){if(!(!payload.toolName||typeof payload.command!="string"))return`${threadId}\0${kind}\0${payload.toolName}\0${payload.command}`}function isApprovalDecision(value){return value==="accept"||value==="acceptForSession"||value==="decline"||value==="cancel"}function isRecord2(value){return typeof value=="object"&&value!==null&&!Array.isArray(value)}function createAppServerUIContext(bridge,threadId,userInput,getTurnId=()=>"turn-user-input"){let pendingInput,editorText="",editorFactory,toolsExpanded=!1;return{question(request,opts){return userInput?.requestUserInput(threadId,getTurnId(),request.requestId,request,opts)??Promise.resolve({status:"unavailable",answers:{},unanswered:request.questions.map(question=>question.id)})},async select(title,options){let prompt=parsePermissionPrompt(title);if(!prompt||!isPermissionOptions(options))return;let outcome=await bridge.requestApproval(threadId,prompt.kind,{turnId:"turn-approval",itemId:`approval-${prompt.toolName}`,toolName:prompt.toolName,command:prompt.command,reason:prompt.reason});return outcome.decision==="accept"?"Allow once":outcome.decision==="acceptForSession"?"Allow always":outcome.reason&&outcome.reason!==NO_SUBSCRIBER_REASON&&outcome.reason!==CANCEL_REASON?(pendingInput=outcome.reason,"Deny with feedback"):"Deny"},async confirm(title,message){return(await bridge.requestApproval(threadId,"commandExecution",{turnId:"turn-approval",itemId:"approval-confirm",toolName:"confirm",command:title,reason:message})).allow},async input(){let value=pendingInput;return pendingInput=void 0,value},notify(){},onTerminalInput(){return()=>{}},setStatus(){},setWorkingMessage(){},setWorkingVisible(){},setWorkingIndicator(){},setHiddenThinkingLabel(){},setWidget(){},setFooter(){},setHeader(){},setTitle(){},custom(){return Promise.reject(new Error("Custom UI is not available in app-server mode."))},pasteToEditor(text){editorText=text},setEditorText(text){editorText=text},getEditorText(){return editorText},async editor(_title,prefill){return prefill},addAutocompleteProvider(){},setEditorComponent(factory){editorFactory=factory},getEditorComponent(){return editorFactory},theme,getAllThemes:getAvailableThemesWithPaths,getTheme(name){return getThemeByName(name)},setTheme(_nextTheme){return{success:!1,error:"Theme switching is not available in app-server mode."}},getToolsExpanded(){return toolsExpanded},setToolsExpanded(expanded){toolsExpanded=expanded}}}function parsePermissionPrompt(title){let[firstLine="",...rest]=title.split(`
|
|
4
4
|
`),prefix="Permission required: ";if(!firstLine.startsWith(prefix))return;let toolName=firstLine.slice(prefix.length).trim(),reason=rest.join(`
|
|
5
5
|
`).trim();return{kind:permissionKind(toolName),toolName,command:readLineValue(reason,"Command: $ ")??readLineValue(reason,"File: ")??readLineValue(reason,"Path: ")??null,reason}}function permissionKind(toolName){return toolName==="edit"||toolName==="write"||toolName==="apply_patch"||toolName==="multiedit"?"fileChange":"commandExecution"}function readLineValue(text,prefix){return text.split(`
|
package/dist/bundle/chunks/{bun-extension-importer-JQZRPNJH.js → bun-extension-importer-HHH4TV4B.js}
RENAMED
|
@@ -2,9 +2,9 @@ import { createRequire as __piCreateRequire } from "node:module"; const require
|
|
|
2
2
|
import{external_exports}from"./chunk-3XHLKHSK.js";import"./chunk-VR4X5O2Z.js";import{readFileSync as readFileSync2,realpathSync}from"node:fs";import{createRequire,isBuiltin}from"node:module";import{dirname as dirname2,extname as extname2,resolve}from"node:path";import{fileURLToPath as fileURLToPath2}from"node:url";var e,a,r,i=1048576,s=new Uint8Array(new Uint16Array([1]).buffer)[0]===1?function(e2,a2){let r2=e2.length,i2=0;for(;i2<r2;)a2[i2]=e2.charCodeAt(i2++)}:function(e2,a2){let r2=e2.length,i2=0;for(;i2<r2;){let r3=e2.charCodeAt(i2);a2[i2++]=(255&r3)<<8|r3>>>8}},f="xportmportlassforetaourceeferromsyncunctionvoyiedelecontininstantybreareturdebuggeawaithrwhileifcatcfinallels",t,c,n;function parse(k2,u2="@"){t=k2,c=u2;let l2=2*t.length+(2<<18);if(l2>i||!e){for(;l2>i;)i*=2;a=new ArrayBuffer(i),s(f,new Uint16Array(a,16,109)),e=(function(e2,a2,r2){var i2=new e2.Int8Array(r2),s2=new e2.Int16Array(r2),f2=new e2.Int32Array(r2),t2=new e2.Uint8Array(r2),c2=new e2.Uint16Array(r2),n2=1040;function b2(){var e3=0,a3=0,r3=0,t3=0,c3=0,b3=0,l4=0,d3=0,C2=0,g2=0;g2=n2,n2=n2+10240|0,i2[808]=1,i2[807]=0,s2[401]=0,s2[402]=0,f2[70]=f2[2],i2[809]=0,f2[68]=0,i2[806]=0,f2[71]=g2+2048,f2[72]=g2,i2[810]=0,e3=(f2[3]|0)+-2|0,f2[73]=e3,a3=e3+(f2[66]<<1)|0,f2[74]=a3;e:for(;;){if(r3=e3+2|0,f2[73]=r3,e3>>>0>=a3>>>0){t3=18;break}a:do switch(s2[r3>>1]|0){case 9:case 10:case 11:case 12:case 13:case 32:break;case 101:{if((s2[402]|0)==0&&J(r3)|0&&(I(e3+4|0,16,10)|0)==0&&(k3(),(i2[808]|0)==0)){t3=9;break e}else t3=17;break}case 105:{J(r3)|0&&(I(e3+4|0,26,10)|0)==0&&u3(),t3=17;break}case 59:{t3=17;break}case 47:switch(s2[e3+4>>1]|0){case 47:{P();break a}case 42:{m(1);break a}default:{t3=16;break e}}default:{t3=16;break e}}while(!1);(t3|0)==17&&(t3=0,f2[70]=f2[73]),e3=f2[73]|0,a3=f2[74]|0}(t3|0)==9?(e3=f2[73]|0,f2[70]=e3,t3=19):(t3|0)==16?(i2[808]=0,f2[73]=e3,t3=19):(t3|0)==18&&(i2[806]|0?e3=0:(e3=r3,t3=19));do if((t3|0)==19){e:for(;;){if(a3=e3+2|0,f2[73]=a3,e3>>>0>=(f2[74]|0)>>>0){t3=102;break}a:do switch(s2[a3>>1]|0){case 9:case 10:case 11:case 12:case 13:case 32:break;case 101:{(s2[402]|0)==0&&J(a3)|0&&(I(e3+4|0,16,10)|0)==0&&k3(),t3=101;break}case 105:{J(a3)|0&&(I(e3+4|0,26,10)|0)==0&&u3(),t3=101;break}case 99:{J(a3)|0&&(I(e3+4|0,36,8)|0)==0&&X(s2[e3+12>>1]|0)|0&&(i2[810]=1),t3=101;break}case 40:{r3=f2[71]|0,e3=s2[402]|0,t3=e3&65535,f2[r3+(t3<<3)>>2]=1,a3=f2[70]|0,s2[402]=e3+1<<16>>16,f2[r3+(t3<<3)+4>>2]=a3,t3=101;break}case 91:{r3=f2[71]|0,e3=s2[402]|0,t3=e3&65535,f2[r3+(t3<<3)>>2]=8,a3=f2[70]|0,s2[402]=e3+1<<16>>16,f2[r3+(t3<<3)+4>>2]=a3,t3=101;break}case 93:{if(e3=s2[402]|0,!(e3<<16>>16)){t3=37;break e}s2[402]=e3+-1<<16>>16,t3=101;break}case 44:{t3=s2[401]|0,a3=t3&65535,t3<<16>>16!=0&&(c3=s2[402]|0,c3<<16>>16!=0)&&(f2[(f2[71]|0)+((c3&65535)+-1<<3)>>2]|0)==5&&(b3=f2[(f2[72]|0)+(a3+-1<<2)>>2]|0,d3=b3+4|0,(f2[d3>>2]|0)==0)&&(f2[d3>>2]=(f2[70]|0)+2,f2[73]=e3+4,w2(1)|0,t3=f2[73]|0,f2[b3+16>>2]=t3,f2[73]=t3+-2),t3=101;break}case 41:{if(a3=s2[402]|0,!(a3<<16>>16)){t3=45;break e}r3=a3+-1<<16>>16,s2[402]=r3,t3=s2[401]|0,a3=t3&65535,t3<<16>>16!=0&&(f2[(f2[71]|0)+((r3&65535)<<3)>>2]|0)==5&&(a3=f2[(f2[72]|0)+(a3+-1<<2)>>2]|0,r3=a3+4|0,f2[r3>>2]|0||(f2[r3>>2]=(f2[70]|0)+2),f2[a3+12>>2]=e3+4,s2[401]=t3+-1<<16>>16),t3=101;break}case 123:{t3=f2[70]|0,r3=f2[63]|0,e3=t3;do if((s2[t3>>1]|0)==41&(r3|0)!=0&&(f2[r3+4>>2]|0)==(t3|0))if(a3=f2[64]|0,f2[63]=a3,a3){f2[a3+36>>2]=0;break}else{f2[59]=0;break}while(!1);r3=f2[71]|0,a3=s2[402]|0,t3=a3&65535,f2[r3+(t3<<3)>>2]=(i2[810]|0)==0?2:6,s2[402]=a3+1<<16>>16,f2[r3+(t3<<3)+4>>2]=e3,i2[810]=0,t3=101;break}case 125:{if(e3=s2[402]|0,!(e3<<16>>16)){t3=58;break e}r3=f2[71]|0,t3=e3+-1<<16>>16,s2[402]=t3,(f2[r3+((t3&65535)<<3)>>2]|0)==4&&h2(),t3=101;break}case 39:{v2(39),t3=101;break}case 34:{v2(34),t3=101;break}case 47:switch(s2[e3+4>>1]|0){case 47:{P();break a}case 42:{m(1);break a}default:{e3=f2[70]|0,a3=s2[e3>>1]|0;r:do if(!(x(a3)|0))a3<<16>>16==41?(r3=s2[402]|0,D(f2[(f2[71]|0)+((r3&65535)<<3)+4>>2]|0)|0||(t3=74)):t3=73;else switch(a3<<16>>16){case 46:if(((s2[e3+-2>>1]|0)+-48&65535)<10){t3=73;break r}else break r;case 43:if((s2[e3+-2>>1]|0)==43){t3=73;break r}else break r;case 45:if((s2[e3+-2>>1]|0)==45){t3=73;break r}else break r;default:break r}while(!1);(t3|0)==73&&(r3=s2[402]|0,t3=74);r:do if((t3|0)==74){if(t3=0,r3<<16>>16!=0&&(l4=f2[71]|0,C2=(r3&65535)+-1|0,a3<<16>>16==102?(f2[l4+(C2<<3)>>2]|0)==1:0)){if((s2[e3+-2>>1]|0)==111&&A(e3+-4|0)|0&&T(f2[l4+(C2<<3)+4>>2]|0,44,3)|0)break}else t3=79;if((t3|0)==79&&a3<<16>>16==125&&(t3=f2[71]|0,r3=r3&65535,y(f2[t3+(r3<<3)+4>>2]|0)|0||(f2[t3+(r3<<3)>>2]|0)==6))break;if(!(o2(e3)|0)){switch(a3<<16>>16){case 0:break r;case 47:{if(i2[809]|0)break r;break}default:}if(t3=f2[65]|0,t3|0&&e3>>>0>=(f2[t3>>2]|0)>>>0&&e3>>>0<=(f2[t3+4>>2]|0)>>>0){p(),i2[809]=0,t3=101;break a}r3=f2[3]|0;do{if(e3>>>0<=r3>>>0)break;e3=e3+-2|0,f2[70]=e3,a3=s2[e3>>1]|0}while(!(E(a3)|0));if(F(a3)|0){do{if(e3>>>0<=r3>>>0)break;e3=e3+-2|0,f2[70]=e3}while(F(s2[e3>>1]|0)|0);if(j(e3)|0){p(),i2[809]=0,t3=101;break a}}i2[809]=1,t3=101;break a}}while(!1);p(),i2[809]=0,t3=101;break a}}case 96:{r3=f2[71]|0,a3=s2[402]|0,t3=a3&65535,f2[r3+(t3<<3)+4>>2]=f2[70],s2[402]=a3+1<<16>>16,f2[r3+(t3<<3)>>2]=3,h2(),t3=101;break}default:t3=101}while(!1);(t3|0)==101&&(t3=0,f2[70]=f2[73]),e3=f2[73]|0}if((t3|0)==37){W(),e3=0;break}else if((t3|0)==45){W(),e3=0;break}else if((t3|0)==58){W(),e3=0;break}else if((t3|0)==102){e3=(i2[806]|0)==0?(s2[401]|s2[402])<<16>>16==0:0;break}}while(!1);return n2=g2,e3|0}function k3(){var e3=0,a3=0,r3=0,t3=0,c3=0,n3=0,b3=0,k4=0,u4=0,o3=0,h3=0,d3=0,A2=0,g2=0;k4=f2[73]|0,u4=f2[65]|0,g2=k4+12|0,f2[73]=g2,r3=w2(1)|0,e3=f2[73]|0,(e3|0)==(g2|0)&&!(U(r3)|0)||(A2=3);e:do if((A2|0)==3){a:do switch(r3<<16>>16){case 123:{for(f2[73]=e3+2,e3=w2(1)|0,a3=f2[73]|0;;){if(Y(e3)|0?(v2(e3),e3=(f2[73]|0)+2|0,f2[73]=e3):(q(e3)|0,e3=f2[73]|0),w2(1)|0,e3=C(a3,e3)|0,e3<<16>>16==44&&(f2[73]=(f2[73]|0)+2,e3=w2(1)|0),e3<<16>>16==125){A2=15;break}if(g2=a3,a3=f2[73]|0,(a3|0)==(g2|0)){A2=12;break}if(a3>>>0>(f2[74]|0)>>>0){A2=14;break}}if((A2|0)==12){W();break e}else if((A2|0)==14){W();break e}else if((A2|0)==15){i2[807]=1,f2[73]=(f2[73]|0)+2;break a}break}case 42:{f2[73]=e3+2,w2(1)|0,g2=f2[73]|0,C(g2,g2)|0;break}default:{switch(i2[808]=0,r3<<16>>16){case 100:{switch(k4=e3+14|0,f2[73]=k4,(w2(1)|0)<<16>>16){case 97:{a3=f2[73]|0,(I(a3+2|0,80,8)|0)==0&&(c3=a3+10|0,F(s2[c3>>1]|0)|0)&&(f2[73]=c3,w2(0)|0,A2=22);break}case 102:{A2=22;break}case 99:{a3=f2[73]|0,(I(a3+2|0,36,8)|0)==0&&(t3=a3+10|0,g2=s2[t3>>1]|0,X(g2)|0|g2<<16>>16==123)&&(f2[73]=t3,n3=w2(1)|0,n3<<16>>16!=123)&&(d3=n3,A2=31);break}default:}r:do if((A2|0)==22&&(b3=f2[73]|0,(I(b3+2|0,88,14)|0)==0)){if(r3=b3+16|0,a3=s2[r3>>1]|0,!(X(a3)|0))switch(a3<<16>>16){case 40:case 42:break;default:break r}f2[73]=r3,a3=w2(1)|0,a3<<16>>16==42&&(f2[73]=(f2[73]|0)+2,a3=w2(1)|0),a3<<16>>16!=40&&(d3=a3,A2=31)}while(!1);if((A2|0)==31&&(o3=f2[73]|0,q(d3)|0,h3=f2[73]|0,h3>>>0>o3>>>0)){$(e3,k4,o3,h3),f2[73]=(f2[73]|0)+-2;break e}$(e3,k4,0,0),f2[73]=e3+12;break e}case 97:{f2[73]=e3+10,w2(0)|0,e3=f2[73]|0,A2=35;break}case 102:{A2=35;break}case 99:{if((I(e3+2|0,36,8)|0)==0&&(a3=e3+10|0,E(s2[a3>>1]|0)|0)){f2[73]=a3,g2=w2(1)|0,A2=f2[73]|0,q(g2)|0,g2=f2[73]|0,$(A2,g2,A2,g2),f2[73]=(f2[73]|0)+-2;break e}e3=e3+4|0,f2[73]=e3;break}case 108:case 118:break;default:break e}if((A2|0)==35){f2[73]=e3+16,e3=w2(1)|0,e3<<16>>16==42&&(f2[73]=(f2[73]|0)+2,e3=w2(1)|0),A2=f2[73]|0,q(e3)|0,g2=f2[73]|0,$(A2,g2,A2,g2),f2[73]=(f2[73]|0)+-2;break e}f2[73]=e3+6,i2[808]=0,r3=w2(1)|0,e3=f2[73]|0,r3=(q(r3)|0|32)<<16>>16==123,t3=f2[73]|0,r3&&(f2[73]=t3+2,g2=w2(1)|0,e3=f2[73]|0,q(g2)|0);r:for(;a3=f2[73]|0,(a3|0)!=(e3|0);){if($(e3,a3,e3,a3),a3=w2(1)|0,r3)switch(a3<<16>>16){case 93:case 125:break e;default:}if(e3=f2[73]|0,a3<<16>>16!=44){A2=51;break}switch(f2[73]=e3+2,a3=w2(1)|0,e3=f2[73]|0,a3<<16>>16){case 91:case 123:{A2=51;break r}default:}q(a3)|0}if((A2|0)==51&&(f2[73]=e3+-2),!r3)break e;f2[73]=t3+-2;break e}}while(!1);if(g2=(w2(1)|0)<<16>>16==102,e3=f2[73]|0,g2&&(I(e3+2|0,74,6)|0)==0)for(f2[73]=e3+8,l3(k4,w2(1)|0,0),e3=(u4|0)==0?240:u4+16|0;;){if(e3=f2[e3>>2]|0,!e3)break e;f2[e3+12>>2]=0,f2[e3+8>>2]=0,e3=e3+16|0}f2[73]=e3+-2}while(!1)}function u3(){var e3=0,a3=0,r3=0,t3=0,c3=0,n3=0,b3=0;b3=f2[73]|0,c3=b3+12|0,f2[73]=c3,e3=w2(1)|0,t3=f2[73]|0;e:do if(e3<<16>>16!=46){if(!(e3<<16>>16==115&t3>>>0>c3>>>0)){if(!(e3<<16>>16==100&t3>>>0>(b3+10|0)>>>0)){t3=0,n3=28;break}if(I(t3+2|0,66,8)|0){a3=t3,e3=100,t3=0,n3=59;break}if(e3=t3+10|0,!(X(s2[e3>>1]|0)|0)){a3=t3,e3=100,t3=0,n3=59;break}if(f2[73]=e3,e3=w2(1)|0,e3<<16>>16==42){e3=42,t3=2,n3=61;break}f2[73]=t3,t3=0,n3=28;break}if((I(t3+2|0,56,10)|0)==0&&(r3=t3+12|0,X(s2[r3>>1]|0)|0)){if(f2[73]=r3,e3=w2(1)|0,a3=f2[73]|0,(a3|0)!=(r3|0)){if(e3<<16>>16!=102){t3=1,n3=28;break}if(I(a3+2|0,74,6)|0){e3=102,t3=1,n3=59;break}if(!(E(s2[a3+8>>1]|0)|0)){e3=102,t3=1,n3=59;break}}f2[73]=t3,t3=0,n3=28}else a3=t3,e3=115,t3=0,n3=59}else switch(f2[73]=t3+2,(w2(1)|0)<<16>>16){case 109:{if(e3=f2[73]|0,I(e3+2|0,50,6)|0||(a3=f2[70]|0,!(G(a3)|0)&&(s2[a3>>1]|0)==46))break e;d2(b3,b3,e3+8|0,2);break e}case 115:{if(e3=f2[73]|0,I(e3+2|0,56,10)|0||(a3=f2[70]|0,!(G(a3)|0)&&(s2[a3>>1]|0)==46))break e;f2[73]=e3+12,e3=w2(1)|0,t3=1,n3=28;break e}case 100:{if(e3=f2[73]|0,I(e3+2|0,66,8)|0||(a3=f2[70]|0,!(G(a3)|0)&&(s2[a3>>1]|0)==46))break e;f2[73]=e3+10,e3=w2(1)|0,t3=2,n3=28;break e}default:break e}while(!1);e:do if((n3|0)==28){if(e3<<16>>16==40){if(r3=f2[71]|0,a3=s2[402]|0,c3=a3&65535,f2[r3+(c3<<3)>>2]=5,e3=f2[73]|0,s2[402]=a3+1<<16>>16,f2[r3+(c3<<3)+4>>2]=e3,(s2[f2[70]>>1]|0)==46)break;switch(f2[73]=e3+2,a3=w2(1)|0,d2(b3,f2[73]|0,0,e3),t3?(e3=f2[63]|0,f2[e3+28>>2]=(t3|0)==1?5:7):e3=f2[63]|0,c3=f2[72]|0,b3=s2[401]|0,s2[401]=b3+1<<16>>16,f2[c3+((b3&65535)<<2)>>2]=e3,a3<<16>>16){case 39:{v2(39);break}case 34:{v2(34);break}default:{f2[73]=(f2[73]|0)+-2;break e}}switch(e3=(f2[73]|0)+2|0,f2[73]=e3,(w2(1)|0)<<16>>16){case 44:{f2[73]=(f2[73]|0)+2,w2(1)|0,c3=f2[63]|0,f2[c3+4>>2]=e3,b3=f2[73]|0,f2[c3+16>>2]=b3,i2[c3+24>>0]=1,f2[73]=b3+-2;break e}case 41:{s2[402]=(s2[402]|0)+-1<<16>>16,b3=f2[63]|0,f2[b3+4>>2]=e3,f2[b3+12>>2]=(f2[73]|0)+2,i2[b3+24>>0]=1,s2[401]=(s2[401]|0)+-1<<16>>16;break e}default:{f2[73]=(f2[73]|0)+-2;break e}}}if(!((t3|0)==0&e3<<16>>16==123)){switch(e3<<16>>16){case 42:case 39:case 34:{n3=61;break e}default:}a3=f2[73]|0,n3=59;break}if(e3=f2[73]|0,s2[402]|0){f2[73]=e3+-2;break}for(;!(e3>>>0>=(f2[74]|0)>>>0);){if(e3=w2(1)|0,Y(e3)|0)v2(e3);else if(e3<<16>>16==125){n3=49;break}e3=(f2[73]|0)+2|0,f2[73]=e3}if((n3|0)==49&&(f2[73]=(f2[73]|0)+2),c3=(w2(1)|0)<<16>>16==102,e3=f2[73]|0,c3&&I(e3+2|0,74,6)|0){W();break}if(f2[73]=e3+8,e3=w2(1)|0,Y(e3)|0){l3(b3,e3,0);break}else{W();break}}while(!1);(n3|0)==59&&((a3|0)==(c3|0)?f2[73]=b3+10:n3=61);do if((n3|0)==61){if(!((e3<<16>>16==42|(t3|0)!=2)&(s2[402]|0)==0)){f2[73]=(f2[73]|0)+-2;break}for(e3=f2[74]|0,a3=f2[73]|0;;){if(a3>>>0>=e3>>>0){n3=68;break}if(r3=s2[a3>>1]|0,Y(r3)|0){n3=66;break}n3=a3+2|0,f2[73]=n3,a3=n3}if((n3|0)==66){l3(b3,r3,t3);break}else if((n3|0)==68){W();break}}while(!1)}function l3(e3,a3,r3){e3=e3|0,a3=a3|0,r3=r3|0;var i3=0,t3=0,c3=0,n3=0,b3=0;switch(i3=(f2[73]|0)+2|0,a3<<16>>16){case 39:{v2(39),t3=5;break}case 34:{v2(34),t3=5;break}default:W()}do if((t3|0)==5){if(d2(e3,i3,f2[73]|0,1),(r3|0)>0&&(f2[(f2[63]|0)+28>>2]=(r3|0)==1?4:6),f2[73]=(f2[73]|0)+2,n3=(w2(0)|0)<<16>>16==119,c3=f2[73]|0,n3&&(s2[c3+2>>1]|0)==105&&(s2[c3+4>>1]|0)==116&&(s2[c3+6>>1]|0)==104){if(f2[73]=c3+8,(w2(1)|0)<<16>>16!=123){f2[73]=c3;break}n3=f2[73]|0,i3=n3,t3=0;e:for(;;){f2[73]=i3+2,i3=w2(1)|0;do if(i3<<16>>16!=39)if(a3=f2[73]|0,i3<<16>>16==34){v2(34),e3=(f2[73]|0)+2|0,f2[73]=e3,i3=w2(1)|0;break}else{i3=q(i3)|0,e3=f2[73]|0;break}else a3=f2[73]|0,v2(39),e3=(f2[73]|0)+2|0,f2[73]=e3,i3=w2(1)|0;while(!1);if(i3<<16>>16!=58){t3=21;break}switch(f2[73]=(f2[73]|0)+2,(w2(1)|0)<<16>>16){case 39:{i3=f2[73]|0,v2(39);break}case 34:{i3=f2[73]|0,v2(34);break}default:{t3=25;break e}}switch(b3=(f2[73]|0)+2|0,r3=f2[67]|0,f2[67]=r3+20,f2[r3>>2]=a3,f2[r3+4>>2]=e3,f2[r3+8>>2]=i3,f2[r3+12>>2]=b3,f2[r3+16>>2]=0,f2[((t3|0)==0?(f2[63]|0)+32|0:t3+16|0)>>2]=r3,f2[73]=(f2[73]|0)+2,(w2(1)|0)<<16>>16){case 125:{t3=29;break e}case 44:break;default:{t3=27;break e}}i3=(f2[73]|0)+2|0,f2[73]=i3,t3=r3}if((t3|0)==21){f2[73]=c3;break}else if((t3|0)==25){f2[73]=c3;break}else if((t3|0)==27){f2[73]=c3;break}else if((t3|0)==29){b3=f2[63]|0,f2[b3+16>>2]=n3,f2[b3+12>>2]=(f2[73]|0)+2;break}}f2[73]=c3+-2}while(!1)}function o2(e3){e3=e3|0;e:do switch(s2[e3>>1]|0){case 100:switch(s2[e3+-2>>1]|0){case 105:{e3=T(e3+-4|0,102,2)|0;break e}case 108:{e3=T(e3+-4|0,106,3)|0;break e}default:{e3=0;break e}}case 101:switch(s2[e3+-2>>1]|0){case 115:switch(s2[e3+-4>>1]|0){case 108:{e3=B(e3+-6|0,101)|0;break e}case 97:{e3=B(e3+-6|0,99)|0;break e}default:{e3=0;break e}}case 116:{e3=T(e3+-4|0,112,4)|0;break e}case 117:{e3=T(e3+-4|0,120,6)|0;break e}default:{e3=0;break e}}case 102:{if((s2[e3+-2>>1]|0)==111&&(s2[e3+-4>>1]|0)==101)switch(s2[e3+-6>>1]|0){case 99:{e3=T(e3+-8|0,132,6)|0;break e}case 112:{e3=T(e3+-8|0,144,2)|0;break e}default:{e3=0;break e}}else e3=0;break}case 107:{e3=T(e3+-2|0,148,4)|0;break}case 110:{e3=e3+-2|0,B(e3,105)|0?e3=1:e3=T(e3,156,5)|0;break}case 111:{e3=B(e3+-2|0,100)|0;break}case 114:{e3=T(e3+-2|0,166,7)|0;break}case 116:{e3=T(e3+-2|0,180,4)|0;break}case 119:switch(s2[e3+-2>>1]|0){case 101:{e3=B(e3+-4|0,110)|0;break e}case 111:{e3=T(e3+-4|0,188,3)|0;break e}default:{e3=0;break e}}default:e3=0}while(!1);return e3|0}function h2(){var e3=0,a3=0,r3=0,i3=0;a3=f2[74]|0,r3=f2[73]|0;e:for(;;){if(e3=r3+2|0,r3>>>0>=a3>>>0){a3=10;break}switch(s2[e3>>1]|0){case 96:{a3=7;break e}case 36:{if((s2[r3+4>>1]|0)==123){a3=6;break e}break}case 92:{e3=r3+4|0;break}default:}r3=e3}(a3|0)==6?(e3=r3+4|0,f2[73]=e3,a3=f2[71]|0,i3=s2[402]|0,r3=i3&65535,f2[a3+(r3<<3)>>2]=4,s2[402]=i3+1<<16>>16,f2[a3+(r3<<3)+4>>2]=e3):(a3|0)==7?(f2[73]=e3,r3=f2[71]|0,i3=(s2[402]|0)+-1<<16>>16,s2[402]=i3,(f2[r3+((i3&65535)<<3)>>2]|0)!=3&&W()):(a3|0)==10&&(f2[73]=e3,W())}function w2(e3){e3=e3|0;var a3=0,r3=0,i3=0;r3=f2[73]|0;e:do{a3=s2[r3>>1]|0;a:do if(a3<<16>>16!=47)if(e3){if(X(a3)|0)break;break e}else{if(F(a3)|0)break;break e}else switch(s2[r3+2>>1]|0){case 47:{P();break a}case 42:{m(e3);break a}default:{a3=47;break e}}while(!1);i3=f2[73]|0,r3=i3+2|0,f2[73]=r3}while(i3>>>0<(f2[74]|0)>>>0);return a3|0}function d2(e3,a3,r3,s3){e3=e3|0,a3=a3|0,r3=r3|0,s3=s3|0;var t3=0,c3=0;c3=f2[67]|0,f2[67]=c3+40,t3=f2[63]|0,f2[((t3|0)==0?236:t3+36|0)>>2]=c3,f2[64]=t3,f2[63]=c3,f2[c3+8>>2]=e3,(s3|0)==2?(e3=3,t3=r3):(t3=(s3|0)==1,e3=t3?1:2,t3=t3?r3+2|0:0),f2[c3+12>>2]=t3,f2[c3+28>>2]=e3,f2[c3>>2]=a3,f2[c3+4>>2]=r3,f2[c3+16>>2]=0,f2[c3+20>>2]=s3,a3=(s3|0)==1,i2[c3+24>>0]=a3&1,f2[c3+32>>2]=0,f2[c3+36>>2]=0,a3|(s3|0)==2&&(i2[807]=1)}function v2(e3){e3=e3|0;var a3=0,r3=0,i3=0,t3=0;for(t3=f2[74]|0,a3=f2[73]|0;;){if(i3=a3+2|0,a3>>>0>=t3>>>0){a3=9;break}if(r3=s2[i3>>1]|0,r3<<16>>16==e3<<16>>16){a3=10;break}if(r3<<16>>16==92)r3=a3+4|0,(s2[r3>>1]|0)==13?(a3=a3+6|0,a3=(s2[a3>>1]|0)==10?a3:r3):a3=r3;else if(ie(r3)|0){a3=9;break}else a3=i3}(a3|0)==9?(f2[73]=i3,W()):(a3|0)==10&&(f2[73]=i3)}function A(e3){e3=e3|0;var a3=0,r3=0;if(a3=s2[e3>>1]|0,X(a3)|0)r3=3;else switch(a3<<16>>16){case 41:case 125:case 93:{r3=3;break}default:e3=0}e:do if((r3|0)==3){for(r3=f2[3]|0;!(e3>>>0<=r3>>>0||(e3=e3+-2|0,!(X(a3)|0)));)a3=s2[e3>>1]|0;switch(a3<<16>>16){case 41:case 125:case 93:{e3=1;break e}default:}e3=(U(a3)|0)^1}while(!1);return e3|0}function C(e3,a3){e3=e3|0,a3=a3|0;var r3=0,i3=0,t3=0,c3=0;return r3=f2[73]|0,i3=s2[r3>>1]|0,c3=(e3|0)==(a3|0),t3=c3?0:e3,c3=c3?0:a3,i3<<16>>16==97&&(f2[73]=r3+4,r3=w2(1)|0,e3=f2[73]|0,Y(r3)|0?(v2(r3),a3=(f2[73]|0)+2|0,f2[73]=a3):(q(r3)|0,a3=f2[73]|0),i3=w2(1)|0,r3=f2[73]|0),(r3|0)!=(e3|0)&&$(e3,a3,t3,c3),i3|0}function g(){var e3=0,a3=0,r3=0;r3=f2[74]|0,a3=f2[73]|0;e:for(;;){if(e3=a3+2|0,a3>>>0>=r3>>>0){a3=6;break}switch(s2[e3>>1]|0){case 13:case 10:{a3=6;break e}case 93:{a3=7;break e}case 92:{e3=a3+4|0;break}default:}a3=e3}return(a3|0)==6?(f2[73]=e3,W(),e3=0):(a3|0)==7&&(f2[73]=e3,e3=93),e3|0}function p(){var e3=0,a3=0,r3=0;e:for(;;){if(e3=f2[73]|0,a3=e3+2|0,f2[73]=a3,e3>>>0>=(f2[74]|0)>>>0){r3=7;break}switch(s2[a3>>1]|0){case 13:case 10:{r3=7;break e}case 47:break e;case 91:{g()|0;break}case 92:{f2[73]=e3+4;break}default:}}(r3|0)==7&&W()}function y(e3){switch(e3=e3|0,s2[e3>>1]|0){case 62:{e3=(s2[e3+-2>>1]|0)==61;break}case 41:case 59:{e3=1;break}case 104:{e3=T(e3+-2|0,208,4)|0;break}case 121:{e3=T(e3+-2|0,216,6)|0;break}case 101:{e3=T(e3+-2|0,228,3)|0;break}default:e3=0}return e3|0}function m(e3){e3=e3|0;var a3=0,r3=0,i3=0,t3=0,c3=0;for(t3=(f2[73]|0)+2|0,f2[73]=t3,r3=f2[74]|0;a3=t3+2|0,!(t3>>>0>=r3>>>0||(i3=s2[a3>>1]|0,!e3&&ie(i3)|0));){if(i3<<16>>16==42&&(s2[t3+4>>1]|0)==47){c3=8;break}t3=a3}(c3|0)==8&&(f2[73]=a3,a3=t3+4|0),f2[73]=a3}function I(e3,a3,r3){e3=e3|0,a3=a3|0,r3=r3|0;var s3=0,f3=0;e:do if(!r3)e3=0;else{for(;s3=i2[e3>>0]|0,f3=i2[a3>>0]|0,s3<<24>>24==f3<<24>>24;)if(r3=r3+-1|0,r3)e3=e3+1|0,a3=a3+1|0;else{e3=0;break e}e3=(s3&255)-(f3&255)|0}while(!1);return e3|0}function U(e3){e3=e3|0;e:do switch(e3<<16>>16){case 38:case 37:case 33:{e3=1;break}default:if((e3&-8)<<16>>16==40|(e3+-58&65535)<6)e3=1;else{switch(e3<<16>>16){case 91:case 93:case 94:{e3=1;break e}default:}e3=(e3+-123&65535)<4}}while(!1);return e3|0}function x(e3){e3=e3|0;e:do switch(e3<<16>>16){case 38:case 37:case 33:break;default:if(!((e3+-58&65535)<6|(e3+-40&65535)<7&e3<<16>>16!=41)){switch(e3<<16>>16){case 91:case 94:break e;default:}return e3<<16>>16!=125&(e3+-123&65535)<4|0}}while(!1);return 1}function S(e3){e3=e3|0;var a3=0;a3=s2[e3>>1]|0;e:do if((a3+-9&65535)>=5){switch(a3<<16>>16){case 160:case 32:{a3=1;break e}default:}if(U(a3)|0)return a3<<16>>16!=46|(G(e3)|0)|0;a3=0}else a3=1;while(!1);return a3|0}function O(e3){e3=e3|0;var a3=0,r3=0,i3=0,t3=0;return r3=n2,n2=n2+16|0,i3=r3,f2[i3>>2]=0,f2[66]=e3,a3=f2[3]|0,t3=a3+(e3<<1)|0,e3=t3+2|0,s2[t3>>1]=0,f2[i3>>2]=e3,f2[67]=e3,f2[59]=0,f2[63]=0,f2[61]=0,f2[60]=0,f2[65]=0,f2[62]=0,n2=r3,a3|0}function $(e3,a3,r3,s3){e3=e3|0,a3=a3|0,r3=r3|0,s3=s3|0;var t3=0,c3=0;t3=f2[67]|0,f2[67]=t3+20,c3=f2[65]|0,f2[((c3|0)==0?240:c3+16|0)>>2]=t3,f2[65]=t3,f2[t3>>2]=e3,f2[t3+4>>2]=a3,f2[t3+8>>2]=r3,f2[t3+12>>2]=s3,f2[t3+16>>2]=0,i2[807]=1}function T(e3,a3,r3){e3=e3|0,a3=a3|0,r3=r3|0;var i3=0,s3=0;return i3=e3+(0-r3<<1)|0,s3=i3+2|0,e3=f2[3]|0,s3>>>0>=e3>>>0&&(I(s3,a3,r3<<1)|0)==0?(s3|0)==(e3|0)?e3=1:e3=S(i3)|0:e3=0,e3|0}function j(e3){switch(e3=e3|0,s2[e3>>1]|0){case 107:{e3=T(e3+-2|0,148,4)|0;break}case 101:{(s2[e3+-2>>1]|0)==117?e3=T(e3+-4|0,120,6)|0:e3=0;break}default:e3=0}return e3|0}function B(e3,a3){e3=e3|0,a3=a3|0;var r3=0;return r3=f2[3]|0,r3>>>0<=e3>>>0&&(s2[e3>>1]|0)==a3<<16>>16?(r3|0)==(e3|0)?r3=1:r3=E(s2[e3+-2>>1]|0)|0:r3=0,r3|0}function E(e3){e3=e3|0;e:do if((e3+-9&65535)<5)e3=1;else{switch(e3<<16>>16){case 32:case 160:{e3=1;break e}default:}e3=e3<<16>>16!=46&(U(e3)|0)}while(!1);return e3|0}function P(){var e3=0,a3=0,r3=0;e3=f2[74]|0,r3=f2[73]|0;e:for(;a3=r3+2|0,!(r3>>>0>=e3>>>0);)switch(s2[a3>>1]|0){case 13:case 10:break e;default:r3=a3}f2[73]=a3}function q(e3){for(e3=e3|0;!(X(e3)|0||U(e3)|0);)if(e3=(f2[73]|0)+2|0,f2[73]=e3,e3=s2[e3>>1]|0,!(e3<<16>>16)){e3=0;break}return e3|0}function z(){var e3=0;switch(e3=f2[(f2[61]|0)+20>>2]|0,e3|0){case 1:{e3=-1;break}case 2:{e3=-2;break}default:e3=e3-(f2[3]|0)>>1}return e3|0}function D(e3){return e3=e3|0,!(T(e3,194,5)|0)&&!(T(e3,44,3)|0)?e3=T(e3,204,2)|0:e3=1,e3|0}function F(e3){switch(e3=e3|0,e3<<16>>16){case 160:case 32:case 12:case 11:case 9:{e3=1;break}default:e3=0}return e3|0}function G(e3){return e3=e3|0,(s2[e3>>1]|0)==46&&(s2[e3+-2>>1]|0)==46?e3=(s2[e3+-4>>1]|0)==46:e3=0,e3|0}function H(){var e3=0;return e3=f2[69]|0,e3=f2[((e3|0)==0?(f2[61]|0)+32|0:e3+16|0)>>2]|0,f2[69]=e3,(e3|0)!=0|0}function J(e3){return e3=e3|0,(f2[3]|0)==(e3|0)?e3=1:e3=S(e3+-2|0)|0,e3|0}function K(){var e3=0;return e3=f2[(f2[62]|0)+12>>2]|0,e3?e3=e3-(f2[3]|0)>>1:e3=-1,e3|0}function L(){var e3=0;return e3=f2[(f2[61]|0)+12>>2]|0,e3?e3=e3-(f2[3]|0)>>1:e3=-1,e3|0}function M(){var e3=0;return e3=f2[(f2[62]|0)+8>>2]|0,e3?e3=e3-(f2[3]|0)>>1:e3=-1,e3|0}function N(){var e3=0;return e3=f2[(f2[61]|0)+16>>2]|0,e3?e3=e3-(f2[3]|0)>>1:e3=-1,e3|0}function Q(){var e3=0;return e3=f2[(f2[61]|0)+4>>2]|0,e3?e3=e3-(f2[3]|0)>>1:e3=-1,e3|0}function R(){var e3=0;return e3=f2[61]|0,e3=f2[((e3|0)==0?236:e3+36|0)>>2]|0,f2[61]=e3,(e3|0)!=0|0}function V(){var e3=0;return e3=f2[62]|0,e3=f2[((e3|0)==0?240:e3+16|0)>>2]|0,f2[62]=e3,(e3|0)!=0|0}function W(){i2[806]=1,f2[68]=(f2[73]|0)-(f2[3]|0)>>1,f2[73]=(f2[74]|0)+2}function X(e3){return e3=e3|0,(e3|128)<<16>>16==160|(e3+-9&65535)<5|0}function Y(e3){return e3=e3|0,e3<<16>>16==39|e3<<16>>16==34|0}function Z(){return(f2[(f2[69]|0)+12>>2]|0)-(f2[3]|0)>>1|0}function _(){return(f2[(f2[69]|0)+8>>2]|0)-(f2[3]|0)>>1|0}function ee(){return(f2[(f2[69]|0)+4>>2]|0)-(f2[3]|0)>>1|0}function ae(){return(f2[(f2[61]|0)+8>>2]|0)-(f2[3]|0)>>1|0}function re(){return(f2[(f2[62]|0)+4>>2]|0)-(f2[3]|0)>>1|0}function ie(e3){return e3=e3|0,e3<<16>>16==13|e3<<16>>16==10|0}function se(){return(f2[f2[69]>>2]|0)-(f2[3]|0)>>1|0}function fe(){return(f2[f2[61]>>2]|0)-(f2[3]|0)>>1|0}function te(){return(f2[f2[62]>>2]|0)-(f2[3]|0)>>1|0}function ce(){return t2[(f2[61]|0)+24>>0]|0|0}function ne(e3){e3=e3|0,f2[3]=e3}function be(){return f2[(f2[61]|0)+28>>2]|0}function ke(){return(i2[807]|0)!=0|0}function ue(){return(i2[808]|0)!=0|0}function le(){f2[69]=0}function oe(){return f2[68]|0}function he(e3){return e3=e3|0,n2=e3+992+15&-16,992}return{su:he,ai:N,ake:ee,aks:se,ave:Z,avs:_,e:oe,ee:re,ele:K,els:M,es:te,f:ue,id:z,ie:Q,ip:ce,is:fe,it:be,ms:ke,p:b2,ra:H,re:V,ri:R,rsa:le,sa:O,se:L,ses:ne,ss:ae}})(typeof globalThis<"u"?globalThis:self,{},a),r=e.su(i-(2<<17))}let h=t.length+1;e.ses(r),e.sa(h-1),s(t,new Uint16Array(a,r,h)),e.p()||(n=e.e(),o());let w=[],d=[];for(;e.ri();){let a2=e.is(),r2=e.ie(),i2=e.ai(),s2=e.id(),f2=e.ss(),c2=e.se(),n2=e.it(),k3;e.ip()&&(k3=b(s2===-1?a2:a2+1,t.charCodeAt(s2===-1?a2-1:a2)));let u3=[];for(e.rsa();e.ra();){let a3=e.aks(),r3=e.ake(),i3=e.avs(),s3=e.ave(),f3=v(a3,r3),t2=v(i3,s3);u3.push([f3,t2])}w.push({t:n2,n:k3,s:a2,e:r2,ss:f2,se:c2,d:s2,a:i2,at:u3.length>0?u3:null})}for(;e.re();){let a2=e.es(),r2=e.ee(),i2=e.els(),s2=e.ele(),f2=v(a2,r2),t2=i2<0?void 0:v(i2,s2);d.push({s:a2,e:r2,ls:i2,le:s2,n:f2,ln:t2})}return[w,d,!!e.f(),!!e.ms()];function v(e2,a2){let r2=t.charCodeAt(e2);return r2===34||r2===39?b(e2+1,r2):t.slice(e2,a2)}}function b(e2,a2){n=e2;let r2="",i2=n;for(;;){n>=t.length&&o();let e3=t.charCodeAt(n);if(e3===a2)break;e3===92?(r2+=t.slice(i2,n),r2+=k(),i2=n):(e3===8232||e3===8233||l(e3)&&o(),++n)}return r2+=t.slice(i2,n++),r2}function k(){let e2=t.charCodeAt(++n);switch(++n,e2){case 110:return`
|
|
3
3
|
`;case 114:return"\r";case 120:return String.fromCharCode(u(2));case 117:return(function(){let e3=t.charCodeAt(n),a2;return e3===123?(++n,a2=u(t.indexOf("}",n)-n),++n,a2>1114111&&o()):a2=u(4),a2<=65535?String.fromCharCode(a2):(a2-=65536,String.fromCharCode(55296+(a2>>10),56320+(1023&a2)))})();case 116:return" ";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 13:t.charCodeAt(n)===10&&++n;case 10:return"";case 56:case 57:o();default:if(e2>=48&&e2<=55){let a2=t.substr(n-1,3).match(/^[0-7]+/)[0],r2=parseInt(a2,8);return r2>255&&(a2=a2.slice(0,-1),r2=parseInt(a2,8)),n+=a2.length-1,e2=t.charCodeAt(n),a2==="0"&&e2!==56&&e2!==57||o(),String.fromCharCode(r2)}return l(e2)?"":String.fromCharCode(e2)}}function u(e2){let a2=n,r2=0,i2=0;for(let a3=0;a3<e2;++a3,++n){let e3,s2=t.charCodeAt(n);if(s2!==95){if(s2>=97)e3=s2-97+10;else if(s2>=65)e3=s2-65+10;else{if(!(s2>=48&&s2<=57))break;e3=s2-48}if(e3>=16)break;i2=s2,r2=16*r2+e3}else i2!==95&&a3!==0||o(),i2=s2}return i2!==95&&n-a2===e2||o(),r2}function l(e2){return e2===13||e2===10}function o(){throw Object.assign(Error(`Parse error ${c}:${t.slice(0,n).split(`
|
|
4
4
|
`).length}:${n-t.lastIndexOf(`
|
|
5
|
-
`,n-1)}`),{idx:n})}import{readFileSync}from"node:fs";import{extname}from"node:path";var commonJsByPath=new Map;function isCommonJsFile(path){let cached=commonJsByPath.get(path);if(cached!==void 0)return cached;let result=detect(path);return commonJsByPath.set(path,result),result}function detect(path){let extension=extname(path);if(extension===".cjs")return!0;if(extension===".mjs"||extension===".ts"||extension===".tsx"||extension===".mts")return!1;try{let[,,,hasModuleSyntax]=parse(readFileSync(path,"utf8"),path);return!hasModuleSyntax}catch{return!1}}function parseImportClause(clause){let rest=clause.trim();if(rest==="")return;let defaultBinding,namespaceBinding,named=[],braceStart=rest.indexOf("{"),head=(braceStart>=0?rest.slice(0,braceStart):rest).trim().replace(/,$/,"").trim();if(head!==""){let namespace=/^\*\s+as\s+([A-Za-z_$][\w$]*)$/.exec(head);if(namespace?.[1]!==void 0)namespaceBinding=namespace[1];else if(/^[A-Za-z_$][\w$]*$/.test(head))defaultBinding=head;else return}if(braceStart>=0){let braceEnd=rest.lastIndexOf("}");if(braceEnd<braceStart)return;rest=rest.slice(braceStart+1,braceEnd);for(let raw of rest.split(",")){let entry=raw.trim();if(entry==="")continue;let aliased=/^(?:(["'])(.+?)\1|([A-Za-z_$][\w$]*))\s+as\s+([A-Za-z_$][\w$]*)$/.exec(entry);if(aliased){named.push({imported:aliased[2]??aliased[3]??"",local:aliased[4]??""});continue}if(/^[A-Za-z_$][\w$]*$/.test(entry)){named.push({imported:entry,local:entry});continue}return}}return{defaultBinding,namespaceBinding,named}}function rewriteCommonJsImport(clause,resolvedId,alias){let parsed=parseImportClause(clause);if(parsed===void 0)return`import ${JSON.stringify(resolvedId)};`;let lines=[`import ${alias} from ${JSON.stringify(resolvedId)};`];if(parsed.defaultBinding!==void 0&&lines.push(`const ${parsed.defaultBinding} = ${alias};`),parsed.namespaceBinding!==void 0&&lines.push(`const ${parsed.namespaceBinding} = ${alias};`),parsed.named.length>0){let pattern=parsed.named.map(({imported,local})=>{let key=/^[A-Za-z_$][\w$]*$/.test(imported)?imported:JSON.stringify(imported);return key===local?key:`${key}: ${local}`}).join(", ");lines.push(`const { ${pattern} } = ${alias};`)}return lines.join(" ")}var diagnosticSchema=external_exports.object({message:external_exports.string(),position:external_exports.object({line:external_exports.number(),column:external_exports.number()}).nullish()}),ExtensionSourceError=class extends Error{constructor(filename,cause){let diagnostics=external_exports.array(diagnosticSchema).parse(cause.errors).map(({message,position})=>({message,...position?{line:position.line,column:position.column}:{}}));super(diagnostics.map(item=>`${filename}${item.line===void 0?"":`:${item.line}:${item.column}`}: ${item.message}`).join(`
|
|
6
|
-
`),{cause}),this.name="ExtensionSourceError",this.filename=filename,this.diagnostics=diagnostics}};import{existsSync}from"node:fs";import{dirname}from"node:path";import{fileURLToPath,pathToFileURL}from"node:url";var RUNTIME_METADATA=Symbol.for("senpi.extension.runtime.metadata");function publishRuntimeMetadata(value){globalThis[RUNTIME_METADATA]=value}var
|
|
5
|
+
`,n-1)}`),{idx:n})}import{readFileSync}from"node:fs";import{extname}from"node:path";var commonJsByPath=new Map;function isCommonJsFile(path){let cached=commonJsByPath.get(path);if(cached!==void 0)return cached;let result=detect(path);return commonJsByPath.set(path,result),result}function detect(path){let extension=extname(path);if(extension===".cjs")return!0;if(extension===".mjs"||extension===".ts"||extension===".tsx"||extension===".mts")return!1;try{let[,,,hasModuleSyntax]=parse(readFileSync(path,"utf8"),path);return!hasModuleSyntax}catch{return!1}}function parseImportClause(clause){let rest=clause.trim();if(rest==="")return;let defaultBinding,namespaceBinding,named=[],braceStart=rest.indexOf("{"),head=(braceStart>=0?rest.slice(0,braceStart):rest).trim().replace(/,$/,"").trim();if(head!==""){let namespace=/^\*\s+as\s+([A-Za-z_$][\w$]*)$/.exec(head);if(namespace?.[1]!==void 0)namespaceBinding=namespace[1];else if(/^[A-Za-z_$][\w$]*$/.test(head))defaultBinding=head;else return}if(braceStart>=0){let braceEnd=rest.lastIndexOf("}");if(braceEnd<braceStart)return;rest=rest.slice(braceStart+1,braceEnd);for(let raw of rest.split(",")){let entry=raw.trim();if(entry==="")continue;let aliased=/^(?:(["'])(.+?)\1|([A-Za-z_$][\w$]*))\s+as\s+([A-Za-z_$][\w$]*)$/.exec(entry);if(aliased){named.push({imported:aliased[2]??aliased[3]??"",local:aliased[4]??""});continue}if(/^[A-Za-z_$][\w$]*$/.test(entry)){named.push({imported:entry,local:entry});continue}return}}return{defaultBinding,namespaceBinding,named}}function rewriteCommonJsImport(clause,resolvedId,alias,attributes=""){let parsed=parseImportClause(clause);if(parsed===void 0)return`import ${JSON.stringify(resolvedId)}${attributes};`;let lines=[`import ${alias} from ${JSON.stringify(resolvedId)}${attributes};`];if(parsed.defaultBinding!==void 0&&lines.push(`const ${parsed.defaultBinding} = ${alias};`),parsed.namespaceBinding!==void 0&&lines.push(`const ${parsed.namespaceBinding} = ${alias};`),parsed.named.length>0){let pattern=parsed.named.map(({imported,local})=>{let key=/^[A-Za-z_$][\w$]*$/.test(imported)?imported:JSON.stringify(imported);return key===local?key:`${key}: ${local}`}).join(", ");lines.push(`const { ${pattern} } = ${alias};`)}return lines.join(" ")}var diagnosticSchema=external_exports.object({message:external_exports.string(),position:external_exports.object({line:external_exports.number(),column:external_exports.number()}).nullish()}),ExtensionSourceError=class extends Error{constructor(filename,cause){let diagnostics=external_exports.array(diagnosticSchema).parse(cause.errors).map(({message,position})=>({message,...position?{line:position.line,column:position.column}:{}}));super(diagnostics.map(item=>`${filename}${item.line===void 0?"":`:${item.line}:${item.column}`}: ${item.message}`).join(`
|
|
6
|
+
`),{cause}),this.name="ExtensionSourceError",this.filename=filename,this.diagnostics=diagnostics}};import{existsSync}from"node:fs";import{dirname}from"node:path";import{fileURLToPath,pathToFileURL}from"node:url";var RUNTIME_METADATA=Symbol.for("senpi.extension.runtime.metadata");function publishRuntimeMetadata(value){globalThis[RUNTIME_METADATA]=value}var importModule=new Function("specifier","options","return import(specifier, options)"),extensionNamespace="senpi-extension",RUNTIME_SPECIFIER="runtime",runtimeModulePath=resolveRuntimeModulePath();function resolveRuntimeModulePath(){try{let candidate=fileURLToPath(new URL("./extension-runtime-module.js",import.meta.url));return existsSync(candidate)?candidate:void 0}catch{return}}function splitModuleId(id){let slash=id.indexOf("/");if(!(slash<=0||slash===id.length-1))return{generation:id.slice(0,slash),filename:decodeURIComponent(id.slice(slash+1))}}var graphs=new Map,collected=new FinalizationRegistry(generation=>graphs.delete(generation)),nextGeneration=0,installed=!1,pluginRegistrations=0,registeredHosts=new Set,ExtensionModuleIdError=class extends Error{constructor(id){super(`Extension module id is not "<generation>/<encoded filename>": ${id}`),this.name="ExtensionModuleIdError"}},ExtensionGenerationDisposedError=class extends Error{constructor(generation){super(`Extension generation ${generation} has been disposed`),this.name="ExtensionGenerationDisposedError",this.generation=generation}};function graphFor(generation){let graph=graphs.get(generation)?.deref();if(!graph)throw new ExtensionGenerationDisposedError(generation);return graph}function metadata(generation,filename){let resolvePath=specifier=>{let id=graphFor(generation).resolve(specifier,filename);return id.startsWith(`${extensionNamespace}:`)?decodeURIComponent(id.slice(id.indexOf("/")+1)):void 0},require2=Object.assign(specifier=>graphFor(generation).require(specifier,filename),{resolve:specifier=>resolvePath(specifier)??graphFor(generation).resolve(specifier,filename)});return{url:pathToFileURL(filename).href,path:filename,dir:dirname(filename),require:require2,commonJs:body=>graphFor(generation).evaluateCommonJs(filename,body),import:async(specifier,options)=>importModule(graphFor(generation).resolve(specifier,filename),options),resolve:specifier=>{let path=resolvePath(specifier);return path===void 0?graphFor(generation).resolve(specifier,filename):pathToFileURL(path).href}}}function installRegistry(virtualModules){let hosts=Object.entries(virtualModules).filter(([name])=>!registeredHosts.has(name));(!installed||hosts.length>0)&&(pluginRegistrations++,Bun.plugin({name:extensionNamespace,setup(builder){for(let[name,exports]of hosts)builder.module(name,()=>({exports,loader:"object"})),registeredHosts.add(name);installed||(publishRuntimeMetadata(metadata),builder.module(`${extensionNamespace}:${RUNTIME_SPECIFIER}`,()=>({exports:{metadata},loader:"object"})),builder.onResolve({filter:/.*/,namespace:extensionNamespace},({path})=>{if(path===RUNTIME_SPECIFIER)return runtimeModulePath===void 0?{path,namespace:extensionNamespace}:{path:runtimeModulePath,namespace:"file"};let parsed=splitModuleId(path);if(parsed===void 0)throw new ExtensionModuleIdError(path);return graphFor(parsed.generation),/\.[cm]?[jt]sx?$/.test(parsed.filename)?{path,namespace:extensionNamespace}:{path:parsed.filename,namespace:"file"}}),builder.onLoad({filter:/.*/,namespace:extensionNamespace},({path})=>{let parsed=splitModuleId(path);if(parsed===void 0)throw new ExtensionModuleIdError(path);return graphFor(parsed.generation).load(parsed.filename)}),installed=!0)}}))}function registerExtensionGraph(graph,virtualModules){installRegistry(virtualModules);let generation=String(nextGeneration++);return graphs.set(generation,new WeakRef(graph)),collected.register(graph,generation,graph),{generation,dispose(){graphs.delete(generation),collected.unregister(graph)}}}function bunExtensionImporterStats(){return{generations:[...graphs.values()].filter(entry=>entry.deref()).length,plugins:pluginRegistrations}}var __rewriteRelativeImportExtension=function(path,preserveJsx){return typeof path=="string"&&/^\.\.?\//.test(path)?path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(m,tsx,d,ext,cm){return tsx?preserveJsx?".jsx":".js":d&&(!ext||!cm)?m:d+ext+"."+cm.toLowerCase()+"js"}):path};function createBunExtensionImporter(virtualModules){let sources=new Map,commonJs=new Set,commonJsModules=new Map,nativeRequire=createRequire(import.meta.url),active=!0,assertActive=()=>{if(!active)throw new ExtensionGenerationDisposedError(registration.generation)},moduleId=filename=>`${extensionNamespace}:${registration.generation}/${encodeURIComponent(filename)}`,resolveTarget=(specifier,filename)=>{if(assertActive(),Object.hasOwn(virtualModules,specifier)||isBuiltin(specifier)||specifier.startsWith("bun:"))return{id:specifier};if(specifier.startsWith(`${extensionNamespace}:`))return{id:specifier};let path=specifier.startsWith("file:")?fileURLToPath2(specifier):specifier,resolved=realpathSync(Bun.resolveSync(path,dirname2(filename)));return{id:moduleId(resolved),path:resolved}},graph={assertActive,resolve(specifier,filename){return resolveTarget(specifier,filename).id},require(specifier,filename){let id=graph.resolve(specifier,filename),evaluating=commonJsModules.get(id);if(evaluating!==void 0)return evaluating.exports;let result=nativeRequire(id);return commonJs.has(id)?result.default:result},evaluateCommonJs(filename,body){assertActive();let id=moduleId(filename),module={exports:{}};commonJsModules.set(id,module);try{body.call(module.exports,module.exports,module)}catch(error){throw commonJsModules.delete(id),error}return module.exports},load(filename){assertActive();let existing=sources.get(filename);if(existing)return existing;let source=readFileSync2(filename,"utf8"),name="__senpiExtensionMeta";for(;source.includes(name);)name+="_";let extension=extname2(filename),transpiler=new Bun.Transpiler({loader:extension===".tsx"?"tsx":extension===".jsx"?"jsx":"ts",target:"bun",define:{"import.meta":name,require:`${name}.require`,__filename:`${name}.path`,__dirname:`${name}.dir`}}),contents;try{contents=transpiler.transformSync(source)}catch(error){throw error instanceof AggregateError?new ExtensionSourceError(filename,error):error}let[imports,,,hasModuleSyntax]=parse(contents,filename),edits=[],commonJsImports=0;for(let edge of imports)if(edge.d>=0)edits.push({start:edge.ss,end:edge.d,text:`${name}.import`});else if(edge.n!==void 0){let target=resolveTarget(edge.n,filename);if(target.path!==void 0&&isCommonJsFile(target.path)){let clause=contents.slice(edge.ss+6,edge.s-1).replace(/\bfrom\s*$/,""),attributes=edge.a<0?"":contents.slice(edge.e+1,edge.se).replace(/;\s*$/,"");edits.push({start:edge.ss,end:edge.se,text:rewriteCommonJsImport(clause,target.id,`${name}Cjs${commonJsImports++}`,attributes)})}else edits.push({start:edge.s-1,end:edge.e+1,text:JSON.stringify(target.id)})}for(let edit of edits.sort((a2,b2)=>b2.start-a2.start))contents=contents.slice(0,edit.start)+edit.text+contents.slice(edit.end);contents=contents.replace(/^#![^\n]*\n/,""),!hasModuleSyntax&&extension!==".mjs"&&extension!==".mts"&&(commonJs.add(moduleId(filename)),contents=`export default ${name}.commonJs(function (exports, module) {
|
|
7
7
|
${contents}
|
|
8
8
|
});`),contents=`import { metadata as ${name}Factory } from "${extensionNamespace}:runtime";
|
|
9
9
|
const ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});
|
|
10
|
-
${contents}`;let prepared={contents,loader:"js"};return sources.set(filename,prepared),prepared}},registration=registerExtensionGraph(graph,virtualModules);return{async import(path,_options){assertActive();let id=moduleId(realpathSync(resolve(path))),factory=(await import(
|
|
10
|
+
${contents}`;let prepared={contents,loader:"js"};return sources.set(filename,prepared),prepared}},registration=registerExtensionGraph(graph,virtualModules);return{async import(path,_options){assertActive();let id=moduleId(realpathSync(resolve(path))),factory=(await import(__rewriteRelativeImportExtension(id))).default;return typeof factory!="function"?factory:function(...args){return graph.assertActive(),factory.apply(this,args)}},dispose(){active=!1,registration.dispose(),sources.clear(),commonJs.clear(),commonJsModules.clear()}}}export{bunExtensionImporterStats,createBunExtensionImporter};
|