pantheon-opencode 1.6.3-beta.16 → 1.6.3-beta.18

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 CHANGED
@@ -10,6 +10,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
10
10
  <!-- Add new changes here. Running `node scripts/versioning.mjs apply` will
11
11
  move this section to a versioned entry and reset the template below. -->
12
12
 
13
+ ## [v1.6.3-beta.18] - 2026-11-06
14
+
15
+ ## 🆕 What's New
16
+ - `mode: "order"`: ORDER 2-4 candidates by fit — one score question per candidate, the descending ordering with per-candidate scores comes back (nulls visible, last, never guessed). Rank picks a winner; order ranks the shortlist.
17
+ - The review questions are self-documenting now: `quality` (score) and `needs_review` (predicate) — "noul" was the decision model's internal archetype leaking into user-visible payloads.
18
+
19
+ ## [v1.6.3-beta.17] - 2026-11-05
20
+
21
+ ## 🆕 What's New
22
+ - The J1 gate is now a ladder: off / shadow / warn / enforce (PANTHEON_J1_RISK_SCORE). Enforce awaits the bounded gate and DENIES a high-risk tool call in-session, with the threshold configurable (PANTHEON_J1_ENFORCE_THRESHOLD, default 0.8). Shadow stays the default-on behavior.
23
+ - CALLER_NOT_ALLOWED refusals now teach the fix: allowlist the caller via PANTHEON_JEV_SPECIALIST_CALLERS or ask Zeus to route.
24
+ - Plan persistence contract: Athena returns the plan as her response; Zeus persists PLAN.md — no more refused write attempts on deepwork plans.
25
+
13
26
  ## [v1.6.3-beta.16] - 2026-11-05
14
27
 
15
28
  ## 🆕 What's New
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-opencode",
3
- "version": "1.6.3-beta.16",
3
+ "version": "1.6.3-beta.18",
4
4
  "description": "Multi-agent orchestration for OpenCode \u2014 14 specialized agents, TDD, Themis review gates.",
5
5
  "type": "module",
