pantheon-opencode 1.6.2-beta.4 → 1.6.2-beta.6

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 (65) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +202 -29
  3. package/README.pt-BR.md +9 -0
  4. package/bin/pantheon-init.mjs +6 -1
  5. package/package.json +2 -1
  6. package/plugin.json +1 -1
  7. package/pyproject.toml +1 -1
  8. package/scripts/decision-router-budget.mjs +7 -8
  9. package/scripts/decision-router-v2-budget.mjs +218 -0
  10. package/scripts/decision-router-v2-egress.mjs +272 -0
  11. package/scripts/decision-router.mjs +268 -46
  12. package/scripts/docs-check-changelog.mjs +5 -3
  13. package/scripts/install/decision-layer-preview.mjs +376 -0
  14. package/scripts/install/decision-router-config.mjs +162 -34
  15. package/scripts/mcp_resources.py +11 -9
  16. package/scripts/release-notes.mjs +30 -7
  17. package/scripts/versioning.mjs +41 -5
  18. package/src/mcp/eval_store.py +11 -4
  19. package/src/mcp/mcp_resources.py +11 -9
  20. package/src/mcp/memory_mcp.py +293 -150
  21. package/src/pantheon/jev-decision-tool.ts +336 -0
  22. package/src/pantheon/jev-decisions.ts +625 -0
  23. package/src/pantheon/local-decision-budget.ts +4 -1
  24. package/src/pantheon/local-decision-egress-gate.ts +16 -136
  25. package/src/pantheon/local-decision-prompt.ts +184 -45
  26. package/src/pantheon/local-decision-provider-matrix.ts +14 -62
  27. package/src/pantheon/local-decision-skills.ts +115 -5
  28. package/src/pantheon/local-decision-tool.ts +35 -1
  29. package/src/pantheon/local-decision-turn.ts +15 -252
  30. package/src/pantheon/local-decision-usage-evidence.internal.ts +80 -119
  31. package/src/pantheon/v2-decision-budget.ts +456 -0
  32. package/src/pantheon/v2-decision-contracts.ts +300 -0
  33. package/src/pantheon/v2-decision-egress.ts +203 -0
  34. package/src/pantheon/v2-decision-events.ts +180 -0
  35. package/src/pantheon/v2-decision-heuristic.ts +121 -0
  36. package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
  37. package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
  38. package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
  39. package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
  40. package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
  41. package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
  42. package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
  43. package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
  44. package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
  45. package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
  46. package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
  47. package/src/pantheon/v2-decision-points.ts +242 -0
  48. package/src/pantheon/v2-decision-policy.ts +166 -0
  49. package/src/pantheon/v2-decision-premises.ts +146 -0
  50. package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
  51. package/src/pantheon/v2-decision-rank.ts +91 -0
  52. package/src/pantheon/v2-decision-registry.ts +391 -0
  53. package/src/pantheon/v2-decision-resource-ids.ts +127 -0
  54. package/src/pantheon/v2-decision-shadow.ts +123 -0
  55. package/src/pantheon/v2-decision-telemetry.ts +214 -0
  56. package/src/pantheon/v2-decision-verify.ts +51 -0
  57. package/src/pantheon/v2-native-decisions.ts +365 -0
  58. package/src/pantheon/v2-tools.ts +24 -2
  59. package/src/plugin-v2.ts +360 -14
  60. package/src/plugins/tui/dist/tui-v2.js +3 -3
  61. package/src/plugins/tui/dist/tui.js +1 -1
  62. package/src/plugins/tui/package-lock.json +2 -2
  63. package/src/plugins/tui/package.json +1 -1
  64. package/src/pantheon/local-decision-provider-protocol.ts +0 -335
  65. package/src/pantheon/local-decision-provider.internal.ts +0 -260
package/src/plugin-v2.ts CHANGED
@@ -73,6 +73,11 @@
73
73
  * If the SDK ever exposes these host domains, replacing `hostDomains` with the real
74
74
  * type is a one-line change. Do NOT make that change while 1.18.x lacks them.
75
75
  *
76
+ * The separate offline native Decisions scaffold is typed against
77
+ * `@opencode/plugin@2.2.5`. It intentionally has no production call site and
78
+ * does not claim native Decisions support for V1 or OpenCode V2.0/2.1. The
79
+ * legacy plugin registrations are not migrated as part of that scaffold.
80
+ *
76
81
  * V2_UNSUPPORTED_FEATURES distinguishes adapter limitations from observed
