pantheon-opencode 1.6.0 → 1.6.1
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 +29 -0
- package/README.md +45 -1
- package/bin/pantheon-init.mjs +152 -23
- package/package.json +6 -5
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/doctor.mjs +22 -5
- package/scripts/install/interactive.mjs +30 -9
- package/scripts/install/interrupt.mjs +78 -0
- package/scripts/install/opencode-state.mjs +91 -0
- package/scripts/install/opencode.mjs +275 -46
- package/scripts/install/run-record.mjs +115 -0
- package/scripts/install/strings.mjs +35 -6
- package/scripts/install/v2-capabilities.mjs +205 -0
- package/scripts/release-gates.mjs +7 -2
- package/src/mcp/requirements-mcp.txt +1 -1
- package/src/mcp/requirements-vision.txt +1 -1
- package/src/pantheon/cost-command.ts +127 -40
- package/src/pantheon/delegation-enforce.ts +160 -23
- package/src/pantheon/guard-path.ts +162 -0
- package/src/pantheon/v2-bounded-read.ts +15 -1
- package/src/pantheon/v2-bridge.ts +27 -0
- package/src/pantheon/v2-shell-hooks.ts +260 -0
- package/src/pantheon/v2-unsupported.mjs +32 -4
- package/src/pantheon/vision.ts +6 -1
- package/src/plugin-v2.ts +388 -12
- package/src/plugin.ts +22 -2
- package/src/plugins/tui/dist/tui-v2.js +2 -2
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +11 -11
- package/src/plugins/tui/package.json +4 -3
package/src/plugin-v2.ts
CHANGED
|
@@ -88,6 +88,7 @@ import type {
|
|
|
88
88
|
ReferenceDraft,
|
|
89
89
|
} from '@opencode-ai/plugin/v2/promise'
|
|
90
90
|
import { define } from '@opencode-ai/plugin/v2/promise'
|
|
91
|
+
import { buildCompactionContext } from './pantheon/compaction-context.ts'
|
|
91
92
|
import {
|
|
92
93
|
CONTEXT_PRUNER_CONFIG_KEYS,
|
|
93
94
|
describeContextPrunerConfigIssues,
|
|
@@ -98,25 +99,43 @@ import {
|
|
|
98
99
|
} from './pantheon/context-pruner.ts'
|
|
99
100
|
import {
|
|
100
101
|
createEnforcementGuard,
|
|
102
|
+
normalizeDelegationAgent,
|
|
101
103
|
readOnlyRegistry,
|
|
102
104
|
syncReadOnlySession,
|
|
103
105
|
type ToolExecuteBeforeInput,
|
|
104
106
|
type ToolExecuteBeforeOutput,
|
|
107
|
+
zeusReadGuard,
|
|
105
108
|
} from './pantheon/delegation-enforce.ts'
|
|
109
|
+
import { GOAL_LOOP_DEFAULTS, GoalStore } from './pantheon/goal-loop.ts'
|
|
110
|
+
import { createGuardPathResolver } from './pantheon/guard-path.ts'
|
|
106
111
|
import {
|
|
107
112
|
applyMemoryInjection,
|
|
108
113
|
MemoryInjectionCache,
|
|
109
114
|
resolveMemoryInjectionConfig,
|
|
110
115
|
warnInvalidMemoryInjectionConfig,
|
|
111
116
|
} from './pantheon/memory-context.ts'
|
|
117
|
+
import { getSharedBoard } from './pantheon/shared-board.ts'
|
|
118
|
+
import {
|
|
119
|
+
TODO_ENFORCER_DEFAULTS,
|
|
120
|
+
TodoEnforcer,
|
|
121
|
+
type TodoEnforcerChild,
|
|
122
|
+
type TodoEnforcerClient,
|
|
123
|
+
type TodoEnforcerMessage,
|
|
124
|
+
type TodoLike,
|
|
125
|
+
todoEnforcerEnabledFromEnv,
|
|
126
|
+
} from './pantheon/todo-enforcer.ts'
|
|
112
127
|
import {
|
|
113
128
|
BOUNDED_READ_TOOL,
|
|
114
129
|
createV2BoundedReadTool,
|
|
115
130
|
type V2BoundedReadOriginRegistry,
|
|
116
131
|
} from './pantheon/v2-bounded-read.ts'
|
|
117
132
|
import {
|
|
133
|
+
createV2Bridge,
|
|
134
|
+
getRegisteredV2Bridge,
|
|
118
135
|
getV2BridgeFromContext,
|
|
136
|
+
injectBridge,
|
|
119
137
|
type PantheonV2Bridge,
|
|
138
|
+
registerV2Bridge,
|
|
120
139
|
type V2ContextLike,
|
|
121
140
|
} from './pantheon/v2-bridge.ts'
|
|
122
141
|
import {
|
|
@@ -129,9 +148,11 @@ import {
|
|
|
129
148
|
} from './pantheon/v2-delegation-enforce.ts'
|
|
130
149
|
import { createV2ExecuteAfter, resolveV2SandboxConfig } from './pantheon/v2-execute-after.ts'
|
|
131
150
|
import { applyV2ModelOverrides, readV2ModelConfiguration } from './pantheon/v2-model-overrides.ts'
|
|
151
|
+
import { createV2ShellHooks, type V2ShellRunner } from './pantheon/v2-shell-hooks.ts'
|
|
132
152
|
import { createV2ToolDefinitions, type V2ToolResult } from './pantheon/v2-tools.ts'
|
|
133
153
|
import { V2_UNSUPPORTED_FEATURE_SEED } from './pantheon/v2-unsupported.mjs'
|
|
134
154
|
import { buildV2VisionPromptContext, type V2VisionRuntime } from './pantheon/v2-vision.ts'
|
|
155
|
+
import { sanitizeVisionHistory } from './pantheon/vision.ts'
|
|
135
156
|
import { type HookPayload, type HookResult, runHook } from './plugins/hook-runner.ts'
|
|
136
157
|
|
|
137
158
|
// ─── Unsupported Features Registry ───────────────────────────────────────
|
|
@@ -226,6 +247,35 @@ function normalizeSystemToParts(system: unknown): unknown[] | null {
|
|
|
226
247
|
return system
|
|
227
248
|
}
|
|
228
249
|
|
|
250
|
+
/** Set once, so a payload without a `system` channel warns once per process. */
|
|
251
|
+
let compactionChannelWarned = false
|
|
252
|
+
|
|
253
|
+
/** Set once, so a failed bridge construction logs one line per process. */
|
|
254
|
+
let bridgeFailureLogged = false
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Append text blocks to a hook payload's `system` channel.
|
|
258
|
+
*
|
|
259
|
+
* Returns `false` when the payload carries no usable channel (absent, or a
|
|
260
|
+
* shape that is neither string nor array) — the caller decides whether that is
|
|
261
|
+
* worth a diagnostic. A bare-string `system` is replaced by its part array on
|
|
262
|
+
* the payload itself, because the host reads the property, not our copy.
|
|
263
|
+
*
|
|
264
|
+
* Used by the V2 compaction hook (#266) to inject the compaction context
|
|
265
|
+
* blocks V1 pushes into `output.context`.
|
|
266
|
+
*/
|
|
267
|
+
function appendSystemBlocks(
|
|
268
|
+
target: { system?: unknown } | null | undefined,
|
|
269
|
+
blocks: readonly string[],
|
|
270
|
+
): boolean {
|
|
271
|
+
if (target == null || blocks.length === 0) return false
|
|
272
|
+
const normalized = normalizeSystemToParts(target.system)
|
|
273
|
+
if (normalized == null) return false
|
|
274
|
+
if (typeof target.system === 'string') target.system = normalized
|
|
275
|
+
for (const block of blocks) normalized.push({ type: 'text', text: block } satisfies SystemPart)
|
|
276
|
+
return true
|
|
277
|
+
}
|
|
278
|
+
|
|
229
279
|
/**
|
|
230
280
|
* Add a feature to the unsupported list (idempotent).
|
|
231
281
|
*/
|
|
@@ -333,18 +383,140 @@ let v1Bridge: PantheonV2Bridge | null = null
|
|
|
333
383
|
*/
|
|
334
384
|
export function setV2Bridge(bridge: PantheonV2Bridge): void {
|
|
335
385
|
v1Bridge = bridge
|
|
386
|
+
// Also publish process-wide so a V1 load that registers FIRST and a V2 load
|
|
387
|
+
// that resolves SECOND converge on one bridge (see v2-bridge.ts).
|
|
388
|
+
registerV2Bridge(bridge)
|
|
336
389
|
}
|
|
337
390
|
|
|
338
391
|
/**
|
|
339
|
-
* Get the V1 bridge, checking module-level first, then
|
|
392
|
+
* Get the V1 bridge, checking module-level first, then the process-wide
|
|
393
|
+
* registration, then ctx.options.
|
|
340
394
|
* Returns null when no bridge is available (V2 standalone mode).
|
|
341
395
|
*/
|
|
342
396
|
function resolveBridge(ctx?: V2ContextLike): PantheonV2Bridge | null {
|
|
343
397
|
if (v1Bridge != null) return v1Bridge
|
|
398
|
+
const registered = getRegisteredV2Bridge()
|
|
399
|
+
if (registered != null) {
|
|
400
|
+
v1Bridge = registered
|
|
401
|
+
return registered
|
|
402
|
+
}
|
|
344
403
|
if (ctx != null) return getV2BridgeFromContext(ctx)
|
|
345
404
|
return null
|
|
346
405
|
}
|
|
347
406
|
|
|
407
|
+
/**
|
|
408
|
+
* The subset of the host's `session` domain a `TodoEnforcerClient` needs.
|
|
409
|
+
*
|
|
410
|
+
* Declared structurally and checked at runtime instead of being added to
|
|
411
|
+
* {@link V2SessionDomain} on faith: the measured 2.1.4 host exposes
|
|
412
|
+
* `hook`/`get`/`list`/`create`/`remove`/`prompt`/`generate`/`interrupt` on that
|
|
413
|
+
* domain. Its `prompt` takes `{ sessionID, text }` and is a DIFFERENT call from
|
|
414
|
+
* V1's `promptAsync({ path, body: { agent?, model?, parts } })` — the enforcer's
|
|
415
|
+
* agent/model inheritance has no V2 counterpart — and whether it exposes
|
|
416
|
+
* `todo`/`messages`/`children` at all is not measured by the repository. The
|
|
417
|
+
* check below therefore requires the V1 shape exactly: a client built on a
|
|
418
|
+
* method that is absent (or on a same-named method with a different contract)
|
|
419
|
+
* would throw inside the enforcer's fail-open guards and leave idle
|
|
420
|
+
* continuation silently dead again — the exact defect this wiring closes.
|
|
421
|
+
*/
|
|
422
|
+
interface V2TodoSessionMethods {
|
|
423
|
+
todo?: (input: { path: { id: string } }) => Promise<unknown>
|
|
424
|
+
messages?: (input: { path: { id: string } }) => Promise<unknown>
|
|
425
|
+
children?: (input: { path: { id: string } }) => Promise<unknown>
|
|
426
|
+
promptAsync?: (input: { path: { id: string }; body: Record<string, unknown> }) => Promise<unknown>
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const V2_TODO_CLIENT_METHODS = ['todo', 'messages', 'children', 'promptAsync'] as const
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Adapt the host's `session` domain to the {@link TodoEnforcerClient} the V1
|
|
433
|
+
* enforcer instance expects, or `undefined` when the domain does not carry the
|
|
434
|
+
* four methods. The input shape is V1's (`{ path: { id } }`) because the
|
|
435
|
+
* enforcer is the V1 instance — this is an adapter, not a second enforcer.
|
|
436
|
+
*/
|
|
437
|
+
function createV2TodoEnforcerClient(
|
|
438
|
+
session: V2SessionDomain | undefined,
|
|
439
|
+
): TodoEnforcerClient | undefined {
|
|
440
|
+
if (session === undefined) return undefined
|
|
441
|
+
const methods = session as V2TodoSessionMethods
|
|
442
|
+
for (const method of V2_TODO_CLIENT_METHODS) {
|
|
443
|
+
if (typeof methods[method] !== 'function') return undefined
|
|
444
|
+
}
|
|
445
|
+
// Every method is present: the guard above is the only place absence is
|
|
446
|
+
// tolerated, so the assertions below cannot fire at runtime.
|
|
447
|
+
const todo = methods.todo as NonNullable<V2TodoSessionMethods['todo']>
|
|
448
|
+
const messages = methods.messages as NonNullable<V2TodoSessionMethods['messages']>
|
|
449
|
+
const children = methods.children as NonNullable<V2TodoSessionMethods['children']>
|
|
450
|
+
const promptAsync = methods.promptAsync as NonNullable<V2TodoSessionMethods['promptAsync']>
|
|
451
|
+
return {
|
|
452
|
+
session: {
|
|
453
|
+
todo: (input) => todo.call(session, input) as Promise<TodoLike[]>,
|
|
454
|
+
messages: (input) => messages.call(session, input) as Promise<TodoEnforcerMessage[]>,
|
|
455
|
+
children: (input) => children.call(session, input) as Promise<TodoEnforcerChild[]>,
|
|
456
|
+
promptAsync: (input) => promptAsync.call(session, input),
|
|
457
|
+
},
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Construct the V1→V2 bridge IN the V2 entry and publish it on both channels
|
|
463
|
+
* (issue #265).
|
|
464
|
+
*
|
|
465
|
+
* Before this, `setV2Bridge`/`injectBridge`/`createV2Bridge` had no production
|
|
466
|
+
* caller: `resolveBridge()` always returned null, so `onSessionIdle` reached a
|
|
467
|
+
* null enforcer and idle continuation never ran on any V2 install — including
|
|
468
|
+
* the V1+V2 co-load, because nothing had ever put a bridge in `ctx.options`
|
|
469
|
+
* either.
|
|
470
|
+
*
|
|
471
|
+
* What is genuinely constructible without a V1 `PluginInput`:
|
|
472
|
+
*
|
|
473
|
+
* - `board` — a process-wide singleton (`getSharedBoard`), the same instance
|
|
474
|
+
* V1 and the hooks plugin use.
|
|
475
|
+
* - `todoEnforcer` — the V1 class, fed by an adapter over the host's session
|
|
476
|
+
* domain. Present only when that domain exposes the four methods the
|
|
477
|
+
* enforcer uses; otherwise the reduction is marked (`idle-todo-enforcer`)
|
|
478
|
+
* and, because the marker is one a migrating user must be told about, it
|
|
479
|
+
* is also part of the static seed.
|
|
480
|
+
*
|
|
481
|
+
* Files in the bridge that need a V1 `client` (goal loop, vision handler) stay
|
|
482
|
+
* out: `goal-tools` already declares the goal surface absent, and the vision
|
|
483
|
+
* handler is V1-only.
|
|
484
|
+
*/
|
|
485
|
+
function installV2Bridge(context: PluginContext): TodoEnforcer | undefined {
|
|
486
|
+
// Co-load guard (#265 review): a bridge with an enforcer may already exist —
|
|
487
|
+
// registered by V1 in this process, or by an earlier V2 setup. Building a
|
|
488
|
+
// second enforcer would answer the same `session.idle` twice (V1's dispatcher
|
|
489
|
+
// and this plugin each inject a continuation prompt). Reuse, never overwrite.
|
|
490
|
+
const existing = resolveBridge(context)
|
|
491
|
+
if (existing?.todoEnforcer !== undefined) {
|
|
492
|
+
injectBridge(context, existing)
|
|
493
|
+
return existing.todoEnforcer
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const todoClient = createV2TodoEnforcerClient(hostDomains(context).session)
|
|
497
|
+
if (todoClient === undefined) markUnsupported('idle-todo-enforcer')
|
|
498
|
+
const board = getSharedBoard()
|
|
499
|
+
const todoEnforcer =
|
|
500
|
+
todoClient === undefined
|
|
501
|
+
? undefined
|
|
502
|
+
: new TodoEnforcer({
|
|
503
|
+
client: todoClient,
|
|
504
|
+
board,
|
|
505
|
+
options: { ...TODO_ENFORCER_DEFAULTS, enabled: todoEnforcerEnabledFromEnv() },
|
|
506
|
+
})
|
|
507
|
+
const bridge = createV2Bridge({ board, ...(todoEnforcer === undefined ? {} : { todoEnforcer }) })
|
|
508
|
+
// Two channels, both needed: `ctx.options` is what a handler holding the
|
|
509
|
+
// context reads (`resolveBridge(ctx)`), and the module-level reference is
|
|
510
|
+
// what the event handlers use, since they receive no context.
|
|
511
|
+
injectBridge(context, bridge)
|
|
512
|
+
setV2Bridge(bridge)
|
|
513
|
+
// Returned so the compaction hook can list the session's PENDING TODOS with
|
|
514
|
+
// the same instance — the `<todo_context>` half of V1's compaction blocks
|
|
515
|
+
// needs exactly `listPendingTodos`, and the host exposes no todo listing of
|
|
516
|
+
// its own.
|
|
517
|
+
return todoEnforcer
|
|
518
|
+
}
|
|
519
|
+
|
|
348
520
|
// ─── V2 Transform Functions ─────────────────────────────────────────────
|
|
349
521
|
|
|
350
522
|
function transformAgents(draft: AgentDraft): void {
|
|
@@ -656,10 +828,11 @@ async function onSessionIdle(_event: V2SessionEvent): Promise<void> {
|
|
|
656
828
|
// ever arrives. Implementing this safely needs V2-side session threading
|
|
657
829
|
// first; until then it stays deferred rather than approximated.
|
|
658
830
|
//
|
|
659
|
-
// Idle continuation — goal loop / todo enforcer dispatch.
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
//
|
|
831
|
+
// Idle continuation — goal loop / todo enforcer dispatch. The bridge is
|
|
832
|
+
// constructed by THIS module in `installV2Bridge` (Phase 0) and holds the
|
|
833
|
+
// V1 TodoEnforcer instance when the host's session domain exposes the
|
|
834
|
+
// methods the enforcer uses. Before issue #265 nothing injected a bridge on
|
|
835
|
+
// the V2 path, so this call was a guaranteed no-op on every install.
|
|
663
836
|
const sessionID = _event.properties?.sessionID as string | undefined
|
|
664
837
|
if (!sessionID) return
|
|
665
838
|
const bridge = resolveBridge()
|
|
@@ -827,6 +1000,16 @@ function warnContextPrunerConfigOnce(options: unknown): void {
|
|
|
827
1000
|
*/
|
|
828
1001
|
const memoryInjectionCache = new MemoryInjectionCache()
|
|
829
1002
|
|
|
1003
|
+
/**
|
|
1004
|
+
* Empty description cache for {@link sanitizeVisionHistory}.
|
|
1005
|
+
*
|
|
1006
|
+
* V1 fills this from the vision handler (per-part text captured at
|
|
1007
|
+
* `chat.message` time). V2 has no equivalent cache, so the sanitizer falls back
|
|
1008
|
+
* to its own placeholder text for every image part — which is the contract that
|
|
1009
|
+
* matters: an image never reaches the provider as image content.
|
|
1010
|
+
*/
|
|
1011
|
+
const V2_VISION_HISTORY_TEXT: ReadonlyMap<string, ReadonlyMap<string, string>> = new Map()
|
|
1012
|
+
|
|
830
1013
|
/**
|
|
831
1014
|
* Register session hooks via V2 ctx.session.hook.
|
|
832
1015
|
*
|
|
@@ -912,6 +1095,24 @@ async function registerV2SessionHooks(context: PluginContext): Promise<boolean>
|
|
|
912
1095
|
appendV2HookLog,
|
|
913
1096
|
)
|
|
914
1097
|
}
|
|
1098
|
+
// Vision history sanitization (V1
|
|
1099
|
+
// `experimental.chat.messages.transform` parity, #266). Image parts are
|
|
1100
|
+
// replaced with their cached description, or with the same placeholder
|
|
1101
|
+
// V1 uses, BEFORE a text-only provider serializer can turn them into
|
|
1102
|
+
// `image_url` content. The host's `context` payload carries the
|
|
1103
|
+
// provider-bound `messages` array and honors mutations per request, so
|
|
1104
|
+
// this is the same seam V1's transform occupies.
|
|
1105
|
+
//
|
|
1106
|
+
// The description map is empty on V2 by construction: descriptions are
|
|
1107
|
+
// cached by the V1 vision handler, which has no V2 counterpart (V2
|
|
1108
|
+
// materializes the image and asks the model to call `vision_describe`).
|
|
1109
|
+
// Every image part therefore becomes the placeholder — the safety
|
|
1110
|
+
// property V1's transform exists for — never a raw image.
|
|
1111
|
+
try {
|
|
1112
|
+
sanitizeVisionHistory({ messages: ctx.messages }, V2_VISION_HISTORY_TEXT)
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
logPruneFailureOnce(ctx.sessionID, 'context', error)
|
|
1115
|
+
}
|
|
915
1116
|
// Opt-in DCP: same engine as the compaction site, but per-request
|
|
916
1117
|
// pruning invalidates the prompt cache, so it runs only when
|
|
917
1118
|
// `context_pruner.enabled` is explicitly true. Disabled = the hook is
|
|
@@ -1316,9 +1517,20 @@ interface V2ToolExecuteBeforeEvent {
|
|
|
1316
1517
|
*
|
|
1317
1518
|
* Omitting all three skips the branch wholesale: the guard only enters it when
|
|
1318
1519
|
* `options?.isRootSession !== undefined`. `task` is still denied inside a
|
|
1319
|
-
* read-only session via the blocked-tool list, so depth-2
|
|
1320
|
-
* apollo/gaia
|
|
1321
|
-
*
|
|
1520
|
+
* read-only session via the blocked-tool list, so the read-only half of depth-2
|
|
1521
|
+
* holds for apollo/gaia.
|
|
1522
|
+
*
|
|
1523
|
+
* The caller/target half is NOT this guard's job on V2, and that is a division
|
|
1524
|
+
* of labour rather than a gap: V2 delegates through the native `subagent` tool
|
|
1525
|
+
* and its `permission.hook('evaluate')` handler, which calls
|
|
1526
|
+
* `evaluateV2Delegation` — the matrix (zeus → anyone; athena/hermes → apollo)
|
|
1527
|
+
* plus the same depth-2 rule, expressed as "a caller session that carries a
|
|
1528
|
+
* `parentID` is denied". Both are proved in
|
|
1529
|
+
* tests/pantheon/plugin-v2-contract.test.ts and
|
|
1530
|
+
* tests/pantheon/v2-delegation-enforce.test.ts.
|
|
1531
|
+
*
|
|
1532
|
+
* The Zeus read guard is a SEPARATE call in the same `execute.before` handler
|
|
1533
|
+
* (issue #264), fed from the same event `agent`; it is not part of this guard.
|
|
1322
1534
|
*/
|
|
1323
1535
|
const v2EnforcementGuard = createEnforcementGuard({
|
|
1324
1536
|
getReadOnlySessions: () => readOnlyRegistry.sessionIDs(),
|
|
@@ -1358,6 +1570,35 @@ function adaptV2ExecuteBeforeEvent(event: unknown): {
|
|
|
1358
1570
|
}
|
|
1359
1571
|
}
|
|
1360
1572
|
|
|
1573
|
+
/**
|
|
1574
|
+
* Test seam — override (or, with `null`, restore) the V2 shell-hook runner.
|
|
1575
|
+
*
|
|
1576
|
+
* Exported only for tests/pantheon/plugin-v2-contract.test.ts, which asserts
|
|
1577
|
+
* that the REGISTERED `execute.before`/`execute.after` handlers invoke the
|
|
1578
|
+
* formatter and the delegation audit scripts. Spawning the real scripts would
|
|
1579
|
+
* make the assertion depend on the shell, not on the wiring; the scripts
|
|
1580
|
+
* themselves are covered by tests/pantheon/v2-shell-hooks.test.ts.
|
|
1581
|
+
*/
|
|
1582
|
+
export function setV2ShellRunnerForTests(runner: V2ShellRunner | null): void {
|
|
1583
|
+
shellRunnerOverride = runner ?? undefined
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
let shellRunnerOverride: V2ShellRunner | undefined
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Test seam — clear the module-level bridge AND the process-wide registration.
|
|
1590
|
+
*
|
|
1591
|
+
* Exported only for tests/pantheon/plugin-v2-contract.test.ts. The co-load guard
|
|
1592
|
+
* makes `installV2Bridge` reuse an existing bridge (so V1's enforcer is never
|
|
1593
|
+
* duplicated), which means a test that asserts the CONSTRUCTION path has to
|
|
1594
|
+
* start from "no bridge". Production has no caller: a process keeps its bridge
|
|
1595
|
+
* for its lifetime.
|
|
1596
|
+
*/
|
|
1597
|
+
export function resetV2BridgeForTests(): void {
|
|
1598
|
+
v1Bridge = null
|
|
1599
|
+
registerV2Bridge(null)
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1361
1602
|
/**
|
|
1362
1603
|
* Register tool execution hooks via V2 ctx.tool.hook.
|
|
1363
1604
|
*
|
|
@@ -1372,12 +1613,27 @@ async function registerV2ToolHooks(
|
|
|
1372
1613
|
subagentOrigins: V2SubagentOriginRegistry,
|
|
1373
1614
|
boundedReadOrigins?: V2BoundedReadOriginRegistry,
|
|
1374
1615
|
): Promise<{ registered: boolean; beforeRegistered: boolean }> {
|
|
1375
|
-
const
|
|
1616
|
+
const host = hostDomains(context)
|
|
1617
|
+
const toolCtx = host.tool
|
|
1376
1618
|
|
|
1377
1619
|
if (!toolCtx?.hook) {
|
|
1378
1620
|
return { registered: false, beforeRegistered: false }
|
|
1379
1621
|
}
|
|
1380
1622
|
|
|
1623
|
+
// V1 shell-hook parity (#266): formatter on every after-event, delegation
|
|
1624
|
+
// audit start/stop. Both scripts are environment-independent, so they are
|
|
1625
|
+
// invoked through the same runner the secret scan uses.
|
|
1626
|
+
const shellHooks = createV2ShellHooks({
|
|
1627
|
+
...(shellRunnerOverride === undefined ? {} : { run: shellRunnerOverride }),
|
|
1628
|
+
onUnkeyed: appendV2HookLog,
|
|
1629
|
+
})
|
|
1630
|
+
|
|
1631
|
+
// Symlink resolution for the Zeus read guard (#272). The predicate is pure,
|
|
1632
|
+
// so the filesystem work happens at this call site, rooted at the project
|
|
1633
|
+
// directory the host reports. Same mechanism as V1's (src/plugin.ts) so the
|
|
1634
|
+
// two registration paths stay consistent.
|
|
1635
|
+
const resolveGuardPath = createGuardPathResolver(host.location?.directory || process.cwd())
|
|
1636
|
+
|
|
1381
1637
|
let registered = false
|
|
1382
1638
|
let beforeRegistered = false
|
|
1383
1639
|
|
|
@@ -1401,6 +1657,24 @@ async function registerV2ToolHooks(
|
|
|
1401
1657
|
// and no session→agent map. A non-read-only (or absent) agent revokes the
|
|
1402
1658
|
// registration, which also covers an in-session agent switch.
|
|
1403
1659
|
syncReadOnlySession(readOnlyRegistry, input.sessionID, agent)
|
|
1660
|
+
// Zeus read guard (issue #264). V1 wires this from its `chat.params`
|
|
1661
|
+
// session→agent map (`src/plugin.ts`); V2 has no such map because the
|
|
1662
|
+
// host puts the active agent on THIS event, so the guard is fed from
|
|
1663
|
+
// the event's `agent` field — the same identity the read-only
|
|
1664
|
+
// registry above already trusts.
|
|
1665
|
+
//
|
|
1666
|
+
// Fail-closed on casing: `zeusReadGuard` compares the agent with an
|
|
1667
|
+
// exact `!== 'zeus'`, so a host that reports `Zeus` would silently
|
|
1668
|
+
// disable the guard. Normalizing through the shared
|
|
1669
|
+
// `normalizeDelegationAgent` keeps the comparison meaningful without
|
|
1670
|
+
// changing the predicate V1 uses.
|
|
1671
|
+
//
|
|
1672
|
+
// Runs BEFORE the read-only guard, matching V1's chain order. Both
|
|
1673
|
+
// throw to deny; neither is inside the scanner's try/catch, so a
|
|
1674
|
+
// denial keeps propagating to the host. The resolver is V1's too:
|
|
1675
|
+
// every TARGET path is also checked in its SYMLINK-RESOLVED form
|
|
1676
|
+
// (#272), and a resolution failure denies.
|
|
1677
|
+
zeusReadGuard(input.tool, output.args, normalizeDelegationAgent(agent), resolveGuardPath)
|
|
1404
1678
|
// Deliberately OUTSIDE the try/catch below: a read-only denial must keep
|
|
1405
1679
|
// propagating to the host, not be swallowed as a scanner failure.
|
|
1406
1680
|
await v2EnforcementGuard(input, output)
|
|
@@ -1469,6 +1743,10 @@ async function registerV2ToolHooks(
|
|
|
1469
1743
|
if (origin !== undefined) {
|
|
1470
1744
|
writeV2AdmissionProof('tool.execute.before', { ...origin })
|
|
1471
1745
|
}
|
|
1746
|
+
// Delegation audit START record (#266). Deliberately AFTER every guard
|
|
1747
|
+
// and the secret scan: a denied call must not leave a start record with
|
|
1748
|
+
// no matching stop. The formatter/stop halves run in `execute.after`.
|
|
1749
|
+
await shellHooks.before(event)
|
|
1472
1750
|
} finally {
|
|
1473
1751
|
// BENCH instrumentation — observation only; runs on the deny paths too.
|
|
1474
1752
|
logBenchHookTiming('before', event, benchStartedAt)
|
|
@@ -1499,6 +1777,10 @@ async function registerV2ToolHooks(
|
|
|
1499
1777
|
subagentOrigins.forget(event)
|
|
1500
1778
|
boundedReadOrigins?.forget(event)
|
|
1501
1779
|
await v2ExecuteAfter(event)
|
|
1780
|
+
// Formatter + delegation audit STOP (#266). Awaited for the same
|
|
1781
|
+
// reason V1 awaits it: the log record should exist before the tool
|
|
1782
|
+
// result is surfaced. Failures are swallowed inside the module.
|
|
1783
|
+
await shellHooks.after(event)
|
|
1502
1784
|
} finally {
|
|
1503
1785
|
// BENCH instrumentation — observation only; the awaited call means the
|
|
1504
1786
|
// duration covers the whole parity chain, not just its dispatch.
|
|
@@ -1778,6 +2060,39 @@ export const plugin = define({
|
|
|
1778
2060
|
id: 'pantheon-opencode-v2',
|
|
1779
2061
|
|
|
1780
2062
|
async setup(context: PluginContext): Promise<void> {
|
|
2063
|
+
// ─── Phase 0: V1→V2 bridge (issue #265) ────────────────────────────
|
|
2064
|
+
// First, because the event subscription below can deliver `session.idle`
|
|
2065
|
+
// as soon as it starts: a bridge installed after it would lose the first
|
|
2066
|
+
// idle of the process. Constructing it here is what makes
|
|
2067
|
+
// `resolveBridge()` non-null on a V2 install — before this, the factory
|
|
2068
|
+
// and the injector had no production call site at all.
|
|
2069
|
+
//
|
|
2070
|
+
// The returned enforcer (when the host session domain supports it) is the
|
|
2071
|
+
// single instance: Phase 7 asks it for pending todos and the idle path asks
|
|
2072
|
+
// it to continue, so there are never two.
|
|
2073
|
+
//
|
|
2074
|
+
// Guarded, because this phase is the only one that MUTATES the context:
|
|
2075
|
+
// `injectBridge` writes `ctx.options`, and an unguarded throw here would
|
|
2076
|
+
// reject `setup()` and remove every later registration with it — the read
|
|
2077
|
+
// guard, the secret scan and all tools. A degraded run is far better than a
|
|
2078
|
+
// plugin that registers nothing, and the degradation is reported (`v1-bridge`
|
|
2079
|
+
// in the live unsupported list) instead of being invisible.
|
|
2080
|
+
let idleEnforcer: TodoEnforcer | undefined
|
|
2081
|
+
try {
|
|
2082
|
+
idleEnforcer = installV2Bridge(context)
|
|
2083
|
+
} catch (error) {
|
|
2084
|
+
idleEnforcer = undefined
|
|
2085
|
+
markUnsupported('v1-bridge')
|
|
2086
|
+
if (!bridgeFailureLogged) {
|
|
2087
|
+
bridgeFailureLogged = true
|
|
2088
|
+
const reason = error instanceof Error ? error.message : String(error)
|
|
2089
|
+
appendV2HookLog(
|
|
2090
|
+
`[v1-bridge] construction failed; continuing without a bridge ` +
|
|
2091
|
+
`(idle continuation and todo context unavailable): ${reason}`,
|
|
2092
|
+
)
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
1781
2096
|
// ─── Phase 1: V2 Transforms (isolated per-domain, best-effort) ────
|
|
1782
2097
|
// Each transform registration is individually wrapped and settled via Promise.allSettled:
|
|
1783
2098
|
// a rejection marks only that transform unsupported
|
|
@@ -1858,13 +2173,17 @@ export const plugin = define({
|
|
|
1858
2173
|
// ─── Phase 7: V2 Compaction Hook (best-effort) ───────────────────
|
|
1859
2174
|
const compactionCtx = hostDomains(context).session
|
|
1860
2175
|
if (compactionCtx?.hook) {
|
|
2176
|
+
// File-based goal store, constructed once: the compaction context needs
|
|
2177
|
+
// active goals per session, and the store needs no host API (same
|
|
2178
|
+
// `.pantheon/goals` directory V1 uses).
|
|
2179
|
+
const goalStore = new GoalStore({ dir: '.pantheon/goals' })
|
|
1861
2180
|
try {
|
|
1862
2181
|
// 2.0.16 `SessionHooks` key is `compaction` (the migration doc maps
|
|
1863
2182
|
// `experimental.session.compacting` → `ctx.session.hook("compaction")`).
|
|
1864
2183
|
// `compacting` is not a valid key: the registry accepts any string and
|
|
1865
2184
|
// silently drops unknown names, so the old name was a permanent no-op.
|
|
1866
2185
|
// Proven by the canary's negative control.
|
|
1867
|
-
await compactionCtx.hook('compaction', (event: unknown) => {
|
|
2186
|
+
await compactionCtx.hook('compaction', async (event: unknown) => {
|
|
1868
2187
|
try {
|
|
1869
2188
|
// Opt-in lifetime proof for the host-backed hook canary
|
|
1870
2189
|
// (tests/pantheon/plugin-v2-hook-canary.test.mjs, MODE=real). It is
|
|
@@ -1889,11 +2208,68 @@ export const plugin = define({
|
|
|
1889
2208
|
// untouched. Apply the rules by default: it only changes what feeds
|
|
1890
2209
|
// the summary. Never set `input.result`: the model must summarize
|
|
1891
2210
|
// the pruned history, not be replaced by a canned summary.
|
|
1892
|
-
|
|
2211
|
+
//
|
|
2212
|
+
// The host's compaction payload is
|
|
2213
|
+
// `{ session, agent, model, tools, system, messages, … }` — the id
|
|
2214
|
+
// is on `session.id`, NOT top-level `sessionID` (measured against
|
|
2215
|
+
// the 2.1.4 host; both spellings are accepted below).
|
|
2216
|
+
const payload = event as {
|
|
2217
|
+
sessionID?: unknown
|
|
2218
|
+
session?: { id?: unknown }
|
|
2219
|
+
messages?: unknown
|
|
2220
|
+
system?: unknown
|
|
2221
|
+
} | null
|
|
2222
|
+
const sessionID =
|
|
2223
|
+
typeof payload?.sessionID === 'string'
|
|
2224
|
+
? payload.sessionID
|
|
2225
|
+
: typeof payload?.session?.id === 'string'
|
|
2226
|
+
? payload.session.id
|
|
2227
|
+
: undefined
|
|
1893
2228
|
const prunerConfig = resolveContextPrunerConfig(context.options)
|
|
1894
2229
|
const stats = pruneMessages(payload?.messages, prunerConfig, 'compaction')
|
|
1895
2230
|
logContextPrune(stats)
|
|
1896
|
-
logPruneShapeIssue(stats,
|
|
2231
|
+
logPruneShapeIssue(stats, sessionID, 'compaction')
|
|
2232
|
+
|
|
2233
|
+
// Compaction context (V1 `experimental.session.compacting`
|
|
2234
|
+
// parity, #266). The SAME builder V1 uses — directive +
|
|
2235
|
+
// `<mission_context>` — pushed into the payload's `system` array,
|
|
2236
|
+
// which is the only text sink the V2 compaction hook exposes
|
|
2237
|
+
// (`context` is the session-hook name in V1, not a field here).
|
|
2238
|
+
//
|
|
2239
|
+
// The `<todo_context>` section is present only when the bridge
|
|
2240
|
+
// built a real enforcer (host session domain exposes the todo
|
|
2241
|
+
// listing), and `<tool_ceiling>` has no V2 producer at all — both
|
|
2242
|
+
// reductions are declared in the capability seed instead of
|
|
2243
|
+
// silently missing.
|
|
2244
|
+
const blocks = await buildCompactionContext({
|
|
2245
|
+
...(sessionID === undefined ? {} : { sessionID }),
|
|
2246
|
+
goals: {
|
|
2247
|
+
// Same gate V1 uses: the goal loop is disabled in this build,
|
|
2248
|
+
// so `<mission_context>` is omitted on both surfaces.
|
|
2249
|
+
enabled: GOAL_LOOP_DEFAULTS.enabled,
|
|
2250
|
+
list: (id: string) => goalStore.list(id),
|
|
2251
|
+
},
|
|
2252
|
+
...(idleEnforcer === undefined
|
|
2253
|
+
? {}
|
|
2254
|
+
: {
|
|
2255
|
+
todos: {
|
|
2256
|
+
// V1's own source: `TodoEnforcer.listPendingTodos`.
|
|
2257
|
+
enabled: todoEnforcerEnabledFromEnv(),
|
|
2258
|
+
list: (id: string) => idleEnforcer.listPendingTodos(id),
|
|
2259
|
+
},
|
|
2260
|
+
}),
|
|
2261
|
+
})
|
|
2262
|
+
if (blocks.length > 0 && !appendSystemBlocks(payload, blocks)) {
|
|
2263
|
+
// The payload carried no usable `system`. Diagnostic once per
|
|
2264
|
+
// process: a silent miss here would look like "no goals".
|
|
2265
|
+
if (!compactionChannelWarned) {
|
|
2266
|
+
compactionChannelWarned = true
|
|
2267
|
+
appendV2HookLog(
|
|
2268
|
+
'[compaction-context] payload.system is not a string or array; ' +
|
|
2269
|
+
'compaction context could not be injected',
|
|
2270
|
+
)
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
1897
2273
|
} catch (error) {
|
|
1898
2274
|
// Fail-open: any unexpected shape or engine failure must not kill
|
|
1899
2275
|
// the compaction request. One diagnostic line per session maximum.
|
package/src/plugin.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
zeusReadGuard,
|
|
19
19
|
} from './pantheon/delegation-enforce.ts'
|
|
20
20
|
import { GOAL_LOOP_DEFAULTS, GoalLoop, GoalStore } from './pantheon/goal-loop.ts'
|
|
21
|
+
import { createGuardPathResolver } from './pantheon/guard-path.ts'
|
|
21
22
|
import { createReadEnhancer } from './pantheon/hashline/read-enhancer.ts'
|
|
22
23
|
import { createHashlineEditTool } from './pantheon/hashline/tool.ts'
|
|
23
24
|
import { createIdleDispatcher } from './pantheon/idle-continuation.ts'
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
import { TodoPreserver } from './pantheon/todo-preserve.ts'
|
|
38
39
|
import { handleToolCeilingEvent, type ToolCeilingResult } from './pantheon/tool-ceiling.ts'
|
|
39
40
|
import { checkTuiVersionStaleness } from './pantheon/tui-version-check.ts'
|
|
41
|
+
import { createV2Bridge, registerV2Bridge } from './pantheon/v2-bridge.ts'
|
|
40
42
|
import { activePresetCandidates, createVisionHandler } from './pantheon/vision.ts'
|
|
41
43
|
|
|
42
44
|
// ─── Background Job Board Singleton ────────────────────────────────────
|
|
@@ -279,6 +281,14 @@ const plugin: Plugin = async (input: PluginInput) => {
|
|
|
279
281
|
// Runtime TUI version staleness check — warns if the copied TUI plugin
|
|
280
282
|
// is older than the installed package. Runs once, fail-open, no auto-sync.
|
|
281
283
|
checkTuiVersionStaleness((msg) => log.warn(msg))
|
|
284
|
+
// Symlink resolution for the Zeus read guard (#272). The guard predicate is
|
|
285
|
+
// pure and synchronous, so the filesystem work happens here instead: one
|
|
286
|
+
// resolver per plugin instance, rooted at the project directory the host
|
|
287
|
+
// reported. `docs/link → ../src` must not read `src/` just because the
|
|
288
|
+
// string path looks harmless.
|
|
289
|
+
const resolveGuardPath = createGuardPathResolver(
|
|
290
|
+
input.directory || input.worktree || process.cwd(),
|
|
291
|
+
)
|
|
282
292
|
const vision = createVisionHandler(input)
|
|
283
293
|
// Wave 1 (PR #46): TODO continuation enforcer for root sessions. The event
|
|
284
294
|
// hook routes `session.idle` events here; an active goal owns the idle
|
|
@@ -316,6 +326,14 @@ const plugin: Plugin = async (input: PluginInput) => {
|
|
|
316
326
|
const goalTools = goalLoop.tools()
|
|
317
327
|
const idleDispatcher = createIdleDispatcher({ goalLoop, todoEnforcer })
|
|
318
328
|
|
|
329
|
+
// Cross-generation bridge (issue #265 review): publish THESE singletons so a
|
|
330
|
+
// V2 plugin loaded in the same process reuses this enforcer instead of
|
|
331
|
+
// building a second one. Two enforcers would answer one `session.idle` twice
|
|
332
|
+
// — V1's dispatcher below and V2's `onSessionIdle` would each inject a
|
|
333
|
+
// continuation prompt. Registration is a no-op on a V1-only install: nothing
|
|
334
|
+
// in this process reads the registry unless a V2 entry resolves it.
|
|
335
|
+
registerV2Bridge(createV2Bridge({ board, todoEnforcer }))
|
|
336
|
+
|
|
319
337
|
// Wave 2 (PR #46): hashline — tag-anchored edits. The read enhancer
|
|
320
338
|
// (tool.execute.after) augments `read` output with per-line sha256 tags
|
|
321
339
|
// (`12#XJ|content`); hashline_edit anchors edits to those refs. Additive —
|
|
@@ -478,8 +496,10 @@ const plugin: Plugin = async (input: PluginInput) => {
|
|
|
478
496
|
// read-only enforcement guard (denies mutating tools in read-only
|
|
479
497
|
// sessions), then release-134 Phase 3 rewrites the first
|
|
480
498
|
// post-compaction `todowrite` with the captured todo snapshot. All are
|
|
481
|
-
// no-ops for non-matching sessions/tools.
|
|
482
|
-
|
|
499
|
+
// no-ops for non-matching sessions/tools. The read guard also checks the
|
|
500
|
+
// SYMLINK-RESOLVED form of every target path (#272), so a link into a
|
|
501
|
+
// denied root cannot pass on its string spelling.
|
|
502
|
+
zeusReadGuard(input.tool, output?.args, sessionAgents.get(input.sessionID), resolveGuardPath)
|
|
483
503
|
await enforcementGuard(input, output)
|
|
484
504
|
await commandNormalizer(input, output)
|
|
485
505
|
await todoPreserver.beforeTodoWrite(input, output)
|
|
@@ -2986,7 +2986,7 @@ function Sidebar(props) {
|
|
|
2986
2986
|
setProp(_el$0, "width", "100%");
|
|
2987
2987
|
setProp(_el$0, "padding", 1);
|
|
2988
2988
|
setProp(_el$1, "attributes", 1);
|
|
2989
|
-
insert(_el$1, `Pantheon v1.6.
|
|
2989
|
+
insert(_el$1, `Pantheon v1.6.1`);
|
|
2990
2990
|
insert(_el$10, () => presetHeaderLine(model.preset().name ?? "", model.provider()));
|
|
2991
2991
|
insert(_el$0, createComponent(Show, {
|
|
2992
2992
|
get when() {
|
|
@@ -3685,7 +3685,7 @@ function HomeStatus(props) {
|
|
|
3685
3685
|
const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
|
|
3686
3686
|
return (() => {
|
|
3687
3687
|
var _el$66 = createElement("text");
|
|
3688
|
-
insert(_el$66, () => `Pantheon v1.6.
|
|
3688
|
+
insert(_el$66, () => `Pantheon v1.6.1${preset().name ? ` ▸ ${preset().name}` : ""}`);
|
|
3689
3689
|
effect((_$p) => setProp(_el$66, "fg", muted(), _$p));
|
|
3690
3690
|
return _el$66;
|
|
3691
3691
|
})();
|