@nanhara/hara 0.53.0 → 0.67.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 CHANGED
@@ -5,6 +5,230 @@ 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.67.0 — unreleased (bounded parallel concurrency)
9
+
10
+ - hara already runs work in parallel — fan-out **`agent`** sub-agents, concurrent read-kind tools in a turn,
11
+ and `hara plan --parallel` waves — but with **no cap**: the model spawning 20 `agent` calls in one turn
12
+ started 20 LLM loops at once (provider rate-limits / resource thrash). Now a **bounded pool** (`mapLimit`)
13
+ caps in-flight parallelism to **8** by default (tunable via `HARA_MAX_CONCURRENCY`), matching cc-haha's
14
+ safeguard (it caps at 10). Excess work queues and runs as slots free; ordering + behavior otherwise
15
+ unchanged. Applied to the loop's read/agent batch and the parallel-plan wave.
16
+
17
+ ## 0.66.0 — unreleased (B-end: device enrollment + `hara-gateway` provider)
18
+
19
+ - First slice of the **B-end** (fleets / control plane): `hara enroll <gateway-url> --code <code>` trades a
20
+ one-time code for a scoped, revocable **device token** (stored `0600` in `~/.hara/org.json`) and switches
21
+ hara to the new **`hara-gateway`** provider — an OpenAI-compatible client pointed at your org's gateway.
22
+ **The real provider key never touches the device** (it stays at the gateway). A heartbeat fires on start
23
+ for fleet visibility; `--status` / `--clear` manage it. The device↔gateway protocol (enroll / heartbeat /
24
+ OpenAI-compatible proxy) is documented in `docs/b-end.md` and **verified end-to-end against a stub control
25
+ plane**. The control-plane server (`hara-control`) + the LiteLLM data-plane are the next, separate increment.
26
+
27
+ ## 0.65.0 — unreleased (frontmatter-aware asset recall)
28
+
29
+ - Asset/skill recall (`searchAssets`, behind `hara recall` / `/recall` / skill dedup) now **ranks by the
30
+ asset's declared dimensions** — a query word in the `title` or the frontmatter `tags`/`lang` counts more
31
+ than one buried in the body. The asset format already declared these (the scaffold seeds `tags`/`lang`);
32
+ retrieval now actually uses them. The base relevance score (distinct query words present) is unchanged,
33
+ so the dedup-before-save threshold is unaffected — this only improves *ordering*. (Studied codex + cc-haha:
34
+ both stay lexical + manual-file curation with no semantic search or auto-capture; hara's hybrid lexical+
35
+ opt-in-semantic recall over a unified skills/code-assets/memory corpus is already ahead.)
36
+
37
+ ## 0.64.0 — unreleased (session export)
38
+
39
+ - **`hara export [session] [--out file]`** renders a saved session to a Markdown transcript — the header
40
+ (title/model/cwd/date), each turn (you / hara), tool calls inline, and tool results in collapsible
41
+ `<details>` blocks (capped). Default is the latest session in the current directory. For sharing a
42
+ decision, pasting into a PR, or archiving. Pure renderer (`src/export.ts`), unit-tested.
43
+
44
+ ## 0.63.0 — unreleased (first-run setup wizard)
45
+
46
+ - **`hara setup`** — an interactive wizard (provider → optional base URL → API key → model) that writes
47
+ `~/.hara/config.json` (0600), so a new user doesn't have to know the individual `hara config set` keys.
48
+ It's also **auto-offered** when you start `hara` unconfigured ("Not authenticated — run setup now?")
49
+ instead of just erroring. TTY-only (scripts get a clear pointer to `hara config set`).
50
+
51
+ ## 0.62.0 — unreleased (shell completions)
52
+
53
+ - **`hara completions bash|zsh|fish`** prints a completion script (eval it in your shell rc) that
54
+ tab-completes the top-level subcommands and the subcommands of each group (`cron`, `memory`, `plugin`,
55
+ `roles`, `skills`, `config`), falling back to file completion. Generated from the live command tree so it
56
+ never drifts; hand-rolled (no new dependency).
57
+
58
+ ## 0.61.3 — unreleased (audit follow-through: session robustness + SECURITY.md)
59
+
60
+ - **Corrupt/hand-edited session files no longer crash** `--resume` or `/sessions` (audit M4): `loadSession`
61
+ validates the shape (meta object + history array), `deriveTitle` tolerates a non-string, and `listSessions`
62
+ skips metaless files instead of throwing.
63
+ - New **`SECURITY.md`** — the threat model, the controls (approval gate, read-only sub-agents, write-confinement
64
+ sandbox, `web_fetch` SSRF guard, 0600 secrets, plugin trust), what is deliberately *not* a security boundary,
65
+ and how to report a vulnerability. Captures the posture from the two audit passes.
66
+
67
+ ## 0.61.2 — unreleased (security hardening — second audit: SSRF, RPA, secrets)
68
+
69
+ A second audit (RPA / network / auth / search) found more real issues; fixed:
70
+ - **`web_fetch` SSRF (critical).** It would fetch any host — incl. `169.254.169.254` (cloud metadata),
71
+ `localhost`/`127.0.0.1` internal services, and private ranges — and followed redirects blindly. Now it
72
+ **refuses private/loopback/link-local/CGNAT targets** (resolving the hostname first), **re-checks on every
73
+ redirect hop** (manual redirects), and reads the body under a **byte ceiling** (no multi-GB / bomb body).
74
+ - **`computer` "don't ask again" defeated the per-action grant (high).** Screen control is supposed to
75
+ confirm every action; the shared "always" approval silently auto-approved all future clicks/types. Now
76
+ `computer` is **never** satisfied by a prior "always" — it always prompts.
77
+ - **Key blocklist bypassable (high).** It only caught spelled-out combos, so Windows SendKeys `%{F4}`/`^w`
78
+ and Linux `XF86LogOff`/`XF86PowerOff` slipped through. Now caught on all three platforms (bare editing
79
+ keys like Delete stay allowed).
80
+ - **Secrets could be embedded into the semantic index (medium).** The asset/skill/memory dirs aren't
81
+ `.gitignore`-filtered, so a stray `credentials.json`/`secrets.yaml` there could be POSTed to the embedding
82
+ provider + persisted. Now secret-named files are skipped in both index collectors.
83
+ - **Token/config files were world-readable (medium).** `~/.hara/qwen-oauth.json` (access+refresh tokens)
84
+ and `~/.hara/config.json` (`apiKey`) are now written **0600** (and tightened on save).
85
+ - **RPA app allowlist was substring-matched (low).** `"Notes"` matched `"Notes - Evil"`; now an exact
86
+ (case-insensitive) frontmost-app match.
87
+
88
+ The RPA + clipboard shell-outs were confirmed injection-safe (argv arrays, JSON-quoted scripts). 198 tests
89
+ (2 new: the SSRF private-IP guard + the widened key blocklist).
90
+
91
+ ## 0.61.1 — unreleased (security + correctness hardening — core audit)
92
+
93
+ A security/correctness audit of the core (sandbox, confirmation gate, file tools, MCP client) found real
94
+ issues; fixed:
95
+ - **Confirmation-gate bypass via sub-agents (critical).** The read-kind `agent` tool never prompts, yet
96
+ spawned sub-agents ran **full-auto, unconfirmed** — so a role granting `edit_file`/`bash` let a fan-out
97
+ sub-agent mutate files / run shell with no approval, even in `suggest` mode. Sub-agents are now **always
98
+ read-only** (a role may narrow further but can never grant write/exec — `subagentToolFilter`). Write-capable
99
+ roles run in the main loop via `hara org`, behind the gate.
100
+ - **`apply_patch` wasn't actually atomic (critical / data-loss).** It claimed all-or-nothing but Phase 2 wrote
101
+ files sequentially — a mid-way failure left a half-patched tree with no undo. Now it **rolls back** every
102
+ applied write on any failure (restores updated/deleted, removes created), so it's truly all-or-nothing.
103
+ - **Sandbox honesty.** It's **file-write confinement only** (not reads/network/exec; `/private/tmp` stays
104
+ writable) — clarified in the header, `--sandbox` docs, and label so it no longer oversells containment.
105
+ - The non-macOS "runs unsandboxed" warning now fires from `runShell` (every entry point: `-p`, org, cron),
106
+ not just the REPL; a runaway `bash` whose output exceeds `maxBuffer` is now **killed** (not streamed to
107
+ the timeout); and `hara plugin add` now **shows the commands a plugin will run** on every launch (its MCP
108
+ servers + hooks are arbitrary code — surface the trust surface).
109
+
110
+ 196 tests (2 new: the sub-agent read-only guard + the apply_patch rollback). The edit tools, hooks matcher,
111
+ and sandbox profile-injection safety were audited and confirmed solid.
112
+
113
+ ## 0.61.0 — unreleased (`hara memory` — inspect + distill durable memory)
114
+
115
+ - New **`hara memory`** command group, giving memory a CLI surface it lacked:
116
+ - **`hara memory show`** — print the digest injected at session start (what the agent actually sees).
117
+ - **`hara memory init`** — scaffold the global + project memory dirs/seed files.
118
+ - **`hara memory distill [--days N] [--scope global|project|all]`** — **promote short-term → long-term**:
119
+ consolidate recent daily logs (`log/YYYY-MM-DD.md`) into durable `MEMORY.md`/`USER.md`, deduped against
120
+ what's already there, skipping the ephemeral. This closes the one tiering gap the PAI/hermes study
121
+ surfaced (the daily-log tier was previously write-only). The agent routes each fact to the right
122
+ target/scope (user pref → `USER.md`, project fact → project memory). Verified live with glm-5.
123
+ - `.hara/` is now gitignored in this repo so dogfooding doesn't leave runtime state (memory/roles/plans).
124
+
125
+ ## 0.60.2 — unreleased (memory digest: per-source budgets)
126
+
127
+ - After studying the PAI and hermes memory systems (both lexical-first; both treat vectors as an *optional*
128
+ optimization, not a requirement — which validates hara's design), tightened the frozen-snapshot digest:
129
+ the old `slice(0, 4000)` on the **concatenated** sources could cut an entry mid-line and let a large
130
+ project `MEMORY.md` **crowd `USER.md` out entirely**. Each source (project MEMORY / global MEMORY / USER)
131
+ now gets its **own** budget and is truncated at a **line boundary**, so high-value user prefs are always
132
+ injected and no entry is split. The rest stays reachable via `memory_search` (which is already hybrid
133
+ lexical + opt-in semantic). No behavior change when memory is small.
134
+
135
+ ## 0.60.1 — unreleased (cron hardening — from a code-review pass)
136
+
137
+ A review of the fast-built `hara cron` module surfaced real bugs; fixed:
138
+ - **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).
139
+ - **`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.
140
+ - **Per-job logs grew unbounded** — capped to the last ~256KB once over ~1MB.
141
+ - **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).
142
+ - **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.
143
+
144
+ 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).
145
+
146
+ ## 0.60.0 — unreleased (single-binary distribution)
147
+
148
+ - **Standalone binaries** — hara can now be a single self-contained executable (no Node required):
149
+ `curl -fsSL .../install.sh | sh`. Built with `bun build --compile` (`npm run build:binary`, or
150
+ `build:binaries` to cross-compile darwin-arm64/x64 + linux-x64/arm64 from one machine). A tagged
151
+ release (`.github/workflows/release.yml`) builds + attaches them; `install.sh` grabs the right one.
152
+ - Build fixes for the bundled binary: a Bun plugin **stubs ink's dev-only `react-devtools-core`** (lazy-
153
+ imported under `DEV`, never in production) so it bundles clean; the version is **baked in via a build
154
+ define** (a compiled binary has no `package.json` to read at runtime); and cron's self-reinvoke now
155
+ detects script-vs-binary mode (`selfArgv`) so `hara cron` works from the binary too. The 60 MB binaries
156
+ are kept out of the npm tarball (`!dist/bin`), which stays ~140 kB.
157
+
158
+ ## 0.59.0 — unreleased (vim keybindings in the input box)
159
+
160
+ - **Vim mode** (opt-in: `hara config set vimMode true`, or `HARA_VIM=1`). The TUI prompt becomes modal —
161
+ **Esc** → normal, **i/a/I/A/o** → insert. Normal-mode motions `h l 0 $ w b e` (+ `gg`/`G`), edits
162
+ `x D C dd cc dw cw`, and paste `p`/`P` with a delete/yank register. A distinct prompt marker (`◆` yellow)
163
+ + a `-- NORMAL -- / -- INSERT --` hint show the mode. Off by default (normal typing is unchanged). The
164
+ editing logic is a pure reducer (`src/tui/vim.ts`), fully unit-tested; `hara doctor` shows the input mode.
165
+
166
+ ## 0.58.0 — unreleased (`hara cron` — scheduled tasks)
167
+
168
+ - **Scheduled tasks.** `hara cron add "<schedule>" "<task>"` runs a task on a schedule — the fired job is a
169
+ fresh `hara` session (the run *is* the agent, like openclaw/hermes). Schedules: a 5-field **cron expr**
170
+ (`"0 9 * * 1-5"`), an **interval** (`"every 30m"`), or a **one-shot** (`"in 2h"` / an ISO timestamp).
171
+ `--org` routes it through the role org instead of a plain prompt.
172
+ - **Fires via your OS, no daemon to babysit.** `hara cron install` registers a per-minute `hara cron tick`
173
+ with **launchd** (macOS) or **crontab** (Linux); `tick` runs whatever's due (lock-guarded so a slow job
174
+ doesn't double-fire) and logs each run. Manage with `hara cron list / run <id> / enable / disable /
175
+ remove / logs / uninstall`. Jobs persist atomically in `~/.hara/cron/jobs.json`; `hara doctor` shows the
176
+ count + scheduler status. Cron matching is hand-rolled (no new dependency), minute-granular, local-time.
177
+
178
+ ## 0.57.0 — unreleased (in-session `/diff`, `/review`, `/commit` in the TUI)
179
+
180
+ - The default TUI now wires three more slash commands so the **change → review → commit** loop happens
181
+ in-session instead of dropping to a subcommand (they used to print "isn't wired into the TUI yet"):
182
+ - **`/diff`** — show the working-tree diff vs HEAD (`/diff staged` for the index), rendered as a colored diff block. No model call.
183
+ - **`/review`** — a senior-reviewer pass over `git diff HEAD` (read-only), streamed inline.
184
+ - **`/commit`** — stage everything and commit with an AI-written message (reuses the review→commit machinery).
185
+ Reuses existing, already-verified pieces (`autoCommit`, `REVIEW_SYSTEM`, `runShell`). Other subcommands
186
+ (`init`/`index`/`plan`/`org`/…) still point you to `hara <cmd>` or `HARA_TUI=0`.
187
+
188
+ ## 0.56.0 — unreleased (review → commit capstone + robust verdict parsing)
189
+
190
+ - **`hara org --review --commit`** closes the loop: once the reviewer approves, hara stages the work and
191
+ commits it with an AI-written message (reusing `hara commit`'s generation). **Guarded** — it only
192
+ auto-commits when the working tree was **clean before the run** (so it captures this run's work, never
193
+ pre-existing WIP), and with `--review` only **after approval** (a review that doesn't pass leaves the
194
+ changes in your tree, uncommitted). `--commit` works without `--review` too (commit the implementer's
195
+ result). Verified live end-to-end: implement → review → approve → `✓ committed`.
196
+ - **Robust verdict parsing** (hardening v0.55, found via live smokes). Real models don't emit the literal
197
+ `VERDICT: APPROVED` token — across runs glm-5 wrote `**VERDICT**: No issues found`, `**VERDICT**: PASS`,
198
+ and `VERDICT: LGTM`. The parser now anchors on a markdown-tolerant `VERDICT` marker and **classifies the
199
+ phrase after it** (approve vs changes synonyms), with a changes-signal veto and an ambiguous-→-not-approved
200
+ safe default (worst case is one extra review round, never a bad auto-commit). `not approved` correctly
201
+ vetoes despite containing "approv". Unit tests now cover the exact shapes seen in live runs.
202
+
203
+ ## 0.55.0 — unreleased (multi-role review chain — `hara org --review`)
204
+
205
+ - **Review chains** — `hara org --review "<task>"` runs the org like an actual engineering team: the owning
206
+ role implements, then a **reviewer** role inspects the diff and either **approves** or sends it back with
207
+ concrete fixes, looping implement → review → fix until approved or a round cap (`--rounds`, default 3).
208
+ This is hara's differentiation — not "one agent + temp sub-agents" but roles that hold each other to a
209
+ bar. The reviewer is read-only (uses your `reviewer` role if defined, else a built-in persona) and ends
210
+ with a machine-parseable `VERDICT: APPROVED | CHANGES_REQUESTED`; on changes-requested the issues feed
211
+ back into the implementer's own conversation so it keeps context. New `src/org/review-chain.ts` (verdict
212
+ parsing, non-destructive `git diff HEAD` capture, prompts) — all unit-tested. **Verified live end-to-end**
213
+ (implementer edits a file → reviewer approves → loop exits).
214
+
215
+ ## 0.54.0 — unreleased (`hara mcp` — run hara as an MCP server)
216
+
217
+ - **MCP server mode** — `hara mcp` runs hara as an MCP server over stdio, so other MCP clients (Claude
218
+ Desktop, Cursor, another hara…) can call its tools. hara was already an MCP *client*; this completes
219
+ the loop. The high-value one is **`codebase_search`** — point any MCP client at a repo and it gets
220
+ hara's semantic/lexical code search, plus `read_file`/`grep`/`glob`/`ls`/`web_fetch`/`web_search`.
221
+ **Read-only by default** — no `edit_file`/`bash`/`computer`, so an external client can't mutate your
222
+ machine through hara; override the exposed set with `HARA_MCP_TOOLS=a,b,c` at your own risk. Reuses
223
+ hara's tool registry (`src/mcp/server.ts`, built on `@modelcontextprotocol/sdk` — already a dep).
224
+ Verified end-to-end (a real MCP client lists the tools + calls `ls`/`codebase_search`). `hara doctor`
225
+ now shows both the client (servers connected) and serve (tools exposed) sides.
226
+
227
+ ```jsonc
228
+ // e.g. in a client's mcpServers config:
229
+ "hara": { "command": "hara", "args": ["mcp"] } // run from the repo you want searchable
230
+ ```
231
+
8
232
  ## 0.53.0 — unreleased (task-done notifications + steering in plan mode)
9
233
 
10
234
  - **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
@@ -51,7 +59,9 @@ hara -p "summarize @README.md and list any TODOs"
51
59
 
52
60
  ## Setup
53
61
 
54
- hara is **multi-provider**pick a provider + key.
62
+ The fastest path is **`hara setup`** an interactive wizard for provider + key + model (it also runs
63
+ automatically the first time you start `hara` unconfigured). Or configure it yourself — hara is
64
+ **multi-provider**:
55
65
 
56
66
  **Anthropic (default)**
57
67
  ```bash
