pantheon-opencode 1.5.0-beta.14 → 1.5.0-beta.15
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 +38 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +2 -5
- package/src/agents/zeus.md +4 -26
- package/src/pantheon/background-job-board.ts +4 -4
- package/src/pantheon/delegate-manager.ts +95 -10
- package/src/pantheon/delegation-classifier.ts +3 -4
- package/src/pantheon/delegation-finalize.ts +69 -7
- package/src/pantheon/delegation.ts +16 -4
- package/src/pantheon/presets.d.mts +0 -20
- package/src/pantheon/presets.mjs +0 -64
- package/src/pantheon/toon-codec.ts +1 -1
- package/src/plugin-v2.ts +4 -6
- package/src/plugin.ts +6 -6
- package/src/plugins/pantheon-hooks.ts +1 -1
- package/src/plugins/tui/dist/tui.d.ts +43 -36
- package/src/plugins/tui/dist/tui.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui.js +102 -38
- package/src/plugins/tui/package-lock.json +2 -2
- package/src/plugins/tui/package.json +1 -1
- package/src/plugins/tui/src/index.tsx +168 -67
- package/src/routing.yml +0 -16
- package/scripts/hash_verify.py +0 -192
- package/scripts/test-context-compression.sh +0 -169
- package/src/pantheon/auto-wake.ts +0 -85
- package/src/pantheon/chat-reminders.ts +0 -9
- package/src/pantheon/comment-checker.ts +0 -48
- package/src/pantheon/compaction-assert.ts +0 -160
- package/src/pantheon/compaction-handoff.ts +0 -304
- package/src/pantheon/cost-tracker.ts +0 -108
- package/src/pantheon/dispatch-guard.ts +0 -109
- package/src/pantheon/permission-eval.ts +0 -284
- package/src/pantheon/preemptive-compact.ts +0 -76
- package/src/pantheon/provider-capabilities.ts +0 -221
- package/src/pantheon/provider-stream-tracker.ts +0 -182
- package/src/pantheon/retry-policy.ts +0 -212
- package/src/pantheon/token-opt.ts +0 -689
- package/src/pantheon/v2-events.ts +0 -148
- package/src/pantheon/v2-hooks.ts +0 -287
- package/src/pantheon/v2-tool-definitions.ts +0 -331
- package/src/pantheon/zeus-delegate-with-retry.ts +0 -406
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# Test: Context Compression Pipeline
|
|
3
|
-
# Simulates Themis APPROVED → triggers compress_context handoff
|
|
4
|
-
#
|
|
5
|
-
# Usage: bash scripts/test-context-compression.sh
|
|
6
|
-
#
|
|
7
|
-
# This script validates the prerequisites for the Level 2 context compression
|
|
8
|
-
# pipeline and creates mock artifacts for end-to-end testing.
|
|
9
|
-
|
|
10
|
-
set -euo pipefail
|
|
11
|
-
|
|
12
|
-
echo "=== Context Compression Test ==="
|
|
13
|
-
echo ""
|
|
14
|
-
|
|
15
|
-
# Step 1: Verify prerequisites
|
|
16
|
-
echo "[1/4] Checking prerequisites..."
|
|
17
|
-
errors=0
|
|
18
|
-
|
|
19
|
-
test -f skills/context-compression/SKILL.md || { echo " ❌ SKILL.md not found"; errors=$((errors + 1)); }
|
|
20
|
-
test -f agents/mnemosyne.agent.md || { echo " ❌ mnemosyne.agent.md not found"; errors=$((errors + 1)); }
|
|
21
|
-
test -f agents/zeus.agent.md || { echo " ❌ zeus.agent.md not found"; errors=$((errors + 1)); }
|
|
22
|
-
test -f routing.yml || { echo " ❌ routing.yml not found"; errors=$((errors + 1)); }
|
|
23
|
-
test -f skills/artifact-management/SKILL.md || { echo " ❌ artifact-protocol.instructions.md not found"; errors=$((errors + 1)); }
|
|
24
|
-
test -f .pantheon/memory-bank/01-active-context.md || { echo " ❌ active-context.md not found"; errors=$((errors + 1)); }
|
|
25
|
-
test -d .pantheon/memory-bank/.tmp || mkdir -p .pantheon/memory-bank/.tmp
|
|
26
|
-
|
|
27
|
-
if [ -f scripts/scrub-secrets.py ]; then
|
|
28
|
-
echo " ✅ scrub-secrets.py found (217 lines, $(grep -c 'def ' scripts/scrub-secrets.py || echo 0) functions)"
|
|
29
|
-
else
|
|
30
|
-
echo " ⚠️ scrub-secrets.py not found (will skip scrubbing)"
|
|
31
|
-
fi
|
|
32
|
-
|
|
33
|
-
# Verify compress_context handoff in routing.yml
|
|
34
|
-
if grep -q "compress_context" routing.yml; then
|
|
35
|
-
HANDOFF_LINE=$(grep -n "compress_context" routing.yml | head -1 | cut -d: -f1)
|
|
36
|
-
echo " ✅ compress_context handoff found in routing.yml at line $HANDOFF_LINE"
|
|
37
|
-
else
|
|
38
|
-
echo " ❌ compress_context handoff missing from routing.yml"
|
|
39
|
-
errors=$((errors + 1))
|
|
40
|
-
fi
|
|
41
|
-
|
|
42
|
-
# Verify ZZ artifact mention in artifact-protocol
|
|
43
|
-
if grep -q "ZZ-phase" skills/artifact-management/SKILL.md; then
|
|
44
|
-
echo " ✅ ZZ artifact format documented in artifact-protocol.instructions.md"
|
|
45
|
-
else
|
|
46
|
-
echo " ❌ ZZ artifact format missing from artifact-protocol.instructions.md"
|
|
47
|
-
errors=$((errors + 1))
|
|
48
|
-
fi
|
|
49
|
-
|
|
50
|
-
# Verify context-compression trigger was added to zeus.agent.md
|
|
51
|
-
if grep -q "Context Compression Trigger" agents/zeus.agent.md; then
|
|
52
|
-
echo " ✅ Context Compression Trigger section present in zeus.agent.md"
|
|
53
|
-
else
|
|
54
|
-
echo " ⚠️ Context Compression Trigger section not yet in zeus.agent.md"
|
|
55
|
-
fi
|
|
56
|
-
|
|
57
|
-
if [ "$errors" -gt 0 ]; then
|
|
58
|
-
echo " ❌ $errors prerequisite(s) missing — aborting"
|
|
59
|
-
exit 1
|
|
60
|
-
fi
|
|
61
|
-
echo " ✅ All prerequisites met"
|
|
62
|
-
echo ""
|
|
63
|
-
|
|
64
|
-
# Step 2: Create a mock IMPL artifact for testing
|
|
65
|
-
echo "[2/4] Creating mock IMPL artifact..."
|
|
66
|
-
|
|
67
|
-
cat > .pantheon/memory-bank/.tmp/IMPL-test-phase-hermes.md << 'ARTIFACT'
|
|
68
|
-
# IMPL-test-phase-hermes
|
|
69
|
-
**Date:** 2026-06-26 **Status:** Awaiting Compression Test
|
|
70
|
-
|
|
71
|
-
## What Was Implemented
|
|
72
|
-
- test/file.py — mock implementation for compression test
|
|
73
|
-
- test/schema.py — mock schema migration for priority scoring test
|
|
74
|
-
|
|
75
|
-
## Tests
|
|
76
|
-
- ✅ 5 tests passing / Coverage: 87%
|
|
77
|
-
|
|
78
|
-
## Notes for Themis
|
|
79
|
-
This is a test artifact to validate the compression pipeline end-to-end.
|
|
80
|
-
ARTIFACT
|
|
81
|
-
|
|
82
|
-
cat > .pantheon/memory-bank/.tmp/IMPL-test-phase-demeter.md << 'ARTIFACT'
|
|
83
|
-
# IMPL-test-phase-demeter
|
|
84
|
-
**Date:** 2026-06-26 **Status:** Awaiting Compression Test
|
|
85
|
-
|
|
86
|
-
## What Was Implemented
|
|
87
|
-
- backend/migrations/0013_add_refresh_tokens.py — new refresh_tokens table
|
|
88
|
-
- backend/models/token.py — Token model with FK to users
|
|
89
|
-
|
|
90
|
-
## Tests
|
|
91
|
-
- ✅ Migration tested: upgrade + downgrade both verified
|
|
92
|
-
|
|
93
|
-
## Notes for Themis
|
|
94
|
-
New table: refresh_tokens with (user_id, token_hash, expires_at, revoked_at)
|
|
95
|
-
ARTIFACT
|
|
96
|
-
|
|
97
|
-
echo " ✅ 2 mock artifacts created (hermes + demeter)"
|
|
98
|
-
echo ""
|
|
99
|
-
|
|
100
|
-
# Step 3: Create mock subtask_summary for compression
|
|
101
|
-
echo "[3/4] Creating mock subtask summaries..."
|
|
102
|
-
|
|
103
|
-
cat > .pantheon/memory-bank/.tmp/subtask-hermes.json << 'JSON'
|
|
104
|
-
{
|
|
105
|
-
"files_changed": ["test/file.py", "test/schema.py"],
|
|
106
|
-
"summary": "Added JWT auth endpoint with refresh token rotation",
|
|
107
|
-
"tests": "✅ All passing",
|
|
108
|
-
"coverage": "87%",
|
|
109
|
-
"status": "complete",
|
|
110
|
-
"blockers": null
|
|
111
|
-
}
|
|
112
|
-
JSON
|
|
113
|
-
|
|
114
|
-
cat > .pantheon/memory-bank/.tmp/subtask-demeter.json << 'JSON'
|
|
115
|
-
{
|
|
116
|
-
"files_changed": ["backend/migrations/0013_add_refresh_tokens.py", "backend/models/token.py"],
|
|
117
|
-
"summary": "Created refresh_tokens table with FK to users, hashed token, expires_at, revoked_at",
|
|
118
|
-
"tests": "✅ Migration upgrade + downgrade verified",
|
|
119
|
-
"coverage": "100%",
|
|
120
|
-
"status": "complete",
|
|
121
|
-
"blockers": null
|
|
122
|
-
}
|
|
123
|
-
JSON
|
|
124
|
-
|
|
125
|
-
echo " ✅ 2 mock subtask summaries created"
|
|
126
|
-
echo ""
|
|
127
|
-
|
|
128
|
-
# Step 4: Verify .tmp structure is writable and correct
|
|
129
|
-
echo "[4/4] Verifying .tmp structure..."
|
|
130
|
-
ls -la .pantheon/memory-bank/.tmp/
|
|
131
|
-
echo ""
|
|
132
|
-
echo " ✅ .tmp structure looks correct"
|
|
133
|
-
echo ""
|
|
134
|
-
|
|
135
|
-
# Step 5: Validate scrub-secrets.py works
|
|
136
|
-
echo "[5/4] Testing scrub-secrets.py (bonus)..."
|
|
137
|
-
if [ -f scripts/scrub-secrets.py ]; then
|
|
138
|
-
# Test with a simple secret. The token is assembled at runtime so the
|
|
139
|
-
# shipped script never contains a literal `Bearer <token>` sequence (the
|
|
140
|
-
# redaction gate flags any such literal as a credential).
|
|
141
|
-
SCRUB_FIXTURE_TOKEN="my-test-token-12345"
|
|
142
|
-
SECRET_TEST=$(echo "Bearer ${SCRUB_FIXTURE_TOKEN}" | python3 scripts/scrub-secrets.py --stdin 2>/dev/null)
|
|
143
|
-
if echo "$SECRET_TEST" | grep -q "REDACTED"; then
|
|
144
|
-
echo " ✅ scrub-secrets.py: secret detection working"
|
|
145
|
-
else
|
|
146
|
-
echo " ⚠️ scrub-secrets.py: did not detect test secret (may need different pattern)"
|
|
147
|
-
fi
|
|
148
|
-
fi
|
|
149
|
-
echo ""
|
|
150
|
-
|
|
151
|
-
echo "=== Test Complete ==="
|
|
152
|
-
echo ""
|
|
153
|
-
echo "Mock artifacts ready for compression pipeline test."
|
|
154
|
-
echo ""
|
|
155
|
-
echo "Next manual step: Trigger compress_context handoff:"
|
|
156
|
-
echo " @mnemosyne Run compression pipeline with test artifacts"
|
|
157
|
-
echo ""
|
|
158
|
-
echo "Expected output:"
|
|
159
|
-
echo " - .pantheon/memory-bank/.tmp/ZZ-test-context.md"
|
|
160
|
-
echo " - Updated 01-active-context.md with compressed entries"
|
|
161
|
-
echo " - Updated 02-progress-log.md with archived mock artifact"
|
|
162
|
-
echo ""
|
|
163
|
-
echo "Scoring verification (expected):"
|
|
164
|
-
echo " - subtask-hermes.json: JWT + endpoint + token keywords → HIGH (score ~0.71)"
|
|
165
|
-
echo " - subtask-demeter.json: migration + new table + FK keywords → CRITICAL (score ~0.83)"
|
|
166
|
-
echo ""
|
|
167
|
-
echo "To clean up test artifacts:"
|
|
168
|
-
echo " rm .pantheon/memory-bank/.tmp/IMPL-test-phase-*.md"
|
|
169
|
-
echo " rm .pantheon/memory-bank/.tmp/subtask-*.json"
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-Wake Consumer — scans signal files from the BackgroundJobBoard
|
|
3
|
-
* and returns completed job signals for Zeus to process.
|
|
4
|
-
*
|
|
5
|
-
* Signal files are created by the board on every terminal state transition
|
|
6
|
-
* (completed/error/cancelled). This module consumes them atomically by
|
|
7
|
-
* reading the `.signal.json` content, then renaming to `.consumed.json`,
|
|
8
|
-
* preventing race conditions where the same signal is processed twice.
|
|
9
|
-
*
|
|
10
|
-
* The rename is the commit point: if Zeus crashes between the read and the
|
|
11
|
-
* rename, the `.signal.json` file remains and will be re-processed on restart.
|
|
12
|
-
* This gives **at-least-once** delivery, which is acceptable because the board's
|
|
13
|
-
* `markReconciled()` is idempotent.
|
|
14
|
-
*
|
|
15
|
-
* @module auto-wake
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { existsSync } from 'node:fs'
|
|
19
|
-
import { readdir, readFile, rename } from 'node:fs/promises'
|
|
20
|
-
import { join } from 'node:path'
|
|
21
|
-
|
|
22
|
-
/** Signal structure written by BackgroundJobBoard.writeSignal(). */
|
|
23
|
-
export interface WakeSignal {
|
|
24
|
-
taskID: string
|
|
25
|
-
alias: string
|
|
26
|
-
agent: string
|
|
27
|
-
state: string
|
|
28
|
-
summary: string | null
|
|
29
|
-
timestamp: number
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Default signal directory (matches BoardOptions.signalDir default in plugin.ts). */
|
|
33
|
-
const DEFAULT_SIGNAL_DIR = '.pantheon/deepwork/board-signals'
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Scan the signal directory for `*.signal.json` files, atomically consume
|
|
37
|
-
* each by renaming to `*.consumed.json`, and return the parsed signals.
|
|
38
|
-
*
|
|
39
|
-
* Safe to call multiple times — already-consumed files (`.consumed.json`)
|
|
40
|
-
* are ignored, and the atomic rename prevents double-processing.
|
|
41
|
-
*
|
|
42
|
-
* The flow per signal file:
|
|
43
|
-
* 1. Read the `.signal.json` content
|
|
44
|
-
* 2. Rename `.signal.json` → `.consumed.json` (atomic: OS-level rename)
|
|
45
|
-
* 3. If rename succeeds, push the signal into the result
|
|
46
|
-
* 4. If rename fails (another process consumed it first), skip
|
|
47
|
-
*
|
|
48
|
-
* @param signalDir Directory to scan (default: `.pantheon/deepwork/board-signals`)
|
|
49
|
-
* @returns List of wake signals from newly consumed files
|
|
50
|
-
*/
|
|
51
|
-
export async function consumeWakeSignals(signalDir?: string): Promise<WakeSignal[]> {
|
|
52
|
-
const dir = signalDir ?? DEFAULT_SIGNAL_DIR
|
|
53
|
-
|
|
54
|
-
// If the signal directory doesn't exist, there are no signals
|
|
55
|
-
if (!existsSync(dir)) {
|
|
56
|
-
return []
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const entries = await readdir(dir, { withFileTypes: true })
|
|
60
|
-
const signals: WakeSignal[] = []
|
|
61
|
-
|
|
62
|
-
for (const entry of entries) {
|
|
63
|
-
if (!entry.isFile()) continue
|
|
64
|
-
if (!entry.name.endsWith('.signal.json')) continue
|
|
65
|
-
|
|
66
|
-
const signalPath = join(dir, entry.name)
|
|
67
|
-
const consumedName = entry.name.replace(/\.signal\.json$/, '.consumed.json')
|
|
68
|
-
const consumedPath = join(dir, consumedName)
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
// Step 1: Read the file content
|
|
72
|
-
const content = await readFile(signalPath, 'utf-8')
|
|
73
|
-
const data = JSON.parse(content) as WakeSignal
|
|
74
|
-
|
|
75
|
-
// Step 2: Atomically rename — this is the commit point.
|
|
76
|
-
// If this fails, the .signal.json remains and we'll retry next call.
|
|
77
|
-
await rename(signalPath, consumedPath)
|
|
78
|
-
|
|
79
|
-
// Step 3: Only add to results after successful rename
|
|
80
|
-
signals.push(data)
|
|
81
|
-
} catch {}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return signals
|
|
85
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retired transcript-notification module.
|
|
3
|
-
*
|
|
4
|
-
* Delegation lifecycle state must not be queued for delivery into user
|
|
5
|
-
* messages. Visibility is provided by the board/list/read tools and TUI
|
|
6
|
-
* toasts; this intentionally exports no delivery API.
|
|
7
|
-
*
|
|
8
|
-
* @module chat-reminders
|
|
9
|
-
*/
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comment Checker — detects trivial/auto-generated comments that make code
|
|
3
|
-
* look machine-produced rather than human-written.
|
|
4
|
-
*
|
|
5
|
-
* Used by @themis (Layer 1: Surface review) to flag comments that add no
|
|
6
|
-
* information value and signal AI-generated code.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/** Regex patterns matching trivial, uninformative comments. */
|
|
10
|
-
export const TRIVIAL_PATTERNS: readonly RegExp[] = [
|
|
11
|
-
/#\s*increment\s+\w+/i,
|
|
12
|
-
/#\s*decrement\s+\w+/i,
|
|
13
|
-
/#\s*set\s+\w+/i,
|
|
14
|
-
/#\s*loop\s+over/i,
|
|
15
|
-
/#\s*(initialize|init)\s+\w+/i,
|
|
16
|
-
/#\s*(return|yield)\s+\w+/i,
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
export interface CommentCheckResult {
|
|
20
|
-
/** Number of trivial comments found (0 = clean). */
|
|
21
|
-
score: number
|
|
22
|
-
/** Human-readable descriptions of each flagged comment. */
|
|
23
|
-
flags: string[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Scan source code for trivial comments that add no information value.
|
|
28
|
-
*
|
|
29
|
-
* Returns a score (count of trivial comments) and a list of flags describing
|
|
30
|
-
* each match. A score of 0 means no trivial comments were detected.
|
|
31
|
-
*/
|
|
32
|
-
export function checkCommentDensity(source: string): CommentCheckResult {
|
|
33
|
-
const flags: string[] = []
|
|
34
|
-
const lines = source.split('\n')
|
|
35
|
-
|
|
36
|
-
for (let i = 0; i < lines.length; i++) {
|
|
37
|
-
const line = lines[i] as string
|
|
38
|
-
for (const pattern of TRIVIAL_PATTERNS) {
|
|
39
|
-
if (pattern.test(line)) {
|
|
40
|
-
const trimmed = line.trim()
|
|
41
|
-
flags.push(`Line ${i + 1}: trivial comment — "${trimmed}"`)
|
|
42
|
-
break // one flag per line, even if multiple patterns match
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { score: flags.length, flags }
|
|
48
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compaction Re-Assert (release-134 Phase 4) — detect fresh state after
|
|
3
|
-
* compaction without writing to the chat transcript.
|
|
4
|
-
*
|
|
5
|
-
* WHY: after a session is compacted, the system state may have changed since
|
|
6
|
-
* the summary was built (new background delegations launched, results
|
|
7
|
-
* delivered, goals updated). The compacted session's context is frozen at
|
|
8
|
-
* summary time — the model would operate on stale state.
|
|
9
|
-
*
|
|
10
|
-
* HOW: the compaction lifecycle keeps the board and goal stores authoritative;
|
|
11
|
-
* the `experimental.session.compacting` hook builds the context that is
|
|
12
|
-
* consumed by the compaction itself. Chat is never used as a delivery channel.
|
|
13
|
-
*
|
|
14
|
-
* Deliberately NOT `session.promptAsync({noReply:true})`: the sprint 4+7
|
|
15
|
-
* spike refuted noReply as a push mechanism on this opencode build (nothing
|
|
16
|
-
* is delivered to the parent).
|
|
17
|
-
*
|
|
18
|
-
* FAIL-OPEN: every source (board list and goals list) is wrapped —
|
|
19
|
-
* a failure logs a warn via the silence-by-default logger and the hook never
|
|
20
|
-
* throws. A session with NO fresh state (nothing running/unread/goals) is a
|
|
21
|
-
* SILENT skip (no warn). The block is capped at
|
|
22
|
-
* REASSERT_MAX_LINES item lines (1 header) so it stays compact.
|
|
23
|
-
*
|
|
24
|
-
* Pure TypeScript — zero runtime deps beyond the board/goal types.
|
|
25
|
-
*
|
|
26
|
-
* @module compaction-assert
|
|
27
|
-
*/
|
|
28
|
-
import type { BackgroundJobBoard } from './background-job-board.ts'
|
|
29
|
-
import type { CompactionGoalSource } from './delegation-compaction.ts'
|
|
30
|
-
import { createPantheonLogger } from './logger.ts'
|
|
31
|
-
|
|
32
|
-
// Silence-by-default TUI policy (pantheon-hooks L42-58): console echo is
|
|
33
|
-
// opt-in via PANTHEON_HOOKS_LOG=1. `deps.logger` injection stays for tests.
|
|
34
|
-
const log = createPantheonLogger({ module: 'pantheon-compaction' })
|
|
35
|
-
|
|
36
|
-
// ─── Constants ─────────────────────────────────────────────────────────
|
|
37
|
-
|
|
38
|
-
/** Max fresh-state item lines (running + unread + goals) in the block. */
|
|
39
|
-
export const REASSERT_MAX_LINES = 10
|
|
40
|
-
|
|
41
|
-
/** Header line — tells the model the summary may be stale. */
|
|
42
|
-
export const REASSERT_HEADER = 'State re-assertion after compaction — the summary may be stale:'
|
|
43
|
-
|
|
44
|
-
// ─── Types ─────────────────────────────────────────────────────────────
|
|
45
|
-
|
|
46
|
-
/** Dependencies threaded to reassertAfterCompaction (wired from plugin.ts). */
|
|
47
|
-
export interface CompactionAssertDeps {
|
|
48
|
-
/** The session whose compaction context is being prepared. */
|
|
49
|
-
sessionID: string
|
|
50
|
-
/** Board query surface — `list` is all the re-assertion needs. */
|
|
51
|
-
board: Pick<BackgroundJobBoard, 'list'>
|
|
52
|
-
/** Goal source for the goals block (optional — same gating as Phase 2). */
|
|
53
|
-
goals?: CompactionGoalSource
|
|
54
|
-
/** Injectable warn logger (testable). Defaults to silence-by-default. */
|
|
55
|
-
logger?: { warn: (message: string) => void }
|
|
56
|
-
/** Non-chat delivery sink (for example a pending `output.context` block). */
|
|
57
|
-
deliverContext?: (context: string[]) => void | Promise<void>
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ─── Formatting ────────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
/** One-line terminal status label, mirroring formatForPrompt. */
|
|
63
|
-
function terminalLabel(state: string): string {
|
|
64
|
-
switch (state) {
|
|
65
|
-
case 'completed':
|
|
66
|
-
return 'OK'
|
|
67
|
-
case 'error':
|
|
68
|
-
return 'ERR'
|
|
69
|
-
case 'cancelled':
|
|
70
|
-
return 'CAN'
|
|
71
|
-
default:
|
|
72
|
-
return state.toUpperCase()
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Collapse whitespace and truncate a description/objective. */
|
|
77
|
-
function truncate(text: string, max = 80): string {
|
|
78
|
-
const flat = text.trim().replace(/\s+/g, ' ')
|
|
79
|
-
return flat.length <= max ? flat : `${flat.slice(0, max)}…`
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ─── Build ─────────────────────────────────────────────────────────────
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Build the compact fresh-state lines: running delegations first (active work
|
|
86
|
-
* is the freshest signal), then unread terminal delegations, then active
|
|
87
|
-
* goals (only while the line budget allows). Returns undefined when there is
|
|
88
|
-
* nothing to assert (silent skip) or a source failed (warn + skip).
|
|
89
|
-
*/
|
|
90
|
-
async function buildStateLines(
|
|
91
|
-
deps: CompactionAssertDeps,
|
|
92
|
-
warn: (message: string) => void,
|
|
93
|
-
): Promise<string[] | undefined> {
|
|
94
|
-
const lines: string[] = []
|
|
95
|
-
try {
|
|
96
|
-
const jobs = deps.board.list(deps.sessionID)
|
|
97
|
-
const running = jobs
|
|
98
|
-
.filter((j) => j.state === 'running')
|
|
99
|
-
.sort((a, b) => a.launchedAt - b.launchedAt)
|
|
100
|
-
const unread = jobs
|
|
101
|
-
.filter((j) => j.terminalUnreconciled)
|
|
102
|
-
.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
103
|
-
|
|
104
|
-
for (const job of running) {
|
|
105
|
-
if (lines.length >= REASSERT_MAX_LINES) break
|
|
106
|
-
lines.push(` running [${job.alias}] ${job.agent} — ${truncate(job.description)}`)
|
|
107
|
-
}
|
|
108
|
-
for (const job of unread) {
|
|
109
|
-
if (lines.length >= REASSERT_MAX_LINES) break
|
|
110
|
-
lines.push(
|
|
111
|
-
` unread [${job.alias}] ${job.agent} — ${truncate(job.description)} — ${terminalLabel(job.state)}`,
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const source = deps.goals
|
|
116
|
-
if (lines.length < REASSERT_MAX_LINES && source !== undefined && source.enabled) {
|
|
117
|
-
const goals = await source.list(deps.sessionID)
|
|
118
|
-
for (const goal of goals.filter((g) => g.status !== 'done')) {
|
|
119
|
-
if (lines.length >= REASSERT_MAX_LINES) break
|
|
120
|
-
lines.push(` goal [${goal.id}] ${truncate(goal.objective)} — ${goal.status}`)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} catch (err: unknown) {
|
|
124
|
-
const reason = err instanceof Error ? err.message : String(err)
|
|
125
|
-
warn(`compaction re-assert failed for session ${deps.sessionID}: ${reason}`)
|
|
126
|
-
return undefined
|
|
127
|
-
}
|
|
128
|
-
return lines.length === 0 ? undefined : lines
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Re-assert fresh state for a compacted session and return the context block
|
|
133
|
-
* to the non-chat caller. The caller can hand this array to OpenCode's
|
|
134
|
-
* `output.context` or persist it through the board; constructing it here and
|
|
135
|
-
* throwing it away would make the hook a no-op.
|
|
136
|
-
*
|
|
137
|
-
* Returns the fresh-state context when found, or undefined when there was
|
|
138
|
-
* nothing to assert (silent skip) or a source failed (warned). NEVER throws —
|
|
139
|
-
* the event hook must never break the session.
|
|
140
|
-
*/
|
|
141
|
-
export async function reassertAfterCompaction(
|
|
142
|
-
deps: CompactionAssertDeps,
|
|
143
|
-
): Promise<string[] | undefined> {
|
|
144
|
-
// Silence-by-default logger: file-only warn, console echo opt-in via
|
|
145
|
-
// PANTHEON_HOOKS_LOG=1 (TUI pollution policy, pantheon-hooks L42-58).
|
|
146
|
-
const warn = deps.logger?.warn ?? ((message: string) => log.warn(message))
|
|
147
|
-
try {
|
|
148
|
-
const lines = await buildStateLines(deps, warn)
|
|
149
|
-
if (lines === undefined) return undefined
|
|
150
|
-
// This is a context return value, not a chat message. The caller owns the
|
|
151
|
-
// supported delivery path (output.context or persisted board state).
|
|
152
|
-
const context = [REASSERT_HEADER, ...lines]
|
|
153
|
-
await deps.deliverContext?.(context)
|
|
154
|
-
return context
|
|
155
|
-
} catch (err: unknown) {
|
|
156
|
-
const reason = err instanceof Error ? err.message : String(err)
|
|
157
|
-
warn(`compaction re-assert failed for session ${deps.sessionID}: ${reason}`)
|
|
158
|
-
return undefined
|
|
159
|
-
}
|
|
160
|
-
}
|