pantheon-opencode 2.1.6 → 2.2.0-beta.2

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.
Files changed (63) hide show
  1. package/AGENTS.global.md +2 -2
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +64 -0
  4. package/README.md +13 -9
  5. package/README.pt-BR.md +13 -9
  6. package/bin/pantheon-init.mjs +1 -1
  7. package/commands/pantheon-audit.md +4 -5
  8. package/commands/pantheon-model.md +1 -2
  9. package/package.json +8 -2
  10. package/plugin.json +1 -1
  11. package/prompts/dynamic/agora-generated.txt +2 -2
  12. package/prompts/dynamic/orchestrate-generated.txt +4 -4
  13. package/prompts/sketch.prompt.md +1 -1
  14. package/pyproject.toml +1 -1
  15. package/scripts/build-agents-md.mjs +73 -12
  16. package/scripts/build-plugin.mjs +3 -1
  17. package/scripts/hooks/format-multi-language.sh +30 -29
  18. package/scripts/install-mcp.mjs +55 -27
  19. package/scripts/prune.mjs +124 -2
  20. package/scripts/setup.mjs +1 -1
  21. package/scripts/themis_heuristic_scan.py +3 -5
  22. package/skills-lock.json +1 -1
  23. package/src/agents/aphrodite.md +1 -1
  24. package/src/agents/athena.md +6 -14
  25. package/src/agents/demeter.md +1 -1
  26. package/src/agents/hermes.md +3 -2
  27. package/src/agents/iris.md +4 -6
  28. package/src/agents/prometheus.md +3 -7
  29. package/src/agents/roster.json +567 -0
  30. package/src/agents/zeus.md +3 -0
  31. package/src/instructions/agent-return-format.instructions.md +1 -1
  32. package/src/instructions/zeus-anti-stall.instructions.md +11 -35
  33. package/src/instructions/zeus-council-synthesis.instructions.md +17 -49
  34. package/src/instructions/zeus-timeout-retry.instructions.md +12 -80
  35. package/src/mcp/mcp_codemap_module.py +6 -5
  36. package/src/mcp/pantheon-mcp-server.mjs +875 -0
  37. package/src/pantheon/agent-forge-tool.ts +316 -0
  38. package/src/pantheon/auto-permissions.ts +31 -1
  39. package/src/pantheon/codemap-tools.ts +525 -0
  40. package/src/pantheon/deepwork/plan-tracker.ts +63 -2
  41. package/src/pantheon/execute-after.ts +21 -0
  42. package/src/pantheon/hook-engine.ts +2 -1
  43. package/src/pantheon/native-memory-tools.ts +686 -0
  44. package/src/pantheon/presets.mjs +15 -0
  45. package/src/pantheon/step-ledger.ts +259 -0
  46. package/src/pantheon/swe-eval-harness.ts +211 -0
  47. package/src/pantheon/tools.ts +62 -7
  48. package/src/plugin/index.js +2091 -136
  49. package/src/plugin/index.ts +1 -14
  50. package/src/plugin.ts +167 -10
  51. package/src/plugins/tui/dist/tui.d.ts +66 -0
  52. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  53. package/src/plugins/tui/dist/tui.js +1259 -367
  54. package/src/plugins/tui/dist/tui.js.map +1 -1
  55. package/src/plugins/tui/package-lock.json +2 -2
  56. package/src/plugins/tui/package.json +1 -1
  57. package/src/plugins/tui/src/index.tsx +632 -71
  58. package/src/plugins/tui/src/pantheon-settings.tsx +78 -14
  59. package/src/plugins/tui/src/quota-state.ts +190 -0
  60. package/src/plugins/tui/src/tui-prefs.ts +169 -12
  61. package/src/routing.yml +3 -0
  62. package/src/skills/auto-continue/references/auto-continue-details.md +2 -31
  63. /package/scripts/{setup-v2-config.mjs → setup-config.mjs} +0 -0
