@movemama/opencode-legacy 1.0.3 → 1.0.4
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/README.md +0 -2
- package/package.json +1 -1
- package/plugin-meta.js +1 -1
- package/tools/agents-rules.js +0 -17
- package/tools/edit.js +2 -17
- package/tools/legacy-edit-feedback.js +0 -68
package/README.md
CHANGED
|
@@ -142,8 +142,6 @@ OpenCode legacy 文本处理插件,默认更偏向 `GBK` 文本兼容,同时
|
|
|
142
142
|
- `classic-tag` 文本可根据 `profile` 和 `scriptMarkers` 判断为更偏 block / line-normalized 的策略
|
|
143
143
|
- `rich-ui-dsl` 文本会优先识别 `<Text|...>` / `<Button|...>` 组件,并在 exact 失败后尝试 widget 字段级更新
|
|
144
144
|
- 失败时会返回当前策略、格式族和 fallback 提示,便于继续排障
|
|
145
|
-
- 编辑成功时也会返回:检测格式、修改策略、修改次数、命中位置,以及旧片段 / 新片段摘要,便于像内置 `edit` 一样快速确认改动位置
|
|
146
|
-
- 插件还会通过 `tool.execute.after` 对 legacy edit 结果做统一包装,补充一致的标题与 metadata,方便后续继续往内置 `edit` 体验靠拢
|
|
147
145
|
|
|
148
146
|
## 支持的格式族
|
|
149
147
|
|
package/package.json
CHANGED
package/plugin-meta.js
CHANGED
package/tools/agents-rules.js
CHANGED
|
@@ -2,7 +2,6 @@ import { existsSync, readFileSync } from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
const EDIT_GUARDED_TOOLS = new Set(['edit', 'write', 'script-edit', 'legacy_edit', 'legacy_write'])
|
|
5
|
-
const LEGACY_EDIT_FEEDBACK_TOOLS = new Set(['edit', 'legacy_edit', 'script-edit'])
|
|
6
5
|
|
|
7
6
|
function normalizeLineEndings(content) {
|
|
8
7
|
return content.replace(/\r\n/g, '\n').trim()
|
|
@@ -73,21 +72,5 @@ export function createAgentsRuleHooks(input = {}) {
|
|
|
73
72
|
throw new Error('当前会话尚未完成 AGENTS.md 规则注入,已禁止编辑类工具执行。请先让插件读取全局与项目 AGENTS.md。')
|
|
74
73
|
}
|
|
75
74
|
},
|
|
76
|
-
'tool.execute.after': async (hookInput, output) => {
|
|
77
|
-
if (!LEGACY_EDIT_FEEDBACK_TOOLS.has(hookInput.tool)) {
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (typeof output?.output !== 'string' || !output.output.includes('修改策略:')) {
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
output.title = 'legacy edit'
|
|
86
|
-
output.metadata = {
|
|
87
|
-
...(output.metadata || {}),
|
|
88
|
-
kind: 'legacy-edit-feedback',
|
|
89
|
-
tool: hookInput.tool,
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
75
|
}
|
|
93
76
|
}
|
package/tools/edit.js
CHANGED
|
@@ -4,7 +4,6 @@ import path from 'node:path'
|
|
|
4
4
|
import readTool from './read.js'
|
|
5
5
|
import writeTool from './write.js'
|
|
6
6
|
import { applyLegacyEdit } from './legacy-edit-core.mjs'
|
|
7
|
-
import { buildEditFeedback } from './legacy-edit-feedback.js'
|
|
8
7
|
import { matchLegacyRule } from './legacy-router.mjs'
|
|
9
8
|
import { loadLegacyRules } from './legacy-rules-loader.js'
|
|
10
9
|
import { chooseEditStrategy } from './legacy-strategy.js'
|
|
@@ -35,14 +34,7 @@ export default tool({
|
|
|
35
34
|
const result = applyLegacyEdit(content, args.oldString, args.newString, Boolean(args.replaceAll))
|
|
36
35
|
|
|
37
36
|
if (result.changed) {
|
|
38
|
-
|
|
39
|
-
return buildEditFeedback({
|
|
40
|
-
writeMessage,
|
|
41
|
-
detectedFamily: strategy.detectedFamily,
|
|
42
|
-
strategy: 'exact-first',
|
|
43
|
-
originalContent: content,
|
|
44
|
-
updatedContent: result.content,
|
|
45
|
-
})
|
|
37
|
+
return writeTool.execute({ filePath, content: result.content }, context)
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
const fallbackResult = applyFallbackEditChain({
|
|
@@ -53,14 +45,7 @@ export default tool({
|
|
|
53
45
|
})
|
|
54
46
|
|
|
55
47
|
if (fallbackResult.changed) {
|
|
56
|
-
|
|
57
|
-
return buildEditFeedback({
|
|
58
|
-
writeMessage,
|
|
59
|
-
detectedFamily: strategy.detectedFamily,
|
|
60
|
-
strategy: fallbackResult.strategy,
|
|
61
|
-
originalContent: content,
|
|
62
|
-
updatedContent: fallbackResult.content,
|
|
63
|
-
})
|
|
48
|
+
return writeTool.execute({ filePath, content: fallbackResult.content }, context)
|
|
64
49
|
}
|
|
65
50
|
|
|
66
51
|
throw new Error(
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
function normalizeNewlines(text) {
|
|
2
|
-
return text.replace(/\r\n/g, '\n')
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function buildPositionLabel(startLine, endLine) {
|
|
6
|
-
if (startLine === endLine) {
|
|
7
|
-
return `${startLine}`
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return `${startLine}-${endLine}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function summarizeChangedBlock(original, updated) {
|
|
14
|
-
const originalLines = normalizeNewlines(original).split('\n')
|
|
15
|
-
const updatedLines = normalizeNewlines(updated).split('\n')
|
|
16
|
-
|
|
17
|
-
let prefix = 0
|
|
18
|
-
while (
|
|
19
|
-
prefix < originalLines.length
|
|
20
|
-
&& prefix < updatedLines.length
|
|
21
|
-
&& originalLines[prefix] === updatedLines[prefix]
|
|
22
|
-
) {
|
|
23
|
-
prefix += 1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let suffix = 0
|
|
27
|
-
while (
|
|
28
|
-
suffix < originalLines.length - prefix
|
|
29
|
-
&& suffix < updatedLines.length - prefix
|
|
30
|
-
&& originalLines[originalLines.length - 1 - suffix] === updatedLines[updatedLines.length - 1 - suffix]
|
|
31
|
-
) {
|
|
32
|
-
suffix += 1
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const originalEnd = Math.max(prefix, originalLines.length - suffix)
|
|
36
|
-
const updatedEnd = Math.max(prefix, updatedLines.length - suffix)
|
|
37
|
-
const oldBlock = originalLines.slice(prefix, originalEnd)
|
|
38
|
-
const newBlock = updatedLines.slice(prefix, updatedEnd)
|
|
39
|
-
const startLine = prefix + 1
|
|
40
|
-
const endLine = Math.max(prefix + oldBlock.length, prefix + newBlock.length)
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
changeCount: 1,
|
|
44
|
-
position: buildPositionLabel(startLine, endLine),
|
|
45
|
-
oldSnippet: oldBlock.join('\n'),
|
|
46
|
-
newSnippet: newBlock.join('\n'),
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function buildEditFeedback({
|
|
51
|
-
writeMessage,
|
|
52
|
-
detectedFamily,
|
|
53
|
-
strategy,
|
|
54
|
-
originalContent,
|
|
55
|
-
updatedContent,
|
|
56
|
-
}) {
|
|
57
|
-
const summary = summarizeChangedBlock(originalContent, updatedContent)
|
|
58
|
-
|
|
59
|
-
return [
|
|
60
|
-
writeMessage,
|
|
61
|
-
`检测格式:${detectedFamily}`,
|
|
62
|
-
`修改策略:${strategy}`,
|
|
63
|
-
`修改次数:${summary.changeCount}`,
|
|
64
|
-
`命中位置:${summary.position}`,
|
|
65
|
-
`旧片段:${summary.oldSnippet}`,
|
|
66
|
-
`新片段:${summary.newSnippet}`,
|
|
67
|
-
].join('\n')
|
|
68
|
-
}
|