@warmdrift/kgauto-compiler 2.0.0-alpha.25 → 2.0.0-alpha.27

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.
@@ -829,12 +829,23 @@ var PROFILES_RAW = [
829
829
  // Each entry's pricing/context/cliffs/lowering reflects the template, NOT
830
830
  // provider docs. Verify before promoting status to 'current' (L-049/L-081).
831
831
  {
832
+ // s37 (2026-05-21): UNVERIFIED-AUTO-ONBOARD → verified against
833
+ // ai.google.dev/gemini-api/docs/models/gemini-3-flash-preview +
834
+ // ai.google.dev/gemini-api/docs/pricing. L-081 catches:
835
+ // maxOutputTokens 65_535 → 65_536 (off-by-one)
836
+ // costInputPer1m 0.30 → 0.50 (template-cloned from 2.5-flash; actual is 1.67× more expensive)
837
+ // costOutputPer1m 2.50 → 3.00 (template-cloned; actual 1.2× more expensive)
838
+ // cache discount default 0.25 → 0.10 (10× discount, $0.05/$0.50 per docs)
839
+ // Cliffs inherited from 2.5-flash conservatively. The 8K-context-quality
840
+ // cliff was a 2.5-Flash observation — Google positions Gemini 3 as
841
+ // sustained-frontier-on-long-context; brain evidence will validate/relax.
842
+ // Kept as guard for now.
832
843
  id: "gemini-3-flash-preview",
833
- verifiedAgainstDocs: "UNVERIFIED-AUTO-ONBOARD",
844
+ verifiedAgainstDocs: "2026-05-21",
834
845
  provider: "google",
835
846
  status: "preview",
836
847
  maxContextTokens: 1048576,
837
- maxOutputTokens: 65535,
848
+ maxOutputTokens: 65536,
838
849
  maxTools: 128,
839
850
  parallelToolCalls: true,
840
851
  structuredOutput: "native",
@@ -845,13 +856,13 @@ var PROFILES_RAW = [
845
856
  metric: "input_tokens",
846
857
  threshold: 8e3,
847
858
  action: "downgrade_quality_warning",
848
- reason: "Quality degrades significantly above ~8K context tokens"
859
+ reason: "Inherited from 2.5-flash guard; brain evidence on Gemini 3 long-context quality will validate/relax"
849
860
  },
850
861
  {
851
862
  metric: "tool_count",
852
863
  threshold: 20,
853
864
  action: "drop_to_top_relevant",
854
- reason: "Tool reliability drops above ~20 tools (despite 128 hard limit)"
865
+ reason: "Tool reliability drops above ~20 tools (despite 128 hard limit) \u2014 inherited from Flash family"
855
866
  },
856
867
  {
857
868
  metric: "thinking_with_short_output",
@@ -860,24 +871,22 @@ var PROFILES_RAW = [
860
871
  reason: "Thinking tokens consume maxOutputTokens \u2014 empty response if drained"
861
872
  },
862
873
  {
863
- // s11 trust artifact (2026-05-02): brain showed 5/5 empty rate on
864
- // tt-intelligence/summarize/gemini-2.5-flash with tools offered.
865
- // v1's disable_thinking_for_short_output already fired and didn't
866
- // help — disabling thinking is necessary but not sufficient. Tools
867
- // present + summarize intent confuses Flash into a no-output state
868
- // (likely tool-decision purgatory). Strip tools entirely for this
869
- // archetype on this model.
874
+ // Inherited from gemini-2.5-flash s11 trust artifact. Family-likely
875
+ // failure mode for Flash architecture. Keep preemptively until brain
876
+ // evidence on Gemini 3 specifically.
870
877
  metric: "tool_count",
871
878
  threshold: 1,
872
879
  whenIntent: "summarize",
873
880
  action: "strip_tools",
874
- reason: "Gemini Flash returns empty when summarize intent has tools offered (5/5 empty rate observed in v1 prod 2026-04-19, replayed into v2 brain 2026-04-29)"
881
+ reason: "Inherited from 2.5-flash s11 cliff: summarize+tools \u2192 empty response. Preemptive guard until brain evidence on 3-flash-preview specifically."
875
882
  }
876
883
  ],
877
- costInputPer1m: 0.3,
878
- costOutputPer1m: 2.5,
884
+ costInputPer1m: 0.5,
885
+ costOutputPer1m: 3,
879
886
  lowering: {
880
887
  ...GOOGLE_LOWERING_BASE,
888
+ // 10× cache discount per Google pricing: $0.05/M cached vs $0.50/M input.
889
+ cache: { ...GOOGLE_LOWERING_BASE.cache, discount: 0.1 },
881
890
  thinking: { field: "generationConfig.thinkingConfig.thinkingBudget", default: "auto" }
882
891
  },
883
892
  recovery: [
@@ -903,40 +912,45 @@ var PROFILES_RAW = [
903
912
  ],
904
913
  strengths: ["speed", "volume", "classification", "1m_context", "cost"],
905
914
  weaknesses: ["complex_schemas", "large_tool_sets", "high_context_quality"],
906
- notes: "AUTO-ONBOARDED 2026-05-16 from `gemini-2.5-flash`. Pricing, context, cliffs are template-cloned and UNVERIFIED \u2014 confirm against provider docs before promoting status to 'current'.",
907
- // Master plan §6.2 anchor. Tier 0 for hunt (parallel tool throughput
908
- // 15-75 calls/step beats Sonnet L-040), summarize, classify.
915
+ notes: "Verified s37 (2026-05-21) against Google docs. Step-change positioning vs 2.5-flash on agentic loops per Google's release notes (Dec 2025). Pricing 1.67\xD7/1.2\xD7 higher than 2.5-flash; cache discount 10\xD7 (vs 4\xD7 for 2.5). Status=preview until brain evidence accumulates.",
916
+ // Anchored to 2.5-flash archetypePerf as starter, with judgment adjustments
917
+ // for Google's "step-change on agentic" positioning. Brain evidence (zero
918
+ // rows today) will replace these starter values.
909
919
  archetypePerf: {
910
920
  hunt: 9,
911
- // L-040: parallel tool throughput 15-75/step
921
+ // Inherits 2.5-flash L-040 parallel-tool tier; Google positions 3 as agentic-loop upgrade
912
922
  classify: 7,
913
- // brain-validated, 218 rows
923
+ // Inherits 2.5-flash brain-validated tier (218 rows on 2.5)
914
924
  summarize: 7,
915
- // brain-validated; cliff strips tools when present
925
+ // Inherits 2.5-flash; cliff strips tools when present
916
926
  transform: 7,
917
- ask: 7,
918
- generate: 6,
919
- plan: 5,
927
+ ask: 8,
928
+ // +1 vs 2.5-flash — sustained-frontier positioning
929
+ generate: 7,
930
+ // +1 vs 2.5-flash — agentic coding upgrade per Google
931
+ plan: 6,
932
+ // +1 vs 2.5-flash — complex iterations per positioning
920
933
  extract: 6,
921
- // alpha.8 MAX_TOKENS history on structured output
922
- critique: 4
923
- // reasoning shallower than Sonnet/Opus
934
+ critique: 5
935
+ // +1 vs 2.5-flash — but still below Sonnet/Opus reasoning floor
924
936
  }
925
937
  },
926
938
  {
927
- // ── Gemini 2.5 Flash-Lite ──
928
- // Onboarded 2026-05-13 (s22) after the model-release watcher surfaced
929
- // it as a UNREGISTERED + NEW candidate. Released by Google July 2025,
930
- // stable. Positioned BELOW Flash on the cost/perf frontier:
931
- // input $0.10/M (Flash $0.30/M) —cheaper
932
- // output $0.40/M (Flash $2.50/M) — 6× cheaper
933
- // cache $0.01/M — 1/10 of input (vs Flash 0.25 discount)
934
- // Cliffs are HYPOTHESIZED from Flash's known failure modes — Flash-Lite
935
- // is a smaller sibling, so we inherit Flash's cliffs at equal-or-tighter
936
- // thresholds. The brain will validate/relax these as evidence accumulates
937
- // per (archetype, model) tuple. Currently ZERO brain rows for this model.
939
+ // ── Gemini 3.1 Flash-Lite ──
940
+ // Onboarded 2026-05-16 by auto-onboarder; s37 (2026-05-21) verified
941
+ // against ai.google.dev/gemini-api/docs/pricing.
942
+ //
943
+ // L-081 CATCHES (template clone from 2.5-flash-lite was 2.5-3.75× too cheap):
944
+ // costInputPer1m 0.10 0.25 (template clone undervalued by 2.)
945
+ // costOutputPer1m 0.40 1.50 (template clone undervalued by 3.75×)
946
+ //
947
+ // Real 3.1-flash-lite is NOT a cost-equivalent successor to 2.5-flash-lite —
948
+ // it sits between 2.5-flash-lite ($0.10/$0.40) and 2.5-flash ($0.30/$2.50).
949
+ // Cache discount 10× verified ($0.025/M cached vs $0.25/M input).
950
+ //
951
+ // Cliffs are HYPOTHESIZED from 2.5-flash family; brain evidence pending.
938
952
  id: "gemini-3.1-flash-lite",
939
- verifiedAgainstDocs: "UNVERIFIED-AUTO-ONBOARD",
953
+ verifiedAgainstDocs: "2026-05-21",
940
954
  provider: "google",
941
955
  status: "preview",
942
956
  maxContextTokens: 1048576,
@@ -977,12 +991,12 @@ var PROFILES_RAW = [
977
991
  reason: "Inherited from Flash s11 cliff: summarize+tools \u2192 empty response. Preemptive guard until brain evidence on Flash-Lite specifically."
978
992
  }
979
993
  ],
980
- costInputPer1m: 0.1,
981
- costOutputPer1m: 0.4,
994
+ costInputPer1m: 0.25,
995
+ costOutputPer1m: 1.5,
982
996
  lowering: {
983
997
  ...GOOGLE_LOWERING_BASE,
984
- // Cache discount 10× (vs Flash 4×) — Google's spec is $0.01/M cache vs
985
- // $0.10/M input. Material for repeat-prompt workloads (classify shape).
998
+ // Cache discount 10× (vs Flash 4×) — Google docs s37: $0.025/M cached vs
999
+ // $0.25/M input. Material for repeat-prompt workloads (classify shape).
986
1000
  cache: { ...GOOGLE_LOWERING_BASE.cache, discount: 0.1 },
987
1001
  thinking: { field: "generationConfig.thinkingConfig.thinkingBudget", default: "auto" }
988
1002
  },
@@ -1007,13 +1021,13 @@ var PROFILES_RAW = [
1007
1021
  reason: "MALFORMED_FUNCTION_CALL maps to stop \u2014 escalate to next target."
1008
1022
  }
1009
1023
  ],
1010
- strengths: ["lowest_cost", "speed", "volume", "classification", "summarize", "1m_context", "cache_friendly"],
1024
+ strengths: ["low_cost", "speed", "volume", "classification", "summarize", "1m_context", "cache_friendly"],
1011
1025
  weaknesses: ["complex_reasoning", "large_tool_sets", "complex_schemas", "structured_output_unproven", "long_context_quality"],
1012
- notes: "AUTO-ONBOARDED 2026-05-16 from `gemini-2.5-flash-lite`. Pricing, context, cliffs are template-cloned and UNVERIFIED \u2014 confirm against provider docs before promoting status to 'current'.",
1013
- // Tier 3 emergency floor for summarize/classify chains. ZERO brain
1014
- // rows — all values are starter hypotheses anchored to "smaller
1015
- // sibling of Flash, at-or-below Flash perf on every archetype." The
1016
- // first 50 brain rows per archetype will validate or relax these.
1026
+ notes: "Verified s37 (2026-05-21) against Google docs. Sits between 2.5-flash-lite (cheaper) and 2.5-flash (more expensive) on cost frontier; 2.5\xD7 more expensive than initial template-clone. Cliffs hypothesized from Flash family \u2014 brain evidence pending.",
1027
+ // Tier 2-3 floor for summarize/classify chains at the new (verified) price
1028
+ // point. ZERO brain rows — values are starter hypotheses anchored to
1029
+ // "smaller sibling of Flash at higher cost than 2.5-flash-lite." The first
1030
+ // 50 brain rows per archetype will validate or relax these.
1017
1031
  archetypePerf: {
1018
1032
  classify: 6,
1019
1033
  // starter hypothesis — verify (Flash is 7, lite likely ≤)
@@ -1028,6 +1042,125 @@ var PROFILES_RAW = [
1028
1042
  plan: 3,
1029
1043
  critique: 3
1030
1044
  }
1045
+ },
1046
+ // ─────────────────────────────────────────────────────────────────────────
1047
+ // Gemini 3.5 Flash — hand-onboarded s37 (2026-05-21)
1048
+ //
1049
+ // Google positioning ("Most intelligent for sustained frontier performance
1050
+ // on agentic and coding tasks" / "particularly effective for rapid agentic
1051
+ // loops involving complex coding cycles and iterations") suggests this is
1052
+ // the Flash-family upgrade specifically aimed at hunt-shape workloads.
1053
+ // Pricing 5× input / 3.6× output vs 2.5-flash — material cost premium.
1054
+ // archetypePerf adjusted +1 vs 2.5-flash on ask/generate/plan/critique
1055
+ // (sustained-frontier positioning); hunt held at 9 inherited from L-040
1056
+ // family parallel-tool tier; brain evidence will validate within 50 rows.
1057
+ //
1058
+ // Cliffs inherited conservatively from 2.5-flash. Google's "sustained
1059
+ // frontier on long-context" positioning suggests the 8K cliff may not
1060
+ // apply to 3.5 — keep as guard until brain evidence shows otherwise.
1061
+ //
1062
+ // Specs verified against:
1063
+ // ai.google.dev/gemini-api/docs/models/gemini-3.5-flash
1064
+ // ai.google.dev/gemini-api/docs/pricing (Standard tier)
1065
+ // ─────────────────────────────────────────────────────────────────────────
1066
+ {
1067
+ id: "gemini-3.5-flash",
1068
+ verifiedAgainstDocs: "2026-05-21",
1069
+ provider: "google",
1070
+ status: "current",
1071
+ maxContextTokens: 1048576,
1072
+ maxOutputTokens: 65536,
1073
+ maxTools: 128,
1074
+ parallelToolCalls: true,
1075
+ structuredOutput: "native",
1076
+ systemPromptMode: "separate",
1077
+ streaming: true,
1078
+ cliffs: [
1079
+ {
1080
+ metric: "input_tokens",
1081
+ threshold: 8e3,
1082
+ action: "downgrade_quality_warning",
1083
+ reason: "Inherited from 2.5-flash guard; Google positions 3.5 as sustained-frontier-on-long-context but brain evidence pending"
1084
+ },
1085
+ {
1086
+ metric: "tool_count",
1087
+ threshold: 20,
1088
+ action: "drop_to_top_relevant",
1089
+ reason: "Inherited from Flash family: tool reliability drops above ~20 (despite 128 hard limit). Validate per (archetype, model) after n\u226520."
1090
+ },
1091
+ {
1092
+ metric: "thinking_with_short_output",
1093
+ threshold: 1,
1094
+ action: "force_thinking_budget_zero",
1095
+ reason: "Thinking mode supported per Google docs; same drain risk as 2.5-flash \u2014 thinking tokens consume maxOutputTokens"
1096
+ },
1097
+ {
1098
+ // Inherited from 2.5-flash s11 trust artifact (5/5 empty rate on
1099
+ // tt-intelligence/summarize/gemini-2.5-flash with tools offered).
1100
+ // Family-likely failure mode for Flash architecture across versions.
1101
+ // Keep preemptively until brain evidence on 3.5-flash specifically.
1102
+ metric: "tool_count",
1103
+ threshold: 1,
1104
+ whenIntent: "summarize",
1105
+ action: "strip_tools",
1106
+ reason: "Inherited from 2.5-flash s11 cliff (kgauto commit 3872832): summarize+tools \u2192 empty response. Preemptive guard until brain evidence on 3.5-flash specifically."
1107
+ }
1108
+ ],
1109
+ costInputPer1m: 1.5,
1110
+ costOutputPer1m: 9,
1111
+ lowering: {
1112
+ ...GOOGLE_LOWERING_BASE,
1113
+ // 10× cache discount per Google pricing: $0.15/M cached vs $1.50/M input.
1114
+ cache: { ...GOOGLE_LOWERING_BASE.cache, discount: 0.1 },
1115
+ thinking: { field: "generationConfig.thinkingConfig.thinkingBudget", default: "auto" }
1116
+ },
1117
+ recovery: [
1118
+ {
1119
+ signal: "empty_response_after_tool",
1120
+ action: "retry_with_params",
1121
+ retryParams: { "generationConfig.thinkingConfig.thinkingBudget": 0 },
1122
+ maxRetries: 1,
1123
+ reason: "Inherited Flash-family pattern: empty after tool result \u2014 retry with thinking off"
1124
+ },
1125
+ {
1126
+ signal: "empty_response",
1127
+ action: "retry_with_params",
1128
+ retryParams: { "generationConfig.thinkingConfig.thinkingBudget": 0 },
1129
+ maxRetries: 1,
1130
+ reason: "Empty response \u2014 try with thinking off"
1131
+ },
1132
+ {
1133
+ signal: "malformed_function_call",
1134
+ action: "escalate",
1135
+ reason: "MALFORMED_FUNCTION_CALL maps to stop \u2014 escalate to next target"
1136
+ }
1137
+ ],
1138
+ strengths: ["agentic_loops", "coding", "1m_context", "parallel_tools", "thinking_mode", "sustained_frontier"],
1139
+ weaknesses: ["cost_vs_2_5_flash", "no_brain_evidence_yet"],
1140
+ notes: "Hand-onboarded s37 (2026-05-21) verified against Google docs. Stable status; positioned as Flash-family upgrade for agentic loops and coding. 5\xD7/3.6\xD7 more expensive than 2.5-flash but Google claims step-change on sustained frontier work. archetypePerf adjustments are judgment-grounded starter hypotheses \u2014 brain evidence will validate within ~50 rows per archetype.",
1141
+ // Starter hypothesis: anchored to 2.5-flash archetypePerf with +1
1142
+ // adjustments where Google's positioning explicitly supports
1143
+ // (agentic/coding/sustained). Hunt held at 9 inherited from L-040 family
1144
+ // parallel-tool tier. Brain evidence will replace.
1145
+ archetypePerf: {
1146
+ hunt: 9,
1147
+ // Inherited from 2.5-flash L-040 parallel-tool tier; Google positions 3.5 as agentic-loop champion
1148
+ classify: 7,
1149
+ // Inherited from 2.5-flash brain-validated tier (218 rows on 2.5)
1150
+ summarize: 7,
1151
+ // Inherited from 2.5-flash; cliff strips tools when present
1152
+ transform: 7,
1153
+ ask: 8,
1154
+ // +1 vs 2.5-flash — sustained-frontier positioning
1155
+ generate: 8,
1156
+ // +1 vs 2.5-flash (6→8) — Google: "complex coding cycles and iterations"
1157
+ plan: 7,
1158
+ // +1 vs 2.5-flash (5→7) — "complex iterations" positioning
1159
+ extract: 7,
1160
+ // +1 vs 2.5-flash — sustained-frontier on structured tasks
1161
+ critique: 5
1162
+ // +1 vs 2.5-flash — but still below Sonnet/Opus reasoning floor
1163
+ }
1031
1164
  }
1032
1165
  ];