@@ -171,14 +181,16 @@ vector DB needed, and lexical still works when there's no index. Re-running `har
171
181
  only changed files re-embed (a full repo rebuild that takes ~a minute re-runs in well under a second).
172
182
 
173
183
  **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).
184
+ **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
185
  **Screen control** (opt-in): the `computer` tool drives desktop software (screenshot → click/type), native per OS
176
186
  (mac `screencapture`+`cliclick` · Windows PowerShell · Linux `scrot`+`xdotool`). Off by default — enable a tier with
177
187
  `hara config set computerUse read|click|full` and allowlist apps with `hara config set computerApps "App, …"`. Guarded
178
188
  by the tier, the frontmost-app allowlist, a dangerous-key blocklist, and a once-per-session grant. Screenshots are read via your
179
189
  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
- **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>`.
190
+ **Sessions**: conversations are saved automatically — `-c` / `--resume <id>` to continue, `hara sessions` to list, `hara export [id] [--out file]` to render one as a Markdown transcript.
191
+ **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).
192
+ **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.
193
+ **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
194
  **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
195
  **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
196
  **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,9 +201,13 @@ Define role-agents in `.hara/roles/*.md` — each is a persona (the file body) p
189
201
  (keywords that route a task here), optional `rejects`, `model`, and `allowTools`/`denyTools`. `hara org
190
202
  "<task>"` routes the task to the role that **owns** it (keyword match, LLM fallback) and runs that role's
191
203
  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. The
204
+ lists them, `hara roles init` scaffolds a starter set, and `--role <id>` forces a specific role. Add
205
+ **`--review`** and the org works like a team: the owning role implements, then a **reviewer** role inspects
206
+ the diff and either approves or sends it back with fixes — looping implement → review → fix until approved
207
+ (or `--rounds N`). Add **`--commit`** and it commits the approved result with an AI-written message (guarded
208
+ to a clean start tree; a review that doesn't pass leaves the work uncommitted). The
193
209
  **`agent`** tool spawns **parallel read-only sub-agents** for fan-out — analyze / review / search
194
- several things at once (each can take a `role`).
210
+ several things at once (each can take a `role`), bounded to 8 concurrent (`HARA_MAX_CONCURRENCY`).
195
211
 
196
212
  Beyond routing, **`hara plan "<task>"`** makes the org *plan*: it decomposes the task into atoms,
197
213
  sequences them as a DAG, and executes each step (optionally routed to a role) behind a per-step
@@ -209,7 +225,7 @@ A streaming agentic loop with built-in tools — `read_file`, `write_file`, **`e
209
225
  read-only **`grep`** / **`glob`** / **`ls`** / **`web_fetch`** — behind a human-in-the-loop confirmation gate on the
210
226
  dangerous ones unless `-y`. Read-only tools run in parallel within a turn, and edits print a
211
227
  **colored diff** of what changed. Shell output streams live; press **Esc** to interrupt a running
212
- turn, or **`/undo`** to revert the last edit.
228
+ 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
229
  - **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
230
  - **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
231
  - **`@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 +233,12 @@ turn, or **`/undo`** to revert the last edit.
217
233
 
218
234
  ### Roadmap
219
235
 
220
- **Shipped:** ink TUI · plan mode · persistent memory + self-evolution · atomization planner · parallel sub-agents · `/compact` context management.
221
- **Next:** parallel plan atoms · multi-role review chains · cron autonomy for the org · single-binary distribution · an enterprise control-plane (fleet + central token management).
236
+ **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.
237
+ **Next:** SSOT data authority · an enterprise control-plane (fleet + central token management).
238
+
239
+ ## Security
240
+
241
+ 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
242
 
223
243
  ## License
224
244
 
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.
@@ -5,6 +5,7 @@ import { activity } from "../activity.js";
5
5
  import { makeRenderer } from "../md.js";
6
6
  import { skillsDigest } from "../skills/skills.js";
7
7
  import { runHooks } from "../hooks.js";
8
+ import { mapLimit, maxParallel } from "../concurrency.js";
8
9
  /** Whether a tool call needs user confirmation under the given approval mode. */
