@letterblack/lbe-core 1.3.4 → 1.3.5
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/.githooks/pre-commit +2 -0
- package/.githooks/pre-push +2 -0
- package/CHANGELOG.md +75 -0
- package/LICENSE +1 -1
- package/README.md +127 -154
- package/RELEASE_WORKSPACE_RULES.md +110 -0
- package/Release-README.md +65 -0
- package/WORKSPACE.md +422 -0
- package/_proof.mjs +246 -0
- package/assets/runtime-boundary.svg +36 -36
- package/bin/lbe.js +12 -0
- package/config/identity.config.json +3 -0
- package/config/policy.default.json +24 -0
- package/dist/cli/lbe.js +4432 -0
- package/dist/hooks/register.cjs +505 -0
- package/dist/state/appendCentral.cjs +87 -0
- package/dist/state/index.cjs +101 -0
- package/exec/cli.js +472 -0
- package/exec/index.js +2 -0
- package/index.js +24 -0
- package/lbe.audit.jsonl +46 -0
- package/package.json +48 -16
- package/release/README.md +216 -0
- package/release/TRUST.md +90 -0
- package/release/exec-README.md +215 -0
- package/release/exec-types.d.ts +50 -0
- package/release-exec/LICENSE +1 -0
- package/release-exec/README.md +215 -0
- package/release-exec/assets/lbe-gates.jpg +0 -0
- package/release-exec/assets/lbe-gates.png +0 -0
- package/release-exec/assets/runtime-boundary.svg +36 -0
- package/release-exec/assets/story-allow.jpg +0 -0
- package/release-exec/assets/story-allow.png +0 -0
- package/release-exec/assets/story-deny.jpg +0 -0
- package/release-exec/assets/story-deny.png +0 -0
- package/release-exec/dist/cli.js +2841 -0
- package/release-exec/dist/index.js +1835 -0
- package/release-exec/dist/lbe_engine.wasm +0 -0
- package/{dist → release-exec/dist}/wasm.lock.json +4 -5
- package/release-exec/hooks/register.cjs +473 -0
- package/release-exec/package.json +35 -0
- package/release-exec/types.d.ts +50 -0
- package/runtime/engine.js +322 -0
- package/runtime/lbe_engine.wasm +0 -0
- package/src/cli/commands/assertConsumer.js +198 -0
- package/src/cli/commands/auditVerify.js +36 -0
- package/src/cli/commands/dryrun.js +175 -0
- package/src/cli/commands/health.js +153 -0
- package/src/cli/commands/init.js +306 -0
- package/src/cli/commands/integrityCheck.js +57 -0
- package/src/cli/commands/logs.js +53 -0
- package/src/cli/commands/openState.js +44 -0
- package/src/cli/commands/policyAdd.js +8 -0
- package/src/cli/commands/policyMode.js +7 -0
- package/src/cli/commands/policySign.js +72 -0
- package/src/cli/commands/proof.js +122 -0
- package/src/cli/commands/run.js +342 -0
- package/src/cli/commands/status.js +73 -0
- package/src/cli/commands/verify.js +144 -0
- package/src/cli/main.js +181 -0
- package/src/cli/parseArgs.js +115 -0
- package/src/exec/localExecutor.js +289 -0
- package/src/hooks/register.cjs +505 -0
- package/src/state/appendCentral.cjs +87 -0
- package/src/state/fileIndex.js +140 -0
- package/src/state/index.cjs +101 -0
- package/src/state/index.js +65 -0
- package/src/state/intentRegistry.js +83 -0
- package/src/state/migration.js +112 -0
- package/src/state/proofRunner.js +246 -0
- package/src/state/stateRoot.js +40 -0
- package/src/state/targetRegistry.js +108 -0
- package/src/state/workspaceId.js +40 -0
- package/src/state/workspaceRegistry.js +65 -0
- package/types.d.ts +175 -2
- package/dist/cli.js +0 -141
- package/dist/index.js +0 -52
- /package/dist/{lbe_engine.wasm → cli/lbe_engine.wasm} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { resolveWorkspaceState } from '../../state/index.js';
|
|
4
|
+
import { stateRoot } from '../../state/stateRoot.js';
|
|
5
|
+
import { isWorkspaceRegistryReadable, listWorkspaces } from '../../state/workspaceRegistry.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* lbe status
|
|
9
|
+
*
|
|
10
|
+
* Resolves central state for the workspace and prints a summary.
|
|
11
|
+
* Policy authority stays in .lbe/policy.json — this command reads it
|
|
12
|
+
* for display only. It does not modify or migrate anything.
|
|
13
|
+
*
|
|
14
|
+
* @returns {{ workspaceId, stateDir, policySource, policyMode, hasProof, hasEvents }}
|
|
15
|
+
*/
|
|
16
|
+
export async function statusCommand(opts) {
|
|
17
|
+
if (opts.all) {
|
|
18
|
+
const registryPath = opts.registryPath || path.join(stateRoot(), 'registry.json');
|
|
19
|
+
if (!isWorkspaceRegistryReadable(registryPath)) {
|
|
20
|
+
console.log('Workspace registry unreadable');
|
|
21
|
+
return { workspaces: [], registryReadable: false };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const workspaces = listWorkspaces(registryPath);
|
|
25
|
+
if (workspaces.length === 0) {
|
|
26
|
+
console.log('No known workspaces yet');
|
|
27
|
+
return { workspaces, registryReadable: true };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log('\nKnown LBE workspaces');
|
|
31
|
+
for (const workspace of workspaces) {
|
|
32
|
+
console.log(` ${workspace.alias}`);
|
|
33
|
+
console.log(` workspace_id ${workspace.workspaceId}`);
|
|
34
|
+
console.log(` path ${workspace.path}`);
|
|
35
|
+
console.log(` last_active ${workspace.last_active}`);
|
|
36
|
+
}
|
|
37
|
+
console.log('');
|
|
38
|
+
return { workspaces, registryReadable: true };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const workspaceRoot = path.resolve(opts.root || process.cwd());
|
|
42
|
+
const { stateDir, workspaceId, paths } = resolveWorkspaceState(workspaceRoot);
|
|
43
|
+
|
|
44
|
+
// ── Policy source (read-only, .lbe/policy.json is authoritative) ──────────
|
|
45
|
+
const policyPath = path.join(workspaceRoot, '.lbe', 'policy.json');
|
|
46
|
+
let policySource = 'not found';
|
|
47
|
+
let policyMode = 'unknown';
|
|
48
|
+
if (fs.existsSync(policyPath)) {
|
|
49
|
+
try {
|
|
50
|
+
const policy = JSON.parse(fs.readFileSync(policyPath, 'utf8'));
|
|
51
|
+
policyMode = policy.mode || 'unknown';
|
|
52
|
+
policySource = policyPath;
|
|
53
|
+
} catch (_) {
|
|
54
|
+
policySource = policyPath + ' (unreadable)';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ── Central state presence ─────────────────────────────────────────────────
|
|
59
|
+
const hasProof = fs.existsSync(paths.proofLatest);
|
|
60
|
+
const hasEvents = fs.existsSync(paths.events);
|
|
61
|
+
|
|
62
|
+
// ── Output ─────────────────────────────────────────────────────────────────
|
|
63
|
+
console.log(`\nLBE Central State — ${workspaceRoot}`);
|
|
64
|
+
console.log(` workspace_id ${workspaceId}`);
|
|
65
|
+
console.log(` state_dir ${stateDir}`);
|
|
66
|
+
console.log(` policy_source ${policySource}`);
|
|
67
|
+
console.log(` policy_mode ${policyMode}`);
|
|
68
|
+
console.log(` central_proof ${hasProof ? paths.proofLatest : 'No central proof yet'}`);
|
|
69
|
+
console.log(` central_logs ${hasEvents ? paths.events : 'No central logs yet. Hook dual-write not enabled.'}`);
|
|
70
|
+
console.log('');
|
|
71
|
+
|
|
72
|
+
return { workspaceId, stateDir, policySource, policyMode, hasProof, hasEvents };
|
|
73
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/cli/commands/verify.js
|
|
2
|
+
// Validate a proposal without executing
|
|
3
|
+
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { validateCommand } from '../../core/validator.js';
|
|
7
|
+
import { NonceStore } from '../../core/nonceStore.js';
|
|
8
|
+
import { loadKeysStore } from '../../core/trustedKeys.js';
|
|
9
|
+
import { verifyPolicySignature } from '../../core/policySignature.js';
|
|
10
|
+
import { validateAndUpdatePolicyVersionState } from '../../core/policyVersionGuard.js';
|
|
11
|
+
|
|
12
|
+
export async function verifyCommand(opts) {
|
|
13
|
+
const { in: inFile } = opts;
|
|
14
|
+
const config = opts.config || opts.policy;
|
|
15
|
+
const pubKey = opts['pub-key'];
|
|
16
|
+
const keysStorePath = opts['keys-store'] || path.resolve('.lbe/config/keys.json');
|
|
17
|
+
const policySigPath = opts['policy-sig'] || path.resolve('.lbe/config/policy.sig.json');
|
|
18
|
+
const policyStatePath = opts['policy-state'] || path.resolve('.lbe/data/policy.state.json');
|
|
19
|
+
const allowUnsignedPolicy = opts['policy-unsigned-ok'] === true || String(opts['policy-unsigned-ok']).toLowerCase() === 'true';
|
|
20
|
+
// Validate required arguments
|
|
21
|
+
if (!inFile) {
|
|
22
|
+
console.error('Error: --in <file> is required');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Read proposal file
|
|
27
|
+
let proposal;
|
|
28
|
+
try {
|
|
29
|
+
const filePath = path.resolve(inFile);
|
|
30
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
31
|
+
proposal = JSON.parse(content);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(JSON.stringify({
|
|
34
|
+
status: 'error',
|
|
35
|
+
error: 'INVALID_PROPOSAL_FILE',
|
|
36
|
+
message: error.message
|
|
37
|
+
}));
|
|
38
|
+
process.exit(5);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Load policy
|
|
42
|
+
let policy;
|
|
43
|
+
try {
|
|
44
|
+
const policyPath = config || path.resolve('.lbe/config/policy.default.json');
|
|
45
|
+
if (!fs.existsSync(policyPath)) {
|
|
46
|
+
console.error(JSON.stringify({
|
|
47
|
+
status: 'error',
|
|
48
|
+
error: 'MISSING_POLICY',
|
|
49
|
+
message: `Policy file not found: ${policyPath}`
|
|
50
|
+
}));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const policyContent = fs.readFileSync(policyPath, 'utf-8');
|
|
54
|
+
policy = JSON.parse(policyContent);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(JSON.stringify({
|
|
57
|
+
status: 'error',
|
|
58
|
+
error: 'INVALID_POLICY',
|
|
59
|
+
message: error.message
|
|
60
|
+
}));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Load key store (preferred) with legacy pub-key fallback
|
|
65
|
+
const keyStoreResult = loadKeysStore(keysStorePath);
|
|
66
|
+
const keyStore = keyStoreResult.ok ? keyStoreResult.store : null;
|
|
67
|
+
|
|
68
|
+
// Preflight: policy signature verification (strict by default)
|
|
69
|
+
const policySigCheck = verifyPolicySignature({
|
|
70
|
+
policyObj: policy,
|
|
71
|
+
keyStore,
|
|
72
|
+
policySigPath,
|
|
73
|
+
allowUnsigned: allowUnsignedPolicy
|
|
74
|
+
});
|
|
75
|
+
if (!policySigCheck.ok) {
|
|
76
|
+
console.error(JSON.stringify({
|
|
77
|
+
status: 'error',
|
|
78
|
+
error: policySigCheck.reason,
|
|
79
|
+
message: policySigCheck.message
|
|
80
|
+
}, null, 2));
|
|
81
|
+
process.exit(8);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const versionCheck = validateAndUpdatePolicyVersionState({
|
|
85
|
+
policyObj: policy,
|
|
86
|
+
statePath: policyStatePath,
|
|
87
|
+
maxCreatedAtSkewSec: policy?.security?.maxPolicyCreatedAtSkewSec
|
|
88
|
+
});
|
|
89
|
+
if (!versionCheck.ok) {
|
|
90
|
+
console.error(JSON.stringify({
|
|
91
|
+
status: 'error',
|
|
92
|
+
error: versionCheck.reason,
|
|
93
|
+
message: versionCheck.message
|
|
94
|
+
}, null, 2));
|
|
95
|
+
process.exit(8);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Load nonce store
|
|
99
|
+
const nonceDb = new NonceStore(path.resolve('.lbe/data/nonce.db.json'));
|
|
100
|
+
await nonceDb.load();
|
|
101
|
+
|
|
102
|
+
if (!keyStore && !pubKey) {
|
|
103
|
+
console.error(JSON.stringify({
|
|
104
|
+
status: 'error',
|
|
105
|
+
error: 'MISSING_KEY_MATERIAL',
|
|
106
|
+
message: `${keyStoreResult.message}. Provide --pub-key/--pub-key-file or create .lbe/config/keys.json`
|
|
107
|
+
}));
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Validate command
|
|
112
|
+
const result = validateCommand({
|
|
113
|
+
commandObj: proposal,
|
|
114
|
+
pubKeyB64: pubKey,
|
|
115
|
+
keyStore,
|
|
116
|
+
nonceDb,
|
|
117
|
+
policy
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Output structured result
|
|
121
|
+
const output = {
|
|
122
|
+
status: result.valid ? 'valid' : 'invalid',
|
|
123
|
+
commandId: proposal.commandId || 'N/A',
|
|
124
|
+
checks: result.checks,
|
|
125
|
+
errors: result.errors || [],
|
|
126
|
+
risk: result.risk || 'UNKNOWN'
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
console.log(JSON.stringify(output, null, 2));
|
|
130
|
+
|
|
131
|
+
// Exit with appropriate code
|
|
132
|
+
if (!result.valid) {
|
|
133
|
+
// Determine which validation failed for exit code
|
|
134
|
+
if (result.checks.schema === false) process.exit(5); // Schema error
|
|
135
|
+
if (result.checks.signature === false) process.exit(3); // Signature error
|
|
136
|
+
if (result.checks.nonce === false) process.exit(4); // Replay detected
|
|
137
|
+
if (result.checks.timestamp === false) process.exit(6); // Clock skew
|
|
138
|
+
if (result.checks.rateLimit === false) process.exit(7); // Rate limited
|
|
139
|
+
if (result.checks.policy === false) process.exit(2); // Policy blocked
|
|
140
|
+
process.exit(9); // Generic error
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
process.exit(0);
|
|
144
|
+
}
|
package/src/cli/main.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// src/cli/main.js
|
|
2
|
+
// LetterBlack Sentinel CLI entrypoint
|
|
3
|
+
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { parseArgs, printHelp } from './parseArgs.js';
|
|
8
|
+
import { initCommand } from './commands/init.js';
|
|
9
|
+
import { verifyCommand } from './commands/verify.js';
|
|
10
|
+
import { dryrunCommand } from './commands/dryrun.js';
|
|
11
|
+
import { runCommand } from './commands/run.js';
|
|
12
|
+
import { auditVerifyCommand } from './commands/auditVerify.js';
|
|
13
|
+
import { integrityCheckCommand, integrityGenerateCommand } from './commands/integrityCheck.js';
|
|
14
|
+
import { performIntegrityCheck } from '../core/integrity.js';
|
|
15
|
+
import { policySignCommand } from './commands/policySign.js';
|
|
16
|
+
import { healthCommand } from './commands/health.js';
|
|
17
|
+
import { policyAddCommand } from './commands/policyAdd.js';
|
|
18
|
+
import { policyModeCommand } from './commands/policyMode.js';
|
|
19
|
+
import { statusCommand } from './commands/status.js';
|
|
20
|
+
import { logsCommand } from './commands/logs.js';
|
|
21
|
+
import { openStateCommand } from './commands/openState.js';
|
|
22
|
+
import { proofCommand } from './commands/proof.js';
|
|
23
|
+
import { assertConsumerCommand } from './commands/assertConsumer.js';
|
|
24
|
+
|
|
25
|
+
function toBoolean(value, defaultValue = false) {
|
|
26
|
+
if (value === undefined) return defaultValue;
|
|
27
|
+
if (value === true || value === false) return value;
|
|
28
|
+
const normalized = String(value).trim().toLowerCase();
|
|
29
|
+
if (normalized === 'true' || normalized === '1' || normalized === 'yes') return true;
|
|
30
|
+
if (normalized === 'false' || normalized === '0' || normalized === 'no') return false;
|
|
31
|
+
return defaultValue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
35
|
+
const packageJsonPath = path.join(__dirname, '../../package.json');
|
|
36
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
37
|
+
|
|
38
|
+
export async function main() {
|
|
39
|
+
const argv = process.argv.slice(2);
|
|
40
|
+
if (argv.includes('--version')) {
|
|
41
|
+
console.log(`LetterBlack Sentinel v${packageJson.version}`);
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
if (argv.length === 0 || argv.includes('--help') || argv.includes('-h')) {
|
|
45
|
+
printHelp(packageJson.version);
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const { command, opts } = parseArgs(argv);
|
|
50
|
+
|
|
51
|
+
// Handle version flag
|
|
52
|
+
if (opts.version) {
|
|
53
|
+
console.log(`LetterBlack Sentinel v${packageJson.version}`);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Handle help flag or no command
|
|
58
|
+
if (opts.help || !command || command === 'help') {
|
|
59
|
+
printHelp(packageJson.version);
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
// Parse --pub-key-file if provided
|
|
65
|
+
if (opts['pub-key-file']) {
|
|
66
|
+
try {
|
|
67
|
+
opts['pub-key'] = fs.readFileSync(path.resolve(opts['pub-key-file']), 'utf-8').trim();
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error(`Error reading public key file: ${error.message}`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Route to command handler
|
|
75
|
+
if (['verify', 'dryrun', 'run'].includes(command)) {
|
|
76
|
+
const integrityStrict = toBoolean(opts['integrity-strict'], false);
|
|
77
|
+
const integrityManifestPath = path.resolve(opts['integrity-manifest'] || '.lbe/config/integrity.manifest.json');
|
|
78
|
+
const integrityResult = await performIntegrityCheck({
|
|
79
|
+
strict: integrityStrict,
|
|
80
|
+
manifestPath: integrityManifestPath
|
|
81
|
+
});
|
|
82
|
+
if (!integrityResult.valid) {
|
|
83
|
+
console.error(JSON.stringify({
|
|
84
|
+
status: 'error',
|
|
85
|
+
error: integrityResult.reason || 'INTEGRITY_CHECK_FAILED',
|
|
86
|
+
message: integrityResult.message
|
|
87
|
+
}, null, 2));
|
|
88
|
+
process.exit(8);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
switch (command) {
|
|
93
|
+
case 'init':
|
|
94
|
+
await initCommand(opts);
|
|
95
|
+
break;
|
|
96
|
+
|
|
97
|
+
case 'verify':
|
|
98
|
+
await verifyCommand(opts);
|
|
99
|
+
break;
|
|
100
|
+
|
|
101
|
+
case 'dryrun':
|
|
102
|
+
await dryrunCommand(opts);
|
|
103
|
+
break;
|
|
104
|
+
|
|
105
|
+
case 'run':
|
|
106
|
+
await runCommand(opts);
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case 'audit-verify':
|
|
110
|
+
await auditVerifyCommand(opts);
|
|
111
|
+
break;
|
|
112
|
+
|
|
113
|
+
case 'integrity-check':
|
|
114
|
+
await integrityCheckCommand(opts);
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
case 'integrity-generate':
|
|
118
|
+
await integrityGenerateCommand(opts);
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
case 'policy-sign':
|
|
122
|
+
await policySignCommand(opts);
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case 'health':
|
|
126
|
+
await healthCommand(opts);
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
case 'policy-add':
|
|
130
|
+
await policyAddCommand(opts);
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case 'observe':
|
|
134
|
+
case 'enforce':
|
|
135
|
+
await policyModeCommand(command, opts);
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 'status':
|
|
139
|
+
await statusCommand(opts);
|
|
140
|
+
break;
|
|
141
|
+
|
|
142
|
+
case 'logs':
|
|
143
|
+
await logsCommand(opts);
|
|
144
|
+
break;
|
|
145
|
+
|
|
146
|
+
case 'open-state':
|
|
147
|
+
await openStateCommand(opts);
|
|
148
|
+
break;
|
|
149
|
+
|
|
150
|
+
case 'proof':
|
|
151
|
+
await proofCommand(opts);
|
|
152
|
+
break;
|
|
153
|
+
|
|
154
|
+
case 'assert-consumer':
|
|
155
|
+
await assertConsumerCommand(opts);
|
|
156
|
+
break;
|
|
157
|
+
|
|
158
|
+
default:
|
|
159
|
+
console.error(`Unknown command: ${command}`);
|
|
160
|
+
printHelp(packageJson.version);
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error(JSON.stringify({
|
|
165
|
+
status: 'error',
|
|
166
|
+
error: 'INTERNAL_ERROR',
|
|
167
|
+
message: error.message,
|
|
168
|
+
stack: process.env.DEBUG ? error.stack : undefined
|
|
169
|
+
}));
|
|
170
|
+
process.exit(9);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
main().catch((error) => {
|
|
175
|
+
console.error(JSON.stringify({
|
|
176
|
+
status: 'error',
|
|
177
|
+
error: 'FATAL_ERROR',
|
|
178
|
+
message: error.message
|
|
179
|
+
}));
|
|
180
|
+
process.exit(9);
|
|
181
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/cli/parseArgs.js
|
|
2
|
+
// Command-line argument parser
|
|
3
|
+
|
|
4
|
+
export function parseArgs(argv) {
|
|
5
|
+
// argv should already have node and script removed
|
|
6
|
+
if (argv.length === 0) {
|
|
7
|
+
return { command: 'help', opts: {} };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const command = argv[0];
|
|
11
|
+
const opts = {};
|
|
12
|
+
|
|
13
|
+
for (let i = 1; i < argv.length; i++) {
|
|
14
|
+
if (argv[i].startsWith('--')) {
|
|
15
|
+
const key = argv[i].substring(2);
|
|
16
|
+
// Handle --key=value format
|
|
17
|
+
if (key.includes('=')) {
|
|
18
|
+
const [k, v] = key.split('=');
|
|
19
|
+
opts[k] = v;
|
|
20
|
+
} else {
|
|
21
|
+
const nextArg = argv[i + 1];
|
|
22
|
+
if (!nextArg || nextArg.startsWith('-')) {
|
|
23
|
+
opts[key] = true;
|
|
24
|
+
} else {
|
|
25
|
+
opts[key] = nextArg;
|
|
26
|
+
i++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} else if (argv[i].startsWith('-')) {
|
|
30
|
+
const key = argv[i].substring(1);
|
|
31
|
+
const nextArg = argv[i + 1];
|
|
32
|
+
if (!nextArg || nextArg.startsWith('-')) {
|
|
33
|
+
opts[key] = true;
|
|
34
|
+
} else {
|
|
35
|
+
opts[key] = nextArg;
|
|
36
|
+
i++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { command, opts };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function printHelp(version = 'unknown') {
|
|
45
|
+
console.log(`
|
|
46
|
+
╔═══════════════════════════════════════════════════════════╗
|
|
47
|
+
║ LetterBlack Sentinel — CLI Governance ║
|
|
48
|
+
║ Local-first execution governance SDK v${version.padEnd(12)}║
|
|
49
|
+
╚═══════════════════════════════════════════════════════════╝
|
|
50
|
+
|
|
51
|
+
USAGE:
|
|
52
|
+
lbe [command] [options]
|
|
53
|
+
|
|
54
|
+
COMMANDS:
|
|
55
|
+
init Initialize LetterBlack Sentinel environment
|
|
56
|
+
verify Verify a proposal (validate, don't execute)
|
|
57
|
+
dryrun Validate and simulate execution (no changes)
|
|
58
|
+
run Validate and execute a proposal
|
|
59
|
+
policy-sign Sign policy and write policy signature envelope
|
|
60
|
+
policy-add Controller-only: add a rule to lbe.policy.json
|
|
61
|
+
observe Set project-local policy to advisory mode
|
|
62
|
+
enforce Set project-local policy to blocking mode
|
|
63
|
+
health Run deployment/runtime health checks
|
|
64
|
+
integrity-check Verify controller integrity manifest
|
|
65
|
+
integrity-generate Generate controller integrity manifest
|
|
66
|
+
audit-verify Verify audit log hash-chain integrity
|
|
67
|
+
status Show central state summary for this workspace
|
|
68
|
+
logs Print recent entries from central event log
|
|
69
|
+
open-state Open the central state directory in the file manager
|
|
70
|
+
proof Show latest proof result (--json for raw JSON, --public for redacted)
|
|
71
|
+
assert-consumer Verify this project consumes LBE as an installed registry dependency
|
|
72
|
+
help Show this help message
|
|
73
|
+
|
|
74
|
+
OPTIONS:
|
|
75
|
+
--in Input file (JSON proposal)
|
|
76
|
+
--config Policy config file (default: ./.lbe/config/policy.default.json)
|
|
77
|
+
--policy Alias for --config
|
|
78
|
+
--policy-sig Policy signature file (default: ./.lbe/config/policy.sig.json)
|
|
79
|
+
--policy-state Policy monotonic state file (default: ./data/policy.state.json)
|
|
80
|
+
--policy-unsigned-ok Allow unsigned policy (dev-only; default: false)
|
|
81
|
+
--policy-key-id Signer keyId for policy-sign (default: policy-signer-v1-2026Q1)
|
|
82
|
+
--secret-key-file Secret key for policy-sign (default: ./keys/secret.key)
|
|
83
|
+
--data-dir Data directory for health checks (default: ./data)
|
|
84
|
+
--nonce-db Nonce DB path for health checks
|
|
85
|
+
--rate-db Rate-limit DB path for health checks
|
|
86
|
+
--keys-store Trusted keys store (default: ./.lbe/config/keys.json)
|
|
87
|
+
--pub-key Public key for verification (Ed25519 base64)
|
|
88
|
+
--pub-key-file Legacy single-key file path (fallback mode)
|
|
89
|
+
--integrity-strict Fail verify/dryrun/run if integrity check fails
|
|
90
|
+
--integrity-manifest Integrity manifest path (default: ./.lbe/config/integrity.manifest.json)
|
|
91
|
+
--manifest Manifest path override for integrity-check
|
|
92
|
+
--out Output path for integrity-generate
|
|
93
|
+
--audit Audit log file (default: ./data/audit.log.jsonl)
|
|
94
|
+
--root Project root for local policy commands (default: cwd)
|
|
95
|
+
--effect Local rule effect: allow or deny
|
|
96
|
+
--type Local rule type: path or command
|
|
97
|
+
--pattern Local rule glob/pattern
|
|
98
|
+
--from Required human-readable rule provenance
|
|
99
|
+
--json JSON output (default: true)
|
|
100
|
+
--fail-fast Stop at first audit integrity error (default: true)
|
|
101
|
+
--max Max audit entries to process (optional)
|
|
102
|
+
--version Show version
|
|
103
|
+
--help Show this help message
|
|
104
|
+
|
|
105
|
+
EXAMPLES:
|
|
106
|
+
lbe execute --input proposal.json
|
|
107
|
+
cat proposal.json | lbe execute
|
|
108
|
+
lbe policy-sign --config ./.lbe/config/policy.default.json --policy-sig ./.lbe/config/policy.sig.json
|
|
109
|
+
lbe integrity-generate --out ./.lbe/config/integrity.manifest.json
|
|
110
|
+
lbe integrity-check --integrity-strict --manifest ./.lbe/config/integrity.manifest.json
|
|
111
|
+
lbe audit-verify --audit ./data/audit.log.jsonl
|
|
112
|
+
|
|
113
|
+
For more info, visit: https://github.com/Letterblack0306/LetterBlack-LBE-Core
|
|
114
|
+
`);
|
|
115
|
+
}
|