1033
1166
  var ALIASES = {
@@ -1,92 +1,6 @@
1
1
  // src/glassbox/types.ts
2
2
  var GLASSBOX_STREAM_TTL_MS = 6e4;
3
3
 
4
- // src/glassbox/pubsub-memory.ts
5
- var MemoryPubSub = class {
6
- subscribers = /* @__PURE__ */ new Map();
7
- async publish(traceId, event) {
8
- const subs = this.subscribers.get(traceId);
9
- if (!subs || subs.size === 0) return;
10
- for (const sub of subs) {
11
- if (sub.closed) continue;
12
- try {
13
- sub.controller.enqueue(event);
14
- } catch {
15
- sub.closed = true;
16
- continue;
17
- }
18
- this.refreshTtl(traceId, sub);
19
- }
20
- }
21
- subscribe(traceId) {
22
- const self = this;
23
- let sub;
24
- return new ReadableStream({
25
- start(controller) {
26
- sub = {
27
- controller,
28
- ttlTimer: setTimeout(() => {
29
- self.closeSubscriber(traceId, sub);
30
- }, GLASSBOX_STREAM_TTL_MS),
31
- closed: false
32
- };
33
- let set = self.subscribers.get(traceId);
34
- if (!set) {
35
- set = /* @__PURE__ */ new Set();
36
- self.subscribers.set(traceId, set);
37
- }
38
- set.add(sub);
39
- },
40
- cancel() {
41
- if (sub) self.removeSubscriber(traceId, sub);
42
- }
43
- });
44
- }
45
- /**
46
- * Refresh the rolling TTL for a subscriber after an event lands. Replaces
47
- * the existing timer with a fresh 60s one.
48
- */
49
- refreshTtl(traceId, sub) {
50
- clearTimeout(sub.ttlTimer);
51
- sub.ttlTimer = setTimeout(() => {
52
- this.closeSubscriber(traceId, sub);
53
- }, GLASSBOX_STREAM_TTL_MS);
54
- }
55
- /**
56
- * Close the subscriber's stream cleanly and remove from the fan-out set.
57
- * Idempotent — safe to call multiple times.
58
- */
59
- closeSubscriber(traceId, sub) {
60
- if (sub.closed) return;
61
- sub.closed = true;
62
- clearTimeout(sub.ttlTimer);
63
- try {
64
- sub.controller.close();
65
- } catch {
66
- }
67
- this.removeSubscriber(traceId, sub);
68
- }
69
- removeSubscriber(traceId, sub) {
70
- clearTimeout(sub.ttlTimer);
71
- const set = this.subscribers.get(traceId);
72
- if (!set) return;
73
- set.delete(sub);
74
- if (set.size === 0) this.subscribers.delete(traceId);
75
- }
76
- /**
77
- * Test-only reset. Tears down all subscribers, clears all state. Calling
78
- * outside of tests is harmless but cancels every active stream.
79
- */
80
- _reset() {
81
- for (const [, set] of this.subscribers) {
82
- for (const sub of set) {
83
- this.closeSubscriber("", sub);
84
- }
85
- }
86
- this.subscribers.clear();
87
- }
88
- };
89
-
90
4
  // src/glassbox/pubsub-upstash.ts
91
5
  var UpstashPubSub = class {
92
6
  url;
@@ -101,8 +15,8 @@ var UpstashPubSub = class {
101
15
  this.blockMs = cfg.blockMs ?? 100;
102
16
  this.maxLen = cfg.maxLen ?? 100;
103
17
  }
104
- async publish(traceId, event) {
105
- const key = streamKey(traceId);
18
+ async publish(channelKey, event) {
19
+ const key = channelKey;
106
20
  const payload = JSON.stringify(event);
107
21
  await this.cmd([
108
22
  "XADD",
@@ -116,8 +30,8 @@ var UpstashPubSub = class {
116
30
  ]);
117
31
  await this.cmd(["EXPIRE", key, String(Math.ceil(GLASSBOX_STREAM_TTL_MS / 1e3))]);
118
32
  }
119
- subscribe(traceId) {
120
- const key = streamKey(traceId);
33
+ subscribe(channelKey) {
34
+ const key = channelKey;
121
35
  const self = this;
122
36
  let cursor = "$";
123
37
  let cancelled = false;
@@ -191,9 +105,12 @@ var UpstashPubSub = class {
191
105
  return json;
192
106
  }
193
107
  };
194
- function streamKey(traceId) {
108
+ function traceChannel(traceId) {
195
109
  return `glassbox:trace:${traceId}`;
196
110
  }
111
+ function appChannel(appId) {
112
+ return `glassbox:app:${appId}`;
113
+ }
197
114
  function decodeEvent(fields) {
198
115
  const raw = fields["event"];
199
116
  if (!raw) return void 0;
@@ -231,6 +148,92 @@ function parseXReadResult(raw) {
231
148
  return { entries };
232
149
  }
233
150
 
151
+ // src/glassbox/pubsub-memory.ts
152
+ var MemoryPubSub = class {
153
+ subscribers = /* @__PURE__ */ new Map();
154
+ async publish(channelKey, event) {
155
+ const subs = this.subscribers.get(channelKey);
156
+ if (!subs || subs.size === 0) return;
157
+ for (const sub of subs) {
158
+ if (sub.closed) continue;
159
+ try {
160
+ sub.controller.enqueue(event);
161
+ } catch {
162
+ sub.closed = true;
163
+ continue;
164
+ }
165
+ this.refreshTtl(channelKey, sub);
166
+ }
167
+ }
168
+ subscribe(channelKey) {
169
+ const self = this;
170
+ let sub;
171
+ return new ReadableStream({
172
+ start(controller) {
173
+ sub = {
174
+ controller,
175
+ ttlTimer: setTimeout(() => {
176
+ self.closeSubscriber(channelKey, sub);
177
+ }, GLASSBOX_STREAM_TTL_MS),
178
+ closed: false
179
+ };
180
+ let set = self.subscribers.get(channelKey);
181
+ if (!set) {
182
+ set = /* @__PURE__ */ new Set();
183
+ self.subscribers.set(channelKey, set);
184
+ }
185
+ set.add(sub);
186
+ },
187
+ cancel() {
188
+ if (sub) self.removeSubscriber(channelKey, sub);
189
+ }
190
+ });
191
+ }
192
+ /**
193
+ * Refresh the rolling TTL for a subscriber after an event lands. Replaces
194
+ * the existing timer with a fresh 60s one.
195
+ */
196
+ refreshTtl(channelKey, sub) {
197
+ clearTimeout(sub.ttlTimer);
198
+ sub.ttlTimer = setTimeout(() => {
199
+ this.closeSubscriber(channelKey, sub);
200
+ }, GLASSBOX_STREAM_TTL_MS);
201
+ }
202
+ /**
203
+ * Close the subscriber's stream cleanly and remove from the fan-out set.
204
+ * Idempotent — safe to call multiple times.
205
+ */
206
+ closeSubscriber(channelKey, sub) {
207
+ if (sub.closed) return;
208
+ sub.closed = true;
209
+ clearTimeout(sub.ttlTimer);
210
+ try {
211
+ sub.controller.close();
212
+ } catch {
213
+ }
214
+ this.removeSubscriber(channelKey, sub);
215
+ }
216
+ removeSubscriber(channelKey, sub) {
217
+ clearTimeout(sub.ttlTimer);
218
+ const set = this.subscribers.get(channelKey);
219
+ if (!set) return;
220
+ set.delete(sub);
221
+ if (set.size === 0) this.subscribers.delete(channelKey);
222
+ }
223
+ /**
224
+ * Test-only reset. Tears down all subscribers, clears all state. Calling
225
+ * outside of tests is harmless but cancels every active stream.
226
+ */
227
+ _reset() {
228
+ for (const [, set] of this.subscribers) {
229
+ for (const sub of set) {
230
+ this.closeSubscriber("", sub);
231
+ }
232
+ }
233
+ this.subscribers.clear();
234
+ }
235
+ };
236
+
234
237
  // src/glassbox/emit.ts
235
238
  var activePubSub;
236
239
  function getPubSub() {
@@ -254,40 +257,52 @@ function readEnv(key) {
254
257
  }
255
258
  return void 0;
256
259
  }
257
- function emitGlassboxEvent(traceId, kind, data) {
260
+ function emitGlassboxEvent(traceId, appId, kind, data) {
258
261
  if (!traceId) return;
259
262
  const event = { kind, at: Date.now(), data };
260
263
  const ps = getPubSub();
261
264
  try {
262
- const p = ps.publish(traceId, event);
263
- if (p && typeof p.then === "function") {
264
- p.catch(() => {
265
+ const p1 = ps.publish(traceChannel(traceId), event);
266
+ if (p1 && typeof p1.then === "function") {
267
+ p1.catch(() => {
265
268
  });
266
269
  }
267
270
  } catch {
268
271
  }
272
+ if (appId) {
273
+ try {
274
+ const p2 = ps.publish(appChannel(appId), event);
275
+ if (p2 && typeof p2.then === "function") {
276
+ p2.catch(() => {
277
+ });
278
+ }
279
+ } catch {
280
+ }
281
+ }
269
282
  }
270
- function emitCompileStart(traceId, data) {
271
- emitGlassboxEvent(traceId, "compile.start", data);
283
+ function emitCompileStart(traceId, appId, data) {
284
+ emitGlassboxEvent(traceId, appId, "compile.start", data);
272
285
  }
273
- function emitCompileDone(traceId, data) {
274
- emitGlassboxEvent(traceId, "compile.done", data);
286
+ function emitCompileDone(traceId, appId, data) {
287
+ emitGlassboxEvent(traceId, appId, "compile.done", data);
275
288
  }
276
- function emitExecuteAttempt(traceId, data) {
277
- emitGlassboxEvent(traceId, "execute.attempt", data);
289
+ function emitExecuteAttempt(traceId, appId, data) {
290
+ emitGlassboxEvent(traceId, appId, "execute.attempt", data);
278
291
  }
279
- function emitExecuteSuccess(traceId, data) {
280
- emitGlassboxEvent(traceId, "execute.success", data);
292
+ function emitExecuteSuccess(traceId, appId, data) {
293
+ emitGlassboxEvent(traceId, appId, "execute.success", data);
281
294
  }
282
- function emitAdvisoryFired(traceId, data) {
283
- emitGlassboxEvent(traceId, "advisory.fired", data);
295
+ function emitAdvisoryFired(traceId, appId, data) {
296
+ emitGlassboxEvent(traceId, appId, "advisory.fired", data);
284
297
  }
285
- function emitFallbackWalked(traceId, data) {
286
- emitGlassboxEvent(traceId, "fallback.walked", data);
298
+ function emitFallbackWalked(traceId, appId, data) {
299
+ emitGlassboxEvent(traceId, appId, "fallback.walked", data);
287
300
  }
288
301
 
289
302
  export {
290
303
  GLASSBOX_STREAM_TTL_MS,
304
+ traceChannel,
305
+ appChannel,
291
306
  getPubSub,
292
307
  emitCompileStart,
293
308
  emitCompileDone,
@@ -0,0 +1,29 @@
1
+ import {
2
+ appChannel,
3
+ getPubSub,
4
+ traceChannel
5
+ } from "./chunk-NBO4R5PC.mjs";
6
+
7
+ // src/glassbox/subscribe.ts
8
+ function emptyStream() {
9
+ return new ReadableStream({
10
+ start(controller) {
11
+ controller.close();
12
+ }
13
+ });
14
+ }
15
+ function subscribe(traceId) {
16
+ if (!traceId) return emptyStream();
17
+ return getPubSub().subscribe(traceChannel(traceId));
18
+ }
19
+ function subscribeApp({
20
+ appId
21
+ }) {
22
+ if (!appId) return emptyStream();
23
+ return getPubSub().subscribe(appChannel(appId));
24
+ }
25
+
26
+ export {
27
+ subscribe,
28
+ subscribeApp
29
+ };
@@ -1,5 +1,5 @@
1
- import { G as GlassboxEvent } from '../types-D9WndxeD.mjs';
2
- export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-D9WndxeD.mjs';
1
+ import { G as GlassboxEvent } from '../types-o9etg93a.mjs';
2
+ export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-o9etg93a.mjs';
3
3
  import '../ir-B9zqlwjH.mjs';
4
4
  import '../dialect.mjs';
5
5
 
@@ -38,5 +38,22 @@ import '../dialect.mjs';
38
38
  * down the subscription cleanly via the underlying adapter.
39
39
  */
40
40
  declare function subscribe(traceId: string): ReadableStream<GlassboxEvent>;
41
+ /**
42
+ * Subscribe to Glass-Box events for ALL traces under an appId — the
43
+ * "tail-all" surface (alpha.26). Backs the extension's default Live mode:
44
+ * rather than needing a specific traceId ahead of time, the panel sees
45
+ * every event for the configured consumer as calls happen.
46
+ *
47
+ * Per-app routing fires only when emit call-sites pass `appId` (the typed
48
+ * builders thread `ir.appId` automatically). Per-trace channel continues to
49
+ * fire for `subscribe(traceId)` callers — both arms are independent.
50
+ *
51
+ * Cross-tenant isolation: the consumer's `/api/glassbox/stream` uses the
52
+ * factory's configured appId — no caller-supplied `?appId=` URL parameter,
53
+ * so a consumer cannot subscribe to another consumer's stream.
54
+ */
55
+ declare function subscribeApp({ appId, }: {
56
+ appId: string;
57
+ }): ReadableStream<GlassboxEvent>;
41
58
 
42
- export { GlassboxEvent, subscribe };
59
+ export { GlassboxEvent, subscribe, subscribeApp };