causari 0.3.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 +202 -0
- package/README.md +38 -0
- package/bin/causari.js +3 -0
- package/bin/re.js +3 -0
- package/lib/shim.js +333 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# ∵ causari
|
|
2
|
+
|
|
3
|
+
**AI-written code has no author. It has causes. Causari records them.**
|
|
4
|
+
|
|
5
|
+
`re audit` reads plain git history, finds the commits that carry
|
|
6
|
+
machine-readable AI authorship (`Co-Authored-By` trailers, bot authors, agent
|
|
7
|
+
markers) and asks `git blame` how many of their lines are still at HEAD. A
|
|
8
|
+
count, not a grade. The same binary records the prompt, model and files behind
|
|
9
|
+
every agent edit into a local, append-only ledger.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx causari audit # the repo you are in
|
|
13
|
+
npx causari audit vercel/next.js
|
|
14
|
+
npm i -g causari && re audit # `re` is the short alias every example uses
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This package is a launcher, not the program. It holds no binary and does
|
|
18
|
+
nothing at `npm install`. On first run it downloads the release archive for
|
|
19
|
+
your platform from
|
|
20
|
+
`https://github.com/croviatrust/causari/releases/download/v<version>/`,
|
|
21
|
+
checks its SHA-256 against the release's `SHA256SUMS.txt`, unpacks `causari`
|
|
22
|
+
and `re` into `~/.cache/causari/<version>/<target>/` (`$XDG_CACHE_HOME` or
|
|
23
|
+
`%LOCALAPPDATA%` when set) and runs it with your arguments. Exit code and
|
|
24
|
+
signals pass through. Node built-ins only; no telemetry.
|
|
25
|
+
|
|
26
|
+
Prebuilt binaries exist for Linux (x86_64, aarch64), macOS (x86_64, Apple
|
|
27
|
+
silicon) and Windows (x86_64). Elsewhere, `cargo install causari --locked`.
|
|
28
|
+
|
|
29
|
+
| Variable | Effect |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `CAUSARI_VERSION` | run another release than the package version |
|
|
32
|
+
| `CAUSARI_BINARY` | path to a binary you already have; nothing is downloaded |
|
|
33
|
+
| `CAUSARI_DOWNLOAD_BASE` | mirror of the release directory (same layout, same `SHA256SUMS.txt`) |
|
|
34
|
+
|
|
35
|
+
Site and method: [causari.dev](https://causari.dev) ·
|
|
36
|
+
[causari.dev/method](https://causari.dev/method). Source, other installers and
|
|
37
|
+
the full command reference: [github.com/croviatrust/causari](https://github.com/croviatrust/causari).
|
|
38
|
+
Apache-2.0.
|
package/bin/causari.js
ADDED
package/bin/re.js
ADDED
package/lib/shim.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Thin launcher for the causari release binaries. On first run it downloads
|
|
3
|
+
// the archive for this platform from the GitHub release that matches the
|
|
4
|
+
// package version, checks its SHA-256 against the release's SHA256SUMS.txt,
|
|
5
|
+
// unpacks `causari` and `re` into a per-version cache and runs the requested
|
|
6
|
+
// one with the caller's arguments. Nothing happens at `npm install`: no
|
|
7
|
+
// network, no postinstall. Node built-ins only.
|
|
8
|
+
//
|
|
9
|
+
// Environment:
|
|
10
|
+
// CAUSARI_VERSION release to run (default: this package's version)
|
|
11
|
+
// CAUSARI_BINARY path to an existing binary; skips the download
|
|
12
|
+
// CAUSARI_DOWNLOAD_BASE where releases live (default: GitHub releases)
|
|
13
|
+
// XDG_CACHE_HOME / LOCALAPPDATA cache root (default: ~/.cache)
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const http = require('http');
|
|
19
|
+
const https = require('https');
|
|
20
|
+
const zlib = require('zlib');
|
|
21
|
+
const crypto = require('crypto');
|
|
22
|
+
const { spawn } = require('child_process');
|
|
23
|
+
|
|
24
|
+
const REPO = 'croviatrust/causari';
|
|
25
|
+
const DEFAULT_BASE = `https://github.com/${REPO}/releases/download`;
|
|
26
|
+
const PACKAGE_VERSION = require('../package.json').version;
|
|
27
|
+
const MAX_REDIRECTS = 5;
|
|
28
|
+
const TIMEOUT_MS = 60_000;
|
|
29
|
+
|
|
30
|
+
class ShimError extends Error {}
|
|
31
|
+
|
|
32
|
+
function log(msg) {
|
|
33
|
+
process.stderr.write(`causari: ${msg}\n`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ---------------------------------------------------------------- platform
|
|
37
|
+
|
|
38
|
+
function target(platform = process.platform, arch = process.arch) {
|
|
39
|
+
const table = {
|
|
40
|
+
'linux-x64': 'x86_64-unknown-linux-gnu',
|
|
41
|
+
'linux-arm64': 'aarch64-unknown-linux-gnu',
|
|
42
|
+
'darwin-x64': 'x86_64-apple-darwin',
|
|
43
|
+
'darwin-arm64': 'aarch64-apple-darwin',
|
|
44
|
+
'win32-x64': 'x86_64-pc-windows-msvc',
|
|
45
|
+
};
|
|
46
|
+
const t = table[`${platform}-${arch}`];
|
|
47
|
+
if (!t) {
|
|
48
|
+
throw new ShimError(
|
|
49
|
+
`no prebuilt binary for ${platform}/${arch}. Releases cover Linux (x86_64, aarch64), ` +
|
|
50
|
+
`macOS (x86_64, Apple silicon) and Windows (x86_64). Build from source instead: ` +
|
|
51
|
+
`cargo install causari --locked`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function version(env = process.env) {
|
|
58
|
+
const v = (env.CAUSARI_VERSION || PACKAGE_VERSION).trim();
|
|
59
|
+
return v.startsWith('v') ? v.slice(1) : v;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function assetName(ver, tgt) {
|
|
63
|
+
const ext = tgt.endsWith('-windows-msvc') ? 'zip' : 'tar.gz';
|
|
64
|
+
return `causari-v${ver}-${tgt}.${ext}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function cacheRoot(env = process.env, platform = process.platform) {
|
|
68
|
+
if (env.XDG_CACHE_HOME) return env.XDG_CACHE_HOME;
|
|
69
|
+
if (platform === 'win32' && env.LOCALAPPDATA) return env.LOCALAPPDATA;
|
|
70
|
+
return path.join(os.homedir(), '.cache');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function cacheDir(ver, tgt, env = process.env, platform = process.platform) {
|
|
74
|
+
return path.join(cacheRoot(env, platform), 'causari', ver, tgt);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function exeName(name, tgt) {
|
|
78
|
+
return tgt.endsWith('-windows-msvc') ? `${name}.exe` : name;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------- download
|
|
82
|
+
|
|
83
|
+
function fetch(url, redirects = 0) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const mod = url.startsWith('http://') ? http : https;
|
|
86
|
+
const req = mod.get(
|
|
87
|
+
url,
|
|
88
|
+
{ headers: { 'User-Agent': `causari-npm-shim/${PACKAGE_VERSION}`, Accept: '*/*' } },
|
|
89
|
+
(res) => {
|
|
90
|
+
const status = res.statusCode || 0;
|
|
91
|
+
if ([301, 302, 303, 307, 308].includes(status) && res.headers.location) {
|
|
92
|
+
res.resume();
|
|
93
|
+
if (redirects >= MAX_REDIRECTS) {
|
|
94
|
+
reject(new ShimError(`too many redirects fetching ${url}`));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
resolve(fetch(new URL(res.headers.location, url).toString(), redirects + 1));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (status !== 200) {
|
|
101
|
+
res.resume();
|
|
102
|
+
reject(new ShimError(`HTTP ${status} fetching ${url}`));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const chunks = [];
|
|
106
|
+
res.on('data', (c) => chunks.push(c));
|
|
107
|
+
res.on('end', () => resolve(Buffer.concat(chunks)));
|
|
108
|
+
res.on('error', reject);
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
req.setTimeout(TIMEOUT_MS, () => req.destroy(new ShimError(`timeout fetching ${url}`)));
|
|
112
|
+
req.on('error', (e) => reject(e instanceof ShimError ? e : new ShimError(`${e.message} fetching ${url}`)));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function sha256(buf) {
|
|
117
|
+
return crypto.createHash('sha256').update(buf).digest('hex');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// One line per file, `<hex> <name>` or `<hex> *<name>` (sha256sum format).
|
|
121
|
+
function expectedSum(sumsText, asset) {
|
|
122
|
+
for (const raw of sumsText.split(/\r?\n/)) {
|
|
123
|
+
const line = raw.trim();
|
|
124
|
+
if (!line) continue;
|
|
125
|
+
const m = /^([0-9a-fA-F]{64})\s+\*?(.+)$/.exec(line);
|
|
126
|
+
if (m && m[2].trim() === asset) return m[1].toLowerCase();
|
|
127
|
+
}
|
|
128
|
+
throw new ShimError(`no checksum for ${asset} in SHA256SUMS.txt; refusing to run an unverified download`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------- tar
|
|
132
|
+
|
|
133
|
+
// Reads a POSIX ustar / pax / GNU tar stream and returns {name: Buffer} for
|
|
134
|
+
// the regular files whose base name is in `wanted`. Release archives hold
|
|
135
|
+
// the two binaries at the top level, but a directory prefix is tolerated.
|
|
136
|
+
function readTar(buf, wanted) {
|
|
137
|
+
const out = {};
|
|
138
|
+
let off = 0;
|
|
139
|
+
let paxPath = null;
|
|
140
|
+
let longName = null;
|
|
141
|
+
while (off + 512 <= buf.length) {
|
|
142
|
+
const header = buf.subarray(off, off + 512);
|
|
143
|
+
if (header.every((b) => b === 0)) break;
|
|
144
|
+
const field = (start, len) => {
|
|
145
|
+
const s = header.subarray(start, start + len);
|
|
146
|
+
const end = s.indexOf(0);
|
|
147
|
+
return s.subarray(0, end === -1 ? len : end).toString('utf8');
|
|
148
|
+
};
|
|
149
|
+
const size = parseInt(field(124, 12).trim() || '0', 8);
|
|
150
|
+
if (!Number.isFinite(size)) throw new ShimError('corrupt tar header');
|
|
151
|
+
const type = String.fromCharCode(header[156] || 0x30);
|
|
152
|
+
let name = field(0, 100);
|
|
153
|
+
const prefix = field(257, 6) === 'ustar' ? field(345, 155) : '';
|
|
154
|
+
if (prefix) name = `${prefix}/${name}`;
|
|
155
|
+
const dataStart = off + 512;
|
|
156
|
+
const data = buf.subarray(dataStart, dataStart + size);
|
|
157
|
+
off = dataStart + Math.ceil(size / 512) * 512;
|
|
158
|
+
|
|
159
|
+
if (type === 'x') {
|
|
160
|
+
// pax extended header: "<len> path=<value>\n" records
|
|
161
|
+
let p = 0;
|
|
162
|
+
const text = data.toString('utf8');
|
|
163
|
+
while (p < text.length) {
|
|
164
|
+
const sp = text.indexOf(' ', p);
|
|
165
|
+
if (sp === -1) break;
|
|
166
|
+
const len = parseInt(text.slice(p, sp), 10);
|
|
167
|
+
if (!len) break;
|
|
168
|
+
const rec = text.slice(sp + 1, p + len - 1);
|
|
169
|
+
const eq = rec.indexOf('=');
|
|
170
|
+
if (eq !== -1 && rec.slice(0, eq) === 'path') paxPath = rec.slice(eq + 1);
|
|
171
|
+
p += len;
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (type === 'L') {
|
|
176
|
+
longName = data.toString('utf8').replace(/\0+$/, '');
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const effective = paxPath || longName || name;
|
|
180
|
+
paxPath = null;
|
|
181
|
+
longName = null;
|
|
182
|
+
if (type !== '0' && type !== '\0') continue;
|
|
183
|
+
const base = effective.split('/').filter(Boolean).pop();
|
|
184
|
+
if (wanted.includes(base) && !(base in out)) out[base] = Buffer.from(data);
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------- zip
|
|
190
|
+
|
|
191
|
+
// Reads a zip central directory and inflates the wanted entries (methods 0
|
|
192
|
+
// and 8, which is what 7z writes for the Windows release). Built in rather
|
|
193
|
+
// than shelling out to tar.exe or Expand-Archive: no dependency on PATH or
|
|
194
|
+
// the execution policy, and the same code path is testable on every OS.
|
|
195
|
+
function readZip(buf, wanted) {
|
|
196
|
+
const out = {};
|
|
197
|
+
let eocd = -1;
|
|
198
|
+
for (let i = buf.length - 22; i >= Math.max(0, buf.length - 22 - 65_535); i--) {
|
|
199
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
200
|
+
eocd = i;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (eocd === -1) throw new ShimError('corrupt zip: no end-of-central-directory record');
|
|
205
|
+
const count = buf.readUInt16LE(eocd + 10);
|
|
206
|
+
let p = buf.readUInt32LE(eocd + 16);
|
|
207
|
+
for (let i = 0; i < count; i++) {
|
|
208
|
+
if (buf.readUInt32LE(p) !== 0x02014b50) throw new ShimError('corrupt zip: bad central directory entry');
|
|
209
|
+
const method = buf.readUInt16LE(p + 10);
|
|
210
|
+
const compSize = buf.readUInt32LE(p + 20);
|
|
211
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
212
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
213
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
214
|
+
const localOff = buf.readUInt32LE(p + 42);
|
|
215
|
+
const name = buf.subarray(p + 46, p + 46 + nameLen).toString('utf8');
|
|
216
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
217
|
+
const base = name.split('/').filter(Boolean).pop();
|
|
218
|
+
if (!wanted.includes(base) || name.endsWith('/')) continue;
|
|
219
|
+
if (buf.readUInt32LE(localOff) !== 0x04034b50) throw new ShimError('corrupt zip: bad local header');
|
|
220
|
+
const lNameLen = buf.readUInt16LE(localOff + 26);
|
|
221
|
+
const lExtraLen = buf.readUInt16LE(localOff + 28);
|
|
222
|
+
const start = localOff + 30 + lNameLen + lExtraLen;
|
|
223
|
+
const raw = buf.subarray(start, start + compSize);
|
|
224
|
+
if (method === 0) out[base] = Buffer.from(raw);
|
|
225
|
+
else if (method === 8) out[base] = zlib.inflateRawSync(raw);
|
|
226
|
+
else throw new ShimError(`zip entry ${name} uses unsupported compression method ${method}`);
|
|
227
|
+
}
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function extract(asset, buf, wanted) {
|
|
232
|
+
const files = asset.endsWith('.zip') ? readZip(buf, wanted) : readTar(zlib.gunzipSync(buf), wanted);
|
|
233
|
+
for (const w of wanted) {
|
|
234
|
+
if (!files[w]) throw new ShimError(`archive ${asset} does not contain ${w}`);
|
|
235
|
+
}
|
|
236
|
+
return files;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ---------------------------------------------------------------- install
|
|
240
|
+
|
|
241
|
+
async function ensureBinary(name, opts = {}) {
|
|
242
|
+
const env = opts.env || process.env;
|
|
243
|
+
if (env.CAUSARI_BINARY) {
|
|
244
|
+
if (!fs.existsSync(env.CAUSARI_BINARY)) {
|
|
245
|
+
throw new ShimError(`CAUSARI_BINARY=${env.CAUSARI_BINARY} does not exist`);
|
|
246
|
+
}
|
|
247
|
+
return env.CAUSARI_BINARY;
|
|
248
|
+
}
|
|
249
|
+
const ver = version(env);
|
|
250
|
+
const tgt = target(opts.platform, opts.arch);
|
|
251
|
+
const dir = cacheDir(ver, tgt, env, opts.platform);
|
|
252
|
+
const wanted = ['causari', 're'].map((n) => exeName(n, tgt));
|
|
253
|
+
const bin = path.join(dir, exeName(name, tgt));
|
|
254
|
+
if (fs.existsSync(bin)) return bin;
|
|
255
|
+
|
|
256
|
+
const base = (env.CAUSARI_DOWNLOAD_BASE || DEFAULT_BASE).replace(/\/+$/, '');
|
|
257
|
+
const asset = assetName(ver, tgt);
|
|
258
|
+
const fetcher = opts.fetch || fetch;
|
|
259
|
+
log(`first run: downloading causari v${ver} (${tgt}) from ${base}/v${ver}/`);
|
|
260
|
+
const sums = (await fetcher(`${base}/v${ver}/SHA256SUMS.txt`)).toString('utf8');
|
|
261
|
+
const expected = expectedSum(sums, asset);
|
|
262
|
+
const archive = await fetcher(`${base}/v${ver}/${asset}`);
|
|
263
|
+
const actual = sha256(archive);
|
|
264
|
+
if (actual !== expected) {
|
|
265
|
+
throw new ShimError(`sha256 mismatch for ${asset}: expected ${expected}, got ${actual}; refusing to run it`);
|
|
266
|
+
}
|
|
267
|
+
const files = extract(asset, archive, wanted);
|
|
268
|
+
|
|
269
|
+
// Unpack next to the final directory, then rename: a concurrent first run
|
|
270
|
+
// either wins the rename or finds the winner's files in place.
|
|
271
|
+
fs.mkdirSync(path.dirname(dir), { recursive: true });
|
|
272
|
+
const tmp = fs.mkdtempSync(path.join(path.dirname(dir), `.${tgt}-`));
|
|
273
|
+
try {
|
|
274
|
+
for (const [file, data] of Object.entries(files)) {
|
|
275
|
+
fs.writeFileSync(path.join(tmp, file), data, { mode: 0o755 });
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
fs.renameSync(tmp, dir);
|
|
279
|
+
} catch (e) {
|
|
280
|
+
if (!fs.existsSync(bin)) throw e;
|
|
281
|
+
}
|
|
282
|
+
} finally {
|
|
283
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
284
|
+
}
|
|
285
|
+
log(`sha256 verified (${actual}); cached in ${dir}`);
|
|
286
|
+
return bin;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// ---------------------------------------------------------------- run
|
|
290
|
+
|
|
291
|
+
function run(name, args = process.argv.slice(2)) {
|
|
292
|
+
ensureBinary(name)
|
|
293
|
+
.then((bin) => {
|
|
294
|
+
const child = spawn(bin, args, { stdio: 'inherit', windowsHide: true });
|
|
295
|
+
const forward = (sig) => {
|
|
296
|
+
if (!child.killed) child.kill(sig);
|
|
297
|
+
};
|
|
298
|
+
for (const sig of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
299
|
+
process.on(sig, forward);
|
|
300
|
+
}
|
|
301
|
+
child.on('error', (e) => {
|
|
302
|
+
log(`could not start ${bin}: ${e.message}`);
|
|
303
|
+
process.exit(126);
|
|
304
|
+
});
|
|
305
|
+
child.on('exit', (code, signal) => {
|
|
306
|
+
if (signal) {
|
|
307
|
+
process.kill(process.pid, signal);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
process.exit(code === null ? 1 : code);
|
|
311
|
+
});
|
|
312
|
+
})
|
|
313
|
+
.catch((e) => {
|
|
314
|
+
log(e instanceof ShimError ? e.message : `unexpected error: ${e && e.stack ? e.stack : e}`);
|
|
315
|
+
process.exit(1);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
module.exports = {
|
|
320
|
+
ShimError,
|
|
321
|
+
target,
|
|
322
|
+
version,
|
|
323
|
+
assetName,
|
|
324
|
+
cacheDir,
|
|
325
|
+
fetch,
|
|
326
|
+
sha256,
|
|
327
|
+
expectedSum,
|
|
328
|
+
readTar,
|
|
329
|
+
readZip,
|
|
330
|
+
extract,
|
|
331
|
+
ensureBinary,
|
|
332
|
+
run,
|
|
333
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "causari",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "AI-written code has no author. It has causes. Causari measures how many lines from AI-tagged commits are still alive in any git repo and records the prompt, model and files behind every agent edit.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai",
|
|
7
|
+
"provenance",
|
|
8
|
+
"git",
|
|
9
|
+
"agents",
|
|
10
|
+
"mcp",
|
|
11
|
+
"audit",
|
|
12
|
+
"survival",
|
|
13
|
+
"claude-code",
|
|
14
|
+
"cursor",
|
|
15
|
+
"aider"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://causari.dev",
|
|
18
|
+
"bugs": "https://github.com/croviatrust/causari/issues",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/croviatrust/causari.git",
|
|
22
|
+
"directory": "packaging/npm"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"author": "Crovia Trust <info@croviatrust.com>",
|
|
26
|
+
"bin": {
|
|
27
|
+
"causari": "bin/causari.js",
|
|
28
|
+
"re": "bin/re.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"bin/",
|
|
32
|
+
"lib/",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "bash ../../scripts/tests/test_npm_shim.sh"
|
|
41
|
+
}
|
|
42
|
+
}
|