pantheon-opencode 1.6.0-beta.9 → 1.6.1
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/AGENTS.global.md +118 -0
- package/AGENTS.md +18 -168
- package/CHANGELOG.md +144 -365
- package/README.md +124 -607
- package/README.pt-BR.md +120 -345
- package/bin/pantheon-init.mjs +504 -141
- package/commands/pantheon-deepwork.md +14 -3
- package/commands/pantheon-vision.md +61 -12
- package/package.json +22 -13
- package/plugin.json +1 -1
- package/pyproject.toml +6 -2
- package/scripts/_pantheon_paths.py +24 -0
- package/scripts/build-agents-md.mjs +368 -69
- package/scripts/changelog-merge.mjs +161 -0
- package/scripts/check-plugin-v2-coverage.mjs +11 -8
- package/scripts/docs-check-changelog.mjs +204 -0
- package/scripts/docs-link-check.mjs +314 -0
- package/scripts/docs-media.mjs +157 -0
- package/scripts/doctor.mjs +850 -45
- package/scripts/install/agents-md.mjs +2 -2
- package/scripts/install/backup.mjs +648 -0
- package/scripts/install/cli-ui.mjs +303 -72
- package/scripts/install/component-selection.mjs +61 -0
- package/scripts/install/config-migration.mjs +583 -27
- package/scripts/install/exit-codes.mjs +26 -0
- package/scripts/install/file-inventory.mjs +555 -0
- package/scripts/install/health-check.mjs +31 -25
- package/scripts/install/interactive.mjs +99 -383
- package/scripts/install/interrupt.mjs +78 -0
- package/scripts/install/migrate.mjs +49 -25
- package/scripts/install/model-picker.mjs +218 -250
- package/scripts/install/opencode-state.mjs +91 -0
- package/scripts/install/opencode-version.mjs +83 -21
- package/scripts/install/opencode.mjs +1675 -187
- package/scripts/install/plan-artifact.mjs +517 -0
- package/scripts/install/plan.mjs +475 -0
- package/scripts/install/plugin.mjs +214 -27
- package/scripts/install/prompt-result.mjs +2 -0
- package/scripts/install/run-record.mjs +115 -0
- package/scripts/install/shared.mjs +256 -99
- package/scripts/install/state.mjs +63 -8
- package/scripts/install/strings.mjs +93 -8
- package/scripts/install/v2-capabilities.mjs +205 -0
- package/scripts/install/venv.mjs +90 -47
- package/scripts/install/verify.mjs +128 -0
- package/scripts/install/vision-prompt.mjs +173 -0
- package/scripts/install-mcp.mjs +2 -2
- package/scripts/manifest-inventory.mjs +49 -3
- package/scripts/mcp_persistence.py +1535 -1050
- package/scripts/memory_mcp.py +12 -843
- package/scripts/node-engine-policy.mjs +85 -0
- package/scripts/package-evidence.mjs +10 -2
- package/scripts/postinstall.mjs +26 -26
- package/scripts/probe-pantheon-cost.mjs +118 -19
- package/scripts/prune.mjs +9 -3
- package/scripts/reconcile.mjs +325 -0
- package/scripts/release-gates.mjs +687 -0
- package/scripts/restore.mjs +222 -0
- package/scripts/run-node-tests.mjs +24 -8
- package/scripts/sync-artifacts.mjs +19 -7
- package/scripts/sync-tui.mjs +5 -1
- package/scripts/test-opencode-v2-sandbox.sh +36 -123
- package/scripts/uninstall.mjs +369 -34
- package/scripts/update.mjs +164 -0
- package/scripts/validate-node-engine-policy.mjs +13 -0
- package/scripts/version-check.mjs +34 -1
- package/scripts/versioning.mjs +23 -3
- package/scripts/vision-status.mjs +682 -0
- package/skills-lock.json +8 -8
- package/src/agents/aphrodite.md +13 -10
- package/src/agents/apollo.md +4 -5
- package/src/agents/athena.md +74 -46
- package/src/agents/demeter.md +10 -7
- package/src/agents/gaia.md +0 -1
- package/src/agents/hephaestus.md +4 -3
- package/src/agents/hermes.md +10 -9
- package/src/agents/iris.md +6 -1
- package/src/agents/mnemosyne.md +10 -4
- package/src/agents/nyx.md +4 -4
- package/src/agents/prometheus.md +12 -11
- package/src/agents/talos.md +6 -0
- package/src/agents/zeus.md +84 -56
- package/src/instructions/agent-return-format.instructions.md +12 -41
- package/src/instructions/memory-protocol.instructions.md +5 -11
- package/src/instructions/test-economy.instructions.md +12 -0
- package/src/instructions/yagni.instructions.md +6 -15
- package/src/instructions/zeus-anti-stall.instructions.md +6 -6
- package/src/instructions/zeus-communication-rules.instructions.md +6 -6
- package/src/instructions/zeus-council-synthesis.instructions.md +11 -12
- package/src/instructions/zeus-memory-operations.instructions.md +13 -7
- package/src/instructions/zeus-timeout-retry.instructions.md +36 -10
- package/src/mcp/_pantheon_paths.py +24 -0
- package/src/mcp/mcp_codemap_module.py +86 -18
- package/src/mcp/mcp_persistence.py +1535 -1050
- package/src/mcp/memory_mcp.py +444 -94
- package/src/mcp/pantheon_vision.py +285 -41
- package/src/mcp/requirements-mcp.txt +6 -1
- package/src/mcp/requirements-vision.txt +1 -1
- package/src/pantheon/context-pruner.ts +541 -0
- package/src/pantheon/cost-command.ts +901 -60
- package/src/pantheon/delegation-enforce.ts +160 -23
- package/src/pantheon/goal-loop.ts +11 -8
- package/src/pantheon/guard-path.ts +162 -0
- package/src/pantheon/memory-context.ts +1017 -0
- package/src/pantheon/model-agents.ts +19 -0
- package/src/pantheon/model-command.ts +218 -56
- package/src/pantheon/model-pricing.ts +536 -0
- package/src/pantheon/presets.mjs +2 -0
- package/src/pantheon/task-result-guard.ts +50 -14
- package/src/pantheon/v2-bounded-read.ts +654 -0
- package/src/pantheon/v2-bridge.ts +27 -0
- package/src/pantheon/v2-delegation-enforce.ts +133 -6
- package/src/pantheon/v2-execute-after.ts +135 -24
- package/src/pantheon/v2-model-overrides.ts +275 -0
- package/src/pantheon/v2-shell-hooks.ts +260 -0
- package/src/pantheon/v2-tools.ts +89 -35
- package/src/pantheon/v2-unsupported.mjs +34 -7
- package/src/pantheon/v2-vision.ts +622 -0
- package/src/pantheon/vision-local.ts +531 -0
- package/src/pantheon/vision.ts +1166 -116
- package/src/plugin-v2.ts +1039 -171
- package/src/plugin.ts +37 -13
- package/src/plugins/tui/dist/tui-v2.d.ts +1029 -2
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +3742 -85
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +15 -15
- package/src/plugins/tui/package.json +7 -5
- package/src/plugins/tui/src/index-v2.tsx +4314 -50
- package/src/plugins/tui/tsconfig.typecheck.json +5 -0
- package/src/routing.yml +50 -5
- package/src/skills/agent-coordination/SKILL.md +7 -2
- package/src/skills/artifact-management/SKILL.md +5 -1
- package/src/skills/auto-continue/SKILL.md +14 -6
- package/src/skills/codemap/SKILL.md +1 -1
- package/src/skills/memory-bank/SKILL.md +21 -13
- package/src/skills/session-goal/SKILL.md +12 -22
- package/src/skills/spec-driven-development/SKILL.md +3 -1
- package/src/skills/worktrees/SKILL.md +30 -11
- package/scripts/probe-context-rehydrate.mjs +0 -263
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
// ─── Types ─────────────────────────────────────────────────────────────
|
|
36
36
|
|
|
37
|
+
import type { GuardPathResolution } from './guard-path.ts'
|
|
37
38
|
import { isAgentAllowed, type PermissionTaskConfig } from './permission-globs.ts'
|
|
38
39
|
|
|
39
40
|
/** Why a session is read-only. */
|
|
@@ -203,43 +204,179 @@ export const DEFAULT_BLOCKED_TOOLS: ReadonlySet<string> = new Set([
|
|
|
203
204
|
export const ZEUS_READ_DENY_PATTERNS: ReadonlyArray<RegExp> = [/^src\//, /^tests?\//, /^scripts?\//]
|
|
204
205
|
|
|
205
206
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
207
|
+
* Normalize a tool-supplied path before it meets the deny patterns.
|
|
208
|
+
*
|
|
209
|
+
* The patterns are anchored on `/`, so two spellings of the same source path
|
|
210
|
+
* used to pass: Windows separators (`src\\file.ts`) and a redundant dot prefix
|
|
211
|
+
* (`./src/file.ts`). Normalizing both is a TIGHTENING — it can only turn a
|
|
212
|
+
* previously allowed spelling into a denied one, never the reverse.
|
|
213
|
+
*/
|
|
214
|
+
function normalizeGuardPath(value: string): string {
|
|
215
|
+
let normalized = value.replace(/\\/g, '/')
|
|
216
|
+
while (normalized.startsWith('./')) normalized = normalized.slice(2)
|
|
217
|
+
return normalized
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** One path-bearing argument, and whether it names a target or a query. */
|
|
221
|
+
interface GuardCandidate {
|
|
222
|
+
value: string
|
|
223
|
+
/** `filePath`/`path` name the read target; `pattern` may be a grep query. */
|
|
224
|
+
target: boolean
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Path-bearing arguments of a read/glob/grep call.
|
|
229
|
+
*
|
|
230
|
+
* EVERY target is returned, not just the first: a `grep` call carries its
|
|
231
|
+
* directory in `path` and query in `pattern`. `pattern` is a TARGET for `glob`
|
|
232
|
+
* (it is the path pattern) but a QUERY for `grep` (it is the text to search
|
|
233
|
+
* for). Zeus' `grep.include` is rejected separately because the host's glob
|
|
234
|
+
* base and basename-matching semantics are not established.
|
|
235
|
+
*/
|
|
236
|
+
function guardPathCandidates(tool: string, args: unknown): GuardCandidate[] {
|
|
237
|
+
if (args === null || typeof args !== 'object') return []
|
|
238
|
+
const record = args as Record<string, unknown>
|
|
239
|
+
const candidates: GuardCandidate[] = []
|
|
240
|
+
for (const key of ['filePath', 'path', 'pattern']) {
|
|
241
|
+
const value = record[key]
|
|
242
|
+
if (typeof value !== 'string' || value.trim() === '') continue
|
|
243
|
+
candidates.push({ value, target: key !== 'pattern' || tool === 'glob' })
|
|
244
|
+
}
|
|
245
|
+
return candidates
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Whether a normalized path points AT or INTO a denied code root.
|
|
250
|
+
*
|
|
251
|
+
* A TARGET spelled without a trailing slash (`path: 'src'`) is a directory
|
|
252
|
+
* reference, so the slash form is tested too — `^src\\/` alone would miss it.
|
|
253
|
+
* A query (`pattern`) is only denied when it is path-shaped, so grepping for
|
|
254
|
+
* the literal word `src` stays allowed while `src/**` does not. Absolute paths
|
|
255
|
+
* are matched on every segment-boundary suffix, so `/abs/src/x` is the same
|
|
256
|
+
* source tree as `src/x`.
|
|
257
|
+
*/
|
|
258
|
+
function isDeniedReadPath(candidate: string, target: boolean): boolean {
|
|
259
|
+
const matches = (value: string): boolean =>
|
|
260
|
+
ZEUS_READ_DENY_PATTERNS.some((pattern) => pattern.test(value))
|
|
261
|
+
const test = (value: string): boolean => {
|
|
262
|
+
if (matches(value)) return true
|
|
263
|
+
return target && !value.endsWith('/') && matches(`${value}/`)
|
|
264
|
+
}
|
|
265
|
+
if (test(candidate)) return true
|
|
266
|
+
if (!candidate.startsWith('/')) return false
|
|
267
|
+
const segments = candidate.split('/').filter((segment) => segment !== '')
|
|
268
|
+
for (let index = 0; index < segments.length; index++) {
|
|
269
|
+
if (test(segments.slice(index).join('/'))) return true
|
|
270
|
+
}
|
|
271
|
+
return false
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Resolve a raw tool path for the guard. Supplied by the call site, never
|
|
276
|
+
* invoked by the pure predicate unless one is passed.
|
|
277
|
+
*/
|
|
278
|
+
export type GuardPathResolver = (rawPath: string) => GuardPathResolution
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Glob expansion is controlled by the host and its symlink-follow behavior is
|
|
282
|
+
* not part of this guard's contract. Only exact, non-glob paths are safe to
|
|
283
|
+
* preflight; fail closed on glob metacharacters rather than infer the host's
|
|
284
|
+
* expansion semantics.
|
|
209
285
|
*/
|
|
210
|
-
|
|
286
|
+
function hasGlobMeta(value: string): boolean {
|
|
287
|
+
return ['*', '?', '[', ']', '{', '}', '(', ')'].some((meta) => value.includes(meta))
|
|
288
|
+
}
|
|
211
289
|
|
|
212
290
|
/**
|
|
213
291
|
* Zeus read guard. When the active agent is Zeus, deny read/glob/grep calls
|
|
214
292
|
* that target source code, tests, or scripts — Zeus must delegate those to
|
|
215
|
-
* @apollo.
|
|
293
|
+
* @apollo. Project-root `.pantheon/` and `memories/` paths and ordinary docs
|
|
294
|
+
* remain readable because they are outside the denied code roots; they never
|
|
295
|
+
* exempt a resolved `src/`, `tests/`, or `scripts/` target. Glob patterns with
|
|
296
|
+
* wildcard metacharacters are rejected conservatively because host expansion
|
|
297
|
+
* and symlink-follow behavior cannot be safely preflighted here.
|
|
298
|
+
*
|
|
299
|
+
* Every path-bearing argument is checked, and path spellings are normalized
|
|
300
|
+
* first. Both are tightenings: a call Zeus could make before with a
|
|
301
|
+
* `path: 'src'` directory plus a harmless `pattern`, or with `./src/x` /
|
|
302
|
+
* `src\\x`, is now denied. When a resolver is supplied every target is resolved
|
|
303
|
+
* before any code-root decision, so the original spelling or an allowed suffix
|
|
304
|
+
* cannot hide a resolved code target. Zeus grep additionally requires resolver
|
|
305
|
+
* evidence that its target is a regular file inside the canonical project root.
|
|
306
|
+
*
|
|
307
|
+
* Symlink resolution is NOT part of this predicate: it is pure and synchronous
|
|
308
|
+
* and shared with V1, so a call site that wants it passes `resolvePath` (see
|
|
309
|
+
* `createGuardPathResolver`). When a resolver is supplied it runs for every
|
|
310
|
+
* TARGET path — a `grep` query is text, not a path — and a resolution FAILURE
|
|
311
|
+
* denies: a read guard fails closed. Non-Zeus behavior remains unchanged; Zeus
|
|
312
|
+
* grep without resolver evidence fails closed.
|
|
313
|
+
*
|
|
314
|
+
* Zeus grep requires an explicit, non-empty `path` that resolves to an existing
|
|
315
|
+
* regular file inside the project root. Directories (including `.` and `..`),
|
|
316
|
+
* paths outside the project, missing paths, and resolution failures are denied
|
|
317
|
+
* to prevent recursive or unbounded reads. Every `include` filter is rejected
|
|
318
|
+
* because host glob semantics are not established. Exact allowed docs files
|
|
319
|
+
* with ordinary text queries remain searchable.
|
|
216
320
|
*
|
|
217
321
|
* Non-Zeus sessions are never affected.
|
|
218
322
|
*
|
|
219
323
|
* @throws {Error} when Zeus attempts a denied read
|
|
220
324
|
*/
|
|
221
|
-
export function zeusReadGuard(
|
|
325
|
+
export function zeusReadGuard(
|
|
326
|
+
tool: string,
|
|
327
|
+
args: unknown,
|
|
328
|
+
agent: string | undefined,
|
|
329
|
+
resolvePath?: GuardPathResolver,
|
|
330
|
+
): void {
|
|
222
331
|
if (agent !== 'zeus') return
|
|
223
332
|
if (tool !== 'read' && tool !== 'glob' && tool !== 'grep') return
|
|
224
333
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
334
|
+
if (tool === 'grep') {
|
|
335
|
+
const record =
|
|
336
|
+
args !== null && typeof args === 'object' ? (args as Record<string, unknown>) : {}
|
|
337
|
+
const grepPath = record.path
|
|
338
|
+
if (typeof grepPath !== 'string' || grepPath.trim() === '') {
|
|
339
|
+
throw new Error('Zeus cannot grep without an explicit non-empty path — delegate to @apollo')
|
|
340
|
+
}
|
|
341
|
+
if (Object.hasOwn(record, 'include')) {
|
|
342
|
+
throw new Error('Zeus cannot use grep include filters — delegate to @apollo')
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
for (const candidate of guardPathCandidates(tool, args)) {
|
|
347
|
+
const normalized = normalizeGuardPath(candidate.value)
|
|
348
|
+
const deny = () => {
|
|
349
|
+
throw new Error(`Zeus cannot read ${candidate.value} — delegate to @apollo`)
|
|
350
|
+
}
|
|
351
|
+
if (normalized === '') {
|
|
352
|
+
if (tool === 'grep' && candidate.target) deny()
|
|
353
|
+
continue
|
|
354
|
+
}
|
|
355
|
+
// A project-root spelling is an unbounded grep target, even though it does
|
|
356
|
+
// not match any individual denied source-root pattern.
|
|
357
|
+
if (tool === 'grep' && candidate.target && normalized === '.') deny()
|
|
358
|
+
const resolution =
|
|
359
|
+
candidate.target && resolvePath !== undefined ? resolvePath(candidate.value) : undefined
|
|
360
|
+
if (resolution?.failed) deny()
|
|
361
|
+
if (
|
|
362
|
+
tool === 'grep' &&
|
|
363
|
+
candidate.target &&
|
|
364
|
+
(resolution === undefined ||
|
|
365
|
+
resolution.isRegularFile !== true ||
|
|
366
|
+
resolution.withinProject !== true)
|
|
367
|
+
) {
|
|
368
|
+
deny()
|
|
369
|
+
}
|
|
370
|
+
const effectivePath = normalizeGuardPath(resolution?.resolved ?? normalized)
|
|
371
|
+
if (effectivePath === '' || (tool === 'grep' && candidate.target && effectivePath === '.')) {
|
|
372
|
+
if (tool === 'grep' && candidate.target) deny()
|
|
373
|
+
continue
|
|
242
374
|
}
|
|
375
|
+
// Resolve every direct grep/glob path before any policy decision. Wildcard
|
|
376
|
+
// expansion itself cannot be safely preflighted using the host's unknown
|
|
377
|
+
// symlink semantics, so Zeus may glob exact paths only.
|
|
378
|
+
if (tool === 'glob' && candidate.target && hasGlobMeta(effectivePath)) deny()
|
|
379
|
+
if (isDeniedReadPath(effectivePath, candidate.target)) deny()
|
|
243
380
|
}
|
|
244
381
|
}
|
|
245
382
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Goal Loop (Wave 3, PR #46) — when enabled, one active goal per session is
|
|
3
3
|
* continued automatically while idle. `pantheon_goal_create` starts a goal;
|
|
4
4
|
* `pantheon_goal_update` moves it pending → in_progress → done; while
|
|
5
5
|
* active, `GoalLoop.onIdle` re-injects the continuation prompt (objective
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* completion-audit prompt — the state machine is the source of truth.
|
|
8
8
|
*
|
|
9
9
|
* Persistence: FILE-based GoalStore (`.pantheon/goals/<sessionID>.json`,
|
|
10
|
-
* atomic tmp+rename).
|
|
10
|
+
* atomic tmp+rename). The plugin uses hard-coded defaults; no runtime config
|
|
11
|
+
* enables the loop in this build. Guards:
|
|
11
12
|
* board-running skip, in-flight Set, cooldown, max_continuations cap (25).
|
|
12
13
|
* Injectable now() clock. Pure TypeScript — zero runtime deps.
|
|
13
14
|
*
|
|
@@ -35,7 +36,7 @@ export { GoalStore }
|
|
|
35
36
|
/** Continuation text injected into idle sessions. `{objective}` is substituted. */
|
|
36
37
|
export const GOAL_CONTINUATION_PROMPT = 'Continue goal: {objective}'
|
|
37
38
|
|
|
38
|
-
/**
|
|
39
|
+
/** Hard-coded runtime defaults; routing.yml is documentation-only. */
|
|
39
40
|
export const GOAL_LOOP_DEFAULTS = {
|
|
40
41
|
enabled: false,
|
|
41
42
|
cooldownMs: 5000,
|
|
@@ -93,7 +94,7 @@ function toolFailure(prefix: string, err: unknown): string {
|
|
|
93
94
|
// ─── Args schemas ──────────────────────────────────────────────────────
|
|
94
95
|
|
|
95
96
|
const goalCreateArgs = {
|
|
96
|
-
objective: z.string().min(1).describe('The
|
|
97
|
+
objective: z.string().min(1).describe('The objective recorded in this legacy session goal.'),
|
|
97
98
|
} satisfies z.ZodRawShape
|
|
98
99
|
|
|
99
100
|
const goalUpdateArgs = {
|
|
@@ -149,8 +150,9 @@ export class GoalLoop {
|
|
|
149
150
|
this.warn = deps.logger?.warn ?? ((message: string) => log.warn(message))
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
/** True when the
|
|
153
|
+
/** True when the enabled loop can own idle for this session. */
|
|
153
154
|
async hasActiveGoal(sessionID: string): Promise<boolean> {
|
|
155
|
+
if (!this.options.enabled) return false
|
|
154
156
|
return this.store.hasActive(sessionID)
|
|
155
157
|
}
|
|
156
158
|
|
|
@@ -243,7 +245,7 @@ export class GoalLoop {
|
|
|
243
245
|
return {
|
|
244
246
|
pantheon_goal_create: {
|
|
245
247
|
description:
|
|
246
|
-
'Create the single active goal for this session.
|
|
248
|
+
'Deprecated legacy V1 tool. Create and store the single active goal for this session. Goals are stored but are not automatically continued in the current build. For durable manual goals, use the Persistence MCP `goal_*` tools available in this branch.',
|
|
247
249
|
args: goalCreateArgs,
|
|
248
250
|
execute: async (args, ctx) => {
|
|
249
251
|
try {
|
|
@@ -270,7 +272,7 @@ export class GoalLoop {
|
|
|
270
272
|
},
|
|
271
273
|
pantheon_goal_update: {
|
|
272
274
|
description:
|
|
273
|
-
'Update the active goal: set status (pending/in_progress/done) and/or rewrite the objective.
|
|
275
|
+
'Deprecated legacy V1 tool. Update the stored active goal: set status (pending/in_progress/done) and/or rewrite the objective. Goal records are not automatically continued in the current build. For durable manual goals, use the Persistence MCP `goal_*` tools available in this branch.',
|
|
274
276
|
args: goalUpdateArgs,
|
|
275
277
|
execute: async (args, ctx) => {
|
|
276
278
|
try {
|
|
@@ -292,7 +294,8 @@ export class GoalLoop {
|
|
|
292
294
|
},
|
|
293
295
|
},
|
|
294
296
|
pantheon_goal_get: {
|
|
295
|
-
description:
|
|
297
|
+
description:
|
|
298
|
+
'Deprecated legacy V1 tool. Return the stored active V1 goal (status, objective, continuation count). Goals are not automatically continued in the current build. For durable manual goals, use the Persistence MCP `goal_*` tools available in this branch.',
|
|
296
299
|
args: goalGetArgs,
|
|
297
300
|
execute: async (_args, ctx) => {
|
|
298
301
|
try {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symlink resolution for the Zeus read guard.
|
|
3
|
+
*
|
|
4
|
+
* `zeusReadGuard` is a pure, synchronous predicate shared by V1 and V2, so it
|
|
5
|
+
* cannot touch the filesystem itself. It therefore used to match only the
|
|
6
|
+
* STRING path: `docs/link → ../src` reached `src/` after resolution but passed
|
|
7
|
+
* the guard, while `pantheon_bounded_read` refused the same path via `lstat` +
|
|
8
|
+
* `realpath`. This module closes that gap at the CALL SITES: they resolve the
|
|
9
|
+
* raw path once, then hand the result to the guard.
|
|
10
|
+
*
|
|
11
|
+
* Resolution rules:
|
|
12
|
+
* - relative paths resolve against the project root, absolute paths stand;
|
|
13
|
+
* - a path that does not exist resolves its deepest EXISTING ancestor and
|
|
14
|
+
* re-appends the remaining segments — a deleted path can still be a bypass;
|
|
15
|
+
* - a resolved path inside the project root is expressed RELATIVE to it (so a
|
|
16
|
+
* project living under a directory named `src` is not a false positive),
|
|
17
|
+
* and a resolved path outside the root stays absolute (the guard already
|
|
18
|
+
* suffix-matches absolute paths, which is what catches `../src`);
|
|
19
|
+
* - any resolution failure (symlink loop, permissions, …) is reported as
|
|
20
|
+
* `failed`: a read guard fails CLOSED, and the guard denies.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { lstatSync, realpathSync, statSync } from 'node:fs'
|
|
24
|
+
import path from 'node:path'
|
|
25
|
+
|
|
26
|
+
/** One path form prepared for the guard. */
|
|
27
|
+
export interface GuardPathResolution {
|
|
28
|
+
/** Path as supplied, with separators normalized. */
|
|
29
|
+
raw: string
|
|
30
|
+
/**
|
|
31
|
+
* Symlink-resolved path: relative to the project root when it lands inside
|
|
32
|
+
* it, absolute otherwise. Absent when resolution failed.
|
|
33
|
+
*/
|
|
34
|
+
resolved?: string
|
|
35
|
+
/** `true` when the path could not be resolved — the guard must DENY. */
|
|
36
|
+
failed: boolean
|
|
37
|
+
/** Filesystem annotation from the call-site resolver; never computed by the pure guard. */
|
|
38
|
+
isRegularFile?: boolean
|
|
39
|
+
/** Whether the canonical target is the project root or one of its descendants. */
|
|
40
|
+
withinProject?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Errors that mean "this component does not exist", not "resolution failed". */
|
|
44
|
+
const MISSING_CODES: ReadonlySet<string> = new Set(['ENOENT', 'ENOTDIR'])
|
|
45
|
+
/** Bound filesystem component walks; paths beyond this limit fail closed. */
|
|
46
|
+
const MAX_PATH_COMPONENTS = 64
|
|
47
|
+
|
|
48
|
+
function errorCode(error: unknown): string {
|
|
49
|
+
if (typeof error !== 'object' || error === null || !('code' in error)) return ''
|
|
50
|
+
return String((error as { code: unknown }).code)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isMissing(error: unknown): boolean {
|
|
54
|
+
return MISSING_CODES.has(errorCode(error))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `true` when `target` is `root` or lives under it (both absolute). */
|
|
58
|
+
function isWithin(root: string, target: string): boolean {
|
|
59
|
+
const relative = path.relative(root, target)
|
|
60
|
+
return (
|
|
61
|
+
relative === '' ||
|
|
62
|
+
(!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative))
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* `realpath` of `absolute`, or of its deepest existing ancestor with the
|
|
68
|
+
* non-existent remainder appended. At most 64 components are examined; an
|
|
69
|
+
* existing dangling symlink or an overlong path fails closed.
|
|
70
|
+
*
|
|
71
|
+
* @returns the resolved absolute path, or `undefined` when resolution failed
|
|
72
|
+
* for a reason other than a missing component.
|
|
73
|
+
*/
|
|
74
|
+
function resolveExistingPrefix(absolute: string): string | undefined {
|
|
75
|
+
let cursor = path.resolve(absolute)
|
|
76
|
+
if (cursor.split(path.sep).filter(Boolean).length > MAX_PATH_COMPONENTS) return undefined
|
|
77
|
+
const remainder: string[] = []
|
|
78
|
+
for (let walked = 0; walked < MAX_PATH_COMPONENTS; walked++) {
|
|
79
|
+
try {
|
|
80
|
+
const resolved = realpathSync(cursor)
|
|
81
|
+
return remainder.length === 0 ? resolved : path.join(resolved, ...remainder)
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (!isMissing(error)) return undefined
|
|
84
|
+
try {
|
|
85
|
+
if (lstatSync(cursor).isSymbolicLink()) return undefined
|
|
86
|
+
} catch (lstatError) {
|
|
87
|
+
if (!isMissing(lstatError)) return undefined
|
|
88
|
+
}
|
|
89
|
+
const parent = path.dirname(cursor)
|
|
90
|
+
// Reached the filesystem root without resolving: unreachable on a sane
|
|
91
|
+
// system, but a failure must stay a failure (fail closed).
|
|
92
|
+
if (parent === cursor) return undefined
|
|
93
|
+
remainder.unshift(path.basename(cursor))
|
|
94
|
+
cursor = parent
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Normalize a resolved absolute path into the form the guard matches. */
|
|
101
|
+
function toGuardForm(resolvedAbsolute: string, rootReal: string): string {
|
|
102
|
+
const relative = isWithin(rootReal, resolvedAbsolute)
|
|
103
|
+
? path.relative(rootReal, resolvedAbsolute)
|
|
104
|
+
: resolvedAbsolute
|
|
105
|
+
return relative.split(path.sep).join('/')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Canonicalize an existing project directory; failure must never broaden access. */
|
|
109
|
+
function canonicalProjectRoot(projectRoot: string): string | undefined {
|
|
110
|
+
try {
|
|
111
|
+
const rootReal = realpathSync(path.resolve(projectRoot))
|
|
112
|
+
return statSync(rootReal).isDirectory() ? rootReal : undefined
|
|
113
|
+
} catch {
|
|
114
|
+
return undefined
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function resolveAgainst(rawPath: string, rootReal: string): GuardPathResolution {
|
|
119
|
+
const raw = rawPath.replace(/\\/g, '/')
|
|
120
|
+
const absolute = path.resolve(rootReal, raw)
|
|
121
|
+
const resolvedAbsolute = resolveExistingPrefix(absolute)
|
|
122
|
+
if (resolvedAbsolute === undefined) return { raw, failed: true }
|
|
123
|
+
let isRegularFile = false
|
|
124
|
+
try {
|
|
125
|
+
isRegularFile = statSync(resolvedAbsolute).isFile()
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (!isMissing(error)) return { raw, failed: true }
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
raw,
|
|
131
|
+
resolved: toGuardForm(resolvedAbsolute, rootReal),
|
|
132
|
+
failed: false,
|
|
133
|
+
isRegularFile,
|
|
134
|
+
withinProject: isWithin(rootReal, resolvedAbsolute),
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolve one raw tool path for the Zeus read guard.
|
|
140
|
+
*
|
|
141
|
+
* Use {@link createGuardPathResolver} at a call site that checks many paths:
|
|
142
|
+
* it resolves the project root once instead of once per path.
|
|
143
|
+
*/
|
|
144
|
+
export function resolveGuardPathForCheck(
|
|
145
|
+
rawPath: string,
|
|
146
|
+
projectRoot: string,
|
|
147
|
+
): GuardPathResolution {
|
|
148
|
+
const rootReal = canonicalProjectRoot(projectRoot)
|
|
149
|
+
return rootReal === undefined ? { raw: rawPath, failed: true } : resolveAgainst(rawPath, rootReal)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Build the per-call-site resolver. The project root is resolved once, so a
|
|
154
|
+
* symlinked root (`/tmp` → `/private/tmp`) compares against real paths.
|
|
155
|
+
*/
|
|
156
|
+
export function createGuardPathResolver(
|
|
157
|
+
projectRoot: string,
|
|
158
|
+
): (rawPath: string) => GuardPathResolution {
|
|
159
|
+
const rootReal = canonicalProjectRoot(projectRoot)
|
|
160
|
+
return (rawPath) =>
|
|
161
|
+
rootReal === undefined ? { raw: rawPath, failed: true } : resolveAgainst(rawPath, rootReal)
|
|
162
|
+
}
|