6
6
  "workspaces": [
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pantheon",
3
3
  "publisher": "ils15",
4
- "version": "1.6.3-beta.16",
4
+ "version": "1.6.3-beta.18",
5
5
  "displayName": "Pantheon",
6
6
  "description": "Conductor-Delegate orchestration platform with 14 specialized agents, 21 skills, and OpenCode support.",
7
7
  "agents": "./src/agents",
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "setuptools.backends._legacy:_Backend"
4
4
 
5
5
  [project]
6
6
  name = "pantheon"
7
- version = "1.6.3-beta.16"
7
+ version = "1.6.3-beta.18"
8
8
  description = "Multi-agent orchestration framework"
9
9
  requires-python = ">=3.11"
10
10
  # Python sources under src/mcp/ import fastmcp/pydantic at runtime, but those
@@ -248,3 +248,5 @@ For external docs/specs, use `webfetch` (see `internet-search` skill for pattern
248
248
 
249
249
  ## Skills
250
250
  Planejamento: `spec-driven-development`, `artifact-management`
251
+
252
+ Your plan is your DELIVERABLE: return it fully in your response. You cannot write files or persist PLAN.md — say so once and hand the plan back; Zeus persists it.
@@ -94,6 +94,14 @@ call before firing it.
94
94
  cheap and typed, an MCP call is the LAST resort for state the session
95
95
  cannot reconstruct.
96
96
 
97
+ ## Plan persistence (deepwork PLAN.md)
98
+
99
+ Athena is plan-only and cannot write files; a plan she produces returns as her
100
+ response. YOU persist it: write `.pantheon/deepwork/<slug>/PLAN.md` yourself
101
+ (or hand the write to the specialist that owns the artifact) right after her
102
+ plan lands. Never ask Athena to save, and never delegate persistence to her —
103
+ the field refusal (beta.16) was the frontmatter working as designed.
104
+
97
105
  ## Vague multi-part request? Refine into a contract first
98
106
 
99
107
  When the user's request spans multiple concerns without explicit acceptance
@@ -47,10 +47,13 @@ import {
47
47
  REVIEW_ENVELOPE_KEYS,
48
48
  } from './jev-quality-score.ts'
49
49
  import {
50
+ buildJevOrderRequest,
50
51
  buildJevRankRequest,
51
52
  buildJevVerifyRequest,
53
+ consumeJevOrderResult,
52
54
  consumeJevRankResult,
53
55
  consumeJevVerifyResult,
56
+ ORDER_ENVELOPE_KEYS,
54
57
  RANK_ENVELOPE_KEYS,
55
58
  VERIFY_ENVELOPE_KEYS,
56
59
  } from './jev-rank-verify.ts'
@@ -134,6 +137,8 @@ export type JevDecisionRunFailure =
134
137
  | 'CRITERIA_INVALID'
135
138
  | 'RANK_INPUT_INVALID'
136
139
  | 'CANDIDATE_INVALID'
140
+ | 'ORDER_INPUT_INVALID'
141
+ | 'ORDER_CANDIDATE_INVALID'
137
142
  | 'VERIFY_INPUT_INVALID'
138
143
  | 'CLAIM_INVALID'
139
144
  | 'CONTEXT_UNAVAILABLE'
@@ -449,10 +454,14 @@ export async function runJevDecision(
449
454
  ? (toolContext as JevToolContext)
450
455
  : undefined
451
456
  const caller = context?.agent
452
- if (typeof caller !== 'string' || caller.length === 0) return refusal('CALLER_NOT_ALLOWED')
457
+ if (typeof caller !== 'string' || caller.length === 0)
458
+ return refusal('CALLER_NOT_ALLOWED', 'CALLER_NOT_ALLOWLISTED')
453
459
  const allowlist = runtime.specialistCallers ?? []
454
460
  if (caller !== 'zeus' && !allowlist.includes(caller)) {
455
- return refusal('CALLER_NOT_ALLOWED')
461
+ return refusal(
462
+ 'CALLER_NOT_ALLOWED',
463
+ 'CALLER_NOT_ALLOWLISTED — allowlist this caller via PANTHEON_JEV_SPECIALIST_CALLERS (then restart) or ask Zeus to route',
464
+ )
456
465
  }
457
466
 
458
467
  const requested = (input ?? {}) as { mode?: unknown; questions?: unknown }
@@ -476,9 +485,11 @@ export async function runJevDecision(
476
485
  ? RANK_ENVELOPE_KEYS
477
486
  : requested.mode === 'verify'
478
487
  ? VERIFY_ENVELOPE_KEYS
479
- : isJevDecisionPreset(requested.mode)
480
- ? JEV_PRESET_ENVELOPE_KEYS
481
- : undefined
488
+ : requested.mode === 'order'
489
+ ? ORDER_ENVELOPE_KEYS
490
+ : isJevDecisionPreset(requested.mode)
491
+ ? JEV_PRESET_ENVELOPE_KEYS
492
+ : undefined
482
493
  if (envelopeKeys !== undefined) {
483
494
  const envelope = checkJevEnvelope(input, envelopeKeys)
484
495
  if (!envelope.ok) {
@@ -491,7 +502,9 @@ export async function runJevDecision(
491
502
  ? 'RANK_INPUT_INVALID'
492
503
  : requested.mode === 'verify'
493
504
  ? 'VERIFY_INPUT_INVALID'
494
- : 'PRESET_INVALID'
505
+ : requested.mode === 'order'
506
+ ? 'ORDER_INPUT_INVALID'
507
+ : 'PRESET_INVALID'
495
508
  return refusal(reasonCode, envelope.detail)
496
509
  }
497
510
  }
@@ -526,6 +539,10 @@ export async function runJevDecision(
526
539
  const prepared = buildJevVerifyRequest(input ?? {})
527
540
  if (!prepared.ok) return refusal(prepared.reasonCode)
528
541
  prebuilt = prepared.request
542
+ } else if (requested.mode === 'order') {
543
+ const prepared = buildJevOrderRequest(input ?? {})
544
+ if (!prepared.ok) return refusal(prepared.reasonCode, prepared.detail)
545
+ prebuilt = prepared.request
529
546
  }
530
547
  const result = await runGatedNativeJevCall({
531
548
  sessionID: context?.sessionID,
@@ -653,6 +670,29 @@ export async function runJevDecision(
653
670
  frozen: result.call.frozen,
654
671
  })
655
672
  }
673
+ if (requested.mode === 'order') {
674
+ // v3.1 ordering: one fit question per candidate (2-4), sorted descending.
675
+ // Null score = the host answered nothing usable for that candidate —
676
+ // visible, placed last, never guessed.
677
+ const ordering = consumeJevOrderResult(result.call.response, result.call.request)
678
+ return JSON.stringify({
679
+ advisory: true,
680
+ effect: 'none',
681
+ reason: 'JEV_DECISION',
682
+ caller,
683
+ route: {
684
+ providerID: result.call.selection.route.model.providerID,
685
+ id: result.call.selection.route.model.id,
686
+ billing: result.call.selection.route.billing,
687
+ },
688
+ mode: 'order',
689
+ ordering,
690
+ answers: advice.answers,
691
+ missing: advice.missing,
692
+ usage: { costUsd: advice.costUsd, tokens: advice.tokens },
693
+ frozen: result.call.frozen,
694
+ })
695
+ }
656
696
  if (requested.mode === 'verify') {
657
697
  // v3.1 verify: one PASS/FAIL/BLOCK verdict per claim, fail-closed. The
658
698
  // tool never acts on the verdicts; a caller that requires a verdict
@@ -704,6 +744,8 @@ const TOOL_DESCRIPTION =
704
744
  'a specialist, `mode: "review"` to score a finished delegated result against named criteria ' +
705
745
  '(advisory quality score + needs-review flag; the result content itself is never sent — ' +
706
746
  'shape metrics and criteria only), `mode: "rank"` to pick the best of 2-20 named candidates ' +
747
+ '(winner + fit; no full ordering), `mode: "order"` to ORDER 2-4 candidates by fit (one ' +
748
+ 'score question per candidate; returns the descending ordering with per-candidate scores), ' +
707
749
  '(returns the winner and its fit score; no full ordering), `mode: "verify"` to check 1-4 ' +
708
750
  'named claims, with optional `state` evidence the claims are judged against ' +
709
751
  '(verdicts PASS, FAIL, or UNVERIFIABLE for the 0.35-0.65 band; any refusal, timeout or ' +
@@ -815,7 +857,7 @@ const JEV_INPUT_SCHEMA: Record<string, unknown> = {
815
857
  properties: {
816
858
  schemaVersion: { type: 'integer', const: 1 },
817
859
  state: { type: 'string', minLength: 1, maxLength: 12_000 },
818
- mode: { type: 'string', enum: ['skills', 'delegation', 'review', 'rank', 'verify'] },
860
+ mode: { type: 'string', enum: ['skills', 'delegation', 'review', 'rank', 'verify', 'order'] },
819
861
  questions: { type: 'array', minItems: 1, maxItems: 4, items: questionSchema },
820
862
  delegateId: {
821
863
  type: 'string',
@@ -63,7 +63,12 @@ export const J4_QUALITY_SCORE_POINT = 'J4'
63
63
 
64
64
  /** Question names of the two prepared questions, matched on consumption. */
65
65
  export const QUALITY_QUESTION_NAME = 'quality'
66
- export const REVIEW_QUESTION_NAME = 'noul'
66
+ /**
67
+ * Field report (beta.13→16): the review question was literally named 'noul'
68
+ * — the decision model's internal archetype leaked into a user-visible
69
+ * payload. The name is ours to choose; `quality` says what it measures.
70
+ */
71
+ export const REVIEW_QUESTION_NAME = 'needs_review'
67
72
 
68
73
  /** DSH hard-cap mirror: at most 4 criteria per review request. */
69
74
  export const J4_MAX_CRITERIA = 4
@@ -46,7 +46,7 @@
46
46
  * @module jev-rank-verify
47
47
  */
48
48
 
49
- import { consumeJevDecisionResult } from './jev-decisions.ts'
49
+ import { consumeJevDecisionResult, JEV_DECISION_MAX_QUESTIONS } from './jev-decisions.ts'
50
50
  import type { NativeDecisionRequest, ResolvedNativeDecisionRoute } from './v2-native-decisions.ts'
51
51
  import { NATIVE_DECISION_MAX_PROMPT_LENGTH } from './v2-native-decisions.ts'
52
52
 
@@ -283,6 +283,166 @@ export function prepareJevRankRequest(
283
283
  }
284
284
  }
285
285
 
286
+ // ─── Order: top-K ordering (2-4 candidates, one fit question each) ───────
287
+
288
+ export const ORDER_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
289
+ 'schemaVersion',
290
+ 'mode',
291
+ 'state',
292
+ 'candidates',
293
+ ])
294
+
295
+ export type JevOrderBuildFailure =
296
+ | 'ORDER_INPUT_INVALID'
297
+ | 'ORDER_CANDIDATE_INVALID'
298
+ | 'STATE_INVALID'
299
+
300
+ export type JevOrderBuildDetail = 'ORDER_CANDIDATE_COUNT_RANGE'
301
+
302
+ export type JevOrderBuild =
303
+ | { readonly ok: true; readonly request: Omit<NativeDecisionRequest, 'model'> }
304
+ | {
305
+ readonly ok: false
306
+ readonly reasonCode: JevOrderBuildFailure
307
+ readonly detail?: JevOrderBuildDetail
308
+ }
309
+
310
+ export type JevOrderPreparation =
311
+ | { readonly ok: true; readonly request: NativeDecisionRequest }
312
+ | {
313
+ readonly ok: false
314
+ readonly reasonCode: JevOrderBuildFailure
315
+ readonly detail?: JevOrderBuildDetail
316
+ }
317
+
318
+ const ORDER_MAX_CANDIDATES = JEV_DECISION_MAX_QUESTIONS // one score question per candidate
319
+
320
+ const ORDER_STATE_TEMPLATE =
321
+ 'Advisory ordering. The caller supplied a task and 2-4 candidates; ' +
322
+ 'each question scores ONE candidate for fit against the stated task. ' +
323
+ 'Score each candidate on its own terms. Nothing is enforced.'
324
+
325
+ /**
326
+ * Build the order request: one SCORE question per candidate (the host answers
327
+ * one scalar per question, so 2-4 candidates is the honest ceiling). Ids ride
328
+ * the candidate validation reused from rank; question names are positional
329
+ * (`fit_1`..) so no id pattern can collide with the question-name grammar.
330
+ */
331
+ export function buildJevOrderRequest(input: unknown): JevOrderBuild {
332
+ if (!isRecord(input)) return { ok: false, reasonCode: 'ORDER_INPUT_INVALID' }
333
+ for (const key of Object.keys(input)) {
334
+ if (!ORDER_ENVELOPE_KEYS.has(key)) return { ok: false, reasonCode: 'ORDER_INPUT_INVALID' }
335
+ }
336
+ const state = input.state
337
+ if (!isBoundedNonBlankString(state, NATIVE_DECISION_MAX_PROMPT_LENGTH) || isHostileProse(state)) {
338
+ return { ok: false, reasonCode: 'STATE_INVALID' }
339
+ }
340
+ const rawCandidates = input.candidates
341
+ if (rawCandidates === undefined) return { ok: false, reasonCode: 'ORDER_INPUT_INVALID' }
342
+ if (!Array.isArray(rawCandidates)) return { ok: false, reasonCode: 'ORDER_CANDIDATE_INVALID' }
343
+ if (rawCandidates.length < 2 || rawCandidates.length > ORDER_MAX_CANDIDATES) {
344
+ return {
345
+ ok: false,
346
+ reasonCode: 'ORDER_CANDIDATE_INVALID',
347
+ detail: 'ORDER_CANDIDATE_COUNT_RANGE',
348
+ }
349
+ }
350
+ const seen = new Set<string>()
351
+ const candidates: Array<{ id: string; description?: string }> = []
352
+ for (const raw of rawCandidates) {
353
+ if (!isRecord(raw)) return { ok: false, reasonCode: 'ORDER_CANDIDATE_INVALID' }
354
+ const extraKeys = Object.keys(raw).filter((key) => key !== 'id' && key !== 'description')
355
+ if (extraKeys.length > 0) return { ok: false, reasonCode: 'ORDER_CANDIDATE_INVALID' }
356
+ const id = raw.id
357
+ if (typeof id !== 'string' || id.length < 1 || id.length > 64) {
358
+ return { ok: false, reasonCode: 'ORDER_CANDIDATE_INVALID' }
359
+ }
360
+ if (seen.has(id)) return { ok: false, reasonCode: 'ORDER_CANDIDATE_INVALID' }
361
+ seen.add(id)
362
+ const description = raw.description
363
+ if (description !== undefined) {
364
+ if (!isBoundedNonBlankString(description, 500) || isHostileProse(description)) {
365
+ return { ok: false, reasonCode: 'ORDER_CANDIDATE_INVALID' }
366
+ }
367
+ candidates.push({ id, description })
368
+ } else {
369
+ candidates.push({ id })
370
+ }
371
+ }
372
+ const levels = Array.from({ length: 9 }, (_, index) => ({
373
+ label: String(index + 2),
374
+ }))
375
+ const questions = candidates.map((candidate, index) => ({
376
+ type: 'score' as const,
377
+ name: `fit_${index + 1}`,
378
+ instructions:
379
+ `Score how well candidate "${candidate.id}"` +
380
+ (candidate.description ? ` (${candidate.description})` : '') +
381
+ ` fits the task. 2 = poor fit, 10 = exact fit.`,
382
+ levels,
383
+ }))
384
+ const request = {
385
+ input: Object.freeze([
386
+ Object.freeze({ type: 'text' as const, text: `${ORDER_STATE_TEMPLATE} Task: ${state}` }),
387
+ ]),
388
+ questions: Object.freeze(questions.map((question) => Object.freeze(question))),
389
+ } satisfies Omit<NativeDecisionRequest, 'model'>
390
+ return { ok: true, request: Object.freeze(request) }
391
+ }
392
+
393
+ export function prepareJevOrderRequest(
394
+ route: ResolvedNativeDecisionRoute,
395
+ input: unknown,
396
+ ): JevOrderPreparation {
397
+ const built = buildJevOrderRequest(input)
398
+ if (!built.ok) return built
399
+ return {
400
+ ok: true,
401
+ request: {
402
+ model: route.model,
403
+ input: built.request.input,
404
+ questions: built.request.questions,
405
+ },
406
+ }
407
+ }
408
+
409
+ /** One ordered entry: the candidate id and its fit score (null when the host answered nothing usable). */
410
+ export interface JevOrderEntry {
411
+ readonly id: string
412
+ readonly score: number | null
413
+ }
414
+
415
+ /**
416
+ * Consume the order result: map each positional score answer back to its
417
+ * candidate, sort by score descending (nulls last, stable), and return the
418
+ * ordering. A missing/invalid score stays visible as null — never guessed.
419
+ */
420
+ export function consumeJevOrderResult(
421
+ response: unknown,
422
+ request: NativeDecisionRequest,
423
+ ): ReadonlyArray<JevOrderEntry> {
424
+ const advice = consumeJevDecisionResult(response, request)
425
+ const entries: Array<{ id: string; score: number | null; order: number }> = []
426
+ request.questions.forEach((question, index) => {
427
+ const answer = advice.answers.find((candidate) => candidate.name === question.name)
428
+ const score =
429
+ answer !== undefined && answer.type === 'score' && typeof answer.score === 'number'
430
+ ? answer.score
431
+ : null
432
+ entries.push({ id: `c${index + 1}`, score, order: index })
433
+ })
434
+ return Object.freeze(
435
+ entries
436
+ .sort((left, right) => {
437
+ if (left.score === null && right.score === null) return left.order - right.order
438
+ if (left.score === null) return 1
439
+ if (right.score === null) return -1
440
+ return right.score - left.score || left.order - right.order
441
+ })
442
+ .map(({ id, score }) => ({ id, score })),
443
+ )
444
+ }
445
+
286
446
  // ─── Verify: request building ────────────────────────────────────────────
287
447
 
288
448
  export const VERIFY_ENVELOPE_KEYS: ReadonlySet<string> = new Set([
@@ -120,12 +120,50 @@ const WRITE_TOOLS: ReadonlySet<string> = new Set([
120
120
  'hashline_edit',
121
121
  ])
122
122
 
123
- /** Whether the operator explicitly enabled the flag. Absence means off. */
123
+ /**
124
+ * The escalation ladder (field beta.14: the operator wants iterative
125
+ * escalation, not a binary flag). `on`/`1`/`true` map to `shadow` for
126
+ * back-compatibility with the shipped setup.
127
+ * off — nothing fires (hard zero)
128
+ * shadow — observe + record; invisible in the session (today's behavior)
129
+ * warn — RESERVED (needs a V2 client channel; currently behaves as shadow)
130
+ * enforce — an affirmative high-risk score DENIES the tool call (the host
131
+ * surfaces the block message in the session); gate unavailability
132
+ * never blocks (fail-open, documented)
133
+ */
134
+ export type J1RiskGateMode = 'off' | 'shadow' | 'warn' | 'enforce'
135
+
136
+ export const J1_ENFORCE_THRESHOLD_ENV = 'PANTHEON_J1_ENFORCE_THRESHOLD'
137
+ export const J1_ENFORCE_THRESHOLD_DEFAULT = 0.8
138
+
139
+ export function j1ModeFromEnv(
140
+ env: Record<string, string | undefined> = process.env,
141
+ ): J1RiskGateMode {
142
+ const raw = (env[J1_RISK_GATE_FLAG_ENV] ?? '').trim().toLowerCase()
143
+ if (raw === 'enforce') return 'enforce'
144
+ if (raw === 'warn') return 'warn'
145
+ return FLAG_ON.has(raw) ? 'shadow' : 'off'
146
+ }
147
+
148
+ /** Back-compatible: any non-off mode counts as enabled. */
124
149
  export function j1RiskGateEnabledFromEnv(
125
150
  env: Record<string, string | undefined> = process.env,
126
151
  ): boolean {
127
- const raw = (env[J1_RISK_GATE_FLAG_ENV] ?? '').trim().toLowerCase()
128
- return FLAG_ON.has(raw)
152
+ return j1ModeFromEnv(env) !== 'off'
153
+ }
154
+
155
+ /**
156
+ * The enforce-mode deny threshold (0..1). Invalid or out-of-range values fall
157
+ * back to the documented default — an operator typo must not disable the gate.
158
+ */
159
+ export function j1EnforceThresholdFromEnv(
160
+ env: Record<string, string | undefined> = process.env,
161
+ ): number {
162
+ const text = (env[J1_ENFORCE_THRESHOLD_ENV] ?? '').trim()
163
+ if (text === '') return J1_ENFORCE_THRESHOLD_DEFAULT
164
+ const raw = Number(text)
165
+ if (!Number.isFinite(raw) || raw < 0 || raw > 1) return J1_ENFORCE_THRESHOLD_DEFAULT
166
+ return raw
129
167
  }
130
168
 
131
169
  /**
@@ -408,12 +446,25 @@ function abortDeadline(signal: AbortSignal): Promise<'timeout'> {
408
446
  * settles its own ledger reservation in the background (settlement of an
409
447
  * already-fired call — not a retry, and it writes no record).
410
448
  */
449
+ export interface J1Verdict {
450
+ /** 'block' only in enforce mode with an affirmative high-risk score. */
451
+ block: boolean
452
+ riskScore: number | null
453
+ reason: string
454
+ }
455
+
411
456
  export function createJ1RiskGateObserver(
412
- options: J1RiskGateObserverOptions,
413
- ): (event: unknown) => Promise<void> {
457
+ options: J1RiskGateObserverOptions & {
458
+ /** enforce: the caller awaits and denies on { block: true }. */
459
+ mode?: J1RiskGateMode
460
+ threshold?: number
461
+ },
462
+ ): (event: unknown) => Promise<void | J1Verdict> {
414
463
  const timeoutMs = options.timeoutMs ?? J1_RISK_GATE_TIMEOUT_MS
415
464
  const sink = options.sink
416
- return async (event: unknown): Promise<void> => {
465
+ const enforce = options.mode === 'enforce'
466
+ const threshold = options.threshold ?? J1_ENFORCE_THRESHOLD_DEFAULT
467
+ return async (event: unknown): Promise<void | J1Verdict> => {
417
468
  try {
418
469
  const payload = (event ?? {}) as J1ExecuteBeforeEvent
419
470
  if (!isRiskGateTarget(payload.tool)) return
@@ -467,6 +518,18 @@ export function createJ1RiskGateObserver(
467
518
  }),
468
519
  sink,
469
520
  )
521
+ if (enforce) {
522
+ const risk = evaluation.riskScore
523
+ const block = risk !== null && risk >= threshold
524
+ return {
525
+ block,
526
+ riskScore: risk,
527
+ reason: block
528
+ ? `J1 enforce: risco ${risk.toFixed(2)} >= threshold ${threshold}`
529
+ : 'allow',
530
+ }
531
+ }
532
+ return
470
533
  } finally {
471
534
  clearTimeout(timer)
472
535
  }
package/src/plugin-v2.ts CHANGED
@@ -126,7 +126,9 @@ import {
126
126
  import {
127
127
  createJ1RiskGateObserver,
128
128
  isRiskGateTarget,
129
- j1RiskGateEnabledFromEnv,
129
+ type J1Verdict,
130
+ j1EnforceThresholdFromEnv,
131
+ j1ModeFromEnv,
130
132
  } from './pantheon/jev-risk-gate.ts'
131
133
  import { DECISION_EGRESS_ACTION } from './pantheon/local-decision-egress-gate.ts'
132
134
  import { applyDecisionRouterToPrompt } from './pantheon/local-decision-prompt.ts'
@@ -1984,14 +1986,17 @@ async function registerV2ToolHooks(
1984
1986
  // ledger reservation, permission kill-switch) and records shadow records
1985
1987
  // only — it is fired WITHOUT await inside the before-handler (fire-and-
1986
1988
  // observe), self-bounds at 2s with an AbortController, and never retries.
1987
- let j1Observer: ((event: unknown) => Promise<void>) | undefined
1988
- if (jevRuntime !== undefined && j1RiskGateEnabledFromEnv()) {
1989
+ const j1Mode = j1ModeFromEnv()
1990
+ let j1Observer: ((event: unknown) => Promise<void | J1Verdict>) | undefined
1991
+ if (jevRuntime !== undefined && j1Mode !== 'off') {
1989
1992
  const j1Sink = createTelemetrySink()
1990
1993
  j1TelemetrySink = j1Sink
1991
1994
  j1Observer = createJ1RiskGateObserver({
1992
1995
  runtime: jevRuntime,
1996
+ mode: j1Mode,
1997
+ threshold: j1EnforceThresholdFromEnv(),
1993
1998
  sink: (record) => {
1994
- j1Sink.emit({ ...record, mode: 'shadow' })
1999
+ j1Sink.emit({ ...record, mode: j1Mode === 'enforce' ? 'enforce' : 'shadow' })
1995
2000
  },
1996
2001
  })
1997
2002
  }
@@ -2148,7 +2153,22 @@ async function registerV2ToolHooks(
2148
2153
  // the flag is off — the only cost of the flag-on check below is the
2149
2154
  // truthiness read.
2150
2155
  if (j1Observer !== undefined && isRiskGateTarget((event as { tool?: unknown }).tool)) {
2151
- void j1Observer(event)
2156
+ // Ladder semantics: shadow/warn stay fire-and-observe (latency
2157
+ // unchanged); ENFORCE awaits (bounded 2s) and DENIES via throw —
2158
+ // the host surfaces the thrown message in the session, which is the
2159
+ // block's visible form. Unavailability never denies (fail-open by
2160
+ // design: a dead budget must not brick every shell call).
2161
+ if (j1Mode === 'enforce') {
2162
+ const verdict = (await j1Observer(event)) as J1Verdict | undefined
2163
+ if (verdict?.block === true) {
2164
+ throw new Error(
2165
+ `[J1 enforce] chamada bloqueada: risco ${verdict.riskScore?.toFixed(2)} ` +
2166
+ `>= threshold (ajuste PANTHEON_J1_ENFORCE_THRESHOLD ou rebaixe o modo para shadow/warn)`,
2167
+ )
2168
+ }
2169
+ } else {
2170
+ void j1Observer(event)
2171
+ }
2152
2172
  }
2153
2173
  // J3 turn-complexity shadow classification. Same fire-and-observe
2154
2174
  // discipline as J1: the dispatch's latency is unchanged, the observer
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
- "version": "1.6.3-beta.16",
3
+ "version": "1.6.3-beta.18",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pantheon-tui",
9
- "version": "1.6.3-beta.16",
9
+ "version": "1.6.3-beta.18",
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.3-beta.16",
4
+ "version": "1.6.3-beta.18",
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": {