pantheon-opencode 1.6.2-beta.3 → 1.6.2-beta.5
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/CHANGELOG.md +42 -0
- package/README.md +209 -1
- package/bin/pantheon-init.mjs +22 -0
- package/package.json +9 -3
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +781 -0
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +519 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +579 -0
- package/scripts/install/interactive.mjs +76 -5
- package/scripts/install/opencode.mjs +12 -0
- package/scripts/install/state.mjs +5 -0
- package/scripts/install/strings.mjs +4 -0
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/versioning.mjs +41 -5
- package/src/agents/zeus.md +12 -0
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1043 -0
- package/src/pantheon/local-decision-egress-gate.ts +264 -0
- package/src/pantheon/local-decision-prompt.ts +268 -0
- package/src/pantheon/local-decision-provider-matrix.ts +92 -0
- package/src/pantheon/local-decision-provider-protocol.ts +335 -0
- package/src/pantheon/local-decision-provider.internal.ts +260 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -0
- package/src/pantheon/local-decision-turn.ts +338 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +366 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-tools.ts +35 -15
- package/src/plugin-v2.ts +357 -22
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/dist/tui-v2.js +3 -3
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
package/src/plugin-v2.ts
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Pantheon V2 Plugin — full orchestration plugin for OpenCode V2.
|
|
3
3
|
*
|
|
4
4
|
* Registers:
|
|
5
|
-
* -
|
|
6
|
-
* pantheon_cost, pantheon_model) plus up to 2 host-dependent ones: native
|
|
5
|
+
* - 4 unconditional self-sufficient tools via V2 tool.transform (hashline_edit,
|
|
6
|
+
* pantheon_cost, pantheon_model, pantheon_local_decision) plus up to 2 host-dependent ones: native
|
|
7
7
|
* `vision_describe` when the host exposes the V2 model catalog (it resolves
|
|
8
8
|
* OpenCode Zen auth and sends images directly to the selected multimodal
|
|
9
9
|
* model), and `pantheon_bounded_read` when the host exposes its permission
|
|
10
10
|
* and session APIs (root Zeus sessions only).
|
|
11
|
+
* `pantheon_local_decision` is advisory and rejects execution unless the
|
|
12
|
+
* host tool context identifies the caller as Zeus.
|
|
11
13
|
* The goal tools need V1 infrastructure and are absent from this surface.
|
|
12
14
|
* - 5 event subscriptions (session.created, idle, deleted, error, compacted)
|
|
13
15
|
* - Session hooks (prompt, context, compaction)
|
|
@@ -108,6 +110,8 @@ import {
|
|
|
108
110
|
} from './pantheon/delegation-enforce.ts'
|
|
109
111
|
import { GOAL_LOOP_DEFAULTS, GoalStore } from './pantheon/goal-loop.ts'
|
|
110
112
|
import { createGuardPathResolver } from './pantheon/guard-path.ts'
|
|
113
|
+
import { DECISION_EGRESS_ACTION } from './pantheon/local-decision-egress-gate.ts'
|
|
114
|
+
import { applyDecisionRouterToPrompt } from './pantheon/local-decision-prompt.ts'
|
|
111
115
|
import { getSharedBoard } from './pantheon/shared-board.ts'
|
|
112
116
|
import {
|
|
113
117
|
TODO_ENFORCER_DEFAULTS,
|
|
@@ -132,6 +136,16 @@ import {
|
|
|
132
136
|
registerV2Bridge,
|
|
133
137
|
type V2ContextLike,
|
|
134
138
|
} from './pantheon/v2-bridge.ts'
|
|
139
|
+
import { createP7LoopPoint, p7LoopEnabledFromEnv } from './pantheon/v2-decision-points/p7-loop.ts'
|
|
140
|
+
import {
|
|
141
|
+
createP8Guardrail,
|
|
142
|
+
p8GuardrailEnabledFromEnv,
|
|
143
|
+
} from './pantheon/v2-decision-points/p8-guardrail.ts'
|
|
144
|
+
import { evaluateCompactionMemoryPoint } from './pantheon/v2-decision-points/p9-memory-compaction.ts'
|
|
145
|
+
import { evaluateCatalogPoint } from './pantheon/v2-decision-points/p11-catalog.ts'
|
|
146
|
+
import { DECISION_POINT_REGISTRY } from './pantheon/v2-decision-points.ts'
|
|
147
|
+
import { observePromptSurface } from './pantheon/v2-decision-prompt-surface.ts'
|
|
148
|
+
import { createTelemetrySink, type TelemetrySink } from './pantheon/v2-decision-telemetry.ts'
|
|
135
149
|
import {
|
|
136
150
|
type AuthoritativeSession,
|
|
137
151
|
evaluateV2Delegation,
|
|
@@ -658,9 +672,23 @@ async function registerV2Tools(
|
|
|
658
672
|
const visionReady = typeof model?.list === 'function'
|
|
659
673
|
if (!visionReady) markUnsupported('vision-tool')
|
|
660
674
|
const visionRuntime = visionReady ? ({ model } as V2VisionRuntime) : undefined
|
|
661
|
-
|
|
675
|
+
// P3 (complexity) declares `tool.invoke`; its construction site is the
|
|
676
|
+
// local selector's execute, fed by that tool's own input schema. The sink
|
|
677
|
+
// is the 0b record path (in-memory, bounded, I/O-free) and every record
|
|
678
|
+
// carries `mode: 'shadow'` — the mode the registry declares.
|
|
679
|
+
const p3Sink = createTelemetrySink()
|
|
680
|
+
p3TelemetrySink = p3Sink
|
|
681
|
+
const toolDefs = createV2ToolDefinitions(visionRuntime, {
|
|
682
|
+
complexitySink: (record) => {
|
|
683
|
+
p3Sink.emit({ ...record, mode: 'shadow' })
|
|
684
|
+
},
|
|
685
|
+
})
|
|
662
686
|
if (boundedRead !== undefined) toolDefs.push(boundedRead)
|
|
663
687
|
|
|
688
|
+
// P11's record sink, created per registration (in-memory, bounded, I/O-free).
|
|
689
|
+
const p11Sink = createTelemetrySink()
|
|
690
|
+
p11TelemetrySink = p11Sink
|
|
691
|
+
|
|
664
692
|
await toolCtx.transform((draft: V2ToolDraft) => {
|
|
665
693
|
// Catalog grouping only. The host computes a tool's registration id as
|
|
666
694
|
// `options.namespace === undefined ? name : `${namespace}_${name}``, and
|
|
@@ -682,6 +710,24 @@ async function registerV2Tools(
|
|
|
682
710
|
execute: def.execute,
|
|
683
711
|
})
|
|
684
712
|
}
|
|
713
|
+
|
|
714
|
+
// P11 (catalog) shadow observation on the only measured catalogue
|
|
715
|
+
// surface: the draft the host hands this callback — `{list, get,
|
|
716
|
+
// namespace, add, update, remove}`, 20 host tools, 46 with MCP servers
|
|
717
|
+
// registered (F-07). `ctx.catalog` is absent at every measured point
|
|
718
|
+
// (F-05) and is not used. The adapter reads and nothing else: `list()` is
|
|
719
|
+
// called, the six members are type-checked, and no add/update/remove is
|
|
720
|
+
// ever invoked, so the registration above is the only mutation. Shadow
|
|
721
|
+
// has no responder, so the record names the validated `choice` question
|
|
722
|
+
// (`catalog.no.answer`) instead of inventing a selection. Runs after the
|
|
723
|
+
// adds so the draft it reads is the one the host will keep.
|
|
724
|
+
try {
|
|
725
|
+
evaluateCatalogPoint(draft, (record) => {
|
|
726
|
+
p11Sink.emit({ ...record, mode: 'shadow' })
|
|
727
|
+
})
|
|
728
|
+
} catch {
|
|
729
|
+
// Observation must never fail the tool registration.
|
|
730
|
+
}
|
|
685
731
|
})
|
|
686
732
|
return true
|
|
687
733
|
} catch {
|
|
@@ -691,6 +737,105 @@ async function registerV2Tools(
|
|
|
691
737
|
|
|
692
738
|
// ─── V2 Event Subscription ──────────────────────────────────────────────
|
|
693
739
|
|
|
740
|
+
/**
|
|
741
|
+
* The P7 telemetry sink created by the most recent event subscription.
|
|
742
|
+
*
|
|
743
|
+
* P7 writes through the 0b record path (`createTelemetrySink`): in-memory,
|
|
744
|
+
* bounded and I/O-free by design, so a test that asserts "the decision was
|
|
745
|
+
* actually recorded" has to read the same collector the wiring wrote to.
|
|
746
|
+
* Exported only for tests/pantheon/plugin-v2-contract.test.ts — production has
|
|
747
|
+
* no caller, and nothing in the plugin reads this back.
|
|
748
|
+
*/
|
|
749
|
+
export function getP7TelemetrySinkForTests(): TelemetrySink | undefined {
|
|
750
|
+
return p7TelemetrySink
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
let p7TelemetrySink: TelemetrySink | undefined
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* The P8 telemetry sink created by the most recent permission-hook
|
|
757
|
+
* registration.
|
|
758
|
+
*
|
|
759
|
+
* P8 records every outcome it is responsible for — `guardrail.narrow`,
|
|
760
|
+
* `guardrail.keep`, `guardrail.refusal`, `p8.write.rejected`,
|
|
761
|
+
* `p8.write.delegation` and `p8.write.unconfirmed` — through the 0b record path
|
|
762
|
+
* (`createTelemetrySink`, in-memory, bounded, I/O-free). A guardrail that
|
|
763
|
+
* narrows without a record is indistinguishable from an inert one, which is
|
|
764
|
+
* exactly the defect PH5-1 closed. Every record carries the P8 registry `mode`
|
|
765
|
+
* (`off`), never `active`, and a `narrow` is recorded only when a re-read of
|
|
766
|
+
* the event still holds it (N9/N10). Exported only for
|
|
767
|
+
* tests/pantheon/plugin-v2-contract.test.ts.
|
|
768
|
+
*/
|
|
769
|
+
export function getP8TelemetrySinkForTests(): TelemetrySink | undefined {
|
|
770
|
+
return p8TelemetrySink
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
let p8TelemetrySink: TelemetrySink | undefined
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* The prompt-surface telemetry sink created by the most recent prompt-hook
|
|
777
|
+
* registration.
|
|
778
|
+
*
|
|
779
|
+
* P1 and P2 observe the same admission payload through `observePromptSurface`;
|
|
780
|
+
* each shadow record is reduced through the 0b record path
|
|
781
|
+
* (`createTelemetrySink`, in-memory, bounded, I/O-free) and carries
|
|
782
|
+
* `mode: 'shadow'` — the registry mode both declare. Nothing in production
|
|
783
|
+
* reads this collector back, so the write is only a claim if a reader can
|
|
784
|
+
* assert it: this accessor is that reader, and
|
|
785
|
+
* tests/pantheon/plugin-v2-contract.test.ts is its only caller.
|
|
786
|
+
*/
|
|
787
|
+
export function getPromptSurfaceTelemetrySinkForTests(): TelemetrySink | undefined {
|
|
788
|
+
return promptSurfaceTelemetrySink
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
let promptSurfaceTelemetrySink: TelemetrySink | undefined
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The P3 telemetry sink created by the most recent tool registration.
|
|
795
|
+
*
|
|
796
|
+
* P3 is constructed at `tool.invoke`: `pantheon_local_decision`'s execute calls
|
|
797
|
+
* the adapter with the tool input, which carries `complexity` and `gateStatus`.
|
|
798
|
+
* Records are reduced through the same in-memory 0b path and carry the P3
|
|
799
|
+
* registry `mode` (`shadow`). Exported only for
|
|
800
|
+
* tests/pantheon/plugin-v2-contract.test.ts and the wiring audit.
|
|
801
|
+
*/
|
|
802
|
+
export function getP3TelemetrySinkForTests(): TelemetrySink | undefined {
|
|
803
|
+
return p3TelemetrySink
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
let p3TelemetrySink: TelemetrySink | undefined
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* The P9 telemetry sink created by the most recent compaction-hook
|
|
810
|
+
* registration.
|
|
811
|
+
*
|
|
812
|
+
* P9 declares `session.hook('compaction')` and observes the MEASURED carrier
|
|
813
|
+
* only: the top-level `sessionID` and the `system` part array (F-01, F-02).
|
|
814
|
+
* Records go through the same in-memory, bounded 0b path and carry the P9
|
|
815
|
+
* registry `mode` (`shadow`). Exported only for
|
|
816
|
+
* tests/pantheon/plugin-v2-contract.test.ts and the wiring audit.
|
|
817
|
+
*/
|
|
818
|
+
export function getP9TelemetrySinkForTests(): TelemetrySink | undefined {
|
|
819
|
+
return p9TelemetrySink
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
let p9TelemetrySink: TelemetrySink | undefined
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* The P11 telemetry sink created by the most recent tool registration.
|
|
826
|
+
*
|
|
827
|
+
* P11 declares `tool.transform` and reads the draft the host hands that
|
|
828
|
+
* callback (F-07) — the only measured catalogue surface, since `ctx.catalog` is
|
|
829
|
+
* absent (F-05). Records go through the in-memory, bounded 0b path and carry the
|
|
830
|
+
* P11 registry `mode` (`shadow`). Exported only for
|
|
831
|
+
* tests/pantheon/plugin-v2-contract.test.ts and the wiring audit.
|
|
832
|
+
*/
|
|
833
|
+
export function getP11TelemetrySinkForTests(): TelemetrySink | undefined {
|
|
834
|
+
return p11TelemetrySink
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
let p11TelemetrySink: TelemetrySink | undefined
|
|
838
|
+
|
|
694
839
|
/**
|
|
695
840
|
* Attempt to subscribe to session events via V2 ctx.event.subscribe.
|
|
696
841
|
*
|
|
@@ -709,12 +854,45 @@ function subscribeV2Events(
|
|
|
709
854
|
return undefined
|
|
710
855
|
}
|
|
711
856
|
|
|
857
|
+
// P7 loop adapter (PLAN §5.1 branch 1, selected by PROBE-D §7). Constructed
|
|
858
|
+
// here but inert unless PANTHEON_V2_P7_LOOP is set: the flag is OFF by
|
|
859
|
+
// default, and activation is Phase 4b — not this change. Observation is
|
|
860
|
+
// synchronous and self-contained, so it cannot block the stream, cannot
|
|
861
|
+
// throw into the dispatch, and does not alter the cleanup below.
|
|
862
|
+
//
|
|
863
|
+
// The sink is the 0b telemetry record path (`createTelemetrySink`, in-memory
|
|
864
|
+
// and bounded, no I/O). Each shadow record is reduced to its own allowlisted
|
|
865
|
+
// fields plus `mode: 'migration'` — the P7 registry mode — and nothing else:
|
|
866
|
+
// the execution count is not on the allowlist, so it is not recorded, and no
|
|
867
|
+
// prompt, response or user content can reach the record. A disabled adapter
|
|
868
|
+
// never calls the sink, so flag-off still emits zero records.
|
|
869
|
+
const telemetrySink = createTelemetrySink()
|
|
870
|
+
p7TelemetrySink = telemetrySink
|
|
871
|
+
const loopPoint = createP7LoopPoint({
|
|
872
|
+
enabled: p7LoopEnabledFromEnv(),
|
|
873
|
+
sink: (record) => {
|
|
874
|
+
telemetrySink.emit({ ...record, mode: 'migration' })
|
|
875
|
+
},
|
|
876
|
+
})
|
|
877
|
+
|
|
712
878
|
const controller = new AbortController()
|
|
713
879
|
void (async () => {
|
|
714
880
|
try {
|
|
715
881
|
// biome-ignore lint/style/noNonNullAssertion: subscribe guaranteed by guard above
|
|
716
882
|
for await (const event of eventCtx.subscribe!({ signal: controller.signal })) {
|
|
717
883
|
await handleV2SessionEvent(event)
|
|
884
|
+
try {
|
|
885
|
+
loopPoint.observe(event)
|
|
886
|
+
} catch {
|
|
887
|
+
// The adapter contains its own failures; this keeps a future
|
|
888
|
+
// regression out of the dispatch loop.
|
|
889
|
+
}
|
|
890
|
+
// KNOWN DEFECT, out of scope for Phase 4a: this branch and
|
|
891
|
+
// `handleV2SessionEvent`'s `session.compacted` case key on types the
|
|
892
|
+
// measured host never delivers — `session.idle` 0/11 runs and
|
|
893
|
+
// `session.compacted` 0/11 (PROBE-C, F-12). The live turn-end signal
|
|
894
|
+
// is `session.execution.succeeded`, observed above. The branches are
|
|
895
|
+
// left untouched on purpose; removing them is a separate change.
|
|
718
896
|
if (event.type === 'session.idle' || event.type === 'session.deleted') {
|
|
719
897
|
const properties = event.properties ?? {}
|
|
720
898
|
const info = properties.info
|
|
@@ -1024,7 +1202,14 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1024
1202
|
// Config validity is independent of hook availability; warn before the early
|
|
1025
1203
|
// return so a typo is visible even on a host that registers no session hook.
|
|
1026
1204
|
warnContextPrunerConfigOnce(context.options)
|
|
1027
|
-
const
|
|
1205
|
+
const host = hostDomains(context)
|
|
1206
|
+
const sessionCtx = host.session
|
|
1207
|
+
const permission = host.permission
|
|
1208
|
+
const assertPermission = permission?.assert
|
|
1209
|
+
const permissionAssert =
|
|
1210
|
+
typeof assertPermission === 'function'
|
|
1211
|
+
? (input: Record<string, unknown>) => assertPermission.call(permission, input)
|
|
1212
|
+
: undefined
|
|
1028
1213
|
|
|
1029
1214
|
if (!sessionCtx?.hook) {
|
|
1030
1215
|
return false
|
|
@@ -1113,10 +1298,17 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1113
1298
|
}
|
|
1114
1299
|
|
|
1115
1300
|
try {
|
|
1301
|
+
// Prompt-surface shadow points (P1 and P2) share this payload. P3 moved to
|
|
1302
|
+
// `tool.invoke`, where its input actually carries a complexity vector; P6
|
|
1303
|
+
// and P10 are unwired because no measured surface carries their inputs.
|
|
1304
|
+
// The sink is in-memory and bounded, exactly like P7/P8; it is created per
|
|
1305
|
+
// registration so one setup cannot observe another's records.
|
|
1306
|
+
const promptSurfaceSink = createTelemetrySink()
|
|
1307
|
+
promptSurfaceTelemetrySink = promptSurfaceSink
|
|
1116
1308
|
// "prompt" hook — preserve attached image references and add model-visible
|
|
1117
1309
|
// instructions so Zeus can inspect visual context and pass it to the
|
|
1118
1310
|
// implementation specialist before editing.
|
|
1119
|
-
await sessionCtx.hook('prompt', (event: unknown) => {
|
|
1311
|
+
await sessionCtx.hook('prompt', async (event: unknown) => {
|
|
1120
1312
|
try {
|
|
1121
1313
|
// 2.0.29 host payload: `{ sessionID, messageID, prompt: { text,
|
|
1122
1314
|
// files, agents, skills }, metadata, delivery }`. The session id is
|
|
@@ -1124,17 +1316,34 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
1124
1316
|
// data: attachment's panic-free moment also relays it to the MCP.
|
|
1125
1317
|
const admission = event as {
|
|
1126
1318
|
sessionID?: unknown
|
|
1127
|
-
|
|
1319
|
+
messageID?: unknown
|
|
1320
|
+
prompt?: { text?: unknown; files?: unknown; skills?: unknown }
|
|
1128
1321
|
} | null
|
|
1129
1322
|
const prompt = admission?.prompt
|
|
1130
1323
|
if (!prompt || typeof prompt.text !== 'string') return
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1324
|
+
const userRequest = prompt.text
|
|
1325
|
+
if (!prompt.text.includes('<!-- pantheon-v2-visual-context -->')) {
|
|
1326
|
+
const sessionID =
|
|
1327
|
+
typeof admission?.sessionID === 'string' && admission.sessionID.trim() !== ''
|
|
1328
|
+
? admission.sessionID
|
|
1329
|
+
: undefined
|
|
1330
|
+
const visualContext = buildV2VisionPromptContext(prompt.files, prompt.text, sessionID)
|
|
1331
|
+
if (visualContext) prompt.text = `${prompt.text}\n\n${visualContext}`
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// Advisory per-turn selection. The helper reads only the prompt text
|
|
1335
|
+
// captured before Pantheon's own visual context, and the router caches
|
|
1336
|
+
// per session/message, so a repeated admission cannot call twice.
|
|
1337
|
+
await applyDecisionRouterToPrompt(admission, permissionAssert, userRequest)
|
|
1338
|
+
|
|
1339
|
+
// Shadow observation only. The projection carries `prompt.agents` and
|
|
1340
|
+
// `prompt.skills` and nothing else, so no prompt text or file bytes
|
|
1341
|
+
// reach a record; observeShadow clones and freezes it, so admission is
|
|
1342
|
+
// not mutated. A failure here is contained by the outer catch and never
|
|
1343
|
+
// reaches the host.
|
|
1344
|
+
observePromptSurface(admission, (record) => {
|
|
1345
|
+
promptSurfaceSink.emit({ ...record, mode: 'shadow' })
|
|
1346
|
+
})
|
|
1138
1347
|
} catch {
|
|
1139
1348
|
// Fail-open: malformed/unsupported prompt shapes must not block input.
|
|
1140
1349
|
}
|
|
@@ -1774,6 +1983,23 @@ async function registerV2ToolHooks(
|
|
|
1774
1983
|
|
|
1775
1984
|
// ─── V2 Permission Hook ─────────────────────────────────────────────────
|
|
1776
1985
|
|
|
1986
|
+
/**
|
|
1987
|
+
* Read `event.effect` after P8 wrote to it, for the record.
|
|
1988
|
+
*
|
|
1989
|
+
* A hostile getter reads as `null`, which can only downgrade a recorded
|
|
1990
|
+
* `narrow` to `keep`, never upgrade one — the failure direction is "the record
|
|
1991
|
+
* claims less", never "the record claims an effect the event does not hold".
|
|
1992
|
+
*/
|
|
1993
|
+
function readPermissionEffect(event: unknown): string | null {
|
|
1994
|
+
try {
|
|
1995
|
+
if (event === null || typeof event !== 'object') return null
|
|
1996
|
+
const effect = (event as { readonly effect?: unknown }).effect
|
|
1997
|
+
return typeof effect === 'string' ? effect : null
|
|
1998
|
+
} catch {
|
|
1999
|
+
return null
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
|
|
1777
2003
|
/**
|
|
1778
2004
|
* Register permission hook via V2 ctx.permission.hook.
|
|
1779
2005
|
*
|
|
@@ -1796,6 +2022,48 @@ async function registerV2PermissionHook(
|
|
|
1796
2022
|
return false
|
|
1797
2023
|
}
|
|
1798
2024
|
|
|
2025
|
+
// P8 guardrail (PLAN §5 P8, Phase 5). Constructed once at registration and
|
|
2026
|
+
// inert by default: `PANTHEON_V2_P8_GUARDRAIL` is absent in a default
|
|
2027
|
+
// install, and absent means disabled — this ships no behavioural change.
|
|
2028
|
+
// Enabled, it may only replace a wider effect with `deny`; it is synchronous,
|
|
2029
|
+
// never throws, and never runs for `decision.egress` or an existing deny.
|
|
2030
|
+
// Its outcome is recorded through the 0b telemetry path (in-memory, bounded,
|
|
2031
|
+
// I/O-free) so a narrow, a refusal and a rejected write are observable; the
|
|
2032
|
+
// disabled guardrail emits nothing.
|
|
2033
|
+
const p8Guardrail = createP8Guardrail({ enabled: p8GuardrailEnabledFromEnv() })
|
|
2034
|
+
const p8Sink = createTelemetrySink()
|
|
2035
|
+
p8TelemetrySink = p8Sink
|
|
2036
|
+
// The record's `mode` mirrors the P8 registry entry — `off` today — instead
|
|
2037
|
+
// of asserting `active` (N10a). A record may never advertise an activation
|
|
2038
|
+
// the registry and C8 deny, and deriving the value from the registry means
|
|
2039
|
+
// the two cannot drift apart again. `mode` describes the point's declared
|
|
2040
|
+
// mode; `decision`/`reason` carry the observation.
|
|
2041
|
+
const p8RegistryMode = DECISION_POINT_REGISTRY.find((point) => point.id === 'P8')?.mode ?? 'off'
|
|
2042
|
+
/**
|
|
2043
|
+
* Record one P8 outcome.
|
|
2044
|
+
*
|
|
2045
|
+
* `event` is re-read immediately before emitting: `narrowed`/`wrote` are the
|
|
2046
|
+
* guardrail's own post-write read, and a `Proxy` whose descriptor trap lies
|
|
2047
|
+
* can make that read and the next one disagree (N9). A `narrow` is therefore
|
|
2048
|
+
* recorded only when the event still holds `deny`; otherwise the record
|
|
2049
|
+
* states the effect that is actually there (`guardrail.keep` with
|
|
2050
|
+
* `p8.write.unconfirmed`), so sink and proof cannot contradict each other.
|
|
2051
|
+
*/
|
|
2052
|
+
const recordP8 = (result: ReturnType<typeof p8Guardrail.apply>, event: unknown): void => {
|
|
2053
|
+
if (!p8Guardrail.enabled) return
|
|
2054
|
+
try {
|
|
2055
|
+
const unconfirmed = result.narrowed && readPermissionEffect(event) !== 'deny'
|
|
2056
|
+
p8Sink.emit({
|
|
2057
|
+
point: 'P8',
|
|
2058
|
+
decision: unconfirmed ? 'guardrail.keep' : result.decision,
|
|
2059
|
+
reason: unconfirmed ? 'p8.write.unconfirmed' : result.reason,
|
|
2060
|
+
mode: p8RegistryMode,
|
|
2061
|
+
})
|
|
2062
|
+
} catch {
|
|
2063
|
+
// Telemetry is best-effort and must not affect permission flow.
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
|
|
1799
2067
|
try {
|
|
1800
2068
|
await permCtx.hook('evaluate', async (rawEvent: unknown) => {
|
|
1801
2069
|
const event = rawEvent as V2PermissionEvent | null
|
|
@@ -1855,6 +2123,17 @@ async function registerV2PermissionHook(
|
|
|
1855
2123
|
deny('permission event is missing')
|
|
1856
2124
|
return
|
|
1857
2125
|
}
|
|
2126
|
+
// `decision.egress` is Pantheon's own custom action. It is NOT decided
|
|
2127
|
+
// here: the user-level config/consent is the source of truth, and the
|
|
2128
|
+
// host's own permission rules are the kill-switch (see
|
|
2129
|
+
// local-decision-egress-gate). The v2.2.0 canary observed this hook runs
|
|
2130
|
+
// on the allow path of `permission.assert` and is skipped for an explicit
|
|
2131
|
+
// deny, so egress must never depend on it. Leaving the effect untouched
|
|
2132
|
+
// preserves whatever the host decided.
|
|
2133
|
+
if (event.action === DECISION_EGRESS_ACTION) {
|
|
2134
|
+
writeProof()
|
|
2135
|
+
return
|
|
2136
|
+
}
|
|
1858
2137
|
if (!Array.isArray(event.resources) || event.resources.length === 0) {
|
|
1859
2138
|
deny('permission resources are missing or malformed')
|
|
1860
2139
|
return
|
|
@@ -1906,8 +2185,29 @@ async function registerV2PermissionHook(
|
|
|
1906
2185
|
// Native-only resources remain under host policy. If a Pantheon target
|
|
1907
2186
|
// appears anywhere, the shared policy evaluates the complete resource set.
|
|
1908
2187
|
decision = evaluateV2Delegation(event, session, event.effect, origin)
|
|
1909
|
-
|
|
1910
|
-
|
|
2188
|
+
|
|
2189
|
+
// P8 (Phase 5): read the effect left in place and, only when the flag is
|
|
2190
|
+
// on and a declared rule matches, replace it with `deny`. Off by default,
|
|
2191
|
+
// synchronous, contained — it cannot grant, delay or throw into admission.
|
|
2192
|
+
//
|
|
2193
|
+
// Apply BEFORE recording (PH5-1): `writeProof` reads `event.effect`, so a
|
|
2194
|
+
// proof written first recorded `effectAfter: allow` for an event P8 then
|
|
2195
|
+
// narrowed. The order below is apply → final effect → record, and the
|
|
2196
|
+
// record carries the post-apply effect plus the guardrail outcome.
|
|
2197
|
+
//
|
|
2198
|
+
// Record only after the effect is final (N10b). `deny()` below rewrites
|
|
2199
|
+
// the effect, and a record emitted before it would describe a state the
|
|
2200
|
+
// handler never leaves behind; when the delegation policy already denies,
|
|
2201
|
+
// the deny is the policy's, so P8 claims no narrowing at all — it changed
|
|
2202
|
+
// nothing about that outcome. `deny()` also throws on an immutable event,
|
|
2203
|
+
// and a record emitted after a throw would describe an unreached state.
|
|
2204
|
+
const p8Result = p8Guardrail.apply(event)
|
|
2205
|
+
if (decision === 'deny') {
|
|
2206
|
+
deny('caller or target is not allowed by delegation policy')
|
|
2207
|
+
return
|
|
2208
|
+
}
|
|
2209
|
+
writeProof()
|
|
2210
|
+
recordP8(p8Result, event)
|
|
1911
2211
|
})
|
|
1912
2212
|
return true
|
|
1913
2213
|
} catch {
|
|
@@ -2110,7 +2410,13 @@ export const plugin = define({
|
|
|
2110
2410
|
const boundedRead = await prepareV2BoundedRead(context).catch(() => undefined)
|
|
2111
2411
|
if (boundedRead === undefined) markUnsupported('bounded-read')
|
|
2112
2412
|
|
|
2113
|
-
// ─── Phase 2: V2
|
|
2413
|
+
// ─── Phase 2: V2 Permission Hook (best-effort) ───────────────────
|
|
2414
|
+
// Registered before the event subscription and session hooks so the
|
|
2415
|
+
// delegation matrix is enforced before any turn runs. Egress never depends
|
|
2416
|
+
// on this hook: the user-level config plus the host's own rules gate it.
|
|
2417
|
+
await registerV2PermissionHook(context, subagentOrigins).catch(() => false)
|
|
2418
|
+
|
|
2419
|
+
// ─── Phase 3: V2 Event Subscription (best-effort) ────────────────
|
|
2114
2420
|
const eventCleanup = subscribeV2Events(context, boundedRead?.clearSession)
|
|
2115
2421
|
if (eventCleanup) {
|
|
2116
2422
|
activeCleanups.push(eventCleanup)
|
|
@@ -2118,13 +2424,13 @@ export const plugin = define({
|
|
|
2118
2424
|
markUnsupported('event-stream')
|
|
2119
2425
|
}
|
|
2120
2426
|
|
|
2121
|
-
// ─── Phase
|
|
2427
|
+
// ─── Phase 4: V2 Session Hooks (best-effort) ─────────────────────
|
|
2122
2428
|
const sessionHooksRegistered = await registerV2SessionHooks(context).catch(() => false)
|
|
2123
2429
|
if (!sessionHooksRegistered) {
|
|
2124
2430
|
markUnsupported('session-hooks')
|
|
2125
2431
|
}
|
|
2126
2432
|
|
|
2127
|
-
// ─── Phase
|
|
2433
|
+
// ─── Phase 5: V2 Tool Hooks (best-effort) ────────────────────────
|
|
2128
2434
|
const toolHookResult = await registerV2ToolHooks(
|
|
2129
2435
|
context,
|
|
2130
2436
|
subagentOrigins,
|
|
@@ -2134,7 +2440,7 @@ export const plugin = define({
|
|
|
2134
2440
|
markUnsupported('tool-execute-hooks')
|
|
2135
2441
|
}
|
|
2136
2442
|
|
|
2137
|
-
// ─── Phase
|
|
2443
|
+
// ─── Phase 6: V2 Tool Registration (best-effort) ─────────────────
|
|
2138
2444
|
const boundedReadDefinition = toolHookResult.beforeRegistered
|
|
2139
2445
|
? boundedRead?.definition
|
|
2140
2446
|
: undefined
|
|
@@ -2144,9 +2450,6 @@ export const plugin = define({
|
|
|
2144
2450
|
const toolsRegistered = await registerV2Tools(context, boundedReadDefinition).catch(() => false)
|
|
2145
2451
|
if (!toolsRegistered) markUnsupported('tool-transform')
|
|
2146
2452
|
|
|
2147
|
-
// ─── Phase 6: V2 Permission Hook (best-effort) ───────────────────
|
|
2148
|
-
await registerV2PermissionHook(context, subagentOrigins).catch(() => false)
|
|
2149
|
-
|
|
2150
2453
|
// ─── Phase 7: V2 Compaction Hook (best-effort) ───────────────────
|
|
2151
2454
|
const compactionCtx = hostDomains(context).session
|
|
2152
2455
|
if (compactionCtx?.hook) {
|
|
@@ -2154,6 +2457,10 @@ export const plugin = define({
|
|
|
2154
2457
|
// active goals per session, and the store needs no host API (same
|
|
2155
2458
|
// `.pantheon/goals` directory V1 uses).
|
|
2156
2459
|
const goalStore = new GoalStore({ dir: '.pantheon/goals' })
|
|
2460
|
+
// P9's record sink, created per registration (in-memory, bounded,
|
|
2461
|
+
// I/O-free) so one setup cannot observe another's records.
|
|
2462
|
+
const p9Sink = createTelemetrySink()
|
|
2463
|
+
p9TelemetrySink = p9Sink
|
|
2157
2464
|
try {
|
|
2158
2465
|
// 2.0.16 `SessionHooks` key is `compaction` (the migration doc maps
|
|
2159
2466
|
// `experimental.session.compacting` → `ctx.session.hook("compaction")`).
|
|
@@ -2202,6 +2509,34 @@ export const plugin = define({
|
|
|
2202
2509
|
: typeof payload?.session?.id === 'string'
|
|
2203
2510
|
? payload.session.id
|
|
2204
2511
|
: undefined
|
|
2512
|
+
|
|
2513
|
+
// P9 (compaction) shadow observation, on the MEASURED carrier only.
|
|
2514
|
+
// The 2.2.5 compaction payload carries a TOP-LEVEL `sessionID` and
|
|
2515
|
+
// no nested `session` object at all (PROBE-A, 11/11 runs), so the
|
|
2516
|
+
// event is handed to the adapter as-is and it reads
|
|
2517
|
+
// `payload.sessionID` — never `session.id`, which is absent there.
|
|
2518
|
+
// A payload that carries only a nested id therefore produces NO
|
|
2519
|
+
// decision (fail-closed) rather than being keyed by a carrier the
|
|
2520
|
+
// host was never observed to send. This runs BEFORE the pruner and
|
|
2521
|
+
// the context injection below, so `systemPartCount` describes the
|
|
2522
|
+
// host payload and not the blocks Pantheon appends; the adapter
|
|
2523
|
+
// clones what it reads and pushes nothing itself, so the injected
|
|
2524
|
+
// context is unchanged — shadow is the record, nothing else.
|
|
2525
|
+
// Child-session compaction is measured and needs no separate path:
|
|
2526
|
+
// PROBE-G §3.1 fired this hook on a real child 3/3 with the CHILD
|
|
2527
|
+
// sessionID at top level and the same payload shape (7 keys, no
|
|
2528
|
+
// nested `session`, `system` array of 4). Compaction with
|
|
2529
|
+
// `reason:"overflow"` was NOT inducible in 6 error shapes (PROBE-G
|
|
2530
|
+
// §3.2 — the host retried and completed, and the one
|
|
2531
|
+
// failure-recovery compaction was persisted as `reason:"auto"`), so
|
|
2532
|
+
// that path remains unmeasured and is not designed for here.
|
|
2533
|
+
try {
|
|
2534
|
+
evaluateCompactionMemoryPoint({ payload }, (record) => {
|
|
2535
|
+
p9Sink.emit({ ...record, mode: 'shadow' })
|
|
2536
|
+
})
|
|
2537
|
+
} catch {
|
|
2538
|
+
// Observation must never reach the compaction request.
|
|
2539
|
+
}
|
|
2205
2540
|
const prunerConfig = resolveContextPrunerConfig(context.options)
|
|
2206
2541
|
const stats = pruneMessages(payload?.messages, prunerConfig, 'compaction')
|
|
2207
2542
|
logContextPrune(stats, sessionID)
|
package/src/plugin.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { createGuardPathResolver } from './pantheon/guard-path.ts'
|
|
|
22
22
|
import { createReadEnhancer } from './pantheon/hashline/read-enhancer.ts'
|
|
23
23
|
import { createHashlineEditTool } from './pantheon/hashline/tool.ts'
|
|
24
24
|
import { createIdleDispatcher } from './pantheon/idle-continuation.ts'
|
|
25
|
+
import { createLocalDecisionTool } from './pantheon/local-decision-tool.ts'
|
|
25
26
|
import { createPantheonLogger } from './pantheon/logger.ts'
|
|
26
27
|
import { createModelCommand } from './pantheon/model-command.ts'
|
|
27
28
|
import { pantheonPluginOnce } from './pantheon/plugin-once.ts'
|
|
@@ -369,6 +370,7 @@ const plugin: Plugin = async (input: PluginInput) => {
|
|
|
369
370
|
// opencode.db read-only via the single node:sqlite backend. Fully wired.
|
|
370
371
|
const costCommand = createCostCommand()
|
|
371
372
|
const modelCommand = createModelCommand()
|
|
373
|
+
const localDecisionTool = createLocalDecisionTool()
|
|
372
374
|
|
|
373
375
|
return {
|
|
374
376
|
config: async (config: PluginConfig) => {
|
|
@@ -436,6 +438,8 @@ const plugin: Plugin = async (input: PluginInput) => {
|
|
|
436
438
|
pantheon_cost: costCommand.pantheon_cost,
|
|
437
439
|
// Deterministic /pantheon-model management of top-level model fields.
|
|
438
440
|
pantheon_model: modelCommand.pantheon_model,
|
|
441
|
+
// Local advisory routing; execute() requires the host's Zeus agent context.
|
|
442
|
+
pantheon_local_decision: localDecisionTool,
|
|
439
443
|
},
|
|
440
444
|
'chat.message': async (hookInput, output) => {
|
|
441
445
|
await vision.chatMessage(hookInput, output)
|
|
@@ -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.
|
|
5025
|
+
insert(_el$61, `Pantheon TUI v1.6.2-beta.5`);
|
|
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.
|
|
8303
|
+
insert(_el$13, `Pantheon v1.6.2-beta.5`);
|
|
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.
|
|
9030
|
+
insert(_el$72, () => `Pantheon v1.6.2-beta.5${preset().name ? ` ▸ ${preset().name}` : ""}`);
|
|
9031
9031
|
effect((_$p) => setProp(_el$72, "fg", muted(), _$p));
|
|
9032
9032
|
return _el$72;
|
|
9033
9033
|
})();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantheon-tui",
|
|
3
|
-
"version": "1.6.2-beta.
|
|
3
|
+
"version": "1.6.2-beta.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pantheon-tui",
|
|
9
|
-
"version": "1.6.2-beta.
|
|
9
|
+
"version": "1.6.2-beta.5",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@opencode-ai/plugin": "1.18.33",
|