nish 0.41.0 → 0.44.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/README.md +16 -4
- package/bin/nish-skills.js +233 -0
- package/docs/AI.md +282 -126
- package/llms.txt +4 -0
- package/package.json +14 -11
- package/runtime/core.d.ts +16 -0
- package/runtime/core.mjs +5 -0
- package/runtime/nish.d.ts +204 -33
- package/runtime/nish.h +19 -3
- package/runtime/nish.mjs +5 -1
- package/runtime/runtime-cross.c +15 -0
- package/runtime/runtime-net.c +876 -10
- package/runtime/runtime-region.c +21 -0
- package/runtime/runtime-sandbox.c +112 -15
- package/runtime/runtime-text.c +11 -0
- package/runtime/runtime-uring.c +533 -77
- package/runtime/runtime-wasm.c +3 -0
- package/runtime/runtime.c +474 -5
- package/runtime/sqlite/README.md +16 -3
- package/runtime/sqlite/nish-sqlite.c +940 -29
- package/scripts/build.sh +125 -29
- package/scripts/link-skills.mjs +1039 -0
- package/scripts/postinstall.mjs +43 -0
- package/skills/writing-nish/SKILL.md +144 -0
- package/std/README.md +3 -3
- package/std/crypto/base64url.ts +102 -1
- package/std/crypto/scram.ts +142 -0
- package/std/crypto/sha1.ts +99 -41
- package/std/host/ring.ts +1 -1
- package/std/host/text.ts +1 -1
- package/std/net/fetch.ts +9 -1
- package/std/net/handler.ts +79 -15
- package/std/net/http-server.ts +2 -3
- package/std/net/http1-server.ts +294 -51
- package/std/net/http3-server.ts +26 -15
- package/std/net/http3.ts +2 -2
- package/std/net/oidc.ts +1107 -0
- package/std/net/postgres-async.ts +64 -33
- package/std/net/postgres.ts +65 -76
- package/std/net/quic-conn-ack.ts +57 -7
- package/std/net/quic-frame.ts +104 -2
- package/std/net/quic-listener.ts +9 -2
- package/std/net/quic.ts +16 -1
- package/std/net/serve.ts +10 -8
- package/std/net/websocket.ts +188 -49
- package/std/sqlite.ts +325 -0
- package/std/text.ts +80 -11
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|

|
|
14
14
|

