@nanhara/hara 0.53.0 → 0.62.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 +181 -0
- package/README.md +25 -7
- package/SECURITY.md +54 -0
- package/dist/agent/loop.js +5 -3
- package/dist/completions.js +49 -0
- package/dist/config.js +17 -7
- package/dist/cron/install.js +112 -0
- package/dist/cron/runner.js +109 -0
- package/dist/cron/schedule.js +147 -0
- package/dist/cron/store.js +87 -0
- package/dist/index.js +381 -11
- package/dist/mcp/server.js +56 -0
- package/dist/memory/store.js +44 -6
- package/dist/org/review-chain.js +91 -0
- package/dist/org/roles.js +11 -0
- package/dist/providers/qwen-oauth.js +9 -2
- package/dist/sandbox.js +25 -3
- package/dist/search/semindex.js +9 -2
- package/dist/session/store.js +12 -2
- package/dist/tools/computer.js +9 -4
- package/dist/tools/patch.js +31 -12
- package/dist/tools/web.js +81 -8
- package/dist/tui/App.js +2 -2
- package/dist/tui/InputBox.js +37 -3
- package/dist/tui/vim.js +115 -0
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,187 @@ All notable changes to `@nanhara/hara`.
|
|
|
5
5
|
> Versioning (pre-1.0, SemVer-style): the **minor** (middle) number bumps for a **new feature**; the
|
|
6
6
|
> **patch** (last) number bumps for **optimizations/fixes of existing features**.
|
|
7
7
|
|
|
8
|
+
## 0.62.0 — unreleased (shell completions)
|
|
9
|
+
|
|
10
|
+
- **`hara completions bash|zsh|fish`** prints a completion script (eval it in your shell rc) that
|
|
11
|
+
tab-completes the top-level subcommands and the subcommands of each group (`cron`, `memory`, `plugin`,
|
|
12
|
+
`roles`, `skills`, `config`), falling back to file completion. Generated from the live command tree so it
|
|
13
|
+
never drifts; hand-rolled (no new dependency).
|
|
14
|
+
|
|
15
|
+
## 0.61.3 — unreleased (audit follow-through: session robustness + SECURITY.md)
|
|
16
|
+
|
|
17
|
+
- **Corrupt/hand-edited session files no longer crash** `--resume` or `/sessions` (audit M4): `loadSession`
|
|
18
|
+
validates the shape (meta object + history array), `deriveTitle` tolerates a non-string, and `listSessions`
|
|
19
|
+
skips metaless files instead of throwing.
|
|
20
|
+
- New **`SECURITY.md`** — the threat model, the controls (approval gate, read-only sub-agents, write-confinement
|
|
21
|
+
sandbox, `web_fetch` SSRF guard, 0600 secrets, plugin trust), what is deliberately *not* a security boundary,
|
|
22
|
+
and how to report a vulnerability. Captures the posture from the two audit passes.
|
|
23
|
+
|
|
24
|
+
## 0.61.2 — unreleased (security hardening — second audit: SSRF, RPA, secrets)
|
|
25
|
+
|
|
26
|
+
A second audit (RPA / network / auth / search) found more real issues; fixed:
|
|
27
|
+
- **`web_fetch` SSRF (critical).** It would fetch any host — incl. `169.254.169.254` (cloud metadata),
|
|
28
|
+
`localhost`/`127.0.0.1` internal services, and private ranges — and followed redirects blindly. Now it
|
|
29
|
+
**refuses private/loopback/link-local/CGNAT targets** (resolving the hostname first), **re-checks on every
|
|
30
|
+
redirect hop** (manual redirects), and reads the body under a **byte ceiling** (no multi-GB / bomb body).
|
|
31
|
+
- **`computer` "don't ask again" defeated the per-action grant (high).** Screen control is supposed to
|
|
32
|
+
confirm every action; the shared "always" approval silently auto-approved all future clicks/types. Now
|
|
33
|
+
`computer` is **never** satisfied by a prior "always" — it always prompts.
|
|
34
|
+
- **Key blocklist bypassable (high).** It only caught spelled-out combos, so Windows SendKeys `%{F4}`/`^w`
|
|
35
|
+
and Linux `XF86LogOff`/`XF86PowerOff` slipped through. Now caught on all three platforms (bare editing
|
|
36
|
+
keys like Delete stay allowed).
|
|
37
|
+
- **Secrets could be embedded into the semantic index (medium).** The asset/skill/memory dirs aren't
|
|
38
|
+
`.gitignore`-filtered, so a stray `credentials.json`/`secrets.yaml` there could be POSTed to the embedding
|
|
39
|
+
provider + persisted. Now secret-named files are skipped in both index collectors.
|
|
40
|
+
- **Token/config files were world-readable (medium).** `~/.hara/qwen-oauth.json` (access+refresh tokens)
|
|
41
|
+
and `~/.hara/config.json` (`apiKey`) are now written **0600** (and tightened on save).
|
|
42
|
+
- **RPA app allowlist was substring-matched (low).** `"Notes"` matched `"Notes - Evil"`; now an exact
|
|
43
|
+
(case-insensitive) frontmost-app match.
|
|
44
|
+
|
|
45
|
+
The RPA + clipboard shell-outs were confirmed injection-safe (argv arrays, JSON-quoted scripts). 198 tests
|
|
46
|
+
(2 new: the SSRF private-IP guard + the widened key blocklist).
|
|
47
|
+
|
|
48
|
+
## 0.61.1 — unreleased (security + correctness hardening — core audit)
|
|
49
|
+
|
|
50
|
+
A security/correctness audit of the core (sandbox, confirmation gate, file tools, MCP client) found real
|
|
51
|
+
issues; fixed:
|
|
52
|
+
- **Confirmation-gate bypass via sub-agents (critical).** The read-kind `agent` tool never prompts, yet
|
|
53
|
+
spawned sub-agents ran **full-auto, unconfirmed** — so a role granting `edit_file`/`bash` let a fan-out
|
|
54
|
+
sub-agent mutate files / run shell with no approval, even in `suggest` mode. Sub-agents are now **always
|
|
55
|
+
read-only** (a role may narrow further but can never grant write/exec — `subagentToolFilter`). Write-capable
|
|
56
|
+
roles run in the main loop via `hara org`, behind the gate.
|
|
57
|
+
- **`apply_patch` wasn't actually atomic (critical / data-loss).** It claimed all-or-nothing but Phase 2 wrote
|
|
58
|
+
files sequentially — a mid-way failure left a half-patched tree with no undo. Now it **rolls back** every
|
|
59
|
+
applied write on any failure (restores updated/deleted, removes created), so it's truly all-or-nothing.
|
|
60
|
+
- **Sandbox honesty.** It's **file-write confinement only** (not reads/network/exec; `/private/tmp` stays
|
|
61
|
+
writable) — clarified in the header, `--sandbox` docs, and label so it no longer oversells containment.
|
|
62
|
+
- The non-macOS "runs unsandboxed" warning now fires from `runShell` (every entry point: `-p`, org, cron),
|
|
63
|
+
not just the REPL; a runaway `bash` whose output exceeds `maxBuffer` is now **killed** (not streamed to
|
|
64
|
+
the timeout); and `hara plugin add` now **shows the commands a plugin will run** on every launch (its MCP
|
|
65
|
+
servers + hooks are arbitrary code — surface the trust surface).
|
|
66
|
+
|
|
67
|
+
196 tests (2 new: the sub-agent read-only guard + the apply_patch rollback). The edit tools, hooks matcher,
|
|
68
|
+
and sandbox profile-injection safety were audited and confirmed solid.
|
|
69
|
+
|
|
70
|
+
## 0.61.0 — unreleased (`hara memory` — inspect + distill durable memory)
|
|
71
|
+
|
|
72
|
+
- New **`hara memory`** command group, giving memory a CLI surface it lacked:
|
|
73
|
+
- **`hara memory show`** — print the digest injected at session start (what the agent actually sees).
|
|
74
|
+
- **`hara memory init`** — scaffold the global + project memory dirs/seed files.
|
|
75
|
+
- **`hara memory distill [--days N] [--scope global|project|all]`** — **promote short-term → long-term**:
|
|
76
|
+
consolidate recent daily logs (`log/YYYY-MM-DD.md`) into durable `MEMORY.md`/`USER.md`, deduped against
|
|
77
|
+
what's already there, skipping the ephemeral. This closes the one tiering gap the PAI/hermes study
|
|
78
|
+
surfaced (the daily-log tier was previously write-only). The agent routes each fact to the right
|
|
79
|
+
target/scope (user pref → `USER.md`, project fact → project memory). Verified live with glm-5.
|
|
80
|
+
- `.hara/` is now gitignored in this repo so dogfooding doesn't leave runtime state (memory/roles/plans).
|
|
81
|
+
|
|
82
|
+
## 0.60.2 — unreleased (memory digest: per-source budgets)
|
|
83
|
+
|
|
84
|
+
- After studying the PAI and hermes memory systems (both lexical-first; both treat vectors as an *optional*
|
|
85
|
+
optimization, not a requirement — which validates hara's design), tightened the frozen-snapshot digest:
|
|
86
|
+
the old `slice(0, 4000)` on the **concatenated** sources could cut an entry mid-line and let a large
|
|
87
|
+
project `MEMORY.md` **crowd `USER.md` out entirely**. Each source (project MEMORY / global MEMORY / USER)
|
|
88
|
+
now gets its **own** budget and is truncated at a **line boundary**, so high-value user prefs are always
|
|
89
|
+
injected and no entry is split. The rest stays reachable via `memory_search` (which is already hybrid
|
|
90
|
+
lexical + opt-in semantic). No behavior change when memory is small.
|
|
91
|
+
|
|
92
|
+
## 0.60.1 — unreleased (cron hardening — from a code-review pass)
|
|
93
|
+
|
|
94
|
+
A review of the fast-built `hara cron` module surfaced real bugs; fixed:
|
|
95
|
+
- **Malformed cron expressions were silently accepted** (`Number("")===0` etc.) — `"0 9 * * 1,"`, `"/5 * * * *"`, `"5/"` parsed as valid jobs that fire at the wrong time. Now strictly validated and rejected; `N/step` correctly extends to max (Vixie semantics).
|
|
96
|
+
- **`hara cron install` could emit a broken plist/crontab** when a path contained `&`/`<`/`>` (launchd XML) or a space/metacharacter (crontab shell line). Now XML-escaped / shell-quoted, and an install is refused if a path contains a newline.
|
|
97
|
+
- **Per-job logs grew unbounded** — capped to the last ~256KB once over ~1MB.
|
|
98
|
+
- **The tick lock could poison the scheduler for 30 min after a crash, or double-fire a long job** — now keyed on PID liveness (a dead owner is taken over within one tick; a live owner is respected for long runs).
|
|
99
|
+
- **An ambiguous id-prefix silently deleted/toggled the *first* match** — `cron remove/enable/disable/run/logs` now error on an ambiguous prefix instead of guessing.
|
|
100
|
+
|
|
101
|
+
The vim reducer, type-ahead steering, Anthropic message coalescing, the MCP allowlist, and the binary build were reviewed and confirmed clean. 192 tests (4 new hardening cases).
|
|
102
|
+
|
|
103
|
+
## 0.60.0 — unreleased (single-binary distribution)
|
|
104
|
+
|
|
105
|
+
- **Standalone binaries** — hara can now be a single self-contained executable (no Node required):
|
|
106
|
+
`curl -fsSL .../install.sh | sh`. Built with `bun build --compile` (`npm run build:binary`, or
|
|
107
|
+
`build:binaries` to cross-compile darwin-arm64/x64 + linux-x64/arm64 from one machine). A tagged
|
|
108
|
+
release (`.github/workflows/release.yml`) builds + attaches them; `install.sh` grabs the right one.
|
|
109
|
+
- Build fixes for the bundled binary: a Bun plugin **stubs ink's dev-only `react-devtools-core`** (lazy-
|
|
110
|
+
imported under `DEV`, never in production) so it bundles clean; the version is **baked in via a build
|
|
111
|
+
define** (a compiled binary has no `package.json` to read at runtime); and cron's self-reinvoke now
|
|
112
|
+
detects script-vs-binary mode (`selfArgv`) so `hara cron` works from the binary too. The 60 MB binaries
|
|
113
|
+
are kept out of the npm tarball (`!dist/bin`), which stays ~140 kB.
|
|
114
|
+
|
|
115
|
+
## 0.59.0 — unreleased (vim keybindings in the input box)
|
|
116
|
+
|
|
117
|
+
- **Vim mode** (opt-in: `hara config set vimMode true`, or `HARA_VIM=1`). The TUI prompt becomes modal —
|
|
118
|
+
**Esc** → normal, **i/a/I/A/o** → insert. Normal-mode motions `h l 0 $ w b e` (+ `gg`/`G`), edits
|
|
119
|
+
`x D C dd cc dw cw`, and paste `p`/`P` with a delete/yank register. A distinct prompt marker (`◆` yellow)
|
|
120
|
+
+ a `-- NORMAL -- / -- INSERT --` hint show the mode. Off by default (normal typing is unchanged). The
|
|
121
|
+
editing logic is a pure reducer (`src/tui/vim.ts`), fully unit-tested; `hara doctor` shows the input mode.
|
|
122
|
+
|
|
123
|
+
## 0.58.0 — unreleased (`hara cron` — scheduled tasks)
|
|
124
|
+
|
|
125
|
+
- **Scheduled tasks.** `hara cron add "<schedule>" "<task>"` runs a task on a schedule — the fired job is a
|
|
126
|
+
fresh `hara` session (the run *is* the agent, like openclaw/hermes). Schedules: a 5-field **cron expr**
|
|
127
|
+
(`"0 9 * * 1-5"`), an **interval** (`"every 30m"`), or a **one-shot** (`"in 2h"` / an ISO timestamp).
|
|
128
|
+
`--org` routes it through the role org instead of a plain prompt.
|
|
129
|
+
- **Fires via your OS, no daemon to babysit.** `hara cron install` registers a per-minute `hara cron tick`
|
|
130
|
+
with **launchd** (macOS) or **crontab** (Linux); `tick` runs whatever's due (lock-guarded so a slow job
|
|
131
|
+
doesn't double-fire) and logs each run. Manage with `hara cron list / run <id> / enable / disable /
|
|
132
|
+
remove / logs / uninstall`. Jobs persist atomically in `~/.hara/cron/jobs.json`; `hara doctor` shows the
|
|
133
|
+
count + scheduler status. Cron matching is hand-rolled (no new dependency), minute-granular, local-time.
|
|
134
|
+
|
|
135
|
+
## 0.57.0 — unreleased (in-session `/diff`, `/review`, `/commit` in the TUI)
|
|
136
|
+
|
|
137
|
+
- The default TUI now wires three more slash commands so the **change → review → commit** loop happens
|
|
138
|
+
in-session instead of dropping to a subcommand (they used to print "isn't wired into the TUI yet"):
|
|
139
|
+
- **`/diff`** — show the working-tree diff vs HEAD (`/diff staged` for the index), rendered as a colored diff block. No model call.
|
|
140
|
+
- **`/review`** — a senior-reviewer pass over `git diff HEAD` (read-only), streamed inline.
|
|
141
|
+
- **`/commit`** — stage everything and commit with an AI-written message (reuses the review→commit machinery).
|
|
142
|
+
Reuses existing, already-verified pieces (`autoCommit`, `REVIEW_SYSTEM`, `runShell`). Other subcommands
|
|
143
|
+
(`init`/`index`/`plan`/`org`/…) still point you to `hara <cmd>` or `HARA_TUI=0`.
|
|
144
|
+
|
|
145
|
+
## 0.56.0 — unreleased (review → commit capstone + robust verdict parsing)
|
|
146
|
+
|
|
147
|
+
- **`hara org --review --commit`** closes the loop: once the reviewer approves, hara stages the work and
|
|
148
|
+
commits it with an AI-written message (reusing `hara commit`'s generation). **Guarded** — it only
|
|
149
|
+
auto-commits when the working tree was **clean before the run** (so it captures this run's work, never
|
|
150
|
+
pre-existing WIP), and with `--review` only **after approval** (a review that doesn't pass leaves the
|
|
151
|
+
changes in your tree, uncommitted). `--commit` works without `--review` too (commit the implementer's
|
|
152
|
+
result). Verified live end-to-end: implement → review → approve → `✓ committed`.
|
|
153
|
+
- **Robust verdict parsing** (hardening v0.55, found via live smokes). Real models don't emit the literal
|
|
154
|
+
`VERDICT: APPROVED` token — across runs glm-5 wrote `**VERDICT**: No issues found`, `**VERDICT**: PASS`,
|
|
155
|
+
and `VERDICT: LGTM`. The parser now anchors on a markdown-tolerant `VERDICT` marker and **classifies the
|
|
156
|
+
phrase after it** (approve vs changes synonyms), with a changes-signal veto and an ambiguous-→-not-approved
|
|
157
|
+
safe default (worst case is one extra review round, never a bad auto-commit). `not approved` correctly
|
|
158
|
+
vetoes despite containing "approv". Unit tests now cover the exact shapes seen in live runs.
|
|
159
|
+
|
|
160
|
+
## 0.55.0 — unreleased (multi-role review chain — `hara org --review`)
|
|
161
|
+
|
|
162
|
+
- **Review chains** — `hara org --review "<task>"` runs the org like an actual engineering team: the owning
|
|
163
|
+
role implements, then a **reviewer** role inspects the diff and either **approves** or sends it back with
|
|
164
|
+
concrete fixes, looping implement → review → fix until approved or a round cap (`--rounds`, default 3).
|
|
165
|
+
This is hara's differentiation — not "one agent + temp sub-agents" but roles that hold each other to a
|
|
166
|
+
bar. The reviewer is read-only (uses your `reviewer` role if defined, else a built-in persona) and ends
|
|
167
|
+
with a machine-parseable `VERDICT: APPROVED | CHANGES_REQUESTED`; on changes-requested the issues feed
|
|
168
|
+
back into the implementer's own conversation so it keeps context. New `src/org/review-chain.ts` (verdict
|
|
169
|
+
parsing, non-destructive `git diff HEAD` capture, prompts) — all unit-tested. **Verified live end-to-end**
|
|
170
|
+
(implementer edits a file → reviewer approves → loop exits).
|
|
171
|
+
|
|
172
|
+
## 0.54.0 — unreleased (`hara mcp` — run hara as an MCP server)
|
|
173
|
+
|
|
174
|
+
- **MCP server mode** — `hara mcp` runs hara as an MCP server over stdio, so other MCP clients (Claude
|
|
175
|
+
Desktop, Cursor, another hara…) can call its tools. hara was already an MCP *client*; this completes
|
|
176
|
+
the loop. The high-value one is **`codebase_search`** — point any MCP client at a repo and it gets
|
|
177
|
+
hara's semantic/lexical code search, plus `read_file`/`grep`/`glob`/`ls`/`web_fetch`/`web_search`.
|
|
178
|
+
**Read-only by default** — no `edit_file`/`bash`/`computer`, so an external client can't mutate your
|
|
179
|
+
machine through hara; override the exposed set with `HARA_MCP_TOOLS=a,b,c` at your own risk. Reuses
|
|
180
|
+
hara's tool registry (`src/mcp/server.ts`, built on `@modelcontextprotocol/sdk` — already a dep).
|
|
181
|
+
Verified end-to-end (a real MCP client lists the tools + calls `ls`/`codebase_search`). `hara doctor`
|
|
182
|
+
now shows both the client (servers connected) and serve (tools exposed) sides.
|
|
183
|
+
|
|
184
|
+
```jsonc
|
|
185
|
+
// e.g. in a client's mcpServers config:
|
|
186
|
+
"hara": { "command": "hara", "args": ["mcp"] } // run from the repo you want searchable
|
|
187
|
+
```
|
|
188
|
+
|
|
8
189
|
## 0.53.0 — unreleased (task-done notifications + steering in plan mode)
|
|
9
190
|
|
|
10
191
|
- **Notifications** — get pinged when a turn finishes so you can walk away during a long run
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
**Highlights**
|
|
12
12
|
- **An org, not just an agent** — `hara org "<task>"` routes work to the role that *owns* it; `hara plan "<task>"` decomposes a task into a verified DAG of atoms (frame → atomize → sequence → execute → **verify gate**), and `hara plan --parallel` runs independent atoms concurrently.
|
|
13
13
|
- **Real terminal UX** — an **ink TUI**: bottom-pinned input box, **plan mode** (read-only → propose a plan → approve → execute), selectable approvals with "don't ask again", windowed reasoning, **paste images** (Ctrl+V) for vision models, light/dark theme.
|
|
14
|
-
- **Persistent memory + self-evolution** — `memory_*` tools over global/project `MEMORY.md`; the agent recalls before acting, **proactively saves** durable facts, and grows its own playbooks (a lexical guard screens what it writes).
|
|
14
|
+
- **Persistent memory + self-evolution** — `memory_*` tools over global/project `MEMORY.md`; the agent recalls before acting, **proactively saves** durable facts, and grows its own playbooks (a lexical guard screens what it writes). Inspect/consolidate it with **`hara memory show`** and **`hara memory distill`** (promote recent daily logs → durable memory). Lexical-first by design — semantic search is opt-in, never required.
|
|
15
15
|
- **Multi-provider, all streamed** — Anthropic (Claude) or any OpenAI-compatible endpoint (Qwen/DashScope, GLM, Kimi, OpenAI) with live Markdown + visible reasoning.
|
|
16
16
|
- **Solid coding core** — `edit_file` / `apply_patch` (atomic multi-file) with colored diffs · `grep`/`glob`/`ls`/`codebase_search` (lexical + optional semantic search over the repo) /`web_fetch` · fuzzy `@file` · `/undo` · `/compact` · **Esc-to-interrupt** · parallel sub-agents · MCP client · macOS sandbox.
|
|
17
17
|
|
|
@@ -23,6 +23,14 @@ Track it: https://github.com/hara-cli/hara · https://hara.run
|
|
|
23
23
|
npm i -g @nanhara/hara
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
Or a **standalone binary** (no Node required):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
curl -fsSL https://raw.githubusercontent.com/hara-cli/hara/main/install.sh | sh
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Tab completion (optional): `eval "$(hara completions zsh)"` in your `~/.zshrc` (or `bash`/`fish`).
|
|
33
|
+
|
|
26
34
|
Or from source:
|
|
27
35
|
|
|
28
36
|
```bash
|
|
@@ -171,14 +179,16 @@ vector DB needed, and lexical still works when there's no index. Re-running `har
|
|
|
171
179
|
only changed files re-embed (a full repo rebuild that takes ~a minute re-runs in well under a second).
|
|
172
180
|
|
|
173
181
|
**Approval modes**: `suggest` confirms edits & shell · `auto-edit` auto-applies file edits but confirms shell · `full-auto` runs everything.
|
|
174
|
-
**Sandbox** (macOS): `--sandbox workspace-write|read-only` runs the `bash` tool under Seatbelt (writes confined to the project / blocked).
|
|
182
|
+
**Sandbox** (macOS): `--sandbox workspace-write|read-only` runs the `bash` tool under Seatbelt — **file-write confinement** (writes confined to the project / blocked). It does not restrict reads, network, or process exec; on non-macOS the shell runs unsandboxed (with a warning).
|
|
175
183
|
**Screen control** (opt-in): the `computer` tool drives desktop software (screenshot → click/type), native per OS
|
|
176
184
|
(mac `screencapture`+`cliclick` · Windows PowerShell · Linux `scrot`+`xdotool`). Off by default — enable a tier with
|
|
177
185
|
`hara config set computerUse read|click|full` and allowlist apps with `hara config set computerApps "App, …"`. Guarded
|
|
178
186
|
by the tier, the frontmost-app allowlist, a dangerous-key blocklist, and a once-per-session grant. Screenshots are read via your
|
|
179
187
|
vision model into **actionable** output — interactive elements + positions (pass `focus` to target what you're after) — so even a text-only main model can click.
|
|
180
188
|
**Sessions**: conversations are saved automatically — `-c` / `--resume <id>` to continue, `hara sessions` to list.
|
|
181
|
-
**MCP**: add an `mcpServers` map to config (global or project `.hara/config.json`); their tools appear to the agent as `mcp__<server>__<tool>`.
|
|
189
|
+
**MCP**: add an `mcpServers` map to config (global or project `.hara/config.json`); their tools appear to the agent as `mcp__<server>__<tool>`. hara can also **be** an MCP server — `hara mcp` exposes its read/search tools (esp. **`codebase_search`**) over stdio so other clients (Claude Desktop, Cursor, another hara) can use them; read-only by default (`HARA_MCP_TOOLS` to override).
|
|
190
|
+
**Vim mode**: `hara config set vimMode true` makes the prompt modal — Esc → normal, `i/a/A/I` insert, `h l 0 $ w b e` motions, `x D C dd cw p` edits. Off by default.
|
|
191
|
+
**Scheduled tasks**: `hara cron add "0 9 * * 1-5" "<task>"` (or `"every 30m"`, `"in 2h"`) runs a task on a schedule — each run is a fresh hara session. `hara cron install` wires a per-minute tick into launchd/crontab (no daemon); `--org` routes through the role org. Manage with `hara cron list/run/enable/disable/remove/logs`.
|
|
182
192
|
**Notifications**: `hara config set notify bell` (terminal bell) or `notify system` (OS notification) pings you when a turn finishes — handy for long runs you've stepped away from. Gated on elapsed time so quick turns stay quiet; off by default.
|
|
183
193
|
**Hooks**: run your own shell commands around tool calls via a `"hooks"` map in config. A **`PreToolUse`** hook can **veto** a call (non-zero exit blocks it; its output becomes the reason the model sees) — gate `bash`, forbid edits outside a path, require a clean tree. A **`PostToolUse`** hook observes (format/lint a file the agent just wrote, log, notify). Each has a `matcher` (regex/literal on the tool name, `*` = all) and gets `{tool, payload}` on stdin + `HARA_TOOL_NAME` in env. Plugins can contribute hooks too.
|
|
184
194
|
**Profiles**: add a `profiles` map to `~/.hara/config.json` (`--profile <name>`), or drop a project-level `.hara/config.json` that overrides the global config.
|
|
@@ -189,7 +199,11 @@ Define role-agents in `.hara/roles/*.md` — each is a persona (the file body) p
|
|
|
189
199
|
(keywords that route a task here), optional `rejects`, `model`, and `allowTools`/`denyTools`. `hara org
|
|
190
200
|
"<task>"` routes the task to the role that **owns** it (keyword match, LLM fallback) and runs that role's
|
|
191
201
|
agent — e.g. a read-only `reviewer` that reports issues vs an `implementer` that edits code. `hara roles`
|
|
192
|
-
lists them, `hara roles init` scaffolds a starter set, and `--role <id>` forces a specific role.
|
|
202
|
+
lists them, `hara roles init` scaffolds a starter set, and `--role <id>` forces a specific role. Add
|
|
203
|
+
**`--review`** and the org works like a team: the owning role implements, then a **reviewer** role inspects
|
|
204
|
+
the diff and either approves or sends it back with fixes — looping implement → review → fix until approved
|
|
205
|
+
(or `--rounds N`). Add **`--commit`** and it commits the approved result with an AI-written message (guarded
|
|
206
|
+
to a clean start tree; a review that doesn't pass leaves the work uncommitted). The
|
|
193
207
|
**`agent`** tool spawns **parallel read-only sub-agents** for fan-out — analyze / review / search
|
|
194
208
|
several things at once (each can take a `role`).
|
|
195
209
|
|
|
@@ -209,7 +223,7 @@ A streaming agentic loop with built-in tools — `read_file`, `write_file`, **`e
|
|
|
209
223
|
read-only **`grep`** / **`glob`** / **`ls`** / **`web_fetch`** — behind a human-in-the-loop confirmation gate on the
|
|
210
224
|
dangerous ones unless `-y`. Read-only tools run in parallel within a turn, and edits print a
|
|
211
225
|
**colored diff** of what changed. Shell output streams live; press **Esc** to interrupt a running
|
|
212
|
-
turn, or **`/undo`** to revert the last edit.
|
|
226
|
+
turn, or **`/undo`** to revert the last edit. In-session **`/diff`**, **`/review`**, and **`/commit`** close the change → review → commit loop without leaving the prompt.
|
|
213
227
|
- **Type-ahead steering**: keep typing while hara works — your message is held, then **folded into the next model call** (not deferred to a new turn), so a clarification or "also do X" course-corrects the task already in flight (codex-style). Messages typed after the final step start a fresh turn; **Esc** drops the queue and stops.
|
|
214
228
|
- **Project context**: auto-loads `AGENTS.md` (the cross-tool standard) walking up to the repo root; `hara init` writes one by analyzing the repo.
|
|
215
229
|
- **`@file` mentions**: attach file contents to a message (`@path`); Tab-completes with a **fuzzy** matcher over the project (subdirs, git-tracked + untracked) — `@idx` → `src/index.ts`. `@<dir>` loads a directory listing, `@src/`+Tab drills into a folder, and mistyped tool/file paths get a "did you mean" suggestion.
|
|
@@ -217,8 +231,12 @@ turn, or **`/undo`** to revert the last edit.
|
|
|
217
231
|
|
|
218
232
|
### Roadmap
|
|
219
233
|
|
|
220
|
-
**Shipped:** ink TUI · plan mode · persistent memory + self-evolution · atomization planner · parallel sub-agents · `/compact` context management.
|
|
221
|
-
**Next:**
|
|
234
|
+
**Shipped:** ink TUI · plan mode · persistent memory + self-evolution · atomization planner · parallel plan atoms · **multi-role review chains** · parallel sub-agents · MCP client *and* server · **scheduled tasks (`hara cron`)** · **single-binary distribution** · `/compact` context management.
|
|
235
|
+
**Next:** SSOT data authority · an enterprise control-plane (fleet + central token management).
|
|
236
|
+
|
|
237
|
+
## Security
|
|
238
|
+
|
|
239
|
+
Human-in-the-loop by default, with a layered model (approval gate · read-only sub-agents · write-confinement sandbox · `web_fetch` SSRF guard · `0600` secrets · reviewed plugin trust). Threat model, controls, and how to report a vulnerability: **[SECURITY.md](SECURITY.md)**.
|
|
222
240
|
|
|
223
241
|
## License
|
|
224
242
|
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
hara is a coding agent that reads/writes files, runs shell commands, drives a browser/desktop, and calls
|
|
4
|
+
LLMs — so it takes a layered, **human-in-the-loop-by-default** stance. This documents the threat model, the
|
|
5
|
+
controls, what is deliberately *not* a security boundary, and how to report a vulnerability.
|
|
6
|
+
|
|
7
|
+
## Threat model
|
|
8
|
+
|
|
9
|
+
hara runs on **your** machine under **your** account, on code **you** point it at. It is not a multi-tenant
|
|
10
|
+
sandbox. The adversary we defend against is primarily **the model going wrong** — a bad suggestion, a
|
|
11
|
+
prompt-injected web page or file steering it toward a destructive or exfiltrating action — not a malicious
|
|
12
|
+
local user (who already has your shell).
|
|
13
|
+
|
|
14
|
+
## Controls
|
|
15
|
+
|
|
16
|
+
- **Approval gate.** Every file edit, shell command, and screen action is classified (`read` / `edit` /
|
|
17
|
+
`exec` / `computer`) and gated by an approval mode: `suggest` (confirm edits & commands), `auto-edit`
|
|
18
|
+
(auto-apply edits, confirm commands), `full-auto` (no prompts — opt-in). Read-only tools never prompt.
|
|
19
|
+
- **Screen control is gated on *every* action.** The `computer` tool always asks before each click/type,
|
|
20
|
+
even in `full-auto`, and "don't ask again" never applies to it. Guarded further by a frontmost-app
|
|
21
|
+
**allowlist** (exact match), a dangerous-key **blocklist** (quit/close/logout across macOS/Windows/Linux
|
|
22
|
+
syntaxes), and a per-session grant. Off by default.
|
|
23
|
+
- **Sub-agents are read-only.** The parallel `agent` fan-out tool runs sub-agents that can never edit or run
|
|
24
|
+
shell — a role may *narrow* their tools but never *grant* write/exec. Write-capable roles run in the main
|
|
25
|
+
loop (`hara org`), behind the gate.
|
|
26
|
+
- **Shell sandbox (macOS).** `--sandbox workspace-write|read-only` runs the `bash` tool under Seatbelt —
|
|
27
|
+
**file-write confinement** (see the non-boundary note below). Commands/paths are passed as argv / a profile
|
|
28
|
+
file, not interpolated into a shell string.
|
|
29
|
+
- **`web_fetch` SSRF guard.** Refuses to fetch private / loopback / link-local / CGNAT addresses (resolving
|
|
30
|
+
the hostname first), re-checks on every redirect hop, and reads the body under a byte ceiling — so the
|
|
31
|
+
model can't reach cloud-metadata endpoints or internal services.
|
|
32
|
+
- **Secrets.** `~/.hara/config.json` (API keys) and `~/.hara/qwen-oauth.json` (tokens) are written `0600`.
|
|
33
|
+
The optional semantic index respects `.gitignore` and skips secret-named files, so keys aren't embedded or
|
|
34
|
+
sent to an embedding provider. The memory guard screens secret-shaped strings out of what the agent saves.
|
|
35
|
+
- **Plugins are code you trust.** Installing a plugin (`hara plugin add`) grants its author code execution:
|
|
36
|
+
its MCP servers and hooks run shell commands on launch. `hara plugin add` **prints the exact commands** a
|
|
37
|
+
plugin will run so you can review them; disable with `hara plugin disable <name>`.
|
|
38
|
+
- **Coding-plan keys.** Provider keys you configure are used only to call the model endpoint you set.
|
|
39
|
+
|
|
40
|
+
## What is *not* a security boundary
|
|
41
|
+
|
|
42
|
+
- **The sandbox confines file writes only** — not reads, not network, not process exec; `/private/tmp`
|
|
43
|
+
stays writable. It stops a stray `rm`/overwrite escaping the project, not a determined exfiltration. Treat
|
|
44
|
+
a `full-auto` + network-capable shell as able to read and send anything your account can.
|
|
45
|
+
- **`@file` mentions** read any file *you* name (including outside the project) — that's you attaching
|
|
46
|
+
context, not the model exfiltrating; mentions are expanded on your typed input only, never on model output.
|
|
47
|
+
- **`full-auto` / `-y`** removes the human gate by your explicit choice. Use it on code and in directories
|
|
48
|
+
you trust.
|
|
49
|
+
|
|
50
|
+
## Reporting a vulnerability
|
|
51
|
+
|
|
52
|
+
Please report security issues privately — open a GitHub **security advisory** on `hara-cli/hara`, or email
|
|
53
|
+
the maintainers — rather than a public issue. Include a minimal reproduction and the impact. We'll
|
|
54
|
+
acknowledge, fix, and credit you.
|
package/dist/agent/loop.js
CHANGED
|
@@ -136,14 +136,16 @@ export async function runAgent(history, opts) {
|
|
|
136
136
|
const preview = String(input.path ?? input.command ?? input.pattern ?? input.url ?? input.task ?? "")
|
|
137
137
|
.replace(/\s+/g, " ")
|
|
138
138
|
.trim();
|
|
139
|
-
|
|
139
|
+
// Screen control is gated on EVERY action — a prior "don't ask again" must never satisfy it.
|
|
140
|
+
const alwaysGate = tool.kind === "computer";
|
|
141
|
+
if (needsConfirm(tool.kind, opts.approval) && (alwaysGate || !opts.autoApprove?.has(tu.name))) {
|
|
140
142
|
const reply = await opts.confirm(`${c.yellow("⚠")} ${c.bold(tu.name)} ${c.dim(preview)} — run?`);
|
|
141
143
|
if (reply === false) {
|
|
142
144
|
plans.push({ tu, tool, denied: "User denied this action." });
|
|
143
145
|
continue;
|
|
144
146
|
}
|
|
145
|
-
if (reply === "always")
|
|
146
|
-
opts.autoApprove?.add(tu.name);
|
|
147
|
+
if (reply === "always" && !alwaysGate)
|
|
148
|
+
opts.autoApprove?.add(tu.name); // computer: treat "always" as one-time yes
|
|
147
149
|
}
|
|
148
150
|
plans.push({ tu, tool });
|
|
149
151
|
if (!opts.quiet) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Shell completion scripts (bash / zsh / fish), generated from the command tree so they never drift.
|
|
2
|
+
// `hara completions <shell>` prints one; the user evals it in their shell rc. Completes the top-level
|
|
3
|
+
// subcommands, the subcommands of each group (cron/memory/plugin/roles/skills/config), and falls back to
|
|
4
|
+
// file completion otherwise. Hand-rolled (no dependency) — same minimal-deps philosophy as the rest.
|
|
5
|
+
const bash = ({ top, subs }) => {
|
|
6
|
+
const cases = Object.entries(subs)
|
|
7
|
+
.map(([cmd, sub]) => ` ${cmd}) COMPREPLY=( $(compgen -W "${sub.join(" ")}" -- "$cur") ); return;;`)
|
|
8
|
+
.join("\n");
|
|
9
|
+
return `# hara bash completion — add to ~/.bashrc: eval "$(hara completions bash)"
|
|
10
|
+
_hara() {
|
|
11
|
+
local cur prev; cur="\${COMP_WORDS[COMP_CWORD]}"; prev="\${COMP_WORDS[1]}"
|
|
12
|
+
if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "${top.join(" ")}" -- "$cur") ); return; fi
|
|
13
|
+
case "$prev" in
|
|
14
|
+
${cases}
|
|
15
|
+
*) COMPREPLY=( $(compgen -f -- "$cur") );;
|
|
16
|
+
esac
|
|
17
|
+
}
|
|
18
|
+
complete -F _hara hara
|
|
19
|
+
`;
|
|
20
|
+
};
|
|
21
|
+
const zsh = ({ top, subs }) => {
|
|
22
|
+
const cases = Object.entries(subs)
|
|
23
|
+
.map(([cmd, sub]) => ` ${cmd}) compadd -- ${sub.join(" ")} ;;`)
|
|
24
|
+
.join("\n");
|
|
25
|
+
return `# hara zsh completion — add to ~/.zshrc: eval "$(hara completions zsh)"
|
|
26
|
+
_hara() {
|
|
27
|
+
if (( CURRENT == 2 )); then compadd -- ${top.join(" ")}; return; fi
|
|
28
|
+
case "\${words[2]}" in
|
|
29
|
+
${cases}
|
|
30
|
+
*) _files ;;
|
|
31
|
+
esac
|
|
32
|
+
}
|
|
33
|
+
compdef _hara hara
|
|
34
|
+
`;
|
|
35
|
+
};
|
|
36
|
+
const fish = ({ top, subs }) => {
|
|
37
|
+
const lines = [
|
|
38
|
+
"# hara fish completion — save to ~/.config/fish/completions/hara.fish: hara completions fish > ~/.config/fish/completions/hara.fish",
|
|
39
|
+
"complete -c hara -f",
|
|
40
|
+
`complete -c hara -n __fish_use_subcommand -a "${top.join(" ")}"`,
|
|
41
|
+
...Object.entries(subs).map(([cmd, sub]) => `complete -c hara -n "__fish_seen_subcommand_from ${cmd}" -a "${sub.join(" ")}"`),
|
|
42
|
+
];
|
|
43
|
+
return lines.join("\n") + "\n";
|
|
44
|
+
};
|
|
45
|
+
/** Render the completion script for a shell, or null if the shell isn't supported. */
|
|
46
|
+
export function completionScript(shell, tree) {
|
|
47
|
+
const gen = { bash, zsh, fish };
|
|
48
|
+
return gen[shell] ? gen[shell](tree) : null;
|
|
49
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { join, dirname, resolve } from "node:path";
|
|
3
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, chmodSync } from "node:fs";
|
|
4
4
|
const PROVIDER_DEFAULTS = {
|
|
5
5
|
anthropic: { model: "claude-opus-4-8", envKey: "ANTHROPIC_API_KEY" },
|
|
6
6
|
qwen: {
|
|
@@ -11,7 +11,7 @@ const PROVIDER_DEFAULTS = {
|
|
|
11
11
|
"qwen-oauth": { model: "coder-model", envKey: "QWEN_OAUTH_TOKEN" },
|
|
12
12
|
openai: { model: "gpt-4o-mini", envKey: "OPENAI_API_KEY" },
|
|
13
13
|
};
|
|
14
|
-
export const CONFIG_KEYS = ["provider", "apiKey", "model", "baseURL", "approval", "sandbox", "theme", "evolve", "assetCapture", "computerUse", "computerApps", "visionModel", "visionBaseURL", "visionApiKey", "embedProvider", "embedModel", "embedBaseURL", "embedApiKey", "notify"];
|
|
14
|
+
export const CONFIG_KEYS = ["provider", "apiKey", "model", "baseURL", "approval", "sandbox", "theme", "evolve", "assetCapture", "computerUse", "computerApps", "visionModel", "visionBaseURL", "visionApiKey", "embedProvider", "embedModel", "embedBaseURL", "embedApiKey", "notify", "vimMode"];
|
|
15
15
|
export const APPROVAL_MODES = ["suggest", "auto-edit", "full-auto"];
|
|
16
16
|
export const SANDBOX_MODES = ["off", "workspace-write", "read-only"];
|
|
17
17
|
const PROJECT_ROOT_MARKERS = [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".hg"];
|
|
@@ -51,12 +51,22 @@ function readProjectConfig(cwd) {
|
|
|
51
51
|
}
|
|
52
52
|
return {};
|
|
53
53
|
}
|
|
54
|
+
/** Write the config 0600 (it can hold `apiKey`) + tighten an existing file. */
|
|
55
|
+
function persistConfig(p, cfg) {
|
|
56
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
57
|
+
writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
58
|
+
try {
|
|
59
|
+
chmodSync(p, 0o600);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* best-effort */
|
|
63
|
+
}
|
|
64
|
+
}
|
|
54
65
|
export function writeConfigValue(key, value) {
|
|
55
66
|
const p = configPath();
|
|
56
67
|
const cfg = readRawConfig();
|
|
57
68
|
cfg[key] = value;
|
|
58
|
-
|
|
59
|
-
writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n", "utf8");
|
|
69
|
+
persistConfig(p, cfg);
|
|
60
70
|
}
|
|
61
71
|
/** Record (or clear, with cap=null) a confirmed per-model vision capability in `modelVision`. */
|
|
62
72
|
export function setModelVisionOverride(model, cap) {
|
|
@@ -68,8 +78,7 @@ export function setModelVisionOverride(model, cap) {
|
|
|
68
78
|
else
|
|
69
79
|
map[model] = cap;
|
|
70
80
|
cfg.modelVision = map;
|
|
71
|
-
|
|
72
|
-
writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n", "utf8");
|
|
81
|
+
persistConfig(p, cfg);
|
|
73
82
|
}
|
|
74
83
|
/**
|
|
75
84
|
* Effective config. Precedence (high→low): env vars > selected profile >
|
|
@@ -109,7 +118,8 @@ export function loadConfig(opts = {}) {
|
|
|
109
118
|
};
|
|
110
119
|
const hooks = (merged.hooks && typeof merged.hooks === "object" ? merged.hooks : {});
|
|
111
120
|
const notify = (process.env.HARA_NOTIFY ?? merged.notify ?? "off");
|
|
112
|
-
|
|
121
|
+
const vimMode = process.env.HARA_VIM === "1" || merged.vimMode === true || merged.vimMode === "true";
|
|
122
|
+
return { provider, apiKey, model, baseURL, approval, sandbox, theme, evolve, assetCapture, computerUse, computerApps, visionModel, visionBaseURL, visionApiKey, modelVision, embedProvider, embedModel, embedBaseURL, embedApiKey, hooks, notify, vimMode, mcpServers, cwd: process.cwd() };
|
|
113
123
|
}
|
|
114
124
|
export function providerEnvKey(provider) {
|
|
115
125
|
return (PROVIDER_DEFAULTS[provider] ?? PROVIDER_DEFAULTS.anthropic).envKey;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Register `hara cron tick` with the OS scheduler so jobs fire without a hara daemon running:
|
|
2
|
+
// launchd (macOS, every 60s) or crontab (Linux, every minute). Survives reboots; nothing to babysit.
|
|
3
|
+
import { platform, homedir } from "node:os";
|
|
4
|
+
import { join, dirname } from "node:path";
|
|
5
|
+
import { writeFileSync, existsSync, rmSync, mkdirSync } from "node:fs";
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
const LABEL = "net.nanhara.hara.cron";
|
|
8
|
+
const CRON_TAG = "# hara-cron";
|
|
9
|
+
const xmlEscape = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
10
|
+
const shQuote = (s) => `'${s.replace(/'/g, `'\\''`)}'`; // safe single-quote for /bin/sh
|
|
11
|
+
const plistFile = () => join(homedir(), "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
12
|
+
function currentCrontab() {
|
|
13
|
+
try {
|
|
14
|
+
return execFileSync("crontab", ["-l"], { encoding: "utf8" });
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return ""; // no crontab yet
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function isInstalled() {
|
|
21
|
+
const os = platform();
|
|
22
|
+
if (os === "darwin")
|
|
23
|
+
return existsSync(plistFile());
|
|
24
|
+
if (os === "linux")
|
|
25
|
+
return currentCrontab().includes(CRON_TAG);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
/** Install the per-minute tick. `cmd` = how to invoke hara (e.g. `["node","/x/index.js"]` or the single
|
|
29
|
+
* binary `["/usr/local/bin/hara"]`); `cron tick` is appended. */
|
|
30
|
+
export function installScheduler(cmd) {
|
|
31
|
+
const os = platform();
|
|
32
|
+
const argv = [...cmd, "cron", "tick"];
|
|
33
|
+
if (argv.some((a) => a.includes("\n")))
|
|
34
|
+
return { ok: false, msg: "refusing to install — a path contains a newline" };
|
|
35
|
+
if (os === "darwin") {
|
|
36
|
+
const p = plistFile();
|
|
37
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
38
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
39
|
+
<plist version="1.0"><dict>
|
|
40
|
+
<key>Label</key><string>${LABEL}</string>
|
|
41
|
+
<key>ProgramArguments</key><array>${argv.map((a) => `<string>${xmlEscape(a)}</string>`).join("")}</array>
|
|
42
|
+
<key>StartInterval</key><integer>60</integer>
|
|
43
|
+
<key>RunAtLoad</key><false/>
|
|
44
|
+
</dict></plist>
|
|
45
|
+
`;
|
|
46
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
47
|
+
writeFileSync(p, plist, "utf8");
|
|
48
|
+
try {
|
|
49
|
+
execFileSync("launchctl", ["unload", p], { stdio: "ignore" });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
/* not loaded yet */
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
execFileSync("launchctl", ["load", p], { stdio: "ignore" });
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return { ok: false, msg: `wrote ${p} but launchctl load failed (${e instanceof Error ? e.message : e})` };
|
|
59
|
+
}
|
|
60
|
+
return { ok: true, msg: `launchd agent installed (${p}) — runs every 60s` };
|
|
61
|
+
}
|
|
62
|
+
if (os === "linux") {
|
|
63
|
+
const kept = currentCrontab()
|
|
64
|
+
.split("\n")
|
|
65
|
+
.filter((l) => !l.includes(CRON_TAG))
|
|
66
|
+
.join("\n")
|
|
67
|
+
.replace(/\n+$/, "");
|
|
68
|
+
const line = `* * * * * ${argv.map(shQuote).join(" ")} >/dev/null 2>&1 ${CRON_TAG}`;
|
|
69
|
+
const next = (kept ? kept + "\n" : "") + line + "\n";
|
|
70
|
+
try {
|
|
71
|
+
execFileSync("crontab", ["-"], { input: next });
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return { ok: false, msg: `crontab update failed (${e instanceof Error ? e.message : e})` };
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, msg: "crontab entry installed — runs every minute" };
|
|
77
|
+
}
|
|
78
|
+
return { ok: false, msg: `auto-install unsupported on ${os} — run \`hara cron tick\` from your own scheduler every minute` };
|
|
79
|
+
}
|
|
80
|
+
export function uninstallScheduler() {
|
|
81
|
+
const os = platform();
|
|
82
|
+
if (os === "darwin") {
|
|
83
|
+
const p = plistFile();
|
|
84
|
+
if (!existsSync(p))
|
|
85
|
+
return { ok: true, msg: "not installed" };
|
|
86
|
+
try {
|
|
87
|
+
execFileSync("launchctl", ["unload", p], { stdio: "ignore" });
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
/* ignore */
|
|
91
|
+
}
|
|
92
|
+
rmSync(p, { force: true });
|
|
93
|
+
return { ok: true, msg: "launchd agent removed" };
|
|
94
|
+
}
|
|
95
|
+
if (os === "linux") {
|
|
96
|
+
if (!currentCrontab().includes(CRON_TAG))
|
|
97
|
+
return { ok: true, msg: "not installed" };
|
|
98
|
+
const kept = currentCrontab()
|
|
99
|
+
.split("\n")
|
|
100
|
+
.filter((l) => !l.includes(CRON_TAG))
|
|
101
|
+
.join("\n")
|
|
102
|
+
.replace(/\n+$/, "") + "\n";
|
|
103
|
+
try {
|
|
104
|
+
execFileSync("crontab", ["-"], { input: kept });
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
return { ok: false, msg: `crontab update failed (${e instanceof Error ? e.message : e})` };
|
|
108
|
+
}
|
|
109
|
+
return { ok: true, msg: "crontab entry removed" };
|
|
110
|
+
}
|
|
111
|
+
return { ok: false, msg: `not supported on ${platform()}` };
|
|
112
|
+
}
|