pantheon-opencode 1.6.0-beta.17 โ 1.6.0-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 +21 -0
- package/README.md +16 -41
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/mcp_persistence.py +278 -71
- package/src/mcp/mcp_persistence.py +278 -71
- 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 +2 -2
- package/src/plugins/tui/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
<!-- Add new changes here. Running `node scripts/versioning.mjs apply` will
|
|
11
|
+
move this section to a versioned entry and reset the template below. -->
|
|
12
|
+
|
|
13
|
+
## ๐ What's New
|
|
14
|
+
|
|
15
|
+
## ๐ Fixed
|
|
16
|
+
|
|
17
|
+
## โ ๏ธ Known Issues
|
|
18
|
+
|
|
19
|
+
## โ
Closed Issues
|
|
20
|
+
|
|
21
|
+
## [v1.6.0-beta.18] - 2026-10-22
|
|
22
|
+
|
|
23
|
+
- **Persistence goal-schema initialization and migration guidance:** a pristine
|
|
24
|
+
project database now starts with both checkpoint and goal schemas; startup
|
|
25
|
+
does not add goal DDL to an existing database. Existing-DB migration is only
|
|
26
|
+
for users who want manual goal tools. When the schema is absent, the goal tools
|
|
27
|
+
themselves return the exact migration command. User-facing guidance covers
|
|
28
|
+
dry-run first, a stopped server, target confirmation, and verified `0600`
|
|
29
|
+
backups.
|
|
30
|
+
|
|
10
31
|
## [v1.6.0-beta.17] - 2026-10-21
|
|
11
32
|
|
|
12
33
|
- **Persistence MCP reduced to six registered tools:** only `context_save`,
|
package/README.md
CHANGED
|
@@ -316,47 +316,22 @@ plus effective-permission verification, not promised hot reload.
|
|
|
316
316
|
|
|
317
317
|
These are manual records only: they do not replace or migrate the V1
|
|
318
318
|
`src/pantheon/goal-store.ts` authority, write to it, or trigger continuation,
|
|
319
|
-
reinjection, an evaluator, loop, board, TUI/RPC, or `ctx.storage`. The
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
for
|
|
334
|
-
|
|
335
|
-
with `<runtime>/.venv/bin/python3 <runtime>/scripts/mcp_persistence.py
|
|
336
|
-
--migrate-goals --dry-run`; for a project install, preview with
|
|
337
|
-
`<project>/.venv/bin/python3
|
|
338
|
-
<project>/.opencode/scripts/mcp_persistence.py --migrate-goals --dry-run`.
|
|
339
|
-
The simplest reliable source of truth for the interpreter is `command[0]` in
|
|
340
|
-
`opencode.json` for `pantheon-persistence`. The dry-run reports database size
|
|
341
|
-
and `-wal`/`-shm` presence before opening the DB. If either sidecar exists, it
|
|
342
|
-
uses plain read-only mode so committed WAL state is visible; if neither exists,
|
|
343
|
-
it uses `immutable=1` to avoid creating sidecars, including in a read-only
|
|
344
|
-
directory. If the goal-table state is `unknown`, the command exits with status
|
|
345
|
-
2: stop and investigate, and do not treat it as a healthy result. Ask the user
|
|
346
|
-
to approve before migration. The migration creates a timestamped
|
|
347
|
-
adjacent full copy of the Persistence DB, including all KV data, with mode
|
|
348
|
-
`0600`; backups live beside the selected DB. With the runtime-default target,
|
|
349
|
-
uninstall/reinstall may replace that directory, so move any backup you need
|
|
350
|
-
outside it first. Content-digest
|
|
351
|
-
verification and backup-retention automation are deferred; for now the operator
|
|
352
|
-
must prune old backups manually. An already-current schema creates no backup. If
|
|
353
|
-
migration history exists but `pantheon_goals` is missing, stop and preserve the
|
|
354
|
-
database; a human operator must restore a verified backup or recover the missing
|
|
355
|
-
schema before approving another migration. The goal tests require the
|
|
356
|
-
pinned `fastmcp==4.0.10` and `mcp==2.2.0` versions from
|
|
357
|
-
`src/mcp/requirements-mcp.txt`. Tests use synthetic temporary databases only;
|
|
358
|
-
no real DB or global configuration is changed, and rollout remains gated on
|
|
359
|
-
Themis review and explicit user approval.
|
|
319
|
+
reinjection, an evaluator, loop, board, TUI/RPC, or `ctx.storage`. The V1 JSON
|
|
320
|
+
store at `.pantheon/goals/*.json` is untouched and not imported. The V2 plugin's
|
|
321
|
+
own goal tools remain unsupported.
|
|
322
|
+
|
|
323
|
+
Fresh/pristine Persistence project databases start with both checkpoint and goal
|
|
324
|
+
schemas; startup performs no goal-schema DDL on an existing database containing
|
|
325
|
+
user schema. Users who do not use manual goals need do nothing; only users who
|
|
326
|
+
want the tools on an existing Persistence project DB need the explicit
|
|
327
|
+
human-run migration. If the schema is absent, the goal tools fail closed and
|
|
328
|
+
return the exact `<venv-python> <installed-script> --migrate-goals` command (with
|
|
329
|
+
installation-specific command forms). Skipping migration leaves checkpoint
|
|
330
|
+
tools working and goal tools unavailable, without data loss or corruption.
|
|
331
|
+
Never migrate `global.db` or the V1 JSON goal store. See
|
|
332
|
+
[Persistence migration guidance](docs/persistence-mcp.md#fresh-databases-and-existing-database-migration)
|
|
333
|
+
for target resolution, dry-run confirmation, backups, and the stopped-server
|
|
334
|
+
procedure.
|
|
360
335
|
|
|
361
336
|
### Verified against which OpenCode versions
|
|
362
337
|
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantheon",
|
|
3
3
|
"publisher": "ils15",
|
|
4
|
-
"version": "1.6.0-beta.
|
|
4
|
+
"version": "1.6.0-beta.18",
|
|
5
5
|
"displayName": "Pantheon",
|
|
6
6
|
"description": "Conductor-Delegate orchestration platform with 14 specialized agents, 20 skills, and OpenCode support.",
|
|
7
7
|
"agents": "./src/agents",
|
package/pyproject.toml
CHANGED
|
@@ -12,6 +12,7 @@ Usage:
|
|
|
12
12
|
from __future__ import annotations
|
|
13
13
|
|
|
14
14
|
import argparse
|
|
15
|
+
import errno
|
|
15
16
|
import json
|
|
16
17
|
import os
|
|
17
18
|
import re
|
|
@@ -27,6 +28,11 @@ from pathlib import Path
|
|
|
27
28
|
from typing import Annotated, Literal
|
|
28
29
|
from uuid import uuid4
|
|
29
30
|
|
|
31
|
+
if os.name == "nt":
|
|
32
|
+
import msvcrt
|
|
33
|
+
else:
|
|
34
|
+
import fcntl
|
|
35
|
+
|
|
30
36
|
from _pantheon_paths import pantheon_home
|
|
31
37
|
from fastmcp import Context, FastMCP
|
|
32
38
|
from fastmcp.exceptions import ToolError
|
|
@@ -96,41 +102,206 @@ mcp = FastMCP(
|
|
|
96
102
|
|
|
97
103
|
_global_db: sqlite3.Connection | None = None
|
|
98
104
|
_project_db: sqlite3.Connection | None = None
|
|
105
|
+
_global_db_path: Path | None = None
|
|
99
106
|
|
|
100
107
|
|
|
101
|
-
def
|
|
102
|
-
"""
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
def _has_goal_schema_objects(conn: sqlite3.Connection) -> bool:
|
|
109
|
+
"""Check for goal tables or indexes, including migration-history remnants."""
|
|
110
|
+
return (
|
|
111
|
+
conn.execute(
|
|
112
|
+
"SELECT 1 FROM sqlite_master WHERE name IN ("
|
|
113
|
+
"'pantheon_goals', 'uq_pantheon_goals_active_session', "
|
|
114
|
+
"'idx_pantheon_goals_session_history', "
|
|
115
|
+
"'pantheon_goal_schema_migrations') LIMIT 1"
|
|
116
|
+
).fetchone()
|
|
117
|
+
is not None
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _resolve_global_db_path(global_db: str | Path | None = None) -> Path:
|
|
122
|
+
"""Resolve the global database path from its configured persistence root."""
|
|
123
|
+
root = (
|
|
124
|
+
Path(global_db).expanduser()
|
|
125
|
+
if global_db is not None
|
|
126
|
+
else pantheon_home() / "persistence"
|
|
127
|
+
)
|
|
128
|
+
return (root / "global.db").resolve()
|
|
129
|
+
|
|
118
130
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
def _assert_not_global_goal_path(db_path: str | Path) -> None:
|
|
132
|
+
"""Keep goal schema changes categorically away from the global database."""
|
|
133
|
+
target = Path(db_path).expanduser().resolve()
|
|
134
|
+
global_path = globals().get("_global_db_path") or _resolve_global_db_path()
|
|
135
|
+
resolves_to_global = target == global_path
|
|
136
|
+
if not resolves_to_global:
|
|
137
|
+
try:
|
|
138
|
+
target_stat = target.stat()
|
|
139
|
+
global_stat = global_path.stat()
|
|
140
|
+
except FileNotFoundError:
|
|
141
|
+
pass
|
|
142
|
+
else:
|
|
143
|
+
resolves_to_global = (target_stat.st_dev, target_stat.st_ino) == (
|
|
144
|
+
global_stat.st_dev,
|
|
145
|
+
global_stat.st_ino,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if resolves_to_global:
|
|
149
|
+
raise GoalSchemaNotInitializedError(
|
|
150
|
+
"goal schema migration and DDL are prohibited for the global "
|
|
151
|
+
f"Persistence database ({global_path}); the target resolves to the "
|
|
152
|
+
"global database; choose a separate project database with --project-db"
|
|
124
153
|
)
|
|
125
|
-
conn.executescript(_no_fts)
|
|
126
|
-
else:
|
|
127
|
-
conn.executescript(CREATE_SQL)
|
|
128
|
-
_ensure_revision_column(conn)
|
|
129
|
-
conn.commit()
|
|
130
154
|
|
|
155
|
+
|
|
156
|
+
def _init_db(db_path: Path, *, project_db: bool = False) -> sqlite3.Connection:
|
|
157
|
+
"""Initialize the KV schema and goal schema only for a pristine project DB."""
|
|
158
|
+
if project_db:
|
|
159
|
+
_assert_not_global_goal_path(db_path)
|
|
160
|
+
db_path.parent.mkdir(parents=True, exist_ok=True)
|
|
161
|
+
lock_path = db_path.with_name(f".{db_path.name}.init.lock")
|
|
162
|
+
lock_fd = os.open(lock_path, os.O_CREAT | os.O_RDWR, 0o600)
|
|
163
|
+
lock_acquired = False
|
|
164
|
+
try:
|
|
165
|
+
# Serialize initialization across processes.
|
|
166
|
+
_acquire_init_lock(lock_fd)
|
|
167
|
+
lock_acquired = True
|
|
168
|
+
conn = _connect_or_create_database(db_path)
|
|
169
|
+
try:
|
|
170
|
+
conn.execute("PRAGMA busy_timeout=5000")
|
|
171
|
+
conn.execute("PRAGMA foreign_keys=ON")
|
|
172
|
+
fts_available = any(
|
|
173
|
+
"ENABLE_FTS5" in row[0]
|
|
174
|
+
for row in conn.execute("PRAGMA compile_options").fetchall()
|
|
175
|
+
)
|
|
176
|
+
if not fts_available:
|
|
177
|
+
print(
|
|
178
|
+
"WARNING: SQLite FTS5 unavailable; the internal full-text index "
|
|
179
|
+
"was not initialized.",
|
|
180
|
+
file=sys.stderr,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
# SQLite's writer lock serializes the schema inspection and every
|
|
184
|
+
# DDL statement. Never use executescript here: it commits implicitly.
|
|
185
|
+
conn.execute("BEGIN IMMEDIATE")
|
|
186
|
+
has_user_schema_objects = (
|
|
187
|
+
conn.execute(
|
|
188
|
+
"SELECT 1 FROM sqlite_master "
|
|
189
|
+
"WHERE substr(name, 1, 7) != 'sqlite_' LIMIT 1"
|
|
190
|
+
).fetchone()
|
|
191
|
+
is not None
|
|
192
|
+
)
|
|
193
|
+
had_goal_schema_before_bootstrap = _has_goal_schema_objects(conn)
|
|
194
|
+
is_pristine = (
|
|
195
|
+
not has_user_schema_objects and not had_goal_schema_before_bootstrap
|
|
196
|
+
)
|
|
197
|
+
had_kv_store_before_bootstrap = (
|
|
198
|
+
conn.execute(
|
|
199
|
+
"SELECT 1 FROM sqlite_master WHERE type = 'table' "
|
|
200
|
+
"AND name = 'kv_store'"
|
|
201
|
+
).fetchone()
|
|
202
|
+
is not None
|
|
203
|
+
)
|
|
204
|
+
skip_kv_bootstrap = (
|
|
205
|
+
project_db
|
|
206
|
+
and not had_kv_store_before_bootstrap
|
|
207
|
+
and had_goal_schema_before_bootstrap
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
schema_sql = CREATE_SQL
|
|
211
|
+
if not fts_available:
|
|
212
|
+
schema_sql = re.sub(
|
|
213
|
+
r"CREATE VIRTUAL TABLE IF NOT EXISTS kv_store_fts.*?;",
|
|
214
|
+
"",
|
|
215
|
+
schema_sql,
|
|
216
|
+
flags=re.DOTALL,
|
|
217
|
+
)
|
|
218
|
+
if not skip_kv_bootstrap:
|
|
219
|
+
_execute_sql_statements(conn, schema_sql)
|
|
220
|
+
_ensure_revision_column(conn)
|
|
221
|
+
|
|
222
|
+
# An empty DB has nothing to preserve, so initializing both schemas
|
|
223
|
+
# cannot destroy user data; any DB with user schema is never touched
|
|
224
|
+
# for goals. A rolled-back first init leaves no schema, so retry sees
|
|
225
|
+
# pristine again.
|
|
226
|
+
if project_db and is_pristine:
|
|
227
|
+
upgrade_goal_schema(
|
|
228
|
+
conn,
|
|
229
|
+
expected_path=db_path,
|
|
230
|
+
explicit_project_db=globals().get("_project_db_explicit", False),
|
|
231
|
+
_transaction_active=True,
|
|
232
|
+
)
|
|
233
|
+
conn.commit()
|
|
234
|
+
conn.execute("PRAGMA journal_mode=WAL")
|
|
235
|
+
return conn
|
|
236
|
+
except BaseException:
|
|
237
|
+
with suppress(sqlite3.Error):
|
|
238
|
+
conn.rollback()
|
|
239
|
+
conn.close()
|
|
240
|
+
raise
|
|
241
|
+
finally:
|
|
242
|
+
if lock_acquired:
|
|
243
|
+
_release_init_lock(lock_fd)
|
|
244
|
+
os.close(lock_fd)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _acquire_init_lock(lock_fd: int) -> None:
|
|
248
|
+
"""Lock the per-database initializer gate across processes."""
|
|
249
|
+
if os.name != "nt":
|
|
250
|
+
fcntl.flock(lock_fd, fcntl.LOCK_EX)
|
|
251
|
+
return
|
|
252
|
+
|
|
253
|
+
if os.fstat(lock_fd).st_size == 0:
|
|
254
|
+
os.write(lock_fd, b"\0")
|
|
255
|
+
os.lseek(lock_fd, 0, os.SEEK_SET)
|
|
256
|
+
while True:
|
|
257
|
+
try:
|
|
258
|
+
msvcrt.locking(lock_fd, msvcrt.LK_NBLCK, 1)
|
|
259
|
+
return
|
|
260
|
+
except OSError as exc:
|
|
261
|
+
if exc.errno not in (errno.EACCES, errno.EDEADLOCK, errno.EAGAIN):
|
|
262
|
+
raise
|
|
263
|
+
time.sleep(0.05)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _release_init_lock(lock_fd: int) -> None:
|
|
267
|
+
"""Release the per-database initializer gate."""
|
|
268
|
+
if os.name != "nt":
|
|
269
|
+
fcntl.flock(lock_fd, fcntl.LOCK_UN)
|
|
270
|
+
return
|
|
271
|
+
os.lseek(lock_fd, 0, os.SEEK_SET)
|
|
272
|
+
msvcrt.locking(lock_fd, msvcrt.LK_UNLCK, 1)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _connect_or_create_database(db_path: Path) -> sqlite3.Connection:
|
|
276
|
+
"""Open an existing database or create an empty SQLite file."""
|
|
277
|
+
database_uri = db_path.resolve().as_uri()
|
|
278
|
+
try:
|
|
279
|
+
conn = sqlite3.connect(
|
|
280
|
+
f"{database_uri}?mode=rw", uri=True, check_same_thread=False
|
|
281
|
+
)
|
|
282
|
+
except sqlite3.OperationalError as exc:
|
|
283
|
+
if "unable to open database file" not in str(exc).lower():
|
|
284
|
+
raise
|
|
285
|
+
conn = sqlite3.connect(
|
|
286
|
+
f"{database_uri}?mode=rwc", uri=True, check_same_thread=False
|
|
287
|
+
)
|
|
288
|
+
return conn
|
|
131
289
|
return conn
|
|
132
290
|
|
|
133
291
|
|
|
292
|
+
def _execute_sql_statements(conn: sqlite3.Connection, script: str) -> None:
|
|
293
|
+
"""Execute a SQL script statement-by-statement without implicit commits."""
|
|
294
|
+
pending = ""
|
|
295
|
+
for line in script.splitlines(keepends=True):
|
|
296
|
+
pending += line
|
|
297
|
+
if sqlite3.complete_statement(pending):
|
|
298
|
+
if pending.strip():
|
|
299
|
+
conn.execute(pending)
|
|
300
|
+
pending = ""
|
|
301
|
+
if pending.strip():
|
|
302
|
+
raise sqlite3.ProgrammingError("incomplete SQL schema statement")
|
|
303
|
+
|
|
304
|
+
|
|
134
305
|
# `revision` was added after `kv_store` shipped, so an existing database has the
|
|
135
306
|
# column only if it is added here. ADD COLUMN is additive and non-destructive:
|
|
136
307
|
# pre-existing rows get NULL, which every reader treats as "no revision yet"
|
|
@@ -213,6 +384,18 @@ class GoalSchemaNotInitializedError(GoalStoreError):
|
|
|
213
384
|
"""Raised when goal operations target a DB without the goal schema."""
|
|
214
385
|
|
|
215
386
|
|
|
387
|
+
class GoalDatabaseInconsistentError(GoalSchemaNotInitializedError):
|
|
388
|
+
"""Raised when the goal schema exists but the Persistence KV schema is absent."""
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
_GOAL_DATABASE_INCONSISTENT_MESSAGE = (
|
|
392
|
+
"Persistence database is inconsistent: KV schema is missing while goal "
|
|
393
|
+
"schema is present; repair is required before goal operations. Stop the "
|
|
394
|
+
"server and restore a verified backup or have an administrator repair "
|
|
395
|
+
"the schema."
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
|
|
216
399
|
class GoalSchemaVersionError(GoalStoreError):
|
|
217
400
|
"""Raised for an unsupported or inconsistent goal schema migration version."""
|
|
218
401
|
|
|
@@ -265,6 +448,7 @@ def _assert_project_goal_connection(
|
|
|
265
448
|
raise GoalSchemaNotInitializedError(
|
|
266
449
|
"goal operations require this server's Persistence database"
|
|
267
450
|
)
|
|
451
|
+
_assert_not_global_goal_path(expected_path)
|
|
268
452
|
project_path = Path(expected_path).expanduser().resolve()
|
|
269
453
|
if not explicit_project_db:
|
|
270
454
|
server_path = _resolve_project_db_path()
|
|
@@ -285,12 +469,20 @@ def _assert_project_goal_connection(
|
|
|
285
469
|
"goal operations are restricted to this server's Persistence database"
|
|
286
470
|
)
|
|
287
471
|
try:
|
|
288
|
-
has_kv_store = conn.execute(
|
|
289
|
-
"SELECT
|
|
472
|
+
has_kv_store, has_goal_schema = conn.execute(
|
|
473
|
+
"SELECT "
|
|
474
|
+
"EXISTS(SELECT 1 FROM sqlite_master WHERE type = 'table' "
|
|
475
|
+
"AND name = 'kv_store'), "
|
|
476
|
+
"EXISTS(SELECT 1 FROM sqlite_master WHERE name IN ("
|
|
477
|
+
"'pantheon_goals', 'uq_pantheon_goals_active_session', "
|
|
478
|
+
"'idx_pantheon_goals_session_history', "
|
|
479
|
+
"'pantheon_goal_schema_migrations'))"
|
|
290
480
|
).fetchone()
|
|
291
481
|
except sqlite3.Error as exc:
|
|
292
482
|
raise GoalStorageError("could not verify Persistence database schema") from exc
|
|
293
|
-
if has_kv_store
|
|
483
|
+
if not has_kv_store and has_goal_schema:
|
|
484
|
+
raise GoalDatabaseInconsistentError(_GOAL_DATABASE_INCONSISTENT_MESSAGE)
|
|
485
|
+
if not has_kv_store:
|
|
294
486
|
raise GoalSchemaNotInitializedError(
|
|
295
487
|
"goal operations require an existing Pantheon Persistence database; "
|
|
296
488
|
"ask the user to start the server once first"
|
|
@@ -335,6 +527,7 @@ def upgrade_goal_schema(
|
|
|
335
527
|
expected_path: str | Path | None = None,
|
|
336
528
|
*,
|
|
337
529
|
explicit_project_db: bool | None = None,
|
|
530
|
+
_transaction_active: bool = False,
|
|
338
531
|
) -> None:
|
|
339
532
|
"""Apply goal schema upgrades to the explicitly supplied Persistence DB."""
|
|
340
533
|
_assert_project_goal_connection(
|
|
@@ -347,46 +540,58 @@ def upgrade_goal_schema(
|
|
|
347
540
|
),
|
|
348
541
|
)
|
|
349
542
|
try:
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
conn.execute(
|
|
360
|
-
"CREATE TABLE pantheon_goals ("
|
|
361
|
-
"goal_id TEXT PRIMARY KEY NOT NULL, "
|
|
362
|
-
"session_id TEXT NOT NULL CHECK ("
|
|
363
|
-
"length(trim(session_id)) BETWEEN 1 AND 128 AND "
|
|
364
|
-
"session_id = trim(session_id)), "
|
|
365
|
-
"title TEXT NOT NULL CHECK ("
|
|
366
|
-
"length(title) BETWEEN 1 AND 512 AND length(trim(title)) > 0), "
|
|
367
|
-
"description TEXT CHECK (description IS NULL OR "
|
|
368
|
-
"length(description) <= 16384), "
|
|
369
|
-
"status TEXT NOT NULL CHECK (status IN ('active', 'done')), "
|
|
370
|
-
"created_at TEXT NOT NULL, updated_at TEXT NOT NULL, "
|
|
371
|
-
"version INTEGER NOT NULL CHECK (version > 0))"
|
|
372
|
-
)
|
|
373
|
-
conn.execute(
|
|
374
|
-
"CREATE UNIQUE INDEX uq_pantheon_goals_active_session "
|
|
375
|
-
"ON pantheon_goals(session_id) WHERE status = 'active'"
|
|
376
|
-
)
|
|
377
|
-
conn.execute(
|
|
378
|
-
"CREATE INDEX idx_pantheon_goals_session_history "
|
|
379
|
-
"ON pantheon_goals(session_id, created_at DESC, goal_id DESC)"
|
|
380
|
-
)
|
|
381
|
-
conn.execute(
|
|
382
|
-
"INSERT INTO pantheon_goal_schema_migrations(version, applied_at) "
|
|
383
|
-
"VALUES (?, ?)",
|
|
384
|
-
(GOAL_SCHEMA_VERSION, _goal_timestamp()),
|
|
385
|
-
)
|
|
543
|
+
if _transaction_active:
|
|
544
|
+
if not conn.in_transaction:
|
|
545
|
+
raise GoalStorageError(
|
|
546
|
+
"goal schema upgrade requires an active transaction"
|
|
547
|
+
)
|
|
548
|
+
_upgrade_goal_schema_in_transaction(conn)
|
|
549
|
+
else:
|
|
550
|
+
with _goal_transaction(conn):
|
|
551
|
+
_upgrade_goal_schema_in_transaction(conn)
|
|
386
552
|
except sqlite3.Error as exc:
|
|
387
553
|
raise GoalStorageError("could not upgrade Persistence goal schema") from exc
|
|
388
554
|
|
|
389
555
|
|
|
556
|
+
def _upgrade_goal_schema_in_transaction(conn: sqlite3.Connection) -> None:
|
|
557
|
+
"""Apply goal DDL using the caller's active transaction."""
|
|
558
|
+
current = _inspect_goal_schema_version(conn)
|
|
559
|
+
if current == GOAL_SCHEMA_VERSION:
|
|
560
|
+
return
|
|
561
|
+
conn.execute(
|
|
562
|
+
"CREATE TABLE IF NOT EXISTS pantheon_goal_schema_migrations ("
|
|
563
|
+
"version INTEGER PRIMARY KEY CHECK (version > 0), "
|
|
564
|
+
"applied_at TEXT NOT NULL)"
|
|
565
|
+
)
|
|
566
|
+
conn.execute(
|
|
567
|
+
"CREATE TABLE pantheon_goals ("
|
|
568
|
+
"goal_id TEXT PRIMARY KEY NOT NULL, "
|
|
569
|
+
"session_id TEXT NOT NULL CHECK ("
|
|
570
|
+
"length(trim(session_id)) BETWEEN 1 AND 128 AND "
|
|
571
|
+
"session_id = trim(session_id)), "
|
|
572
|
+
"title TEXT NOT NULL CHECK ("
|
|
573
|
+
"length(title) BETWEEN 1 AND 512 AND length(trim(title)) > 0), "
|
|
574
|
+
"description TEXT CHECK (description IS NULL OR "
|
|
575
|
+
"length(description) <= 16384), "
|
|
576
|
+
"status TEXT NOT NULL CHECK (status IN ('active', 'done')), "
|
|
577
|
+
"created_at TEXT NOT NULL, updated_at TEXT NOT NULL, "
|
|
578
|
+
"version INTEGER NOT NULL CHECK (version > 0))"
|
|
579
|
+
)
|
|
580
|
+
conn.execute(
|
|
581
|
+
"CREATE UNIQUE INDEX uq_pantheon_goals_active_session "
|
|
582
|
+
"ON pantheon_goals(session_id) WHERE status = 'active'"
|
|
583
|
+
)
|
|
584
|
+
conn.execute(
|
|
585
|
+
"CREATE INDEX idx_pantheon_goals_session_history "
|
|
586
|
+
"ON pantheon_goals(session_id, created_at DESC, goal_id DESC)"
|
|
587
|
+
)
|
|
588
|
+
conn.execute(
|
|
589
|
+
"INSERT INTO pantheon_goal_schema_migrations(version, applied_at) "
|
|
590
|
+
"VALUES (?, ?)",
|
|
591
|
+
(GOAL_SCHEMA_VERSION, _goal_timestamp()),
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
|
|
390
595
|
def downgrade_goal_schema(
|
|
391
596
|
conn: sqlite3.Connection,
|
|
392
597
|
target_version: int = 0,
|
|
@@ -868,6 +1073,7 @@ def migrate_goal_schema_with_backup(
|
|
|
868
1073
|
) -> tuple[Path, Path | None, int, bool]:
|
|
869
1074
|
"""Back up an existing Persistence DB, then migrate its goal schema."""
|
|
870
1075
|
db_path = Path(project_db_path).expanduser().resolve()
|
|
1076
|
+
_assert_not_global_goal_path(db_path)
|
|
871
1077
|
if not db_path.is_file():
|
|
872
1078
|
raise GoalSchemaNotInitializedError(
|
|
873
1079
|
f"Persistence database does not exist at {db_path}; "
|
|
@@ -884,6 +1090,8 @@ def migrate_goal_schema_with_backup(
|
|
|
884
1090
|
"SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'kv_store'"
|
|
885
1091
|
).fetchone()
|
|
886
1092
|
if has_kv_store is None:
|
|
1093
|
+
if _has_goal_schema_objects(source):
|
|
1094
|
+
raise GoalDatabaseInconsistentError(_GOAL_DATABASE_INCONSISTENT_MESSAGE)
|
|
887
1095
|
raise GoalSchemaNotInitializedError(
|
|
888
1096
|
"target is not a Pantheon Persistence database: kv_store is missing; "
|
|
889
1097
|
"ask the user to start the server once first"
|
|
@@ -1187,10 +1395,12 @@ if args.dry_run and not args.migrate_goals:
|
|
|
1187
1395
|
|
|
1188
1396
|
_project_db_path: Path | None = None
|
|
1189
1397
|
_project_db_explicit = args.project_db is not None
|
|
1398
|
+
_global_db_path = _resolve_global_db_path(args.global_db)
|
|
1190
1399
|
if args.migrate_goals:
|
|
1191
1400
|
_warn_if_symlinked_launcher()
|
|
1192
1401
|
try:
|
|
1193
1402
|
migration_db_path = _resolve_project_db_path(args.project_db)
|
|
1403
|
+
_assert_not_global_goal_path(migration_db_path)
|
|
1194
1404
|
if args.dry_run:
|
|
1195
1405
|
raise SystemExit(_print_goal_migration_dry_run(migration_db_path))
|
|
1196
1406
|
db_path, backup_path, version, already_current = (
|
|
@@ -1212,13 +1422,10 @@ if args.migrate_goals:
|
|
|
1212
1422
|
print("Goal schema migration applied.")
|
|
1213
1423
|
raise SystemExit(0)
|
|
1214
1424
|
|
|
1215
|
-
|
|
1216
|
-
Path(args.global_db) if args.global_db else pantheon_home() / "persistence"
|
|
1217
|
-
)
|
|
1218
|
-
_global_db = _init_db(_global_root / "global.db")
|
|
1425
|
+
_global_db = _init_db(_global_db_path)
|
|
1219
1426
|
|
|
1220
1427
|
_project_db_path = _resolve_project_db_path(args.project_db)
|
|
1221
|
-
_project_db_instance = _init_db(_project_db_path)
|
|
1428
|
+
_project_db_instance = _init_db(_project_db_path, project_db=True)
|
|
1222
1429
|
_project_db = _project_db_instance
|
|
1223
1430
|
|
|
1224
1431
|
|
|
@@ -12,6 +12,7 @@ Usage:
|
|
|
12
12
|
from __future__ import annotations
|
|
13
13
|
|
|
14
14
|
import argparse
|
|
15
|
+
import errno
|
|
15
16
|
import json
|
|
16
17
|
import os
|
|
17
18
|
import re
|
|
@@ -27,6 +28,11 @@ from pathlib import Path
|
|
|
27
28
|
from typing import Annotated, Literal
|
|
28
29
|
from uuid import uuid4
|
|
29
30
|
|
|
31
|
+
if os.name == "nt":
|
|
32
|
+
import msvcrt
|
|
33
|
+
else:
|
|
34
|
+
import fcntl
|
|
35
|
+
|
|
30
36
|
from _pantheon_paths import pantheon_home
|
|
31
37
|
from fastmcp import Context, FastMCP
|
|
32
38
|
from fastmcp.exceptions import ToolError
|
|
@@ -96,41 +102,206 @@ mcp = FastMCP(
|
|
|
96
102
|
|
|
97
103
|
_global_db: sqlite3.Connection | None = None
|
|
98
104
|
_project_db: sqlite3.Connection | None = None
|
|
105
|
+
_global_db_path: Path | None = None
|
|
99
106
|
|
|
100
107
|
|
|
101
|
-
def
|
|
102
|
-
"""
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
def _has_goal_schema_objects(conn: sqlite3.Connection) -> bool:
|
|
109
|
+
"""Check for goal tables or indexes, including migration-history remnants."""
|
|
110
|
+
return (
|
|
111
|
+
conn.execute(
|
|
112
|
+
"SELECT 1 FROM sqlite_master WHERE name IN ("
|
|
113
|
+
"'pantheon_goals', 'uq_pantheon_goals_active_session', "
|
|
114
|
+
"'idx_pantheon_goals_session_history', "
|
|
115
|
+
"'pantheon_goal_schema_migrations') LIMIT 1"
|
|
116
|
+
).fetchone()
|
|
117
|
+
is not None
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _resolve_global_db_path(global_db: str | Path | None = None) -> Path:
|
|
122
|
+
"""Resolve the global database path from its configured persistence root."""
|
|
123
|
+
root = (
|
|
124
|
+
Path(global_db).expanduser()
|
|
125
|
+
if global_db is not None
|
|
126
|
+
else pantheon_home() / "persistence"
|
|
127
|
+
)
|
|
128
|
+
return (root / "global.db").resolve()
|
|
129
|
+
|
|
118
130
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
def _assert_not_global_goal_path(db_path: str | Path) -> None:
|
|
132
|
+
"""Keep goal schema changes categorically away from the global database."""
|
|
133
|
+
target = Path(db_path).expanduser().resolve()
|
|
134
|
+
global_path = globals().get("_global_db_path") or _resolve_global_db_path()
|
|
135
|
+
resolves_to_global = target == global_path
|
|
136
|
+
if not resolves_to_global:
|
|
137
|
+
try:
|
|
138
|
+
target_stat = target.stat()
|
|
139
|
+
global_stat = global_path.stat()
|
|
140
|
+
except FileNotFoundError:
|
|
141
|
+
pass
|
|
142
|
+
else:
|
|
143
|
+
resolves_to_global = (target_stat.st_dev, target_stat.st_ino) == (
|
|
144
|
+
global_stat.st_dev,
|
|
145
|
+
global_stat.st_ino,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if resolves_to_global:
|
|
149
|
+
raise GoalSchemaNotInitializedError(
|
|
150
|
+
"goal schema migration and DDL are prohibited for the global "
|
|
151
|
+
f"Persistence database ({global_path}); the target resolves to the "
|
|
152
|
+
"global database; choose a separate project database with --project-db"
|
|
124
153
|
)
|
|
125
|
-
conn.executescript(_no_fts)
|
|
126
|
-
else:
|
|
127
|
-
conn.executescript(CREATE_SQL)
|
|
128
|
-
_ensure_revision_column(conn)
|
|
129
|
-
conn.commit()
|
|
130
154
|
|
|
155
|
+
|
|
156
|
+
def _init_db(db_path: Path, *, project_db: bool = False) -> sqlite3.Connection:
|
|
157
|
+
"""Initialize the KV schema and goal schema only for a pristine project DB."""
|
|
158
|
+
if project_db:
|
|
159
|
+
_assert_not_global_goal_path(db_path)
|
|
160
|
+
db_path.parent.mkdir(parents=True, exist_ok=True)
|
|
161
|
+
lock_path = db_path.with_name(f".{db_path.name}.init.lock")
|
|
162
|
+
lock_fd = os.open(lock_path, os.O_CREAT | os.O_RDWR, 0o600)
|
|
163
|
+
lock_acquired = False
|
|
164
|
+
try:
|
|
165
|
+
# Serialize initialization across processes.
|
|
166
|
+
_acquire_init_lock(lock_fd)
|
|
167
|
+
lock_acquired = True
|
|
168
|
+
conn = _connect_or_create_database(db_path)
|
|
169
|
+
try:
|
|
170
|
+
conn.execute("PRAGMA busy_timeout=5000")
|
|
171
|
+
conn.execute("PRAGMA foreign_keys=ON")
|
|
172
|
+
fts_available = any(
|
|
173
|
+
"ENABLE_FTS5" in row[0]
|
|
174
|
+
for row in conn.execute("PRAGMA compile_options").fetchall()
|
|
175
|
+
)
|
|
176
|
+
if not fts_available:
|
|
177
|
+
print(
|
|
178
|
+
"WARNING: SQLite FTS5 unavailable; the internal full-text index "
|
|
179
|
+
"was not initialized.",
|
|
180
|
+
file=sys.stderr,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
# SQLite's writer lock serializes the schema inspection and every
|
|
184
|
+
# DDL statement. Never use executescript here: it commits implicitly.
|
|
185
|
+
conn.execute("BEGIN IMMEDIATE")
|
|
186
|
+
has_user_schema_objects = (
|
|
187
|
+
conn.execute(
|
|
188
|
+
"SELECT 1 FROM sqlite_master "
|
|
189
|
+
"WHERE substr(name, 1, 7) != 'sqlite_' LIMIT 1"
|
|
190
|
+
).fetchone()
|
|
191
|
+
is not None
|
|
192
|
+
)
|
|
193
|
+
had_goal_schema_before_bootstrap = _has_goal_schema_objects(conn)
|
|
194
|
+
is_pristine = (
|
|
195
|
+
not has_user_schema_objects and not had_goal_schema_before_bootstrap
|
|
196
|
+
)
|
|
197
|
+
had_kv_store_before_bootstrap = (
|
|
198
|
+
conn.execute(
|
|
199
|
+
"SELECT 1 FROM sqlite_master WHERE type = 'table' "
|
|
200
|
+
"AND name = 'kv_store'"
|
|
201
|
+
).fetchone()
|
|
202
|
+
is not None
|
|
203
|
+
)
|
|
204
|
+
skip_kv_bootstrap = (
|
|
205
|
+
project_db
|
|
206
|
+
and not had_kv_store_before_bootstrap
|
|
207
|
+
and had_goal_schema_before_bootstrap
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
schema_sql = CREATE_SQL
|
|
211
|
+
if not fts_available:
|
|
212
|
+
schema_sql = re.sub(
|
|
213
|
+
r"CREATE VIRTUAL TABLE IF NOT EXISTS kv_store_fts.*?;",
|
|
214
|
+
"",
|
|
215
|
+
schema_sql,
|
|
216
|
+
flags=re.DOTALL,
|
|
217
|
+
)
|
|
218
|
+
if not skip_kv_bootstrap:
|
|
219
|
+
_execute_sql_statements(conn, schema_sql)
|
|
220
|
+
_ensure_revision_column(conn)
|
|
221
|
+
|
|
222
|
+
# An empty DB has nothing to preserve, so initializing both schemas
|
|
223
|
+
# cannot destroy user data; any DB with user schema is never touched
|
|
224
|
+
# for goals. A rolled-back first init leaves no schema, so retry sees
|
|
225
|
+
# pristine again.
|
|
226
|
+
if project_db and is_pristine:
|
|
227
|
+
upgrade_goal_schema(
|
|
228
|
+
conn,
|
|
229
|
+
expected_path=db_path,
|
|
230
|
+
explicit_project_db=globals().get("_project_db_explicit", False),
|
|
231
|
+
_transaction_active=True,
|
|
232
|
+
)
|
|
233
|
+
conn.commit()
|
|
234
|
+
conn.execute("PRAGMA journal_mode=WAL")
|
|
235
|
+
return conn
|
|
236
|
+
except BaseException:
|
|
237
|
+
with suppress(sqlite3.Error):
|
|
238
|
+
conn.rollback()
|
|
239
|
+
conn.close()
|
|
240
|
+
raise
|
|
241
|
+
finally:
|
|
242
|
+
if lock_acquired:
|
|
243
|
+
_release_init_lock(lock_fd)
|
|
244
|
+
os.close(lock_fd)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _acquire_init_lock(lock_fd: int) -> None:
|
|
248
|
+
"""Lock the per-database initializer gate across processes."""
|
|
249
|
+
if os.name != "nt":
|
|
250
|
+
fcntl.flock(lock_fd, fcntl.LOCK_EX)
|
|
251
|
+
return
|
|
252
|
+
|
|
253
|
+
if os.fstat(lock_fd).st_size == 0:
|
|
254
|
+
os.write(lock_fd, b"\0")
|
|
255
|
+
os.lseek(lock_fd, 0, os.SEEK_SET)
|
|
256
|
+
while True:
|
|
257
|
+
try:
|
|
258
|
+
msvcrt.locking(lock_fd, msvcrt.LK_NBLCK, 1)
|
|
259
|
+
return
|
|
260
|
+
except OSError as exc:
|
|
261
|
+
if exc.errno not in (errno.EACCES, errno.EDEADLOCK, errno.EAGAIN):
|
|
262
|
+
raise
|
|
263
|
+
time.sleep(0.05)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _release_init_lock(lock_fd: int) -> None:
|
|
267
|
+
"""Release the per-database initializer gate."""
|
|
268
|
+
if os.name != "nt":
|
|
269
|
+
fcntl.flock(lock_fd, fcntl.LOCK_UN)
|
|
270
|
+
return
|
|
271
|
+
os.lseek(lock_fd, 0, os.SEEK_SET)
|
|
272
|
+
msvcrt.locking(lock_fd, msvcrt.LK_UNLCK, 1)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _connect_or_create_database(db_path: Path) -> sqlite3.Connection:
|
|
276
|
+
"""Open an existing database or create an empty SQLite file."""
|
|
277
|
+
database_uri = db_path.resolve().as_uri()
|
|
278
|
+
try:
|
|
279
|
+
conn = sqlite3.connect(
|
|
280
|
+
f"{database_uri}?mode=rw", uri=True, check_same_thread=False
|
|
281
|
+
)
|
|
282
|
+
except sqlite3.OperationalError as exc:
|
|
283
|
+
if "unable to open database file" not in str(exc).lower():
|
|
284
|
+
raise
|
|
285
|
+
conn = sqlite3.connect(
|
|
286
|
+
f"{database_uri}?mode=rwc", uri=True, check_same_thread=False
|
|
287
|
+
)
|
|
288
|
+
return conn
|
|
131
289
|
return conn
|
|
132
290
|
|
|
133
291
|
|
|
292
|
+
def _execute_sql_statements(conn: sqlite3.Connection, script: str) -> None:
|
|
293
|
+
"""Execute a SQL script statement-by-statement without implicit commits."""
|
|
294
|
+
pending = ""
|
|
295
|
+
for line in script.splitlines(keepends=True):
|
|
296
|
+
pending += line
|
|
297
|
+
if sqlite3.complete_statement(pending):
|
|
298
|
+
if pending.strip():
|
|
299
|
+
conn.execute(pending)
|
|
300
|
+
pending = ""
|
|
301
|
+
if pending.strip():
|
|
302
|
+
raise sqlite3.ProgrammingError("incomplete SQL schema statement")
|
|
303
|
+
|
|
304
|
+
|
|
134
305
|
# `revision` was added after `kv_store` shipped, so an existing database has the
|
|
135
306
|
# column only if it is added here. ADD COLUMN is additive and non-destructive:
|
|
136
307
|
# pre-existing rows get NULL, which every reader treats as "no revision yet"
|
|
@@ -213,6 +384,18 @@ class GoalSchemaNotInitializedError(GoalStoreError):
|
|
|
213
384
|
"""Raised when goal operations target a DB without the goal schema."""
|
|
214
385
|
|
|
215
386
|
|
|
387
|
+
class GoalDatabaseInconsistentError(GoalSchemaNotInitializedError):
|
|
388
|
+
"""Raised when the goal schema exists but the Persistence KV schema is absent."""
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
_GOAL_DATABASE_INCONSISTENT_MESSAGE = (
|
|
392
|
+
"Persistence database is inconsistent: KV schema is missing while goal "
|
|
393
|
+
"schema is present; repair is required before goal operations. Stop the "
|
|
394
|
+
"server and restore a verified backup or have an administrator repair "
|
|
395
|
+
"the schema."
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
|
|
216
399
|
class GoalSchemaVersionError(GoalStoreError):
|
|
217
400
|
"""Raised for an unsupported or inconsistent goal schema migration version."""
|
|
218
401
|
|
|
@@ -265,6 +448,7 @@ def _assert_project_goal_connection(
|
|
|
265
448
|
raise GoalSchemaNotInitializedError(
|
|
266
449
|
"goal operations require this server's Persistence database"
|
|
267
450
|
)
|
|
451
|
+
_assert_not_global_goal_path(expected_path)
|
|
268
452
|
project_path = Path(expected_path).expanduser().resolve()
|
|
269
453
|
if not explicit_project_db:
|
|
270
454
|
server_path = _resolve_project_db_path()
|
|
@@ -285,12 +469,20 @@ def _assert_project_goal_connection(
|
|
|
285
469
|
"goal operations are restricted to this server's Persistence database"
|
|
286
470
|
)
|
|
287
471
|
try:
|
|
288
|
-
has_kv_store = conn.execute(
|
|
289
|
-
"SELECT
|
|
472
|
+
has_kv_store, has_goal_schema = conn.execute(
|
|
473
|
+
"SELECT "
|
|
474
|
+
"EXISTS(SELECT 1 FROM sqlite_master WHERE type = 'table' "
|
|
475
|
+
"AND name = 'kv_store'), "
|
|
476
|
+
"EXISTS(SELECT 1 FROM sqlite_master WHERE name IN ("
|
|
477
|
+
"'pantheon_goals', 'uq_pantheon_goals_active_session', "
|
|
478
|
+
"'idx_pantheon_goals_session_history', "
|
|
479
|
+
"'pantheon_goal_schema_migrations'))"
|
|
290
480
|
).fetchone()
|
|
291
481
|
except sqlite3.Error as exc:
|
|
292
482
|
raise GoalStorageError("could not verify Persistence database schema") from exc
|
|
293
|
-
if has_kv_store
|
|
483
|
+
if not has_kv_store and has_goal_schema:
|
|
484
|
+
raise GoalDatabaseInconsistentError(_GOAL_DATABASE_INCONSISTENT_MESSAGE)
|
|
485
|
+
if not has_kv_store:
|
|
294
486
|
raise GoalSchemaNotInitializedError(
|
|
295
487
|
"goal operations require an existing Pantheon Persistence database; "
|
|
296
488
|
"ask the user to start the server once first"
|
|
@@ -335,6 +527,7 @@ def upgrade_goal_schema(
|
|
|
335
527
|
expected_path: str | Path | None = None,
|
|
336
528
|
*,
|
|
337
529
|
explicit_project_db: bool | None = None,
|
|
530
|
+
_transaction_active: bool = False,
|
|
338
531
|
) -> None:
|
|
339
532
|
"""Apply goal schema upgrades to the explicitly supplied Persistence DB."""
|
|
340
533
|
_assert_project_goal_connection(
|
|
@@ -347,46 +540,58 @@ def upgrade_goal_schema(
|
|
|
347
540
|
),
|
|
348
541
|
)
|
|
349
542
|
try:
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
conn.execute(
|
|
360
|
-
"CREATE TABLE pantheon_goals ("
|
|
361
|
-
"goal_id TEXT PRIMARY KEY NOT NULL, "
|
|
362
|
-
"session_id TEXT NOT NULL CHECK ("
|
|
363
|
-
"length(trim(session_id)) BETWEEN 1 AND 128 AND "
|
|
364
|
-
"session_id = trim(session_id)), "
|
|
365
|
-
"title TEXT NOT NULL CHECK ("
|
|
366
|
-
"length(title) BETWEEN 1 AND 512 AND length(trim(title)) > 0), "
|
|
367
|
-
"description TEXT CHECK (description IS NULL OR "
|
|
368
|
-
"length(description) <= 16384), "
|
|
369
|
-
"status TEXT NOT NULL CHECK (status IN ('active', 'done')), "
|
|
370
|
-
"created_at TEXT NOT NULL, updated_at TEXT NOT NULL, "
|
|
371
|
-
"version INTEGER NOT NULL CHECK (version > 0))"
|
|
372
|
-
)
|
|
373
|
-
conn.execute(
|
|
374
|
-
"CREATE UNIQUE INDEX uq_pantheon_goals_active_session "
|
|
375
|
-
"ON pantheon_goals(session_id) WHERE status = 'active'"
|
|
376
|
-
)
|
|
377
|
-
conn.execute(
|
|
378
|
-
"CREATE INDEX idx_pantheon_goals_session_history "
|
|
379
|
-
"ON pantheon_goals(session_id, created_at DESC, goal_id DESC)"
|
|
380
|
-
)
|
|
381
|
-
conn.execute(
|
|
382
|
-
"INSERT INTO pantheon_goal_schema_migrations(version, applied_at) "
|
|
383
|
-
"VALUES (?, ?)",
|
|
384
|
-
(GOAL_SCHEMA_VERSION, _goal_timestamp()),
|
|
385
|
-
)
|
|
543
|
+
if _transaction_active:
|
|
544
|
+
if not conn.in_transaction:
|
|
545
|
+
raise GoalStorageError(
|
|
546
|
+
"goal schema upgrade requires an active transaction"
|
|
547
|
+
)
|
|
548
|
+
_upgrade_goal_schema_in_transaction(conn)
|
|
549
|
+
else:
|
|
550
|
+
with _goal_transaction(conn):
|
|
551
|
+
_upgrade_goal_schema_in_transaction(conn)
|
|
386
552
|
except sqlite3.Error as exc:
|
|
387
553
|
raise GoalStorageError("could not upgrade Persistence goal schema") from exc
|
|
388
554
|
|
|
389
555
|
|
|
556
|
+
def _upgrade_goal_schema_in_transaction(conn: sqlite3.Connection) -> None:
|
|
557
|
+
"""Apply goal DDL using the caller's active transaction."""
|
|
558
|
+
current = _inspect_goal_schema_version(conn)
|
|
559
|
+
if current == GOAL_SCHEMA_VERSION:
|
|
560
|
+
return
|
|
561
|
+
conn.execute(
|
|
562
|
+
"CREATE TABLE IF NOT EXISTS pantheon_goal_schema_migrations ("
|
|
563
|
+
"version INTEGER PRIMARY KEY CHECK (version > 0), "
|
|
564
|
+
"applied_at TEXT NOT NULL)"
|
|
565
|
+
)
|
|
566
|
+
conn.execute(
|
|
567
|
+
"CREATE TABLE pantheon_goals ("
|
|
568
|
+
"goal_id TEXT PRIMARY KEY NOT NULL, "
|
|
569
|
+
"session_id TEXT NOT NULL CHECK ("
|
|
570
|
+
"length(trim(session_id)) BETWEEN 1 AND 128 AND "
|
|
571
|
+
"session_id = trim(session_id)), "
|
|
572
|
+
"title TEXT NOT NULL CHECK ("
|
|
573
|
+
"length(title) BETWEEN 1 AND 512 AND length(trim(title)) > 0), "
|
|
574
|
+
"description TEXT CHECK (description IS NULL OR "
|
|
575
|
+
"length(description) <= 16384), "
|
|
576
|
+
"status TEXT NOT NULL CHECK (status IN ('active', 'done')), "
|
|
577
|
+
"created_at TEXT NOT NULL, updated_at TEXT NOT NULL, "
|
|
578
|
+
"version INTEGER NOT NULL CHECK (version > 0))"
|
|
579
|
+
)
|
|
580
|
+
conn.execute(
|
|
581
|
+
"CREATE UNIQUE INDEX uq_pantheon_goals_active_session "
|
|
582
|
+
"ON pantheon_goals(session_id) WHERE status = 'active'"
|
|
583
|
+
)
|
|
584
|
+
conn.execute(
|
|
585
|
+
"CREATE INDEX idx_pantheon_goals_session_history "
|
|
586
|
+
"ON pantheon_goals(session_id, created_at DESC, goal_id DESC)"
|
|
587
|
+
)
|
|
588
|
+
conn.execute(
|
|
589
|
+
"INSERT INTO pantheon_goal_schema_migrations(version, applied_at) "
|
|
590
|
+
"VALUES (?, ?)",
|
|
591
|
+
(GOAL_SCHEMA_VERSION, _goal_timestamp()),
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
|
|
390
595
|
def downgrade_goal_schema(
|
|
391
596
|
conn: sqlite3.Connection,
|
|
392
597
|
target_version: int = 0,
|
|
@@ -868,6 +1073,7 @@ def migrate_goal_schema_with_backup(
|
|
|
868
1073
|
) -> tuple[Path, Path | None, int, bool]:
|
|
869
1074
|
"""Back up an existing Persistence DB, then migrate its goal schema."""
|
|
870
1075
|
db_path = Path(project_db_path).expanduser().resolve()
|
|
1076
|
+
_assert_not_global_goal_path(db_path)
|
|
871
1077
|
if not db_path.is_file():
|
|
872
1078
|
raise GoalSchemaNotInitializedError(
|
|
873
1079
|
f"Persistence database does not exist at {db_path}; "
|
|
@@ -884,6 +1090,8 @@ def migrate_goal_schema_with_backup(
|
|
|
884
1090
|
"SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'kv_store'"
|
|
885
1091
|
).fetchone()
|
|
886
1092
|
if has_kv_store is None:
|
|
1093
|
+
if _has_goal_schema_objects(source):
|
|
1094
|
+
raise GoalDatabaseInconsistentError(_GOAL_DATABASE_INCONSISTENT_MESSAGE)
|
|
887
1095
|
raise GoalSchemaNotInitializedError(
|
|
888
1096
|
"target is not a Pantheon Persistence database: kv_store is missing; "
|
|
889
1097
|
"ask the user to start the server once first"
|
|
@@ -1187,10 +1395,12 @@ if args.dry_run and not args.migrate_goals:
|
|
|
1187
1395
|
|
|
1188
1396
|
_project_db_path: Path | None = None
|
|
1189
1397
|
_project_db_explicit = args.project_db is not None
|
|
1398
|
+
_global_db_path = _resolve_global_db_path(args.global_db)
|
|
1190
1399
|
if args.migrate_goals:
|
|
1191
1400
|
_warn_if_symlinked_launcher()
|
|
1192
1401
|
try:
|
|
1193
1402
|
migration_db_path = _resolve_project_db_path(args.project_db)
|
|
1403
|
+
_assert_not_global_goal_path(migration_db_path)
|
|
1194
1404
|
if args.dry_run:
|
|
1195
1405
|
raise SystemExit(_print_goal_migration_dry_run(migration_db_path))
|
|
1196
1406
|
db_path, backup_path, version, already_current = (
|
|
@@ -1212,13 +1422,10 @@ if args.migrate_goals:
|
|
|
1212
1422
|
print("Goal schema migration applied.")
|
|
1213
1423
|
raise SystemExit(0)
|
|
1214
1424
|
|
|
1215
|
-
|
|
1216
|
-
Path(args.global_db) if args.global_db else pantheon_home() / "persistence"
|
|
1217
|
-
)
|
|
1218
|
-
_global_db = _init_db(_global_root / "global.db")
|
|
1425
|
+
_global_db = _init_db(_global_db_path)
|
|
1219
1426
|
|
|
1220
1427
|
_project_db_path = _resolve_project_db_path(args.project_db)
|
|
1221
|
-
_project_db_instance = _init_db(_project_db_path)
|
|
1428
|
+
_project_db_instance = _init_db(_project_db_path, project_db=True)
|
|
1222
1429
|
_project_db = _project_db_instance
|
|
1223
1430
|
|
|
1224
1431
|
|
|
@@ -477,7 +477,7 @@ function Sidebar(props) {
|
|
|
477
477
|
setProp(_el$, "width", "100%");
|
|
478
478
|
setProp(_el$, "padding", 1);
|
|
479
479
|
setProp(_el$2, "attributes", 1);
|
|
480
|
-
insert(_el$2, `Pantheon v1.6.0-beta.
|
|
480
|
+
insert(_el$2, `Pantheon v1.6.0-beta.18`);
|
|
481
481
|
insertNode(_el$3, createTextNode(`OpenCode V2 ยท plugin TUI ativo`));
|
|
482
482
|
insert(_el$, createComponent(Show, {
|
|
483
483
|
get when() {
|
|
@@ -623,7 +623,7 @@ function HomeStatus(props) {
|
|
|
623
623
|
const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
|
|
624
624
|
return (() => {
|
|
625
625
|
var _el$20 = createElement("text");
|
|
626
|
-
insert(_el$20, () => `Pantheon v1.6.0-beta.
|
|
626
|
+
insert(_el$20, () => `Pantheon v1.6.0-beta.18${preset().name ? ` โก ${preset().name}` : ""}`);
|
|
627
627
|
effect((_$p) => setProp(_el$20, "fg", muted(), _$p));
|
|
628
628
|
return _el$20;
|
|
629
629
|
})();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pantheon-tui",
|
|
3
|
-
"version": "1.6.0-beta.
|
|
3
|
+
"version": "1.6.0-beta.18",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pantheon-tui",
|
|
9
|
-
"version": "1.6.0-beta.
|
|
9
|
+
"version": "1.6.0-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.0-beta.
|
|
4
|
+
"version": "1.6.0-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": {
|