@livx.cc/agentx 0.99.165 → 0.99.167

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.
@@ -25,6 +25,49 @@ if CommandLine.arguments.contains("--check-mic") {
25
25
  }
26
26
  }
27
27
 
28
+ // The gate CROSSFADES the mic into a quiet steady noise floor (comfort noise), never to digital zeros with a hard
29
+ // cut: zeros + the short residue bursts that slip the gate are an unnatural signal stt-rt-v6 rounds up into words —
30
+ // "Okay."/"Yeah."/"Mm-hmm." heard 186x over our own speech (agentx 20261111-105859); a steady floor yields none.
31
+ let GATE_RAMP: Float = 1 / 320 // gain step per 16k sample: a full open/close takes 20ms
32
+ let COMFORT_AMP: Float = 60 // uniform ±60 (≈35 rms, -61 dBFS) — below any voice, above digital silence
33
+ // A closing chunk's fade-out tail is capped to this rms: the host reads a chunk at rms ≥ 50 as a gate PASS (VoiceEngine
34
+ // overlapEnergyHold), so an unscaled 20ms fade of the residue after one burst counted the burst twice → a false hold.
35
+ let FADE_LEAK_RMS: Float = 25
36
+ var gateGain: Float = 1 // 1 = mic passes, 0 = comfort noise only (tap thread only)
37
+ var noiseSeed: UInt32 = 0x9E3779B9
38
+ func comfortNoise() -> Float { noiseSeed = noiseSeed &* 1664525 &+ 1013904223; return (Float(noiseSeed >> 8) / 8388608 - 1) * COMFORT_AMP }
39
+ /** Apply the gate decision to one chunk in place: ramp the gain toward pass (1) / floor (0) and fill with comfort noise. */
40
+ func gateRender(_ pcm: inout [Int16], gate: Bool) {
41
+ guard gate || gateGain < 1, !pcm.isEmpty else { return }
42
+ let target: Float = gate ? 0 : 1
43
+ var gains = [Float](repeating: 0, count: pcm.count)
44
+ var g = gateGain, leakSq: Float = 0
45
+ for k in 0..<pcm.count {
46
+ g = target > g ? min(target, g + GATE_RAMP) : max(target, g - GATE_RAMP)
47
+ gains[k] = g
48
+ let v = Float(pcm[k]) * g; leakSq += v * v
49
+ }
50
+ gateGain = g
51
+ let leak = (leakSq / Float(pcm.count)).squareRoot()
52
+ let scale: Float = gate && leak > FADE_LEAK_RMS ? FADE_LEAK_RMS / leak : 1
53
+ for k in 0..<pcm.count {
54
+ pcm[k] = Int16(clamping: Int32((Float(pcm[k]) * gains[k] * scale + comfortNoise() * (1 - gains[k])).rounded()))
55
+ }
56
+ }
57
+ // `--gate-sim open:rms,...`: TEST HARNESS — run gateRender over synthetic 46ms chunks (a 300Hz tone at that rms; open =
58
+ // 1 passes, 0 gates) and print each output chunk's rms. No mic, no audio engine.
59
+ if let i = CommandLine.arguments.firstIndex(of: "--gate-sim"), i + 1 < CommandLine.arguments.count {
60
+ var phase: Float = 0
61
+ for spec in CommandLine.arguments[i + 1].split(separator: ",") {
62
+ let f = spec.split(separator: ":"); let open = f[0] == "1"; let amp = (Float(f[1]) ?? 0) * Float(2).squareRoot()
63
+ var pcm = (0..<743).map { _ -> Int16 in phase += 2 * Float.pi * 300 / 16000; return Int16(amp * sin(phase)) }
64
+ gateRender(&pcm, gate: !open)
65
+ let r = (pcm.reduce(Float(0)) { $0 + Float($1) * Float($1) } / Float(pcm.count)).squareRoot()
66
+ print(Int(r.rounded()))
67
+ }
68
+ exit(0)
69
+ }
70
+
28
71
  // VPIO checks mic TCC explicitly (plain HAL capture may work while VPIO silently mutes) — request it
29
72
  let sem = DispatchSemaphore(value: 0)
30
73
  var granted = false
@@ -156,7 +199,7 @@ input.installTap(onBus: 0, bufferSize: 2048, format: inFmt) { buf, _ in
156
199
  }
157
200
  let gate = gateEnabled && audible && rms < threshold // user speech must clearly dominate the expected residue
158
201
  gateLock.unlock()
159
- if gate { for k in 0..<pcm.count { pcm[k] = 0 } } // keep the stream's timing — send silence, not nothing
202
+ gateRender(&pcm, gate: gate) // keep the stream's timing — send a noise floor, not nothing
160
203
  diagTaps += 1; diagAcc += n
161
204
  if diagAcc >= Int(inFmt.sampleRate) * 2 { // ~every 2s of input audio
162
205
  FileHandle.standardError.write("tap: \(diagTaps) firings/2s, rms=\(Int(rms)), gate=\(gate)\n".data(using: .utf8)!)
@@ -246,6 +246,8 @@ declare class PermissionOptions {
246
246
  decision: 'allow' | 'deny';
247
247
  remember?: boolean;
248
248
  } | undefined>;
249
+ /** Observer: a rule (or the allow-list default) refused a call — a host surfaces it (the CLI's live status). */
250
+ onDeny?(call: ToolUse, reason: string): void;
249
251
  }
250
252
  declare class PermissionPolicy {
251
253
  options: PermissionOptions;
@@ -668,6 +670,9 @@ declare class AgentOptions {
668
670
  * caps, MCP soft timeout) live on `JobRegistryOptions`. Completion notices reach the model via `inject` unless
669
671
  * the host set its own `onExit`. */
670
672
  jobs?: JobRegistry;
673
+ /** Called after every `inject()` (a background job's completion notice, a host steer). A REPL uses it to wake an
674
+ * IDLE session — between turns nothing drains the queue, so a finished job would otherwise wait for the next prompt. */
675
+ onInject?: () => void;
671
676
  /** Plan mode: block mutating tools until the agent calls `ExitPlanMode` (host-approved). */
672
677
  planMode: boolean;
673
678
  /** Permission policy gating each tool call (allow / ask / deny). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/agentx",
3
- "version": "0.99.165",
3
+ "version": "0.99.167",
4
4
  "description": "Edge-native AI agent runtime — drives a virtual filesystem via any LLM (ai.libx.js). Same bytes run in node, browser, or edge.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -86,7 +86,7 @@
86
86
  "libx.js": "^6.3.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@bod.ee/voice": "^0.3.55",
89
+ "@bod.ee/voice": "^0.3.58",
90
90
  "@types/bun": "latest",
91
91
  "tsup": "^8.5.1",
92
92
  "typescript": "^5"