@@ -90,6 +90,21 @@ export const CAPABILITY_TABLE = [
90
90
  { prefix: 'nemotron-3-super-free', maxEffort: 'high', stripEffort: false, vision: false },
91
91
  { prefix: 'nemotron-3-ultra-free', maxEffort: 'high', stripEffort: false, vision: false },
92
92
  { prefix: 'north-mini-code-free', maxEffort: 'high', stripEffort: false, vision: false },
93
+ // Multi-provider catalog extensions (Gemini, GPT-4o/4.1/5, Llama, Mistral, Grok, Ollama, OpenRouter)
94
+ { prefix: 'gemini-2.0', maxEffort: 'high', stripEffort: false, vision: true },
95
+ { prefix: 'gemini-2.5', maxEffort: 'high', stripEffort: false, vision: true },
96
+ { prefix: 'gemini-3-', maxEffort: 'high', stripEffort: false, vision: true },
97
+ { prefix: 'gemini-3.0', maxEffort: 'high', stripEffort: false, vision: true },
98
+ { prefix: 'gemini-3.1', maxEffort: 'high', stripEffort: false, vision: true },
99
+ { prefix: 'gpt-4o', maxEffort: null, stripEffort: true, vision: true },
100
+ { prefix: 'gpt-4.1', maxEffort: null, stripEffort: true, vision: true },
101
+ { prefix: 'gpt-5', maxEffort: 'high', stripEffort: false, vision: true },
102
+ { prefix: 'llama', maxEffort: null, stripEffort: true, vision: false },
103
+ { prefix: 'mistral', maxEffort: null, stripEffort: true, vision: false },
104
+ { prefix: 'codestral', maxEffort: null, stripEffort: true, vision: false },
105
+ { prefix: 'grok', maxEffort: 'high', stripEffort: false, vision: true },
106
+ { prefix: 'ollama/', maxEffort: null, stripEffort: true, vision: false },
107
+ { prefix: 'openrouter/', maxEffort: 'high', stripEffort: false, vision: true },
93
108
  ]
94
109
 
