sentinelayer-cli 0.28.3 → 0.29.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/package.json
CHANGED
package/src/commands/omargate.js
CHANGED
|
@@ -20,6 +20,8 @@ export function registerOmarGateCommand(program, invokeLegacy) {
|
|
|
20
20
|
.option("--model <id>", "LLM model override (default: gpt-5.3-codex)")
|
|
21
21
|
.option("--provider <name>", "LLM provider: sentinelayer, openai, anthropic")
|
|
22
22
|
.option("--max-cost <usd>", "Maximum AI layer cost in USD (default: 5.0)")
|
|
23
|
+
.option("--notify-session <session-id>", "Write Omar Deep billing-grade usage entries into this Senti session")
|
|
24
|
+
.option("--require-usage-ledger", "Fail if Omar Deep AI calls cannot write billing-grade session_usage")
|
|
23
25
|
.option("--persona <csv>", "Only run these personas (comma-separated IDs); unknown IDs are dropped + warned")
|
|
24
26
|
.option("--skip-persona <csv>", "Skip these personas (comma-separated IDs)")
|
|
25
27
|
.option("--stream", "Emit NDJSON events to stdout as personas run")
|
package/src/legacy-cli.js
CHANGED
|
@@ -1298,6 +1298,8 @@ async function runLocalOmarGateCommand(args) {
|
|
|
1298
1298
|
const maxCostUsd = parseFloat(getCommandOptionValue(args, "--max-cost") || "5.0") || 5.0;
|
|
1299
1299
|
const modelOverride = getCommandOptionValue(args, "--model") || "";
|
|
1300
1300
|
const providerOverride = getCommandOptionValue(args, "--provider") || "";
|
|
1301
|
+
const notifySession = getCommandOptionValue(args, "--notify-session") || "";
|
|
1302
|
+
const requireUsageLedger = hasCommandOption(args, "--require-usage-ledger");
|
|
1301
1303
|
const scanMode = getCommandOptionValue(args, "--scan-mode") || "deep";
|
|
1302
1304
|
const maxParallel = parseInt(getCommandOptionValue(args, "--max-parallel") || "4", 10) || 4;
|
|
1303
1305
|
const streamEnabled = hasCommandOption(args, "--stream");
|
|
@@ -1388,6 +1390,8 @@ async function runLocalOmarGateCommand(args) {
|
|
|
1388
1390
|
onEvent: streamHandler,
|
|
1389
1391
|
includeOnly: includeOnly.length > 0 ? includeOnly : null,
|
|
1390
1392
|
skipPersonas: skipPersonas.length > 0 ? skipPersonas : null,
|
|
1393
|
+
usageSessionId: notifySession,
|
|
1394
|
+
requireUsageLedger,
|
|
1391
1395
|
});
|
|
1392
1396
|
|
|
1393
1397
|
// Use orchestrator results as the AI layer. aiResult represents ONLY
|
|
@@ -1415,6 +1419,7 @@ async function runLocalOmarGateCommand(args) {
|
|
|
1415
1419
|
status: p.status,
|
|
1416
1420
|
findings: p.findings || 0,
|
|
1417
1421
|
costUsd: p.costUsd || 0,
|
|
1422
|
+
billing: p.billing || null,
|
|
1418
1423
|
durationMs: p.durationMs || 0,
|
|
1419
1424
|
error: p.error || null,
|
|
1420
1425
|
})),
|
|
@@ -1445,8 +1450,17 @@ async function runLocalOmarGateCommand(args) {
|
|
|
1445
1450
|
outputDir: outputDirArg,
|
|
1446
1451
|
provider: providerOverride || undefined,
|
|
1447
1452
|
model: modelOverride || undefined,
|
|
1453
|
+
sessionId: notifySession,
|
|
1448
1454
|
maxCostUsd,
|
|
1449
1455
|
dryRun: aiDryRun,
|
|
1456
|
+
requireUsageLedger,
|
|
1457
|
+
sourceCommand: "omargate deep",
|
|
1458
|
+
billingAgentId: "omargate-orchestrator",
|
|
1459
|
+
billingAction: "omargate_deep",
|
|
1460
|
+
billingMetadata: {
|
|
1461
|
+
scanMode,
|
|
1462
|
+
},
|
|
1463
|
+
usageFailureLabel: "OmarGate AI",
|
|
1450
1464
|
env: process.env,
|
|
1451
1465
|
});
|
|
1452
1466
|
} catch (aiError) {
|
package/src/review/ai-review.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
resolveProvider,
|
|
9
9
|
} from "../ai/client.js";
|
|
10
10
|
import { computeProviderCost } from "../billing/price-book.js";
|
|
11
|
-
import { buildBillingRunId, buildCallIdempotencyKey } from "../billing/ledger-entry.js";
|
|
11
|
+
import { buildBillingRunId, buildCallIdempotencyKey, sanitizeBillingMetadata } from "../billing/ledger-entry.js";
|
|
12
12
|
import { recordSessionUsage } from "../billing/session-usage.js";
|
|
13
13
|
import { loadConfig } from "../config/service.js";
|
|
14
14
|
import { evaluateBudget } from "../cost/budget.js";
|
|
@@ -488,6 +488,12 @@ export async function runAiReviewLayer({
|
|
|
488
488
|
dryRun = false,
|
|
489
489
|
requireUsageLedger = false,
|
|
490
490
|
usageRecorder = recordSessionUsage,
|
|
491
|
+
sourceCommand = "review",
|
|
492
|
+
billingAgentId = "audit-orchestrator",
|
|
493
|
+
billingAction = "audit_run",
|
|
494
|
+
billingTier = "internal",
|
|
495
|
+
billingMetadata = {},
|
|
496
|
+
usageFailureLabel = "Review AI",
|
|
491
497
|
env = process.env,
|
|
492
498
|
} = {}) {
|
|
493
499
|
const normalizedTargetPath = path.resolve(String(targetPath || "."));
|
|
@@ -499,6 +505,12 @@ export async function runAiReviewLayer({
|
|
|
499
505
|
);
|
|
500
506
|
const normalizedRunId = normalizeString(runId) || "review-ai";
|
|
501
507
|
const normalizedRequireUsageLedger = Boolean(requireUsageLedger);
|
|
508
|
+
const normalizedSourceCommand = normalizeString(sourceCommand) || "review";
|
|
509
|
+
const normalizedBillingAgentId = normalizeString(billingAgentId) || "audit-orchestrator";
|
|
510
|
+
const normalizedBillingAction = normalizeString(billingAction) || "audit_run";
|
|
511
|
+
const normalizedBillingTier = normalizeString(billingTier) || "internal";
|
|
512
|
+
const normalizedBillingMetadata = sanitizeBillingMetadata(billingMetadata);
|
|
513
|
+
const normalizedUsageFailureLabel = normalizeString(usageFailureLabel) || "Review AI";
|
|
502
514
|
|
|
503
515
|
const config = await loadConfig({ cwd: normalizedTargetPath, env });
|
|
504
516
|
let resolvedProvider = resolveProvider({
|
|
@@ -641,7 +653,7 @@ export async function runAiReviewLayer({
|
|
|
641
653
|
toolCalls: 1,
|
|
642
654
|
},
|
|
643
655
|
metadata: {
|
|
644
|
-
sourceCommand:
|
|
656
|
+
sourceCommand: normalizedSourceCommand,
|
|
645
657
|
layer: "ai_reasoning",
|
|
646
658
|
provider: resolvedProvider,
|
|
647
659
|
model: resolvedModel,
|
|
@@ -657,28 +669,31 @@ export async function runAiReviewLayer({
|
|
|
657
669
|
sessionId: normalizedSessionId,
|
|
658
670
|
invocationTimestamp: startedAtIso,
|
|
659
671
|
configHash: stableConfigHash({
|
|
660
|
-
sourceCommand:
|
|
672
|
+
sourceCommand: normalizedSourceCommand,
|
|
661
673
|
layer: "ai_reasoning",
|
|
662
674
|
provider: resolvedProvider,
|
|
663
675
|
model: resolvedModel,
|
|
664
676
|
mode: normalizedMode,
|
|
665
677
|
runId: normalizedRunId,
|
|
666
678
|
dryRun: Boolean(dryRun),
|
|
679
|
+
billingAgentId: normalizedBillingAgentId,
|
|
680
|
+
billingAction: normalizedBillingAction,
|
|
667
681
|
}),
|
|
668
682
|
});
|
|
669
683
|
sessionUsageLedger = await usageRecorder(
|
|
670
684
|
normalizedSessionId,
|
|
671
685
|
{
|
|
672
|
-
agentId:
|
|
673
|
-
action:
|
|
686
|
+
agentId: normalizedBillingAgentId,
|
|
687
|
+
action: normalizedBillingAction,
|
|
674
688
|
model: resolvedModel,
|
|
675
689
|
inputTokens,
|
|
676
690
|
outputTokens,
|
|
677
691
|
idempotencyKey: buildCallIdempotencyKey({ runId: billingRunId, callIndex: 0 }),
|
|
678
|
-
billingTier:
|
|
692
|
+
billingTier: normalizedBillingTier,
|
|
679
693
|
createdAt: startedAtIso,
|
|
680
694
|
metadata: {
|
|
681
|
-
|
|
695
|
+
...normalizedBillingMetadata,
|
|
696
|
+
sourceCommand: normalizedSourceCommand,
|
|
682
697
|
layer: "ai_reasoning",
|
|
683
698
|
provider: resolvedProvider,
|
|
684
699
|
mode: normalizedMode,
|
|
@@ -698,7 +713,7 @@ export async function runAiReviewLayer({
|
|
|
698
713
|
};
|
|
699
714
|
if (normalizedRequireUsageLedger) {
|
|
700
715
|
throw new Error(
|
|
701
|
-
|
|
716
|
+
`${normalizedUsageFailureLabel} usage ledger recording failed: ${sessionUsageLedger.reason || "unknown"}.`
|
|
702
717
|
);
|
|
703
718
|
}
|
|
704
719
|
}
|
|
@@ -729,7 +744,7 @@ export async function runAiReviewLayer({
|
|
|
729
744
|
reasonCodes: budget.reasons.map((reason) => reason.code),
|
|
730
745
|
},
|
|
731
746
|
metadata: {
|
|
732
|
-
sourceCommand:
|
|
747
|
+
sourceCommand: normalizedSourceCommand,
|
|
733
748
|
layer: "ai_reasoning",
|
|
734
749
|
provider: resolvedProvider,
|
|
735
750
|
model: resolvedModel,
|
|
@@ -423,6 +423,10 @@ function omargateConfidenceFloorForPersona(personaId) {
|
|
|
423
423
|
return OMARGATE_CONFIDENCE_FLOORS[personaId] || OMARGATE_DEFAULT_CONFIDENCE_FLOOR;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
+
function isUsageLedgerFailure(message = "") {
|
|
427
|
+
return /usage ledger/i.test(String(message || ""));
|
|
428
|
+
}
|
|
429
|
+
|
|
426
430
|
async function runOmarPersonaSwarm({
|
|
427
431
|
personaId,
|
|
428
432
|
identity,
|
|
@@ -436,6 +440,9 @@ async function runOmarPersonaSwarm({
|
|
|
436
440
|
perPersonaCost,
|
|
437
441
|
dryRun,
|
|
438
442
|
onEvent,
|
|
443
|
+
usageSessionId = "",
|
|
444
|
+
requireUsageLedger = false,
|
|
445
|
+
usageRecorder = undefined,
|
|
439
446
|
} = {}) {
|
|
440
447
|
const scope = buildPersonaFileScope({ deterministic });
|
|
441
448
|
const decision = decideSwarm({ scope });
|
|
@@ -537,10 +544,26 @@ async function runOmarPersonaSwarm({
|
|
|
537
544
|
outputDir,
|
|
538
545
|
provider: provider || undefined,
|
|
539
546
|
model: model || undefined,
|
|
540
|
-
sessionId: `${subagentRunId}-ai`,
|
|
547
|
+
sessionId: usageSessionId || `${subagentRunId}-ai`,
|
|
541
548
|
maxCostUsd: budget.maxCostUsd,
|
|
542
549
|
systemPrompt,
|
|
543
550
|
dryRun,
|
|
551
|
+
requireUsageLedger,
|
|
552
|
+
usageRecorder,
|
|
553
|
+
sourceCommand: "omargate deep",
|
|
554
|
+
billingAgentId: `omargate-${personaId}-subagent-${subagentIndex}`,
|
|
555
|
+
billingAction: "omargate_deep",
|
|
556
|
+
billingMetadata: {
|
|
557
|
+
personaId,
|
|
558
|
+
subagentIndex,
|
|
559
|
+
partitionCount: partitions.length,
|
|
560
|
+
parentRunId: runId,
|
|
561
|
+
swarmRunId,
|
|
562
|
+
subagentRunId,
|
|
563
|
+
scanMode: mode,
|
|
564
|
+
fileCount: scopedFiles.length,
|
|
565
|
+
},
|
|
566
|
+
usageFailureLabel: "OmarGate AI",
|
|
544
567
|
env: process.env,
|
|
545
568
|
});
|
|
546
569
|
|
|
@@ -610,6 +633,7 @@ async function runOmarPersonaSwarm({
|
|
|
610
633
|
summary: result?.summary || summarizeFindings(findings),
|
|
611
634
|
costUsd: result?.usage?.costUsd || 0,
|
|
612
635
|
model: result?.model || model || null,
|
|
636
|
+
billing: result?.billing || null,
|
|
613
637
|
artifacts: result?.artifacts || null,
|
|
614
638
|
durationMs: Date.now() - subagentStart,
|
|
615
639
|
};
|
|
@@ -671,6 +695,41 @@ async function runOmarPersonaSwarm({
|
|
|
671
695
|
const summary = summarizeFindings(findings);
|
|
672
696
|
const okCount = settledSubagents.filter((result) => result.status === "ok").length;
|
|
673
697
|
const errorCount = settledSubagents.filter((result) => result.status === "error").length;
|
|
698
|
+
const usageLedgerErrors = settledSubagents.filter((result) =>
|
|
699
|
+
result.status === "error" && isUsageLedgerFailure(result.error)
|
|
700
|
+
);
|
|
701
|
+
if (requireUsageLedger && usageLedgerErrors.length > 0) {
|
|
702
|
+
return {
|
|
703
|
+
personaId,
|
|
704
|
+
status: "error",
|
|
705
|
+
findings: [],
|
|
706
|
+
summary: { P0: 0, P1: 0, P2: 0, P3: 0, blocking: false },
|
|
707
|
+
costUsd: totalCostUsd,
|
|
708
|
+
model: model || null,
|
|
709
|
+
durationMs: Date.now() - startedAt,
|
|
710
|
+
error: `OmarGate required usage ledger failed for ${usageLedgerErrors.length}/${settledSubagents.length} subagent(s).`,
|
|
711
|
+
swarm: {
|
|
712
|
+
runId: swarmRunId,
|
|
713
|
+
decision,
|
|
714
|
+
subagentCount: settledSubagents.length,
|
|
715
|
+
ok: okCount,
|
|
716
|
+
error: errorCount,
|
|
717
|
+
partitionSizes: partitions.map((files) => files.length),
|
|
718
|
+
blackboardEntries: blackboard.length,
|
|
719
|
+
subagents: settledSubagents.map((result) => ({
|
|
720
|
+
id: result.agentId,
|
|
721
|
+
index: result.subagentIndex,
|
|
722
|
+
status: result.status,
|
|
723
|
+
files: result.files,
|
|
724
|
+
findings: (result.findings || []).length,
|
|
725
|
+
costUsd: result.costUsd || 0,
|
|
726
|
+
durationMs: result.durationMs || 0,
|
|
727
|
+
error: result.error || null,
|
|
728
|
+
artifacts: result.artifacts || null,
|
|
729
|
+
})),
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
}
|
|
674
733
|
|
|
675
734
|
if (onEvent) {
|
|
676
735
|
onEvent(createAgentEvent({
|
|
@@ -723,6 +782,7 @@ async function runOmarPersonaSwarm({
|
|
|
723
782
|
files: result.files,
|
|
724
783
|
findings: (result.findings || []).length,
|
|
725
784
|
costUsd: result.costUsd || 0,
|
|
785
|
+
billing: result.billing || null,
|
|
726
786
|
durationMs: result.durationMs || 0,
|
|
727
787
|
error: result.error || null,
|
|
728
788
|
artifacts: result.artifacts || null,
|
|
@@ -747,6 +807,8 @@ async function runOmarPersonaSwarm({
|
|
|
747
807
|
* @param {Function} [options.onEvent] - Event callback for streaming
|
|
748
808
|
* @param {string[] | null} [options.includeOnly] - Only run these persona IDs (filters scan-mode roster).
|
|
749
809
|
* @param {string[] | null} [options.skipPersonas] - Skip these persona IDs (filters scan-mode roster).
|
|
810
|
+
* @param {boolean} [options.requireUsageLedger] - Fail if Omar Deep AI calls cannot write billing-grade session_usage.
|
|
811
|
+
* @param {string} [options.usageSessionId] - Optional shared Senti session id for billing-grade usage entries.
|
|
750
812
|
* @returns {Promise<object>} Orchestrated results
|
|
751
813
|
*/
|
|
752
814
|
export async function runOmarGateOrchestrator({
|
|
@@ -762,6 +824,9 @@ export async function runOmarGateOrchestrator({
|
|
|
762
824
|
onEvent = null,
|
|
763
825
|
includeOnly = null,
|
|
764
826
|
skipPersonas = null,
|
|
827
|
+
requireUsageLedger = false,
|
|
828
|
+
usageSessionId = "",
|
|
829
|
+
usageRecorder = undefined,
|
|
765
830
|
} = {}) {
|
|
766
831
|
const runId = `omargate-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
|
767
832
|
const startTime = Date.now();
|
|
@@ -931,6 +996,9 @@ export async function runOmarGateOrchestrator({
|
|
|
931
996
|
perPersonaCost,
|
|
932
997
|
dryRun,
|
|
933
998
|
onEvent,
|
|
999
|
+
requireUsageLedger,
|
|
1000
|
+
usageSessionId,
|
|
1001
|
+
usageRecorder,
|
|
934
1002
|
});
|
|
935
1003
|
|
|
936
1004
|
if (swarmResult) {
|
|
@@ -999,9 +1067,21 @@ export async function runOmarGateOrchestrator({
|
|
|
999
1067
|
outputDir,
|
|
1000
1068
|
provider: provider || undefined,
|
|
1001
1069
|
model: model || undefined,
|
|
1070
|
+
sessionId: usageSessionId || `${runId}-${personaId}-ai`,
|
|
1002
1071
|
maxCostUsd: perPersonaCost,
|
|
1003
1072
|
systemPrompt,
|
|
1004
1073
|
dryRun,
|
|
1074
|
+
requireUsageLedger,
|
|
1075
|
+
usageRecorder,
|
|
1076
|
+
sourceCommand: "omargate deep",
|
|
1077
|
+
billingAgentId: `omargate-${personaId}`,
|
|
1078
|
+
billingAction: "omargate_deep",
|
|
1079
|
+
billingMetadata: {
|
|
1080
|
+
personaId,
|
|
1081
|
+
parentRunId: runId,
|
|
1082
|
+
scanMode: mode,
|
|
1083
|
+
},
|
|
1084
|
+
usageFailureLabel: "OmarGate AI",
|
|
1005
1085
|
env: process.env,
|
|
1006
1086
|
});
|
|
1007
1087
|
|
|
@@ -1062,6 +1142,7 @@ export async function runOmarGateOrchestrator({
|
|
|
1062
1142
|
summary: result?.summary || { P0: 0, P1: 0, P2: 0, P3: 0 },
|
|
1063
1143
|
costUsd: personaCost,
|
|
1064
1144
|
model: result?.model || model || null,
|
|
1145
|
+
billing: result?.billing || null,
|
|
1065
1146
|
artifacts: result?.artifacts || null,
|
|
1066
1147
|
durationMs: Date.now() - personaStart,
|
|
1067
1148
|
};
|
|
@@ -1106,6 +1187,18 @@ export async function runOmarGateOrchestrator({
|
|
|
1106
1187
|
durationMs: 0,
|
|
1107
1188
|
})
|
|
1108
1189
|
);
|
|
1190
|
+
const usageLedgerFailures = settled.filter((r) =>
|
|
1191
|
+
r.status === "error" && isUsageLedgerFailure(r.error)
|
|
1192
|
+
);
|
|
1193
|
+
if (requireUsageLedger && usageLedgerFailures.length > 0) {
|
|
1194
|
+
const examples = usageLedgerFailures
|
|
1195
|
+
.slice(0, 3)
|
|
1196
|
+
.map((r) => `${r.personaId}: ${r.error}`)
|
|
1197
|
+
.join("; ");
|
|
1198
|
+
throw new Error(
|
|
1199
|
+
`OmarGate required usage ledger recording failed for ${usageLedgerFailures.length}/${settled.length} persona(s).${examples ? ` ${examples}` : ""}`
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1109
1202
|
|
|
1110
1203
|
// Reconcile AI findings with deterministic findings — canonical single list.
|
|
1111
1204
|
// Confidence boost when multiple layers agree; deterministic findings get
|
|
@@ -1183,6 +1276,7 @@ export async function runOmarGateOrchestrator({
|
|
|
1183
1276
|
costUsd: r.costUsd,
|
|
1184
1277
|
durationMs: r.durationMs,
|
|
1185
1278
|
model: r.model || null,
|
|
1279
|
+
billing: r.billing || null,
|
|
1186
1280
|
error: r.error || null,
|
|
1187
1281
|
swarm: r.swarm || null,
|
|
1188
1282
|
artifacts: r.artifacts || null,
|
package/src/session/listener.js
CHANGED
|
@@ -311,6 +311,7 @@ export async function listenSessionEvents({
|
|
|
311
311
|
const latest = await _pollLatest(normalizedSessionId, {
|
|
312
312
|
targetPath,
|
|
313
313
|
limit: 1,
|
|
314
|
+
forceCircuitProbe: true,
|
|
314
315
|
});
|
|
315
316
|
if (!latest?.ok) {
|
|
316
317
|
throw new Error(`Unable to start listener from the latest event (${latest?.reason || "unknown"}).`);
|