pantheon-opencode 1.6.2-beta.15 → 1.6.2-beta.17

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/src/plugin-v2.ts CHANGED
@@ -116,6 +116,16 @@ import {
116
116
  import { GOAL_LOOP_DEFAULTS, GoalStore } from './pantheon/goal-loop.ts'
117
117
  import { createGuardPathResolver } from './pantheon/guard-path.ts'
118
118
  import type { V2JevDecisionRuntime } from './pantheon/jev-decision-tool.ts'
119
+ import {
120
+ createJ3EscalationObserver,
121
+ isSubagentDispatchEvent,
122
+ j3EscalationEnabledFromEnv,
123
+ } from './pantheon/jev-escalation.ts'
124
+ import {
125
+ createJ1RiskGateObserver,
126
+ isRiskGateTarget,
127
+ j1RiskGateEnabledFromEnv,
128
+ } from './pantheon/jev-risk-gate.ts'
119
129
  import { DECISION_EGRESS_ACTION } from './pantheon/local-decision-egress-gate.ts'
120
130
  import { applyDecisionRouterToPrompt } from './pantheon/local-decision-prompt.ts'
121
131
  import { getSharedBoard } from './pantheon/shared-board.ts'
@@ -660,6 +670,56 @@ function transformReferences(draft: ReferenceDraft): void {
660
670
 
661
671
  // ─── V2 Tool Registration ───────────────────────────────────────────────
662
672
 
673
+ /**
674
+ * Construct the ONE Jev runtime the plugin threads everywhere: the explicit
675
+ * `pantheon_jev_decide` tool and the J1 risk-score shadow observer both call
676
+ * through this instance, so `decide` and `permissionAssert` are bound to their
677
+ * owning host domains exactly once. `undefined` when the host lacks either the
678
+ * native Decisions API or the model catalog (the route no longer consults the
679
+ * catalog, but the tool registration contract still feature-detects both).
680
+ */
681
+ function buildV2JevRuntime(host: ReturnType<typeof hostDomains>): V2JevDecisionRuntime | undefined {
682
+ const decisionsFn = host.experimental?.generate?.decisions
683
+ const modelListFn = host.model?.list
684
+ if (typeof decisionsFn !== 'function' || typeof modelListFn !== 'function') return undefined
685
+ const decisionsOwner = host.experimental?.generate
686
+ const decide = decisionsFn
687
+ const listModels = modelListFn
688
+ // The 2.2.5 host exposes ctx.skill as the SkillEditor (list()); the SDK
689
+ // types this file sees declare skill as the registration hook, so the
690
+ // runtime shape is read through one narrow, feature-detected cast.
691
+ const skillDomain = (host as { skill?: { list?: () => unknown } }).skill
692
+ const skillList = skillDomain?.list
693
+ const permissionAssertFn = host.permission?.assert
694
+ const permissionAssert =
695
+ typeof permissionAssertFn === 'function'
696
+ ? (input: Record<string, unknown>) => permissionAssertFn.call(host.permission, input)
697
+ : undefined
698
+ // The J4 output-quality review telemetry sink (jev-quality-score.ts): the
699
+ // review mode of `pantheon_jev_decide` records ONE observer-style shadow
700
+ // record per run (q-token or skip token) through the in-memory, bounded 0b
701
+ // path (`createTelemetrySink`, no I/O), carrying `mode: 'shadow'`. The sink
702
+ // is created per runtime build so it always matches the runtime that holds
703
+ // it; the records are advisory and never read back by the tool path.
704
+ const j4Sink = createTelemetrySink()
705
+ j4TelemetrySink = j4Sink
706
+ return {
707
+ // Every host method is invoked with its owning domain as receiver: the
708
+ // canary records `ctx.model.list()` (bound) succeeding on 2.2.5 while a
709
+ // detached reference threw in the field and surfaced only as
710
+ // CATALOG_UNAVAILABLE. Same discipline as permissionAssert above.
711
+ listModels: () => listModels.call(host.model),
712
+ decide: (request: NativeDecisionRequest) => decide.call(decisionsOwner, request),
713
+ // Sync-or-async host skill list; absent/throwing falls back to the
714
+ // catalog-only preset inside the tool.
715
+ listSkills: async () => skillList?.call(skillDomain),
716
+ ...(permissionAssert === undefined ? {} : { permissionAssert }),
717
+ shadowSink: (record) => {
718
+ j4Sink.emit({ ...record, mode: 'shadow' })
719
+ },
720
+ }
721
+ }
722
+
663
723
  /**
664
724
  * Attempt to register Pantheon tools via V2 ctx.tool.transform.
665
725
  *
@@ -675,6 +735,7 @@ function transformReferences(draft: ReferenceDraft): void {
675
735
  async function registerV2Tools(
676
736
  context: PluginContext,
677
737
  boundedRead?: ReturnType<typeof createV2BoundedReadTool>['definition'],
738
+ jevRuntime?: V2JevDecisionRuntime,
678
739
  ): Promise<boolean> {
679
740
  const host = hostDomains(context)
680
741
  const toolCtx = host.tool
@@ -698,34 +759,10 @@ async function registerV2Tools(
698
759
  const decisionsFn = host.experimental?.generate?.decisions
699
760
  const jevReady = visionReady && typeof decisionsFn === 'function'
700
761
  if (!jevReady) markUnsupported('jev-decision-tool')
701
- const permissionAssertFn = host.permission?.assert
702
- let jevRuntime: V2JevDecisionRuntime | undefined
703
- if (jevReady && typeof decisionsFn === 'function' && typeof modelListFn === 'function') {
704
- const decisionsOwner = host.experimental?.generate
705
- const decide = decisionsFn
706
- const listModels = modelListFn
707
- // The 2.2.5 host exposes ctx.skill as the SkillEditor (list()); the SDK
708
- // types this file sees declare skill as the registration hook, so the
709
- // runtime shape is read through one narrow, feature-detected cast.
710
- const skillDomain = (host as { skill?: { list?: () => unknown } }).skill
711
- const skillList = skillDomain?.list
712
- const permissionAssert =
713
- typeof permissionAssertFn === 'function'
714
- ? (input: Record<string, unknown>) => permissionAssertFn.call(host.permission, input)
715
- : undefined
716
- jevRuntime = {
717
- // Every host method is invoked with its owning domain as receiver:
718
- // the canary records `ctx.model.list()` (bound) succeeding on 2.2.5
719
- // while a detached reference threw in the field and surfaced only as
720
- // CATALOG_UNAVAILABLE. Same discipline as permissionAssert above.
721
- listModels: () => listModels.call(host.model),
722
- decide: (request: NativeDecisionRequest) => decide.call(decisionsOwner, request),
723
- // Sync-or-async host skill list; absent/throwing falls back to the
724
- // catalog-only preset inside the tool.
725
- listSkills: async () => skillList?.call(skillDomain),
726
- ...(permissionAssert === undefined ? {} : { permissionAssert }),
727
- }
728
- }
762
+ // The setup flow threads the ONE runtime instance it built (shared with
763
+ // the J1 observer in the execute.before hook); this local fallback keeps a
764
+ // direct registration call self-sufficient.
765
+ const runtime = jevRuntime ?? (jevReady ? buildV2JevRuntime(host) : undefined)
729
766
  // P3 (complexity) declares `tool.invoke`; its construction site is the
730
767
  // local selector's execute, fed by that tool's own input schema. The sink
731
768
  // is the 0b record path (in-memory, bounded, I/O-free) and every record
@@ -739,7 +776,7 @@ async function registerV2Tools(
739
776
  p3Sink.emit({ ...record, mode: 'shadow' })
740
777
  },
741
778
  },
742
- jevRuntime,
779
+ runtime,
743
780
  )
744
781
  if (boundedRead !== undefined) toolDefs.push(boundedRead)
745
782
 
@@ -894,6 +931,65 @@ export function getP11TelemetrySinkForTests(): TelemetrySink | undefined {
894
931
 
895
932
  let p11TelemetrySink: TelemetrySink | undefined
896
933
 
934
+ /**
935
+ * The J1 risk-score telemetry sink created by the most recent tool-hook
936
+ * registration.
937
+ *
938
+ * J1 (the risk-score advisory gate, `jev-risk-gate.ts`) is NOT a registry
939
+ * point: it is a flag-gated shadow observer on write/execute tool calls. The
940
+ * sink exists only when `PANTHEON_J1_RISK_SCORE` is on AND the host runtime
941
+ * exposes the native Decisions API, so flag-off leaves it undefined — the
942
+ * zero-overhead contract. Records go through the in-memory, bounded 0b path
943
+ * (`createTelemetrySink`, no I/O) and carry `mode: 'shadow'`; the observer is
944
+ * fire-and-observe, so the tool call never waits on it. Exported only for
945
+ * tests/pantheon/plugin-v2-contract.test.ts.
946
+ */
947
+ export function getJ1TelemetrySinkForTests(): TelemetrySink | undefined {
948
+ return j1TelemetrySink
949
+ }
950
+
951
+ let j1TelemetrySink: TelemetrySink | undefined
952
+
953
+ /**
954
+ * The J3 turn-complexity escalation telemetry sink created by the most recent
955
+ * tool-hook registration.
956
+ *
957
+ * J3 (the escalation shadow classifier, `jev-escalation.ts`) is NOT a registry
958
+ * point: it is a flag-gated shadow observer on delegate dispatches (the native
959
+ * `subagent` tool). The sink exists only when `PANTHEON_J3_ESCALATION` is on
960
+ * AND the host runtime exposes the native Decisions API, so flag-off leaves it
961
+ * undefined — the zero-overhead contract. Records go through the in-memory,
962
+ * bounded 0b path (`createTelemetrySink`, no I/O) and carry `mode: 'shadow'`;
963
+ * the observer is fire-and-observe, so the dispatch never waits on it. The
964
+ * recorded verdict never changes the dispatched model: the override mechanism
965
+ * for the activation step lives in `jev-escalation.ts` and is unreachable from
966
+ * this wiring. Exported only for tests/pantheon/plugin-v2-contract.test.ts.
967
+ */
968
+ export function getJ3TelemetrySinkForTests(): TelemetrySink | undefined {
969
+ return j3TelemetrySink
970
+ }
971
+
972
+ let j3TelemetrySink: TelemetrySink | undefined
973
+
974
+ /**
975
+ * The J4 output-quality review telemetry sink created by the most recent Jev
976
+ * runtime build.
977
+ *
978
+ * J4 (the review mode of `pantheon_jev_decide`, `jev-quality-score.ts`) is
979
+ * NOT a registry point and has no flag: the review runs only when Zeus
980
+ * explicitly requests it, and the record (`point: 'J4'`, `mode: 'shadow'`,
981
+ * `effect: 'none'`, reason token `q-<n>-review-<yes|no|na>` or a `skip-…`
982
+ * token) is the whole effect — advisory, never read back by the tool path.
983
+ * The sink is created inside `buildV2JevRuntime`, so it exists exactly when
984
+ * the runtime (and with it the tool) exists. Exported only for
985
+ * tests/pantheon/plugin-v2-contract.test.ts.
986
+ */
987
+ export function getJ4TelemetrySinkForTests(): TelemetrySink | undefined {
988
+ return j4TelemetrySink
989
+ }
990
+
991
+ let j4TelemetrySink: TelemetrySink | undefined
992
+
897
993
  /**
898
994
  * Attempt to subscribe to session events via V2 ctx.event.subscribe.
899
995
  *
@@ -1856,6 +1952,7 @@ async function registerV2ToolHooks(
1856
1952
  context: PluginContext,
1857
1953
  subagentOrigins: V2SubagentOriginRegistry,
1858
1954
  boundedReadOrigins?: V2BoundedReadOriginRegistry,
1955
+ jevRuntime?: V2JevDecisionRuntime,
1859
1956
  ): Promise<{ registered: boolean; beforeRegistered: boolean }> {
1860
1957
  const host = hostDomains(context)
1861
1958
  const toolCtx = host.tool
@@ -1872,6 +1969,51 @@ async function registerV2ToolHooks(
1872
1969
  onUnkeyed: appendV2HookLog,
1873
1970
  })
1874
1971
 
1972
+ // J1 risk-score advisory gate (jev-risk-gate.ts). Constructed ONLY when
1973
+ // PANTHEON_J1_RISK_SCORE is on AND the host runtime exposes the native
1974
+ // Decisions API (the same instance `pantheon_jev_decide` uses), so flag-off
1975
+ // is a hard zero: no sink, no observer, no per-call work. When enabled, the
1976
+ // observer runs the SAME gate chain as the explicit tool (config, consent,
1977
+ // ledger reservation, permission kill-switch) and records shadow records
1978
+ // only — it is fired WITHOUT await inside the before-handler (fire-and-
1979
+ // observe), self-bounds at 2s with an AbortController, and never retries.
1980
+ let j1Observer: ((event: unknown) => Promise<void>) | undefined
1981
+ if (jevRuntime !== undefined && j1RiskGateEnabledFromEnv()) {
1982
+ const j1Sink = createTelemetrySink()
1983
+ j1TelemetrySink = j1Sink
1984
+ j1Observer = createJ1RiskGateObserver({
1985
+ runtime: jevRuntime,
1986
+ sink: (record) => {
1987
+ j1Sink.emit({ ...record, mode: 'shadow' })
1988
+ },
1989
+ })
1990
+ }
1991
+
1992
+ // J3 turn-complexity escalation (jev-escalation.ts) — SHADOW. Constructed
1993
+ // ONLY when PANTHEON_J3_ESCALATION is on AND the host runtime exposes the
1994
+ // native Decisions API (the same instance `pantheon_jev_decide` uses), so
1995
+ // flag-off is a hard zero: no sink, no observer, no per-dispatch work. When
1996
+ // enabled, the observer classifies ONE delegate dispatch (the native
1997
+ // `subagent` tool) through the SAME gate chain as the explicit tool and
1998
+ // records shadow records only — fired WITHOUT await inside the before-
1999
+ // handler (fire-and-observe), self-bounded at 2s with an AbortController,
2000
+ // never retried. The verdict NEVER changes the dispatched model in this
2001
+ // phase: the per-agent override mechanism for activation lives in
2002
+ // jev-escalation.ts and this wiring has no path to it (asserted
2003
+ // structurally by the contract test below — the override function's name
2004
+ // must not appear in this file at all).
2005
+ let j3Observer: ((event: unknown) => Promise<void>) | undefined
2006
+ if (jevRuntime !== undefined && j3EscalationEnabledFromEnv()) {
2007
+ const j3Sink = createTelemetrySink()
2008
+ j3TelemetrySink = j3Sink
2009
+ j3Observer = createJ3EscalationObserver({
2010
+ runtime: jevRuntime,
2011
+ sink: (record) => {
2012
+ j3Sink.emit({ ...record, mode: 'shadow' })
2013
+ },
2014
+ })
2015
+ }
2016
+
1875
2017
  // Symlink resolution for the Zeus read guard (#272). The predicate is pure,
1876
2018
  // so the filesystem work happens at this call site, rooted at the project
1877
2019
  // directory the host reports. Same mechanism as V1's (src/plugin.ts) so the
@@ -1987,6 +2129,26 @@ async function registerV2ToolHooks(
1987
2129
  if (origin !== undefined) {
1988
2130
  writeV2AdmissionProof('tool.execute.before', { ...origin })
1989
2131
  }
2132
+ // J1 risk-score shadow observation. Deliberately AFTER every guard: a
2133
+ // denied call must not spend decision budget. Fire-and-observe — the
2134
+ // promise is deliberately NOT awaited, so the hook's latency is
2135
+ // unchanged; the observer self-bounds at 2s (AbortController),
2136
+ // contains its own failures, records at most one shadow record per
2137
+ // event, and never blocks, retries, or queues. Undefined (no-op) when
2138
+ // the flag is off — the only cost of the flag-on check below is the
2139
+ // truthiness read.
2140
+ if (j1Observer !== undefined && isRiskGateTarget((event as { tool?: unknown }).tool)) {
2141
+ void j1Observer(event)
2142
+ }
2143
+ // J3 turn-complexity shadow classification. Same fire-and-observe
2144
+ // discipline as J1: the dispatch's latency is unchanged, the observer
2145
+ // self-bounds at 2s, contains its own failures, records at most one
2146
+ // shadow record per dispatch, and never blocks, retries, or queues.
2147
+ // The recorded verdict NEVER changes the dispatched model (shadow
2148
+ // contract); undefined (no-op) when the flag is off.
2149
+ if (j3Observer !== undefined && isSubagentDispatchEvent(event)) {
2150
+ void j3Observer(event)
2151
+ }
1990
2152
  // Delegation audit START record (#266). Deliberately AFTER every guard
1991
2153
  // and the secret scan: a denied call must not leave a start record with
1992
2154
  // no matching stop. The formatter/stop halves run in `execute.after`.
@@ -2489,10 +2651,17 @@ export const plugin = define({
2489
2651
  }
2490
2652
 
2491
2653
  // ─── Phase 5: V2 Tool Hooks (best-effort) ────────────────────────
2654
+ // The Jev runtime is built ONCE here and threaded to both consumers — the
2655
+ // tool registration (Phase 6) and the J1 risk-score observer inside the
2656
+ // execute.before hook — so `decide` and `permissionAssert` are bound to
2657
+ // their owning host domains exactly once. Pure construction over the host
2658
+ // domains: nothing is marked unsupported here; Phase 6 keeps that job.
2659
+ const jevRuntime = buildV2JevRuntime(hostDomains(context))
2492
2660
  const toolHookResult = await registerV2ToolHooks(
2493
2661
  context,
2494
2662
  subagentOrigins,
2495
2663
  boundedRead?.origins,
2664
+ jevRuntime,
2496
2665
  ).catch(() => ({ registered: false, beforeRegistered: false }))
2497
2666
  if (!toolHookResult.registered) {
2498
2667
  markUnsupported('tool-execute-hooks')
@@ -2505,7 +2674,9 @@ export const plugin = define({
2505
2674
  if (boundedRead !== undefined && boundedReadDefinition === undefined) {
2506
2675
  markUnsupported('bounded-read')
2507
2676
  }
2508
- const toolsRegistered = await registerV2Tools(context, boundedReadDefinition).catch(() => false)
2677
+ const toolsRegistered = await registerV2Tools(context, boundedReadDefinition, jevRuntime).catch(
2678
+ () => false,
2679
+ )
2509
2680
  if (!toolsRegistered) markUnsupported('tool-transform')
2510
2681
 
2511
2682
  // ─── Phase 7: V2 Compaction Hook (best-effort) ───────────────────
@@ -3197,7 +3197,7 @@ function Sidebar(props) {
3197
3197
  setProp(_el$12, "width", "100%");
3198
3198
  setProp(_el$12, "padding", 1);
3199
3199
  setProp(_el$13, "attributes", 1);
3200
- insert(_el$13, `Pantheon v1.6.2-beta.15`);
3200
+ insert(_el$13, `Pantheon v1.6.2-beta.17`);
3201
3201
  insert(_el$14, () => presetHeaderLine(model.preset().name ?? "", model.provider()));
3202
3202
  insert(_el$12, createComponent(Show, {
3203
3203
  get when() {
@@ -3918,7 +3918,7 @@ function HomeStatus(props) {
3918
3918
  const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
3919
3919
  return (() => {
3920
3920
  var _el$72 = createElement("text");
3921
- insert(_el$72, () => `Pantheon v1.6.2-beta.15${preset().name ? ` ▸ ${preset().name}` : ""}`);
3921
+ insert(_el$72, () => `Pantheon v1.6.2-beta.17${preset().name ? ` ▸ ${preset().name}` : ""}`);
3922
3922
  effect((_$p) => setProp(_el$72, "fg", muted(), _$p));
3923
3923
  return _el$72;
3924
3924
  })();
@@ -167,7 +167,7 @@ async function detectVersion(api) {
167
167
  if (ver) return ver;
168
168
  }
169
169
  } catch {}
170
- return "1.6.2-beta.15";
170
+ return "1.6.2-beta.17";
171
171
  }
172
172
  /**
173
173
  * usage-bar — AI subscription usage gauge for the opencode TUI.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
- "version": "1.6.2-beta.15",
3
+ "version": "1.6.2-beta.17",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pantheon-tui",
9
- "version": "1.6.2-beta.15",
9
+ "version": "1.6.2-beta.17",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@opencode-ai/plugin": "1.18.33",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
3
  "type": "module",
4
- "version": "1.6.2-beta.15",
4
+ "version": "1.6.2-beta.17",
5
5
  "description": "Pantheon TUI plugin — V1 rich sidebar and usage gauges; native V2 status, session and delegation sidebar",
6
6
  "license": "MIT",
7
7
  "engines": {