osmogrep 0.0.0-stage → 0.3.16
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 +22 -2
- package/bin/osmogrep.mjs +32 -0
- package/native.mjs +98 -0
- package/package.json +15 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kaushal Kumar Choudhary
|
|
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
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OsmoGrep
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A terminal coding agent for building features, understanding code, and fixing bugs.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install -g osmogrep
|
|
7
|
+
# or
|
|
8
|
+
pnpm add -g osmogrep
|
|
9
|
+
|
|
10
|
+
osmogrep
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
You can also use `npx osmogrep` or `pnpm dlx osmogrep`. GitHub releases include
|
|
14
|
+
the same launcher as `osmogrep-npm.tgz` for direct tarball installation.
|
|
15
|
+
|
|
16
|
+
Requires Node.js 22.19+. This small package downloads the matching, checksummed
|
|
17
|
+
Rust executable on its first launch and reuses it afterward. It does not depend
|
|
18
|
+
on install scripts, so pnpm's blocked lifecycle scripts do not prevent setup.
|
|
19
|
+
Supported releases: macOS Apple silicon/Intel, Linux x64 with glibc, Windows x64.
|
|
20
|
+
macOS and iPhone companions are optional downloads inside Settings → Workspace;
|
|
21
|
+
they are not included in the npm package or the Rust executable.
|
|
22
|
+
|
|
23
|
+
[Documentation](https://github.com/kaushal07wick/OsmoGrep#readme) · [Issues](https://github.com/kaushal07wick/OsmoGrep/issues)
|
package/bin/osmogrep.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {spawn} from 'node:child_process';
|
|
3
|
+
import {readFile} from 'node:fs/promises';
|
|
4
|
+
import {delimiter, dirname} from 'node:path';
|
|
5
|
+
import {ensureBinary} from '../native.mjs';
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const {version} = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
9
|
+
if (process.platform === 'linux' && !process.report.getReport().header.glibcVersionRuntime) {
|
|
10
|
+
throw new Error('The Linux prebuilt binary requires glibc. Build OsmoGrep with Cargo on musl/Alpine.');
|
|
11
|
+
}
|
|
12
|
+
const binary = await ensureBinary({version, onDownload: target => {
|
|
13
|
+
process.stderr.write(`Downloading OsmoGrep ${version} for ${target} (first launch only)…\n`);
|
|
14
|
+
}});
|
|
15
|
+
const child = spawn(binary, process.argv.slice(2), {stdio: 'inherit', env: {
|
|
16
|
+
...process.env, PATH: dirname(process.execPath) + delimiter + (process.env.PATH ?? ''),
|
|
17
|
+
}});
|
|
18
|
+
// The terminal delivers Ctrl+C to both processes; let Rust restore its terminal before exiting.
|
|
19
|
+
const interrupt = () => {}, terminate = () => child.kill('SIGTERM');
|
|
20
|
+
process.on('SIGINT', interrupt);
|
|
21
|
+
process.on('SIGTERM', terminate);
|
|
22
|
+
child.once('error', error => {process.stderr.write(`osmogrep: ${error.message}\n`); process.exitCode = 1;});
|
|
23
|
+
child.once('exit', (code, signal) => {
|
|
24
|
+
process.removeListener('SIGINT', interrupt);
|
|
25
|
+
process.removeListener('SIGTERM', terminate);
|
|
26
|
+
if (signal) process.kill(process.pid, signal);
|
|
27
|
+
else process.exitCode = code ?? 1;
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
process.stderr.write(`osmogrep: ${error.message}\n`);
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
}
|
package/native.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
import {spawnSync} from 'node:child_process';
|
|
3
|
+
import {createWriteStream} from 'node:fs';
|
|
4
|
+
import {access, chmod, lstat, mkdir, mkdtemp, readFile, rename, rm} from 'node:fs/promises';
|
|
5
|
+
import {homedir} from 'node:os';
|
|
6
|
+
import {join} from 'node:path';
|
|
7
|
+
import {Readable, Transform} from 'node:stream';
|
|
8
|
+
import {pipeline} from 'node:stream/promises';
|
|
9
|
+
|
|
10
|
+
const releases = 'https://github.com/kaushal07wick/OsmoGrep/releases/download';
|
|
11
|
+
const targets = {
|
|
12
|
+
'darwin-arm64': 'aarch64-apple-darwin',
|
|
13
|
+
'darwin-x64': 'x86_64-apple-darwin',
|
|
14
|
+
'linux-x64': 'x86_64-unknown-linux-gnu',
|
|
15
|
+
'win32-x64': 'x86_64-pc-windows-msvc',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function targetFor(platform, arch) {
|
|
19
|
+
const target = targets[`${platform}-${arch}`];
|
|
20
|
+
if (!target) throw new Error(`No prebuilt OsmoGrep binary for ${platform}/${arch}. Install from source with Cargo instead.`);
|
|
21
|
+
return target;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function checksumFor(text, asset) {
|
|
25
|
+
for (const line of text.trim().split(/\r?\n/)) {
|
|
26
|
+
const [hash, name] = line.trim().split(/\s+/);
|
|
27
|
+
if (/^[a-f\d]{64}$/i.test(hash ?? '') && (!name || name.replace(/^\*/, '') === asset)) return hash.toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Release checksum does not identify ${asset}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function download(url, file, maxBytes, fetchImpl) {
|
|
33
|
+
for (let attempt = 0; ; attempt++) {
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetchImpl(url, {signal: AbortSignal.timeout(180_000)});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
await response.body?.cancel();
|
|
38
|
+
const error = new Error(`Download returned HTTP ${response.status}: ${url}`);
|
|
39
|
+
error.retryable = response.status >= 500 || [408, 429].includes(response.status);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (!response.body) throw new Error('Release download has no body');
|
|
43
|
+
let received = 0;
|
|
44
|
+
const limit = new Transform({transform(chunk, encoding, done) {
|
|
45
|
+
received += chunk.length;
|
|
46
|
+
done(received > maxBytes ? new Error('Release download exceeds its size limit') : null, chunk);
|
|
47
|
+
}});
|
|
48
|
+
await pipeline(Readable.fromWeb(response.body), limit, createWriteStream(file, {mode: 0o600}));
|
|
49
|
+
return;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (attempt >= 2 || error.retryable === false || /size limit/.test(error.message)) throw error;
|
|
52
|
+
await new Promise(resolve => setTimeout(resolve, 500 * (attempt + 1)));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function extractBinary(archive, directory, name) {
|
|
58
|
+
// Extract only the release's named executable; archive paths cannot choose another destination.
|
|
59
|
+
const result = spawnSync('tar', ['-xf', archive, '-C', directory, '--', name], {encoding: 'utf8', windowsHide: true, timeout: 30_000});
|
|
60
|
+
if (result.error || result.status !== 0) throw new Error(`Cannot unpack OsmoGrep: ${result.error?.message ?? result.stderr}. Ensure tar is available.`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function ensureBinary({version, platform = process.platform, arch = process.arch,
|
|
64
|
+
cacheRoot = process.env.LOCALAPPDATA && platform === 'win32' ? process.env.LOCALAPPDATA : process.env.XDG_CACHE_HOME ?? join(homedir(), '.cache'),
|
|
65
|
+
fetchImpl = fetch, extract = extractBinary, onDownload = () => {}}) {
|
|
66
|
+
if (!/^\d+\.\d+\.\d+(?:-[a-z\d.-]+)?$/i.test(version)) throw new Error('Invalid OsmoGrep package version');
|
|
67
|
+
const target = targetFor(platform, arch);
|
|
68
|
+
const name = platform === 'win32' ? 'osmogrep.exe' : 'osmogrep';
|
|
69
|
+
const directory = join(cacheRoot, 'osmogrep', 'npm', version, target);
|
|
70
|
+
const binary = join(directory, name);
|
|
71
|
+
try {
|
|
72
|
+
const cached = await lstat(binary);
|
|
73
|
+
if (cached.isFile() && !cached.isSymbolicLink()) {await access(binary, platform === 'win32' ? 0 : 1); return binary;}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (!['ENOENT', 'EACCES'].includes(error.code)) throw error;
|
|
76
|
+
}
|
|
77
|
+
await mkdir(directory, {recursive: true, mode: 0o700});
|
|
78
|
+
const temporary = await mkdtemp(join(directory, 'download-'));
|
|
79
|
+
const asset = `osmogrep-${target}.${platform === 'win32' ? 'zip' : 'tar.gz'}`;
|
|
80
|
+
const archive = join(temporary, asset), checksum = `${archive}.sha256`;
|
|
81
|
+
try {
|
|
82
|
+
onDownload(target);
|
|
83
|
+
await download(`${releases}/v${version}/${asset}.sha256`, checksum, 4096, fetchImpl);
|
|
84
|
+
const expected = checksumFor(await readFile(checksum, 'utf8'), asset);
|
|
85
|
+
await download(`${releases}/v${version}/${asset}`, archive, 128 * 1024 * 1024, fetchImpl);
|
|
86
|
+
if (createHash('sha256').update(await readFile(archive)).digest('hex') !== expected) throw new Error('OsmoGrep download checksum mismatch; nothing was installed.');
|
|
87
|
+
extract(archive, temporary, name);
|
|
88
|
+
const candidate = join(temporary, name), stat = await lstat(candidate);
|
|
89
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1) throw new Error('Release executable must be a regular file without links');
|
|
90
|
+
await chmod(candidate, 0o755);
|
|
91
|
+
try {await rename(candidate, binary);} catch (error) {
|
|
92
|
+
if (error.code !== 'EEXIST' || !(await lstat(binary)).isFile()) throw error;
|
|
93
|
+
}
|
|
94
|
+
return binary;
|
|
95
|
+
} finally {
|
|
96
|
+
await rm(temporary, {recursive: true, force: true});
|
|
97
|
+
}
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osmogrep",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.3.16",
|
|
4
|
+
"description": "A terminal coding agent for building features, understanding code, and fixing bugs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "osmogrep": "bin/osmogrep.mjs" },
|
|
7
|
+
"files": ["bin/", "native.mjs", "README.md", "LICENSE"],
|
|
8
|
+
"engines": { "node": ">=22.19.0" },
|
|
9
|
+
"scripts": { "test": "node --test native.test.mjs" },
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/kaushal07wick/OsmoGrep.git", "directory": "npm" },
|
|
11
|
+
"homepage": "https://osmogrep.com",
|
|
12
|
+
"bugs": "https://github.com/kaushal07wick/OsmoGrep/issues",
|
|
13
|
+
"author": "Kaushal Choudhary <kaushalc64@gmail.com>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"keywords": ["ai", "agent", "coding", "terminal", "rust"],
|
|
16
|
+
"publishConfig": { "access": "public" }
|
|
17
|
+
}
|