pantheon-opencode 1.6.2-beta.4 → 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 +8 -0
- package/README.md +174 -3
- package/bin/pantheon-init.mjs +6 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +3 -3
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +268 -46
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +158 -11
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/versioning.mjs +41 -5
- 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-prompt.ts +181 -36
- package/src/pantheon/local-decision-skills.ts +115 -5
- package/src/pantheon/local-decision-tool.ts +35 -1
- 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 +21 -2
- package/src/plugin-v2.ts +305 -3
- 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
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V2 decision telemetry — allowlist sanitisation, closing defect D10.
|
|
3
|
+
*
|
|
4
|
+
* Telemetry must never carry prompt, response, user content, credentials or
|
|
5
|
+
* free-form text. The strongest way to guarantee that is not to scrub known
|
|
6
|
+
* keys but to accept only a small allowlist whose values are constrained to
|
|
7
|
+
* short tokens and bounded numbers:
|
|
8
|
+
*
|
|
9
|
+
* schemaVersion, point, decision, effect, reason, mode, durationMs, candidateCount
|
|
10
|
+
*
|
|
11
|
+
* Any other key is dropped and only a count is reported. Neither the key nor
|
|
12
|
+
* its value is ever copied into the result, so no attacker-controlled string
|
|
13
|
+
* reaches telemetry through a rejection path.
|
|
14
|
+
*
|
|
15
|
+
* `effect` is fixed to `'none'`. An event that claims anything else is rejected
|
|
16
|
+
* outright: this layer has no measured effect to report, and silently rewriting
|
|
17
|
+
* the claim would hide the caller's error.
|
|
18
|
+
*
|
|
19
|
+
* The sink is in-memory and bounded. It performs no I/O, so the offline harness
|
|
20
|
+
* can assert exactly what would be emitted.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { DecisionPointId } from './v2-decision-registry.ts'
|
|
24
|
+
|
|
25
|
+
export const TELEMETRY_SCHEMA_VERSION = 1
|
|
26
|
+
export const TELEMETRY_FIELDS = [
|
|
27
|
+
'schemaVersion',
|
|
28
|
+
'point',
|
|
29
|
+
'decision',
|
|
30
|
+
'effect',
|
|
31
|
+
'reason',
|
|
32
|
+
'mode',
|
|
33
|
+
'durationMs',
|
|
34
|
+
'candidateCount',
|
|
35
|
+
] as const
|
|
36
|
+
|
|
37
|
+
export type TelemetryField = (typeof TELEMETRY_FIELDS)[number]
|
|
38
|
+
export type TelemetryMode = 'shadow' | 'active' | 'off' | 'migration'
|
|
39
|
+
|
|
40
|
+
export interface DecisionTelemetryEvent {
|
|
41
|
+
readonly schemaVersion: typeof TELEMETRY_SCHEMA_VERSION
|
|
42
|
+
readonly point: DecisionPointId
|
|
43
|
+
readonly decision: string
|
|
44
|
+
readonly effect: 'none'
|
|
45
|
+
readonly reason: string
|
|
46
|
+
readonly mode?: TelemetryMode
|
|
47
|
+
readonly durationMs?: number
|
|
48
|
+
readonly candidateCount?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type TelemetryRejection = 'INVALID_INPUT' | 'MISSING_REQUIRED_FIELD' | 'EFFECT_NOT_MEASURED'
|
|
52
|
+
|
|
53
|
+
export type TelemetryResult =
|
|
54
|
+
| {
|
|
55
|
+
readonly ok: true
|
|
56
|
+
readonly event: DecisionTelemetryEvent
|
|
57
|
+
readonly droppedFieldCount: number
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
readonly ok: false
|
|
61
|
+
readonly reasonCode: TelemetryRejection
|
|
62
|
+
readonly droppedFieldCount: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const TOKEN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/
|
|
66
|
+
const POINT_ID = /^P(?:[1-9]|1[01])$/
|
|
67
|
+
const TELEMETRY_KEYS: ReadonlySet<string> = new Set(TELEMETRY_FIELDS)
|
|
68
|
+
const MODES: ReadonlySet<string> = new Set(['shadow', 'active', 'off', 'migration'])
|
|
69
|
+
const DURATION_MAX_MS = 60_000
|
|
70
|
+
const CANDIDATE_MAX = 10_000
|
|
71
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
72
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isToken(value: unknown): value is string {
|
|
76
|
+
return typeof value === 'string' && TOKEN.test(value)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isPointId(value: unknown): value is DecisionPointId {
|
|
80
|
+
return typeof value === 'string' && POINT_ID.test(value)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function rejected(reasonCode: TelemetryRejection, droppedFieldCount: number): TelemetryResult {
|
|
84
|
+
return { ok: false, reasonCode, droppedFieldCount }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Reduce an arbitrary record to the telemetry allowlist.
|
|
89
|
+
*
|
|
90
|
+
* Required survivors: `point`, `decision` and `reason`. `effect`, when present,
|
|
91
|
+
* must already be `'none'`; the output always carries `'none'`.
|
|
92
|
+
*/
|
|
93
|
+
export function sanitizeTelemetry(input: unknown): TelemetryResult {
|
|
94
|
+
if (!isRecord(input)) return rejected('INVALID_INPUT', 0)
|
|
95
|
+
|
|
96
|
+
let droppedFieldCount = 0
|
|
97
|
+
const drop = (): void => {
|
|
98
|
+
droppedFieldCount += 1
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let point: DecisionPointId | null = null
|
|
102
|
+
let decision: string | null = null
|
|
103
|
+
let reason: string | null = null
|
|
104
|
+
let mode: TelemetryMode | null = null
|
|
105
|
+
let durationMs: number | null = null
|
|
106
|
+
let candidateCount: number | null = null
|
|
107
|
+
let effectNotMeasured = false
|
|
108
|
+
|
|
109
|
+
for (const key of Object.keys(input).sort()) {
|
|
110
|
+
const value = input[key]
|
|
111
|
+
if (!TELEMETRY_KEYS.has(key)) {
|
|
112
|
+
drop()
|
|
113
|
+
continue
|
|
114
|
+
}
|
|
115
|
+
switch (key) {
|
|
116
|
+
case 'schemaVersion':
|
|
117
|
+
if (value !== TELEMETRY_SCHEMA_VERSION) drop()
|
|
118
|
+
break
|
|
119
|
+
case 'point':
|
|
120
|
+
if (isPointId(value)) point = value
|
|
121
|
+
else drop()
|
|
122
|
+
break
|
|
123
|
+
case 'decision':
|
|
124
|
+
if (isToken(value)) decision = value
|
|
125
|
+
else drop()
|
|
126
|
+
break
|
|
127
|
+
case 'reason':
|
|
128
|
+
if (isToken(value)) reason = value
|
|
129
|
+
else drop()
|
|
130
|
+
break
|
|
131
|
+
case 'mode':
|
|
132
|
+
if (typeof value === 'string' && MODES.has(value)) {
|
|
133
|
+
mode = value as TelemetryMode
|
|
134
|
+
} else {
|
|
135
|
+
drop()
|
|
136
|
+
}
|
|
137
|
+
break
|
|
138
|
+
case 'durationMs':
|
|
139
|
+
if (
|
|
140
|
+
typeof value === 'number' &&
|
|
141
|
+
Number.isFinite(value) &&
|
|
142
|
+
value >= 0 &&
|
|
143
|
+
value <= DURATION_MAX_MS
|
|
144
|
+
) {
|
|
145
|
+
durationMs = value
|
|
146
|
+
} else {
|
|
147
|
+
drop()
|
|
148
|
+
}
|
|
149
|
+
break
|
|
150
|
+
case 'candidateCount':
|
|
151
|
+
if (
|
|
152
|
+
Number.isInteger(value) &&
|
|
153
|
+
(value as number) >= 0 &&
|
|
154
|
+
(value as number) <= CANDIDATE_MAX
|
|
155
|
+
) {
|
|
156
|
+
candidateCount = value as number
|
|
157
|
+
} else {
|
|
158
|
+
drop()
|
|
159
|
+
}
|
|
160
|
+
break
|
|
161
|
+
case 'effect':
|
|
162
|
+
if (value === 'none') break
|
|
163
|
+
effectNotMeasured = true
|
|
164
|
+
drop()
|
|
165
|
+
break
|
|
166
|
+
default:
|
|
167
|
+
drop()
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (effectNotMeasured) return rejected('EFFECT_NOT_MEASURED', droppedFieldCount)
|
|
172
|
+
if (point === null || decision === null || reason === null) {
|
|
173
|
+
return rejected('MISSING_REQUIRED_FIELD', droppedFieldCount)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const event: DecisionTelemetryEvent = {
|
|
177
|
+
schemaVersion: TELEMETRY_SCHEMA_VERSION,
|
|
178
|
+
point,
|
|
179
|
+
decision,
|
|
180
|
+
effect: 'none',
|
|
181
|
+
reason,
|
|
182
|
+
...(mode !== null ? { mode } : {}),
|
|
183
|
+
...(durationMs !== null ? { durationMs } : {}),
|
|
184
|
+
...(candidateCount !== null ? { candidateCount } : {}),
|
|
185
|
+
}
|
|
186
|
+
return { ok: true, event: Object.freeze(event), droppedFieldCount }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** In-memory, bounded telemetry collector. No I/O, no network. */
|
|
190
|
+
export interface TelemetrySink {
|
|
191
|
+
emit(input: unknown): TelemetryResult
|
|
192
|
+
events(): readonly DecisionTelemetryEvent[]
|
|
193
|
+
size(): number
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function createTelemetrySink(maxEvents = 1_000): TelemetrySink {
|
|
197
|
+
if (!Number.isInteger(maxEvents) || maxEvents < 0 || maxEvents > 100_000) {
|
|
198
|
+
throw new RangeError('maxEvents must be an integer in 0..100000')
|
|
199
|
+
}
|
|
200
|
+
const collected: DecisionTelemetryEvent[] = []
|
|
201
|
+
return {
|
|
202
|
+
emit(input: unknown) {
|
|
203
|
+
const result = sanitizeTelemetry(input)
|
|
204
|
+
if (result.ok && collected.length < maxEvents) collected.push(result.event)
|
|
205
|
+
return result
|
|
206
|
+
},
|
|
207
|
+
events() {
|
|
208
|
+
return Object.freeze([...collected])
|
|
209
|
+
},
|
|
210
|
+
size() {
|
|
211
|
+
return collected.length
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V2 verification contract — explicit verdicts, never inferred.
|
|
3
|
+
*
|
|
4
|
+
* `failed_to_respond` during mandatory verification is `BLOCK`; during advisory
|
|
5
|
+
* verification it is `FAIL`. Neither is ever `PASS`, and no scalar can stand in
|
|
6
|
+
* for a verdict.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const VERIFY_VERDICTS = ['PASS', 'FAIL', 'BLOCK'] as const
|
|
10
|
+
export type VerifyVerdict = (typeof VERIFY_VERDICTS)[number]
|
|
11
|
+
|
|
12
|
+
export interface VerifyRequirement {
|
|
13
|
+
readonly id: string
|
|
14
|
+
readonly mandatory: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type VerifyReasonCode = 'VERDICT' | 'FAILED_TO_RESPOND' | 'UNRECOGNIZED_VERDICT'
|
|
18
|
+
|
|
19
|
+
export interface VerifyOutcome {
|
|
20
|
+
readonly requirementId: string
|
|
21
|
+
readonly verdict: VerifyVerdict
|
|
22
|
+
readonly reasonCode: VerifyReasonCode
|
|
23
|
+
readonly mandatory: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a verification verdict.
|
|
28
|
+
*
|
|
29
|
+
* The verdict must be stated explicitly. `failed_to_respond` during a
|
|
30
|
+
* mandatory verification is `BLOCK`; during an advisory verification it is
|
|
31
|
+
* `FAIL`. Neither case is ever `PASS`, and no certainty scalar can stand in
|
|
32
|
+
* for a verdict.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveVerify(requirement: VerifyRequirement, response: unknown): VerifyOutcome {
|
|
35
|
+
const base = { requirementId: requirement.id, mandatory: requirement.mandatory }
|
|
36
|
+
if (typeof response === 'string') {
|
|
37
|
+
if (response === 'PASS' || response === 'FAIL' || response === 'BLOCK') {
|
|
38
|
+
return { ...base, verdict: response, reasonCode: 'VERDICT' }
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
...base,
|
|
42
|
+
verdict: requirement.mandatory ? 'BLOCK' : 'FAIL',
|
|
43
|
+
reasonCode: 'UNRECOGNIZED_VERDICT',
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...base,
|
|
48
|
+
verdict: requirement.mandatory ? 'BLOCK' : 'FAIL',
|
|
49
|
+
reasonCode: 'FAILED_TO_RESPOND',
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/pantheon/v2-tools.ts
CHANGED
|
@@ -51,6 +51,7 @@ import { createHashlineEditTool, type HashlineToolResult } from './hashline/tool
|
|
|
51
51
|
import { createV2LocalDecisionDefinition } from './local-decision-tool.ts'
|
|
52
52
|
import { createModelCommand } from './model-command.ts'
|
|
53
53
|
import type { ToolContextLike } from './tool-context.ts'
|
|
54
|
+
import type { ShadowSink } from './v2-decision-shadow.ts'
|
|
54
55
|
import { createV2VisionTool, type V2VisionRuntime } from './v2-vision.ts'
|
|
55
56
|
|
|
56
57
|
// ─── Contract types ─────────────────────────────────────────────────────
|
|
@@ -420,6 +421,17 @@ async function executeModel(
|
|
|
420
421
|
|
|
421
422
|
// ─── Tool set ───────────────────────────────────────────────────────────
|
|
422
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Optional shadow sinks wired at tool registration.
|
|
426
|
+
*
|
|
427
|
+
* `complexity` belongs to P3, whose declared host surface is `tool.invoke`: the
|
|
428
|
+
* local selector's own input carries the complexity vector and gate status, so
|
|
429
|
+
* the observation is constructed where the payload can actually feed it.
|
|
430
|
+
*/
|
|
431
|
+
export interface V2ToolShadowOptions {
|
|
432
|
+
readonly complexitySink?: ShadowSink
|
|
433
|
+
}
|
|
434
|
+
|
|
423
435
|
/**
|
|
424
436
|
* Build the V2 tool definitions.
|
|
425
437
|
*
|
|
@@ -434,7 +446,10 @@ async function executeModel(
|
|
|
434
446
|
* per-call definition with no construction-time I/O. A fresh descriptor array
|
|
435
447
|
* prevents callers from mutating another registration's definitions.
|
|
436
448
|
*/
|
|
437
|
-
export function createV2ToolDefinitions(
|
|
449
|
+
export function createV2ToolDefinitions(
|
|
450
|
+
visionRuntime?: V2VisionRuntime,
|
|
451
|
+
shadow: V2ToolShadowOptions = {},
|
|
452
|
+
): V2ToolDef[] {
|
|
438
453
|
const definitions: V2ToolDef[] = [
|
|
439
454
|
{
|
|
440
455
|
name: 'hashline_edit',
|
|
@@ -475,7 +490,11 @@ export function createV2ToolDefinitions(visionRuntime?: V2VisionRuntime): V2Tool
|
|
|
475
490
|
execute: executeModel,
|
|
476
491
|
},
|
|
477
492
|
]
|
|
478
|
-
definitions.push(
|
|
493
|
+
definitions.push(
|
|
494
|
+
createV2LocalDecisionDefinition({
|
|
495
|
+
...(shadow.complexitySink === undefined ? {} : { sink: shadow.complexitySink }),
|
|
496
|
+
}),
|
|
497
|
+
)
|
|
479
498
|
if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime))
|
|
480
499
|
return definitions
|
|
481
500
|
}
|