ur-agent 1.11.0
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 +101 -0
- package/LICENSE +37 -0
- package/QUALITY.md +53 -0
- package/README.md +141 -0
- package/bin/ur.js +94 -0
- package/dist/cli.js +494587 -0
- package/docs/CONFIGURATION.md +133 -0
- package/docs/DEVELOPMENT.md +69 -0
- package/docs/USAGE.md +101 -0
- package/docs/VALIDATION.md +197 -0
- package/examples/basic_chat.md +11 -0
- package/examples/browser.md +7 -0
- package/examples/coding_task.md +14 -0
- package/examples/images.md +8 -0
- package/examples/mcp.md +7 -0
- package/examples/memory.md +9 -0
- package/examples/research_task.md +13 -0
- package/examples/video.md +8 -0
- package/package.json +132 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.11.0
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- **Ollama model selection now lets routing work by default.** The launcher no
|
|
7
|
+
longer forces `OLLAMA_MODEL` when neither `OLLAMA_MODEL` nor `UR_MODEL` is
|
|
8
|
+
set, so UR's Ollama router can choose from the models exposed by the local
|
|
9
|
+
Ollama app. The built-in fallback is `qwen3-coder:480b-cloud` when model-list
|
|
10
|
+
discovery is unavailable.
|
|
11
|
+
- **Repository metadata now matches production.** Package metadata, docs, bundled
|
|
12
|
+
issue links, marketplace defaults, and GitHub workflow templates now point to
|
|
13
|
+
`Maitham16/UR-mapek`.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- **Release consistency gate.** `bun run release:check` verifies package,
|
|
17
|
+
`bunfig.toml`, bundled CLI, docs, and launcher version output agree. It also
|
|
18
|
+
runs automatically from `prepack`.
|
|
19
|
+
- **Quality notes.** `QUALITY.md` documents the release gate, runtime
|
|
20
|
+
assumptions, safety boundaries, and known limits.
|
|
21
|
+
- **Stronger production CI.** The GitHub workflow now runs typecheck, tests,
|
|
22
|
+
bundle, smoke, secret scan, release check, package dry-run, and global install
|
|
23
|
+
verification.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- **Stale bundle/version drift.** The release process now prevents publishing a
|
|
27
|
+
package where `package.json`, `dist/cli.js`, `bunfig.toml`, and `ur --version`
|
|
28
|
+
disagree.
|
|
29
|
+
- **Ollama Cloud wording.** Docs now clarify that UR talks only to the local
|
|
30
|
+
Ollama app, while models exposed by that app may be local or Ollama
|
|
31
|
+
Cloud-backed.
|
|
32
|
+
|
|
33
|
+
## 1.10.2
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- **Clipboard image paste — the fix that actually ships.** The 1.10.1 change edited the native NSPasteboard branch, which is dead-code-eliminated from the bundle (its feature gate compiles out), so it never ran. The live path is osascript, whose `saveImage` reused a fixed temp file (`ur_cli_latest_screenshot.png`) opened `with write permission` but never truncated — so a smaller image pasted over a previously larger one kept the old trailing bytes, producing a corrupt PNG ("found in clipboard but not attached"). Added `set eof fp to 0` to truncate before writing.
|
|
37
|
+
|
|
38
|
+
## 1.10.1
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
- **Clipboard image paste.** An image the clipboard reported as present but the native reader couldn't decode was silently dropped — "found in clipboard but not attached." `getImageFromClipboard` now falls back to the osascript path instead of treating a native `null` as authoritative.
|
|
42
|
+
- **Token truncation on Ollama Cloud models.** Cloud models (the `-cloud` / `:cloud` suffix) now default to a 128K-token context floor for both `num_ctx` and auto-compaction, instead of the small or missing value `/api/show` reports for them — so prompts are no longer silently truncated, with no env vars required. The reported value is still used when it is larger, and `UR_OLLAMA_NUM_CTX` (no longer capped to the detected value) / `OLLAMA_CONTEXT_TOKENS` still override.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
- **Default model** is now `qwen3-coder:480b-cloud` instead of `llama3.2`, so a session started without an explicit model no longer falls back to a 3B model.
|
|
46
|
+
- **Comment discipline now applies to all sessions.** UR's "default to writing no comments / don't explain WHAT the code does / verify it actually works before reporting complete" guidance was gated to internal builds; it is now enabled for everyone (the upstream `@[MODEL LAUNCH]` TODO had it marked for external release).
|
|
47
|
+
|
|
48
|
+
## 1.10.0
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
- **`skill-forge` plugin** in the `ur-plugins-official` marketplace — have the agent author skills for you. `/forge-skill <description>` runs on the active session model: it designs the skill (name, `when_to_use` triggers, arguments, minimal `allowed-tools`, inline vs fork, and steps that each carry a success criterion), shows the `SKILL.md` for a single confirmation, then saves it to `~/.ur/skills/<name>/` (or `./.ur/skills/` with `--project`) without clobbering an existing one. `/skill-refine <name> : <change>` improves an existing skill, and a bundled `skill-authoring` skill encodes the conventions. Complements the built-in `/create-skill`, which only scaffolds an empty template.
|
|
52
|
+
|
|
53
|
+
### Verified
|
|
54
|
+
- The plugin manifest plus its two command and one skill frontmatter blocks parse as strict YAML; the marketplace entry resolves; and there are no slash-command name collisions across the marketplace.
|
|
55
|
+
|
|
56
|
+
## 1.9.0
|
|
57
|
+
|
|
58
|
+
### Added
|
|
59
|
+
- **Seven first-party integration plugins** in the `ur-plugins-official` marketplace. Each bundles an official MCP server, curated slash commands, and a methodology skill, and falls back to a CLI or local library so the commands still work before any token is configured:
|
|
60
|
+
- **`obsidian`** — operate a vault as a second brain: `/second-brain`, `/daily-note`, `/moc`, `/backlinks`, `/vault-search`. Direct vault file edits or the Obsidian Local REST API MCP server, plus a Zettelkasten/PARA/MOC skill.
|
|
61
|
+
- **`github`** — `/gh-pr-review`, `/gh-pr-create`, `/gh-issues`, `/gh-repo-health` via GitHub's official remote MCP server (`api.githubcopilot.com/mcp/`) or the `gh` CLI.
|
|
62
|
+
- **`gitlab`** — `/gl-mr-review`, `/gl-mr-create`, `/gl-issues`, `/gl-pipeline` via GitLab's official MCP server (OAuth) or the `glab` CLI.
|
|
63
|
+
- **`huggingface`** — `/hf-model-search`, `/hf-dataset-search`, `/hf-model-card`, `/hf-download` via the official Hugging Face MCP server or the `hf` CLI.
|
|
64
|
+
- **`word`** — `/docx-new`, `/docx-from-md`, `/docx-review`, `/docx-edit` via the Office Word MCP server (`uvx`) or a pandoc / python-docx fallback.
|
|
65
|
+
- **`powerpoint`** — `/pptx-new`, `/pptx-from-md`, `/pptx-review`, `/pptx-theme` via the Office PowerPoint MCP server (`uvx`) or a python-pptx fallback.
|
|
66
|
+
- **`miro`** — `/miro-board`, `/miro-diagram`, `/miro-stickies`, `/miro-export` via Miro's official MCP server (OAuth) or the REST API.
|
|
67
|
+
- Each manifest wires its MCP server through `userConfig`, so tokens are prompted at enable time and stored in secure storage (keychain / credentials file) — never in plaintext settings or prompt content.
|
|
68
|
+
|
|
69
|
+
### Verified
|
|
70
|
+
- All seven manifests validate against the plugin schema (mcpServers transport, `userConfig` identifiers, `${user_config}` resolution); 36 command/skill frontmatter blocks parse as strict YAML; no secret keys are referenced in prompt content; and there are no slash-command name collisions across the marketplace.
|
|
71
|
+
|
|
72
|
+
## 1.8.0
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
- **`/create-skill` command.** Scaffold a new skill without leaving the REPL: `/create-skill <name> [: <description>] [--project]` writes a ready-to-edit `SKILL.md` (with frontmatter) to `~/.ur/skills/<name>/` — or `.ur/skills/` with `--project` — refuses to clobber an existing skill, and clears caches so it shows up immediately (alias `/new-skill`).
|
|
76
|
+
- **Game Designer mode.** A new built-in output style (`/output-style`) that makes UR reason like a game designer — core loops, player fantasy, game feel, and tunable balance constants — while it writes working code.
|
|
77
|
+
- **Thinking toggle in the model picker.** `/model` now lets you toggle extended thinking with `t` (alongside `← →` effort cycling) for models that support it. The choice applies to the session and persists via `alwaysThinkingEnabled`.
|
|
78
|
+
|
|
79
|
+
### Fixed
|
|
80
|
+
- **`/update-config` no longer crashes** with `Undefined cannot be represented in JSON Schema`. The settings-schema generator now tolerates Zod types with no JSON Schema equivalent (e.g. the `enabledPlugins` union) instead of throwing.
|
|
81
|
+
|
|
82
|
+
## 1.7.0
|
|
83
|
+
|
|
84
|
+
### Added
|
|
85
|
+
- **Adaptive model routing (Ollama).** The agent auto-selects the best installed model per tier — the strongest coder model for the main loop, the smallest fast model for light internal work (titles, classification, session search, hooks). Honors `OLLAMA_MODEL` / `OLLAMA_SMALL_FAST_MODEL`; gated by `UR_OLLAMA_AUTO_ROUTE`.
|
|
86
|
+
- **Per-model context auto-tuning.** Each request sets `num_ctx` from the model's real context window and the prompt size (floored at 32K for agent work, bucketed so the KV cache stays warm), fixing silent truncation at Ollama's 4096 default. Override with `UR_OLLAMA_NUM_CTX`.
|
|
87
|
+
- **Keep-alive for faster responses.** Requests set `keep_alive` (default 30m) to keep the active model warm between turns and cut first-token latency. Override with `UR_OLLAMA_KEEP_ALIVE`.
|
|
88
|
+
- **Smarter model listing.** `/model` shows each model's tier (coder/fast) and context window; `/ur-doctor` reports the routing picks and recommends pulling a coder model when none is installed.
|
|
89
|
+
|
|
90
|
+
### Verified
|
|
91
|
+
- New unit tests for routing, context tuning, and keep-alive (including an end-to-end request-body assertion); full suite green.
|
|
92
|
+
|
|
93
|
+
## 1.6.0
|
|
94
|
+
|
|
95
|
+
### Added
|
|
96
|
+
- **Proactive clarification & planning prompts.** The agent now uses the `AskUserQuestion` multiple-choice popup before significant or ambiguous work and at key planning decisions. Options are navigated with arrow keys and submitted; the last "Other" entry always lets you type a custom answer.
|
|
97
|
+
- **Smarter prompt handling.** New always-on guidance makes the agent resolve ambiguity before acting, work in verifiable steps and check each step's output against the request before continuing, verify work actually runs before reporting done, report outcomes faithfully, and keep changes precisely scoped and professional.
|
|
98
|
+
|
|
99
|
+
### Changed
|
|
100
|
+
- **Fewer permission prompts (Balanced default).** When no permission mode is explicitly configured, sessions now start in `acceptEdits`: in-project file edits and safe filesystem/read-only commands are auto-approved, while risky or out-of-project actions still prompt. Override anytime with `permissions.defaultMode` or `--permission-mode`.
|
|
101
|
+
- **Elegant breathing spinner.** The house glyph (`⌂`) and bar now pulse smoothly between dim and bright instead of hard-blinking.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
UR Agent Non-Commercial Self-Responsibility License
|
|
2
|
+
Version 1.0
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Maitham Al-rubaye
|
|
5
|
+
|
|
6
|
+
Permission is granted to install, run, copy, inspect, and modify this software
|
|
7
|
+
only for personal, educational, research, evaluation, and other
|
|
8
|
+
non-commercial purposes.
|
|
9
|
+
|
|
10
|
+
Commercial use is not permitted without prior written permission from the
|
|
11
|
+
copyright holder. Commercial use includes selling the software, offering it as
|
|
12
|
+
part of a paid product or service, using it to provide paid consulting or
|
|
13
|
+
managed services, or using it primarily for business revenue generation.
|
|
14
|
+
|
|
15
|
+
You may share modified or unmodified copies only if you keep this license and
|
|
16
|
+
copyright notice with the software, clearly mark material changes, and do not
|
|
17
|
+
remove attribution to the original author.
|
|
18
|
+
|
|
19
|
+
You, the user, are solely responsible for how you use this software and for
|
|
20
|
+
any outputs, actions, commands, files, network requests, automation,
|
|
21
|
+
integrations, or decisions created with it. You are responsible for reviewing
|
|
22
|
+
the software, its configuration, its tool access, and its outputs before using
|
|
23
|
+
them in any project, system, repository, device, or service.
|
|
24
|
+
|
|
25
|
+
This software is provided "as is", without warranty of any kind, express or
|
|
26
|
+
implied, including warranties of merchantability, fitness for a particular
|
|
27
|
+
purpose, non-infringement, accuracy, security, availability, or suitability for
|
|
28
|
+
any use.
|
|
29
|
+
|
|
30
|
+
To the maximum extent permitted by law, the author and copyright holder will
|
|
31
|
+
not be liable for any claim, damage, loss, cost, security incident, data loss,
|
|
32
|
+
business interruption, legal issue, or other liability arising from or related
|
|
33
|
+
to this software, its outputs, or its use, whether in contract, tort, or any
|
|
34
|
+
other legal theory.
|
|
35
|
+
|
|
36
|
+
Any use outside this license requires prior written permission from the
|
|
37
|
+
copyright holder.
|
package/QUALITY.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# UR Quality Notes
|
|
2
|
+
|
|
3
|
+
UR is a local-first terminal coding agent. Production releases should be
|
|
4
|
+
verifiable from a clean checkout and should not depend on local machine state
|
|
5
|
+
other than Bun and the local Ollama app.
|
|
6
|
+
|
|
7
|
+
## Release Gate
|
|
8
|
+
|
|
9
|
+
Run these commands before tagging or pushing a release:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
bun run typecheck
|
|
13
|
+
bun test
|
|
14
|
+
bun run bundle
|
|
15
|
+
bun run smoke
|
|
16
|
+
bun run secrets:scan
|
|
17
|
+
bun run release:check
|
|
18
|
+
npm pack --dry-run
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`bun run release:check` is also wired into `prepack`, so stale bundles and
|
|
22
|
+
version drift fail before packaging.
|
|
23
|
+
|
|
24
|
+
## Runtime Assumptions
|
|
25
|
+
|
|
26
|
+
- UR runs through Bun.
|
|
27
|
+
- Model requests go to the local Ollama app at `http://localhost:11434/api`.
|
|
28
|
+
- The local Ollama app may expose local models or Ollama Cloud-backed models.
|
|
29
|
+
- UR does not call model provider APIs directly and does not manage model API
|
|
30
|
+
keys.
|
|
31
|
+
- The GitHub install path runs `dist/cli.js`, so the bundle must match the
|
|
32
|
+
package version.
|
|
33
|
+
|
|
34
|
+
## Safety Boundaries
|
|
35
|
+
|
|
36
|
+
- Sensitive tool actions go through permission checks.
|
|
37
|
+
- Dangerous auto-allow rules for shell, PowerShell, and subagents are blocked
|
|
38
|
+
from classifier-backed auto mode.
|
|
39
|
+
- The verifier runs deterministic L1 checks for false completion claims,
|
|
40
|
+
repeated tool loops, empty assistant turns, and project gates.
|
|
41
|
+
- Deep verification through the verification subagent is manual by default and
|
|
42
|
+
can be enabled with `UR_VERIFIER_AUTO_SUBAGENT=1`.
|
|
43
|
+
- Secrets must stay in environment variables, secure storage, or local ignored
|
|
44
|
+
settings files; tracked files are scanned by `bun run secrets:scan`.
|
|
45
|
+
|
|
46
|
+
## Known Limits
|
|
47
|
+
|
|
48
|
+
- `dist/cli.js` is generated and must be rebuilt after source, version, or macro
|
|
49
|
+
changes.
|
|
50
|
+
- A failed Ollama model-list lookup falls back to `qwen3-coder:480b-cloud`.
|
|
51
|
+
- MCP servers can access external systems; only enable servers you trust.
|
|
52
|
+
- Live model behavior should be validated manually with `docs/VALIDATION.md`
|
|
53
|
+
before major releases.
|
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# UR Agent
|
|
2
|
+
|
|
3
|
+
UR is a Bun/TypeScript terminal coding agent. It starts an interactive session by default, can run once in print mode for scripts, and supports project context, slash commands, MCP servers, plugins, skills, and custom agents.
|
|
4
|
+
|
|
5
|
+
The package installs a global `ur` command from this GitHub repository. The launcher requires Bun and sends all model requests to the local Ollama app.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Bun. This workspace was verified with Bun 1.3.14.
|
|
10
|
+
- Node.js-compatible shell environment
|
|
11
|
+
- A local Ollama app/server for model requests at http://localhost:11434/api
|
|
12
|
+
- Optional: GitHub CLI, tmux, and IDE integrations for workflows that use them
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
### IMPORTANT
|
|
17
|
+
If you have previous version remove it with:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm uninstall -g ur-agent
|
|
21
|
+
bun remove -g ur-agent
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Then, install:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
bun add -g github:Maitham16/UR-mapek
|
|
28
|
+
ur --version
|
|
29
|
+
ur
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If you prefer npm for the global install, Bun is still required at runtime:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npm install -g github:Maitham16/UR-mapek
|
|
36
|
+
ur --version
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
UR auto-routes to an installed Ollama model when possible. If you want a specific model, choose it explicitly:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
UR_MODEL=qwen3-coder:480b-cloud ur
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The launch wrapper reads `OLLAMA_MODEL` first, then `UR_MODEL`. If neither is set, UR lets its Ollama router choose from the models exposed by your local Ollama app, including Ollama Cloud-backed models. If routing cannot discover a model list, the built-in fallback is `qwen3-coder:480b-cloud`.
|
|
46
|
+
|
|
47
|
+
## Development From Source
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
bun install
|
|
51
|
+
bun run start
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To make the `ur` command available from this checkout during development:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
bun link
|
|
58
|
+
ur
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Common Usage
|
|
62
|
+
|
|
63
|
+
Start an interactive session:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
ur
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Ask one question and print the answer:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
ur -p "summarize this repository"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Use JSON output for automation:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
ur -p --output-format json "list the main commands"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Resume a recent session:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
ur --continue
|
|
85
|
+
ur --resume
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Run with a specific model:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
ur --model qwen3-coder:480b-cloud
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
See all CLI options and subcommands:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
ur --help
|
|
98
|
+
ur mcp --help
|
|
99
|
+
ur plugin --help
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
- [Usage Guide](docs/USAGE.md)
|
|
105
|
+
- [Configuration](docs/CONFIGURATION.md)
|
|
106
|
+
- [Development Guide](docs/DEVELOPMENT.md)
|
|
107
|
+
|
|
108
|
+
The `examples/` directory also contains prompt examples for coding, research, browser, image, video, MCP, and memory workflows.
|
|
109
|
+
|
|
110
|
+
## License And Responsibility
|
|
111
|
+
|
|
112
|
+
UR Agent is released under the [UR Agent Non-Commercial Self-Responsibility License](LICENSE). Commercial use is not allowed without written permission from Maitham Al-rubaye.
|
|
113
|
+
|
|
114
|
+
The software is provided as-is. Users are responsible for reviewing how they run it, what tools it can access, and any outputs or actions it creates.
|
|
115
|
+
|
|
116
|
+
## Security
|
|
117
|
+
|
|
118
|
+
Do not commit secrets, passwords, API keys, OAuth tokens, private keys, `.env` files, local UR memory, generated indexes, logs, or local settings. The package `files` list ships the launcher, bundled CLI, docs, examples, changelog, quality notes, README, and license.
|
|
119
|
+
|
|
120
|
+
## Project Context
|
|
121
|
+
|
|
122
|
+
UR reads project instructions from `UR.md` files and can load project assets from `.ur/`. Shared project configuration may be committed, but local files such as `.ur/settings.local.json`, `.ur/memory/`, `.ur/index/`, and `UR.local.md` are ignored by Git.
|
|
123
|
+
|
|
124
|
+
## Development
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
bun run dev
|
|
128
|
+
bun run typecheck
|
|
129
|
+
bun test
|
|
130
|
+
bun run bundle
|
|
131
|
+
bun run smoke
|
|
132
|
+
bun run secrets:scan
|
|
133
|
+
bun run release:check
|
|
134
|
+
npm pack --dry-run
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The package is configured for GitHub installation through `github:Maitham16/UR-mapek`. It is not published to the npm registry yet.
|
|
138
|
+
|
|
139
|
+
## Designed By
|
|
140
|
+
|
|
141
|
+
Maitham Al-rubaye
|
package/bin/ur.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process'
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
8
|
+
const entrypoint = resolve(packageRoot, 'src/entrypoints/cli.tsx')
|
|
9
|
+
const bundledEntrypoint = resolve(packageRoot, 'dist/cli.js')
|
|
10
|
+
const preload = resolve(packageRoot, 'plugins/bunBundleDev.ts')
|
|
11
|
+
const packageJsonPath = resolve(packageRoot, 'package.json')
|
|
12
|
+
|
|
13
|
+
function readPackageMetadata() {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
16
|
+
} catch {
|
|
17
|
+
return {}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function defineMacro(name, value) {
|
|
22
|
+
return `${name}=${value === undefined ? 'undefined' : JSON.stringify(value)}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const packageMetadata = readPackageMetadata()
|
|
26
|
+
const version =
|
|
27
|
+
typeof packageMetadata.version === 'string'
|
|
28
|
+
? packageMetadata.version
|
|
29
|
+
: '0.0.0-dev'
|
|
30
|
+
const packageName =
|
|
31
|
+
typeof packageMetadata.name === 'string' ? packageMetadata.name : 'ur-agent'
|
|
32
|
+
const issuesUrl =
|
|
33
|
+
typeof packageMetadata.bugs?.url === 'string'
|
|
34
|
+
? packageMetadata.bugs.url
|
|
35
|
+
: 'https://github.com/Maitham16/UR-mapek/issues'
|
|
36
|
+
|
|
37
|
+
const bun = process.env.BUN_BIN || process.env.BUN_EXECUTABLE || 'bun'
|
|
38
|
+
const ollamaModel =
|
|
39
|
+
process.env.OLLAMA_MODEL || process.env.UR_MODEL
|
|
40
|
+
const userArgs = process.argv.slice(2)
|
|
41
|
+
const args =
|
|
42
|
+
existsSync(bundledEntrypoint)
|
|
43
|
+
? [bundledEntrypoint, ...userArgs]
|
|
44
|
+
: [
|
|
45
|
+
'run',
|
|
46
|
+
'--preload',
|
|
47
|
+
preload,
|
|
48
|
+
'--define',
|
|
49
|
+
defineMacro('MACRO.VERSION', version),
|
|
50
|
+
'--define',
|
|
51
|
+
defineMacro('MACRO.BUILD_TIME', ''),
|
|
52
|
+
'--define',
|
|
53
|
+
defineMacro('MACRO.PACKAGE_URL', packageName),
|
|
54
|
+
'--define',
|
|
55
|
+
defineMacro('MACRO.NATIVE_PACKAGE_URL', undefined),
|
|
56
|
+
'--define',
|
|
57
|
+
defineMacro('MACRO.FEEDBACK_CHANNEL', issuesUrl),
|
|
58
|
+
'--define',
|
|
59
|
+
defineMacro('MACRO.ISSUES_EXPLAINER', `file an issue at ${issuesUrl}`),
|
|
60
|
+
'--define',
|
|
61
|
+
defineMacro('MACRO.VERSION_CHANGELOG', ''),
|
|
62
|
+
entrypoint,
|
|
63
|
+
...userArgs,
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
const child = spawn(bun, args, {
|
|
67
|
+
cwd: process.cwd(),
|
|
68
|
+
env: {
|
|
69
|
+
...process.env,
|
|
70
|
+
...(ollamaModel ? { OLLAMA_MODEL: ollamaModel } : {}),
|
|
71
|
+
},
|
|
72
|
+
stdio: 'inherit',
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
child.on('error', error => {
|
|
76
|
+
if (error.code === 'ENOENT') {
|
|
77
|
+
console.error(
|
|
78
|
+
'Ur requires Bun to run. Install Bun from https://bun.sh, then retry.',
|
|
79
|
+
)
|
|
80
|
+
process.exit(1)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.error(error.message)
|
|
84
|
+
process.exit(1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
child.on('exit', (code, signal) => {
|
|
88
|
+
if (signal) {
|
|
89
|
+
process.kill(process.pid, signal)
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
process.exit(code ?? 1)
|
|
94
|
+
})
|