sanook-cli 0.4.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/.env.example +23 -0
- package/CHANGELOG.md +38 -0
- package/LICENSE +201 -0
- package/README.md +239 -0
- package/dist/agentContext.js +2 -0
- package/dist/approval.js +78 -0
- package/dist/bin.js +461 -0
- package/dist/brain.js +186 -0
- package/dist/commands.js +66 -0
- package/dist/compaction.js +85 -0
- package/dist/config.js +101 -0
- package/dist/cost.js +59 -0
- package/dist/diff.js +36 -0
- package/dist/gateway/auth.js +32 -0
- package/dist/gateway/ledger.js +94 -0
- package/dist/gateway/lock.js +114 -0
- package/dist/gateway/schedule.js +74 -0
- package/dist/gateway/scheduler.js +87 -0
- package/dist/gateway/serve.js +57 -0
- package/dist/gateway/server.js +94 -0
- package/dist/gateway/telegram.js +115 -0
- package/dist/git.js +55 -0
- package/dist/hooks.js +104 -0
- package/dist/knowledge.js +68 -0
- package/dist/loop.js +169 -0
- package/dist/mcp.js +191 -0
- package/dist/memory.js +108 -0
- package/dist/providers/codex.js +86 -0
- package/dist/providers/keys.js +37 -0
- package/dist/providers/models.js +55 -0
- package/dist/providers/registry.js +241 -0
- package/dist/session.js +36 -0
- package/dist/skill-install.js +190 -0
- package/dist/skills.js +111 -0
- package/dist/tools/bash.js +26 -0
- package/dist/tools/edit.js +107 -0
- package/dist/tools/git.js +68 -0
- package/dist/tools/index.js +36 -0
- package/dist/tools/list.js +24 -0
- package/dist/tools/permission.js +30 -0
- package/dist/tools/read.js +18 -0
- package/dist/tools/recall.js +12 -0
- package/dist/tools/remember.js +14 -0
- package/dist/tools/schedule.js +61 -0
- package/dist/tools/search.js +54 -0
- package/dist/tools/skill.js +65 -0
- package/dist/tools/task.js +46 -0
- package/dist/tools/util.js +5 -0
- package/dist/tools/write.js +27 -0
- package/dist/ui/app.js +132 -0
- package/dist/ui/banner.js +20 -0
- package/dist/ui/brain-wizard.js +29 -0
- package/dist/ui/render.js +57 -0
- package/dist/ui/setup.js +46 -0
- package/package.json +77 -0
- package/second-brain/AGENTS.md +18 -0
- package/second-brain/CLAUDE.md +96 -0
- package/second-brain/Evals/retrieval-eval.md +30 -0
- package/second-brain/GEMINI.md +15 -0
- package/second-brain/Home.md +33 -0
- package/second-brain/README.md +29 -0
- package/second-brain/Runbooks/ingest-quarantine.md +27 -0
- package/second-brain/Runbooks/sleep-time-consolidation.md +26 -0
- package/second-brain/Shared/AI-Context-Index.md +52 -0
- package/second-brain/Shared/Core-Facts/protected-facts.md +21 -0
- package/second-brain/Shared/Decision-Memory/decision-log.md +24 -0
- package/second-brain/Shared/Memory-Inbox/memory-inbox.md +23 -0
- package/second-brain/Shared/Operating-State/current-state.md +30 -0
- package/second-brain/Shared/Provenance/ingest-log.md +27 -0
- package/second-brain/Shared/Rules/context-assembly-policy.md +28 -0
- package/second-brain/Shared/Rules/frontmatter-standard.md +33 -0
- package/second-brain/Shared/Rules/skills-admission.md +30 -0
- package/second-brain/Shared/User-Memory/user-preferences.md +25 -0
- package/second-brain/Templates/bug.md +22 -0
- package/second-brain/Templates/handoff.md +21 -0
- package/second-brain/Templates/project.md +24 -0
- package/second-brain/Templates/session.md +26 -0
- package/second-brain/USER.md +36 -0
- package/second-brain/Vault Structure Map.md +106 -0
- package/skills/agent-tool-mcp-builder/SKILL.md +88 -0
- package/skills/api-design-review/SKILL.md +70 -0
- package/skills/async-concurrency-correctness/SKILL.md +93 -0
- package/skills/audit-accessibility-wcag/SKILL.md +59 -0
- package/skills/audit-technical-seo/SKILL.md +62 -0
- package/skills/auth-jwt-session/SKILL.md +88 -0
- package/skills/brainstorm-design/SKILL.md +73 -0
- package/skills/build-etl-pipeline/SKILL.md +58 -0
- package/skills/build-form-validation/SKILL.md +103 -0
- package/skills/build-office-docs/SKILL.md +80 -0
- package/skills/build-react-component/SKILL.md +116 -0
- package/skills/build-spreadsheet/SKILL.md +106 -0
- package/skills/caching-strategy/SKILL.md +75 -0
- package/skills/cicd-pipeline-author/SKILL.md +65 -0
- package/skills/cloud-cost-optimize/SKILL.md +91 -0
- package/skills/code-comments/SKILL.md +52 -0
- package/skills/code-review/SKILL.md +61 -0
- package/skills/db-migration-safety/SKILL.md +67 -0
- package/skills/debug-frontend-browser/SKILL.md +58 -0
- package/skills/debug-root-cause/SKILL.md +54 -0
- package/skills/dependency-upgrade/SKILL.md +56 -0
- package/skills/deploy-release/SKILL.md +64 -0
- package/skills/diff-table-parity/SKILL.md +58 -0
- package/skills/dockerfile-optimize/SKILL.md +82 -0
- package/skills/error-message/SKILL.md +58 -0
- package/skills/estimate-work/SKILL.md +54 -0
- package/skills/explore-codebase/SKILL.md +73 -0
- package/skills/git-commit-pr/SKILL.md +65 -0
- package/skills/gitops-deploy-workflow/SKILL.md +97 -0
- package/skills/implement-from-design/SKILL.md +69 -0
- package/skills/incident-response-sre/SKILL.md +78 -0
- package/skills/k8s-debug-workload/SKILL.md +135 -0
- package/skills/k8s-manifest-review/SKILL.md +86 -0
- package/skills/llm-eval-harness/SKILL.md +63 -0
- package/skills/manage-client-server-state/SKILL.md +94 -0
- package/skills/mermaid-diagram/SKILL.md +61 -0
- package/skills/message-queue-jobs/SKILL.md +139 -0
- package/skills/naming-helper/SKILL.md +57 -0
- package/skills/observability-instrument/SKILL.md +113 -0
- package/skills/optimize-core-web-vitals/SKILL.md +75 -0
- package/skills/optimize-sql-query/SKILL.md +67 -0
- package/skills/performance-profiling/SKILL.md +65 -0
- package/skills/process-pdf/SKILL.md +107 -0
- package/skills/profile-dataset/SKILL.md +97 -0
- package/skills/prompt-engineering/SKILL.md +70 -0
- package/skills/rag-pipeline/SKILL.md +53 -0
- package/skills/rate-limiting/SKILL.md +96 -0
- package/skills/refactor-cleanup/SKILL.md +54 -0
- package/skills/regex-build/SKILL.md +72 -0
- package/skills/release-notes/SKILL.md +79 -0
- package/skills/rest-graphql-contract/SKILL.md +71 -0
- package/skills/scrape-structured-web-data/SKILL.md +61 -0
- package/skills/secrets-management/SKILL.md +96 -0
- package/skills/security-review/SKILL.md +62 -0
- package/skills/shell-script-robust/SKILL.md +71 -0
- package/skills/style-responsive-tailwind/SKILL.md +70 -0
- package/skills/terraform-plan-review/SKILL.md +95 -0
- package/skills/type-safety-strict/SKILL.md +82 -0
- package/skills/validate-data-quality/SKILL.md +62 -0
- package/skills/wrangle-tabular-data/SKILL.md +75 -0
- package/skills/write-adr/SKILL.md +75 -0
- package/skills/write-analytical-sql/SKILL.md +71 -0
- package/skills/write-data-viz/SKILL.md +58 -0
- package/skills/write-docs/SKILL.md +54 -0
- package/skills/write-plan/SKILL.md +59 -0
- package/skills/write-playwright-e2e/SKILL.md +86 -0
- package/skills/write-prd/SKILL.md +65 -0
- package/skills/write-rfc/SKILL.md +75 -0
- package/skills/write-tests/SKILL.md +50 -0
package/.env.example
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# BYOK — API key ตรงจาก console ของค่ายเท่านั้น
|
|
2
|
+
# ห้าม OAuth / subscription token (Claude.ai / ChatGPT plan) — ละเมิด ToS, บัญชีโดนแบนได้
|
|
3
|
+
# ตั้งเฉพาะค่ายที่ใช้ (อันไหนไม่มี key ก็ข้ามได้)
|
|
4
|
+
|
|
5
|
+
# ── ToS-sensitive: ต้อง API key ตรง ห้าม OAuth ──
|
|
6
|
+
ANTHROPIC_API_KEY=sk-ant-api03-xxx # console.anthropic.com → API Keys
|
|
7
|
+
GOOGLE_GENERATIVE_AI_API_KEY=AIzaxxx # aistudio.google.com/apikey (restrict เป็น Gemini-only)
|
|
8
|
+
|
|
9
|
+
# ── Cloud BYOK ──
|
|
10
|
+
OPENAI_API_KEY=sk-xxx # platform.openai.com (รวม Codex: model gpt-5-codex)
|
|
11
|
+
DEEPSEEK_API_KEY=sk-xxx # platform.deepseek.com
|
|
12
|
+
XAI_API_KEY=xai-xxx # console.x.ai
|
|
13
|
+
MISTRAL_API_KEY=xxx # console.mistral.ai
|
|
14
|
+
GROQ_API_KEY=gsk_xxx # console.groq.com
|
|
15
|
+
MINIMAX_API_KEY=xxx # platform.minimax.io (MINIMAX_BASE_URL สลับ region)
|
|
16
|
+
ZHIPU_API_KEY=xxx # z.ai / open.bigmodel.cn (GLM — GLM_BASE_URL สลับ region)
|
|
17
|
+
|
|
18
|
+
# ── Local (ไม่ต้อง key — ตั้ง baseURL ถ้าไม่ใช่ default) ──
|
|
19
|
+
# OLLAMA_BASE_URL=http://localhost:11434/v1
|
|
20
|
+
# LMSTUDIO_BASE_URL=http://localhost:1234/v1
|
|
21
|
+
|
|
22
|
+
# default model (alias หรือ provider:model) — เช่น sonnet | opus | gpt | grok | groq:fast
|
|
23
|
+
SANOOK_MODEL=sonnet
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0 — second brain, GLM Coding Plan, Telegram, hardening
|
|
4
|
+
|
|
5
|
+
- **Second brain**: `sanook brain init` scaffolds a portable Obsidian "second-brain" workspace — full folder taxonomy (each with `_Index.md`), a central `Vault Structure Map.md`, seed memory files, and a portable AI operating constitution (`CLAUDE/GEMINI/AGENTS.md`). Research-backed rules: context-assembly (anti context-rot), intake quarantine + injection-scan, bi-temporal fact validity, provenance tracking, a verification-gated `Skills/` library, sleep-time consolidation. The agent now **loads the vault** into context, and `brain init` **auto-wires a filesystem MCP** to it. First-run wizard offers to create one (personalized).
|
|
6
|
+
- **GLM Coding Plan**: GLM routes through the Anthropic-compatible endpoint (`/api/anthropic`), so Coding Plan keys work; curated ids `glm-4.6 / glm-5.1 / glm-4.5-air`.
|
|
7
|
+
- **Telegram channel**: drive the agent from your phone (long-polling, fail-closed allowlist, private-only). Remote surface defaults to ask-mode (mutations denied) unless `TELEGRAM_ALLOW_WRITE=1`.
|
|
8
|
+
- **Auto-compaction**: token-aware sliding window keeps long sessions under the limit.
|
|
9
|
+
- **Interactive approval** (`ask` mode) + capability-based gating — any non-read-only tool (incl. MCP) is confirmed before running.
|
|
10
|
+
- **REPL resume** (`sanook -c`), **stdin piping** (`git diff | sanook "review"`), gateway multi-turn history, and `sanook config` / `sanook mcp` management commands.
|
|
11
|
+
- **Provider audit**: corrected stale model ids (OpenAI `gpt-5.3-codex`, DeepSeek `v4-flash/pro`, xAI `grok-4.3`).
|
|
12
|
+
- **Hardening**: budget cap now actually fires on the default fast model; write paths confined (no `~/.sanook` / shell-rc / ssh backdoors); MCP child processes get a minimal env (no secret leakage); provider errors surface a clean one-line message; versions read from `package.json`. Added tests for the BYOK/redaction core and budget cap.
|
|
13
|
+
|
|
14
|
+
## 0.3.0 — providers, memory, gateway, MCP, git
|
|
15
|
+
|
|
16
|
+
- **Providers**: data-driven registry, now 12 providers (added MiniMax, GLM, and OpenAI Codex via the official CLI). Per-provider model picker that fetches the live model list.
|
|
17
|
+
- **Memory**: auto-memory (`remember` / `recall`), session resume (`--continue`), and in-session REPL conversation history.
|
|
18
|
+
- **Gateway + cron**: `sanook serve` runs a loopback HTTP endpoint (OpenAI-compatible) plus a cron scheduler with natural-language scheduling, backed by a file-locked JSON task ledger.
|
|
19
|
+
- **Skills**: load `SKILL.md` files on demand; the agent can author its own with `create_skill`.
|
|
20
|
+
- **Subagents**: a `task` tool spawns a fresh-context sub-agent (read-only by default, depth-guarded).
|
|
21
|
+
- **Hooks**: PreToolUse / PostToolUse commands via `~/.sanook/hooks.json`.
|
|
22
|
+
- **Plan mode** (`--plan`): read-only exploration that produces a plan before acting.
|
|
23
|
+
- **MCP**: connect Model Context Protocol servers (stdio) via `~/.sanook/mcp.json`.
|
|
24
|
+
- **Git**: automatic git context in the prompt + `git_status` / `git_diff` / `git_log` / `git_commit` tools.
|
|
25
|
+
- Onboarding: welcome banner + first-run setup wizard.
|
|
26
|
+
- Hardened across several adversarial reviews — command injection, prompt injection, concurrency, and secret redaction.
|
|
27
|
+
|
|
28
|
+
## 0.1.0 — first usable release
|
|
29
|
+
|
|
30
|
+
A terminal AI coding agent, built from scratch in TypeScript. BYOK, works with any model.
|
|
31
|
+
|
|
32
|
+
- **Agent loop** on Vercel AI SDK 6 (`streamText` + `stopWhen` + `fullStream`), streamed output
|
|
33
|
+
- **Tools**: read / write / edit (multi-tier matcher) / list / glob / grep / bash, with a permission gate (denies destructive commands + protected paths)
|
|
34
|
+
- **Multi-provider BYOK**: Anthropic / OpenAI / Google / Ollama via one model spec; direct API key only (no OAuth/subscription reuse)
|
|
35
|
+
- **Cost meter** + budget cap (per-token, cache-aware)
|
|
36
|
+
- **Context memory**: hierarchical `SANOOK.md` loader (stops at project boundary) + tool-result compaction
|
|
37
|
+
- **Ink TUI** REPL with slash commands (`/model` `/cost` `/clear` `/compact` `/help`), plus headless `--json` mode for CI
|
|
38
|
+
- Eval harness (outcome-checked tasks) + CI matrix (mac/linux/windows × Node 22/24)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Sanook contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Sanook CLI
|
|
4
|
+
|
|
5
|
+
**A terminal AI coding agent — built from scratch in TypeScript.**
|
|
6
|
+
|
|
7
|
+
Bring your own key, run with any of 12 model providers, and let it remember what it did across sessions.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/Sir-chawakorn/sanook-cli/releases)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://nodejs.org)
|
|
12
|
+
[](https://www.typescriptlang.org)
|
|
13
|
+
[](#development)
|
|
14
|
+
[](https://github.com/Sir-chawakorn/sanook-cli/actions/workflows/ci.yml)
|
|
15
|
+
|
|
16
|
+
[Quickstart](#quickstart) · [Providers](#providers) · [Usage](#usage) · [Gateway](#gateway--scheduling) · [Skills](#skills) · [MCP](#mcp) · [Security](#security)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Overview
|
|
23
|
+
|
|
24
|
+
Sanook is a small, transparent coding agent for your terminal. At its heart is a single loop —
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
prompt → LLM → tool call → result → loop → answer
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
— wrapped with everything that makes it usable for real work: a permission gate, a memory the agent writes itself, a long-running gateway with cron and chat channels, on-demand skills, MCP servers, and first-class git awareness.
|
|
31
|
+
|
|
32
|
+
It is **BYOK (bring your own key)** by design. Every provider connects with a **direct API key from that provider's own console** — Sanook never reuses OAuth or subscription credentials, because that violates provider terms and gets accounts banned.
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g sanook-cli
|
|
38
|
+
|
|
39
|
+
export ANTHROPIC_API_KEY=sk-ant-... # or run `sanook` and use the setup wizard
|
|
40
|
+
sanook "read package.json and list the dependencies"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Run `sanook` with no task to drop into an interactive REPL. On the very first run with no key configured, a setup wizard walks you through picking a provider, pasting a key, and choosing a model.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
sanook # interactive REPL
|
|
47
|
+
sanook "fix the failing test" # one-shot, headless
|
|
48
|
+
sanook --json "..." # JSONL output for CI / scripts
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
| Area | What you get |
|
|
54
|
+
|---|---|
|
|
55
|
+
| **Agent loop** | Built on the Vercel AI SDK 6 (`streamText` + `stopWhen` + `fullStream`), with streamed output, a cost meter, and a budget cap. |
|
|
56
|
+
| **Tools** | `read_file` · `write_file` · `edit_file` (multi-tier matcher) · `list_dir` · `glob` · `grep` · `run_bash`, plus git tools — gated by a permission layer that denies destructive commands and protected paths. |
|
|
57
|
+
| **Approval** | Interactive `ask` mode prompts `y/n` before any file write or shell command. `--yes` for auto-approve; headless defaults to safe-deny. |
|
|
58
|
+
| **Memory** | The agent writes its own notes (`remember`), recalls them across past sessions (`recall`), and `--continue` resumes the last run where it left off. |
|
|
59
|
+
| **Skills** | 69 built-in skills + install your own from a GitHub repo, URL, or local path. The agent can also author new skills after a repeatable task. |
|
|
60
|
+
| **Subagents** | A `task` tool spawns a fresh-context sub-agent for scoped exploration without bloating the main context — read-only by default, depth-guarded. |
|
|
61
|
+
| **Gateway + cron** | `sanook serve` runs a long-lived daemon: a loopback OpenAI-compatible HTTP endpoint plus a cron scheduler. Ask it in plain language and it schedules itself. |
|
|
62
|
+
| **Channels** | A Telegram adapter (long-polling, no public URL) lets you drive the agent from your phone — locked down with a required allowlist and private-chat-only policy. |
|
|
63
|
+
| **MCP** | Connect any Model Context Protocol server (filesystem, GitHub, Postgres, …) via `~/.sanook/mcp.json`. |
|
|
64
|
+
| **Git** | Branch, uncommitted changes, and recent commits are injected automatically, with `git_status` / `git_diff` / `git_log` / `git_commit` tools. |
|
|
65
|
+
| **Hooks** | Run your own command before/after any tool. A non-zero `PreToolUse` exit blocks the tool — enforce lint, format, or policy. |
|
|
66
|
+
| **Plan mode** | `--plan` restricts the agent to read-only tools and asks it to produce a plan before touching anything. |
|
|
67
|
+
| **Auto-compaction** | A token-aware sliding window keeps long sessions under the context limit with zero extra LLM cost. |
|
|
68
|
+
| **Second brain** | `sanook brain init` scaffolds a structured Obsidian "second-brain" workspace (folders + `_Index` + a portable AI operating constitution) for organising work and giving the agent durable, cross-session memory. |
|
|
69
|
+
|
|
70
|
+
## Providers
|
|
71
|
+
|
|
72
|
+
One model spec, twelve providers. Switch with `-m <spec>` on the command line or `/model` in the REPL.
|
|
73
|
+
|
|
74
|
+
| Provider | Spec example | Key |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| Anthropic (Claude) | `-m sonnet`, `-m opus`, `-m haiku` | `ANTHROPIC_API_KEY` |
|
|
77
|
+
| Google (Gemini) | `-m gemini`, `-m google:gemini-2.5-flash` | `GOOGLE_GENERATIVE_AI_API_KEY` |
|
|
78
|
+
| OpenAI | `-m gpt`, `-m openai:gpt-5.5` | `OPENAI_API_KEY` |
|
|
79
|
+
| DeepSeek | `-m deepseek` | `DEEPSEEK_API_KEY` |
|
|
80
|
+
| xAI (Grok) | `-m grok` | `XAI_API_KEY` |
|
|
81
|
+
| Mistral | `-m mistral` | `MISTRAL_API_KEY` |
|
|
82
|
+
| Groq | `-m groq:fast` | `GROQ_API_KEY` |
|
|
83
|
+
| MiniMax | `-m minimax` | `MINIMAX_API_KEY` |
|
|
84
|
+
| GLM (Zhipu) | `-m glm` | `ZHIPU_API_KEY` |
|
|
85
|
+
| Ollama | `-m ollama` | — (local) |
|
|
86
|
+
| LM Studio | `-m lmstudio` | — (local) |
|
|
87
|
+
| OpenAI Codex | `-m codex` | via the official Codex CLI |
|
|
88
|
+
|
|
89
|
+
A spec is an alias (`sonnet`), a `provider:model-id` pair (`openai:gpt-5.5`), or a bare model id. `sanook models <provider>` lists the curated ids and, when a key is set, verifies them against the provider's live `/models` endpoint.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
sanook models # list all providers
|
|
93
|
+
sanook models anthropic # curated ids (+ live verification if a key is set)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Usage
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
sanook "<task>" run one task (headless)
|
|
100
|
+
sanook interactive REPL
|
|
101
|
+
sanook -c "<task>" resume the latest session
|
|
102
|
+
sanook --plan "<task>" plan mode (read-only)
|
|
103
|
+
sanook --json "<task>" JSONL output for scripts / CI
|
|
104
|
+
|
|
105
|
+
-m, --model <spec> model or provider:model-id
|
|
106
|
+
-b, --budget <usd> stop when estimated cost exceeds this
|
|
107
|
+
-y, --yes auto-approve tool calls (skip ask-mode)
|
|
108
|
+
-v, --version print version
|
|
109
|
+
-h, --help show help
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**REPL slash commands:** `/model` · `/tools` · `/skills` · `/cost` · `/clear` · `/compact` · `/help` · `/quit`
|
|
113
|
+
|
|
114
|
+
## Gateway & scheduling
|
|
115
|
+
|
|
116
|
+
`sanook serve` starts a single long-lived process that hosts an HTTP API, a cron scheduler, and optional chat channels — all driving the same agent core.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
sanook serve --port 8787 # HTTP (127.0.0.1 only) + scheduler
|
|
120
|
+
sanook cron add "every 30m" "check the CI" # also "09:00", an ISO time, or "now"
|
|
121
|
+
sanook cron list
|
|
122
|
+
sanook cron rm <id>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The HTTP server binds to **loopback only** and authenticates every endpoint (except `/health`) with a bearer token stored at `~/.sanook/gateway/token` (chmod 600). It speaks the OpenAI chat-completions shape, so existing clients work unchanged:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
curl http://127.0.0.1:8787/v1/chat/completions \
|
|
129
|
+
-H "Authorization: Bearer $(cat ~/.sanook/gateway/token)" \
|
|
130
|
+
-H 'content-type: application/json' \
|
|
131
|
+
-d '{"messages":[{"role":"user","content":"summarise today's commits"}]}'
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
| Method | Endpoint | Purpose |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `GET` | `/health` | liveness (public) |
|
|
137
|
+
| `POST` | `/v1/chat/completions` | run the agent (OpenAI-compatible) |
|
|
138
|
+
| `GET` / `POST` | `/tasks` | list / enqueue scheduled tasks |
|
|
139
|
+
|
|
140
|
+
### Telegram channel
|
|
141
|
+
|
|
142
|
+
Set two environment variables before `sanook serve` and the gateway adds a Telegram adapter via long-polling (no public URL needed):
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
export TELEGRAM_BOT_TOKEN=123:abc
|
|
146
|
+
export TELEGRAM_ALLOWED_CHATS=5222385839 # required — comma-separated chat ids
|
|
147
|
+
sanook serve
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The channel is **fail-closed**: with no allowlist it refuses to start, it accepts private chats only, and it never leaks internal errors back to the sender. See [Security](#security).
|
|
151
|
+
|
|
152
|
+
## Skills
|
|
153
|
+
|
|
154
|
+
A skill is a `SKILL.md` file (front-matter + instructions) the agent loads on demand. Sanook ships with 69 built-in skills and can install more.
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
sanook skill list # browse all skills
|
|
158
|
+
sanook skill add anthropics/skills # from a GitHub repo
|
|
159
|
+
sanook skill add https://…/SKILL.md # from a URL
|
|
160
|
+
sanook skill add ./my-skill # from a local path
|
|
161
|
+
sanook skill remove my-skill
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
> ⚠️ A skill is an instruction the agent will follow. Install only from sources you trust.
|
|
165
|
+
|
|
166
|
+
## Second brain
|
|
167
|
+
|
|
168
|
+
Scaffold a structured [Obsidian](https://obsidian.md) workspace for organising your work and giving the agent a durable, cross-session memory:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
sanook brain init # interactive — asks where + a few identity questions
|
|
172
|
+
sanook brain init ~/notes/brain # non-interactive (with --yes)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
It creates a full folder taxonomy (`Projects/`, `Sessions/`, `Shared/` memory layer, `Goals/`, `Research/`, `Skills/`, …), an `_Index.md` in every folder, seed memory files, and a portable AI **operating constitution** (`CLAUDE.md` / `GEMINI.md` / `AGENTS.md`) so any AI agent works with the vault consistently. It ships with research-backed operating rules — context-assembly (anti context-rot), an intake quarantine + injection-scan gate, bi-temporal fact validity, provenance tracking, a verification-gated `Skills/` library, and sleep-time consolidation. The first-run setup wizard also offers to create one.
|
|
176
|
+
|
|
177
|
+
Everything is **create-if-missing** — re-running never overwrites your notes. Point an Obsidian or filesystem MCP server at the workspace to let the agent read and write it.
|
|
178
|
+
|
|
179
|
+
## MCP
|
|
180
|
+
|
|
181
|
+
Connect Model Context Protocol servers (stdio) with the same config shape you already use elsewhere:
|
|
182
|
+
|
|
183
|
+
```jsonc
|
|
184
|
+
// ~/.sanook/mcp.json
|
|
185
|
+
{
|
|
186
|
+
"mcpServers": {
|
|
187
|
+
"filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"] }
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Their tools are merged into the agent's toolset automatically. `/tools` in the REPL lists everything currently available.
|
|
193
|
+
|
|
194
|
+
## Configuration
|
|
195
|
+
|
|
196
|
+
Everything lives under `~/.sanook/` (with per-project `.sanook/` overrides where relevant):
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
~/.sanook/auth.json API keys (chmod 600)
|
|
200
|
+
~/.sanook/memory/ auto-memory the agent writes
|
|
201
|
+
~/.sanook/sessions/ saved conversations (for --continue)
|
|
202
|
+
~/.sanook/skills/<name>/ installed SKILL.md files
|
|
203
|
+
~/.sanook/mcp.json MCP servers { "mcpServers": { … } }
|
|
204
|
+
~/.sanook/hooks.json PreToolUse / PostToolUse hooks
|
|
205
|
+
~/.sanook/gateway/ gateway token + task ledger
|
|
206
|
+
SANOOK.md project memory (hierarchical, like a system prompt)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Security
|
|
210
|
+
|
|
211
|
+
Sanook runs shell commands and edits files, so safety is built into the core rather than bolted on:
|
|
212
|
+
|
|
213
|
+
- **BYOK, direct keys only** — OAuth and subscription tokens are rejected by an explicit guard (`ya29.`, `Bearer`, `sk-ant-oat…`). This keeps you within every provider's terms of service.
|
|
214
|
+
- **Permission gate** — destructive commands (`rm -rf`, `git reset --hard`, `push --force`, fork bombs, …) and writes to protected paths are denied; interactive `ask` mode confirms mutations.
|
|
215
|
+
- **Secret redaction** — API keys are stripped from error messages and logs.
|
|
216
|
+
- **Gateway** — HTTP binds to `127.0.0.1` only and requires a bearer token on every non-health endpoint.
|
|
217
|
+
- **Telegram** — fail-closed: a required allowlist, private-chat-only, per-chat rate-limiting, and generic error replies that never reveal internal paths.
|
|
218
|
+
|
|
219
|
+
Hardened across several adversarial security reviews covering command injection, prompt injection, concurrency, and credential leakage.
|
|
220
|
+
|
|
221
|
+
## Development
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
npm install
|
|
225
|
+
npm run build # → dist/
|
|
226
|
+
npm test # vitest — 143 tests
|
|
227
|
+
npm run typecheck # tsc --noEmit (strict)
|
|
228
|
+
npm run dev -- "…" # run from source without building
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
CI runs the suite across macOS / Linux / Windows on Node 22 and 24. Requires **Node ≥ 22**.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
[Apache-2.0](LICENSE)
|
|
236
|
+
|
|
237
|
+
<div align="center">
|
|
238
|
+
<sub>Built from scratch in TypeScript on the Vercel AI SDK — no framework, no magic.</sub>
|
|
239
|
+
</div>
|
package/dist/approval.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export const approvalContext = new AsyncLocalStorage();
|
|
3
|
+
// tool ที่เปลี่ยน state จริง → ต้องขออนุมัติใน ask-mode
|
|
4
|
+
// NOTE: ต้อง sync กับ tools ที่ mutate — มี test guard ใน approval.test.ts กันหลุด
|
|
5
|
+
export const MUTATE_TOOLS = new Set([
|
|
6
|
+
'write_file',
|
|
7
|
+
'edit_file',
|
|
8
|
+
'run_bash',
|
|
9
|
+
'git_commit',
|
|
10
|
+
'schedule_task',
|
|
11
|
+
'cancel_scheduled',
|
|
12
|
+
'remember', // เขียน auto-memory ถาวร
|
|
13
|
+
'create_skill', // เขียน skill ถาวร
|
|
14
|
+
]);
|
|
15
|
+
// capability-based gate: tool ที่ "อ่านอย่างเดียว" เท่านั้นที่ผ่านโดยไม่ขออนุมัติ
|
|
16
|
+
// อย่างอื่น (รวม MCP tools ที่ไม่รู้จัก เช่น fs write / postgres DELETE) = treat as mutating → gate ใน ask-mode
|
|
17
|
+
const READ_ONLY_TOOLS = new Set([
|
|
18
|
+
'read_file',
|
|
19
|
+
'list_dir',
|
|
20
|
+
'glob',
|
|
21
|
+
'grep',
|
|
22
|
+
'recall',
|
|
23
|
+
'find_skills',
|
|
24
|
+
'skill',
|
|
25
|
+
'git_status',
|
|
26
|
+
'git_diff',
|
|
27
|
+
'git_log',
|
|
28
|
+
'list_scheduled',
|
|
29
|
+
]);
|
|
30
|
+
/** สรุป tool input เป็นบรรทัดเดียวให้ user ตัดสินใจ */
|
|
31
|
+
export function summarizeToolCall(tool, input) {
|
|
32
|
+
const i = (input ?? {});
|
|
33
|
+
switch (tool) {
|
|
34
|
+
case 'run_bash':
|
|
35
|
+
return `$ ${String(i.cmd ?? '')}`;
|
|
36
|
+
case 'write_file':
|
|
37
|
+
return `เขียนไฟล์ ${String(i.path ?? '')}`;
|
|
38
|
+
case 'edit_file':
|
|
39
|
+
return `แก้ไฟล์ ${String(i.path ?? '')}`;
|
|
40
|
+
case 'git_commit':
|
|
41
|
+
return `git commit -m "${String(i.message ?? '')}"`;
|
|
42
|
+
case 'schedule_task':
|
|
43
|
+
return `ตั้ง cron: ${String(i.when ?? '')} → ${String(i.task ?? '').slice(0, 40)}`;
|
|
44
|
+
case 'cancel_scheduled':
|
|
45
|
+
return `ยกเลิก task ${String(i.id ?? '')}`;
|
|
46
|
+
case 'remember':
|
|
47
|
+
return `จำ: ${String(i.fact ?? '').slice(0, 50)}`;
|
|
48
|
+
case 'create_skill':
|
|
49
|
+
return `สร้าง skill ${String(i.name ?? '')}`;
|
|
50
|
+
default:
|
|
51
|
+
return tool;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** ครอบ mutate tools ด้วย approval gate — ask-mode เรียก approve() ก่อน execute */
|
|
55
|
+
export function wrapToolsWithApproval(tools) {
|
|
56
|
+
const out = {};
|
|
57
|
+
for (const [name, t] of Object.entries(tools)) {
|
|
58
|
+
// read-only → ผ่าน · ที่เหลือ (mutate + MCP/unknown) → gate ใน ask-mode (deny-by-default)
|
|
59
|
+
if (READ_ONLY_TOOLS.has(name) || typeof t.execute !== 'function') {
|
|
60
|
+
out[name] = t;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const orig = t.execute;
|
|
64
|
+
out[name] = {
|
|
65
|
+
...t,
|
|
66
|
+
execute: async (input, opts) => {
|
|
67
|
+
const ctx = approvalContext.getStore();
|
|
68
|
+
if (ctx?.mode === 'ask') {
|
|
69
|
+
const ok = ctx.approve ? await ctx.approve(name, summarizeToolCall(name, input)) : false;
|
|
70
|
+
if (!ok)
|
|
71
|
+
return `⛔ ผู้ใช้ปฏิเสธการรัน ${name} (${summarizeToolCall(name, input)})`;
|
|
72
|
+
}
|
|
73
|
+
return orig(input, opts);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|