pantheon-opencode 1.6.1 → 1.6.2-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.
- package/AGENTS.global.md +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +29 -0
- package/README.md +100 -19
- package/README.pt-BR.md +27 -11
- package/bin/pantheon-init.mjs +106 -19
- package/package.json +3 -2
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +1 -1
- package/scripts/doctor.mjs +213 -45
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- package/scripts/install/mcp-permissions.mjs +164 -0
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +240 -69
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plugin.mjs +17 -1
- package/scripts/install/v2-capabilities.mjs +5 -6
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/sandbox-env.sh +174 -0
- package/scripts/setup-v2-config.mjs +1703 -0
- package/scripts/setup.mjs +415 -0
- package/scripts/sync-tui.mjs +9 -1
- package/scripts/test-opencode-v2-sandbox.sh +438 -151
- package/scripts/update-skills-lock.mjs +30 -0
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +5 -2
- package/src/agents/apollo.md +5 -0
- package/src/agents/athena.md +6 -1
- package/src/agents/demeter.md +5 -1
- package/src/agents/gaia.md +4 -0
- package/src/agents/hephaestus.md +6 -1
- package/src/agents/hermes.md +6 -3
- package/src/agents/iris.md +5 -1
- package/src/agents/mnemosyne.md +20 -50
- package/src/agents/nyx.md +5 -1
- package/src/agents/prometheus.md +4 -0
- package/src/agents/talos.md +4 -0
- package/src/agents/themis.md +4 -0
- package/src/agents/zeus.md +9 -3
- package/src/instructions/agent-return-format.instructions.md +1 -1
- package/src/instructions/memory-protocol.instructions.md +3 -3
- package/src/instructions/test-economy.instructions.md +6 -6
- package/src/mcp/pantheon_vision.py +37 -36
- package/src/pantheon/cost-command.ts +30 -133
- package/src/pantheon/model-pricing.ts +1 -536
- package/src/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +43 -10
- package/src/plugin-v2.ts +30 -53
- package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
- package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +749 -0
- package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +1 -0
- package/src/plugins/tui/dist/quota-adapters.d.ts +89 -0
- package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-adapters.js +1142 -0
- package/src/plugins/tui/dist/quota-adapters.js.map +1 -0
- package/src/plugins/tui/dist/quota-cli.d.ts +17 -0
- package/src/plugins/tui/dist/quota-cli.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-cli.js +184 -0
- package/src/plugins/tui/dist/quota-cli.js.map +1 -0
- package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js +684 -0
- package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +1 -0
- package/src/plugins/tui/dist/server-v2.d.ts +14 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +796 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +375 -53
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +5876 -530
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +118 -0
- package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +1 -0
- package/src/plugins/tui/dist/usage-history-worker.js +25 -0
- package/src/plugins/tui/dist/usage-history-worker.js.map +1 -0
- package/src/plugins/tui/index-v2.ts +3 -6
- package/src/plugins/tui/package-lock.json +17 -2
- package/src/plugins/tui/package.json +6 -3
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/go-key-diagnostic-ui.ts +100 -0
- package/src/plugins/tui/src/go-key-diagnostic.ts +125 -0
- package/src/plugins/tui/src/index-v2.tsx +231 -240
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/quota-adapters.ts +1598 -0
- package/src/plugins/tui/src/quota-cli.ts +237 -0
- package/src/plugins/tui/src/quota-rpc.ts +373 -0
- package/src/plugins/tui/src/quota-v2-model.ts +1032 -0
- package/src/plugins/tui/src/quota-v2.tsx +1238 -0
- package/src/plugins/tui/src/server-v2.ts +985 -0
- package/src/plugins/tui/src/sidebar-width.ts +129 -0
- package/src/plugins/tui/src/usage-history-contract.ts +217 -0
- package/src/plugins/tui/src/usage-history-validation.ts +104 -0
- package/src/plugins/tui/src/usage-history-view.tsx +236 -0
- package/src/plugins/tui/src/usage-history-worker.ts +25 -0
- package/src/plugins/tui/src/usage-view-model.ts +272 -0
- package/src/plugins/tui/tsconfig.typecheck.json +6 -1
- package/src/plugins/tui/tsdown.config.ts +44 -5
- package/src/routing.yml +72 -13
- package/src/skills/README.md +4 -0
- package/src/skills/agent-coordination/SKILL.md +0 -3
- package/src/skills/artifact-management/SKILL.md +0 -3
- package/src/skills/auto-continue/SKILL.md +0 -3
- package/src/skills/code-review-checklist/SKILL.md +0 -3
- package/src/skills/context-compression/SKILL.md +0 -3
- package/src/skills/memory-bank/SKILL.md +6 -28
- package/src/skills/session-goal/SKILL.md +0 -3
- package/src/skills/simplify/SKILL.md +5 -4
- package/src/skills/tdd-with-agents/SKILL.md +0 -3
- package/src/skills/visual-review-pipeline/SKILL.md +0 -1
- package/src/pantheon/memory-context.ts +0 -1017
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import os from 'node:os'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
/** Resolve the global OpenCode config directory used by init and setup. */
|
|
5
|
+
export function resolveGlobalConfigDirectory(env = process.env, home = os.homedir()) {
|
|
6
|
+
const xdgConfigHome = env.XDG_CONFIG_HOME
|
|
7
|
+
if (
|
|
8
|
+
xdgConfigHome !== undefined &&
|
|
9
|
+
xdgConfigHome !== '' &&
|
|
10
|
+
(typeof xdgConfigHome !== 'string' || !path.isAbsolute(xdgConfigHome))
|
|
11
|
+
) {
|
|
12
|
+
throw new Error('XDG_CONFIG_HOME must be an absolute path.')
|
|
13
|
+
}
|
|
14
|
+
return path.join(xdgConfigHome || path.join(home, '.config'), 'opencode')
|
|
15
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { opencodeWildcardPatternsOverlap } from './opencode-wildcard.mjs'
|
|
2
|
+
|
|
3
|
+
/** Canonical OpenCode V2 MCP action-name normalization shared by all writers. */
|
|
4
|
+
|
|
5
|
+
export function normalizeMcpPermissionSegment(value) {
|
|
6
|
+
return value.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** V1 spellings support V1 hosts; normalized spellings are required by V2. */
|
|
10
|
+
export function mcpPermissionAliases(value) {
|
|
11
|
+
return [...new Set([value, normalizeMcpPermissionSegment(value)])]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function mcpServerPermissionActions(server) {
|
|
15
|
+
return mcpPermissionAliases(server).map((alias) => `${alias}_*`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* These generated action patterns are all fixed prefixes followed by `*`.
|
|
20
|
+
* Their languages intersect exactly when one fixed prefix contains the other.
|
|
21
|
+
*/
|
|
22
|
+
export function mcpPermissionActionPatternsOverlap(left, right) {
|
|
23
|
+
return opencodeWildcardPatternsOverlap(left, right)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function mcpServerPermissionScopesOverlap(left, right) {
|
|
27
|
+
return mcpServerPermissionActions(left).some((leftAction) =>
|
|
28
|
+
mcpServerPermissionActions(right).some((rightAction) =>
|
|
29
|
+
mcpPermissionActionPatternsOverlap(leftAction, rightAction),
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Refuse distinct V1 server names whose generated action globs overlap in V2. */
|
|
35
|
+
export function assertMcpServerPermissionScopesUnambiguous(rules) {
|
|
36
|
+
for (let leftIndex = 0; leftIndex < rules.length; leftIndex += 1) {
|
|
37
|
+
const left = rules[leftIndex]
|
|
38
|
+
for (let rightIndex = leftIndex + 1; rightIndex < rules.length; rightIndex += 1) {
|
|
39
|
+
const right = rules[rightIndex]
|
|
40
|
+
if (
|
|
41
|
+
left.server !== right.server &&
|
|
42
|
+
mcpServerPermissionScopesOverlap(left.server, right.server)
|
|
43
|
+
) {
|
|
44
|
+
throw new TypeError(
|
|
45
|
+
'Distinct MCP permission server scopes overlap after OpenCode V2 action normalization.',
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Refuse policy scopes that also match a distinct configured MCP server. */
|
|
53
|
+
export function assertMcpPermissionScopesDoNotAliasConfiguredServers(
|
|
54
|
+
policyServers,
|
|
55
|
+
configuredServers,
|
|
56
|
+
) {
|
|
57
|
+
for (const policyServer of policyServers) {
|
|
58
|
+
for (const configuredServer of configuredServers) {
|
|
59
|
+
if (
|
|
60
|
+
policyServer !== configuredServer &&
|
|
61
|
+
mcpServerPermissionScopesOverlap(policyServer, configuredServer)
|
|
62
|
+
) {
|
|
63
|
+
throw new TypeError(
|
|
64
|
+
'An MCP permission scope overlaps a distinct configured server after OpenCode V2 action normalization.',
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Agent MCP metadata emits default server denies and then explicit grants.
|
|
73
|
+
* Refuse grants that can also match a different server's denied action scope.
|
|
74
|
+
*/
|
|
75
|
+
export function assertMcpPermissionServerGrantsUnambiguous(servers) {
|
|
76
|
+
const scopes = servers.map(({ server, tools }) => ({
|
|
77
|
+
server,
|
|
78
|
+
tools,
|
|
79
|
+
effect: tools === 'all' ? 'allow' : 'deny',
|
|
80
|
+
}))
|
|
81
|
+
|
|
82
|
+
for (let leftIndex = 0; leftIndex < scopes.length; leftIndex += 1) {
|
|
83
|
+
const left = scopes[leftIndex]
|
|
84
|
+
for (let rightIndex = leftIndex + 1; rightIndex < scopes.length; rightIndex += 1) {
|
|
85
|
+
const right = scopes[rightIndex]
|
|
86
|
+
if (
|
|
87
|
+
left.effect !== right.effect &&
|
|
88
|
+
mcpServerPermissionScopesOverlap(left.server, right.server)
|
|
89
|
+
) {
|
|
90
|
+
throw new TypeError('Overlapping MCP permission scopes have conflicting agent effects.')
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const grant of scopes) {
|
|
96
|
+
if (!Array.isArray(grant.tools)) continue
|
|
97
|
+
const grantActions = grant.tools.flatMap((tool) =>
|
|
98
|
+
mcpPermissionAliases(grant.server).flatMap((serverAlias) =>
|
|
99
|
+
mcpPermissionAliases(tool).map((toolAlias) => `${serverAlias}_${toolAlias}`),
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
for (const deny of scopes) {
|
|
103
|
+
if (grant.server === deny.server || deny.effect !== 'deny') continue
|
|
104
|
+
if (
|
|
105
|
+
grantActions.some((action) =>
|
|
106
|
+
mcpServerPermissionActions(deny.server).some((scope) =>
|
|
107
|
+
mcpPermissionActionPatternsOverlap(action, scope),
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
) {
|
|
111
|
+
throw new TypeError('An MCP tool grant overlaps a different server deny scope.')
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Refuse generated MCP allows that would replace an explicit agent deny/ask. */
|
|
118
|
+
export function assertMcpGeneratedPermissionsDoNotWeakenExplicitRules(explicit, generated) {
|
|
119
|
+
if (explicit === undefined) return
|
|
120
|
+
if (explicit === null || typeof explicit !== 'object' || Array.isArray(explicit)) {
|
|
121
|
+
throw new TypeError(
|
|
122
|
+
'Explicit agent permissions must be an object when combined with mcp_tools.',
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const grants = Object.entries(generated).filter(([, effect]) => effect === 'allow')
|
|
127
|
+
if (grants.length === 0) return
|
|
128
|
+
|
|
129
|
+
for (const [action, rule] of Object.entries(explicit)) {
|
|
130
|
+
if (!grants.some(([grantAction]) => opencodeWildcardPatternsOverlap(action, grantAction))) {
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
const isResourceMap = rule !== null && typeof rule === 'object' && !Array.isArray(rule)
|
|
134
|
+
if (typeof rule !== 'string' && !isResourceMap) {
|
|
135
|
+
throw new TypeError(
|
|
136
|
+
'An overlapping explicit agent permission cannot be safely combined with mcp_tools.',
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
const effects = typeof rule === 'string' ? [rule] : isResourceMap ? Object.values(rule) : []
|
|
140
|
+
if (effects.some((effect) => !['allow', 'ask', 'deny'].includes(effect))) {
|
|
141
|
+
throw new TypeError(
|
|
142
|
+
'An overlapping explicit agent permission cannot be safely combined with mcp_tools.',
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
if (effects.some((effect) => effect === 'deny' || effect === 'ask')) {
|
|
146
|
+
throw new TypeError(
|
|
147
|
+
'A generated MCP grant overlaps an explicit agent deny or ask permission.',
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Refuse names whose V2-normalized action cannot distinguish their source. */
|
|
154
|
+
export function assertMcpPermissionNamesUnambiguous(names) {
|
|
155
|
+
const normalizedOwners = new Map()
|
|
156
|
+
for (const name of names) {
|
|
157
|
+
const normalized = normalizeMcpPermissionSegment(name)
|
|
158
|
+
const owner = normalizedOwners.get(normalized)
|
|
159
|
+
if (owner !== undefined && owner !== name) {
|
|
160
|
+
throw new TypeError('MCP names collide after OpenCode V2 permission normalization.')
|
|
161
|
+
}
|
|
162
|
+
normalizedOwners.set(normalized, name)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -11,20 +11,38 @@ const VALID_VERSIONS = new Set(['v1', 'v2', 'auto'])
|
|
|
11
11
|
|
|
12
12
|
/** @param {string[]} args @returns {'v1'|'v2'|'auto'|null} */
|
|
13
13
|
export function parseOpenCodeVersion(args) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
// Match init's selector precedence: modern --version wins over the legacy
|
|
15
|
+
// alias regardless of argument order. The package-level --version command is
|
|
16
|
+
// handled before this init selector parser is called.
|
|
17
|
+
const inlineModern = args.find((arg) => arg.startsWith('--version='))
|
|
18
|
+
if (inlineModern !== undefined) {
|
|
19
|
+
const value = inlineModern.slice('--version='.length)
|
|
20
|
+
if (!value) throw missingVersionValue('--version')
|
|
21
|
+
return normalize(value)
|
|
22
|
+
}
|
|
23
|
+
const modernIndex = args.indexOf('--version')
|
|
24
|
+
if (modernIndex >= 0) {
|
|
25
|
+
const modern = args[modernIndex + 1]
|
|
26
|
+
if (modern === undefined || modern.startsWith('-')) throw missingVersionValue('--version')
|
|
27
|
+
return normalize(modern)
|
|
28
|
+
}
|
|
29
|
+
const inlineLegacy = args.find((arg) => arg.startsWith('--opencode-version='))
|
|
30
|
+
if (inlineLegacy !== undefined) {
|
|
31
|
+
const value = inlineLegacy.slice('--opencode-version='.length)
|
|
32
|
+
if (!value) throw missingVersionValue('--opencode-version')
|
|
33
|
+
return normalize(value)
|
|
26
34
|
}
|
|
27
|
-
|
|
35
|
+
const legacyIndex = args.indexOf('--opencode-version')
|
|
36
|
+
if (legacyIndex < 0) return null
|
|
37
|
+
const legacy = args[legacyIndex + 1]
|
|
38
|
+
if (legacy === undefined || legacy.startsWith('-')) {
|
|
39
|
+
throw missingVersionValue('--opencode-version')
|
|
40
|
+
}
|
|
41
|
+
return normalize(legacy)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function missingVersionValue(flag) {
|
|
45
|
+
return new Error(`${flag} requires a value: v1, v2, or auto.`)
|
|
28
46
|
}
|
|
29
47
|
|
|
30
48
|
function normalize(value) {
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** OpenCode's permission wildcard matcher and exact language intersection. */
|
|
2
|
+
|
|
3
|
+
const CASE_INSENSITIVE = process.platform === 'win32'
|
|
4
|
+
|
|
5
|
+
function normalizePattern(pattern) {
|
|
6
|
+
return pattern.replaceAll('\\', '/')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function escapeRegexCharacter(char) {
|
|
10
|
+
return /[\\^$.*+?()[\]{}|]/.test(char) ? `\\${char}` : char
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Match the OpenCode Wildcard.match behavior used by permission evaluation. */
|
|
14
|
+
export function opencodeWildcardMatch(input, pattern) {
|
|
15
|
+
const normalizedPattern = normalizePattern(pattern)
|
|
16
|
+
const trailingSpaceStar = normalizedPattern.endsWith(' *')
|
|
17
|
+
const body = trailingSpaceStar ? normalizedPattern.slice(0, -2) : normalizedPattern
|
|
18
|
+
let expression = '^'
|
|
19
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
20
|
+
const char = body[index]
|
|
21
|
+
if (char === '*') expression += '.*'
|
|
22
|
+
else if (char === '?') expression += '.'
|
|
23
|
+
else expression += escapeRegexCharacter(char)
|
|
24
|
+
}
|
|
25
|
+
if (trailingSpaceStar) expression += '(?: .*)?'
|
|
26
|
+
return new RegExp(`${expression}$`, CASE_INSENSITIVE ? 'is' : 's').test(normalizePattern(input))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function compileWildcard(pattern) {
|
|
30
|
+
const normalized = normalizePattern(pattern)
|
|
31
|
+
const trailingSpaceStar = normalized.endsWith(' *')
|
|
32
|
+
const body = trailingSpaceStar ? normalized.slice(0, -2) : normalized
|
|
33
|
+
const states = [{ epsilon: [], edges: [] }]
|
|
34
|
+
let current = 0
|
|
35
|
+
const addState = () => {
|
|
36
|
+
states.push({ epsilon: [], edges: [] })
|
|
37
|
+
return states.length - 1
|
|
38
|
+
}
|
|
39
|
+
const edge = (from, to, kind, value) => states[from].edges.push({ to, kind, value })
|
|
40
|
+
|
|
41
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
42
|
+
const char = body[index]
|
|
43
|
+
if (char === '*') {
|
|
44
|
+
const next = addState()
|
|
45
|
+
states[current].epsilon.push(next)
|
|
46
|
+
edge(current, current, 'any')
|
|
47
|
+
current = next
|
|
48
|
+
} else {
|
|
49
|
+
const next = addState()
|
|
50
|
+
edge(current, next, char === '?' ? 'any' : 'literal', char)
|
|
51
|
+
current = next
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (trailingSpaceStar) {
|
|
56
|
+
const next = addState()
|
|
57
|
+
const spaceLoop = addState()
|
|
58
|
+
states[current].epsilon.push(next)
|
|
59
|
+
edge(current, spaceLoop, 'literal', ' ')
|
|
60
|
+
states[spaceLoop].epsilon.push(next)
|
|
61
|
+
edge(spaceLoop, spaceLoop, 'any')
|
|
62
|
+
current = next
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { states, start: 0, accept: current }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function literalCharactersOverlap(left, right) {
|
|
69
|
+
if (!CASE_INSENSITIVE) return left === right
|
|
70
|
+
return new RegExp(`^${escapeRegexCharacter(left)}$`, 'i').test(right)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function edgesOverlap(left, right) {
|
|
74
|
+
if (left.kind === 'any' || right.kind === 'any') return true
|
|
75
|
+
return literalCharactersOverlap(left.value, right.value)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Exact non-empty language intersection for OpenCode's `*`/`?` wildcard
|
|
80
|
+
* grammar. Brackets and other regex punctuation are literal; backslashes are
|
|
81
|
+
* normalized to slashes; `*` crosses slashes; and a final ` *` is optional.
|
|
82
|
+
*/
|
|
83
|
+
export function opencodeWildcardPatternsOverlap(leftPattern, rightPattern) {
|
|
84
|
+
const left = compileWildcard(leftPattern)
|
|
85
|
+
const right = compileWildcard(rightPattern)
|
|
86
|
+
const queue = [[left.start, right.start]]
|
|
87
|
+
const visited = new Set()
|
|
88
|
+
|
|
89
|
+
for (let cursor = 0; cursor < queue.length; cursor += 1) {
|
|
90
|
+
const [leftState, rightState] = queue[cursor]
|
|
91
|
+
const key = `${leftState}:${rightState}`
|
|
92
|
+
if (visited.has(key)) continue
|
|
93
|
+
visited.add(key)
|
|
94
|
+
if (leftState === left.accept && rightState === right.accept) return true
|
|
95
|
+
|
|
96
|
+
for (const next of left.states[leftState].epsilon) queue.push([next, rightState])
|
|
97
|
+
for (const next of right.states[rightState].epsilon) queue.push([leftState, next])
|
|
98
|
+
for (const leftEdge of left.states[leftState].edges) {
|
|
99
|
+
for (const rightEdge of right.states[rightState].edges) {
|
|
100
|
+
if (edgesOverlap(leftEdge, rightEdge)) queue.push([leftEdge.to, rightEdge.to])
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false
|
|
106
|
+
}
|