omnicell-router 0.2.0 → 0.3.1

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.
Files changed (102) hide show
  1. package/backend/dist/budget/budget-manager.d.ts +25 -0
  2. package/backend/dist/budget/budget-manager.js +54 -0
  3. package/backend/dist/cli/clients/index.js +2 -0
  4. package/backend/dist/cli/clients/omp.d.ts +53 -0
  5. package/backend/dist/cli/clients/omp.js +664 -0
  6. package/backend/dist/cli/clients/pi.js +79 -32
  7. package/backend/dist/cli/index.js +2 -2
  8. package/backend/dist/cli/types.d.ts +1 -1
  9. package/backend/dist/config/governance-limits.d.ts +68 -0
  10. package/backend/dist/config/governance-limits.js +261 -0
  11. package/backend/dist/config/index.js +1 -1
  12. package/backend/dist/config/types.d.ts +15 -5
  13. package/backend/dist/flywheel/collector.d.ts +74 -0
  14. package/backend/dist/flywheel/collector.js +235 -0
  15. package/backend/dist/flywheel/dataset.d.ts +130 -0
  16. package/backend/dist/flywheel/dataset.js +638 -0
  17. package/backend/dist/flywheel/decision-capture.d.ts +68 -0
  18. package/backend/dist/flywheel/decision-capture.js +85 -0
  19. package/backend/dist/flywheel/prune.d.ts +133 -0
  20. package/backend/dist/flywheel/prune.js +495 -0
  21. package/backend/dist/flywheel/schema.d.ts +108 -0
  22. package/backend/dist/flywheel/schema.js +117 -0
  23. package/backend/dist/flywheel/trainer.d.ts +84 -0
  24. package/backend/dist/flywheel/trainer.js +198 -0
  25. package/backend/dist/harness/adapters/amp.js +1 -0
  26. package/backend/dist/harness/adapters/claude.js +1 -0
  27. package/backend/dist/harness/adapters/cline.js +3 -1
  28. package/backend/dist/harness/adapters/codex.js +3 -1
  29. package/backend/dist/harness/adapters/cursor.js +1 -0
  30. package/backend/dist/harness/adapters/declarative.d.ts +3 -1
  31. package/backend/dist/harness/adapters/declarative.js +15 -1
  32. package/backend/dist/harness/adapters/dsh.js +1 -1
  33. package/backend/dist/harness/adapters/gemini-cli.js +1 -0
  34. package/backend/dist/harness/adapters/github-copilot.js +1 -0
  35. package/backend/dist/harness/adapters/index.d.ts +11 -3
  36. package/backend/dist/harness/adapters/index.js +48 -1
  37. package/backend/dist/harness/adapters/omp.d.ts +11 -0
  38. package/backend/dist/harness/adapters/omp.js +22 -0
  39. package/backend/dist/harness/adapters/opencode.js +1 -0
  40. package/backend/dist/harness/adapters/pi.js +2 -1
  41. package/backend/dist/harness/adapters/types.d.ts +19 -4
  42. package/backend/dist/harness/adapters/windsurf.js +1 -0
  43. package/backend/dist/harness/adapters/zed.js +3 -1
  44. package/backend/dist/harness/hosts.js +1 -0
  45. package/backend/dist/harness/translation.js +12 -4
  46. package/backend/dist/harness/types.d.ts +2 -2
  47. package/backend/dist/harness/writers/skill.d.ts +1 -1
  48. package/backend/dist/opencode/agents.d.ts +7 -0
  49. package/backend/dist/opencode/agents.js +22 -3
  50. package/backend/dist/opencode/catalog/custom-store.d.ts +50 -0
  51. package/backend/dist/opencode/catalog/custom-store.js +144 -0
  52. package/backend/dist/opencode/credentials/push.d.ts +38 -0
  53. package/backend/dist/opencode/credentials/push.js +116 -0
  54. package/backend/dist/opencode/credentials/reconcile.d.ts +49 -0
  55. package/backend/dist/opencode/credentials/reconcile.js +216 -0
  56. package/backend/dist/opencode/sync.d.ts +29 -0
  57. package/backend/dist/opencode/sync.js +186 -0
  58. package/backend/dist/pipeline/account-selection.d.ts +101 -0
  59. package/backend/dist/pipeline/account-selection.js +112 -0
  60. package/backend/dist/pipeline/orchestrator.js +34 -3
  61. package/backend/dist/providers/systemone.d.ts +29 -0
  62. package/backend/dist/providers/systemone.js +170 -0
  63. package/backend/dist/ratelimit/duration.d.ts +24 -0
  64. package/backend/dist/ratelimit/duration.js +43 -0
  65. package/backend/dist/ratelimit/governance-runtime.d.ts +121 -0
  66. package/backend/dist/ratelimit/governance-runtime.js +183 -0
  67. package/backend/dist/ratelimit/index.d.ts +4 -0
  68. package/backend/dist/ratelimit/index.js +4 -0
  69. package/backend/dist/ratelimit/limiter.d.ts +157 -0
  70. package/backend/dist/ratelimit/limiter.js +244 -0
  71. package/backend/dist/ratelimit/sliding-window-counter.d.ts +63 -0
  72. package/backend/dist/ratelimit/sliding-window-counter.js +103 -0
  73. package/backend/dist/ratelimit/subject.d.ts +26 -0
  74. package/backend/dist/ratelimit/subject.js +28 -0
  75. package/backend/dist/resilience/account-state.d.ts +84 -0
  76. package/backend/dist/resilience/account-state.js +228 -0
  77. package/backend/dist/router/layer1-classifier.d.ts +111 -0
  78. package/backend/dist/router/layer1-classifier.js +467 -0
  79. package/backend/dist/router/layer2-judge.d.ts +111 -0
  80. package/backend/dist/router/layer2-judge.js +373 -0
  81. package/backend/dist/router/retry-escalation.d.ts +89 -0
  82. package/backend/dist/router/retry-escalation.js +99 -0
  83. package/backend/dist/routes/flywheel.d.ts +3 -0
  84. package/backend/dist/routes/flywheel.js +268 -0
  85. package/backend/dist/routes/harness.js +4 -1
  86. package/backend/dist/routes/systemone.d.ts +3 -0
  87. package/backend/dist/routes/systemone.js +90 -0
  88. package/backend/dist/server.d.ts +0 -15
  89. package/backend/dist/server.js +40 -43
  90. package/backend/dist/session/session-manager.d.ts +15 -0
  91. package/backend/dist/session/session-manager.js +17 -0
  92. package/backend/dist/session/session-row.d.ts +78 -0
  93. package/backend/dist/session/session-row.js +52 -0
  94. package/backend/dist/surfaces/governance-envelope.d.ts +34 -0
  95. package/backend/dist/surfaces/governance-envelope.js +47 -0
  96. package/backend/dist/utils/token-estimator.d.ts +7 -0
  97. package/backend/dist/utils/token-estimator.js +20 -0
  98. package/bin/ocr.js +2 -2
  99. package/frontend/dist/assets/{index-DvXKvNxl.js → index-B7GKsUyU.js} +264 -244
  100. package/frontend/dist/assets/{index-1o7qI-KJ.css → index-DLKLOkQJ.css} +1 -1
  101. package/frontend/dist/index.html +2 -2
  102. package/package.json +1 -1
