osuite 2.9.8 → 2.10.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 +69 -37
- package/cli.js +405 -41
- package/osuite.js +9 -2
- package/package.json +2 -1
- package/projectHooks.js +741 -0
- package/reviewSurface.js +10 -2
package/cli.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
3
4
|
import fs from 'node:fs';
|
|
4
5
|
import path from 'node:path';
|
|
5
6
|
import crypto from 'node:crypto';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { OSuite, buildReviewSurface } from './osuite.js';
|
|
9
|
+
import {
|
|
10
|
+
describeInstallResult,
|
|
11
|
+
findHookInstallations,
|
|
12
|
+
installBlockers,
|
|
13
|
+
installProjectFile,
|
|
14
|
+
resolveProjectPath,
|
|
15
|
+
runHookCheck,
|
|
16
|
+
} from './projectHooks.js';
|
|
8
17
|
|
|
9
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
19
|
const __dirname = path.dirname(__filename);
|
|
@@ -55,6 +64,30 @@ const PROJECT_BOOTSTRAPS = {
|
|
|
55
64
|
},
|
|
56
65
|
};
|
|
57
66
|
|
|
67
|
+
const RUNTIME_COVERAGE_TIERS = [
|
|
68
|
+
{
|
|
69
|
+
id: 'reference',
|
|
70
|
+
label: 'Reference adapters',
|
|
71
|
+
summary: 'Open CAVA schemas, parser-pack contracts, and reproducible local examples.',
|
|
72
|
+
cli: 'cava scan ./repo --adapter github-actions --adapter package-json',
|
|
73
|
+
studio: 'Shown as reference coverage only; production lanes should upgrade to managed coverage.',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'managed',
|
|
77
|
+
label: 'Managed OSuite adapters',
|
|
78
|
+
summary: 'OSuite-maintained adapters for Codex, Claude, ChatGPT Apps, MCP, SDK, hooks, and workflow runtimes.',
|
|
79
|
+
cli: 'osuite connect auto && osuite adapters status',
|
|
80
|
+
studio: 'Shown in Runtime Coverage with parser posture, evidence gaps, and remediation paths.',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'enterprise_custom',
|
|
84
|
+
label: 'Enterprise custom adapters',
|
|
85
|
+
summary: 'Customer-specific mapping for ERP, CRM, ticketing, payments, manufacturing, warehouses, and private workflows.',
|
|
86
|
+
cli: 'osuite adapter init acme-erp && osuite adapter test .osuite/adapters/acme-erp.json',
|
|
87
|
+
studio: 'Shown as customer runtime coverage with versioning, field mapping, approval routing, and proof export.',
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
|
|
58
91
|
function useColor() {
|
|
59
92
|
return !process.env.NO_COLOR && process.stdout.isTTY !== false;
|
|
60
93
|
}
|
|
@@ -106,6 +139,8 @@ function parseArgs(argv) {
|
|
|
106
139
|
return { command, args };
|
|
107
140
|
}
|
|
108
141
|
|
|
142
|
+
// Hooks run with the agent's environment, not the values this CLI loads from project .env files.
|
|
143
|
+
const SHELL_ENV = { ...process.env };
|
|
109
144
|
loadProjectEnvironment();
|
|
110
145
|
|
|
111
146
|
function envValue(name, fallback) {
|
|
@@ -285,6 +320,33 @@ async function startDeviceConnect({ baseUrl, runtime, agentId }) {
|
|
|
285
320
|
return payload;
|
|
286
321
|
}
|
|
287
322
|
|
|
323
|
+
// Opens the handoff in the browser, as `gh auth login` does. Not with
|
|
324
|
+
// --no-browser or OSUITE_NO_BROWSER=1, in CI, over SSH, without a terminal or
|
|
325
|
+
// a Linux display: there the printed link is opened by hand.
|
|
326
|
+
function shouldOpenBrowser(args = {}, env = process.env) {
|
|
327
|
+
if (args['no-browser']) return false;
|
|
328
|
+
if (['1', 'true', 'yes'].includes(String(env.OSUITE_NO_BROWSER || '').trim().toLowerCase())) return false;
|
|
329
|
+
if (env.CI || env.SSH_CONNECTION || env.SSH_TTY) return false;
|
|
330
|
+
if (process.platform === 'linux' && !env.DISPLAY && !env.WAYLAND_DISPLAY) return false;
|
|
331
|
+
return Boolean(process.stdout.isTTY);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function openInBrowser(url) {
|
|
335
|
+
const [command, commandArgs] = process.platform === 'darwin'
|
|
336
|
+
? ['open', [url]]
|
|
337
|
+
: process.platform === 'win32'
|
|
338
|
+
? ['rundll32', ['url.dll,FileProtocolHandler', url]]
|
|
339
|
+
: ['xdg-open', [url]];
|
|
340
|
+
try {
|
|
341
|
+
const child = spawn(command, commandArgs, { stdio: 'ignore', detached: true });
|
|
342
|
+
child.on('error', () => {});
|
|
343
|
+
child.unref();
|
|
344
|
+
return true;
|
|
345
|
+
} catch {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
288
350
|
async function pollDeviceConnect({ baseUrl, deviceCode, pollToken, timeoutMs, intervalMs }) {
|
|
289
351
|
const deadline = Date.now() + timeoutMs;
|
|
290
352
|
while (Date.now() <= deadline) {
|
|
@@ -302,7 +364,7 @@ async function pollDeviceConnect({ baseUrl, deviceCode, pollToken, timeoutMs, in
|
|
|
302
364
|
continue;
|
|
303
365
|
}
|
|
304
366
|
if (response.status === 410 || payload.status === 'expired') {
|
|
305
|
-
throw new Error('
|
|
367
|
+
throw new Error('The connect code expired before it was approved. Run osuite connect again for a new code.');
|
|
306
368
|
}
|
|
307
369
|
if (response.status === 409 || payload.status === 'consumed') {
|
|
308
370
|
throw new Error(payload.error || 'Browser handoff was already consumed.');
|
|
@@ -316,13 +378,7 @@ async function pollDeviceConnect({ baseUrl, deviceCode, pollToken, timeoutMs, in
|
|
|
316
378
|
}
|
|
317
379
|
|
|
318
380
|
function projectFilePath(relativePath) {
|
|
319
|
-
|
|
320
|
-
const root = path.resolve(process.cwd());
|
|
321
|
-
const absolute = path.resolve(root, clean);
|
|
322
|
-
if (absolute !== root && !absolute.startsWith(`${root}${path.sep}`)) {
|
|
323
|
-
throw new Error(`Refusing to write outside the project root: ${relativePath}`);
|
|
324
|
-
}
|
|
325
|
-
return absolute;
|
|
381
|
+
return resolveProjectPath(process.cwd(), relativePath);
|
|
326
382
|
}
|
|
327
383
|
|
|
328
384
|
function writeProjectFile(relativePath, body, { force = false } = {}) {
|
|
@@ -333,6 +389,75 @@ function writeProjectFile(relativePath, body, { force = false } = {}) {
|
|
|
333
389
|
return { relativePath, status: 'written' };
|
|
334
390
|
}
|
|
335
391
|
|
|
392
|
+
function readProjectJsonFile(filePath) {
|
|
393
|
+
const absolute = path.isAbsolute(filePath) ? filePath : projectFilePath(filePath);
|
|
394
|
+
return JSON.parse(fs.readFileSync(absolute, 'utf8'));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function slugifyAdapterName(value) {
|
|
398
|
+
const slug = String(value || 'enterprise-runtime')
|
|
399
|
+
.trim()
|
|
400
|
+
.toLowerCase()
|
|
401
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
402
|
+
.replace(/^-+|-+$/g, '');
|
|
403
|
+
return slug || 'enterprise-runtime';
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function enterpriseAdapterTemplate(adapterId) {
|
|
407
|
+
return {
|
|
408
|
+
schema_version: 'osuite.runtime_adapter_mapping.v1',
|
|
409
|
+
adapter_id: adapterId,
|
|
410
|
+
display_name: adapterId
|
|
411
|
+
.split(/[-_.]+/)
|
|
412
|
+
.filter(Boolean)
|
|
413
|
+
.map((part) => part.slice(0, 1).toUpperCase() + part.slice(1))
|
|
414
|
+
.join(' '),
|
|
415
|
+
coverage_tier: 'enterprise_custom',
|
|
416
|
+
parser_posture: 'enterprise_custom',
|
|
417
|
+
support_model: 'customer_owned_osuite_reviewed',
|
|
418
|
+
description: 'Map a private enterprise runtime event into the CAVA canonical action object.',
|
|
419
|
+
source: {
|
|
420
|
+
kind: 'sample_event',
|
|
421
|
+
runtime_family: 'enterprise_workflow',
|
|
422
|
+
evidence_boundary: 'customer_private_runtime',
|
|
423
|
+
},
|
|
424
|
+
field_map: {
|
|
425
|
+
actor: 'actor.id',
|
|
426
|
+
operation: 'action.operation',
|
|
427
|
+
target: 'action.target',
|
|
428
|
+
systems_touched: 'runtime.system',
|
|
429
|
+
data_boundary: 'data.boundary',
|
|
430
|
+
authority_boundary: 'approval.group',
|
|
431
|
+
reversible: 'action.reversible',
|
|
432
|
+
declared_goal: 'action.goal',
|
|
433
|
+
},
|
|
434
|
+
sample_event: {
|
|
435
|
+
actor: { id: 'agent-or-operator-id' },
|
|
436
|
+
action: {
|
|
437
|
+
operation: 'refund_review',
|
|
438
|
+
target: 'case-123',
|
|
439
|
+
reversible: false,
|
|
440
|
+
goal: 'Review a high-value customer support case before any external side effect.',
|
|
441
|
+
},
|
|
442
|
+
runtime: { system: 'acme-erp' },
|
|
443
|
+
data: { boundary: 'customer_support_context' },
|
|
444
|
+
approval: { group: 'risk-ops' },
|
|
445
|
+
},
|
|
446
|
+
validation: {
|
|
447
|
+
required_fields: [
|
|
448
|
+
'actor',
|
|
449
|
+
'operation',
|
|
450
|
+
'target',
|
|
451
|
+
'systems_touched',
|
|
452
|
+
'data_boundary',
|
|
453
|
+
'authority_boundary',
|
|
454
|
+
'reversible',
|
|
455
|
+
],
|
|
456
|
+
expected_output: 'CAVA canonical action object with stable semantic key and approval binding.',
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
336
461
|
function remapBootstrapPath(spec, relativePath) {
|
|
337
462
|
if (relativePath === 'README.md') return spec.readmePath;
|
|
338
463
|
return relativePath;
|
|
@@ -352,7 +477,7 @@ async function loadRuntimeBootstrap(spec, args, config) {
|
|
|
352
477
|
return response.json();
|
|
353
478
|
}
|
|
354
479
|
|
|
355
|
-
async function installRuntimeProjectBootstrap(target, args = {}) {
|
|
480
|
+
async function installRuntimeProjectBootstrap(target, args = {}, { nextSteps = true } = {}) {
|
|
356
481
|
const spec = PROJECT_BOOTSTRAPS[target];
|
|
357
482
|
const config = readConfig();
|
|
358
483
|
const bootstrap = await loadRuntimeBootstrap(spec, args, config);
|
|
@@ -360,29 +485,64 @@ async function installRuntimeProjectBootstrap(target, args = {}) {
|
|
|
360
485
|
const results = [];
|
|
361
486
|
|
|
362
487
|
Object.entries(bootstrap.files || {}).forEach(([relativePath, body]) => {
|
|
363
|
-
results.push(
|
|
488
|
+
results.push(installProjectFile(process.cwd(), remapBootstrapPath(spec, relativePath), body, { force }));
|
|
364
489
|
});
|
|
365
490
|
|
|
366
491
|
if (bootstrap.recommended_env) {
|
|
367
|
-
results.push(
|
|
492
|
+
results.push(installProjectFile(process.cwd(), spec.envPath, `${bootstrap.recommended_env.trim()}\n`, { force }));
|
|
368
493
|
}
|
|
369
494
|
|
|
370
|
-
const
|
|
371
|
-
const
|
|
495
|
+
const blockers = installBlockers(results);
|
|
496
|
+
const colors = { created: ANSI.green, merged: ANSI.green, replaced: ANSI.green, failed: ANSI.red, kept: ANSI.yellow };
|
|
372
497
|
|
|
373
498
|
write(c(spec.label, ANSI.bold));
|
|
374
499
|
write(`Installing project files into ${process.cwd()}`);
|
|
375
500
|
write('');
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
501
|
+
results.forEach((result) => {
|
|
502
|
+
describeInstallResult(result).forEach((line) => {
|
|
503
|
+
const status = line.split(/\s+/)[0];
|
|
504
|
+
write(` ${colors[status] ? `${c(status, colors[status])}${line.slice(status.length)}` : line}`);
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
if (blockers.length) {
|
|
508
|
+
write('');
|
|
509
|
+
write(c('OSuite hook setup is not ready, so this agent is not governed:', ANSI.red));
|
|
510
|
+
blockers.forEach((blocker) => write(` ${blocker}`));
|
|
511
|
+
}
|
|
512
|
+
if (nextSteps) {
|
|
513
|
+
write('');
|
|
514
|
+
write(c('Next steps', ANSI.bold));
|
|
515
|
+
write(` 1. Copy ${spec.envPath} to ${spec.envPath.replace(/\.example$/, '')} and fill OSUITE_API_KEY.`);
|
|
516
|
+
write(' 2. Run osuite doctor. It checks project enablement, connection, telemetry, and governance with a direct hook probe.');
|
|
517
|
+
write(` 3. ${spec.runLine}`);
|
|
518
|
+
write(` 4. ${spec.smokeLine}`);
|
|
519
|
+
write('');
|
|
520
|
+
write(c('OSuite CLI is the control surface; the project hook files are what intercept agent actions.', ANSI.dim));
|
|
521
|
+
}
|
|
522
|
+
return { ok: blockers.length === 0, results, blockers };
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function writeCheckLine(status, label, detail) {
|
|
526
|
+
const tags = {
|
|
527
|
+
ok: c('OK ', ANSI.green),
|
|
528
|
+
miss: c('MISS', ANSI.yellow),
|
|
529
|
+
warn: c('WARN', ANSI.yellow),
|
|
530
|
+
fail: c('FAIL', ANSI.red),
|
|
531
|
+
};
|
|
532
|
+
write(`${tags[status]} ${label.padEnd(18)} ${detail}`);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// A telemetry-only result must never count as successful governance.
|
|
536
|
+
async function verifyProjectHooks(runtimes) {
|
|
537
|
+
const installations = findHookInstallations(process.cwd(), runtimes);
|
|
538
|
+
const checks = [];
|
|
539
|
+
for (const installation of installations) {
|
|
540
|
+
const check = await runHookCheck({ projectRoot: process.cwd(), installation, shellEnv: SHELL_ENV });
|
|
541
|
+
check.steps.forEach((step) => writeCheckLine(step.ok ? 'ok' : 'fail', step.label, `${installation.label}: ${step.detail}`));
|
|
542
|
+
(check.warnings || []).forEach((warning) => writeCheckLine('warn', 'Hook warning', `${installation.label}: ${warning}`));
|
|
543
|
+
checks.push({ installation, ...check });
|
|
544
|
+
}
|
|
545
|
+
return checks;
|
|
386
546
|
}
|
|
387
547
|
|
|
388
548
|
function banner() {
|
|
@@ -399,16 +559,21 @@ function printHelp() {
|
|
|
399
559
|
write(c(`OSuite CLI v${pkg.version}`, ANSI.dim));
|
|
400
560
|
write('');
|
|
401
561
|
write(c('Useful commands', ANSI.bold));
|
|
402
|
-
write(' osuite doctor Check connection,
|
|
562
|
+
write(' osuite doctor Check connection, then run the project hook with a sample call');
|
|
403
563
|
write(' osuite status Ping Studio and show current workspace connection');
|
|
404
564
|
write(' osuite explain "git push origin main" Explain how CAVA/Decision V2 will read a command');
|
|
405
565
|
write(' osuite approvals --limit 20 Show pending approval inbox');
|
|
406
566
|
write(' osuite review <actionId> Render the decision review card');
|
|
407
|
-
write(' osuite approve <actionId>
|
|
567
|
+
write(' osuite approve <actionId> Approve from the CLI where the workspace allows it;');
|
|
568
|
+
write(' otherwise prints the Studio link to approve it');
|
|
408
569
|
write(' osuite deny <actionId> --reason "Outside change window"');
|
|
570
|
+
write(' osuite adapters [status|coverage] Explain Runtime Coverage tiers and next steps');
|
|
571
|
+
write(' osuite adapter init <name> Scaffold an enterprise custom adapter mapping');
|
|
572
|
+
write(' osuite adapter test <file> Validate an enterprise custom adapter mapping');
|
|
409
573
|
write(' osuite external status Show external verifier network setup and usage');
|
|
410
|
-
write(' osuite external configure --provider babyblue_invinoveritas --mode shadow --api-key <key>');
|
|
574
|
+
write(' osuite external configure --provider babyblue_invinoveritas --mode shadow --api-key <key> --expected-source-class independent_mediator');
|
|
411
575
|
write(' osuite connect [auto|codex|claude|sdk|mcp] Detect runtime and start browser handoff');
|
|
576
|
+
write(' --no-browser prints the link instead of opening it');
|
|
412
577
|
write(' osuite init [sdk|codex|claude|mcp] Print setup steps for a runtime lane');
|
|
413
578
|
write('');
|
|
414
579
|
write(c('Environment', ANSI.bold));
|
|
@@ -419,6 +584,146 @@ function printHelp() {
|
|
|
419
584
|
write(c('Old DASHCLAW_* environment names are still accepted for compatibility.', ANSI.dim));
|
|
420
585
|
}
|
|
421
586
|
|
|
587
|
+
function printRuntimeCoverage(args = {}) {
|
|
588
|
+
const config = readConfig();
|
|
589
|
+
const subcommand = args._[0] || 'status';
|
|
590
|
+
write(c('OSuite Runtime Coverage', `${ANSI.bold}${ANSI.cyan}`));
|
|
591
|
+
write(c('CAVA adapter coverage is split into reference, managed, and enterprise custom layers.', ANSI.dim));
|
|
592
|
+
write('');
|
|
593
|
+
|
|
594
|
+
for (const tier of RUNTIME_COVERAGE_TIERS) {
|
|
595
|
+
write(c(tier.label, ANSI.bold));
|
|
596
|
+
write(` id ${tier.id}`);
|
|
597
|
+
write(` purpose ${tier.summary}`);
|
|
598
|
+
write(` cli ${tier.cli}`);
|
|
599
|
+
write(` studio ${tier.studio}`);
|
|
600
|
+
write(` fields coverage_tier=${tier.id}; parser_posture=${tier.id === 'reference' ? 'reference' : tier.id}`);
|
|
601
|
+
write('');
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (subcommand === 'coverage') {
|
|
605
|
+
write(c('Workspace coverage', ANSI.bold));
|
|
606
|
+
if (config.baseUrl && config.apiKey) {
|
|
607
|
+
write(` Studio report ${normalizedBaseUrl(config.baseUrl)}/runtime-security`);
|
|
608
|
+
write(' Export /api/runtime-security/report?format=md&download=1');
|
|
609
|
+
write(' Note The Studio report is the source of truth for connected lanes and parser posture.');
|
|
610
|
+
} else {
|
|
611
|
+
write(' Not connected. Run `osuite connect auto` or set OSUITE_BASE_URL and OSUITE_API_KEY.');
|
|
612
|
+
}
|
|
613
|
+
write('');
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
write(c('Rule of thumb', ANSI.bold));
|
|
617
|
+
write(' Reference teaches the action language. Managed makes common runtimes easy. Enterprise custom maps private systems without changing CAVA core.');
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function validateEnterpriseAdapterMapping(mapping = {}) {
|
|
621
|
+
const problems = [];
|
|
622
|
+
if (mapping.schema_version !== 'osuite.runtime_adapter_mapping.v1') problems.push('schema_version must be osuite.runtime_adapter_mapping.v1');
|
|
623
|
+
if (!mapping.adapter_id) problems.push('adapter_id is required');
|
|
624
|
+
if (mapping.coverage_tier !== 'enterprise_custom') problems.push('coverage_tier must be enterprise_custom');
|
|
625
|
+
if (!mapping.field_map || typeof mapping.field_map !== 'object') problems.push('field_map is required');
|
|
626
|
+
|
|
627
|
+
const required = mapping.validation?.required_fields || [
|
|
628
|
+
'actor',
|
|
629
|
+
'operation',
|
|
630
|
+
'target',
|
|
631
|
+
'systems_touched',
|
|
632
|
+
'data_boundary',
|
|
633
|
+
'authority_boundary',
|
|
634
|
+
'reversible',
|
|
635
|
+
];
|
|
636
|
+
|
|
637
|
+
required.forEach((field) => {
|
|
638
|
+
if (!mapping.field_map?.[field]) problems.push(`field_map.${field} is required`);
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
if (!mapping.sample_event || typeof mapping.sample_event !== 'object') problems.push('sample_event is required');
|
|
642
|
+
return { ok: problems.length === 0, problems, required };
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function printEnterpriseAdapterValidation(mapping, filePath) {
|
|
646
|
+
const validation = validateEnterpriseAdapterMapping(mapping);
|
|
647
|
+
write(c('Enterprise custom adapter', `${ANSI.bold}${ANSI.cyan}`));
|
|
648
|
+
write(c('Local CAVA mapping check. No server call was made.', ANSI.dim));
|
|
649
|
+
write('');
|
|
650
|
+
write(`File ${filePath}`);
|
|
651
|
+
write(`Adapter ${mapping.adapter_id || 'missing'}`);
|
|
652
|
+
write(`coverage_tier ${mapping.coverage_tier || 'missing'}`);
|
|
653
|
+
write(`parser_posture ${mapping.parser_posture || 'missing'}`);
|
|
654
|
+
write(`support_model ${mapping.support_model || 'missing'}`);
|
|
655
|
+
write('');
|
|
656
|
+
|
|
657
|
+
if (!validation.ok) {
|
|
658
|
+
write(c('Mapping problems', ANSI.red));
|
|
659
|
+
validation.problems.forEach((problem) => write(` - ${problem}`));
|
|
660
|
+
return validation;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
write(c('adapter mapping looks usable', ANSI.green));
|
|
664
|
+
write('Required CAVA fields are mapped:');
|
|
665
|
+
validation.required.forEach((field) => write(` - ${field} <- ${mapping.field_map[field]}`));
|
|
666
|
+
write('');
|
|
667
|
+
write(c('Next step', ANSI.bold));
|
|
668
|
+
write(' Review the mapping with the runtime owner, then open Studio > Runtime Security > Runtime Coverage to register it.');
|
|
669
|
+
return validation;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
function enterpriseAdapter(args = {}) {
|
|
673
|
+
const subcommand = args._[0] || 'help';
|
|
674
|
+
|
|
675
|
+
if (subcommand === 'init') {
|
|
676
|
+
const adapterId = slugifyAdapterName(args._[1] || args.name || 'enterprise-runtime');
|
|
677
|
+
const relativePath = `.osuite/adapters/${adapterId}.json`;
|
|
678
|
+
const template = enterpriseAdapterTemplate(adapterId);
|
|
679
|
+
const result = writeProjectFile(relativePath, `${JSON.stringify(template, null, 2)}\n`, { force: Boolean(args.force) });
|
|
680
|
+
|
|
681
|
+
write(c('Enterprise custom adapter', `${ANSI.bold}${ANSI.cyan}`));
|
|
682
|
+
write(c('Scaffolded a private-runtime mapping for CAVA Runtime Coverage.', ANSI.dim));
|
|
683
|
+
write('');
|
|
684
|
+
write(`${result.status === 'written' ? c('created', ANSI.green) : c('kept ', ANSI.yellow)} ${relativePath}`);
|
|
685
|
+
write('');
|
|
686
|
+
write(c('Next steps', ANSI.bold));
|
|
687
|
+
write(` 1. Edit ${relativePath} so field_map points at your real runtime event fields.`);
|
|
688
|
+
write(` 2. Run osuite adapter test ${relativePath}.`);
|
|
689
|
+
write(' 3. Register the validated mapping in Studio > Runtime Security > Runtime Coverage.');
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
if (subcommand === 'test') {
|
|
694
|
+
const filePath = args._[1] || '.osuite/adapters/enterprise-runtime.json';
|
|
695
|
+
const mapping = readProjectJsonFile(filePath);
|
|
696
|
+
const validation = printEnterpriseAdapterValidation(mapping, filePath);
|
|
697
|
+
if (!validation.ok) process.exit(1);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
if (subcommand === 'deploy') {
|
|
702
|
+
const filePath = args._[1] || '.osuite/adapters/enterprise-runtime.json';
|
|
703
|
+
const mapping = readProjectJsonFile(filePath);
|
|
704
|
+
const validation = printEnterpriseAdapterValidation(mapping, filePath);
|
|
705
|
+
if (!validation.ok) process.exit(1);
|
|
706
|
+
|
|
707
|
+
const config = readConfig();
|
|
708
|
+
write(c('Deploy status', ANSI.bold));
|
|
709
|
+
if (!config.baseUrl || !config.apiKey) {
|
|
710
|
+
write(' validated locally; no Studio credentials were found.');
|
|
711
|
+
write(' Connect OSuite before deploy: osuite connect auto');
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
write(` validated locally; open ${normalizedBaseUrl(config.baseUrl)}/runtime-security to finish registration.`);
|
|
716
|
+
write(' Studio stores enterprise mappings with workspace policy, versioning, and review ownership.');
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
write(c('Enterprise custom adapter', `${ANSI.bold}${ANSI.cyan}`));
|
|
721
|
+
write('Usage:');
|
|
722
|
+
write(' osuite adapter init <name>');
|
|
723
|
+
write(' osuite adapter test <file>');
|
|
724
|
+
write(' osuite adapter deploy <file>');
|
|
725
|
+
}
|
|
726
|
+
|
|
422
727
|
function tokenize(command) {
|
|
423
728
|
return String(command || '').match(/"[^"]*"|'[^']*'|\S+/g)?.map((token) => token.replace(/^['"]|['"]$/g, '')) || [];
|
|
424
729
|
}
|
|
@@ -741,16 +1046,28 @@ async function doctor() {
|
|
|
741
1046
|
}
|
|
742
1047
|
}
|
|
743
1048
|
|
|
1049
|
+
const hookChecks = await verifyProjectHooks();
|
|
1050
|
+
if (!hookChecks.length) writeCheckLine('miss', 'Agent hooks', 'none in this project (fine for SDK and MCP runtimes)');
|
|
1051
|
+
const hooksOk = hookChecks.every((check) => check.ok);
|
|
1052
|
+
|
|
744
1053
|
write('');
|
|
745
|
-
if (!ok) {
|
|
1054
|
+
if (!ok || !hooksOk) {
|
|
746
1055
|
write(c('Next step', ANSI.bold));
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1056
|
+
if (!ok) {
|
|
1057
|
+
write(' osuite init');
|
|
1058
|
+
write(' export OSUITE_BASE_URL=https://studio.osuite.ai');
|
|
1059
|
+
write(' export OSUITE_API_KEY=<workspace-api-key>');
|
|
1060
|
+
}
|
|
1061
|
+
hookChecks.filter((check) => !check.ok).forEach((check) => {
|
|
1062
|
+
write(` ${check.installation.label} is not governed yet. Fix the FAIL line above, or run osuite connect ${check.installation.runtime} to reinstall, then run osuite doctor again.`);
|
|
1063
|
+
});
|
|
750
1064
|
process.exit(1);
|
|
751
1065
|
}
|
|
752
1066
|
|
|
753
1067
|
write(c('Your OSuite CLI is ready.', ANSI.green));
|
|
1068
|
+
hookChecks.forEach((check) => {
|
|
1069
|
+
write(` ${check.installation.label} direct hook probe was governed and reached OSuite; verify host invocation after starting the runtime.`);
|
|
1070
|
+
});
|
|
754
1071
|
}
|
|
755
1072
|
|
|
756
1073
|
async function status() {
|
|
@@ -792,6 +1109,9 @@ async function approvals(args) {
|
|
|
792
1109
|
|
|
793
1110
|
write(`${'Action ID'.padEnd(18)} ${'Risk'.padStart(3)} ${'Type'.padEnd(24)} ${'Agent'.padEnd(18)} Goal`);
|
|
794
1111
|
actions.forEach((action) => write(renderActionRow(action)));
|
|
1112
|
+
write('');
|
|
1113
|
+
write(c('Review and decide in Studio:', ANSI.dim));
|
|
1114
|
+
actions.forEach((action) => write(` ${client.baseUrl}/approvals?action=${encodeURIComponent(action.action_id)}`));
|
|
795
1115
|
}
|
|
796
1116
|
|
|
797
1117
|
async function review(actionId) {
|
|
@@ -811,7 +1131,19 @@ async function decide(actionId, decision, args) {
|
|
|
811
1131
|
process.exit(1);
|
|
812
1132
|
}
|
|
813
1133
|
const client = requireClient();
|
|
814
|
-
|
|
1134
|
+
let result;
|
|
1135
|
+
try {
|
|
1136
|
+
result = await client.approveAction(actionId, decision, args.reason || args.reasoning);
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
// Agents share this machine's API key, so the workspace only accepts
|
|
1139
|
+
// decisions from a person signed in to Studio.
|
|
1140
|
+
if (error?.response?.code === 'HUMAN_APPROVER_REQUIRED') {
|
|
1141
|
+
write(c('Approvals are made by a person signed in to OSuite Studio.', ANSI.yellow));
|
|
1142
|
+
write(`Open this request to ${decision === 'allow' ? 'approve' : 'deny'} it: ${error.response.review_url || `${client.baseUrl}/approvals?action=${encodeURIComponent(actionId)}`}`);
|
|
1143
|
+
process.exit(1);
|
|
1144
|
+
}
|
|
1145
|
+
throw error;
|
|
1146
|
+
}
|
|
815
1147
|
const label = decision === 'allow' ? 'Approved' : 'Denied';
|
|
816
1148
|
write(c(`${label} ${actionId}`, decision === 'allow' ? ANSI.green : ANSI.red));
|
|
817
1149
|
if (result?.action?.status) write(`New status ${result.action.status}`);
|
|
@@ -923,7 +1255,8 @@ async function external(args = {}) {
|
|
|
923
1255
|
async function init(target = 'generic', args = {}) {
|
|
924
1256
|
write(c('OSuite init', `${ANSI.bold}${ANSI.cyan}`));
|
|
925
1257
|
if (PROJECT_BOOTSTRAPS[target]) {
|
|
926
|
-
await installRuntimeProjectBootstrap(target, args);
|
|
1258
|
+
const install = await installRuntimeProjectBootstrap(target, args);
|
|
1259
|
+
if (!install.ok) process.exitCode = 1;
|
|
927
1260
|
return;
|
|
928
1261
|
}
|
|
929
1262
|
|
|
@@ -977,17 +1310,21 @@ async function connect(target = 'auto', args = {}) {
|
|
|
977
1310
|
write(`Browser handoff ${handoffUrl}`);
|
|
978
1311
|
write(`One-time code ${code}`);
|
|
979
1312
|
write('');
|
|
1313
|
+
const opened = !args['dry-run'] && shouldOpenBrowser(args) && openInBrowser(handoffUrl);
|
|
980
1314
|
write(c('What happens next', ANSI.bold));
|
|
981
|
-
write(
|
|
1315
|
+
write(opened
|
|
1316
|
+
? ' 1. Studio opened in your browser. Check the code matches, then approve this terminal.'
|
|
1317
|
+
: ' 1. Open the browser handoff URL, check the code matches, then approve this terminal in Studio.');
|
|
982
1318
|
write(' 2. OSuite prepares the runtime identity, project hook lane, and signed env for this project.');
|
|
983
1319
|
write(' 3. Return here; the CLI will finish automatically and then you can run osuite doctor.');
|
|
984
1320
|
write('');
|
|
985
1321
|
|
|
1322
|
+
let install = null;
|
|
986
1323
|
if (PROJECT_BOOTSTRAPS[runtime]) {
|
|
987
1324
|
if (args['dry-run']) {
|
|
988
1325
|
write(`Dry run: would install project hook files for ${runtime}.`);
|
|
989
1326
|
} else {
|
|
990
|
-
await installRuntimeProjectBootstrap(runtime, args);
|
|
1327
|
+
install = await installRuntimeProjectBootstrap(runtime, args, { nextSteps: false });
|
|
991
1328
|
}
|
|
992
1329
|
} else {
|
|
993
1330
|
write(c('Runtime setup', ANSI.bold));
|
|
@@ -997,7 +1334,9 @@ async function connect(target = 'auto', args = {}) {
|
|
|
997
1334
|
}
|
|
998
1335
|
|
|
999
1336
|
if (!args['dry-run'] && connectPayload) {
|
|
1000
|
-
|
|
1337
|
+
// Wait as long as the code is valid, so approving late still connects.
|
|
1338
|
+
const expiresInSeconds = Math.max(30, Number(connectPayload.expires_in || 600));
|
|
1339
|
+
const timeoutMs = parsePositiveInt(args['poll-timeout-ms'], expiresInSeconds * 1000);
|
|
1001
1340
|
const intervalMs = parsePositiveInt(
|
|
1002
1341
|
args['poll-interval-ms'],
|
|
1003
1342
|
Math.max(1000, Number(connectPayload.interval_seconds || 2) * 1000),
|
|
@@ -1005,7 +1344,7 @@ async function connect(target = 'auto', args = {}) {
|
|
|
1005
1344
|
|
|
1006
1345
|
write('');
|
|
1007
1346
|
write(c('Waiting for browser approval', ANSI.bold));
|
|
1008
|
-
write(` Code ${code} expires in about ${Math.round(
|
|
1347
|
+
write(` Code ${code} expires in about ${Math.round(expiresInSeconds / 60)} minutes. Press Ctrl+C to stop waiting.`);
|
|
1009
1348
|
|
|
1010
1349
|
const credential = await pollDeviceConnect({
|
|
1011
1350
|
baseUrl,
|
|
@@ -1019,13 +1358,36 @@ async function connect(target = 'auto', args = {}) {
|
|
|
1019
1358
|
const envPath = envPathForRuntime(runtime);
|
|
1020
1359
|
const result = writeProjectFile(envPath, formatEnvBody(credential.env), { force: true });
|
|
1021
1360
|
write('');
|
|
1022
|
-
write(
|
|
1023
|
-
|
|
1024
|
-
|
|
1361
|
+
write(`Saved credentials to ${result.relativePath}`);
|
|
1362
|
+
if (!PROJECT_BOOTSTRAPS[runtime]) {
|
|
1363
|
+
write(c('Connected to OSuite', ANSI.green));
|
|
1364
|
+
write(' Run osuite doctor, then start the agent from this project root.');
|
|
1365
|
+
} else if (!install?.ok) {
|
|
1366
|
+
write(c('Not connected: OSuite hook setup is not ready, so this agent is not governed.', ANSI.red));
|
|
1367
|
+
(install?.blockers || []).forEach((blocker) => write(` ${blocker}`));
|
|
1368
|
+
write(` Fix the file above, then run osuite connect ${runtime} again.`);
|
|
1369
|
+
process.exitCode = 1;
|
|
1370
|
+
} else {
|
|
1371
|
+
write('');
|
|
1372
|
+
write(c('Checking the installed hook', ANSI.bold));
|
|
1373
|
+
const checks = await verifyProjectHooks([runtime]);
|
|
1374
|
+
write('');
|
|
1375
|
+
if (checks.length && checks.every((check) => check.ok)) {
|
|
1376
|
+
write(c('Connected to OSuite', ANSI.green));
|
|
1377
|
+
write(` The direct ${PROJECT_BOOTSTRAPS[runtime].label.replace(/ hook runtime$/, '')} hook probe was governed and reached Studio; host invocation still needs runtime verification.`);
|
|
1378
|
+
write(` ${PROJECT_BOOTSTRAPS[runtime].runLine}`);
|
|
1379
|
+
} else {
|
|
1380
|
+
write(c('Not connected: credentials are saved, but the hook check failed, so this agent is not governed yet.', ANSI.red));
|
|
1381
|
+
write(' Fix the FAIL line above, then run osuite doctor.');
|
|
1382
|
+
process.exitCode = 1;
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1025
1385
|
} else {
|
|
1026
1386
|
write('');
|
|
1027
|
-
write(c('
|
|
1028
|
-
write(
|
|
1387
|
+
write(c('Not connected: nobody approved this terminal in the browser in time.', ANSI.yellow));
|
|
1388
|
+
write(` Run osuite connect ${runtime} again for a new code${install?.ok ? '; the hook files are already installed, only the credentials are missing' : ''}.`);
|
|
1389
|
+
write(' If the browser did not open, copy the handoff link above into it.');
|
|
1390
|
+
process.exitCode = 1;
|
|
1029
1391
|
}
|
|
1030
1392
|
}
|
|
1031
1393
|
|
|
@@ -1053,6 +1415,8 @@ async function main() {
|
|
|
1053
1415
|
if (command === 'review') return review(args._[0]);
|
|
1054
1416
|
if (command === 'approve') return decide(args._[0], 'allow', args);
|
|
1055
1417
|
if (command === 'deny') return decide(args._[0], 'deny', args);
|
|
1418
|
+
if (command === 'adapters' || command === 'coverage') return printRuntimeCoverage(args);
|
|
1419
|
+
if (command === 'adapter') return enterpriseAdapter(args);
|
|
1056
1420
|
if (command === 'external') return external(args);
|
|
1057
1421
|
if (command === 'connect') return connect(args._[0] || 'auto', args);
|
|
1058
1422
|
if (command === 'init') return init(args._[0] || 'generic', args);
|
package/osuite.js
CHANGED
|
@@ -142,10 +142,17 @@ class OSuite {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
if (action.status === 'pending_approval') wasPending = true;
|
|
145
|
-
if (action.
|
|
146
|
-
|
|
145
|
+
if (action.status === 'expired') {
|
|
146
|
+
throw new ApprovalDeniedError(
|
|
147
|
+
action.error_message || 'The approval request expired before anyone reviewed it. Ask again.',
|
|
148
|
+
'expired',
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (['failed', 'cancelled', 'blocked'].includes(action.status)) {
|
|
147
152
|
throw new ApprovalDeniedError(action.error_message || 'Operator denied the action.', action.status);
|
|
148
153
|
}
|
|
154
|
+
// Denials also carry reviewer metadata; it is not permission on its own.
|
|
155
|
+
if (action.status === 'running' && (action.approved_by || action.approved_at)) return action;
|
|
149
156
|
if (wasPending && action.status !== 'pending_approval') {
|
|
150
157
|
throw new Error(`Action ${actionId} left pending_approval without explicit approval metadata.`);
|
|
151
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osuite",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "OSuite governed action SDK for AI agents. Approve, replay, prove, and verify runtime decisions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"cli.js",
|
|
26
|
+
"projectHooks.js",
|
|
26
27
|
"reviewSurface.js",
|
|
27
28
|
"osuite.js",
|
|
28
29
|
"index.cjs",
|