9
10
  export function needsConfirm(kind, mode) {
10
11
  if (kind === "read")
@@ -136,14 +137,16 @@ export async function runAgent(history, opts) {
136
137
  const preview = String(input.path ?? input.command ?? input.pattern ?? input.url ?? input.task ?? "")
137
138
  .replace(/\s+/g, " ")
138
139
  .trim();
139
- if (needsConfirm(tool.kind, opts.approval) && !opts.autoApprove?.has(tu.name)) {
140
+ // Screen control is gated on EVERY action — a prior "don't ask again" must never satisfy it.
141
+ const alwaysGate = tool.kind === "computer";
142
+ if (needsConfirm(tool.kind, opts.approval) && (alwaysGate || !opts.autoApprove?.has(tu.name))) {
140
143
  const reply = await opts.confirm(`${c.yellow("⚠")} ${c.bold(tu.name)} ${c.dim(preview)} — run?`);
141
144
  if (reply === false) {
142
145
  plans.push({ tu, tool, denied: "User denied this action." });
143
146
  continue;
144
147
  }
145
- if (reply === "always")
146
- opts.autoApprove?.add(tu.name);
148
+ if (reply === "always" && !alwaysGate)
149
+ opts.autoApprove?.add(tu.name); // computer: treat "always" as one-time yes
147
150
  }
148
151
  plans.push({ tu, tool });
149
152
  if (!opts.quiet) {
@@ -179,21 +182,25 @@ export async function runAgent(history, opts) {
179
182
  activity.dec();
180
183
  }
181
184
  };
182
- let batch = [];
185
+ let batch = []; // indices of pending read-kind tools (run concurrently, capped)
186
+ const flush = async () => {
187
+ if (!batch.length)
188
+ return;
189
+ const idx = batch;
190
+ batch = [];
191
+ await mapLimit(idx, maxParallel(), (i) => runOne(i, plans[i])); // bounded fan-out (e.g. 20 parallel agents → 8 at a time)
192
+ };
183
193
  for (let i = 0; i < plans.length; i++) {
184
194
  const p = plans[i];
185
195
  if (p.denied === undefined && p.tool?.kind === "read") {
186
- batch.push(runOne(i, p)); // safe → accumulate to run concurrently
196
+ batch.push(i); // safe → accumulate to run concurrently
187
197
  }
188
198
  else {
189
- if (batch.length) {
190
- await Promise.all(batch); // flush pending reads before an edit/exec
191
- batch = [];
192
- }
199
+ await flush(); // flush pending reads before an edit/exec
193
200
  await runOne(i, p);
194
201
  }
195
202
  }
196
- await Promise.all(batch);
203
+ await flush();
197
204
  history.push({ role: "tool", results });
198
205
  }
199
206
  }
@@ -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
+ }
@@ -0,0 +1,22 @@
1
+ // Bounded-concurrency map: run `fn` over `items` with at most `limit` in flight at once, preserving input
2
+ // order in the results. Used to cap parallel sub-agents / read-tools / plan atoms so a wide fan-out (the
3
+ // model spawning 20 `agent` calls in one turn) doesn't hammer the provider's rate limits or thrash the box.
4
+ // cc-haha caps tool concurrency at 10; hara defaults to 8, tunable via HARA_MAX_CONCURRENCY.
5
+ export function maxParallel() {
6
+ const n = Number(process.env.HARA_MAX_CONCURRENCY);
7
+ return Number.isInteger(n) && n >= 1 ? n : 8;
8
+ }
9
+ export async function mapLimit(items, limit, fn) {
10
+ const results = new Array(items.length);
11
+ let next = 0;
12
+ const worker = async () => {
13
+ for (;;) {
14
+ const i = next++;
15
+ if (i >= items.length)
16
+ return;
17
+ results[i] = await fn(items[i], i);
18
+ }
19
+ };
20
+ await Promise.all(Array.from({ length: Math.min(Math.max(1, limit), items.length) }, worker));
21
+ return results;
22
+ }
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: {
@@ -10,8 +10,9 @@ const PROVIDER_DEFAULTS = {
10
10
  },
11
11
  "qwen-oauth": { model: "coder-model", envKey: "QWEN_OAUTH_TOKEN" },
12
12
  openai: { model: "gpt-4o-mini", envKey: "OPENAI_API_KEY" },
13
+ "hara-gateway": { model: "", envKey: "HARA_GATEWAY_TOKEN" }, // B-end: enrolled device → token in ~/.hara/org.json, routed by the gateway
13
14
  };