77
82
  * host-absent APIs; setup handles optional registrations on a best-effort basis.
78
83
  *
@@ -110,6 +115,7 @@ import {
110
115
  } from './pantheon/delegation-enforce.ts'
111
116
  import { GOAL_LOOP_DEFAULTS, GoalStore } from './pantheon/goal-loop.ts'
112
117
  import { createGuardPathResolver } from './pantheon/guard-path.ts'
118
+ import type { V2JevDecisionRuntime } from './pantheon/jev-decision-tool.ts'
113
119
  import { DECISION_EGRESS_ACTION } from './pantheon/local-decision-egress-gate.ts'
114
120
  import { applyDecisionRouterToPrompt } from './pantheon/local-decision-prompt.ts'
115
121
  import { getSharedBoard } from './pantheon/shared-board.ts'
@@ -136,6 +142,16 @@ import {
136
142
  registerV2Bridge,
137
143
  type V2ContextLike,
138
144
  } from './pantheon/v2-bridge.ts'
145
+ import { createP7LoopPoint, p7LoopEnabledFromEnv } from './pantheon/v2-decision-points/p7-loop.ts'
146
+ import {
147
+ createP8Guardrail,
148
+ p8GuardrailEnabledFromEnv,
149
+ } from './pantheon/v2-decision-points/p8-guardrail.ts'
150
+ import { evaluateCompactionMemoryPoint } from './pantheon/v2-decision-points/p9-memory-compaction.ts'
151
+ import { evaluateCatalogPoint } from './pantheon/v2-decision-points/p11-catalog.ts'
152
+ import { DECISION_POINT_REGISTRY } from './pantheon/v2-decision-points.ts'
153
+ import { observePromptSurface } from './pantheon/v2-decision-prompt-surface.ts'
154
+ import { createTelemetrySink, type TelemetrySink } from './pantheon/v2-decision-telemetry.ts'
139
155
  import {
140
156
  type AuthoritativeSession,
141
157
  evaluateV2Delegation,
@@ -146,6 +162,7 @@ import {
146
162
  } from './pantheon/v2-delegation-enforce.ts'
147
163
  import { createV2ExecuteAfter, resolveV2SandboxConfig } from './pantheon/v2-execute-after.ts'
148
164
  import { applyV2ModelOverrides, readV2ModelConfiguration } from './pantheon/v2-model-overrides.ts'
165
+ import type { NativeDecisionRequest } from './pantheon/v2-native-decisions.ts'
149
166
  import { createV2ShellHooks, type V2ShellRunner } from './pantheon/v2-shell-hooks.ts'
150
167
  import { createV2ToolDefinitions, type V2ToolResult } from './pantheon/v2-tools.ts'
151
168
  import { V2_UNSUPPORTED_FEATURE_SEED } from './pantheon/v2-unsupported.mjs'
@@ -341,6 +358,16 @@ interface V2GenerateDomain {
341
358
  text?: (input: { model: { providerID: string; id: string }; prompt: string }) => Promise<unknown>
342
359
  }
343
360
 
361
+ /**
362
+ * The host's experimental generation domain. Only `decisions` is declared: the
363
+ * native Jev route feature-detects it, and every other member stays unknown.
364
+ */
365
+ interface V2ExperimentalDomain {
366
+ generate?: {
367
+ decisions?: (request: NativeDecisionRequest) => Promise<unknown>
368
+ }
369
+ }
370
+
344
371
  /** `PluginContext` plus the host domains 1.18.x omits. See the module header. */
345
372
  interface HostPluginContext extends PluginContext {
346
373
  tool?: V2ToolDomain
@@ -349,6 +376,7 @@ interface HostPluginContext extends PluginContext {
349
376
  session?: V2SessionDomain
350
377
  model?: V2ModelDomain
351
378
  generate?: V2GenerateDomain
379
+ experimental?: V2ExperimentalDomain
352
380
  location?: V2LocationDomain
353
381
  }
354
382
 
@@ -659,12 +687,59 @@ async function registerV2Tools(
659
687
  // it, and the host rejects a definition whose result shape cannot satisfy
660
688
  // the declaration it makes.
661
689
  const model = host.model
662
- const visionReady = typeof model?.list === 'function'
690
+ const modelListFn = model?.list
691
+ const visionReady = typeof modelListFn === 'function'
663
692
  if (!visionReady) markUnsupported('vision-tool')
664
693
  const visionRuntime = visionReady ? ({ model } as V2VisionRuntime) : undefined
665
- const toolDefs = createV2ToolDefinitions(visionRuntime)
694
+ // The native Jev tool needs BOTH the V2 model catalog (route resolution)
695
+ // and the host's native Decisions API. A host without either simply does
696
+ // not get the tool — same feature-detect discipline as vision_describe.
697
+ const decisionsFn = host.experimental?.generate?.decisions
698
+ const jevReady = visionReady && typeof decisionsFn === 'function'
699
+ if (!jevReady) markUnsupported('jev-decision-tool')
700
+ const permissionAssertFn = host.permission?.assert
701
+ let jevRuntime: V2JevDecisionRuntime | undefined
702
+ if (jevReady && typeof decisionsFn === 'function' && typeof modelListFn === 'function') {
703
+ const decide = decisionsFn
704
+ const listModels = modelListFn
705
+ // The 2.2.5 host exposes ctx.skill as the SkillEditor (list()); the SDK
706
+ // types this file sees declare skill as the registration hook, so the
707
+ // runtime shape is read through one narrow, feature-detected cast.
708
+ const skillList = (host as { skill?: { list?: () => unknown } }).skill?.list
709
+ const permissionAssert =
710
+ typeof permissionAssertFn === 'function'
711
+ ? (input: Record<string, unknown>) => permissionAssertFn.call(host.permission, input)
712
+ : undefined
713
+ jevRuntime = {
714
+ listModels: () => listModels(),
715
+ decide: (request: NativeDecisionRequest) => decide(request),
716
+ // Sync-or-async host skill list; absent/throwing falls back to the
717
+ // catalog-only preset inside the tool.
718
+ listSkills: async () => skillList?.(),
719
+ ...(permissionAssert === undefined ? {} : { permissionAssert }),
720
+ }
721
+ }
722
+ // P3 (complexity) declares `tool.invoke`; its construction site is the
723
+ // local selector's execute, fed by that tool's own input schema. The sink
724
+ // is the 0b record path (in-memory, bounded, I/O-free) and every record
725
+ // carries `mode: 'shadow'` — the mode the registry declares.
726
+ const p3Sink = createTelemetrySink()
727
+ p3TelemetrySink = p3Sink
728
+ const toolDefs = createV2ToolDefinitions(
729
+ visionRuntime,
730
+ {
731
+ complexitySink: (record) => {
732
+ p3Sink.emit({ ...record, mode: 'shadow' })
733
+ },
734
+ },
735
+ jevRuntime,
736
+ )
666
737
  if (boundedRead !== undefined) toolDefs.push(boundedRead)
667
738
 
739
+ // P11's record sink, created per registration (in-memory, bounded, I/O-free).
740
+ const p11Sink = createTelemetrySink()
741
+ p11TelemetrySink = p11Sink
742
+
668
743
  await toolCtx.transform((draft: V2ToolDraft) => {
669
744
  // Catalog grouping only. The host computes a tool's registration id as
670
745
  // `options.namespace === undefined ? name : `${namespace}_${name}``, and
@@ -686,6 +761,24 @@ async function registerV2Tools(
686
761
  execute: def.execute,
687
762
  })
688
763
  }
764
+
765
+ // P11 (catalog) shadow observation on the only measured catalogue
766
+ // surface: the draft the host hands this callback — `{list, get,
767
+ // namespace, add, update, remove}`, 20 host tools, 46 with MCP servers
768
+ // registered (F-07). `ctx.catalog` is absent at every measured point
769
+ // (F-05) and is not used. The adapter reads and nothing else: `list()` is
770
+ // called, the six members are type-checked, and no add/update/remove is
771
+ // ever invoked, so the registration above is the only mutation. Shadow
772
+ // has no responder, so the record names the validated `choice` question
773
+ // (`catalog.no.answer`) instead of inventing a selection. Runs after the
774
+ // adds so the draft it reads is the one the host will keep.
775
+ try {
776
+ evaluateCatalogPoint(draft, (record) => {
777
+ p11Sink.emit({ ...record, mode: 'shadow' })
778
+ })
779
+ } catch {
780
+ // Observation must never fail the tool registration.
781
+ }
689
782
  })
690
783
  return true
691
784
  } catch {
@@ -695,6 +788,105 @@ async function registerV2Tools(
695
788
 
696
789
  // ─── V2 Event Subscription ──────────────────────────────────────────────
697
790
 
791
+ /**
792
+ * The P7 telemetry sink created by the most recent event subscription.
793
+ *
794
+ * P7 writes through the 0b record path (`createTelemetrySink`): in-memory,
795
+ * bounded and I/O-free by design, so a test that asserts "the decision was
796
+ * actually recorded" has to read the same collector the wiring wrote to.
797
+ * Exported only for tests/pantheon/plugin-v2-contract.test.ts — production has
798
+ * no caller, and nothing in the plugin reads this back.
799
+ */
800
+ export function getP7TelemetrySinkForTests(): TelemetrySink | undefined {
801
+ return p7TelemetrySink
802
+ }
803
+
804
+ let p7TelemetrySink: TelemetrySink | undefined
805
+
806
+ /**
807
+ * The P8 telemetry sink created by the most recent permission-hook
808
+ * registration.
809
+ *
810
+ * P8 records every outcome it is responsible for — `guardrail.narrow`,
811
+ * `guardrail.keep`, `guardrail.refusal`, `p8.write.rejected`,
812
+ * `p8.write.delegation` and `p8.write.unconfirmed` — through the 0b record path
813
+ * (`createTelemetrySink`, in-memory, bounded, I/O-free). A guardrail that
814
+ * narrows without a record is indistinguishable from an inert one, which is
815
+ * exactly the defect PH5-1 closed. Every record carries the P8 registry `mode`
816
+ * (`off`), never `active`, and a `narrow` is recorded only when a re-read of
817
+ * the event still holds it (N9/N10). Exported only for
818
+ * tests/pantheon/plugin-v2-contract.test.ts.
819
+ */
820
+ export function getP8TelemetrySinkForTests(): TelemetrySink | undefined {
821
+ return p8TelemetrySink
822
+ }
823
+
824
+ let p8TelemetrySink: TelemetrySink | undefined
825
+
826
+ /**
827
+ * The prompt-surface telemetry sink created by the most recent prompt-hook
828
+ * registration.
829
+ *
830
+ * P1 and P2 observe the same admission payload through `observePromptSurface`;
831
+ * each shadow record is reduced through the 0b record path
832
+ * (`createTelemetrySink`, in-memory, bounded, I/O-free) and carries
833
+ * `mode: 'shadow'` — the registry mode both declare. Nothing in production
834
+ * reads this collector back, so the write is only a claim if a reader can
835
+ * assert it: this accessor is that reader, and
836
+ * tests/pantheon/plugin-v2-contract.test.ts is its only caller.
837
+ */
838
+ export function getPromptSurfaceTelemetrySinkForTests(): TelemetrySink | undefined {
839
+ return promptSurfaceTelemetrySink
840
+ }
841
+
842
+ let promptSurfaceTelemetrySink: TelemetrySink | undefined
843
+
844
+ /**
845
+ * The P3 telemetry sink created by the most recent tool registration.
846
+ *
847
+ * P3 is constructed at `tool.invoke`: `pantheon_local_decision`'s execute calls
848
+ * the adapter with the tool input, which carries `complexity` and `gateStatus`.
849
+ * Records are reduced through the same in-memory 0b path and carry the P3
850
+ * registry `mode` (`shadow`). Exported only for
851
+ * tests/pantheon/plugin-v2-contract.test.ts and the wiring audit.
852
+ */
853
+ export function getP3TelemetrySinkForTests(): TelemetrySink | undefined {
854
+ return p3TelemetrySink
855
+ }
856
+
857
+ let p3TelemetrySink: TelemetrySink | undefined
858
+
859
+ /**
860
+ * The P9 telemetry sink created by the most recent compaction-hook
861
+ * registration.
862
+ *
863
+ * P9 declares `session.hook('compaction')` and observes the MEASURED carrier
864
+ * only: the top-level `sessionID` and the `system` part array (F-01, F-02).
865
+ * Records go through the same in-memory, bounded 0b path and carry the P9
866
+ * registry `mode` (`shadow`). Exported only for
867
+ * tests/pantheon/plugin-v2-contract.test.ts and the wiring audit.
868
+ */
869
+ export function getP9TelemetrySinkForTests(): TelemetrySink | undefined {
870
+ return p9TelemetrySink
871
+ }
872
+
873
+ let p9TelemetrySink: TelemetrySink | undefined
874
+
875
+ /**
876
+ * The P11 telemetry sink created by the most recent tool registration.
877
+ *
878
+ * P11 declares `tool.transform` and reads the draft the host hands that
879
+ * callback (F-07) — the only measured catalogue surface, since `ctx.catalog` is
880
+ * absent (F-05). Records go through the in-memory, bounded 0b path and carry the
881
+ * P11 registry `mode` (`shadow`). Exported only for
882
+ * tests/pantheon/plugin-v2-contract.test.ts and the wiring audit.
883
+ */
884
+ export function getP11TelemetrySinkForTests(): TelemetrySink | undefined {
885
+ return p11TelemetrySink
886
+ }
887
+
888
+ let p11TelemetrySink: TelemetrySink | undefined
889
+
698
890
  /**
699
891
  * Attempt to subscribe to session events via V2 ctx.event.subscribe.
700
892
  *
@@ -713,12 +905,45 @@ function subscribeV2Events(
713
905
  return undefined
714
906
  }
715
907
 
908
+ // P7 loop adapter (PLAN §5.1 branch 1, selected by PROBE-D §7). Constructed
909
+ // here but inert unless PANTHEON_V2_P7_LOOP is set: the flag is OFF by
910
+ // default, and activation is Phase 4b — not this change. Observation is
911
+ // synchronous and self-contained, so it cannot block the stream, cannot
912
+ // throw into the dispatch, and does not alter the cleanup below.
913
+ //
914
+ // The sink is the 0b telemetry record path (`createTelemetrySink`, in-memory
915
+ // and bounded, no I/O). Each shadow record is reduced to its own allowlisted
916
+ // fields plus `mode: 'migration'` — the P7 registry mode — and nothing else:
917
+ // the execution count is not on the allowlist, so it is not recorded, and no
918
+ // prompt, response or user content can reach the record. A disabled adapter
919
+ // never calls the sink, so flag-off still emits zero records.
920
+ const telemetrySink = createTelemetrySink()
921
+ p7TelemetrySink = telemetrySink
922
+ const loopPoint = createP7LoopPoint({
923
+ enabled: p7LoopEnabledFromEnv(),
924
+ sink: (record) => {
925
+ telemetrySink.emit({ ...record, mode: 'migration' })
926
+ },
927
+ })
928
+
716
929
  const controller = new AbortController()
717
930
  void (async () => {
718
931
  try {
719
932
  // biome-ignore lint/style/noNonNullAssertion: subscribe guaranteed by guard above
720
933
  for await (const event of eventCtx.subscribe!({ signal: controller.signal })) {
721
934
  await handleV2SessionEvent(event)
935
+ try {
936
+ loopPoint.observe(event)
937
+ } catch {
938
+ // The adapter contains its own failures; this keeps a future
939
+ // regression out of the dispatch loop.
940
+ }
941
+ // KNOWN DEFECT, out of scope for Phase 4a: this branch and
942
+ // `handleV2SessionEvent`'s `session.compacted` case key on types the
943
+ // measured host never delivers — `session.idle` 0/11 runs and
944
+ // `session.compacted` 0/11 (PROBE-C, F-12). The live turn-end signal
945
+ // is `session.execution.succeeded`, observed above. The branches are
946
+ // left untouched on purpose; removing them is a separate change.
722
947
  if (event.type === 'session.idle' || event.type === 'session.deleted') {
723
948
  const properties = event.properties ?? {}
724
949
  const info = properties.info
@@ -1030,12 +1255,6 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
1030
1255
  warnContextPrunerConfigOnce(context.options)
1031
1256
  const host = hostDomains(context)
1032
1257
  const sessionCtx = host.session
1033
- const permission = host.permission
1034
- const assertPermission = permission?.assert
1035
- const permissionAssert =
1036
- typeof assertPermission === 'function'
1037
- ? (input: Record<string, unknown>) => assertPermission.call(permission, input)
1038
- : undefined
1039
1258
 
1040
1259
  if (!sessionCtx?.hook) {
1041
1260
  return false
@@ -1124,6 +1343,13 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
1124
1343
  }
1125
1344
 
1126
1345
  try {
1346
+ // Prompt-surface shadow points (P1 and P2) share this payload. P3 moved to
1347
+ // `tool.invoke`, where its input actually carries a complexity vector; P6
1348
+ // and P10 are unwired because no measured surface carries their inputs.
1349
+ // The sink is in-memory and bounded, exactly like P7/P8; it is created per
1350
+ // registration so one setup cannot observe another's records.
1351
+ const promptSurfaceSink = createTelemetrySink()
1352
+ promptSurfaceTelemetrySink = promptSurfaceSink
1127
1353
  // "prompt" hook — preserve attached image references and add model-visible
1128
1354
  // instructions so Zeus can inspect visual context and pass it to the
1129
1355
  // implementation specialist before editing.
@@ -1150,10 +1376,18 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
1150
1376
  if (visualContext) prompt.text = `${prompt.text}\n\n${visualContext}`
1151
1377
  }
1152
1378
 
1153
- // Advisory per-turn selection. The helper reads only the prompt text
1154
- // captured before Pantheon's own visual context, and the router caches
1155
- // per session/message, so a repeated admission cannot call twice.
1156
- await applyDecisionRouterToPrompt(admission, permissionAssert, userRequest)
1379
+ // Local deterministic recommendations are advisory only. This path
1380
+ // never consults provider consent/credentials or invokes remote egress.
1381
+ await applyDecisionRouterToPrompt(admission, userRequest)
1382
+
1383
+ // Shadow observation only. The projection carries `prompt.agents` and
1384
+ // `prompt.skills` and nothing else, so no prompt text or file bytes
1385
+ // reach a record; observeShadow clones and freezes it, so admission is
1386
+ // not mutated. A failure here is contained by the outer catch and never
1387
+ // reaches the host.
1388
+ observePromptSurface(admission, (record) => {
1389
+ promptSurfaceSink.emit({ ...record, mode: 'shadow' })
1390
+ })
1157
1391
  } catch {
1158
1392
  // Fail-open: malformed/unsupported prompt shapes must not block input.
1159
1393
  }
@@ -1793,6 +2027,23 @@ async function registerV2ToolHooks(
1793
2027
 
1794
2028
  // ─── V2 Permission Hook ─────────────────────────────────────────────────
1795
2029
 
2030
+ /**
2031
+ * Read `event.effect` after P8 wrote to it, for the record.
2032
+ *
2033
+ * A hostile getter reads as `null`, which can only downgrade a recorded
2034
+ * `narrow` to `keep`, never upgrade one — the failure direction is "the record
2035
+ * claims less", never "the record claims an effect the event does not hold".
2036
+ */
2037
+ function readPermissionEffect(event: unknown): string | null {
2038
+ try {
2039
+ if (event === null || typeof event !== 'object') return null
2040
+ const effect = (event as { readonly effect?: unknown }).effect
2041
+ return typeof effect === 'string' ? effect : null
2042
+ } catch {
2043
+ return null
2044
+ }
2045
+ }
2046
+
1796
2047
  /**
1797
2048
  * Register permission hook via V2 ctx.permission.hook.
1798
2049
  *
@@ -1815,6 +2066,48 @@ async function registerV2PermissionHook(
1815
2066
  return false
1816
2067
  }
1817
2068
 
2069
+ // P8 guardrail (PLAN §5 P8, Phase 5). Constructed once at registration and
2070
+ // inert by default: `PANTHEON_V2_P8_GUARDRAIL` is absent in a default
2071
+ // install, and absent means disabled — this ships no behavioural change.
2072
+ // Enabled, it may only replace a wider effect with `deny`; it is synchronous,
2073
+ // never throws, and never runs for `decision.egress` or an existing deny.
2074
+ // Its outcome is recorded through the 0b telemetry path (in-memory, bounded,
2075
+ // I/O-free) so a narrow, a refusal and a rejected write are observable; the
2076
+ // disabled guardrail emits nothing.
2077
+ const p8Guardrail = createP8Guardrail({ enabled: p8GuardrailEnabledFromEnv() })
2078
+ const p8Sink = createTelemetrySink()
2079
+ p8TelemetrySink = p8Sink
2080
+ // The record's `mode` mirrors the P8 registry entry — `off` today — instead
2081
+ // of asserting `active` (N10a). A record may never advertise an activation
2082
+ // the registry and C8 deny, and deriving the value from the registry means
2083
+ // the two cannot drift apart again. `mode` describes the point's declared
2084
+ // mode; `decision`/`reason` carry the observation.
2085
+ const p8RegistryMode = DECISION_POINT_REGISTRY.find((point) => point.id === 'P8')?.mode ?? 'off'
2086
+ /**
2087
+ * Record one P8 outcome.
2088
+ *
2089
+ * `event` is re-read immediately before emitting: `narrowed`/`wrote` are the
2090
+ * guardrail's own post-write read, and a `Proxy` whose descriptor trap lies
2091
+ * can make that read and the next one disagree (N9). A `narrow` is therefore
2092
+ * recorded only when the event still holds `deny`; otherwise the record
2093
+ * states the effect that is actually there (`guardrail.keep` with
2094
+ * `p8.write.unconfirmed`), so sink and proof cannot contradict each other.
2095
+ */
2096
+ const recordP8 = (result: ReturnType<typeof p8Guardrail.apply>, event: unknown): void => {
2097
+ if (!p8Guardrail.enabled) return
2098
+ try {
2099
+ const unconfirmed = result.narrowed && readPermissionEffect(event) !== 'deny'
2100
+ p8Sink.emit({
2101
+ point: 'P8',
2102
+ decision: unconfirmed ? 'guardrail.keep' : result.decision,
2103
+ reason: unconfirmed ? 'p8.write.unconfirmed' : result.reason,
2104
+ mode: p8RegistryMode,
2105
+ })
2106
+ } catch {
2107
+ // Telemetry is best-effort and must not affect permission flow.
2108
+ }
2109
+ }
2110
+
1818
2111
  try {
1819
2112
  await permCtx.hook('evaluate', async (rawEvent: unknown) => {
1820
2113
  const event = rawEvent as V2PermissionEvent | null
@@ -1936,8 +2229,29 @@ async function registerV2PermissionHook(
1936
2229
  // Native-only resources remain under host policy. If a Pantheon target
1937
2230
  // appears anywhere, the shared policy evaluates the complete resource set.
1938
2231
  decision = evaluateV2Delegation(event, session, event.effect, origin)
1939
- if (decision === 'deny') deny('caller or target is not allowed by delegation policy')
1940
- else writeProof()
2232
+
2233
+ // P8 (Phase 5): read the effect left in place and, only when the flag is
2234
+ // on and a declared rule matches, replace it with `deny`. Off by default,
2235
+ // synchronous, contained — it cannot grant, delay or throw into admission.
2236
+ //
2237
+ // Apply BEFORE recording (PH5-1): `writeProof` reads `event.effect`, so a
2238
+ // proof written first recorded `effectAfter: allow` for an event P8 then
2239
+ // narrowed. The order below is apply → final effect → record, and the
2240
+ // record carries the post-apply effect plus the guardrail outcome.
2241
+ //
2242
+ // Record only after the effect is final (N10b). `deny()` below rewrites
2243
+ // the effect, and a record emitted before it would describe a state the
2244
+ // handler never leaves behind; when the delegation policy already denies,
2245
+ // the deny is the policy's, so P8 claims no narrowing at all — it changed
2246
+ // nothing about that outcome. `deny()` also throws on an immutable event,
2247
+ // and a record emitted after a throw would describe an unreached state.
2248
+ const p8Result = p8Guardrail.apply(event)
2249
+ if (decision === 'deny') {
2250
+ deny('caller or target is not allowed by delegation policy')
2251
+ return
2252
+ }
2253
+ writeProof()
2254
+ recordP8(p8Result, event)
1941
2255
  })
1942
2256
  return true
1943
2257
  } catch {
@@ -2187,6 +2501,10 @@ export const plugin = define({
2187
2501
  // active goals per session, and the store needs no host API (same
2188
2502
  // `.pantheon/goals` directory V1 uses).
2189
2503
  const goalStore = new GoalStore({ dir: '.pantheon/goals' })
2504
+ // P9's record sink, created per registration (in-memory, bounded,
2505
+ // I/O-free) so one setup cannot observe another's records.
2506
+ const p9Sink = createTelemetrySink()
2507
+ p9TelemetrySink = p9Sink
2190
2508
  try {
2191
2509
  // 2.0.16 `SessionHooks` key is `compaction` (the migration doc maps
2192
2510
  // `experimental.session.compacting` → `ctx.session.hook("compaction")`).
@@ -2235,6 +2553,34 @@ export const plugin = define({
2235
2553
  : typeof payload?.session?.id === 'string'
2236
2554
  ? payload.session.id
2237
2555
  : undefined
2556
+
2557
+ // P9 (compaction) shadow observation, on the MEASURED carrier only.
2558
+ // The 2.2.5 compaction payload carries a TOP-LEVEL `sessionID` and
2559
+ // no nested `session` object at all (PROBE-A, 11/11 runs), so the
2560
+ // event is handed to the adapter as-is and it reads
2561
+ // `payload.sessionID` — never `session.id`, which is absent there.
2562
+ // A payload that carries only a nested id therefore produces NO
2563
+ // decision (fail-closed) rather than being keyed by a carrier the
2564
+ // host was never observed to send. This runs BEFORE the pruner and
2565
+ // the context injection below, so `systemPartCount` describes the
2566
+ // host payload and not the blocks Pantheon appends; the adapter
2567
+ // clones what it reads and pushes nothing itself, so the injected
2568
+ // context is unchanged — shadow is the record, nothing else.
2569
+ // Child-session compaction is measured and needs no separate path:
2570
+ // PROBE-G §3.1 fired this hook on a real child 3/3 with the CHILD
2571
+ // sessionID at top level and the same payload shape (7 keys, no
2572
+ // nested `session`, `system` array of 4). Compaction with
2573
+ // `reason:"overflow"` was NOT inducible in 6 error shapes (PROBE-G
2574
+ // §3.2 — the host retried and completed, and the one
2575
+ // failure-recovery compaction was persisted as `reason:"auto"`), so
2576
+ // that path remains unmeasured and is not designed for here.
2577
+ try {
2578
+ evaluateCompactionMemoryPoint({ payload }, (record) => {
2579
+ p9Sink.emit({ ...record, mode: 'shadow' })
2580
+ })
2581
+ } catch {
2582
+ // Observation must never reach the compaction request.
2583
+ }
2238
2584
  const prunerConfig = resolveContextPrunerConfig(context.options)
2239
2585
  const stats = pruneMessages(payload?.messages, prunerConfig, 'compaction')
2240
2586
  logContextPrune(stats, sessionID)
@@ -5022,7 +5022,7 @@ function QuotaPluginDetails(props) {
5022
5022
  setProp(_el$58, "paddingTop", 1);
5023
5023
  insertNode(_el$59, createTextNode(`Plugin`));
5024
5024
  setProp(_el$59, "attributes", 1);
5025
- insert(_el$61, `Pantheon TUI v1.6.2-beta.4`);
5025
+ insert(_el$61, `Pantheon TUI v1.6.2-beta.6`);
5026
5026
  insertNode(_el$62, createTextNode(`Status de conexão consultado pelo OpenCode; segredos não são exibidos.`));
5027
5027
  insert(_el$64, () => `Status da quota: ${quotaSnapshotStatusLabel(props.snapshot.status, props.snapshot.error)}`);
5028
5028
  insert(_el$58, createComponent(Show, {
@@ -8300,7 +8300,7 @@ function Sidebar(props) {
8300
8300
  setProp(_el$12, "width", "100%");
8301
8301
  setProp(_el$12, "padding", 1);
8302
8302
  setProp(_el$13, "attributes", 1);
8303
- insert(_el$13, `Pantheon v1.6.2-beta.4`);
8303
+ insert(_el$13, `Pantheon v1.6.2-beta.6`);
8304
8304
  insert(_el$14, () => presetHeaderLine(model.preset().name ?? "", model.provider()));
8305
8305
  insert(_el$12, createComponent(Show, {
8306
8306
  get when() {
@@ -9027,7 +9027,7 @@ function HomeStatus(props) {
9027
9027
  const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
9028
9028
  return (() => {
9029
9029
  var _el$72 = createElement("text");
9030
- insert(_el$72, () => `Pantheon v1.6.2-beta.4${preset().name ? ` ▸ ${preset().name}` : ""}`);
9030
+ insert(_el$72, () => `Pantheon v1.6.2-beta.6${preset().name ? ` ▸ ${preset().name}` : ""}`);
9031
9031
  effect((_$p) => setProp(_el$72, "fg", muted(), _$p));
9032
9032
  return _el$72;
9033
9033
  })();
@@ -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.4";
170
+ return "1.6.2-beta.6";
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.4",
3
+ "version": "1.6.2-beta.6",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pantheon-tui",
9
- "version": "1.6.2-beta.4",
9
+ "version": "1.6.2-beta.6",
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.4",
4
+ "version": "1.6.2-beta.6",
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": {