@taf0711/splice 0.1.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/LICENSE +21 -0
- package/README.md +486 -0
- package/bin/splice.js +104 -0
- package/package.json +42 -0
- package/scripts/postinstall.mjs +316 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gitlawb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/assets/splice-logo.png" alt="splice" width="560">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>A terminal coding agent with a deterministic, multi-stage pipeline.</strong></p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-blue"></a>
|
|
9
|
+
<img alt="Go 1.25+" src="https://img.shields.io/badge/Go-1.25+-00ADD8?logo=go&logoColor=white">
|
|
10
|
+
<img alt="25+ providers" src="https://img.shields.io/badge/providers-25+-34E2EA">
|
|
11
|
+
<br>
|
|
12
|
+
<strong>English</strong> | <a href="README_ZH.md">中文</a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
Splice is an AI coding agent for your local terminal. It inspects a repository,
|
|
16
|
+
edits files, runs commands, uses browser and terminal helpers, and keeps
|
|
17
|
+
durable local sessions while you choose the model and the permission level.
|
|
18
|
+
On top of that engine, Splice layers an orchestrator-mediated, schema-as-contract
|
|
19
|
+
pipeline: a request is classified, turned into a typed execution plan, and run
|
|
20
|
+
through specialized stages (code writer, static analyzer, test generator,
|
|
21
|
+
security auditor, test runner) with a deterministic trajectory monitor that
|
|
22
|
+
catches death spirals before they waste tokens.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
splice
|
|
26
|
+
splice exec "fix the failing test in ./pkg"
|
|
27
|
+
splice exec --output-format stream-json < turns.jsonl
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Why Splice
|
|
31
|
+
|
|
32
|
+
- **Use the model you want.** Bring OpenAI, Anthropic, Gemini, Groq, OpenRouter,
|
|
33
|
+
DeepSeek, Mistral, xAI, Qwen, Kimi, GitHub Models, Ollama, LM Studio, or any
|
|
34
|
+
OpenAI- or Anthropic-compatible endpoint.
|
|
35
|
+
- **A pipeline, not just a chat.** A request is classified into a tier, turned
|
|
36
|
+
into a typed execution plan, and run through specialized stages whose inputs
|
|
37
|
+
and outputs are Go structs with `Validate()` methods. The orchestrator is the
|
|
38
|
+
foreman: agents never pass data to each other directly, and summaries flow
|
|
39
|
+
forward, not raw outputs.
|
|
40
|
+
- **Deterministic-first.** Anything answerable with code (ripgrep, AST, Bandit,
|
|
41
|
+
pytest, git diff) is answered with code. The LLM is the last resort. The
|
|
42
|
+
context builder pulls real file, directory, and grep results from Zero's tool
|
|
43
|
+
registry so a stage prompt sees the workspace, not a guess.
|
|
44
|
+
- **Trajectory-aware.** A deterministic scorer watches every iteration. Hard
|
|
45
|
+
limit, budget exhaustion, state-hash cycles, oscillation, regression, and
|
|
46
|
+
confidence collapse each escalate explicitly instead of looping silently.
|
|
47
|
+
- **Stay in control.** File writes, shell commands, network access, and
|
|
48
|
+
out-of-workspace writes go through Splice's permission and sandbox policy.
|
|
49
|
+
- **Works in the terminal.** The TUI has model and provider pickers, image
|
|
50
|
+
input, slash commands, live plan and tool rendering, scrollback, themes, and
|
|
51
|
+
resume and fork support.
|
|
52
|
+
- **Works without the TUI.** `splice exec` is scriptable, supports text, JSON,
|
|
53
|
+
and stream-JSON I/O, isolated worktrees, spec-first runs, and meaningful exit
|
|
54
|
+
codes for CI.
|
|
55
|
+
- **Keeps context local.** Sessions are stored on disk, searchable, resumable,
|
|
56
|
+
and never uploaded as telemetry by Splice.
|
|
57
|
+
- **Extensible when you need it.** Use MCP servers, skills, plugins, hooks, and
|
|
58
|
+
specialist subagents from the same CLI.
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
> Packaging is a work in progress. There are no published GitHub Releases or
|
|
63
|
+
> npm packages yet, so the npm and install-script paths below are the intended
|
|
64
|
+
> flow once the first release is cut. For now, build from source.
|
|
65
|
+
|
|
66
|
+
### npm (planned)
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install -g @taf0711/splice
|
|
70
|
+
splice
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The npm package will install a small wrapper plus the matching Splice binary for
|
|
74
|
+
your platform from GitHub Releases. It will support Linux, macOS, and Windows
|
|
75
|
+
on x64 and arm64.
|
|
76
|
+
|
|
77
|
+
### Bun (planned)
|
|
78
|
+
|
|
79
|
+
Bun does not run dependency lifecycle scripts by default, so the `postinstall`
|
|
80
|
+
that fetches the Splice binary is skipped and the first run fails with
|
|
81
|
+
`No native binary found next to the npm wrapper`.
|
|
82
|
+
|
|
83
|
+
The simplest fix is to trust the package after installing, which runs the
|
|
84
|
+
blocked postinstall. This works for project and global installs:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# project install
|
|
88
|
+
bun add @taf0711/splice
|
|
89
|
+
bun pm trust @taf0711/splice
|
|
90
|
+
|
|
91
|
+
# global install
|
|
92
|
+
bun add -g @taf0711/splice
|
|
93
|
+
bun pm -g trust @taf0711/splice
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Alternatives: allow the postinstall up front by adding
|
|
97
|
+
`"trustedDependencies": ["@taf0711/splice"]` to your project's package.json
|
|
98
|
+
before `bun add`, or run the installer manually
|
|
99
|
+
(`node node_modules/@taf0711/splice/scripts/postinstall.mjs`) on Bun versions
|
|
100
|
+
that do not have `bun pm trust`.
|
|
101
|
+
|
|
102
|
+
### Install scripts (planned)
|
|
103
|
+
|
|
104
|
+
Linux/macOS:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
curl -fsSL https://raw.githubusercontent.com/Taf0711/splice/main/scripts/install.sh | bash
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Windows PowerShell:
|
|
111
|
+
|
|
112
|
+
```powershell
|
|
113
|
+
irm https://raw.githubusercontent.com/Taf0711/splice/main/scripts/install.ps1 | iex
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### From source (works today)
|
|
117
|
+
|
|
118
|
+
Source builds require Go 1.25+.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
git clone https://github.com/Taf0711/splice.git
|
|
122
|
+
cd splice
|
|
123
|
+
go run ./cmd/splice
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
If you are testing before the first public release, build from source:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
go build -o splice ./cmd/splice
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
On Linux, build the sandbox helper too if you want native sandboxing:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
go build -o splice-linux-sandbox ./cmd/splice-linux-sandbox
|
|
136
|
+
go build -o splice-seccomp ./cmd/splice-seccomp # optional compatibility wrapper
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Put `splice` and `splice-linux-sandbox` in the same directory on `PATH`
|
|
140
|
+
(`~/.local/bin` is a good default). macOS does not need an extra helper binary.
|
|
141
|
+
Windows source builds can use the main `splice.exe` as their sandbox helper;
|
|
142
|
+
release archives will still ship standalone Windows helper executables.
|
|
143
|
+
|
|
144
|
+
More install details: [docs/INSTALL.md](docs/INSTALL.md).
|
|
145
|
+
|
|
146
|
+
## First Run
|
|
147
|
+
|
|
148
|
+
Start the TUI:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
splice
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The setup wizard helps you pick a provider and model. You can also configure
|
|
155
|
+
providers from the command line:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
splice setup
|
|
159
|
+
splice providers list
|
|
160
|
+
splice models list
|
|
161
|
+
splice doctor
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
For API providers, set the matching environment variable before setup or enter
|
|
165
|
+
the key in the wizard:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
export OPENAI_API_KEY=sk-...
|
|
169
|
+
export ANTHROPIC_API_KEY=...
|
|
170
|
+
export GEMINI_API_KEY=...
|
|
171
|
+
export LONGCAT_API_KEY=...
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
To configure Meituan LongCat (LongCat-2.0) directly, run:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
splice providers setup longcat --set-active
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
For local models, run Ollama or LM Studio and then use `splice setup` or
|
|
181
|
+
`splice providers detect`. Model-backed pipeline stages require tool-calling
|
|
182
|
+
support. If a model omits the required typed tool call or returns invalid JSON,
|
|
183
|
+
Splice gives it up to two corrective retries and then reports an actionable
|
|
184
|
+
error. Splice never falls back from a local model to a cloud provider.
|
|
185
|
+
|
|
186
|
+
## Daily Use
|
|
187
|
+
|
|
188
|
+
### Interactive TUI
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
splice
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Useful controls:
|
|
195
|
+
|
|
196
|
+
| Control | Action |
|
|
197
|
+
|---|---|
|
|
198
|
+
| `Enter` | send the prompt |
|
|
199
|
+
| `/` | open slash-command suggestions |
|
|
200
|
+
| `Shift+Tab` | cycle permission mode |
|
|
201
|
+
| `Ctrl+B` | show/hide the sidebar |
|
|
202
|
+
| `Ctrl+C` | cancel or exit |
|
|
203
|
+
|
|
204
|
+
Common slash commands:
|
|
205
|
+
|
|
206
|
+
| Command | Purpose |
|
|
207
|
+
|---|---|
|
|
208
|
+
| `/model`, `/provider` | switch the active model/provider |
|
|
209
|
+
| `/stages` | route the model-backed code writer and test generator, plus defaults and escalation |
|
|
210
|
+
| `/spec`, `/plan` | draft and review a plan before building |
|
|
211
|
+
| `/image` | attach an image for vision-capable models |
|
|
212
|
+
| `/resume`, `/rewind` | continue or roll back local sessions |
|
|
213
|
+
| `/loop` | repeat a prompt or custom `/command` on an interval (`/loop 5m /babysit-prs`) or self-paced |
|
|
214
|
+
| `/compact`, `/context` | manage context usage |
|
|
215
|
+
| `/permissions`, `/tools` | inspect available tools and policy |
|
|
216
|
+
| `/add-dir` | allow an extra write directory for this session |
|
|
217
|
+
| `/theme`, `/doctor`, `/config` | adjust appearance and inspect setup |
|
|
218
|
+
|
|
219
|
+
### Headless `exec`
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
splice exec "explain internal/agent/loop.go"
|
|
223
|
+
splice exec --model claude-sonnet-4.5 "refactor the config loader"
|
|
224
|
+
splice exec --use-spec "add rate limiting to the API client"
|
|
225
|
+
splice exec --worktree "try the migration in an isolated worktree"
|
|
226
|
+
splice exec --worktree --merge-back "run it isolated, then merge the result back"
|
|
227
|
+
splice exec --plan design-plan.json
|
|
228
|
+
splice exec --resume
|
|
229
|
+
splice exec --fork <session-id> "try the other approach"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`--plan` executes a design plan JSON file: tasks are ordered topologically by
|
|
233
|
+
their dependencies and each task runs as its own pipeline run, failing fast on
|
|
234
|
+
the first task that does not complete. `--merge-back` (requires `--worktree`)
|
|
235
|
+
commits the worktree's work, pins a `splice/<name>` recovery branch, and merges
|
|
236
|
+
into the source repo with `--no-ff`; a dirty source tree or a merge conflict
|
|
237
|
+
never forces anything, and the recovery branch survives every non-merged case.
|
|
238
|
+
|
|
239
|
+
Programmatic use:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
splice exec --input-format stream-json --output-format stream-json < turns.jsonl
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The stream-JSON contract is documented in
|
|
246
|
+
[docs/STREAM_JSON_PROTOCOL.md](docs/STREAM_JSON_PROTOCOL.md).
|
|
247
|
+
|
|
248
|
+
## The Pipeline
|
|
249
|
+
|
|
250
|
+
Splice's distinguishing layer is the deterministic pipeline in
|
|
251
|
+
`internal/splice/`. It is ported from the Flug paradigm (Flug is the archived
|
|
252
|
+
Python predecessor; see `AGENTS.zero.md` and the plans under `plans/` for
|
|
253
|
+
history) and built new in Go on top of Zero's engine.
|
|
254
|
+
|
|
255
|
+
The flow:
|
|
256
|
+
|
|
257
|
+
1. **Classify.** `ClassifyRequest` inspects the request and assigns one of five
|
|
258
|
+
tiers (trivial, light, standard, substantial, architectural) using
|
|
259
|
+
keyword and risk-domain detection with rune-count thresholds that match the
|
|
260
|
+
Python source.
|
|
261
|
+
2. **Plan.** `BuildExecutionPlan` turns the tier into a typed `ExecutionPlan`
|
|
262
|
+
with per-stage `TokenBudget` allocations. Unknown tiers fail loudly with an
|
|
263
|
+
error, matching Python's `KeyError`.
|
|
264
|
+
3. **Fulfill context.** Before a stage runs, its `ContextRequest` is fulfilled
|
|
265
|
+
deterministically through `FulfillContextRequest`, which calls Zero's real
|
|
266
|
+
`tools.Registry` (`read_file`, `list_directory`, `grep`). All six legal query
|
|
267
|
+
types are handled; payloads are text, truncation is rune-safe, and a failed
|
|
268
|
+
tool becomes an errored `ContextItem` rather than a silent empty payload.
|
|
269
|
+
4. **Run stages.** Each pipeline stage is a typed Go function in
|
|
270
|
+
`internal/splice/stages/`. The code writer and test generator call the
|
|
271
|
+
configured provider. Static analysis, security audit, and test execution are
|
|
272
|
+
model-free and run through deterministic local tools. The `splicerun.Run`
|
|
273
|
+
orchestrator drives them under Zero's full callback contract (streaming,
|
|
274
|
+
usage, tool call/result pairs, permission events) and is wired into headless
|
|
275
|
+
`splice exec`.
|
|
276
|
+
5. **Monitor trajectory.** `ComputeIterationState` builds a state vector from
|
|
277
|
+
stage outputs; `EvaluateTrajectory` scores it and decides continue,
|
|
278
|
+
escalate, rollback, step back, or surface to user. Repeated state hashes
|
|
279
|
+
escalate as a cycle, including empty hashes, so an orchestrator bug surfaces
|
|
280
|
+
loudly instead of looping.
|
|
281
|
+
6. **Iterate or abort.** The orchestrator acts on the trajectory decision.
|
|
282
|
+
Failures are typed, not swallowed: a malformed stage payload names the data
|
|
283
|
+
key and offending index.
|
|
284
|
+
|
|
285
|
+
Everything in `internal/splice/` is deterministic Go with full test coverage:
|
|
286
|
+
JSON round-trip tests cover every `Validate()`-bearing struct, and the context
|
|
287
|
+
builder has an end-to-end test against the real tool registry.
|
|
288
|
+
|
|
289
|
+
## Safety Model
|
|
290
|
+
|
|
291
|
+
Splice is designed to make side effects visible.
|
|
292
|
+
|
|
293
|
+
- Workspace reads are allowed by default.
|
|
294
|
+
- File writes are limited to the workspace unless you grant another directory.
|
|
295
|
+
- Shell commands, network access, destructive commands, and elevated actions are
|
|
296
|
+
permission-gated.
|
|
297
|
+
- `--add-dir <path>` and `/add-dir <path>` grant additional write roots without
|
|
298
|
+
giving the agent the whole filesystem.
|
|
299
|
+
- Unsafe and autonomous modes are explicit opt-ins.
|
|
300
|
+
- Secrets are redacted from tool output and logs where Splice controls the
|
|
301
|
+
surface.
|
|
302
|
+
|
|
303
|
+
Example:
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
splice --add-dir ../docs-site
|
|
307
|
+
splice exec --add-dir ../shared "update both repos"
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Sandbox behavior can be inspected with:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
splice sandbox policy
|
|
314
|
+
splice sandbox grants list
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Web And Local Control
|
|
318
|
+
|
|
319
|
+
Splice includes local file, search, edit, and shell tools, `web_fetch` for
|
|
320
|
+
public URLs, and MCP support for additional tools.
|
|
321
|
+
|
|
322
|
+
For local dev servers, use shell commands such as `curl` through `exec_command`
|
|
323
|
+
so the normal sandbox and permission policy applies. Long-running commands stay
|
|
324
|
+
attached to a background terminal session and can be listed or stopped from the
|
|
325
|
+
TUI.
|
|
326
|
+
|
|
327
|
+
The npm package will also include browser and terminal helper packages used by
|
|
328
|
+
local browser and terminal tools. Source builds can use the same helpers when
|
|
329
|
+
they are on `PATH` or configured in Splice's local-control settings.
|
|
330
|
+
|
|
331
|
+
## Common Commands
|
|
332
|
+
|
|
333
|
+
```text
|
|
334
|
+
splice interactive TUI
|
|
335
|
+
splice exec one-shot or scripted agent run
|
|
336
|
+
splice setup first-run provider setup
|
|
337
|
+
splice auth OAuth/login helpers for supported providers
|
|
338
|
+
splice login subscription login helpers for supported providers
|
|
339
|
+
splice models model registry and capabilities
|
|
340
|
+
splice providers provider profiles and detection
|
|
341
|
+
splice doctor setup, key, and connectivity checks
|
|
342
|
+
splice context context-budget report
|
|
343
|
+
splice repo-map deterministic repository map
|
|
344
|
+
splice repo-info local repository summary
|
|
345
|
+
splice search | find search local session history
|
|
346
|
+
splice sessions inspect, resume, fork, and rewind sessions
|
|
347
|
+
splice spec manage spec-mode drafts
|
|
348
|
+
splice specialist manage specialist subagents
|
|
349
|
+
splice skills manage markdown instruction skills
|
|
350
|
+
splice plugins manage plugins
|
|
351
|
+
splice hooks manage lifecycle hooks
|
|
352
|
+
splice mcp manage MCP servers and tools
|
|
353
|
+
splice serve --mcp expose Splice tools over MCP stdio
|
|
354
|
+
splice sandbox inspect sandbox policy and grants
|
|
355
|
+
splice worktrees prepare isolated git worktrees
|
|
356
|
+
splice verify detect and run local verification checks
|
|
357
|
+
splice changes inspect and commit local git changes
|
|
358
|
+
splice usage token usage and estimated cost
|
|
359
|
+
splice cron scheduled agent jobs
|
|
360
|
+
splice update check for newer releases
|
|
361
|
+
splice upgrade apply a newer release
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Extending Splice
|
|
365
|
+
|
|
366
|
+
### Project and personal instructions
|
|
367
|
+
|
|
368
|
+
Splice appends project-specific guidance to the system prompt from the first
|
|
369
|
+
`AGENTS.md`, `SPLICE.md`, or `.splice/AGENTS.md` file found in each directory
|
|
370
|
+
from the git root down to your current working directory (checked in that order
|
|
371
|
+
per directory). Files are injected general-to-specific, capped at 8 KiB per
|
|
372
|
+
file and 32 KiB total.
|
|
373
|
+
|
|
374
|
+
A personal `SPLICE.md` under
|
|
375
|
+
`config.UserConfigDir()/splice/SPLICE.md`
|
|
376
|
+
(`$XDG_CONFIG_HOME/splice/SPLICE.md` or `~/.config/splice/SPLICE.md` on
|
|
377
|
+
Linux/macOS, `%AppData%\Roaming\splice\SPLICE.md` on Windows) applies across
|
|
378
|
+
every workspace, ahead of any project guidelines.
|
|
379
|
+
|
|
380
|
+
### Plugins
|
|
381
|
+
|
|
382
|
+
Plugins are discovered from
|
|
383
|
+
`~/.config/splice/plugins/<name>/plugin.json` (user scope, `$XDG_CONFIG_HOME`
|
|
384
|
+
or `~/.config` on every OS, independent of the `config.UserConfigDir()` path
|
|
385
|
+
used above) and `<cwd>/.splice/plugins/<name>/plugin.json` (project scope,
|
|
386
|
+
resolved from the current working directory, not the repo root), and managed
|
|
387
|
+
with `splice plugins`. A manifest can declare:
|
|
388
|
+
|
|
389
|
+
- `tools` — custom tools (`command`, `args`, `inputSchema`, and a
|
|
390
|
+
`permission` of `prompt` or `deny`; `allow` is honored only when manifest
|
|
391
|
+
tool auto-approval is enabled)
|
|
392
|
+
- `hooks` — commands run on `beforeTool`, `afterTool`, `sessionStart`, or
|
|
393
|
+
`sessionEnd`
|
|
394
|
+
- `prompts` and `skills` — additional prompt and skill files
|
|
395
|
+
|
|
396
|
+
MCP servers (`splice mcp`) and standalone markdown skills (`splice skills`)
|
|
397
|
+
use the same extension points and can also be wired up outside of a plugin
|
|
398
|
+
manifest.
|
|
399
|
+
|
|
400
|
+
## Appearance And Accessibility
|
|
401
|
+
|
|
402
|
+
| Control | Effect |
|
|
403
|
+
|---|---|
|
|
404
|
+
| `NO_COLOR=<anything>` | disables color output |
|
|
405
|
+
| `ZERO_THEME=<name>` | selects the startup theme (`auto`, `dark`, `light`, or a color theme like `dracula`, `nord`, `gruvbox`, `tokyo-night`, `catppuccin`, `one-dark`, `solarized-dark`, `rose-pine`, `everforest`, `solarized-light`) |
|
|
406
|
+
| `--theme <name>` | selects the TUI theme from the CLI (same names) |
|
|
407
|
+
| `/theme` | opens the theme picker inside the TUI (live preview; `/theme <name>` switches directly) |
|
|
408
|
+
| `ZERO_NO_FADE=1` | disables streaming fade animation |
|
|
409
|
+
|
|
410
|
+
> Note: the theme environment variables still use the `ZERO_` prefix from the
|
|
411
|
+
> upstream engine. A rename to `SPLICE_` is planned but not yet applied; both
|
|
412
|
+
> names will be accepted during a transition.
|
|
413
|
+
|
|
414
|
+
Meaning does not rely on color alone; diffs, permissions, and statuses also use
|
|
415
|
+
text or glyph markers.
|
|
416
|
+
|
|
417
|
+
## Development
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
go test ./...
|
|
421
|
+
go run ./cmd/splice-release build
|
|
422
|
+
go run ./cmd/splice-release smoke
|
|
423
|
+
go run ./cmd/splice-perf-bench
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
Cross-compile examples:
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
go run ./cmd/splice-release build --goos linux --goarch amd64
|
|
430
|
+
go run ./cmd/splice-release build --goos windows --goarch amd64 --output dist/splice.exe
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
The deterministic pipeline layer lives in `internal/splice/` and is pure Go
|
|
434
|
+
with no provider SDK imports. Its packages:
|
|
435
|
+
|
|
436
|
+
- `internal/splice/schemas/` — typed stage and pipeline structs with
|
|
437
|
+
`Validate()` methods.
|
|
438
|
+
- `internal/splice/classifier.go` — request-to-tier classification.
|
|
439
|
+
- `internal/splice/planner.go` — tier-to-execution-plan, intent distillation.
|
|
440
|
+
- `internal/splice/budget.go` — per-tier token budgets.
|
|
441
|
+
- `internal/splice/trajectory.go` — iteration state, scoring, trajectory
|
|
442
|
+
decisions.
|
|
443
|
+
- `internal/splice/context.go` + `registry_runner.go` — deterministic context
|
|
444
|
+
fulfillment through Zero's tool registry.
|
|
445
|
+
- `internal/splice/stages/`: the stage agents (code writer, static analyzer,
|
|
446
|
+
test generator, security auditor, test runner, design conversation, plan
|
|
447
|
+
critic) with embedded prompts.
|
|
448
|
+
- `internal/splice/run.go`: the `splicerun.Run` orchestrator loop.
|
|
449
|
+
- `internal/splice/design_runner.go`: `RunDesignPlan`, topological task
|
|
450
|
+
sequencing for `splice exec --plan`.
|
|
451
|
+
|
|
452
|
+
Adjacent Splice-specific pieces: `internal/worktrees/` adds `MergeBack` on top
|
|
453
|
+
of Zero's worktree lifecycle, `memd/` is the memory sidecar (its own Go module,
|
|
454
|
+
binary `splice-memd`, SQLite/FTS5 over a Unix socket), and `internal/memd/` is
|
|
455
|
+
the sidecar's HTTP client (complete).
|
|
456
|
+
|
|
457
|
+
## Documentation
|
|
458
|
+
|
|
459
|
+
- [Install](docs/INSTALL.md)
|
|
460
|
+
- [Update flow](docs/UPDATE.md)
|
|
461
|
+
- [Stream-JSON protocol](docs/STREAM_JSON_PROTOCOL.md)
|
|
462
|
+
- [Specialists](docs/SPECIALISTS.md)
|
|
463
|
+
- [GitHub Action](docs/GITHUB_ACTION.md)
|
|
464
|
+
- [Benchmarks](docs/BENCHMARK.md)
|
|
465
|
+
- [Performance](docs/PERFORMANCE.md)
|
|
466
|
+
- [Agent evals](docs/AGENT_EVALS.md)
|
|
467
|
+
|
|
468
|
+
## Contributing
|
|
469
|
+
|
|
470
|
+
Contributions are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md), run the
|
|
471
|
+
relevant tests, and open a focused pull request.
|
|
472
|
+
|
|
473
|
+
Security reports should follow [SECURITY.md](SECURITY.md).
|
|
474
|
+
|
|
475
|
+
## License
|
|
476
|
+
|
|
477
|
+
Splice is released under the [MIT License](LICENSE).
|
|
478
|
+
|
|
479
|
+
## Attribution
|
|
480
|
+
|
|
481
|
+
Splice is built on top of [Gitlawb's Zero CLI](https://github.com/gitlawb/zero),
|
|
482
|
+
an open-source MIT-licensed terminal coding agent. Splice extends Zero's engine
|
|
483
|
+
with a deterministic, orchestrator-mediated multi-stage pipeline paradigm ported
|
|
484
|
+
from the archived Flug prototype. All upstream Zero code retains its original
|
|
485
|
+
copyright and license. See [UPSTREAM.md](UPSTREAM.md) for the full divergence
|
|
486
|
+
list and the upstream sync procedure.
|
package/bin/splice.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
function spliceBinaryName(platform = process.platform) {
|
|
9
|
+
return platform === 'win32' ? 'splice.exe' : 'splice';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function helperShimNames(name, platform = process.platform) {
|
|
13
|
+
if (platform === 'win32') {
|
|
14
|
+
return [`${name}.cmd`, `${name}.exe`, name];
|
|
15
|
+
}
|
|
16
|
+
return [name];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function commandForShim(path, platform = process.platform) {
|
|
20
|
+
if (platform === 'win32' && path.toLowerCase().endsWith('.cmd')) {
|
|
21
|
+
return {
|
|
22
|
+
command: process.env.ComSpec || 'cmd.exe',
|
|
23
|
+
prefixArgs: ['/d', '/s', '/c', `"${path.replace(/"/g, '""')}"`],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { command: path, prefixArgs: [] };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resolveHelper(packageRoot, name) {
|
|
30
|
+
const binDir = join(packageRoot, 'node_modules', '.bin');
|
|
31
|
+
for (const shimName of helperShimNames(name)) {
|
|
32
|
+
const candidate = join(binDir, shimName);
|
|
33
|
+
if (!existsSync(candidate)) continue;
|
|
34
|
+
return {
|
|
35
|
+
...commandForShim(candidate),
|
|
36
|
+
pathPrepend: [binDir],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function localControlHelperManifest(packageRoot) {
|
|
43
|
+
const helpers = {};
|
|
44
|
+
for (const name of ['agent-browser', 'tuistory']) {
|
|
45
|
+
const helper = resolveHelper(packageRoot, name);
|
|
46
|
+
if (helper) helpers[name] = helper;
|
|
47
|
+
}
|
|
48
|
+
if (Object.keys(helpers).length === 0) return '';
|
|
49
|
+
return JSON.stringify({ version: 1, helpers });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
53
|
+
const nativePath = join(packageRoot, spliceBinaryName());
|
|
54
|
+
const localControlHelpers = localControlHelperManifest(packageRoot);
|
|
55
|
+
|
|
56
|
+
if (!existsSync(nativePath)) {
|
|
57
|
+
const postinstallScript = join(packageRoot, 'scripts', 'postinstall.mjs');
|
|
58
|
+
const ranByBun = process.execPath.includes('bun') || !!process.versions?.bun;
|
|
59
|
+
console.error(
|
|
60
|
+
'[splice] No native binary found next to the npm wrapper.\n' +
|
|
61
|
+
'The platform binary is fetched at install time by a postinstall script,\n' +
|
|
62
|
+
'which did not run (or was skipped) for this install.\n' +
|
|
63
|
+
'\n' +
|
|
64
|
+
'Fix it now by running the installer manually:\n' +
|
|
65
|
+
` node "${postinstallScript}"\n` +
|
|
66
|
+
'\n' +
|
|
67
|
+
(ranByBun
|
|
68
|
+
? 'You installed with Bun, which does not run dependency lifecycle scripts\n' +
|
|
69
|
+
'by default. Trust the package to run the blocked postinstall:\n' +
|
|
70
|
+
' bun pm trust @taf0711/splice (project install)\n' +
|
|
71
|
+
' bun pm -g trust @taf0711/splice (global install)\n' +
|
|
72
|
+
'On Bun versions without `bun pm trust`, add\n' +
|
|
73
|
+
' "trustedDependencies": ["@taf0711/splice"]\n' +
|
|
74
|
+
'to your project package.json and reinstall.\n' +
|
|
75
|
+
'\n'
|
|
76
|
+
: '') +
|
|
77
|
+
'If that fails, build from source: https://github.com/Taf0711/splice\n' +
|
|
78
|
+
'(go run ./cmd/splice, requires Go 1.25+).',
|
|
79
|
+
);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const env = { ...process.env };
|
|
84
|
+
if (localControlHelpers) {
|
|
85
|
+
env.ZERO_LOCAL_CONTROL_HELPERS = localControlHelpers;
|
|
86
|
+
} else {
|
|
87
|
+
delete env.ZERO_LOCAL_CONTROL_HELPERS;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const child = spawnSync(nativePath, process.argv.slice(2), {
|
|
91
|
+
stdio: 'inherit',
|
|
92
|
+
env,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (child.error) {
|
|
96
|
+
console.error(`[splice] Failed to launch wrapper target: ${child.error.message}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (child.signal) {
|
|
101
|
+
process.kill(process.pid, child.signal);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
process.exit(child.status ?? 1);
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@taf0711/splice",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Splice — a fast, multi-provider terminal coding agent.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "bin/splice.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"splice": "bin/splice.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node scripts/postinstall.mjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/splice.js",
|
|
15
|
+
"scripts/postinstall.mjs"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=24"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"agent-browser": "^0.30.1",
|
|
22
|
+
"tuistory": "^0.10.0"
|
|
23
|
+
},
|
|
24
|
+
"os": [
|
|
25
|
+
"linux",
|
|
26
|
+
"darwin",
|
|
27
|
+
"win32"
|
|
28
|
+
],
|
|
29
|
+
"cpu": [
|
|
30
|
+
"x64",
|
|
31
|
+
"arm64"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/Taf0711/splice.git"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/Taf0711/splice#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/Taf0711/splice/issues"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT"
|
|
42
|
+
}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// postinstall: fetch the prebuilt `splice` binary for this platform from the
|
|
3
|
+
// matching GitHub Release and place it next to bin/splice.js, which execs it.
|
|
4
|
+
//
|
|
5
|
+
// Mirrors scripts/install.sh and scripts/install.ps1. The asset-name scheme is
|
|
6
|
+
// the source of truth in internal/release/release.go:
|
|
7
|
+
// splice-v{version}-{linux|macos|windows}-{x64|arm64}.{tar.gz|zip} (+ .sha256)
|
|
8
|
+
//
|
|
9
|
+
// Safety: HTTPS-only download from the pinned repo, SHA-256 verification against
|
|
10
|
+
// the release's own .sha256, and extraction that never trusts archive paths —
|
|
11
|
+
// we extract to a temp dir and copy only known binary basenames into place, so a
|
|
12
|
+
// crafted archive cannot write outside the package (no zip-slip).
|
|
13
|
+
//
|
|
14
|
+
// Env overrides (testing / mirrors / locked-down installs):
|
|
15
|
+
// ZERO_SKIP_DOWNLOAD=1 skip entirely, exit 0 (wrapper will guide if run)
|
|
16
|
+
// SPLICE_INSTALL_DRY_RUN=1 print the resolved plan as JSON, no network, exit 0
|
|
17
|
+
// SPLICE_INSTALL_PLATFORM=… override process.platform (linux|darwin|win32|android)
|
|
18
|
+
// SPLICE_INSTALL_ARCH=… override process.arch (x64|arm64)
|
|
19
|
+
// SPLICE_REPO=owner/name override the GitHub repo (default Taf0711/splice)
|
|
20
|
+
// ZERO_GITHUB_BASE_URL=… override the download host (default https://github.com)
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
chmodSync,
|
|
24
|
+
copyFileSync,
|
|
25
|
+
existsSync,
|
|
26
|
+
mkdirSync,
|
|
27
|
+
mkdtempSync,
|
|
28
|
+
readdirSync,
|
|
29
|
+
readFileSync,
|
|
30
|
+
rmSync,
|
|
31
|
+
statSync,
|
|
32
|
+
writeFileSync,
|
|
33
|
+
} from 'node:fs';
|
|
34
|
+
import { createHash } from 'node:crypto';
|
|
35
|
+
import { tmpdir } from 'node:os';
|
|
36
|
+
import { dirname, join } from 'node:path';
|
|
37
|
+
import { fileURLToPath } from 'node:url';
|
|
38
|
+
import { spawnSync } from 'node:child_process';
|
|
39
|
+
|
|
40
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
41
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'));
|
|
42
|
+
const VERSION = pkg.version;
|
|
43
|
+
|
|
44
|
+
const REPO = process.env.SPLICE_REPO || 'Taf0711/splice';
|
|
45
|
+
const BASE = (process.env.ZERO_GITHUB_BASE_URL || 'https://github.com').replace(/\/+$/, '');
|
|
46
|
+
// The .sha256 is fetched from the same origin as the archive, so TLS authenticity
|
|
47
|
+
// is the only real integrity control — require https unless explicitly overridden
|
|
48
|
+
// for local testing (e.g. a localhost mirror in tests).
|
|
49
|
+
const ALLOW_INSECURE = process.env.ZERO_ALLOW_INSECURE_DOWNLOAD === '1';
|
|
50
|
+
const MAX_DOWNLOAD_BYTES = 512 * 1024 * 1024;
|
|
51
|
+
|
|
52
|
+
function fail(message) {
|
|
53
|
+
console.error(`[splice] ${message}`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function warnSkip(message) {
|
|
58
|
+
// Exit 0 so an unsupported platform or an opt-out does not break `npm install`;
|
|
59
|
+
// bin/splice.js reports a clear "no native binary" message if the user runs splice.
|
|
60
|
+
console.error(`[splice] ${message}`);
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Maps mirror internal/release/release.go (ReleasePlatform / ReleaseArch).
|
|
65
|
+
function resolvePlatform(p) {
|
|
66
|
+
switch (p) {
|
|
67
|
+
case 'linux':
|
|
68
|
+
return 'linux';
|
|
69
|
+
case 'darwin':
|
|
70
|
+
return 'macos';
|
|
71
|
+
case 'win32':
|
|
72
|
+
return 'windows';
|
|
73
|
+
default:
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function resolveArch(a) {
|
|
79
|
+
switch (a) {
|
|
80
|
+
case 'x64':
|
|
81
|
+
return 'x64';
|
|
82
|
+
case 'arm64':
|
|
83
|
+
return 'arm64';
|
|
84
|
+
default:
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (process.env.ZERO_SKIP_DOWNLOAD === '1') {
|
|
90
|
+
warnSkip('ZERO_SKIP_DOWNLOAD=1 set — skipping native binary download.');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const rawPlatform = process.env.SPLICE_INSTALL_PLATFORM || process.platform;
|
|
94
|
+
const rawArch = process.env.SPLICE_INSTALL_ARCH || process.arch;
|
|
95
|
+
|
|
96
|
+
// Android is unsupported: there is no prebuilt Splice binary for Android and the
|
|
97
|
+
// npm package no longer declares android in its `os` array, so installs are
|
|
98
|
+
// skipped there by npm itself. Fail loudly if a manual/forced run targets it.
|
|
99
|
+
if (rawPlatform === 'android') {
|
|
100
|
+
fail(
|
|
101
|
+
`Android is unsupported: there is no prebuilt Splice binary for Android. ` +
|
|
102
|
+
`Build from source: https://github.com/${REPO} (go run ./cmd/splice).`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const platform = resolvePlatform(rawPlatform);
|
|
107
|
+
const arch = resolveArch(rawArch);
|
|
108
|
+
|
|
109
|
+
if (!platform || !arch) {
|
|
110
|
+
warnSkip(
|
|
111
|
+
`no prebuilt binary for ${rawPlatform}/${rawArch}. Build from source: ` +
|
|
112
|
+
`https://github.com/${REPO} (go run ./cmd/splice).`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// The release matrix builds linux/macos {x64,arm64} and windows-x64 — there is no
|
|
117
|
+
// windows-arm64 artifact. (win32, arm64) otherwise resolves to a valid
|
|
118
|
+
// platform/arch, so it would proceed to download a non-existent asset and hard
|
|
119
|
+
// -fail npm install on a 404. Guard it explicitly to skip gracefully; Windows on
|
|
120
|
+
// ARM runs the x64 build under emulation, so the x64 package is the fallback.
|
|
121
|
+
if (platform === 'windows' && arch === 'arm64') {
|
|
122
|
+
warnSkip(
|
|
123
|
+
`no prebuilt binary for windows-arm64 (the windows-x64 build runs under ` +
|
|
124
|
+
`emulation on Windows on ARM). Build from source or install the x64 package: ` +
|
|
125
|
+
`https://github.com/${REPO} (go run ./cmd/splice).`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const ext = platform === 'windows' ? 'zip' : 'tar.gz';
|
|
130
|
+
const binaryName = platform === 'windows' ? 'splice.exe' : 'splice';
|
|
131
|
+
const tag = `v${VERSION}`;
|
|
132
|
+
const assetName = `splice-v${VERSION}-${platform}-${arch}.${ext}`;
|
|
133
|
+
const assetUrl = `${BASE}/${REPO}/releases/download/${tag}/${assetName}`;
|
|
134
|
+
const checksumUrl = `${assetUrl}.sha256`;
|
|
135
|
+
|
|
136
|
+
// Extra binaries the archive may carry; copied when present so the platform
|
|
137
|
+
// sandbox finds its adjacent helpers (tier-1 discovery), but never required.
|
|
138
|
+
const optionalBinaries =
|
|
139
|
+
platform === 'windows'
|
|
140
|
+
? ['splice-windows-command-runner.exe', 'splice-windows-sandbox-setup.exe']
|
|
141
|
+
: platform === 'linux'
|
|
142
|
+
? ['splice-linux-sandbox', 'splice-seccomp']
|
|
143
|
+
: [];
|
|
144
|
+
|
|
145
|
+
if (process.env.SPLICE_INSTALL_DRY_RUN === '1') {
|
|
146
|
+
process.stdout.write(
|
|
147
|
+
JSON.stringify({
|
|
148
|
+
version: VERSION,
|
|
149
|
+
platform,
|
|
150
|
+
arch,
|
|
151
|
+
tag,
|
|
152
|
+
assetName,
|
|
153
|
+
assetUrl,
|
|
154
|
+
checksumUrl,
|
|
155
|
+
binaryName,
|
|
156
|
+
optionalBinaries,
|
|
157
|
+
}) + '\n',
|
|
158
|
+
);
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Idempotent: skip if the binary for this exact version is already in place.
|
|
163
|
+
const markerPath = join(packageRoot, '.splice-binary-version');
|
|
164
|
+
const installedBinary = join(packageRoot, binaryName);
|
|
165
|
+
if (
|
|
166
|
+
existsSync(installedBinary) &&
|
|
167
|
+
existsSync(markerPath) &&
|
|
168
|
+
readFileSync(markerPath, 'utf8').trim() === VERSION
|
|
169
|
+
) {
|
|
170
|
+
process.exit(0);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function download(url) {
|
|
174
|
+
if (!ALLOW_INSECURE && !url.startsWith('https://')) {
|
|
175
|
+
fail(
|
|
176
|
+
`refusing insecure download origin for ${url}: only https:// is allowed ` +
|
|
177
|
+
`(set ZERO_ALLOW_INSECURE_DOWNLOAD=1 to override for local testing).`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
let response;
|
|
181
|
+
try {
|
|
182
|
+
response = await fetch(url, { redirect: 'follow' });
|
|
183
|
+
} catch (error) {
|
|
184
|
+
fail(`download failed for ${url}: ${error.message}`);
|
|
185
|
+
}
|
|
186
|
+
// Catch an https->http downgrade across redirects: the verified bytes must
|
|
187
|
+
// still have arrived over TLS for the same-origin checksum to mean anything.
|
|
188
|
+
if (!ALLOW_INSECURE && response.url && !response.url.startsWith('https://')) {
|
|
189
|
+
fail(`refusing insecure redirect to ${response.url}`);
|
|
190
|
+
}
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
fail(
|
|
193
|
+
`download failed (HTTP ${response.status}) for ${url} (release tag ${tag}). ` +
|
|
194
|
+
`If no release exists yet, or the tag and package.json version disagree, ` +
|
|
195
|
+
`build from source: https://github.com/${REPO} (go run ./cmd/splice).`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const declared = Number(response.headers.get('content-length') || 0);
|
|
199
|
+
if (declared && declared > MAX_DOWNLOAD_BYTES) {
|
|
200
|
+
fail(`refusing oversized download (${declared} bytes) from ${url}`);
|
|
201
|
+
}
|
|
202
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
203
|
+
if (buffer.length > MAX_DOWNLOAD_BYTES) {
|
|
204
|
+
fail(`download from ${url} exceeded ${MAX_DOWNLOAD_BYTES} bytes`);
|
|
205
|
+
}
|
|
206
|
+
return buffer;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Parse a sha256sum-style file. Anchored per line, and when the line carries a
|
|
210
|
+
// filename field it must equal the requested asset — mirrors the Go
|
|
211
|
+
// ParseSHA256Checksum so a checksum file cannot misattribute a digest.
|
|
212
|
+
function parseSha256(text, wantName) {
|
|
213
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
214
|
+
const line = rawLine.trim();
|
|
215
|
+
if (!line) continue;
|
|
216
|
+
const match = line.match(/^([a-fA-F0-9]{64})(?:\s+\*?(.+))?$/);
|
|
217
|
+
if (!match) continue;
|
|
218
|
+
const [, hex, name] = match;
|
|
219
|
+
if (!name || name.trim() === wantName) {
|
|
220
|
+
return hex.toLowerCase();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
fail(`could not find a SHA-256 digest for ${wantName} in ${wantName}.sha256`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function findByBasename(dir, name) {
|
|
227
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
228
|
+
const full = join(dir, entry.name);
|
|
229
|
+
if (entry.isDirectory()) {
|
|
230
|
+
const nested = findByBasename(full, name);
|
|
231
|
+
if (nested) return nested;
|
|
232
|
+
} else if (entry.name === name) {
|
|
233
|
+
return full;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// extract runs from `workDir` and passes RELATIVE names so no Windows drive
|
|
240
|
+
// letter (e.g. C:\) appears in tar's archive argument — GNU tar otherwise reads
|
|
241
|
+
// `C:foo` as a remote `host:path` and fails. archiveName and destName are both
|
|
242
|
+
// relative to workDir.
|
|
243
|
+
function extract(workDir, archiveName, destName) {
|
|
244
|
+
const opts = { stdio: 'inherit', cwd: workDir };
|
|
245
|
+
if (ext === 'zip') {
|
|
246
|
+
// Windows 10+ ships bsdtar as tar.exe, which extracts zips; fall back to
|
|
247
|
+
// PowerShell Expand-Archive if tar is unavailable or cannot read the zip.
|
|
248
|
+
const viaTar = spawnSync('tar', ['-xf', archiveName, '-C', destName], opts);
|
|
249
|
+
if (viaTar.status === 0) return;
|
|
250
|
+
const absArchive = join(workDir, archiveName);
|
|
251
|
+
const absDest = join(workDir, destName);
|
|
252
|
+
const viaPwsh = spawnSync(
|
|
253
|
+
'powershell',
|
|
254
|
+
[
|
|
255
|
+
'-NoProfile',
|
|
256
|
+
'-NonInteractive',
|
|
257
|
+
'-Command',
|
|
258
|
+
`Expand-Archive -LiteralPath '${absArchive.replace(/'/g, "''")}' ` +
|
|
259
|
+
`-DestinationPath '${absDest.replace(/'/g, "''")}' -Force`,
|
|
260
|
+
],
|
|
261
|
+
{ stdio: 'inherit' },
|
|
262
|
+
);
|
|
263
|
+
if (viaPwsh.status !== 0) fail(`failed to extract ${assetName}`);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const viaTar = spawnSync('tar', ['-xzf', archiveName, '-C', destName], opts);
|
|
267
|
+
if (viaTar.status !== 0) fail(`failed to extract ${assetName} (tar exited ${viaTar.status})`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function main() {
|
|
271
|
+
const archiveBuffer = await download(assetUrl);
|
|
272
|
+
const checksumText = (await download(checksumUrl)).toString('utf8');
|
|
273
|
+
const expected = parseSha256(checksumText, assetName);
|
|
274
|
+
const actual = createHash('sha256').update(archiveBuffer).digest('hex');
|
|
275
|
+
if (actual !== expected) {
|
|
276
|
+
fail(`checksum mismatch for ${assetName}: expected ${expected}, got ${actual}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'splice-install-'));
|
|
280
|
+
try {
|
|
281
|
+
const archivePath = join(tempDir, assetName);
|
|
282
|
+
writeFileSync(archivePath, archiveBuffer);
|
|
283
|
+
const extractDir = join(tempDir, 'extracted');
|
|
284
|
+
mkdirSync(extractDir);
|
|
285
|
+
extract(tempDir, assetName, 'extracted');
|
|
286
|
+
|
|
287
|
+
// Copy only known basenames into the package root. We never honor
|
|
288
|
+
// archive-relative paths, so a crafted entry cannot escape the package.
|
|
289
|
+
const primarySource = findByBasename(extractDir, binaryName);
|
|
290
|
+
if (!primarySource) fail(`archive ${assetName} did not contain ${binaryName}`);
|
|
291
|
+
copyFileSync(primarySource, installedBinary);
|
|
292
|
+
if (platform !== 'windows') chmodSync(installedBinary, 0o755);
|
|
293
|
+
|
|
294
|
+
for (const name of optionalBinaries) {
|
|
295
|
+
const source = findByBasename(extractDir, name);
|
|
296
|
+
if (!source) {
|
|
297
|
+
console.error(
|
|
298
|
+
`[splice] note: optional helper ${name} was not in ${assetName}; ` +
|
|
299
|
+
`the sandbox may run with reduced isolation.`,
|
|
300
|
+
);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const dest = join(packageRoot, name);
|
|
304
|
+
copyFileSync(source, dest);
|
|
305
|
+
if (platform !== 'windows') chmodSync(dest, 0o755);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
writeFileSync(markerPath, VERSION + '\n');
|
|
309
|
+
const sizeKb = Math.round(statSync(installedBinary).size / 1024);
|
|
310
|
+
console.error(`[splice] installed ${binaryName} ${VERSION} (${platform}-${arch}, ${sizeKb} KB).`);
|
|
311
|
+
} finally {
|
|
312
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
main().catch((error) => fail(error.message));
|