@plainconceptsplatform/agent-harness 2.2.0 → 2.3.0
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/package.json +1 -1
- package/src/commands/migrate.js +17 -1
- package/src/commands/update.js +13 -1
- package/src/content/.agents/skills/pc-make-engineer/SKILL.md +219 -219
- package/src/content/.agents/skills/pc-make-engineer/template.md +80 -81
- package/src/content/.opencode/plugins/pc-subagent-tiers.js +337 -281
- package/src/content/opencode.jsonc +41 -39
- package/src/steps/copy/agents.js +119 -118
- package/src/steps/copy/commands.js +95 -91
- package/src/steps/copy/fullstack-engineer.js +88 -85
- package/src/steps/copy/opencode-json.js +161 -147
- package/src/steps/metadata/index.js +4 -0
- package/src/steps/optimization/detect.js +66 -0
- package/src/steps/optimization/patch-guardrails.js +109 -108
- package/src/utils/agent-color.js +83 -0
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://opencode.ai/config.json",
|
|
3
|
-
"instructions": [
|
|
4
|
-
"AGENTS.md"
|
|
5
|
-
],
|
|
6
|
-
"plugin": [
|
|
7
|
-
"@different-ai/opencode-browser@4.6.1",
|
|
8
|
-
"@mohak34/opencode-notifier@0.2.8"
|
|
9
|
-
],
|
|
10
|
-
"experimental": {
|
|
11
|
-
"mcp_timeout": 300000
|
|
12
|
-
},
|
|
13
|
-
"compaction": {
|
|
14
|
-
"auto": true,
|
|
15
|
-
"prune": true,
|
|
16
|
-
"reserved": 10000
|
|
17
|
-
},
|
|
18
|
-
"permission": {
|
|
19
|
-
"question": "allow",
|
|
20
|
-
"todowrite": "allow",
|
|
21
|
-
"skill": "allow"
|
|
22
|
-
},
|
|
23
|
-
"skills": {
|
|
24
|
-
"paths": [".agents/skills"]
|
|
25
|
-
},
|
|
26
|
-
// build and plan are the only primaries
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://opencode.ai/config.json",
|
|
3
|
+
"instructions": [
|
|
4
|
+
"AGENTS.md"
|
|
5
|
+
],
|
|
6
|
+
"plugin": [
|
|
7
|
+
"@different-ai/opencode-browser@4.6.1",
|
|
8
|
+
"@mohak34/opencode-notifier@0.2.8"
|
|
9
|
+
],
|
|
10
|
+
"experimental": {
|
|
11
|
+
"mcp_timeout": 300000
|
|
12
|
+
},
|
|
13
|
+
"compaction": {
|
|
14
|
+
"auto": true,
|
|
15
|
+
"prune": true,
|
|
16
|
+
"reserved": 10000
|
|
17
|
+
},
|
|
18
|
+
"permission": {
|
|
19
|
+
"question": "allow",
|
|
20
|
+
"todowrite": "allow",
|
|
21
|
+
"skill": "allow"
|
|
22
|
+
},
|
|
23
|
+
"skills": {
|
|
24
|
+
"paths": [".agents/skills"]
|
|
25
|
+
},
|
|
26
|
+
// build and plan are the only primaries, and plan is the default: a session
|
|
27
|
+
// starts read-only and you switch to build once you know what to change.
|
|
28
|
+
// The pc-subagent-tiers plugin
|
|
29
|
+
// regenerates .opencode/agents/{build,plan}.md from fullstack-engineer.md on
|
|
30
|
+
// every startup and overrides these two entries with the resolved tier model,
|
|
31
|
+
// so what is here is only the floor if the plugin cannot run. Every engineer
|
|
32
|
+
// is mode: subagent and reached through task(), never picked by a human.
|
|
33
|
+
"default_agent": "plan",
|
|
34
|
+
"agent": {
|
|
35
|
+
"build": { "mode": "primary" },
|
|
36
|
+
"plan": {
|
|
37
|
+
"mode": "primary",
|
|
38
|
+
"permission": { "edit": "deny" }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/steps/copy/agents.js
CHANGED
|
@@ -1,118 +1,119 @@
|
|
|
1
|
-
import fse from 'fs-extra'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { fileURLToPath } from 'url'
|
|
4
|
-
import { info, success, warn } from '../../utils/exec.js'
|
|
5
|
-
|
|
6
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
const agentsContent = await fse.readJson(path.resolve(__dirname, '../../presets/agents-content.json'))
|
|
8
|
-
|
|
9
|
-
// Steps are matched by their title text, not by exact heading string:
|
|
10
|
-
// heading level (###/####) and step numbers have drifted before and silently
|
|
11
|
-
// broke removal. Matching `^#{3,4} Step N, <title>` survives both.
|
|
12
|
-
const HISTORY_STEP_TITLE = 'Archive project history'
|
|
13
|
-
const CHAIN_STEP_TITLE = 'Chain make commands'
|
|
14
|
-
|
|
15
|
-
const CHAIN_CONFIRM_LINE = '- ARCHITECTURE.md generated'
|
|
16
|
-
|
|
17
|
-
function stepHeadingPattern(title) {
|
|
18
|
-
const escaped = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
19
|
-
return new RegExp(`^#{2,4} Step \\d+, ${escaped}`)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// The step heading is kept and its body replaced with an explicit skip note.
|
|
23
|
-
// Removing the block and renumbering the remaining steps (the old approach)
|
|
24
|
-
// went stale against prose cross-references like "Skip steps 2, 3, and 4";
|
|
25
|
-
// stable numbering plus a visible reason is unambiguous for the agent.
|
|
26
|
-
export function skipStepBlock(content, title, note) {
|
|
27
|
-
const lines = content.split('\n')
|
|
28
|
-
const pattern = stepHeadingPattern(title)
|
|
29
|
-
const start = lines.findIndex(l => pattern.test(l.trim()))
|
|
30
|
-
if (start === -1) return { content, matched: false }
|
|
31
|
-
|
|
32
|
-
let end = lines.length
|
|
33
|
-
for (let i = start + 1; i < lines.length; i++) {
|
|
34
|
-
if (lines[i].trim() === '---') { end = i; break }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
lines.splice(start + 1, end - start - 1, '', `> ${note}`, '')
|
|
38
|
-
return { content: lines.join('\n'), matched: true }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function removeConfirmLine(content, line) {
|
|
42
|
-
return content.split('\n').filter(l => l.trim() !== line.trim()).join('\n')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const PLATFORM_WORKFLOW_START = '<!-- PC-PLATFORM-WORKFLOW-START -->'
|
|
46
|
-
const PLATFORM_WORKFLOW_END = '<!-- PC-PLATFORM-WORKFLOW-END -->'
|
|
47
|
-
const PLATFORM_SKILLS_GUIDE_START = '<!-- PC-PLATFORM-SKILLS-GUIDE-START -->'
|
|
48
|
-
const PLATFORM_SKILLS_GUIDE_END = '<!-- PC-PLATFORM-SKILLS-GUIDE-END -->'
|
|
49
|
-
|
|
50
|
-
function platformContent(platform, key) {
|
|
51
|
-
const p = agentsContent.platform[platform] ?? agentsContent.platform.github
|
|
52
|
-
return p[key] ?? ''
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function mixedPlatformContent(backlogPlatform, repoPlatform, key) {
|
|
56
|
-
if (backlogPlatform === repoPlatform) {
|
|
57
|
-
return platformContent(backlogPlatform, key)
|
|
58
|
-
}
|
|
59
|
-
const backlog = agentsContent.platform[backlogPlatform] ?? agentsContent.platform.github
|
|
60
|
-
const repo = agentsContent.platform[repoPlatform] ?? agentsContent.platform.github
|
|
61
|
-
const mixed = agentsContent.platform.mixed ?? {}
|
|
62
|
-
const mixedKey = `${backlogPlatform}-${repoPlatform}`
|
|
63
|
-
return mixed[mixedKey]?.[key] ?? mixed.default?.[key]?.replace('{backlog}', backlog[key] ?? '').replace('{repo}', repo[key] ?? '') ?? platformContent(repoPlatform, key)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function replaceBetween(content, start, end, replacement) {
|
|
67
|
-
if (!content.includes(start) || !content.includes(end)) return content
|
|
68
|
-
const pattern = new RegExp(`${start}[\\s\\S]*?${end}`)
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
content =
|
|
111
|
-
content = replaceBetween(content,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
import fse from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
4
|
+
import { info, success, warn } from '../../utils/exec.js'
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const agentsContent = await fse.readJson(path.resolve(__dirname, '../../presets/agents-content.json'))
|
|
8
|
+
|
|
9
|
+
// Steps are matched by their title text, not by exact heading string:
|
|
10
|
+
// heading level (###/####) and step numbers have drifted before and silently
|
|
11
|
+
// broke removal. Matching `^#{3,4} Step N, <title>` survives both.
|
|
12
|
+
const HISTORY_STEP_TITLE = 'Archive project history'
|
|
13
|
+
const CHAIN_STEP_TITLE = 'Chain make commands'
|
|
14
|
+
|
|
15
|
+
const CHAIN_CONFIRM_LINE = '- ARCHITECTURE.md generated'
|
|
16
|
+
|
|
17
|
+
function stepHeadingPattern(title) {
|
|
18
|
+
const escaped = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
19
|
+
return new RegExp(`^#{2,4} Step \\d+, ${escaped}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The step heading is kept and its body replaced with an explicit skip note.
|
|
23
|
+
// Removing the block and renumbering the remaining steps (the old approach)
|
|
24
|
+
// went stale against prose cross-references like "Skip steps 2, 3, and 4";
|
|
25
|
+
// stable numbering plus a visible reason is unambiguous for the agent.
|
|
26
|
+
export function skipStepBlock(content, title, note) {
|
|
27
|
+
const lines = content.split('\n')
|
|
28
|
+
const pattern = stepHeadingPattern(title)
|
|
29
|
+
const start = lines.findIndex(l => pattern.test(l.trim()))
|
|
30
|
+
if (start === -1) return { content, matched: false }
|
|
31
|
+
|
|
32
|
+
let end = lines.length
|
|
33
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
34
|
+
if (lines[i].trim() === '---') { end = i; break }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
lines.splice(start + 1, end - start - 1, '', `> ${note}`, '')
|
|
38
|
+
return { content: lines.join('\n'), matched: true }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function removeConfirmLine(content, line) {
|
|
42
|
+
return content.split('\n').filter(l => l.trim() !== line.trim()).join('\n')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const PLATFORM_WORKFLOW_START = '<!-- PC-PLATFORM-WORKFLOW-START -->'
|
|
46
|
+
const PLATFORM_WORKFLOW_END = '<!-- PC-PLATFORM-WORKFLOW-END -->'
|
|
47
|
+
const PLATFORM_SKILLS_GUIDE_START = '<!-- PC-PLATFORM-SKILLS-GUIDE-START -->'
|
|
48
|
+
const PLATFORM_SKILLS_GUIDE_END = '<!-- PC-PLATFORM-SKILLS-GUIDE-END -->'
|
|
49
|
+
|
|
50
|
+
function platformContent(platform, key) {
|
|
51
|
+
const p = agentsContent.platform[platform] ?? agentsContent.platform.github
|
|
52
|
+
return p[key] ?? ''
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function mixedPlatformContent(backlogPlatform, repoPlatform, key) {
|
|
56
|
+
if (backlogPlatform === repoPlatform) {
|
|
57
|
+
return platformContent(backlogPlatform, key)
|
|
58
|
+
}
|
|
59
|
+
const backlog = agentsContent.platform[backlogPlatform] ?? agentsContent.platform.github
|
|
60
|
+
const repo = agentsContent.platform[repoPlatform] ?? agentsContent.platform.github
|
|
61
|
+
const mixed = agentsContent.platform.mixed ?? {}
|
|
62
|
+
const mixedKey = `${backlogPlatform}-${repoPlatform}`
|
|
63
|
+
return mixed[mixedKey]?.[key] ?? mixed.default?.[key]?.replace('{backlog}', backlog[key] ?? '').replace('{repo}', repo[key] ?? '') ?? platformContent(repoPlatform, key)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function replaceBetween(content, start, end, replacement) {
|
|
67
|
+
if (!content.includes(start) || !content.includes(end)) return content
|
|
68
|
+
const pattern = new RegExp(`${start}[\\s\\S]*?${end}`)
|
|
69
|
+
// Replacer function so $&, $' and $` in injected content stay literal.
|
|
70
|
+
return content.replace(pattern, () => `${start}\n${replacement.trim()}\n${end}`)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function patchAgentsMd(ctx) {
|
|
74
|
+
const obInitSkillPath = path.join(process.cwd(), '.agents', 'skills', 'pc-repo-initialize', 'SKILL.md')
|
|
75
|
+
if (!await fse.pathExists(obInitSkillPath)) return
|
|
76
|
+
|
|
77
|
+
let content = await fse.readFile(obInitSkillPath, 'utf-8')
|
|
78
|
+
const patches = []
|
|
79
|
+
|
|
80
|
+
const skips = [
|
|
81
|
+
[ctx.hasOpenspec, HISTORY_STEP_TITLE, null,
|
|
82
|
+
'Skipped during onboarding: this project already had an openspec/ history. Do not archive again; continue with the next step.'],
|
|
83
|
+
[ctx.hasDesign || ctx.hasArchitecture, CHAIN_STEP_TITLE, CHAIN_CONFIRM_LINE,
|
|
84
|
+
'Skipped during onboarding: project files already exist. Run /make-architecture or /make-design individually to regenerate.'],
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
for (const [enabled, title, confirmLine, note] of skips) {
|
|
88
|
+
if (!enabled) continue
|
|
89
|
+
const result = skipStepBlock(content, title, note)
|
|
90
|
+
if (!result.matched) {
|
|
91
|
+
warn(`pc-repo-initialize SKILL.md step "${title}" not found: template drift? Skipping this patch.`)
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
94
|
+
content = result.content
|
|
95
|
+
if (confirmLine) content = removeConfirmLine(content, confirmLine)
|
|
96
|
+
patches.push(`Step "${title}" marked as skipped, file already exists`)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (patches.length > 0) {
|
|
100
|
+
await fse.writeFile(obInitSkillPath, content, 'utf-8')
|
|
101
|
+
for (const msg of patches) info(msg)
|
|
102
|
+
success('pc-repo-initialize SKILL.md patched for existing project state')
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function patchAgentGuidance(backlogPlatform, repoPlatform, cwd = process.cwd()) {
|
|
107
|
+
const agentsMdPath = path.join(cwd, 'AGENTS.md')
|
|
108
|
+
if (await fse.pathExists(agentsMdPath)) {
|
|
109
|
+
const repo = repoPlatform ?? backlogPlatform ?? 'github'
|
|
110
|
+
let content = await fse.readFile(agentsMdPath, 'utf-8')
|
|
111
|
+
content = replaceBetween(content, PLATFORM_WORKFLOW_START, PLATFORM_WORKFLOW_END, mixedPlatformContent(backlogPlatform, repo, 'workflow'))
|
|
112
|
+
content = replaceBetween(content, PLATFORM_SKILLS_GUIDE_START, PLATFORM_SKILLS_GUIDE_END, mixedPlatformContent(backlogPlatform, repo, 'skillsGuide'))
|
|
113
|
+
await fse.writeFile(agentsMdPath, `${content.replace(/\s*$/, '')}\n`, 'utf-8')
|
|
114
|
+
const label = backlogPlatform === repo ? repo : `${backlogPlatform}→${repo}`
|
|
115
|
+
success(`AGENTS.md patched for platform workflow: ${label}`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
@@ -1,91 +1,95 @@
|
|
|
1
|
-
import fse from 'fs-extra'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { fileURLToPath } from 'url'
|
|
4
|
-
import { success } from '../../utils/exec.js'
|
|
5
|
-
|
|
6
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
|
|
8
|
-
const _archive = {
|
|
9
|
-
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/az.md'), 'utf-8'),
|
|
10
|
-
github: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/gh.md'), 'utf-8'),
|
|
11
|
-
gitlab: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/gl.md'), 'utf-8'),
|
|
12
|
-
none: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/none.md'), 'utf-8'),
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const _ship = {
|
|
16
|
-
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-ship/gh.md'), 'utf-8'),
|
|
17
|
-
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-ship/az.md'), 'utf-8'),
|
|
18
|
-
gitlab: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-ship/gl.md'), 'utf-8'),
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const _review = {
|
|
22
|
-
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-review/gh.md'), 'utf-8'),
|
|
23
|
-
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-review/az.md'), 'utf-8'),
|
|
24
|
-
gitlab: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-review/gl.md'), 'utf-8'),
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const _backlog = {
|
|
28
|
-
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-backlog/gh.md'), 'utf-8'),
|
|
29
|
-
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-backlog/az.md'), 'utf-8'),
|
|
30
|
-
jira: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-backlog/jira.md'), 'utf-8'),
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Evidence comments target the backlog platform (where the issue/work-item lives).
|
|
34
|
-
const _evidence = {
|
|
35
|
-
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-evidence/gh.md'), 'utf-8'),
|
|
36
|
-
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-evidence/az.md'), 'utf-8'),
|
|
37
|
-
jira: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-evidence/jira.md'), 'utf-8'),
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// relativePath is POSIX-style relative to the project root; commands live in
|
|
41
|
-
// .opencode/commands/, skill-backed procedures (plan-archive, ops-ship) in
|
|
42
|
-
// .agents/skills/<name>/SKILL.md.
|
|
43
|
-
function patchFile(relativePath, startMarker, endMarker, content, platform, cwd = process.cwd()) {
|
|
44
|
-
const targetPath = path.join(cwd, ...relativePath.split('/'))
|
|
45
|
-
if (!fse.pathExistsSync(targetPath)) return
|
|
46
|
-
|
|
47
|
-
let fileContent = fse.readFileSync(targetPath, 'utf-8')
|
|
48
|
-
if (!fileContent.includes(startMarker) || !fileContent.includes(endMarker)) return
|
|
49
|
-
|
|
50
|
-
const pattern = new RegExp(`${startMarker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${endMarker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
import fse from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
4
|
+
import { success } from '../../utils/exec.js'
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
|
|
8
|
+
const _archive = {
|
|
9
|
+
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/az.md'), 'utf-8'),
|
|
10
|
+
github: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/gh.md'), 'utf-8'),
|
|
11
|
+
gitlab: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/gl.md'), 'utf-8'),
|
|
12
|
+
none: await fse.readFile(path.resolve(__dirname, '../../fragments/archive/none.md'), 'utf-8'),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const _ship = {
|
|
16
|
+
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-ship/gh.md'), 'utf-8'),
|
|
17
|
+
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-ship/az.md'), 'utf-8'),
|
|
18
|
+
gitlab: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-ship/gl.md'), 'utf-8'),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const _review = {
|
|
22
|
+
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-review/gh.md'), 'utf-8'),
|
|
23
|
+
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-review/az.md'), 'utf-8'),
|
|
24
|
+
gitlab: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-review/gl.md'), 'utf-8'),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const _backlog = {
|
|
28
|
+
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-backlog/gh.md'), 'utf-8'),
|
|
29
|
+
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-backlog/az.md'), 'utf-8'),
|
|
30
|
+
jira: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-backlog/jira.md'), 'utf-8'),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Evidence comments target the backlog platform (where the issue/work-item lives).
|
|
34
|
+
const _evidence = {
|
|
35
|
+
github: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-evidence/gh.md'), 'utf-8'),
|
|
36
|
+
azure: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-evidence/az.md'), 'utf-8'),
|
|
37
|
+
jira: await fse.readFile(path.resolve(__dirname, '../../fragments/ops-evidence/jira.md'), 'utf-8'),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// relativePath is POSIX-style relative to the project root; commands live in
|
|
41
|
+
// .opencode/commands/, skill-backed procedures (plan-archive, ops-ship) in
|
|
42
|
+
// .agents/skills/<name>/SKILL.md.
|
|
43
|
+
function patchFile(relativePath, startMarker, endMarker, content, platform, cwd = process.cwd()) {
|
|
44
|
+
const targetPath = path.join(cwd, ...relativePath.split('/'))
|
|
45
|
+
if (!fse.pathExistsSync(targetPath)) return
|
|
46
|
+
|
|
47
|
+
let fileContent = fse.readFileSync(targetPath, 'utf-8')
|
|
48
|
+
if (!fileContent.includes(startMarker) || !fileContent.includes(endMarker)) return
|
|
49
|
+
|
|
50
|
+
const pattern = new RegExp(`${startMarker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${endMarker.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`)
|
|
51
|
+
// Replacer function, not a replacement string: the injected fragments contain
|
|
52
|
+
// shell quoting like $'...' and a string replacement expands $' as "everything
|
|
53
|
+
// after the match", silently truncating the command. That is how the ops-ship
|
|
54
|
+
// screenshot comment lost its entire --body argument.
|
|
55
|
+
fileContent = fileContent.replace(pattern, () => `${startMarker}\n${content.trim()}\n${endMarker}`)
|
|
56
|
+
fse.writeFileSync(targetPath, `${fileContent.replace(/\s*$/, '')}\n`, 'utf-8')
|
|
57
|
+
success(`${relativePath} content injected for platform: ${platform}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function patchArchiveCommand(platform, cwd = process.cwd()) {
|
|
61
|
+
const repoPlatform = typeof platform === 'object' ? (platform.repoPlatform ?? platform.backlogPlatform ?? 'github') : platform
|
|
62
|
+
const replacement = _archive[repoPlatform]
|
|
63
|
+
if (!replacement) return
|
|
64
|
+
patchFile('.agents/skills/pc-plan-archive/SKILL.md', '<!-- PC-PLATFORM-ARCHIVE-START -->', '<!-- PC-PLATFORM-ARCHIVE-END -->', replacement, repoPlatform, cwd)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function patchOpsShip(platform, cwd = process.cwd()) {
|
|
68
|
+
const repoPlatform = typeof platform === 'object' ? (platform.repoPlatform ?? 'github') : platform
|
|
69
|
+
const replacement = _ship[repoPlatform]
|
|
70
|
+
if (!replacement) return
|
|
71
|
+
patchFile('.agents/skills/pc-ops-ship/SKILL.md', '<!-- PC-PLATFORM-SHIP-START -->', '<!-- PC-PLATFORM-SHIP-END -->', replacement, repoPlatform, cwd)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function patchOpsReview(platform, cwd = process.cwd()) {
|
|
75
|
+
const repoPlatform = typeof platform === 'object' ? (platform.repoPlatform ?? 'github') : platform
|
|
76
|
+
const replacement = _review[repoPlatform]
|
|
77
|
+
if (!replacement) return
|
|
78
|
+
patchFile('.opencode/commands/ops-review.md', '<!-- PC-PLATFORM-REVIEW-START -->', '<!-- PC-PLATFORM-REVIEW-END -->', replacement, repoPlatform, cwd)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function patchOpsBacklog(platform, cwd = process.cwd()) {
|
|
82
|
+
const backlogPlatform = typeof platform === 'object' ? (platform.backlogPlatform ?? 'github') : platform
|
|
83
|
+
const replacement = _backlog[backlogPlatform]
|
|
84
|
+
if (!replacement) return
|
|
85
|
+
patchFile('.opencode/commands/ops-backlog.md', '<!-- PC-PLATFORM-BACKLOG-START -->', '<!-- PC-PLATFORM-BACKLOG-END -->', replacement, backlogPlatform, cwd)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function patchOpsEvidence(platform, cwd = process.cwd()) {
|
|
89
|
+
const backlogPlatform = typeof platform === 'object' ? (platform.backlogPlatform ?? 'github') : platform
|
|
90
|
+
const replacement = _evidence[backlogPlatform]
|
|
91
|
+
// browser/none have no CLI to post with: leave the markers empty (the skill skips commenting).
|
|
92
|
+
if (!replacement) return
|
|
93
|
+
patchFile('.agents/skills/pc-ops-evidence/SKILL.md', '<!-- PC-PLATFORM-EVIDENCE-START -->', '<!-- PC-PLATFORM-EVIDENCE-END -->', replacement, backlogPlatform, cwd)
|
|
94
|
+
}
|
|
95
|
+
|