|
|
15
15
|
|
|
16
|
+
**[nishlang.com](https://nishlang.com/)** · [Get started](https://nishlang.com/getting-started/installation) · [Language reference](https://nishlang.com/reference/language) · [Changelog](https://nishlang.com/reference/changelog)
|
|
17
|
+
|
|
16
18
|
</div>
|
|
17
19
|
|
|
18
20
|
---
|
|
@@ -69,7 +71,10 @@ for (const side of sides) {
|
|
|
69
71
|
|
|
70
72
|
The IR is readable. `examples/add.ts`, `a + b` on two `number`s (32-bit
|
|
71
73
|
integers by default), compiles to a checked add: an overflow panics instead
|
|
72
|
-
of wrapping, and a sum the compiler proves fits is a plain `add nsw`.
|
|
74
|
+
of wrapping, and a sum the compiler proves fits is a plain `add nsw`. That
|
|
75
|
+
check is a panic site, so the compiler's default, which holds a package to no
|
|
76
|
+
panic, refuses the file on purpose and `nish --allow-panics` builds it; each
|
|
77
|
+
example that keeps a panic site says why in its first lines.
|
|
73
78
|
|
|
74
79
|
```llvm
|
|
75
80
|
define noundef i32 @add(i32 noundef %a, i32 noundef %b) #0 {
|
|
@@ -236,6 +241,11 @@ module can be a few hundred bytes. The benchmark suite runs the same
|
|
|
236
241
|
algorithms in Nish, C and Rust and records wall time, size and memory in
|
|
237
242
|
[docs/BENCHMARKS.md](docs/BENCHMARKS.md).
|
|
238
243
|
|
|
244
|
+
On public leaderboards, a Nish entry placed second in the
|
|
245
|
+
[multicore server challenge](https://github.com/arjaythedev/multicore-server-challenge),
|
|
246
|
+
holding 220,000 users on 8 cores: the result and how it got there are in
|
|
247
|
+
[docs/LEADERBOARDS.md](docs/LEADERBOARDS.md).
|
|
248
|
+
|
|
239
249
|
## Interop
|
|
240
250
|
|
|
241
251
|
Nish never embeds a JavaScript engine; JavaScript calls Nish. A program
|
|
@@ -252,6 +262,10 @@ has the playground.
|
|
|
252
262
|
|
|
253
263
|
## Documentation
|
|
254
264
|
|
|
265
|
+
The documentation site, **[nishlang.com](https://nishlang.com/)**, publishes
|
|
266
|
+
the user guide, the language and library reference and the changelog; the
|
|
267
|
+
files below are its sources.
|
|
268
|
+
|
|
255
269
|
| Read | For |
|
|
256
270
|
|:---|:---|
|
|
257
271
|
| [The user guide](docs/guide/index.md) | Learning Nish page by page, every example compiled by the test suite |
|
|
@@ -261,15 +275,13 @@ has the playground.
|
|
|
261
275
|
| [`std/` README](std/README.md) | Every standard library module |
|
|
262
276
|
| [FAQ](docs/FAQ.md) | Why the design is the way it is |
|
|
263
277
|
| [IR cookbook](docs/IR_COOKBOOK.md) | The exact IR of every construct |
|
|
264
|
-
| [Roadmap](docs/roadmap/index.md) | What is built and what is next |
|
|
265
278
|
| [Changelog](CHANGELOG.md) | What changed in each release |
|
|
266
279
|
|
|
267
280
|
## Project status
|
|
268
281
|
|
|
269
282
|
Pre-alpha and on 0.x, with no compatibility promise: a construct's spelling,
|
|
270
283
|
a flag's name and the IR either lowers to can change between minor releases.
|
|
271
|
-
Every commit compiles, tests and rebuilds the compiler with itself.
|
|
272
|
-
[roadmap](docs/roadmap/index.md) has what is built and what is next.
|
|
284
|
+
Every commit compiles, tests and rebuilds the compiler with itself.
|
|
273
285
|
|
|
274
286
|
## Contributing, security and license
|
|
275
287
|
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The `nish-skills` command: review the agent skills of every installed Nish
|
|
4
|
+
* package and link the ones the user accepts into the project's
|
|
5
|
+
* `.claude/skills/`.
|
|
6
|
+
*
|
|
7
|
+
* A skill can grant an agent tools, so installing a package never links one:
|
|
8
|
+
* this command does, and only for a skill accepted at its current hash -- a
|
|
9
|
+
* `y` at the prompt on a terminal, its name on the command line, or `--yes`
|
|
10
|
+
* for a skill that grants nothing. The rules -- which packages qualify, what
|
|
11
|
+
* is hashed and recorded, which entries the linker owns, what it prunes -- are
|
|
12
|
+
* `scripts/link-skills.mjs`'s.
|
|
13
|
+
*
|
|
14
|
+
* A separate node bin rather than a `nish` subcommand on purpose: it is
|
|
15
|
+
* install tooling, and the compiler stays out of it.
|
|
16
|
+
*
|
|
17
|
+
* Exit 0 when it ran, even if some skills were not linked; 2 for a usage
|
|
18
|
+
* error, an unknown skill name, or when no project is found; 1 when a write
|
|
19
|
+
* failed; 130 when Ctrl-C interrupts a question, and then nothing is written.
|
|
20
|
+
* `--help` is usage on stdout and exit 0, whatever else is on the line, the
|
|
21
|
+
* contract `nish --help` keeps.
|
|
22
|
+
*/
|
|
23
|
+
import fs from "node:fs"
|
|
24
|
+
import path from "node:path"
|
|
25
|
+
import readline from "node:readline"
|
|
26
|
+
import { clean, projectOf, review } from "../scripts/link-skills.mjs"
|
|
27
|
+
|
|
28
|
+
const USAGE = `Usage: nish-skills [--dir <dir>] [--yes] [<skill>...]
|
|
29
|
+
|
|
30
|
+
Review the agent skills of every installed Nish package and link the ones you
|
|
31
|
+
accept into <dir>/.claude/skills/. A skill is linked only once accepted, and
|
|
32
|
+
accepted again whenever its files change: the acceptance is recorded with a
|
|
33
|
+
hash of the skill in <dir>/.claude/skills/.nish-skills.json.
|
|
34
|
+
|
|
35
|
+
On a terminal, with no <skill> and no --yes, each skill not yet accepted is
|
|
36
|
+
shown with what it grants and asked about; only y accepts. Otherwise nothing is
|
|
37
|
+
asked: a named <skill> is accepted, --yes accepts every skill that grants
|
|
38
|
+
nothing, and a skill that grants anything (tools, hooks, a shell command run at
|
|
39
|
+
load, or a frontmatter key not known to be inert) is accepted only by name.
|
|
40
|
+
Ctrl-C at a question exits 130 and writes nothing.
|
|
41
|
+
|
|
42
|
+
<dir> defaults to the project this copy of nish is installed in: the current
|
|
43
|
+
directory or the nearest ancestor holding a package.json whose node_modules/nish
|
|
44
|
+
is this copy (a workspace's root, run from a member), else the nearest ancestor
|
|
45
|
+
holding a package.json. Only links that resolve inside <dir>/node_modules/ are
|
|
46
|
+
ever replaced or removed; anything else is left alone.
|
|
47
|
+
|
|
48
|
+
Options:
|
|
49
|
+
--dir <dir> the project to link skills into
|
|
50
|
+
-y, --yes accept every skill that grants nothing
|
|
51
|
+
-h, --help print this and exit
|
|
52
|
+
|
|
53
|
+
Exit status: 0 ran (some skills may not be linked), 1 a write failed,
|
|
54
|
+
2 usage error, unknown skill, or no project, 130 interrupted.
|
|
55
|
+
`
|
|
56
|
+
|
|
57
|
+
/** Print a usage error and set exit 2. */
|
|
58
|
+
const usageError = (message) => {
|
|
59
|
+
process.stderr.write(`nish-skills: ${message}\n${USAGE}`)
|
|
60
|
+
process.exitCode = 2
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** This package's root: the directory holding `bin/` and `scripts/`. */
|
|
64
|
+
const root = path.resolve(import.meta.dirname, "..")
|
|
65
|
+
|
|
66
|
+
/** The nearest directory from `start` upwards that holds a `package.json`, or null. */
|
|
67
|
+
const findProject = (start) => {
|
|
68
|
+
for (let dir = path.resolve(start); ; dir = path.dirname(dir)) {
|
|
69
|
+
if (fs.existsSync(path.join(dir, "package.json"))) {
|
|
70
|
+
return dir
|
|
71
|
+
}
|
|
72
|
+
if (path.dirname(dir) === dir) {
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The arguments as options, or a usage error's message.
|
|
80
|
+
*
|
|
81
|
+
* @param {string[]} args
|
|
82
|
+
* @returns {{ dir: string | null, yes: boolean, names: string[], help: boolean } | string}
|
|
83
|
+
*/
|
|
84
|
+
const parse = (args) => {
|
|
85
|
+
const options = { dir: null, yes: false, names: [], help: false }
|
|
86
|
+
const end = args.indexOf("--")
|
|
87
|
+
if ((end === -1 ? args : args.slice(0, end)).some((a) => a === "-h" || a === "--help")) {
|
|
88
|
+
// --help wins over anything else on the line, a bad option included.
|
|
89
|
+
return { ...options, help: true }
|
|
90
|
+
}
|
|
91
|
+
for (let i = 0; i < args.length; i++) {
|
|
92
|
+
const arg = args[i]
|
|
93
|
+
if (arg === "--") {
|
|
94
|
+
options.names.push(...args.slice(i + 1))
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
if (arg === "-h" || arg === "--help") {
|
|
98
|
+
options.help = true
|
|
99
|
+
} else if (arg === "-y" || arg === "--yes") {
|
|
100
|
+
options.yes = true
|
|
101
|
+
} else if (arg === "--dir" || arg.startsWith("--dir=")) {
|
|
102
|
+
const dir = arg === "--dir" ? args[++i] : arg.slice("--dir=".length)
|
|
103
|
+
if (dir === undefined || dir === "") {
|
|
104
|
+
return "--dir needs a directory"
|
|
105
|
+
}
|
|
106
|
+
options.dir = dir
|
|
107
|
+
} else if (arg.startsWith("-")) {
|
|
108
|
+
return `unknown option ${arg}`
|
|
109
|
+
} else {
|
|
110
|
+
options.names.push(arg)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return options
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Thrown by a question that Ctrl-C interrupted. */
|
|
117
|
+
class Interrupted extends Error {}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Discard whatever is already waiting on the terminal, for about `ms`
|
|
121
|
+
* milliseconds: keys typed while the skills were being found must not answer a
|
|
122
|
+
* question the user has not seen yet. Raw mode lets a part line go too, not
|
|
123
|
+
* only whole lines.
|
|
124
|
+
*/
|
|
125
|
+
const drainTypeAhead = async (ms) => {
|
|
126
|
+
const discard = () => {
|
|
127
|
+
// Typed before the question was shown, so it answers nothing.
|
|
128
|
+
}
|
|
129
|
+
process.stdin.setRawMode?.(true)
|
|
130
|
+
process.stdin.on("data", discard)
|
|
131
|
+
process.stdin.resume()
|
|
132
|
+
await new Promise((resolve) => setTimeout(resolve, ms))
|
|
133
|
+
process.stdin.pause()
|
|
134
|
+
process.stdin.off("data", discard)
|
|
135
|
+
process.stdin.setRawMode?.(false)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Questions asked on the terminal: each answers its line, or null at end of
|
|
140
|
+
* input, and Ctrl-C rejects it with `Interrupted`. The terminal is first opened
|
|
141
|
+
* at the first question, which comes after every skill has been found. Each
|
|
142
|
+
* question gets a terminal of its own, opened after what was typed ahead is
|
|
143
|
+
* thrown away and closed once it is answered, so no line typed before a
|
|
144
|
+
* question, a second line pasted at the one before included, can answer it.
|
|
145
|
+
*/
|
|
146
|
+
const terminalAsk = () => {
|
|
147
|
+
let ended = false
|
|
148
|
+
return {
|
|
149
|
+
ask: async (question) => {
|
|
150
|
+
if (ended) {
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
await drainTypeAhead(50)
|
|
154
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true })
|
|
155
|
+
try {
|
|
156
|
+
/** @type {{ promise: Promise<never>, reject: (err: Error) => void }} */
|
|
157
|
+
const { promise: interrupted, reject } = Promise.withResolvers()
|
|
158
|
+
// Without a listener readline only pauses on Ctrl-C, and the question would hang.
|
|
159
|
+
rl.on("SIGINT", () => reject(new Interrupted("interrupted")))
|
|
160
|
+
process.stdout.write(question)
|
|
161
|
+
const next = await Promise.race([rl[Symbol.asyncIterator]().next(), interrupted])
|
|
162
|
+
if (next.done === true) {
|
|
163
|
+
ended = true
|
|
164
|
+
return null
|
|
165
|
+
}
|
|
166
|
+
return next.value
|
|
167
|
+
} finally {
|
|
168
|
+
rl.close()
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Review and link for the project the arguments name, and report one line per skill. */
|
|
175
|
+
const run = async (args) => {
|
|
176
|
+
const options = parse(args)
|
|
177
|
+
if (typeof options === "string") {
|
|
178
|
+
usageError(options)
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
if (options.help) {
|
|
182
|
+
process.stdout.write(USAGE)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
let project
|
|
186
|
+
if (options.dir !== null) {
|
|
187
|
+
if (!fs.statSync(options.dir, { throwIfNoEntry: false })?.isDirectory()) {
|
|
188
|
+
usageError(`${options.dir} is not a directory`)
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
project = path.resolve(options.dir)
|
|
192
|
+
} else {
|
|
193
|
+
// The rule postinstall uses, so a workspace member links at the root nish
|
|
194
|
+
// was hoisted to; a copy installed nowhere above (npx's cache) falls back.
|
|
195
|
+
project = projectOf(process.cwd(), root) ?? findProject(process.cwd())
|
|
196
|
+
if (project === null) {
|
|
197
|
+
usageError("no package.json in this directory or any above it")
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const interactive =
|
|
202
|
+
options.names.length === 0 &&
|
|
203
|
+
!options.yes &&
|
|
204
|
+
process.stdin.isTTY === true &&
|
|
205
|
+
process.stdout.isTTY === true
|
|
206
|
+
const terminal = interactive ? terminalAsk() : null
|
|
207
|
+
try {
|
|
208
|
+
const { unknown } = await review(project, {
|
|
209
|
+
names: options.names,
|
|
210
|
+
yes: options.yes,
|
|
211
|
+
ask: terminal?.ask ?? null,
|
|
212
|
+
})
|
|
213
|
+
if (unknown.length > 0) {
|
|
214
|
+
const dirs = unknown.filter((n) => fs.statSync(n, { throwIfNoEntry: false })?.isDirectory() === true)
|
|
215
|
+
const hint = dirs.length > 0 ? `; did you mean --dir ${clean(dirs[0], 200)}?` : ""
|
|
216
|
+
usageError(
|
|
217
|
+
`no installed Nish package ships a skill named ${unknown.map((n) => clean(JSON.stringify(n), 200)).join(", ")}${hint}`
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (err instanceof Interrupted) {
|
|
222
|
+
// Every question is asked before anything is linked, so nothing was written.
|
|
223
|
+
process.stdout.write("\n")
|
|
224
|
+
process.stderr.write("nish-skills: interrupted; nothing was written\n")
|
|
225
|
+
process.exitCode = 130
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
process.stderr.write(`nish-skills: ${clean(err instanceof Error ? err.message : String(err), 1000)}\n`)
|
|
229
|
+
process.exitCode = 1
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
await run(process.argv.slice(2))
|