14
- export const CONFIG_KEYS = ["provider", "apiKey", "model", "baseURL", "approval", "sandbox", "theme", "evolve", "assetCapture", "computerUse", "computerApps", "visionModel", "visionBaseURL", "visionApiKey", "embedProvider", "embedModel", "embedBaseURL", "embedApiKey", "notify"];
15
+ 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
16
  export const APPROVAL_MODES = ["suggest", "auto-edit", "full-auto"];
16
17
  export const SANDBOX_MODES = ["off", "workspace-write", "read-only"];
17
18
  const PROJECT_ROOT_MARKERS = [".git", "package.json", "Cargo.toml", "go.mod", "pyproject.toml", ".hg"];
@@ -51,12 +52,22 @@ function readProjectConfig(cwd) {
51
52
  }
52
53
  return {};
53
54
  }
55
+ /** Write the config 0600 (it can hold `apiKey`) + tighten an existing file. */
56
+ function persistConfig(p, cfg) {
57
+ mkdirSync(dirname(p), { recursive: true });
58
+ writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
59
+ try {
60
+ chmodSync(p, 0o600);
61
+ }
62
+ catch {
63
+ /* best-effort */
64
+ }
65
+ }
54
66
  export function writeConfigValue(key, value) {
55
67
  const p = configPath();
56
68
  const cfg = readRawConfig();
57
69
  cfg[key] = value;
58
- mkdirSync(dirname(p), { recursive: true });
59
- writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n", "utf8");
70
+ persistConfig(p, cfg);
60
71
  }
