@causyne/agent 1.20.118 → 1.20.121
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/package.json +1 -1
- package/src/agent/errorClassifier.js +113 -0
- package/src/agent/errorClassifier.ts +161 -0
- package/src/agent/promptIntent.js +200 -0
- package/src/agent/promptIntent.ts +203 -0
- package/src/agent/toolArgValidator.js +97 -0
- package/src/agent/toolArgValidator.ts +112 -0
- package/src/agentLoop.js +51 -351
- package/src/agentLoop.ts +69 -363
- package/src/autoUpdate.js +111 -8
- package/src/autoUpdate.ts +144 -8
- package/src/browser/causyneBrowser.js +231 -136
- package/src/browser/causyneBrowser.ts +229 -140
- package/src/browser/searchProviders.js +41 -30
- package/src/browser/searchProviders.ts +24 -14
- package/src/browser/workspacePathSafety.js +50 -0
- package/src/browser/workspacePathSafety.ts +50 -0
- package/src/browser/workspacePreview.js +27 -4
- package/src/browser/workspacePreview.ts +28 -4
- package/src/cliMode.js +17 -3
- package/src/commands.js +15 -22
- package/src/config.js +42 -63
- package/src/configVault.js +204 -0
- package/src/configVault.ts +213 -0
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/creative/liveBridge.js +34 -1
- package/src/creative/liveBridge.ts +28 -1
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +304 -0
- package/src/headlessCli.ts +380 -0
- package/src/mcp/mcpClient.js +38 -11
- package/src/mcp/mcpClient.ts +44 -11
- package/src/mcp/mcpRegistry.js +2 -5
- package/src/mcp/mcpRegistry.ts +2 -5
- package/src/mcp/mcpSecurity.js +189 -0
- package/src/mcp/mcpSecurity.ts +190 -0
- package/src/observer/evidence.js +23 -0
- package/src/observer/evidence.ts +21 -0
- package/src/osKeychain.js +209 -0
- package/src/osKeychain.ts +245 -0
- package/src/providers/anthropic.js +61 -28
- package/src/providers/base.js +14 -0
- package/src/providers/byokHttp.js +354 -0
- package/src/providers/byokHttp.ts +454 -0
- package/src/providers/byokStream.js +657 -0
- package/src/providers/byokStream.ts +759 -0
- package/src/providers/dashscope-byok.js +47 -32
- package/src/providers/deepseek.js +43 -39
- package/src/providers/gemini.js +73 -38
- package/src/providers/moonshot.js +43 -33
- package/src/providers/muse.js +10 -10
- package/src/providers/ollama.js +46 -31
- package/src/providers/openai-compatible.js +57 -32
- package/src/providers/openrouter.js +77 -113
- package/src/providers/openrouter.ts +99 -118
- package/src/providers/qwen-byok.js +46 -23
- package/src/providers/toolContracts.js +9 -3
- package/src/providers/toolContracts.ts +9 -3
- package/src/providers/wireNormalizer.js +238 -0
- package/src/providers/wireNormalizer.ts +279 -0
- package/src/providers/xai.js +43 -33
- package/src/sandbox.js +77 -56
- package/src/sandboxPolicy.js +1208 -0
- package/src/sandboxPolicy.ts +1300 -0
- package/src/sessionJournal.js +47 -0
- package/src/sessionJournal.ts +49 -0
- package/src/tools/browserAutomator.js +13 -1
- package/src/tools/browserAutomator.ts +13 -0
- package/src/tools/creativeApps.js +2 -1
- package/src/tools/creativeApps.ts +2 -1
- package/src/tools/gameAssetFetcher.js +130 -26
- package/src/tools/gameAssetHarvester.js +80 -58
- package/src/tools/nativeEngine.js +1 -1
- package/src/tools/nativeEngine.ts +1 -1
- package/src/tools/osSandbox.js +473 -0
- package/src/tools/osSandbox.ts +554 -0
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/registry.js +13 -0
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +39 -6
- package/src/tools/sysRun.ts +53 -7
- package/src/tools/toolScanner.js +596 -140
- package/src/tools/toolScanner.ts +665 -147
- package/src/tools/toolSelfRepair.js +243 -114
- package/src/tools/toolSelfRepair.ts +262 -111
- package/src/tools/webFetch.js +161 -24
- package/src/tools/webFetch.ts +157 -22
- package/src/tools/webSearch.js +33 -4
- package/src/tools/webSearch.ts +27 -4
- package/src/tui/sessionPicker.js +132 -35
- package/src/tui/sessionPicker.ts +153 -32
- package/src/tui/sessionPickerView.js +277 -34
- package/src/tui/sessionPickerView.ts +328 -34
- package/src/tui/statusLine.js +3 -0
- package/src/tui/statusLine.ts +5 -0
- package/src/tui/workspaceIdentity.js +133 -0
- package/src/tui/workspaceIdentity.ts +146 -0
package/src/autoUpdate.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// causyne.com installer. A source checkout is never rewritten. Commands are
|
|
5
5
|
// passed as argv arrays with shell disabled, and the only accepted package is
|
|
6
6
|
// the public @causyne/agent package from the npm registry.
|
|
7
|
+
import crypto from 'node:crypto';
|
|
7
8
|
import fs from 'node:fs';
|
|
8
9
|
import path from 'node:path';
|
|
9
10
|
import { fileURLToPath } from 'node:url';
|
|
@@ -11,6 +12,8 @@ import { spawnSync } from 'node:child_process';
|
|
|
11
12
|
import { UI } from './utils/cli_ui.js';
|
|
12
13
|
import { causyneHome } from './utils/paths.js';
|
|
13
14
|
import { getPackageVersion } from './version.js';
|
|
15
|
+
import { probeOsSandbox, resolveOsSandboxMode } from './tools/osSandbox.js';
|
|
16
|
+
import { probeOsKeychain, resolveKeychainMode } from './osKeychain.js';
|
|
14
17
|
const PACKAGE_NAME = '@causyne/agent';
|
|
15
18
|
const REGISTRY_LATEST = 'https://registry.npmjs.org/@causyne%2fagent/latest';
|
|
16
19
|
const DEFAULT_CHECK_INTERVAL_MS = 0; // A bare 'causyne' checks the published version on every launch
|
|
@@ -140,23 +143,110 @@ function writeState(state, options = {}) {
|
|
|
140
143
|
// Update state is an optimisation. Failure must never stop the CLI.
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
|
-
|
|
146
|
+
const SRI_PATTERN = /^(sha512|sha384|sha256)-([A-Za-z0-9+/]+={0,2})$/;
|
|
147
|
+
function isOfficialRegistryHttpsUrl(rawUrl) {
|
|
148
|
+
if (typeof rawUrl !== 'string' || !rawUrl.trim())
|
|
149
|
+
return false;
|
|
150
|
+
try {
|
|
151
|
+
const parsed = new URL(rawUrl.trim());
|
|
152
|
+
return parsed.protocol === 'https:' && parsed.hostname === 'registry.npmjs.org';
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Verifies constant-time SRI integrity (`sha512-...`, `sha384-...`, or `sha256-...`)
|
|
160
|
+
* of a downloaded tarball buffer against the registry-declared integrity string.
|
|
161
|
+
*/
|
|
162
|
+
export function verifyTarballIntegrity(data, expectedIntegrity) {
|
|
163
|
+
if (!Buffer.isBuffer(data) || typeof expectedIntegrity !== 'string')
|
|
164
|
+
return false;
|
|
165
|
+
const match = expectedIntegrity.trim().match(SRI_PATTERN);
|
|
166
|
+
if (!match)
|
|
167
|
+
return false;
|
|
168
|
+
const algorithm = match[1];
|
|
169
|
+
const expectedDigest = Buffer.from(match[2], 'base64');
|
|
170
|
+
const actualDigest = crypto.createHash(algorithm).update(data).digest();
|
|
171
|
+
if (expectedDigest.length !== actualDigest.length)
|
|
172
|
+
return false;
|
|
173
|
+
return crypto.timingSafeEqual(expectedDigest, actualDigest);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Validates npm registry metadata for `@causyne/agent`, enforcing official HTTPS
|
|
177
|
+
* tarball origin, valid SRI integrity format, and optional Sigstore provenance
|
|
178
|
+
* attestation checks (`requireProvenance` or `CAUSYNE_REQUIRE_PROVENANCE=1`).
|
|
179
|
+
*/
|
|
180
|
+
export function verifyRegistryMetadataIntegrity(metadata, options = {}) {
|
|
181
|
+
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
|
|
182
|
+
throw new Error('npm registry returned invalid package metadata');
|
|
183
|
+
}
|
|
184
|
+
const record = metadata;
|
|
185
|
+
if (record.name !== PACKAGE_NAME || typeof record.version !== 'string' || !versionParts(record.version)) {
|
|
186
|
+
throw new Error('npm registry returned invalid package metadata');
|
|
187
|
+
}
|
|
188
|
+
let tarballUrl;
|
|
189
|
+
let integrity;
|
|
190
|
+
let attestationUrl;
|
|
191
|
+
let provenanceVerified = false;
|
|
192
|
+
if (record.dist !== undefined) {
|
|
193
|
+
if (!record.dist || typeof record.dist !== 'object' || Array.isArray(record.dist)) {
|
|
194
|
+
throw new Error('npm registry returned malformed dist metadata');
|
|
195
|
+
}
|
|
196
|
+
if (record.dist.tarball !== undefined) {
|
|
197
|
+
if (!isOfficialRegistryHttpsUrl(record.dist.tarball)) {
|
|
198
|
+
throw new Error('npm registry tarball URL must use HTTPS on registry.npmjs.org');
|
|
199
|
+
}
|
|
200
|
+
tarballUrl = record.dist.tarball;
|
|
201
|
+
}
|
|
202
|
+
if (record.dist.integrity !== undefined) {
|
|
203
|
+
if (typeof record.dist.integrity !== 'string' || !SRI_PATTERN.test(record.dist.integrity.trim())) {
|
|
204
|
+
throw new Error('npm registry returned malformed SRI integrity digest');
|
|
205
|
+
}
|
|
206
|
+
integrity = record.dist.integrity.trim();
|
|
207
|
+
}
|
|
208
|
+
if (record.dist.attestations && typeof record.dist.attestations === 'object') {
|
|
209
|
+
const attUrl = record.dist.attestations.url;
|
|
210
|
+
const predicateType = record.dist.attestations.provenance?.predicateType;
|
|
211
|
+
if (isOfficialRegistryHttpsUrl(attUrl) && typeof predicateType === 'string' && predicateType.length > 0) {
|
|
212
|
+
attestationUrl = attUrl;
|
|
213
|
+
provenanceVerified = true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (options.requireProvenance && !provenanceVerified) {
|
|
218
|
+
throw new Error(`Release ${PACKAGE_NAME}@${record.version} lacks verified npm provenance attestations.`);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
version: record.version,
|
|
222
|
+
...(tarballUrl ? { tarballUrl } : {}),
|
|
223
|
+
...(integrity ? { integrity } : {}),
|
|
224
|
+
provenanceVerified,
|
|
225
|
+
...(attestationUrl ? { attestationUrl } : {})
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export async function latestPackageRelease(options = {}) {
|
|
144
229
|
const fetchImpl = options.fetchImpl || globalThis.fetch;
|
|
145
230
|
if (typeof fetchImpl !== 'function')
|
|
146
231
|
throw new Error('This Node.js runtime has no fetch implementation.');
|
|
147
232
|
const timeoutMs = options.timeoutMs || 3500;
|
|
148
233
|
const signal = options.signal || AbortSignal.timeout(timeoutMs);
|
|
234
|
+
const env = options.env || process.env;
|
|
235
|
+
const requireProvenance = options.requireProvenance
|
|
236
|
+
?? (env.CAUSYNE_REQUIRE_PROVENANCE === '1' || env.CAUSYNE_REQUIRE_PROVENANCE === 'true');
|
|
149
237
|
const response = await fetchImpl(REGISTRY_LATEST, {
|
|
150
238
|
headers: { accept: 'application/json', 'user-agent': `causyne/${getPackageVersion()}` },
|
|
239
|
+
redirect: 'error',
|
|
151
240
|
signal
|
|
152
241
|
});
|
|
153
242
|
if (!response.ok)
|
|
154
243
|
throw new Error(`npm registry returned HTTP ${response.status}`);
|
|
155
|
-
const metadata =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
244
|
+
const metadata = await response.json();
|
|
245
|
+
return verifyRegistryMetadataIntegrity(metadata, { requireProvenance });
|
|
246
|
+
}
|
|
247
|
+
export async function latestPackageVersion(options = {}) {
|
|
248
|
+
const release = await latestPackageRelease(options);
|
|
249
|
+
return release.version;
|
|
160
250
|
}
|
|
161
251
|
function installLatest(info, options = {}) {
|
|
162
252
|
if (!info.prefix) {
|
|
@@ -195,8 +285,14 @@ function installLatest(info, options = {}) {
|
|
|
195
285
|
}
|
|
196
286
|
export async function checkForUpdate(options = {}) {
|
|
197
287
|
const current = options.currentVersion || getPackageVersion();
|
|
198
|
-
const
|
|
199
|
-
return {
|
|
288
|
+
const release = await latestPackageRelease(options);
|
|
289
|
+
return {
|
|
290
|
+
current,
|
|
291
|
+
latest: release.version,
|
|
292
|
+
available: compareVersions(release.version, current) > 0,
|
|
293
|
+
provenanceVerified: release.provenanceVerified,
|
|
294
|
+
...(release.integrity ? { integrity: release.integrity } : {})
|
|
295
|
+
};
|
|
200
296
|
}
|
|
201
297
|
export async function runSelfUpdate(verbose = false, options = {}) {
|
|
202
298
|
const info = installationInfo(options);
|
|
@@ -277,14 +373,21 @@ export async function diagnoseInstallation(options = {}) {
|
|
|
277
373
|
};
|
|
278
374
|
}
|
|
279
375
|
export function formatDoctorReport(status, runtime = process) {
|
|
376
|
+
const sandboxCap = probeOsSandbox();
|
|
377
|
+
const sandboxMode = resolveOsSandboxMode(runtime.env);
|
|
378
|
+
const keychainCap = probeOsKeychain({ env: runtime.env });
|
|
379
|
+
const keychainMode = resolveKeychainMode(runtime.env);
|
|
280
380
|
const rows = [
|
|
281
381
|
`Version : ${status.current || 'unknown'}`,
|
|
282
382
|
`Latest : ${status.latest || `unavailable (${status.error || 'unknown error'})`}`,
|
|
383
|
+
`Provenance : ${status.provenanceVerified ? 'verified (npm Sigstore attestation)' : 'unverified / not reported'}`,
|
|
283
384
|
`Installation : ${status.type}`,
|
|
284
385
|
`Package root : ${status.packageRoot}`,
|
|
285
386
|
`NPM command : ${status.npmCommand}`,
|
|
286
387
|
`Node.js : ${runtime.version}`,
|
|
287
388
|
`Platform : ${runtime.platform} ${runtime.arch}`,
|
|
389
|
+
`OS Sandbox : ${sandboxMode.mode} (backend: ${sandboxCap.backend}${sandboxCap.available ? ', available' : ', unavailable'})`,
|
|
390
|
+
`OS Keychain : ${keychainMode} (backend: ${keychainCap.backend}${keychainCap.available ? ', available' : ', unavailable'})`,
|
|
288
391
|
`Auto updates : ${status.autoUpdates ? 'enabled' : 'disabled'}`,
|
|
289
392
|
`Workspace : ${runtime.cwd()}`
|
|
290
393
|
];
|
package/src/autoUpdate.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// passed as argv arrays with shell disabled, and the only accepted package is
|
|
6
6
|
// the public @causyne/agent package from the npm registry.
|
|
7
7
|
|
|
8
|
+
import crypto from 'node:crypto';
|
|
8
9
|
import fs from 'node:fs';
|
|
9
10
|
import path from 'node:path';
|
|
10
11
|
import { fileURLToPath } from 'node:url';
|
|
@@ -13,6 +14,8 @@ import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
|
|
|
13
14
|
import { UI } from './utils/cli_ui.js';
|
|
14
15
|
import { causyneHome } from './utils/paths.js';
|
|
15
16
|
import { getPackageVersion } from './version.js';
|
|
17
|
+
import { probeOsSandbox, resolveOsSandboxMode } from './tools/osSandbox.js';
|
|
18
|
+
import { probeOsKeychain, resolveKeychainMode } from './osKeychain.js';
|
|
16
19
|
|
|
17
20
|
const PACKAGE_NAME = '@causyne/agent';
|
|
18
21
|
const REGISTRY_LATEST = 'https://registry.npmjs.org/@causyne%2fagent/latest';
|
|
@@ -46,6 +49,15 @@ export interface CheckUpdateOptions {
|
|
|
46
49
|
timeoutMs?: number;
|
|
47
50
|
signal?: AbortSignal;
|
|
48
51
|
env?: NodeJS.ProcessEnv;
|
|
52
|
+
requireProvenance?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface VerifiedReleaseMetadata {
|
|
56
|
+
version: string;
|
|
57
|
+
tarballUrl?: string | undefined;
|
|
58
|
+
integrity?: string | undefined;
|
|
59
|
+
provenanceVerified: boolean;
|
|
60
|
+
attestationUrl?: string | undefined;
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
export interface SelfUpdateOptions extends CheckUpdateOptions {
|
|
@@ -61,6 +73,8 @@ export interface CheckResult {
|
|
|
61
73
|
current: string;
|
|
62
74
|
latest: string;
|
|
63
75
|
available: boolean;
|
|
76
|
+
provenanceVerified?: boolean | undefined;
|
|
77
|
+
integrity?: string | undefined;
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
export interface UpdateResult extends InstallationInfo {
|
|
@@ -76,6 +90,8 @@ export interface DiagnosisResult extends InstallationInfo {
|
|
|
76
90
|
current?: string | undefined;
|
|
77
91
|
latest?: string | null | undefined;
|
|
78
92
|
available?: boolean | undefined;
|
|
93
|
+
provenanceVerified?: boolean | undefined;
|
|
94
|
+
integrity?: string | undefined;
|
|
79
95
|
autoUpdates: boolean;
|
|
80
96
|
error?: string | undefined;
|
|
81
97
|
}
|
|
@@ -202,21 +218,128 @@ function writeState(state: UpdateState, options: { stateFile?: string; env?: Nod
|
|
|
202
218
|
}
|
|
203
219
|
}
|
|
204
220
|
|
|
205
|
-
|
|
221
|
+
const SRI_PATTERN = /^(sha512|sha384|sha256)-([A-Za-z0-9+/]+={0,2})$/;
|
|
222
|
+
|
|
223
|
+
function isOfficialRegistryHttpsUrl(rawUrl: unknown): rawUrl is string {
|
|
224
|
+
if (typeof rawUrl !== 'string' || !rawUrl.trim()) return false;
|
|
225
|
+
try {
|
|
226
|
+
const parsed = new URL(rawUrl.trim());
|
|
227
|
+
return parsed.protocol === 'https:' && parsed.hostname === 'registry.npmjs.org';
|
|
228
|
+
} catch {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Verifies constant-time SRI integrity (`sha512-...`, `sha384-...`, or `sha256-...`)
|
|
235
|
+
* of a downloaded tarball buffer against the registry-declared integrity string.
|
|
236
|
+
*/
|
|
237
|
+
export function verifyTarballIntegrity(data: Buffer, expectedIntegrity: string): boolean {
|
|
238
|
+
if (!Buffer.isBuffer(data) || typeof expectedIntegrity !== 'string') return false;
|
|
239
|
+
const match = expectedIntegrity.trim().match(SRI_PATTERN);
|
|
240
|
+
if (!match) return false;
|
|
241
|
+
const algorithm = match[1]!;
|
|
242
|
+
const expectedDigest = Buffer.from(match[2]!, 'base64');
|
|
243
|
+
const actualDigest = crypto.createHash(algorithm).update(data).digest();
|
|
244
|
+
if (expectedDigest.length !== actualDigest.length) return false;
|
|
245
|
+
return crypto.timingSafeEqual(expectedDigest, actualDigest);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Validates npm registry metadata for `@causyne/agent`, enforcing official HTTPS
|
|
250
|
+
* tarball origin, valid SRI integrity format, and optional Sigstore provenance
|
|
251
|
+
* attestation checks (`requireProvenance` or `CAUSYNE_REQUIRE_PROVENANCE=1`).
|
|
252
|
+
*/
|
|
253
|
+
export function verifyRegistryMetadataIntegrity(
|
|
254
|
+
metadata: unknown,
|
|
255
|
+
options: { requireProvenance?: boolean | undefined } = {}
|
|
256
|
+
): VerifiedReleaseMetadata {
|
|
257
|
+
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
|
|
258
|
+
throw new Error('npm registry returned invalid package metadata');
|
|
259
|
+
}
|
|
260
|
+
const record = metadata as {
|
|
261
|
+
name?: unknown;
|
|
262
|
+
version?: unknown;
|
|
263
|
+
dist?: {
|
|
264
|
+
tarball?: unknown;
|
|
265
|
+
integrity?: unknown;
|
|
266
|
+
attestations?: {
|
|
267
|
+
url?: unknown;
|
|
268
|
+
provenance?: { predicateType?: unknown };
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
if (record.name !== PACKAGE_NAME || typeof record.version !== 'string' || !versionParts(record.version)) {
|
|
274
|
+
throw new Error('npm registry returned invalid package metadata');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let tarballUrl: string | undefined;
|
|
278
|
+
let integrity: string | undefined;
|
|
279
|
+
let attestationUrl: string | undefined;
|
|
280
|
+
let provenanceVerified = false;
|
|
281
|
+
|
|
282
|
+
if (record.dist !== undefined) {
|
|
283
|
+
if (!record.dist || typeof record.dist !== 'object' || Array.isArray(record.dist)) {
|
|
284
|
+
throw new Error('npm registry returned malformed dist metadata');
|
|
285
|
+
}
|
|
286
|
+
if (record.dist.tarball !== undefined) {
|
|
287
|
+
if (!isOfficialRegistryHttpsUrl(record.dist.tarball)) {
|
|
288
|
+
throw new Error('npm registry tarball URL must use HTTPS on registry.npmjs.org');
|
|
289
|
+
}
|
|
290
|
+
tarballUrl = record.dist.tarball;
|
|
291
|
+
}
|
|
292
|
+
if (record.dist.integrity !== undefined) {
|
|
293
|
+
if (typeof record.dist.integrity !== 'string' || !SRI_PATTERN.test(record.dist.integrity.trim())) {
|
|
294
|
+
throw new Error('npm registry returned malformed SRI integrity digest');
|
|
295
|
+
}
|
|
296
|
+
integrity = record.dist.integrity.trim();
|
|
297
|
+
}
|
|
298
|
+
if (record.dist.attestations && typeof record.dist.attestations === 'object') {
|
|
299
|
+
const attUrl = record.dist.attestations.url;
|
|
300
|
+
const predicateType = record.dist.attestations.provenance?.predicateType;
|
|
301
|
+
if (isOfficialRegistryHttpsUrl(attUrl) && typeof predicateType === 'string' && predicateType.length > 0) {
|
|
302
|
+
attestationUrl = attUrl;
|
|
303
|
+
provenanceVerified = true;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (options.requireProvenance && !provenanceVerified) {
|
|
309
|
+
throw new Error(`Release ${PACKAGE_NAME}@${record.version} lacks verified npm provenance attestations.`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
version: record.version,
|
|
314
|
+
...(tarballUrl ? { tarballUrl } : {}),
|
|
315
|
+
...(integrity ? { integrity } : {}),
|
|
316
|
+
provenanceVerified,
|
|
317
|
+
...(attestationUrl ? { attestationUrl } : {})
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export async function latestPackageRelease(options: CheckUpdateOptions = {}): Promise<VerifiedReleaseMetadata> {
|
|
206
322
|
const fetchImpl = options.fetchImpl || globalThis.fetch;
|
|
207
323
|
if (typeof fetchImpl !== 'function') throw new Error('This Node.js runtime has no fetch implementation.');
|
|
208
324
|
const timeoutMs = options.timeoutMs || 3500;
|
|
209
325
|
const signal = options.signal || AbortSignal.timeout(timeoutMs);
|
|
326
|
+
const env = options.env || process.env;
|
|
327
|
+
const requireProvenance = options.requireProvenance
|
|
328
|
+
?? (env.CAUSYNE_REQUIRE_PROVENANCE === '1' || env.CAUSYNE_REQUIRE_PROVENANCE === 'true');
|
|
329
|
+
|
|
210
330
|
const response = await fetchImpl(REGISTRY_LATEST, {
|
|
211
331
|
headers: { accept: 'application/json', 'user-agent': `causyne/${getPackageVersion()}` },
|
|
332
|
+
redirect: 'error',
|
|
212
333
|
signal
|
|
213
334
|
});
|
|
214
335
|
if (!response.ok) throw new Error(`npm registry returned HTTP ${response.status}`);
|
|
215
|
-
const metadata =
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
336
|
+
const metadata: unknown = await response.json();
|
|
337
|
+
return verifyRegistryMetadataIntegrity(metadata, { requireProvenance });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export async function latestPackageVersion(options: CheckUpdateOptions = {}): Promise<string> {
|
|
341
|
+
const release = await latestPackageRelease(options);
|
|
342
|
+
return release.version;
|
|
220
343
|
}
|
|
221
344
|
|
|
222
345
|
function installLatest(info: InstallationInfo, options: SelfUpdateOptions = {}): void {
|
|
@@ -260,8 +383,14 @@ function installLatest(info: InstallationInfo, options: SelfUpdateOptions = {}):
|
|
|
260
383
|
|
|
261
384
|
export async function checkForUpdate(options: CheckUpdateOptions = {}): Promise<CheckResult> {
|
|
262
385
|
const current = options.currentVersion || getPackageVersion();
|
|
263
|
-
const
|
|
264
|
-
return {
|
|
386
|
+
const release = await latestPackageRelease(options);
|
|
387
|
+
return {
|
|
388
|
+
current,
|
|
389
|
+
latest: release.version,
|
|
390
|
+
available: compareVersions(release.version, current) > 0,
|
|
391
|
+
provenanceVerified: release.provenanceVerified,
|
|
392
|
+
...(release.integrity ? { integrity: release.integrity } : {})
|
|
393
|
+
};
|
|
265
394
|
}
|
|
266
395
|
|
|
267
396
|
export async function runSelfUpdate(verbose: boolean = false, options: SelfUpdateOptions = {}): Promise<UpdateResult> {
|
|
@@ -344,14 +473,21 @@ export async function diagnoseInstallation(options: CheckUpdateOptions = {}): Pr
|
|
|
344
473
|
}
|
|
345
474
|
|
|
346
475
|
export function formatDoctorReport(status: DiagnosisResult, runtime: typeof process = process): string {
|
|
476
|
+
const sandboxCap = probeOsSandbox();
|
|
477
|
+
const sandboxMode = resolveOsSandboxMode(runtime.env);
|
|
478
|
+
const keychainCap = probeOsKeychain({ env: runtime.env });
|
|
479
|
+
const keychainMode = resolveKeychainMode(runtime.env);
|
|
347
480
|
const rows = [
|
|
348
481
|
`Version : ${status.current || 'unknown'}`,
|
|
349
482
|
`Latest : ${status.latest || `unavailable (${status.error || 'unknown error'})`}`,
|
|
483
|
+
`Provenance : ${status.provenanceVerified ? 'verified (npm Sigstore attestation)' : 'unverified / not reported'}`,
|
|
350
484
|
`Installation : ${status.type}`,
|
|
351
485
|
`Package root : ${status.packageRoot}`,
|
|
352
486
|
`NPM command : ${status.npmCommand}`,
|
|
353
487
|
`Node.js : ${runtime.version}`,
|
|
354
488
|
`Platform : ${runtime.platform} ${runtime.arch}`,
|
|
489
|
+
`OS Sandbox : ${sandboxMode.mode} (backend: ${sandboxCap.backend}${sandboxCap.available ? ', available' : ', unavailable'})`,
|
|
490
|
+
`OS Keychain : ${keychainMode} (backend: ${keychainCap.backend}${keychainCap.available ? ', available' : ', unavailable'})`,
|
|
355
491
|
`Auto updates : ${status.autoUpdates ? 'enabled' : 'disabled'}`,
|
|
356
492
|
`Workspace : ${runtime.cwd()}`
|
|
357
493
|
];
|