@plainconceptsplatform/agent-harness 3.1.1 → 3.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/LICENSE +21 -21
- package/README.md +24 -4
- package/cli/commands/join.js +259 -259
- package/cli/commands/migrate.js +310 -310
- package/cli/commands/shared.js +27 -27
- package/cli/commands/single.js +79 -79
- package/cli/commands/wizard.js +134 -134
- package/cli/fragments/ops-backlog/az.md +28 -28
- package/cli/fragments/ops-backlog/gh.md +28 -28
- package/cli/fragments/ops-backlog/jira.md +28 -28
- package/cli/fragments/ops-review/az.md +62 -62
- package/cli/fragments/ops-review/gh.md +51 -51
- package/cli/fragments/ops-review/gl.md +55 -55
- package/cli/fragments/ops-ship/gh.md +67 -67
- package/cli/fragments/ops-ship/gl.md +84 -84
- package/cli/index.js +116 -116
- package/cli/presets/clean.json +21 -21
- package/cli/presets/models.json +68 -68
- package/cli/presets/optimization.json +32 -32
- package/cli/presets/platforms.json +76 -76
- package/cli/presets/source.json +23 -23
- package/cli/steps/clean/index.js +120 -120
- package/cli/steps/copy/agents.js +120 -120
- package/cli/steps/copy/fullstack-engineer.js +89 -89
- package/cli/steps/copy/opencode-json.js +324 -324
- package/cli/steps/models/format.js +88 -88
- package/cli/steps/models/index.js +64 -64
- package/cli/steps/openspec/index.js +136 -136
- package/cli/steps/optimization/codegraph.js +141 -127
- package/cli/steps/optimization/detect.js +66 -66
- package/cli/steps/optimization/humanizer.js +17 -17
- package/cli/steps/optimization/index.js +158 -158
- package/cli/steps/optimization/memory.js +91 -88
- package/cli/steps/optimization/patch-guardrails.js +111 -111
- package/cli/steps/optimization/simple-english.js +17 -17
- package/cli/steps/optimization/skills-lock.js +30 -30
- package/cli/steps/platform/index.js +109 -109
- package/cli/steps/source/index.js +123 -123
- package/cli/utils/agent-color.js +111 -111
- package/cli/utils/copy.js +134 -131
- package/cli/utils/exec-spinner.js +47 -47
- package/cli/utils/exec.js +134 -134
- package/cli/utils/legacy-check.js +30 -30
- package/cli/utils/models-cache.js +58 -58
- package/cli/utils/models-pricing.js +42 -42
- package/cli/utils/process.js +3 -3
- package/cli/utils/terminal.js +6 -6
- package/cli/utils/update-manifest.js +75 -75
- package/harness/.opencode/commands/ops-backlog.md +10 -10
- package/harness/.opencode/commands/ops-review.md +8 -8
- package/harness/.opencode/commands/ops-ship.md +9 -9
- package/harness/.opencode/commands/plan-archive.md +5 -5
- package/harness/.opencode/commands/plan-explore.md +9 -9
- package/harness/.opencode/commands/plan-propose.md +9 -9
- package/harness/.opencode/commands/repo-help.md +5 -5
- package/harness/.opencode/package.json +5 -5
- package/harness/.opencode/plugins/pc-subagent-monitor.js +184 -184
- package/harness/.opencode/plugins/pc-subagent-tiers.js +354 -354
- package/harness/.opencode/plugins/pc-system-reminders.js +386 -386
- package/harness/.opencode/scripts/check-diff.mjs +244 -0
- package/harness/.opencode/scripts/code-rules.mjs +288 -0
- package/harness/ARCHITECTURE.md +13 -13
- package/harness/DESIGN.md +13 -13
- package/harness/opencode.jsonc +36 -36
- package/harness/openspec/config.yaml +20 -20
- package/harness/skills-lock.json +17 -17
- package/package.json +14 -12
- package/skills/agent-harness-cli/SKILL.md +86 -86
- package/skills/pc-guardrails-generic/SKILL.md +2 -1
- package/skills/pc-guardrails-project/SKILL.md +8 -8
- package/skills/pc-make-architecture/structure-template.md +64 -64
- package/skills/pc-make-engineer/SKILL.md +59 -59
- package/skills/pc-make-engineer/template.md +36 -36
- package/skills/pc-make-guardrails/category-reference.md +112 -112
- package/skills/pc-make-merge-risk-assess/SKILL.md +70 -70
- package/skills/pc-make-merge-risk-assess/category-reference.md +114 -114
- package/skills/pc-ops-ship/SKILL.md +22 -18
- package/skills/pc-plan-apply/SKILL.md +86 -86
- package/skills/pc-plan-apply/simple-mode.md +1 -1
- package/skills/pc-plan-explore/SKILL.md +21 -21
- package/skills/pc-plan-goal/SKILL.md +91 -91
- package/skills/pc-plan-goal/failure-policy.md +30 -30
- package/skills/pc-plan-goal/output-mode.md +10 -10
- package/skills/pc-plan-propose/SKILL.md +125 -125
- package/skills/pc-plan-propose/task-annotation.md +39 -39
- package/skills/pc-plan-quick/SKILL.md +1 -1
- package/skills/pc-repo-audit/SKILL.md +44 -44
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import { checkbox, select } from '@inquirer/prompts'
|
|
2
|
-
import fse from 'fs-extra'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import { fileURLToPath } from 'url'
|
|
5
|
-
import { header, info, success, warn } from '../../utils/exec.js'
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
const SOURCE_PRESET_PATH = path.resolve(__dirname, '../../presets/source.json')
|
|
9
|
-
const sourcePreset = await fse.readJson(SOURCE_PRESET_PATH)
|
|
10
|
-
|
|
11
|
-
async function listChildFolders(cwd) {
|
|
12
|
-
const entries = await fse.readdir(cwd)
|
|
13
|
-
const dirs = []
|
|
14
|
-
|
|
15
|
-
for (const name of entries) {
|
|
16
|
-
if (name.startsWith('.')) continue
|
|
17
|
-
const abs = path.join(cwd, name)
|
|
18
|
-
try {
|
|
19
|
-
const stat = await fse.stat(abs)
|
|
20
|
-
if (!stat.isDirectory()) continue
|
|
21
|
-
dirs.push({ name, abs })
|
|
22
|
-
} catch {
|
|
23
|
-
// ignore invalid entries
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
dirs.sort((a, b) => a.name.localeCompare(b.name))
|
|
28
|
-
return dirs
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function listParentFolders(cwd) {
|
|
32
|
-
const parent = path.resolve(cwd, '..')
|
|
33
|
-
const entries = await fse.readdir(parent)
|
|
34
|
-
const dirs = []
|
|
35
|
-
|
|
36
|
-
for (const name of entries) {
|
|
37
|
-
if (name.startsWith('.')) continue
|
|
38
|
-
const abs = path.join(parent, name)
|
|
39
|
-
try {
|
|
40
|
-
const stat = await fse.stat(abs)
|
|
41
|
-
if (!stat.isDirectory()) continue
|
|
42
|
-
if (path.resolve(abs) === path.resolve(cwd)) continue
|
|
43
|
-
dirs.push({ name, abs })
|
|
44
|
-
} catch {
|
|
45
|
-
// ignore invalid entries
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
dirs.sort((a, b) => a.name.localeCompare(b.name))
|
|
50
|
-
return dirs
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function chooseSourceScope() {
|
|
54
|
-
header('Step 1, Source code scope')
|
|
55
|
-
|
|
56
|
-
const cwd = process.cwd()
|
|
57
|
-
info('Choose where agents should read source code from during init analysis.')
|
|
58
|
-
|
|
59
|
-
const mode = await select({
|
|
60
|
-
message: sourcePreset.message,
|
|
61
|
-
default: sourcePreset.default,
|
|
62
|
-
choices: sourcePreset.choices,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if (mode === 'current') {
|
|
66
|
-
success(`Source scope: ${cwd}`)
|
|
67
|
-
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (mode === 'children') {
|
|
71
|
-
const childFolders = await listChildFolders(cwd)
|
|
72
|
-
if (childFolders.length === 0) {
|
|
73
|
-
warn('No child folders found in current directory. Falling back to current folder.')
|
|
74
|
-
success(`Source scope: ${cwd}`)
|
|
75
|
-
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const selected = await checkbox({
|
|
79
|
-
message: sourcePreset.childrenSelectionMessage,
|
|
80
|
-
choices: childFolders.map(d => ({
|
|
81
|
-
name: `./${d.name}`,
|
|
82
|
-
value: d.abs,
|
|
83
|
-
checked: true,
|
|
84
|
-
})),
|
|
85
|
-
required: true,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
if (!selected || selected.length === 0) {
|
|
89
|
-
warn('No folders selected. Falling back to current folder.')
|
|
90
|
-
success(`Source scope: ${cwd}`)
|
|
91
|
-
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
success(`Source scope: ${selected.map(p => path.basename(p)).join(', ')}`)
|
|
95
|
-
return { sourceMode: 'children-selected', sourceRoots: selected }
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const parentFolders = await listParentFolders(cwd)
|
|
99
|
-
if (parentFolders.length === 0) {
|
|
100
|
-
warn('No sibling folders found in parent directory. Falling back to current folder.')
|
|
101
|
-
success(`Source scope: ${cwd}`)
|
|
102
|
-
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const selected = await checkbox({
|
|
106
|
-
message: sourcePreset.parentSelectionMessage,
|
|
107
|
-
choices: parentFolders.map(d => ({
|
|
108
|
-
name: `../${d.name}`,
|
|
109
|
-
value: d.abs,
|
|
110
|
-
checked: true,
|
|
111
|
-
})),
|
|
112
|
-
required: true,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
if (!selected || selected.length === 0) {
|
|
116
|
-
warn('No folders selected. Falling back to current folder.')
|
|
117
|
-
success(`Source scope: ${cwd}`)
|
|
118
|
-
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
success(`Source scope: ${selected.map(p => path.basename(p)).join(', ')}`)
|
|
122
|
-
return { sourceMode: 'parent-selected', sourceRoots: selected }
|
|
123
|
-
}
|
|
1
|
+
import { checkbox, select } from '@inquirer/prompts'
|
|
2
|
+
import fse from 'fs-extra'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { fileURLToPath } from 'url'
|
|
5
|
+
import { header, info, success, warn } from '../../utils/exec.js'
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
const SOURCE_PRESET_PATH = path.resolve(__dirname, '../../presets/source.json')
|
|
9
|
+
const sourcePreset = await fse.readJson(SOURCE_PRESET_PATH)
|
|
10
|
+
|
|
11
|
+
async function listChildFolders(cwd) {
|
|
12
|
+
const entries = await fse.readdir(cwd)
|
|
13
|
+
const dirs = []
|
|
14
|
+
|
|
15
|
+
for (const name of entries) {
|
|
16
|
+
if (name.startsWith('.')) continue
|
|
17
|
+
const abs = path.join(cwd, name)
|
|
18
|
+
try {
|
|
19
|
+
const stat = await fse.stat(abs)
|
|
20
|
+
if (!stat.isDirectory()) continue
|
|
21
|
+
dirs.push({ name, abs })
|
|
22
|
+
} catch {
|
|
23
|
+
// ignore invalid entries
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
dirs.sort((a, b) => a.name.localeCompare(b.name))
|
|
28
|
+
return dirs
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function listParentFolders(cwd) {
|
|
32
|
+
const parent = path.resolve(cwd, '..')
|
|
33
|
+
const entries = await fse.readdir(parent)
|
|
34
|
+
const dirs = []
|
|
35
|
+
|
|
36
|
+
for (const name of entries) {
|
|
37
|
+
if (name.startsWith('.')) continue
|
|
38
|
+
const abs = path.join(parent, name)
|
|
39
|
+
try {
|
|
40
|
+
const stat = await fse.stat(abs)
|
|
41
|
+
if (!stat.isDirectory()) continue
|
|
42
|
+
if (path.resolve(abs) === path.resolve(cwd)) continue
|
|
43
|
+
dirs.push({ name, abs })
|
|
44
|
+
} catch {
|
|
45
|
+
// ignore invalid entries
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dirs.sort((a, b) => a.name.localeCompare(b.name))
|
|
50
|
+
return dirs
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function chooseSourceScope() {
|
|
54
|
+
header('Step 1, Source code scope')
|
|
55
|
+
|
|
56
|
+
const cwd = process.cwd()
|
|
57
|
+
info('Choose where agents should read source code from during init analysis.')
|
|
58
|
+
|
|
59
|
+
const mode = await select({
|
|
60
|
+
message: sourcePreset.message,
|
|
61
|
+
default: sourcePreset.default,
|
|
62
|
+
choices: sourcePreset.choices,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
if (mode === 'current') {
|
|
66
|
+
success(`Source scope: ${cwd}`)
|
|
67
|
+
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (mode === 'children') {
|
|
71
|
+
const childFolders = await listChildFolders(cwd)
|
|
72
|
+
if (childFolders.length === 0) {
|
|
73
|
+
warn('No child folders found in current directory. Falling back to current folder.')
|
|
74
|
+
success(`Source scope: ${cwd}`)
|
|
75
|
+
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const selected = await checkbox({
|
|
79
|
+
message: sourcePreset.childrenSelectionMessage,
|
|
80
|
+
choices: childFolders.map(d => ({
|
|
81
|
+
name: `./${d.name}`,
|
|
82
|
+
value: d.abs,
|
|
83
|
+
checked: true,
|
|
84
|
+
})),
|
|
85
|
+
required: true,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
if (!selected || selected.length === 0) {
|
|
89
|
+
warn('No folders selected. Falling back to current folder.')
|
|
90
|
+
success(`Source scope: ${cwd}`)
|
|
91
|
+
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
success(`Source scope: ${selected.map(p => path.basename(p)).join(', ')}`)
|
|
95
|
+
return { sourceMode: 'children-selected', sourceRoots: selected }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const parentFolders = await listParentFolders(cwd)
|
|
99
|
+
if (parentFolders.length === 0) {
|
|
100
|
+
warn('No sibling folders found in parent directory. Falling back to current folder.')
|
|
101
|
+
success(`Source scope: ${cwd}`)
|
|
102
|
+
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const selected = await checkbox({
|
|
106
|
+
message: sourcePreset.parentSelectionMessage,
|
|
107
|
+
choices: parentFolders.map(d => ({
|
|
108
|
+
name: `../${d.name}`,
|
|
109
|
+
value: d.abs,
|
|
110
|
+
checked: true,
|
|
111
|
+
})),
|
|
112
|
+
required: true,
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
if (!selected || selected.length === 0) {
|
|
116
|
+
warn('No folders selected. Falling back to current folder.')
|
|
117
|
+
success(`Source scope: ${cwd}`)
|
|
118
|
+
return { sourceMode: 'current', sourceRoots: [cwd] }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
success(`Source scope: ${selected.map(p => path.basename(p)).join(', ')}`)
|
|
122
|
+
return { sourceMode: 'parent-selected', sourceRoots: selected }
|
|
123
|
+
}
|
package/cli/utils/agent-color.js
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deterministic colour for an agent, derived from its name.
|
|
3
|
-
*
|
|
4
|
-
* opencode accepts either a hex value or one of its theme keywords. Two of
|
|
5
|
-
* those keywords are reserved for the primaries so they stay recognisable
|
|
6
|
-
* across every project: build is `primary`, plan is `warning`. Every other
|
|
7
|
-
* agent gets a hex derived from its name, so a `butterfly-engineer` is the
|
|
8
|
-
* same colour in every repository that has one, with no central registry and
|
|
9
|
-
* no chance of two agents in one project colliding by accident.
|
|
10
|
-
*
|
|
11
|
-
* Saturation and lightness are fixed rather than hashed. That is what keeps
|
|
12
|
-
* the result usable: hashing them too would eventually produce near-grey,
|
|
13
|
-
* near-black or near-white agents that are invisible against one theme or the
|
|
14
|
-
* other. Only the hue varies.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/** opencode's theme keywords. Treated as unset so a name-derived hex wins. */
|
|
18
|
-
export const THEME_COLORS = new Set([
|
|
19
|
-
'primary',
|
|
20
|
-
'secondary',
|
|
21
|
-
'accent',
|
|
22
|
-
'success',
|
|
23
|
-
'warning',
|
|
24
|
-
'error',
|
|
25
|
-
'info',
|
|
26
|
-
])
|
|
27
|
-
|
|
28
|
-
/** Reserved: the two primaries, which never take a derived colour. */
|
|
29
|
-
export const RESERVED_COLORS = { build: 'primary', plan: 'warning' }
|
|
30
|
-
|
|
31
|
-
const SATURATION = 68
|
|
32
|
-
const LIGHTNESS = 52
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* FNV-1a, 32 bit. Chosen because it is short enough to duplicate verbatim in
|
|
36
|
-
* the shipped plugin and produces the same hue everywhere: the same name must
|
|
37
|
-
* resolve to the same colour on every machine and in every project.
|
|
38
|
-
*/
|
|
39
|
-
function hash(value) {
|
|
40
|
-
let h = 0x811c9dc5
|
|
41
|
-
for (let i = 0; i < value.length; i++) {
|
|
42
|
-
h ^= value.charCodeAt(i)
|
|
43
|
-
h = Math.imul(h, 0x01000193) >>> 0
|
|
44
|
-
}
|
|
45
|
-
return h >>> 0
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function hslToHex(h, s, l) {
|
|
49
|
-
const sat = s / 100
|
|
50
|
-
const light = l / 100
|
|
51
|
-
const c = (1 - Math.abs(2 * light - 1)) * sat
|
|
52
|
-
const x = c * (1 - Math.abs(((h / 60) % 2) - 1))
|
|
53
|
-
const m = light - c / 2
|
|
54
|
-
|
|
55
|
-
const [r, g, b] =
|
|
56
|
-
h < 60 ? [c, x, 0] :
|
|
57
|
-
h < 120 ? [x, c, 0] :
|
|
58
|
-
h < 180 ? [0, c, x] :
|
|
59
|
-
h < 240 ? [0, x, c] :
|
|
60
|
-
h < 300 ? [x, 0, c] :
|
|
61
|
-
[c, 0, x]
|
|
62
|
-
|
|
63
|
-
const toHex = v => Math.round((v + m) * 255).toString(16).padStart(2, '0')
|
|
64
|
-
return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** The colour for an agent, honouring the two reserved primaries. */
|
|
68
|
-
export function agentColor(name) {
|
|
69
|
-
if (name in RESERVED_COLORS) return RESERVED_COLORS[name]
|
|
70
|
-
return hslToHex(hash(name) % 360, SATURATION, LIGHTNESS)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Render a colour for YAML frontmatter.
|
|
75
|
-
*
|
|
76
|
-
* A hex has to be quoted. `#` opens a comment in YAML, so `color: #D83155`
|
|
77
|
-
* parses as null and opencode rejects the agent outright with "Invalid input
|
|
78
|
-
* color". Theme keywords need no quoting and are left bare.
|
|
79
|
-
*/
|
|
80
|
-
export function yamlColor(value) {
|
|
81
|
-
return value.startsWith('#') ? `"${value}"` : value
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** The value of a frontmatter colour, with any quoting removed. */
|
|
85
|
-
export function unquoteColor(raw) {
|
|
86
|
-
return (raw ?? '').trim().replace(/^["']/, '').replace(/["']$/, '')
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* The frontmatter colour line an agent should have, or null when the current
|
|
91
|
-
* one is already correct. Covers both jobs: choosing the colour, and quoting it
|
|
92
|
-
* so the file actually parses.
|
|
93
|
-
*/
|
|
94
|
-
export function colorLineFor(name, rawCurrent) {
|
|
95
|
-
const current = unquoteColor(rawCurrent)
|
|
96
|
-
const target = shouldDeriveColor(current) ? agentColor(name) : current
|
|
97
|
-
const rendered = yamlColor(target)
|
|
98
|
-
return (rawCurrent ?? '').trim() === rendered ? null : `color: ${rendered}`
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Whether a frontmatter colour should be replaced by the derived one.
|
|
103
|
-
*
|
|
104
|
-
* A theme keyword is replaced: those came from the old template, which asked
|
|
105
|
-
* whoever ran /make-engineer to pick one and avoid collisions by hand. An
|
|
106
|
-
* explicit hex is left alone, because someone chose it deliberately.
|
|
107
|
-
*/
|
|
108
|
-
export function shouldDeriveColor(current) {
|
|
109
|
-
if (!current) return true
|
|
110
|
-
return THEME_COLORS.has(current.trim().toLowerCase())
|
|
111
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic colour for an agent, derived from its name.
|
|
3
|
+
*
|
|
4
|
+
* opencode accepts either a hex value or one of its theme keywords. Two of
|
|
5
|
+
* those keywords are reserved for the primaries so they stay recognisable
|
|
6
|
+
* across every project: build is `primary`, plan is `warning`. Every other
|
|
7
|
+
* agent gets a hex derived from its name, so a `butterfly-engineer` is the
|
|
8
|
+
* same colour in every repository that has one, with no central registry and
|
|
9
|
+
* no chance of two agents in one project colliding by accident.
|
|
10
|
+
*
|
|
11
|
+
* Saturation and lightness are fixed rather than hashed. That is what keeps
|
|
12
|
+
* the result usable: hashing them too would eventually produce near-grey,
|
|
13
|
+
* near-black or near-white agents that are invisible against one theme or the
|
|
14
|
+
* other. Only the hue varies.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** opencode's theme keywords. Treated as unset so a name-derived hex wins. */
|
|
18
|
+
export const THEME_COLORS = new Set([
|
|
19
|
+
'primary',
|
|
20
|
+
'secondary',
|
|
21
|
+
'accent',
|
|
22
|
+
'success',
|
|
23
|
+
'warning',
|
|
24
|
+
'error',
|
|
25
|
+
'info',
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
/** Reserved: the two primaries, which never take a derived colour. */
|
|
29
|
+
export const RESERVED_COLORS = { build: 'primary', plan: 'warning' }
|
|
30
|
+
|
|
31
|
+
const SATURATION = 68
|
|
32
|
+
const LIGHTNESS = 52
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* FNV-1a, 32 bit. Chosen because it is short enough to duplicate verbatim in
|
|
36
|
+
* the shipped plugin and produces the same hue everywhere: the same name must
|
|
37
|
+
* resolve to the same colour on every machine and in every project.
|
|
38
|
+
*/
|
|
39
|
+
function hash(value) {
|
|
40
|
+
let h = 0x811c9dc5
|
|
41
|
+
for (let i = 0; i < value.length; i++) {
|
|
42
|
+
h ^= value.charCodeAt(i)
|
|
43
|
+
h = Math.imul(h, 0x01000193) >>> 0
|
|
44
|
+
}
|
|
45
|
+
return h >>> 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function hslToHex(h, s, l) {
|
|
49
|
+
const sat = s / 100
|
|
50
|
+
const light = l / 100
|
|
51
|
+
const c = (1 - Math.abs(2 * light - 1)) * sat
|
|
52
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1))
|
|
53
|
+
const m = light - c / 2
|
|
54
|
+
|
|
55
|
+
const [r, g, b] =
|
|
56
|
+
h < 60 ? [c, x, 0] :
|
|
57
|
+
h < 120 ? [x, c, 0] :
|
|
58
|
+
h < 180 ? [0, c, x] :
|
|
59
|
+
h < 240 ? [0, x, c] :
|
|
60
|
+
h < 300 ? [x, 0, c] :
|
|
61
|
+
[c, 0, x]
|
|
62
|
+
|
|
63
|
+
const toHex = v => Math.round((v + m) * 255).toString(16).padStart(2, '0')
|
|
64
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The colour for an agent, honouring the two reserved primaries. */
|
|
68
|
+
export function agentColor(name) {
|
|
69
|
+
if (name in RESERVED_COLORS) return RESERVED_COLORS[name]
|
|
70
|
+
return hslToHex(hash(name) % 360, SATURATION, LIGHTNESS)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Render a colour for YAML frontmatter.
|
|
75
|
+
*
|
|
76
|
+
* A hex has to be quoted. `#` opens a comment in YAML, so `color: #D83155`
|
|
77
|
+
* parses as null and opencode rejects the agent outright with "Invalid input
|
|
78
|
+
* color". Theme keywords need no quoting and are left bare.
|
|
79
|
+
*/
|
|
80
|
+
export function yamlColor(value) {
|
|
81
|
+
return value.startsWith('#') ? `"${value}"` : value
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The value of a frontmatter colour, with any quoting removed. */
|
|
85
|
+
export function unquoteColor(raw) {
|
|
86
|
+
return (raw ?? '').trim().replace(/^["']/, '').replace(/["']$/, '')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The frontmatter colour line an agent should have, or null when the current
|
|
91
|
+
* one is already correct. Covers both jobs: choosing the colour, and quoting it
|
|
92
|
+
* so the file actually parses.
|
|
93
|
+
*/
|
|
94
|
+
export function colorLineFor(name, rawCurrent) {
|
|
95
|
+
const current = unquoteColor(rawCurrent)
|
|
96
|
+
const target = shouldDeriveColor(current) ? agentColor(name) : current
|
|
97
|
+
const rendered = yamlColor(target)
|
|
98
|
+
return (rawCurrent ?? '').trim() === rendered ? null : `color: ${rendered}`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a frontmatter colour should be replaced by the derived one.
|
|
103
|
+
*
|
|
104
|
+
* A theme keyword is replaced: those came from the old template, which asked
|
|
105
|
+
* whoever ran /make-engineer to pick one and avoid collisions by hand. An
|
|
106
|
+
* explicit hex is left alone, because someone chose it deliberately.
|
|
107
|
+
*/
|
|
108
|
+
export function shouldDeriveColor(current) {
|
|
109
|
+
if (!current) return true
|
|
110
|
+
return THEME_COLORS.has(current.trim().toLowerCase())
|
|
111
|
+
}
|