61
72
  /** Record (or clear, with cap=null) a confirmed per-model vision capability in `modelVision`. */
62
73
  export function setModelVisionOverride(model, cap) {
@@ -68,8 +79,7 @@ export function setModelVisionOverride(model, cap) {
68
79
  else
69
80
  map[model] = cap;
70
81
  cfg.modelVision = map;
71
- mkdirSync(dirname(p), { recursive: true });
72
- writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n", "utf8");
82
+ persistConfig(p, cfg);
73
83
  }
74
84
  /**
75
85
  * Effective config. Precedence (high→low): env vars > selected profile >
@@ -109,7 +119,8 @@ export function loadConfig(opts = {}) {
109
119
  };
110
120
  const hooks = (merged.hooks && typeof merged.hooks === "object" ? merged.hooks : {});
111
121
  const notify = (process.env.HARA_NOTIFY ?? merged.notify ?? "off");
112
- return { provider, apiKey, model, baseURL, approval, sandbox, theme, evolve, assetCapture, computerUse, computerApps, visionModel, visionBaseURL, visionApiKey, modelVision, embedProvider, embedModel, embedBaseURL, embedApiKey, hooks, notify, mcpServers, cwd: process.cwd() };
122
+ const vimMode = process.env.HARA_VIM === "1" || merged.vimMode === true || merged.vimMode === "true";
123
+ 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
124
  }
114
125
  export function providerEnvKey(provider) {
115
126
  return (PROVIDER_DEFAULTS[provider] ?? PROVIDER_DEFAULTS.anthropic).envKey;