95
110
  /**
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Step-Ledger Execution Mode & Mechanical Completion Gate (`step-ledger.ts`).
3
+ *
4
+ * Implements the Pantheon 2.2.0 Step-Ledger mechanical verification architecture:
5
+ * 1. Workflows decompose into atomic steps identified by a `stepKey`.
6
+ * 2. Every file mutation (`edit`, `write`, `hashline_edit`) bumps `lastMutationAt`
7
+ * and invalidates prior verification for active steps.
8
+ * 3. A step may transition to `done` ONLY when a verification command exited `0`
9
+ * AFTER the latest file mutation (`lastVerifiedAt >= lastMutationAt`),
10
+ * minting a cryptographic Execution Proof Receipt (`execution-receipt.ts`).
11
+ * 4. Failed verifications feed directly into `ThemisReflexController`
12
+ * (`themis-reflex.ts`) for bounded self-healing.
13
+ *
14
+ * @module pantheon/step-ledger
15
+ */
16
+
17
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs'
18
+ import { join, resolve, sep } from 'node:path'
19
+ import { createExecutionReceipt } from './execution-receipt.ts'
20
+ import { ThemisReflexController } from './themis-reflex.ts'
21
+ import { resolveToolCwd } from './tool-context.ts'
22
+ import type { PantheonToolDef, PantheonToolResult } from './tools.ts'
23
+
24
+ export type StepState = 'pending' | 'in_progress' | 'done' | 'blocked'
25
+
26
+ export interface StepLedgerEntry {
27
+ stepKey: string
28
+ objective: string
29
+ agent: string
30
+ state: StepState
31
+ mutatedFiles: string[]
32
+ lastMutationAt: number | null
33
+ lastVerifiedAt: number | null
34
+ verificationCommand?: string
35
+ verificationExitCode?: number
36
+ receiptId?: string
37
+ updatedAt: string
38
+ }
39
+
40
+ export interface StepLedgerStore {
41
+ version: 1
42
+ steps: Record<string, StepLedgerEntry>
43
+ }
44
+
45
+ const SAFE_STEP_KEY_RE = /^[a-zA-Z0-9._:-]{1,128}$/
46
+ const stepReflex = new ThemisReflexController({ maxRetries: 2 })
47
+
48
+ function assertSafeStepKey(stepKey: unknown): string {
49
+ if (typeof stepKey !== 'string' || !SAFE_STEP_KEY_RE.test(stepKey) || stepKey.includes('..')) {
50
+ throw new Error('stepKey must be a safe alphanumeric identifier (1..128 chars)')
51
+ }
52
+ return stepKey
53
+ }
54
+
55
+ function resolveLedgerPath(workspaceDir: string): string {
56
+ const dir = join(workspaceDir, '.pantheon', 'ledger')
57
+ mkdirSync(dir, { recursive: true })
58
+ const canonicalDir = realpathSync(dir)
59
+ const filePath = resolve(canonicalDir, 'step-ledger.json')
60
+ const prefix = canonicalDir.endsWith(sep) ? canonicalDir : `${canonicalDir}${sep}`
61
+ if (!filePath.startsWith(prefix)) {
62
+ throw new Error('Path traversal denied for step-ledger.json')
63
+ }
64
+ return filePath
65
+ }
66
+
67
+ export function readStepLedger(workspaceDir: string): StepLedgerStore {
68
+ const filePath = resolveLedgerPath(workspaceDir)
69
+ if (!existsSync(filePath)) {
70
+ return { version: 1, steps: {} }
71
+ }
72
+ try {
73
+ const parsed = JSON.parse(readFileSync(filePath, 'utf8')) as Partial<StepLedgerStore>
74
+ if (parsed && typeof parsed.steps === 'object' && parsed.steps !== null) {
75
+ return { version: 1, steps: parsed.steps as Record<string, StepLedgerEntry> }
76
+ }
77
+ } catch {
78
+ /* recover empty store on corrupt file */
79
+ }
80
+ return { version: 1, steps: {} }
81
+ }
82
+
83
+ export function writeStepLedger(workspaceDir: string, store: StepLedgerStore): void {
84
+ const filePath = resolveLedgerPath(workspaceDir)
85
+ writeFileSync(filePath, `${JSON.stringify(store, null, 2)}\n`, 'utf8')
86
+ }
87
+
88
+ /**
89
+ * Hard mechanical invariant: a step can transition to `done` if and only if
90
+ * a verification command exited 0 at or after the last file mutation.
91
+ */
92
+ export function canTransitionStepToDone(step: StepLedgerEntry): {
93
+ allowed: boolean
94
+ reason?: string
95
+ } {
96
+ if (step.verificationExitCode !== 0 || step.lastVerifiedAt === null) {
97
+ return {
98
+ allowed: false,
99
+ reason: `Step "${step.stepKey}" cannot transition to done: no passing verification command (exitCode === 0) has been recorded.`,
100
+ }
101
+ }
102
+ if (step.lastMutationAt !== null && step.lastVerifiedAt < step.lastMutationAt) {
103
+ return {
104
+ allowed: false,
105
+ reason: `Step "${step.stepKey}" cannot transition to done: files were mutated after the last verification run. Re-run the verification slice first.`,
106
+ }
107
+ }
108
+ return { allowed: true }
109
+ }
110
+
111
+ function jsonResult(payload: unknown): PantheonToolResult {
112
+ return { output: JSON.stringify(payload) }
113
+ }
114
+
115
+ export function createStepLedgerTool(fallbackDir?: string): PantheonToolDef {
116
+ return {
117
+ name: 'pantheon_step_ledger',
118
+ description:
119
+ 'Manage atomic Step-Ledger execution contracts with hard verification gates: a step can transition to done ONLY after a verification command exits 0 following the last file mutation.',
120
+ input: {
121
+ type: 'object',
122
+ additionalProperties: false,
123
+ required: ['action'],
124
+ properties: {
125
+ action: {
126
+ type: 'string',
127
+ enum: ['init_step', 'record_mutation', 'record_verification', 'complete_step', 'status'],
128
+ description: 'Ledger operation to perform',
129
+ },
130
+ stepKey: { type: 'string', description: 'Unique atomic step identifier' },
131
+ objective: { type: 'string', description: 'Bounded step objective' },
132
+ agent: { type: 'string', description: 'Assigned specialist agent' },
133
+ files: {
134
+ type: 'array',
135
+ items: { type: 'string' },
136
+ description: 'Mutated file paths for record_mutation',
137
+ },
138
+ command: { type: 'string', description: 'Executed verification slice command' },
139
+ exitCode: { type: 'number', description: 'Exit code of the verification command' },
140
+ durationMs: { type: 'number', description: 'Duration of verification command in ms' },
141
+ },
142
+ },
143
+ output: {},
144
+ execute: async (input, context) => {
145
+ try {
146
+ const action = typeof input.action === 'string' ? input.action : 'status'
147
+ const cwd = resolveToolCwd(context, fallbackDir)
148
+ const store = readStepLedger(cwd)
149
+ const now = Date.now()
150
+ const nowIso = new Date(now).toISOString()
151
+
152
+ if (action === 'status') {
153
+ if (typeof input.stepKey === 'string' && input.stepKey.trim()) {
154
+ const key = assertSafeStepKey(input.stepKey.trim())
155
+ const step = store.steps[key]
156
+ if (!step) return jsonResult({ ok: false, error: 'step_not_found', stepKey: key })
157
+ return jsonResult({ ok: true, step, gate: canTransitionStepToDone(step) })
158
+ }
159
+ return jsonResult({ ok: true, steps: Object.values(store.steps) })
160
+ }
161
+
162
+ const key = assertSafeStepKey(input.stepKey)
163
+
164
+ if (action === 'init_step') {
165
+ const objective = typeof input.objective === 'string' ? input.objective.trim() : ''
166
+ if (!objective) return jsonResult({ ok: false, error: 'objective is required' })
167
+ const agent =
168
+ typeof input.agent === 'string' && input.agent.trim()
169
+ ? input.agent.trim()
170
+ : 'specialist'
171
+ const entry: StepLedgerEntry = {
172
+ stepKey: key,
173
+ objective,
174
+ agent,
175
+ state: 'in_progress',
176
+ mutatedFiles: [],
177
+ lastMutationAt: null,
178
+ lastVerifiedAt: null,
179
+ updatedAt: nowIso,
180
+ }
181
+ store.steps[key] = entry
182
+ writeStepLedger(cwd, store)
183
+ return jsonResult({ ok: true, step: entry })
184
+ }
185
+
186
+ const step = store.steps[key]
187
+ if (!step) {
188
+ return jsonResult({ ok: false, error: `Step "${key}" is not initialized` })
189
+ }
190
+
191
+ if (action === 'record_mutation') {
192
+ const files = Array.isArray(input.files) ? input.files.map(String) : []
193
+ const merged = Array.from(new Set([...step.mutatedFiles, ...files]))
194
+ step.mutatedFiles = merged
195
+ step.lastMutationAt = now
196
+ if (step.state === 'done') step.state = 'in_progress'
197
+ step.updatedAt = nowIso
198
+ writeStepLedger(cwd, store)
199
+ return jsonResult({ ok: true, step })
200
+ }
201
+
202
+ if (action === 'record_verification') {
203
+ const command = typeof input.command === 'string' ? input.command.trim() : ''
204
+ const exitCode = typeof input.exitCode === 'number' ? input.exitCode : 1
205
+ const durationMs = typeof input.durationMs === 'number' ? input.durationMs : 0
206
+ if (!command) return jsonResult({ ok: false, error: 'command is required' })
207
+
208
+ step.verificationCommand = command
209
+ step.verificationExitCode = exitCode
210
+ step.lastVerifiedAt = now
211
+ step.updatedAt = nowIso
212
+
213
+ if (exitCode === 0) {
214
+ stepReflex.evaluate(key, step.agent, [])
215
+ const receipt = createExecutionReceipt({
216
+ taskID: key,
217
+ agent: step.agent,
218
+ files: step.mutatedFiles.map((f) => ({ path: f, content: `${key}:${f}:${now}` })),
219
+ testSlice: { command, exitCode: 0, durationMs },
220
+ })
221
+ step.receiptId = receipt.receiptId
222
+ writeStepLedger(cwd, store)
223
+ return jsonResult({ ok: true, verified: true, receiptId: receipt.receiptId, step })
224
+ }
225
+
226
+ const reflex = stepReflex.evaluate(key, step.agent, [
227
+ {
228
+ file: step.mutatedFiles[0] ?? key,
229
+ error: `Verification command "${command}" failed with exit code ${exitCode}`,
230
+ },
231
+ ])
232
+ if (reflex.action === 'escalate') {
233
+ step.state = 'blocked'
234
+ }
235
+ writeStepLedger(cwd, store)
236
+ return jsonResult({ ok: false, verified: false, reflex, step })
237
+ }
238
+
239
+ if (action === 'complete_step') {
240
+ const gate = canTransitionStepToDone(step)
241
+ if (!gate.allowed) {
242
+ return jsonResult({ ok: false, error: gate.reason, step })
243
+ }
244
+ step.state = 'done'
245
+ step.updatedAt = nowIso
246
+ writeStepLedger(cwd, store)
247
+ return jsonResult({ ok: true, status: 'done', receiptId: step.receiptId, step })
248
+ }
249
+
250
+ return jsonResult({ ok: false, error: `Unsupported action: ${action}` })
251
+ } catch (err) {
252
+ return jsonResult({
253
+ ok: false,
254
+ error: err instanceof Error ? err.message : String(err),
255
+ })
256
+ }
257
+ },
258
+ }
259
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Multi-File Engineering Evaluation Harness (`swe-eval-harness.ts`).
3
+ *
4
+ * Replaces synthetic string-match benchmarks ("ZEUS_OK") with reproducible,
5
+ * multi-file software engineering tasks evaluated against hidden test suites
6
+ * in isolated workspaces (RED before patch -> GREEN after patch), integrated
7
+ * with `createExecutionReceipt` and `StepLedger`.
8
+ *
9
+ * @module pantheon/swe-eval-harness
10
+ */
11
+
12
+ import { execFile } from 'node:child_process'
13
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
14
+ import { tmpdir } from 'node:os'
15
+ import { dirname, join } from 'node:path'
16
+ import { promisify } from 'node:util'
17
+ import { createExecutionReceipt } from './execution-receipt.ts'
18
+
19
+ const execFileAsync = promisify(execFile)
20
+
21
+ export interface SweEvalTask {
22
+ readonly id: string
23
+ readonly title: string
24
+ readonly description: string
25
+ readonly initialFiles: Readonly<Record<string, string>>
26
+ readonly hiddenTestFile: {
27
+ readonly path: string
28
+ readonly content: string
29
+ }
30
+ readonly referencePatch: Readonly<Record<string, string>>
31
+ }
32
+
33
+ export interface SweEvalTaskResult {
34
+ readonly taskId: string
35
+ readonly failedBeforePatch: boolean
36
+ readonly passedAfterPatch: boolean
37
+ readonly durationMs: number
38
+ readonly receiptId: string
39
+ }
40
+
41
+ export const CANONICAL_SWE_EVAL_TASKS: readonly SweEvalTask[] = [
42
+ {
43
+ id: 'swe-01-token-expiry-boundary',
44
+ title: 'Fix off-by-one boundary & clock skew in multi-file token validator',
45
+ description:
46
+ 'Tokens expiring at the exact current second or with negative TTL must be rejected across token.mjs and validator.mjs.',
47
+ initialFiles: {
48
+ 'src/token.mjs': [
49
+ 'export function parseToken(raw) {',
50
+ ' const parts = String(raw || "").split(":");',
51
+ ' if (parts.length !== 2) return null;',
52
+ ' return { subject: parts[0], expiresAt: Number(parts[1]) };',
53
+ '}',
54
+ ].join('\n'),
55
+ 'src/validator.mjs': [
56
+ "import { parseToken } from './token.mjs';",
57
+ 'export function isTokenValid(raw, nowMs) {',
58
+ ' const parsed = parseToken(raw);',
59
+ ' if (!parsed || !parsed.subject) return false;',
60
+ ' // BUG: allows expired tokens when expiresAt === nowMs or NaN',
61
+ ' return parsed.expiresAt >= nowMs || Number.isNaN(parsed.expiresAt);',
62
+ '}',
63
+ ].join('\n'),
64
+ },
65
+ hiddenTestFile: {
66
+ path: 'tests/validator.test.mjs',
67
+ content: [
68
+ "import assert from 'node:assert/strict';",
69
+ "import test from 'node:test';",
70
+ "import { isTokenValid } from '../src/validator.mjs';",
71
+ "test('rejects expired at boundary and malformed timestamps', () => {",
72
+ " assert.equal(isTokenValid('user1:1000', 1000), false);",
73
+ " assert.equal(isTokenValid('user1:abc', 1000), false);",
74
+ " assert.equal(isTokenValid('user1:1001', 1000), true);",
75
+ '});',
76
+ ].join('\n'),
77
+ },
78
+ referencePatch: {
79
+ 'src/validator.mjs': [
80
+ "import { parseToken } from './token.mjs';",
81
+ 'export function isTokenValid(raw, nowMs) {',
82
+ ' const parsed = parseToken(raw);',
83
+ ' if (!parsed || !parsed.subject) return false;',
84
+ ' if (!Number.isFinite(parsed.expiresAt) || !Number.isFinite(nowMs)) return false;',
85
+ ' return parsed.expiresAt > nowMs;',
86
+ '}',
87
+ ].join('\n'),
88
+ },
89
+ },
90
+ {
91
+ id: 'swe-02-invoice-cents-rounding',
92
+ title: 'Eliminate floating-point drift in multi-item invoice aggregation',
93
+ description:
94
+ 'Invoice subtotal and tax computation across line-item.mjs and invoice.mjs must compute in integer cents.',
95
+ initialFiles: {
96
+ 'src/line-item.mjs': [
97
+ 'export function lineTotalUsd(priceUsd, qty) {',
98
+ ' return priceUsd * qty;',
99
+ '}',
100
+ ].join('\n'),
101
+ 'src/invoice.mjs': [
102
+ "import { lineTotalUsd } from './line-item.mjs';",
103
+ 'export function computeInvoiceTotal(items) {',
104
+ ' // BUG: raw float addition yields 0.30000000000000004',
105
+ ' return items.reduce((sum, it) => sum + lineTotalUsd(it.price, it.qty), 0);',
106
+ '}',
107
+ ].join('\n'),
108
+ },
109
+ hiddenTestFile: {
110
+ path: 'tests/invoice.test.mjs',
111
+ content: [
112
+ "import assert from 'node:assert/strict';",
113
+ "import test from 'node:test';",
114
+ "import { computeInvoiceTotal } from '../src/invoice.mjs';",
115
+ "test('computes exact two-decimal USD total without IEEE-754 drift', () => {",
116
+ ' const total = computeInvoiceTotal([{ price: 0.1, qty: 1 }, { price: 0.2, qty: 1 }]);',
117
+ ' assert.equal(total, 0.3);',
118
+ '});',
119
+ ].join('\n'),
120
+ },
121
+ referencePatch: {
122
+ 'src/line-item.mjs': [
123
+ 'export function lineTotalCents(priceUsd, qty) {',
124
+ ' return Math.round(priceUsd * 100) * qty;',
125
+ '}',
126
+ ].join('\n'),
127
+ 'src/invoice.mjs': [
128
+ "import { lineTotalCents } from './line-item.mjs';",
129
+ 'export function computeInvoiceTotal(items) {',
130
+ ' const cents = items.reduce((sum, it) => sum + lineTotalCents(it.price, it.qty), 0);',
131
+ ' return Number((cents / 100).toFixed(2));',
132
+ '}',
133
+ ].join('\n'),
134
+ },
135
+ },
136
+ ]
137
+
138
+ async function runHiddenTest(workspaceDir: string, testRelPath: string): Promise<number> {
139
+ const childEnv = { ...process.env }
140
+ delete childEnv.NODE_TEST_CONTEXT
141
+ try {
142
+ await execFileAsync(process.execPath, ['--test', join(workspaceDir, testRelPath)], {
143
+ cwd: workspaceDir,
144
+ env: childEnv,
145
+ timeout: 15_000,
146
+ })
147
+ return 0
148
+ } catch (err) {
149
+ const code = (err as { code?: unknown })?.code
150
+ return typeof code === 'number' ? code : 1
151
+ }
152
+ }
153
+
154
+ function writeWorkspaceFiles(workspaceDir: string, files: Readonly<Record<string, string>>): void {
155
+ for (const [relPath, content] of Object.entries(files)) {
156
+ const absPath = join(workspaceDir, relPath)
157
+ mkdirSync(dirname(absPath), { recursive: true })
158
+ writeFileSync(absPath, content, 'utf8')
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Execute a multi-file SWE evaluation task in an isolated workspace:
164
+ * 1. Verifies the initial buggy codebase FAILS the hidden test suite (RED).
165
+ * 2. Applies the candidate patch.
166
+ * 3. Verifies the patched codebase PASSES the hidden test suite (GREEN).
167
+ * 4. Mints a cryptographic Execution Proof Receipt.
168
+ */
169
+ export async function evaluateSweTask(
170
+ task: SweEvalTask,
171
+ candidatePatch: Readonly<Record<string, string>> = task.referencePatch,
172
+ ): Promise<SweEvalTaskResult> {
173
+ const workDir = mkdtempSync(join(tmpdir(), `pantheon-swe-eval-${task.id}-`))
174
+ const start = Date.now()
175
+ try {
176
+ writeWorkspaceFiles(workDir, task.initialFiles)
177
+ writeWorkspaceFiles(workDir, { [task.hiddenTestFile.path]: task.hiddenTestFile.content })
178
+
179
+ const preExit = await runHiddenTest(workDir, task.hiddenTestFile.path)
180
+ const failedBeforePatch = preExit !== 0
181
+
182
+ writeWorkspaceFiles(workDir, candidatePatch)
183
+ const postExit = await runHiddenTest(workDir, task.hiddenTestFile.path)
184
+ const passedAfterPatch = postExit === 0
185
+ const durationMs = Date.now() - start
186
+
187
+ const receipt = createExecutionReceipt({
188
+ taskID: task.id,
189
+ agent: 'swe-eval-harness',
190
+ files: Object.keys(candidatePatch).map((relPath) => ({
191
+ path: relPath,
192
+ content: readFileSync(join(workDir, relPath), 'utf8'),
193
+ })),
194
+ testSlice: {
195
+ command: `node --test ${task.hiddenTestFile.path}`,
196
+ exitCode: postExit,
197
+ durationMs,
198
+ },
199
+ })
200
+
201
+ return {
202
+ taskId: task.id,
203
+ failedBeforePatch,
204
+ passedAfterPatch,
205
+ durationMs,
206
+ receiptId: receipt.receiptId,
207
+ }
208
+ } finally {
209
+ rmSync(workDir, { recursive: true, force: true })
210
+ }
211
+ }
@@ -48,6 +48,9 @@
48
48
 
49
49
  import { exec } from 'node:child_process'
50
50
  import { promisify } from 'node:util'
51
+ import { createAgentForgeTool } from './agent-forge-tool.ts'
52
+ import { isDangerousCommand, NON_EDIT_AGENTS, NON_SHELL_AGENTS } from './auto-permissions.ts'
53
+ import { createCodemapTools } from './codemap-tools.ts'
51
54
  import { createCostCommand } from './cost-command.ts'
52
55
  import type { ShadowSink } from './decision-shadow.ts'
53
56
  import { createDeepworkTool } from './deepwork/deepwork-tool.ts'
@@ -55,8 +58,10 @@ import { createHashlineEditTool, type HashlineToolResult } from './hashline/tool
55
58
  import { createV2JevDecisionDefinition, type V2JevDecisionRuntime } from './jev-decision-tool.ts'
56
59
  import { createV2LocalDecisionDefinition } from './local-decision-tool.ts'
57
60
  import { createModelCommand } from './model-command.ts'
61
+ import { createNativeMemoryAndPersistenceTools } from './native-memory-tools.ts'
58
62
  import { createV2VisionTool, type V2VisionRuntime } from './native-vision.ts'
59
63
  import { createV2SkillSearchDefinition } from './skill-search-tool.ts'
64
+ import { createStepLedgerTool } from './step-ledger.ts'
60
65
  import { resolveToolCwd, type ToolContextLike } from './tool-context.ts'
61
66
 
62
67
  // ─── Contract types ─────────────────────────────────────────────────────
@@ -270,11 +275,18 @@ async function executeHashlineEdit(
270
275
  input: Record<string, unknown>,
271
276
  context: unknown,
272
277
  ): Promise<V2ToolResult> {
278
+ const ctx = toolContext(context)
279
+ const callerAgent = (ctx.agent ?? '').toLowerCase().trim()
280
+ if (callerAgent && callerAgent !== 'zeus' && NON_EDIT_AGENTS.has(callerAgent)) {
281
+ return {
282
+ output: `hashline_edit denied: agent '${callerAgent}' is not permitted to edit files directly.`,
283
+ }
284
+ }
273
285
  const coerced = coerceHashlineEditArgs(input)
274
286
  if (!coerced.ok) return { output: coerced.error }
275
287
  let result: HashlineToolResult
276
288
  try {
277
- result = await hashlineEdit.execute(coerced.args, toolContext(context))
289
+ result = await hashlineEdit.execute(coerced.args, ctx)
278
290
  } catch (err: unknown) {
279
291
  // The V1 tool does not throw for user errors; this is defence in depth so
280
292
  // an unexpected throw surfaces as text instead of an absent tool result.
@@ -479,13 +491,33 @@ const TODOWRITE_INPUT = {
479
491
  } as const
480
492
 
481
493
  let latestSessionTodos: unknown[] = []
494
+ const sessionTodosBySession = new Map<string, unknown[]>()
495
+
496
+ function resolveTodoSessionKey(context: unknown): string | undefined {
497
+ if (!context || typeof context !== 'object') return undefined
498
+ const ctx = context as Record<string, unknown>
499
+ if (typeof ctx.sessionID === 'string' && ctx.sessionID.trim() !== '') {
500
+ return ctx.sessionID.trim()
501
+ }
502
+ const sessionObj = ctx.session as Record<string, unknown> | undefined
503
+ if (typeof sessionObj?.id === 'string' && sessionObj.id.trim() !== '') {
504
+ return sessionObj.id.trim()
505
+ }
506
+ return undefined
507
+ }
482
508
 
483
- export function getLatestSessionTodos(): unknown[] {
509
+ export function getLatestSessionTodos(sessionID?: string): unknown[] {
510
+ if (sessionID && sessionTodosBySession.has(sessionID)) {
511
+ return sessionTodosBySession.get(sessionID) ?? []
512
+ }
484
513
  return latestSessionTodos
485
514
  }
486
515
 
487
- export function setLatestSessionTodos(todos: unknown[]): void {
516
+ export function setLatestSessionTodos(todos: unknown[], sessionID?: string): void {
488
517
  latestSessionTodos = todos
518
+ if (sessionID) {
519
+ sessionTodosBySession.set(sessionID, todos)
520
+ }
489
521
  }
490
522
 
491
523
  /** A V2 pass-through `todowrite`: the host stores the tool part in the
@@ -498,10 +530,11 @@ const todowriteTool: V2ToolDef = {
498
530
  'newest list; mark each item in_progress/completed as soon as its state changes.',
499
531
  input: TODOWRITE_INPUT,
500
532
  output: {},
501
- execute: async (input) => {
533
+ execute: async (input, context) => {
502
534
  const rawTodos = (input as Record<string, unknown>).todos
503
535
  const todos: unknown[] = Array.isArray(rawTodos) ? (rawTodos as unknown[]) : []
504
- latestSessionTodos = todos
536
+ const sessionKey = resolveTodoSessionKey(context)
537
+ setLatestSessionTodos(todos, sessionKey)
505
538
  return { ok: true, todos, output: JSON.stringify({ todos }) }
506
539
  },
507
540
  }
@@ -524,9 +557,10 @@ const todoreadTool: V2ToolDef = {
524
557
  'Read the active session task checklist. Returns the newest list of tasks written via todowrite.',
525
558
  input: TODOREAD_INPUT,
526
559
  output: {},
527
- execute: async (input) => {
560
+ execute: async (input, context) => {
528
561
  const statusFilter = (input as Record<string, unknown>)?.status
529
- let todos = latestSessionTodos
562
+ const sessionKey = resolveTodoSessionKey(context)
563
+ let todos = getLatestSessionTodos(sessionKey)
530
564
  if (typeof statusFilter === 'string' && statusFilter.trim() !== '') {
531
565
  todos = todos.filter(
532
566
  (t) =>
@@ -544,6 +578,7 @@ const todoreadTool: V2ToolDef = {
544
578
  }
545
579
 
546
580
  const execAsync = promisify(exec)
581
+ const SHELL_TIMEOUT_MS = 120_000
547
582
 
548
583
  const SHELL_INPUT = {
549
584
  type: 'object',
@@ -568,16 +603,28 @@ export function createShellTool(fallbackDir?: string): V2ToolDef {
568
603
  input: SHELL_INPUT,
569
604
  output: {},
570
605
  execute: async (input, context) => {
606
+ const ctx = toolContext(context)
607
+ const callerAgent = (ctx.agent ?? '').toLowerCase().trim()
608
+ if (callerAgent && NON_SHELL_AGENTS.has(callerAgent)) {
609
+ const msg = `shell denied: agent '${callerAgent}' is not permitted to execute shell commands`
610
+ return { output: msg, ok: false, error: msg }
611
+ }
571
612
  const raw = (input as Record<string, unknown>) ?? {}
572
613
  const command = String(raw.command ?? raw.cmd ?? '')
573
614
  if (!command.trim()) {
574
615
  return { output: '', ok: false, error: 'Command cannot be empty' }
575
616
  }
617
+ if (isDangerousCommand(command)) {
618
+ const msg =
619
+ 'shell denied: destructive or privilege-escalation command blocked by safety guard'
620
+ return { output: msg, ok: false, error: msg }
621
+ }
576
622
  const cwd = resolveToolCwd(context, fallbackDir)
577
623
  try {
578
624
  const { stdout, stderr } = await execAsync(command, {
579
625
  cwd,
580
626
  maxBuffer: 10 * 1024 * 1024,
627
+ timeout: SHELL_TIMEOUT_MS,
581
628
  shell: '/bin/bash',
582
629
  })
583
630
  const output = [stdout, stderr].filter(Boolean).join('\n')
@@ -651,7 +698,15 @@ export function createV2ToolDefinitions(
651
698
  definitions.push(createShellTool(hostLocationDirectory))
652
699
  definitions.push(createV2SkillSearchDefinition(hostLocationDirectory))
653
700
  definitions.push(createDeepworkTool(hostLocationDirectory))
701
+ definitions.push(createStepLedgerTool(hostLocationDirectory))
702
+ definitions.push(createAgentForgeTool(hostLocationDirectory))
703
+ definitions.push(...createNativeMemoryAndPersistenceTools(hostLocationDirectory))
704
+ definitions.push(...createCodemapTools(hostLocationDirectory))
654
705
  if (visionRuntime) definitions.push(createV2VisionTool(visionRuntime))
655
706
  if (jevRuntime) definitions.push(createV2JevDecisionDefinition(jevRuntime))
656
707
  return definitions
657
708
  }
709
+
710
+ export type PantheonToolResult = V2ToolResult
711
+ export type PantheonToolDef = V2ToolDef
712
+ export const createToolDefinitions = createV2ToolDefinitions