pantheon-opencode 2.0.3 → 2.0.4

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.
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Themis Local Reflex Loop — Self-healing inline verification for implementer agents.
3
+ *
4
+ * Catches syntax errors, lint failures, and sliced test failures directly in the
5
+ * implementer's execution cycle, granting up to 2 bounded retry attempts before
6
+ * escalating to the Zeus coordinator.
7
+ *
8
+ * Emits reactive events on `getSharedBus()` for auditability and observability.
9
+ *
10
+ * Pure TypeScript — zero external dependencies.
11
+ *
12
+ * @module themis-reflex
13
+ */
14
+
15
+ import { getSharedBus } from './bus.ts'
16
+
17
+ export interface ThemisDiscrepancy {
18
+ readonly file: string
19
+ readonly error: string
20
+ readonly expected?: string
21
+ readonly actual?: string
22
+ readonly suggestedFix?: string
23
+ }
24
+
25
+ export interface ReflexAttemptState {
26
+ taskID: string
27
+ agent: string
28
+ attempt: number
29
+ maxAttempts: number
30
+ discrepancies: ThemisDiscrepancy[]
31
+ timestamp: number
32
+ }
33
+
34
+ export type ThemisReflexDecision =
35
+ | {
36
+ readonly action: 'retry'
37
+ readonly prompt: string
38
+ readonly attempt: number
39
+ readonly maxAttempts: number
40
+ }
41
+ | {
42
+ readonly action: 'escalate'
43
+ readonly verdict: 'BLOCK' | 'FAIL'
44
+ readonly reason: string
45
+ readonly attempts: number
46
+ }
47
+ | {
48
+ readonly action: 'pass'
49
+ readonly verdict: 'PASS'
50
+ }
51
+
52
+ export class ThemisReflexController {
53
+ private readonly states: Map<string, ReflexAttemptState> = new Map()
54
+ private readonly maxRetries: number
55
+
56
+ constructor(options: { maxRetries?: number } = {}) {
57
+ this.maxRetries = options.maxRetries ?? 2
58
+ }
59
+
60
+ /**
61
+ * Evaluate a task execution result against Themis verification findings.
62
+ * If discrepancies are found and attempts remain, returns an actionable retry directive.
63
+ */
64
+ evaluate(
65
+ taskID: string,
66
+ agent: string,
67
+ discrepancies: readonly ThemisDiscrepancy[],
68
+ ): ThemisReflexDecision {
69
+ if (discrepancies.length === 0) {
70
+ const existing = this.states.get(taskID)
71
+ if (existing) {
72
+ getSharedBus().emit('themis:reflex:resolved', {
73
+ taskID,
74
+ agent,
75
+ file: existing.discrepancies[0]?.file ?? '',
76
+ error: '',
77
+ attempt: existing.attempt,
78
+ maxAttempts: this.maxRetries,
79
+ timestamp: Date.now(),
80
+ resolved: true,
81
+ })
82
+ this.states.delete(taskID)
83
+ }
84
+ return { action: 'pass', verdict: 'PASS' }
85
+ }
86
+
87
+ let state = this.states.get(taskID)
88
+ if (!state) {
89
+ state = {
90
+ taskID,
91
+ agent,
92
+ attempt: 0,
93
+ maxAttempts: this.maxRetries,
94
+ discrepancies: [...discrepancies],
95
+ timestamp: Date.now(),
96
+ }
97
+ this.states.set(taskID, state)
98
+ }
99
+
100
+ state.attempt += 1
101
+ state.discrepancies = [...discrepancies]
102
+ state.timestamp = Date.now()
103
+
104
+ const firstDisc = discrepancies[0]
105
+ getSharedBus().emit('themis:reflex:discrepancy', {
106
+ taskID,
107
+ agent,
108
+ file: firstDisc?.file ?? 'unknown',
109
+ error: firstDisc?.error ?? 'unspecified',
110
+ attempt: state.attempt,
111
+ maxAttempts: this.maxRetries,
112
+ timestamp: state.timestamp,
113
+ })
114
+
115
+ if (state.attempt <= this.maxRetries) {
116
+ const prompt = this.formatReflexPrompt(state.attempt, this.maxRetries, discrepancies)
117
+ return {
118
+ action: 'retry',
119
+ prompt,
120
+ attempt: state.attempt,
121
+ maxAttempts: this.maxRetries,
122
+ }
123
+ }
124
+
125
+ // Retries exhausted — escalate to coordinator
126
+ this.states.delete(taskID)
127
+ return {
128
+ action: 'escalate',
129
+ verdict: 'FAIL',
130
+ reason: `themis.reflex.exhausted:${state.attempt - 1}_retries_failed`,
131
+ attempts: state.attempt,
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Format an inline, high-density reflex prompt directing the implementer to self-heal.
137
+ */
138
+ private formatReflexPrompt(
139
+ attempt: number,
140
+ maxAttempts: number,
141
+ discrepancies: readonly ThemisDiscrepancy[],
142
+ ): string {
143
+ const lines = [
144
+ `[THEMIS INLINE REFLEX — Attempt ${attempt}/${maxAttempts}]`,
145
+ 'Themis automated audit detected discrepancies in your edits. Fix them directly before returning:',
146
+ ]
147
+
148
+ for (const d of discrepancies) {
149
+ lines.push(`- File: ${d.file}`)
150
+ lines.push(` Error: ${d.error}`)
151
+ if (d.expected) lines.push(` Expected: ${d.expected}`)
152
+ if (d.actual) lines.push(` Actual: ${d.actual}`)
153
+ if (d.suggestedFix) lines.push(` Fix hint: ${d.suggestedFix}`)
154
+ }
155
+
156
+ lines.push('Do NOT escalate to Zeus yet. Apply the targeted fix and re-verify your slice.')
157
+ return lines.join('\n')
158
+ }
159
+
160
+ /** Reset state for a taskID */
161
+ reset(taskID: string): void {
162
+ this.states.delete(taskID)
163
+ }
164
+ }
@@ -2273,7 +2273,7 @@ function readUserDecisionRouterConfig({ env = process.env } = {}) {
2273
2273
  const filePath = resolveUserDecisionRouterConfigPath(env);
2274
2274
  try {
2275
2275
  assertNoSymlinkAncestors(filePath);
2276
- assertTrustedDirectoryChain(dirname2(filePath));
2276
+ assertTrustedDirectoryChain(dirname2(filePath), { env });
2277
2277
  const stat2 = lstatSync2(filePath);
2278
2278
  assertPrivatePath(stat2, true);
2279
2279
  const parsed = JSON.parse(readFileSync2(filePath, "utf8"));
@@ -2349,7 +2349,16 @@ function assertPrivatePath(stat2, isFile) {
2349
2349
  if ((stat2.mode & 63) !== 0)
2350
2350
  throw new Error("Decision-router configuration permissions must be private");
2351
2351
  }
2352
- function assertTrustedDirectoryChain(directory) {
2352
+ function isPermittedGroupWritable(_current, env = process.env) {
2353
+ if (env.PANTHEON_ALLOW_GROUP_WRITABLE === "1" || env.PANTHEON_ALLOW_GROUP_WRITABLE === "true") {
2354
+ return true;
2355
+ }
2356
+ if (env.JUPYTERHUB_USER || env.JUPYTER_IMAGE || env.JUPYTER_SERVER_ROOT || env.KUBERNETES_SERVICE_HOST || env.container || existsSync("/.dockerenv")) {
2357
+ return true;
2358
+ }
2359
+ return false;
2360
+ }
2361
+ function assertTrustedDirectoryChain(directory, { env = process.env } = {}) {
2353
2362
  const absolute = resolve2(directory);
2354
2363
  const root = parse2(absolute).root;
2355
2364
  const parts = absolute.slice(root.length).split(sep2).filter(Boolean);
@@ -2369,14 +2378,22 @@ function assertTrustedDirectoryChain(directory) {
2369
2378
  if (!stat2.isDirectory() || stat2.isSymbolicLink()) {
2370
2379
  throw new Error("Decision-router configuration path contains a non-directory component");
2371
2380
  }
2372
- if (stat2.uid !== uid && stat2.uid !== 0) {
2381
+ const mode = stat2.mode & 4095;
2382
+ const isSticky = (mode & 512) !== 0;
2383
+ const isSystemOrUser = stat2.uid === uid || stat2.uid === 0 || isSticky && stat2.uid === 65534;
2384
+ if (!isSystemOrUser) {
2373
2385
  throw new Error("Decision-router configuration path has an untrusted owner");
2374
2386
  }
2375
- const mode = stat2.mode & 4095;
2376
- const rootStickyDirectory = stat2.uid === 0 && (mode & 512) !== 0;
2377
- if ((mode & 18) !== 0 && !rootStickyDirectory) {
2387
+ const worldWritable = (mode & 2) !== 0;
2388
+ const groupWritable = (mode & 16) !== 0;
2389
+ if (worldWritable && !isSticky) {
2378
2390
  throw new Error("Decision-router configuration path is writable by other users");
2379
2391
  }
2392
+ if (groupWritable && !isSticky && !isPermittedGroupWritable(current, env)) {
2393
+ throw new Error(
2394
+ `Decision-router configuration path "${current}" is group-writable (mode ${(mode & 511).toString(8)}). In containers or JupyterHub, set PANTHEON_ALLOW_GROUP_WRITABLE=1 to permit group-writable ancestors, or run: chmod +t "${current}"`
2395
+ );
2396
+ }
2380
2397
  }
2381
2398
  }
2382
2399
 
@@ -5837,7 +5854,14 @@ function createJ1RiskGateObserver(options) {
5837
5854
 
5838
5855
  // src/pantheon/local-decision-budget.ts
5839
5856
  import { randomUUID } from "node:crypto";
5840
- import { chmodSync as chmodSync2, closeSync as closeSync2, lstatSync as lstatSync4, mkdirSync as mkdirSync3, openSync as openSync2 } from "node:fs";
5857
+ import {
5858
+ chmodSync as chmodSync2,
5859
+ closeSync as closeSync2,
5860
+ existsSync as existsSync2,
5861
+ lstatSync as lstatSync4,
5862
+ mkdirSync as mkdirSync3,
5863
+ openSync as openSync2
5864
+ } from "node:fs";
5841
5865
  import { homedir as homedir2 } from "node:os";
5842
5866
  import { basename, dirname as dirname4, isAbsolute as isAbsolute3, join as join6, parse as parse3, resolve as resolve3, sep as sep3 } from "node:path";
5843
5867
  import { performance } from "node:perf_hooks";
@@ -6762,20 +6786,34 @@ function ensureTrustedDirectoryChain(directoryPath) {
6762
6786
  }
6763
6787
  }
6764
6788
  }
6789
+ function isPermittedGroupWritable2(env = process.env) {
6790
+ if (env.PANTHEON_ALLOW_GROUP_WRITABLE === "1" || env.PANTHEON_ALLOW_GROUP_WRITABLE === "true") {
6791
+ return true;
6792
+ }
6793
+ if (env.JUPYTERHUB_USER || env.JUPYTER_IMAGE || env.JUPYTER_SERVER_ROOT || env.KUBERNETES_SERVICE_HOST || env.container || existsSync2("/.dockerenv")) {
6794
+ return true;
6795
+ }
6796
+ return false;
6797
+ }
6765
6798
  function validateDirectoryTrust(stat2, uid, isFinalDirectory) {
6766
6799
  if (!stat2.isDirectory() || stat2.isSymbolicLink()) {
6767
6800
  throw new Error("Budget ledger path contains a non-directory or symlink ancestor");
6768
6801
  }
6769
- if (stat2.uid !== uid && stat2.uid !== 0) {
6802
+ const mode = stat2.mode & 4095;
6803
+ const isSticky = (mode & 512) !== 0;
6804
+ const isSystemOrUser = stat2.uid === uid || stat2.uid === 0 || isSticky && stat2.uid === 65534;
6805
+ if (!isSystemOrUser) {
6770
6806
  throw new Error("Budget ledger path contains an untrusted owner");
6771
6807
  }
6772
6808
  if (isFinalDirectory && stat2.uid !== uid) {
6773
6809
  throw new Error("Budget ledger directory must be owned by the current user");
6774
6810
  }
6775
- const mode = stat2.mode & 4095;
6776
- const writableByOthers = (mode & 18) !== 0;
6777
- const rootStickyDirectory = stat2.uid === 0 && (mode & 512) !== 0;
6778
- if (writableByOthers && !rootStickyDirectory) {
6811
+ const worldWritable = (mode & 2) !== 0;
6812
+ const groupWritable = (mode & 16) !== 0;
6813
+ if (worldWritable && !isSticky) {
6814
+ throw new Error("Budget ledger path contains a group/other-writable directory");
6815
+ }
6816
+ if (groupWritable && !isSticky && !isFinalDirectory && !isPermittedGroupWritable2()) {
6779
6817
  throw new Error("Budget ledger path contains a group/other-writable directory");
6780
6818
  }
6781
6819
  }
@@ -6870,8 +6908,9 @@ async function runGatedNativeJevCall(params) {
6870
6908
  let config;
6871
6909
  try {
6872
6910
  config = readUserDecisionRouterConfig();
6873
- } catch {
6874
- return { ok: false, reasonCode: "CONFIG_UNAVAILABLE" };
6911
+ } catch (error) {
6912
+ const detail = error instanceof Error && error.message.includes("group-writable") ? "CONFIG_PATH_GROUP_WRITABLE" : error instanceof Error ? error.name : "ConfigError";
6913
+ return { ok: false, reasonCode: "CONFIG_UNAVAILABLE", detail };
6875
6914
  }
6876
6915
  if (!config.enabled) return { ok: false, reasonCode: "DISABLED" };
6877
6916
  if (!config.egress_consent) return { ok: false, reasonCode: "CONSENT_MISSING" };
@@ -8045,7 +8084,7 @@ function safeSessionPath(id) {
8045
8084
  import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
8046
8085
  import {
8047
8086
  chmodSync as chmodSync3,
8048
- existsSync as existsSync2,
8087
+ existsSync as existsSync3,
8049
8088
  mkdirSync as mkdirSync4,
8050
8089
  readdirSync,
8051
8090
  readFileSync as readFileSync5,
@@ -8297,7 +8336,7 @@ function extractCredentialCellToken(value) {
8297
8336
  }
8298
8337
  async function readV2CredentialToken(providerIDs, stateDir, env) {
8299
8338
  const dbPath = v2CredentialDbPath(stateDir, env);
8300
- if (!existsSync2(dbPath)) return null;
8339
+ if (!existsSync3(dbPath)) return null;
8301
8340
  let sqlite;
8302
8341
  try {
8303
8342
  sqlite = await import("node:sqlite");
@@ -10383,7 +10422,7 @@ var TodoEnforcer = class {
10383
10422
 
10384
10423
  // src/pantheon/cost-command.ts
10385
10424
  import { execFile } from "node:child_process";
10386
- import { accessSync, constants as constants3, existsSync as existsSync4, statSync as statSync3 } from "node:fs";
10425
+ import { accessSync, constants as constants3, existsSync as existsSync5, statSync as statSync3 } from "node:fs";
10387
10426
  import { delimiter, dirname as dirname8, join as join14 } from "node:path";
10388
10427
  import { fileURLToPath as fileURLToPath4 } from "node:url";
10389
10428
  import { z } from "zod";
@@ -10393,7 +10432,7 @@ import { homedir as homedir6 } from "node:os";
10393
10432
  import { join as join13 } from "node:path";
10394
10433
 
10395
10434
  // src/plugins/tui/src/model-pricing.ts
10396
- import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
10435
+ import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
10397
10436
  import { homedir as homedir5 } from "node:os";
10398
10437
  import { dirname as dirname7, join as join12 } from "node:path";
10399
10438
  var MODELS_DEV_URL = "https://models.dev/api.json";
@@ -10539,7 +10578,7 @@ function parseCachedCatalog(raw) {
10539
10578
  }
10540
10579
  function readPricingCache(cachePath) {
10541
10580
  try {
10542
- if (!existsSync3(cachePath)) return void 0;
10581
+ if (!existsSync4(cachePath)) return void 0;
10543
10582
  return parseCachedCatalog(JSON.parse(readFileSync6(cachePath, "utf8")));
10544
10583
  } catch {
10545
10584
  return void 0;
@@ -10770,7 +10809,7 @@ var costArgs = {
10770
10809
  };
10771
10810
  function findExistingDb(override) {
10772
10811
  const candidate = override === void 0 ? resolveCostDbPath() : resolveCostDbPath({ dbPath: override });
10773
- return existsSync4(candidate) ? candidate : void 0;
10812
+ return existsSync5(candidate) ? candidate : void 0;
10774
10813
  }
10775
10814
  var COST_AGGREGATE_SQL = {
10776
10815
  message: (sessionId) => `
@@ -11476,7 +11515,7 @@ async function queryWithCliFallback(dbPath, days, deps) {
11476
11515
  const execFileAsync = deps?.execFile ?? defaultExecFile;
11477
11516
  const isExecutable = deps?.isExecutable ?? defaultIsExecutable;
11478
11517
  const costScript = join14(__dirname, "..", "..", "scripts", "cost.mjs");
11479
- if (!existsSync4(costScript)) {
11518
+ if (!existsSync5(costScript)) {
11480
11519
  throw new Error(`CLI fallback script not found: ${costScript}`);
11481
11520
  }
11482
11521
  const node = resolveNodeExecutable(env, isExecutable);
@@ -1950,7 +1950,7 @@ async function readChangelogForBundle(bundleUrl) {
1950
1950
  }
1951
1951
  /** The ambient build-time version, or null outside a tsdown build. */
1952
1952
  function embeddedVersion() {
1953
- return "2.0.3";
1953
+ return "2.0.4";
1954
1954
  }
1955
1955
  /**
1956
1956
  * Resolve the running Pantheon version for the what's-new window: the plugin
@@ -2175,7 +2175,7 @@ function persistUpdateCheckState(previous, latest) {
2175
2175
  } catch {}
2176
2176
  }
2177
2177
  function resolveRunningVersion() {
2178
- return "2.0.3";
2178
+ return "2.0.4";
2179
2179
  }
2180
2180
  const VALUE_WIDTH = 24;
2181
2181
  function SettingsWindow(props) {
@@ -6341,7 +6341,7 @@ async function checkForPantheonUpdate(context) {
6341
6341
  const latest = String((await response.json())?.version ?? "");
6342
6342
  if (!latest) return;
6343
6343
  const notice = pickUpdateNotice({
6344
- currentVersion: "2.0.3",
6344
+ currentVersion: "2.0.4",
6345
6345
  latestVersion: latest,
6346
6346
  state: readState(),
6347
6347
  nowMs: Date.now()
@@ -7153,7 +7153,7 @@ function Sidebar(props) {
7153
7153
  get children() {
7154
7154
  var _el$13 = createElement("text");
7155
7155
  setProp(_el$13, "attributes", 1);
7156
- insert(_el$13, `Pantheon v2.0.3`);
7156
+ insert(_el$13, `Pantheon v2.0.4`);
7157
7157
  effect((_$p) => setProp(_el$13, "fg", text(), _$p));
7158
7158
  return _el$13;
7159
7159
  }
@@ -7925,7 +7925,7 @@ function HomeStatus(props) {
7925
7925
  },
7926
7926
  get children() {
7927
7927
  var _el$73 = createElement("text");
7928
- insert(_el$73, () => `Pantheon v2.0.3${preset().name ? ` ▸ ${preset().name}` : ""}`);
7928
+ insert(_el$73, () => `Pantheon v2.0.4${preset().name ? ` ▸ ${preset().name}` : ""}`);
7929
7929
  effect((_$p) => setProp(_el$73, "fg", muted(), _$p));
7930
7930
  return _el$73;
7931
7931
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pantheon-tui",
9
- "version": "2.0.3",
9
+ "version": "2.0.4",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@opencode/plugin": "2.0.26",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pantheon-tui",
3
3
  "type": "module",
4
- "version": "2.0.3",
4
+ "version": "2.0.4",
5
5
  "description": "Pantheon TUI plugin \u2014 V1 rich sidebar and usage gauges; native V2 status, session and delegation sidebar",
6
6
  "license": "MIT",
7
7
  "engines": {