@@ -0,0 +1,68 @@
1
+ import type { Layer2JudgeConfig } from '../config/types.js';
2
+ /**
3
+ * Decision-capture SINK for the Layer 2 System One judge — the missing half
4
+ * of the L2 capability loop. The flywheel records what EXECUTED (so Layer 1
5
+ * can be retrained); nothing records what the JUDGE decided, which is exactly
6
+ * the raw material two future capabilities need:
7
+ * - distilling converted chat-model judgments into a native decision model
8
+ * - calibrating the "uncalibrated self-report" confidence
9
+ *
10
+ * Deferred data cannot be recovered, so the sink exists from day one — but it
11
+ * is OPT-IN behind a SINGLE-KEY gate: `classifier.layer2.collectEnabled`. The
12
+ * old three-tier chain (capture.enabled × systemoneEnabled × l2DecisionEnabled)
13
+ * is retired — the capture master switch no longer involves this sink; the
14
+ * capture page never shows these rows either. `state` carries user
15
+ * conversation content, so the default stays OFF. Nothing consumes the file
16
+ * yet by design; the trainer for native decision models is deliberately out
17
+ * of scope until real traffic exists to train on.
18
+ *
19
+ * Size cap: once the dataset passes 64 MB sampling PAUSES (warn once per
20
+ * process) — a runaway jsonl must not fill the operator's disk unnoticed.
21
+ * Deleting/rotating the file resumes writes.
22
+ *
23
+ * Gating lives HERE, not in the judge: callers stay dumb and just hand over
24
+ * the decided row. Console config saves hot-apply via applyConfig (called
25
+ * beside CaptureRecorder.applyConfig in routes/console.ts, fed the
26
+ * classifier.layer2 node) — no restart.
27
+ *
28
+ * Correlation note: rows carry no requestId (the judge sits below the layer
29
+ * that mints one). Join with flywheel rows by timestamp proximity when an
30
+ * accuracy-vs-execution evaluation is built — or thread requestId through
31
+ * routeAsync in a future change.
32
+ */
33
+ export interface DecisionCaptureRecord {
34
+ v: 1;
35
+ ts: string;
36
+ source: 'layer2_judge';
37
+ model: string;
38
+ provider: string;
39
+ upstreamKind: 'native' | 'converted';
40
+ /** The exact System One state the judge evaluated (user content — opt-in). */
41
+ state: unknown;
42
+ tier: string;
43
+ confidence: number;
44
+ latencyMs: number;
45
+ }
46
+ /**
47
+ * Derive the gate from the classifier.layer2 config node: the sink writes
48
+ * only when `collectEnabled` is literally true (single key; absent/false =
49
+ * closed). Called by the console save paths and lazily to seed from disk
50
+ * config.
51
+ */
52
+ export declare function applyConfig(cfg?: Layer2JudgeConfig): {
53
+ enabled: boolean;
54
+ datasetPath: string;
55
+ };
56
+ /**
57
+ * Pure size-capacity check (exported as the test seam — no 64 MB fixtures).
58
+ * A missing file counts as empty. Past the cap the first caller warns ONCE
59
+ * per process and every later caller is told "no capacity" until the file
60
+ * shrinks (delete/rotate) or the process restarts.
61
+ */
62
+ export declare function datasetHasCapacity(datasetPath: string, maxBytes?: number): boolean;
63
+ /** Append one judged decision. Fire-and-forget: capture is observability, so
64
+ * every failure degrades to a warn, never an error thrown into routing. */
65
+ export declare function captureDecision(record: Omit<DecisionCaptureRecord, 'v' | 'ts' | 'source'>): void;
66
+ /** Test seam: drop the cached gate so the next call re-seeds from disk, and
67
+ * allow the once-per-process cap warning to fire again. */
68
+ export declare function resetDecisionCaptureConfig(): void;
@@ -0,0 +1,85 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { loadConfig } from '../config/index.js';
4
+ import { getEnvRootDir } from '../config/env.js';
5
+ // Fixed dataset path, relative to the ACTIVE ENVIRONMENT's root (see
6
+ // applyConfig): the trainer-side contract reads this exact file, so unlike
7
+ // the retired decisionCapture block it is no longer a config knob. The path
8
+ // resolves against the env root (env.ts getEnvPaths). Upgrade path if it ever
9
+ // must move: add a classifier.layer2.collectDatasetPath key next to the gate.
10
+ const DATASET_PATH = './data/layer2-decisions.jsonl';
11
+ // Hard ceiling for the dataset: past this, sampling pauses (see capWarned).
12
+ const MAX_DATASET_BYTES = 64 * 1024 * 1024;
13
+ let captureConfig = null;
14
+ let capWarned = false;
15
+ /**
16
+ * Derive the gate from the classifier.layer2 config node: the sink writes
17
+ * only when `collectEnabled` is literally true (single key; absent/false =
18
+ * closed). Called by the console save paths and lazily to seed from disk
19
+ * config.
20
+ */
21
+ export function applyConfig(cfg) {
22
+ const enabled = cfg?.collectEnabled === true;
23
+ const datasetPath = path.resolve(getEnvRootDir(), DATASET_PATH);
24
+ captureConfig = { enabled, datasetPath };
25
+ if (enabled) {
26
+ const dir = path.dirname(datasetPath);
27
+ if (!fs.existsSync(dir)) {
28
+ try {
29
+ fs.mkdirSync(dir, { recursive: true });
30
+ }
31
+ catch {
32
+ // Sink failures must never touch routing — handled at append time too.
33
+ }
34
+ }
35
+ }
36
+ return captureConfig;
37
+ }
38
+ /**
39
+ * Pure size-capacity check (exported as the test seam — no 64 MB fixtures).
40
+ * A missing file counts as empty. Past the cap the first caller warns ONCE
41
+ * per process and every later caller is told "no capacity" until the file
42
+ * shrinks (delete/rotate) or the process restarts.
43
+ */
44
+ export function datasetHasCapacity(datasetPath, maxBytes = MAX_DATASET_BYTES) {
45
+ let size = 0;
46
+ try {
47
+ size = fs.statSync(datasetPath).size;
48
+ }
49
+ catch {
50
+ size = 0; // absent = fresh
51
+ }
52
+ if (size > maxBytes) {
53
+ if (!capWarned) {
54
+ capWarned = true;
55
+ console.warn('[layer2-decisions] 64MB cap reached, sampling paused — delete or rotate data/layer2-decisions.jsonl to resume (warns once per process).');
56
+ }
57
+ return false;
58
+ }
59
+ return true;
60
+ }
61
+ /** Current gate state; seeded from the disk config until a hot apply lands. */
62
+ function getConfig() {
63
+ return captureConfig ?? applyConfig(loadConfig().classifier?.layer2);
64
+ }
65
+ /** Append one judged decision. Fire-and-forget: capture is observability, so
66
+ * every failure degrades to a warn, never an error thrown into routing. */
67
+ export function captureDecision(record) {
68
+ const config = getConfig();
69
+ if (!config.enabled)
70
+ return;
71
+ // Stat-then-append races a few rows past the cap under concurrency —
72
+ // acceptable: the cap bounds disk usage, it is not a hard record ledger.
73
+ if (!datasetHasCapacity(config.datasetPath))
74
+ return;
75
+ const line = JSON.stringify({ v: 1, ts: new Date().toISOString(), source: 'layer2_judge', ...record }) + '\n';
76
+ fs.promises
77
+ .appendFile(config.datasetPath, line, 'utf8')
78
+ .catch((err) => console.warn(`[Layer2Judge] decision capture write failed: ${err?.message}`));
79
+ }
80
+ /** Test seam: drop the cached gate so the next call re-seeds from disk, and
81
+ * allow the once-per-process cap warning to fire again. */
82
+ export function resetDecisionCaptureConfig() {
83
+ captureConfig = null;
84
+ capWarned = false;
85
+ }
@@ -0,0 +1,133 @@
1
+ /** Sidecar overlay path for human label corrections — mirrors FlywheelDataset. */
2
+ export declare function labelsPathFor(datasetPath: string): string;
3
+ /** Backup sidecar for batch-deleted lines (D3): removed rows land here verbatim. */
4
+ export declare function sidecarPathFor(datasetPath: string): string;
5
+ export interface PruneOptions {
6
+ dropSynthetic: boolean;
7
+ dropDuplicates: boolean;
8
+ }
9
+ export interface PruneCounters {
10
+ synthetic: number;
11
+ duplicate: number;
12
+ malformed: number;
13
+ }
14
+ export interface PrunePlan {
15
+ total: number;
16
+ keptLines: string[];
17
+ removedLines: string[];
18
+ /** Ids of surviving records — drives the labels-overlay orphan purge. */
19
+ keptIds: Set<string>;
20
+ dropped: PruneCounters;
21
+ }
22
+ /**
23
+ * Pure prune planner — no fs at all, so a preview can never write. Decision
24
+ * order is identical to the historic CLI: synthetic → duplicate; malformed
25
+ * (unparseable) lines are dropped unconditionally — hygiene IS prune's job
26
+ * (D4). Valid-JSON lines that are not records are kept verbatim (CLI parity).
27
+ */
28
+ export declare function planPrune(lines: string[], opts: PruneOptions): PrunePlan;
29
+ export interface PruneOutcome {
30
+ total: number;
31
+ kept: number;
32
+ dropped: PruneCounters;
33
+ /** true only when apply was requested AND something was actually dropped (§3.1). */
34
+ applied: boolean;
35
+ backupPath: string | null;
36
+ removedLabels: number;
37
+ }
38
+ /**
39
+ * Prune one dataset file (CLI + HTTP share this). `apply: false` is pure
40
+ * preview. Nothing-to-prune → no rewrite, no backup, mtime untouched,
41
+ * `applied: false`. Returns null when the dataset file does not exist
42
+ * (caller decides 404 vs no-op).
43
+ */
44
+ export declare function pruneDataset(datasetPath: string, opts: PruneOptions, apply: boolean): PruneOutcome | null;
45
+ export interface RewriteResult {
46
+ total: number;
47
+ kept: number;
48
+ removed: number;
49
+ rewrote: boolean;
50
+ backupPath: string | null;
51
+ }
52
+ interface RewriteOptions {
53
+ /** Copy the pre-rewrite file to `<path>.bak-<ts>` before swapping. */
54
+ backup?: boolean;
55
+ /** Backups to keep after writing one (default 3). */
56
+ rotateKeep?: number;
57
+ /** Removed lines are appended verbatim to this file before the swap. */
58
+ sidecarPath?: string | null;
59
+ }
60
+ /**
61
+ * Generic filter-and-rewrite (D2): `filter` is consulted once per non-blank
62
+ * line, in file order; a false verdict discards the line verbatim (into the
63
+ * sidecar when one is configured). Nothing removed → zero writes.
64
+ */
65
+ export declare function rewriteDataset(datasetPath: string, filter: (line: string) => boolean, opts?: RewriteOptions): RewriteResult;
66
+ /**
67
+ * Delete all but the newest `keep` `<path>.bak-<ts>` siblings (rotation keeps
68
+ * `.bak` churn bounded — design risk table). Best-effort: a failed unlink
69
+ * leaves one stale backup, which must never fail an operation whose backup
70
+ * already landed.
71
+ */
72
+ export declare function rotateBackups(datasetPath: string, keep?: number): void;
73
+ export interface DeleteOutcome {
74
+ deleted: number;
75
+ /** Requested ids with no line in the dataset — in request order, deduped. */
76
+ notFound: string[];
77
+ removedLabels: number;
78
+ sidecarPath: string;
79
+ rewrote: boolean;
80
+ }
81
+ /**
82
+ * Partial-success + idempotent batch delete: every line whose record id is in
83
+ * `ids` is discarded (all duplicates of a deleted id go — whole-record
84
+ * discard), the removed lines are appended verbatim to the sidecar, and the
85
+ * labels overlay is purged down to the surviving ids (which also sweeps up
86
+ * pre-existing orphans keyed to ids that died earlier).
87
+ * Missing dataset file → every id is notFound, zero writes.
88
+ */
89
+ export declare function deleteRecordsById(datasetPath: string, ids: string[]): DeleteOutcome;
90
+ export interface ResetOutcome {
91
+ removedRecords: number;
92
+ removedLabels: number;
93
+ backupPath: string | null;
94
+ labelsBackupPath: string | null;
95
+ /** true when the dataset file itself was rewritten (route invalidates on it). */
96
+ datasetRewrote: boolean;
97
+ }
98
+ /**
99
+ * Empty the dataset and clear the labels overlay; both are archived as
100
+ * `.bak-<ts>` before the swap (the overlay only when non-empty — D3). Never
101
+ * touches the trained model files: data lifecycle ≠ deployed weights (D8).
102
+ * Missing/empty dataset → zero removals, no backup, no write (idempotent).
103
+ */
104
+ export declare function resetDataset(datasetPath: string): ResetOutcome;
105
+ export interface RetentionConfig {
106
+ retentionDays: number;
107
+ maxFileSizeMB: number;
108
+ }
109
+ export interface RetentionOutcome {
110
+ removed: number;
111
+ removedLabels: number;
112
+ rewrote: boolean;
113
+ }
114
+ /**
115
+ * One combined rewrite: the age pass runs first (drop records whose
116
+ * `timestamp` is older than retentionDays), then the size pass trims
117
+ * oldest-first until the file fits maxFileSizeMB. A record with an
118
+ * unparseable timestamp is ALWAYS kept (and treated as newest for the size
119
+ * pass); malformed lines are kept too — hygiene is prune's job (D4).
120
+ * NO backup is written (D3: retention is the only zero-backup path; the
121
+ * knobs are default-off to guard it). Zero removals or both knobs off →
122
+ * zero fs writes.
123
+ */
124
+ export declare function applyRetention(datasetPath: string, cfg: RetentionConfig): RetentionOutcome;
125
+ /**
126
+ * Atomically rewrite the labels overlay. `keepIds === null` clears every
127
+ * entry (reset); a Set keeps only entries whose id is still alive in the
128
+ * dataset. Missing or unparseable overlay → zero writes (the dataset reader
129
+ * already ignores a corrupt overlay; deleting targeted entries from bytes we
130
+ * cannot interpret would be data loss). Returns entries removed.
131
+ */
132
+ export declare function pruneLabelOverlay(labelsPath: string, keepIds: Set<string> | null): number;
133
+ export {};